<commit_before>// MemCheck.cpp (Oclgrind)
// Copyright (c) 2013-2015, <NAME> and <NAME>,
// University of Bristol. All rights reserved.
//
// This program is provided under a three-clause BSD license. For full
// license terms please see the LICENSE file distributed with this
// source code.

#include "core/common.h"

#include "core/Context.h"
#include "core/Memory.h"
#include "core/WorkItem.h"

#include "llvm/IR/Instructions.h"
#include "llvm/IR/Type.h"

#include "MemCheck.h"

using namespace oclgrind;
using namespace std;

MemCheck::MemCheck(const Context *context)
 : Plugin(context)
{
}

void MemCheck::instructionExecuted(const WorkItem *workItem,
                                   const llvm::Instruction *instruction,
                                   const TypedValue& result)
{
  // Check static array bounds if load or store is executed
  const llvm::Value *PtrOp = nullptr;

  if (auto LI = llvm::dyn_cast<llvm::LoadInst>(instruction))
  {
    PtrOp = LI->getPointerOperand();
  }
  else if (auto SI = llvm::dyn_cast<llvm::StoreInst>(instruction))
  {
    PtrOp = SI->getPointerOperand();
  }
  else
  {
    return;
  }

  if (auto GEPI = llvm::dyn_cast<llvm::GetElementPtrInst>(PtrOp->stripPointerCasts()))
  {
    checkArrayAccess(workItem, GEPI);
  }
}

void MemCheck::memoryAtomicLoad(const Memory *memory,
                                const WorkItem *workItem,
                                AtomicOp op, size_t address, size_t size)
{
  checkLoad(memory, address, size);
}
<commit_msg>Check full chain of GEP instructions for static arrays<commit_after>// MemCheck.cpp (Oclgrind)
// Copyright (c) 2013-2015, <NAME> and <NAME>,
// University of Bristol. All rights reserved.
//
// This program is provided under a three-clause BSD license. For full
// license terms please see the LICENSE file distributed with this
// source code.

#include "core/common.h"

#include "core/Context.h"
#include "core/Memory.h"
#include "core/WorkItem.h"

#include "llvm/IR/Instructions.h"
#include "llvm/IR/Type.h"

#include "MemCheck.h"

using namespace oclgrind;
using namespace std;

MemCheck::MemCheck(const Context *context)
 : Plugin(context)
{
}

void MemCheck::instructionExecuted(const WorkItem *workItem,
                                   const llvm::Instruction *instruction,
                                   const TypedValue& result)
{
  // Check static array bounds if load or store is executed
  const llvm::Value *PtrOp = nullptr;

  if (auto LI = llvm::dyn_cast<llvm::LoadInst>(instruction))
  {
    PtrOp = LI->getPointerOperand();
  }
  else if (auto SI = llvm::dyn_cast<llvm::StoreInst>(instruction))
  {
    PtrOp = SI->getPointerOperand();
  }
  else
  {
    return;
  }

  // Walk up chain of GEP instructions leading to this access
  while (auto GEPI =
           llvm::dyn_cast<llvm::GetElementPtrInst>(PtrOp->stripPointerCasts()))
  {
    checkArrayAccess(workItem, GEPI);

    PtrOp = GEPI->getPointerOperand();
  }
}

void MemCheck::memoryAtomicLoad(const Memory *memory,
                                const WorkItem *workItem,
                                AtomicOp op, size_t address, size_t size)
{
  checkLoad(memory, address, size);
}

{'fraction_non_alphanumeric': 0.11616954474097331, 'fraction_numerical': 0.005023547880690738, 'mean_word_length': 2.933333333333333, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3274602', 'n_tokens_mistral': 1005, 'n_tokens_neox': 971, 'n_words': 266}