Browse code

bb#11578 - adjustments to pointer last argument check (exclude hidden ctx)

Kevin Lin authored on 2016/06/03 06:31:56
Showing 1 changed files
... ...
@@ -488,8 +488,13 @@ namespace llvm {
488 488
           constType *I64Ty =
489 489
               Type::getInt64Ty(Base->getContext());
490 490
 
491
-          if (Base->getType()->isPointerTy()) {
492
-              if (Argument *A = dyn_cast<Argument>(Base)) {
491
+#ifndef CLAMBC_COMPILER
492
+          // first arg is hidden ctx
493
+          if (Argument *A = dyn_cast<Argument>(Base)) {
494
+              if (A->getArgNo() == 0) {
495
+                  constType *Ty = cast<PointerType>(A->getType())->getElementType();
496
+                  return ConstantInt::get(I64Ty, TD->getTypeAllocSize(Ty));
497
+              } else if (Base->getType()->isPointerTy()) {
493 498
                   Function *F = A->getParent();
494 499
                   const FunctionType *FT = F->getFunctionType();
495 500
 
... ...
@@ -514,15 +519,6 @@ namespace llvm {
514 514
                       return BoundsMap[Base] = getValAtIdx(F, A->getArgNo()+1);
515 515
               }
516 516
           }
517
-
518
-#ifndef CLAMBC_COMPILER
519
-          // first arg is hidden ctx
520
-          if (Argument *A = dyn_cast<Argument>(Base)) {
521
-              if (A->getArgNo() == 0) {
522
-                  constType *Ty = cast<PointerType>(A->getType())->getElementType();
523
-                  return ConstantInt::get(I64Ty, TD->getTypeAllocSize(Ty));
524
-              }
525
-          }
526 517
           if (LoadInst *LI = dyn_cast<LoadInst>(Base)) {
527 518
               Value *V = GetUnderlyingObject(LI->getPointerOperand()->stripPointerCasts(), TD);
528 519
               if (Argument *A = dyn_cast<Argument>(V)) {
... ...
@@ -534,6 +530,33 @@ namespace llvm {
534 534
                   }
535 535
               }
536 536
           }
537
+#else
538
+          if (Base->getType()->isPointerTy()) {
539
+              if (Argument *A = dyn_cast<Argument>(Base)) {
540
+                  Function *F = A->getParent();
541
+                  const FunctionType *FT = F->getFunctionType();
542
+
543
+                  bool checks = true;
544
+                  // last argument check
545
+                  if (A->getArgNo() == (FT->getNumParams()-1)) {
546
+                      //printDiagnostic("pointer argument cannot be last argument", F);
547
+                      errs() << "pointer argument cannot be last argument\n";
548
+                      errs() << *F << "\n";
549
+                      checks = false;
550
+                  }
551
+
552
+                  // argument after pointer MUST be a integer (unsigned probably too)
553
+                  if (checks && !FT->getParamType(A->getArgNo()+1)->isIntegerTy()) {
554
+                      //printDiagnostic("argument following pointer argument is not an integer", F);
555
+                      errs() << "argument following pointer argument is not an integer\n";
556
+                      errs() << *F << "\n";
557
+                      checks = false;
558
+                  }
559
+
560
+                  if (checks)
561
+                      return BoundsMap[Base] = getValAtIdx(F, A->getArgNo()+1);
562
+              }
563
+          }
537 564
 #endif
538 565
           if (PHINode *PN = dyn_cast<PHINode>(Base)) {
539 566
               BasicBlock::iterator It = PN;