@@ -186,7 +186,9 @@ TypeAnalyzer::TypeAnalyzer(
186
186
}
187
187
188
188
// / Given a constant value, deduce any type information applicable
189
- TypeTree getConstantAnalysis (Constant *Val, TypeAnalyzer &TA) {
189
+ TypeTree
190
+ getConstantAnalysis (Constant *Val, TypeAnalyzer &TA,
191
+ SmallPtrSetImpl<GlobalVariable *> *seen = nullptr ) {
190
192
auto &DL = TA.fntypeinfo .Function ->getParent ()->getDataLayout ();
191
193
// Undefined value is an anything everywhere
192
194
if (isa<UndefValue>(Val) || isa<ConstantAggregateZero>(Val)) {
@@ -238,9 +240,10 @@ TypeTree getConstantAnalysis(Constant *Val, TypeAnalyzer &TA) {
238
240
239
241
int Off = (int )ai.getLimitedValue ();
240
242
241
- Result |= getConstantAnalysis (Op, TA).ShiftIndices (DL, /* init offset*/ 0 ,
242
- /* maxSize*/ ObjSize,
243
- /* addOffset*/ Off);
243
+ Result |= getConstantAnalysis (Op, TA, seen)
244
+ .ShiftIndices (DL, /* init offset*/ 0 ,
245
+ /* maxSize*/ ObjSize,
246
+ /* addOffset*/ Off);
244
247
Off += ObjSize;
245
248
}
246
249
if (TA.fntypeinfo .Function ->getParent ()->getDataLayout ().getTypeSizeInBits (
@@ -284,9 +287,10 @@ TypeTree getConstantAnalysis(Constant *Val, TypeAnalyzer &TA) {
284
287
285
288
int Off = (int )ai.getLimitedValue ();
286
289
287
- Result |= getConstantAnalysis (Op, TA).ShiftIndices (DL, /* init offset*/ 0 ,
288
- /* maxSize*/ ObjSize,
289
- /* addOffset*/ Off);
290
+ Result |= getConstantAnalysis (Op, TA, seen)
291
+ .ShiftIndices (DL, /* init offset*/ 0 ,
292
+ /* maxSize*/ ObjSize,
293
+ /* addOffset*/ Off);
290
294
}
291
295
if (TA.fntypeinfo .Function ->getParent ()->getDataLayout ().getTypeSizeInBits (
292
296
CD->getType ()) >= 16 ) {
@@ -334,10 +338,10 @@ TypeTree getConstantAnalysis(Constant *Val, TypeAnalyzer &TA) {
334
338
if (CE->isCast ()) {
335
339
if (CE->getType ()->isPointerTy () && isa<ConstantInt>(CE->getOperand (0 )))
336
340
return TypeTree (BaseType::Anything).Only (-1 );
337
- return getConstantAnalysis (CE->getOperand (0 ), TA);
341
+ return getConstantAnalysis (CE->getOperand (0 ), TA, seen );
338
342
}
339
343
if (CE->isGEPWithNoNotionalOverIndexing ()) {
340
- auto gepData0 = getConstantAnalysis (CE->getOperand (0 ), TA).Data0 ();
344
+ auto gepData0 = getConstantAnalysis (CE->getOperand (0 ), TA, seen ).Data0 ();
341
345
342
346
auto g2 = cast<GetElementPtrInst>(CE->getAsInstruction ());
343
347
#if LLVM_VERSION_MAJOR > 6
@@ -380,10 +384,16 @@ TypeTree getConstantAnalysis(Constant *Val, TypeAnalyzer &TA) {
380
384
}
381
385
382
386
if (auto GV = dyn_cast<GlobalVariable>(Val)) {
387
+ if (seen && seen->count (GV))
388
+ return TypeTree ();
383
389
// A fixed constant global is a pointer to its initializer
384
390
if (GV->isConstant () && GV->hasInitializer ()) {
391
+ SmallPtrSet<GlobalVariable *, 2 > seen2;
392
+ if (seen)
393
+ seen2.insert (seen->begin (), seen->end ());
394
+ seen2.insert (GV);
385
395
TypeTree Result = ConcreteType (BaseType::Pointer);
386
- Result |= getConstantAnalysis (GV->getInitializer (), TA);
396
+ Result |= getConstantAnalysis (GV->getInitializer (), TA, &seen2 );
387
397
return Result.Only (-1 );
388
398
}
389
399
if (GV->getName () == " __cxa_thread_atexit_impl" ) {
@@ -998,8 +1008,6 @@ void TypeAnalyzer::visitConstantExpr(ConstantExpr &CE) {
998
1008
pointerData0.ShiftIndices (DL, /* init offset*/ 0 , /* max size*/ -1 ,
999
1009
/* new offset*/ off);
1000
1010
result.insert ({}, BaseType::Pointer);
1001
- llvm::errs () << " CE: " << CE << " pdata0: " << pointerData0.str ()
1002
- << " off: " << off << " res: " << result.str () << " \n " ;
1003
1011
updateAnalysis (CE.getOperand (0 ), result.Only (-1 ), &CE);
1004
1012
}
1005
1013
return ;
0 commit comments