<commit_before>#include "llvm/Pass.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/ADT/SmallPtrSet.h"

#include "boost/range.hpp"
#include <set>

namespace crab_llvm {
  
  using namespace llvm;

  class LowerCstExpr: public ModulePass {
    ConstantExpr* hasCstExpr(Value *V, std::set<Value*> &visited) {
      if (visited.count (V) > 0) return nullptr;
      
      visited.insert (V);
      if (Constant * cst = dyn_cast<Constant>(V)) {
        if (ConstantExpr * ce = dyn_cast<ConstantExpr>(cst)) {
          return ce;
	} else {
          // for ConstantStruct, ConstantArray, etc, we need to check
          // recursively.
          for (unsigned u=0; u < cst->getNumOperands (); ++u) {
            Use& p = cst->getOperandUse(u);
            // for (auto p : boost::make_iterator_range (cst->op_begin (),
            //                                           cst->op_end ()))
            // {
            if (ConstantExpr * cst_exp_i = hasCstExpr(p.get (), visited))
              return cst_exp_i;
          }
        }          
      }
      return nullptr;
    }
    
    ConstantExpr* hasCstExpr(Value *V) {
      std::set<Value*> visited;
      return hasCstExpr(V,visited);
    }

    Instruction * lowerCstExpr(ConstantExpr* CstExp, 
                               Instruction* InsertionLoc) {
      Instruction* NewI = CstExp->getAsInstruction ();
      // insert before
      InsertionLoc->getParent()->getInstList().insert(InsertionLoc, NewI); 
      return NewI;<commit_msg>[FIXED] we only lower top-level constant expressions.<commit_after>#include "llvm/Pass.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/ADT/SmallPtrSet.h"

namespace crab_llvm {
  
  using namespace llvm;

  class LowerCstExpr: public ModulePass {
    
    ConstantExpr* hasCstExpr(Value *V) {
      // We only handle top-level constant expressions ignoring
      // constant subexpressions
      if (Constant * cst = dyn_cast<Constant>(V)) {
        if (ConstantExpr * ce = dyn_cast<ConstantExpr>(cst)) {
          return ce;
	}
      }
      return nullptr;
    }

    Instruction * lowerCstExpr(ConstantExpr* CstExp, 
                               Instruction* InsertionLoc) {
      Instruction* NewI = CstExp->getAsInstruction ();
      // insert before
      InsertionLoc->getParent()->getInstList().insert(InsertionLoc, NewI); 
      return NewI;
{'fraction_non_alphanumeric': 0.12581511315688532, 'fraction_numerical': 0.0007671653241273494, 'mean_word_length': 2.3608247422680413, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7196144', 'n_tokens_mistral': 826, 'n_tokens_neox': 817, 'n_words': 171}