================
@@ -6878,6 +6878,41 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, 
CallBase &Call) {
           &Call);
     break;
   }
+  case Intrinsic::structured_gep: {
+    // Parser should refuse those 2 cases.
+    assert(Call.getNumOperands() >= 2);
+    assert(Call.getOperand(0)->getType()->isPointerTy());
+
+    Check(Call.paramHasAttr(0, Attribute::ElementType),
+          "Intrinsic first parameter is missing an ElementType attribute",
+          &Call);
+
+    Type *T = Call.getParamAttr(0, Attribute::ElementType).getValueAsType();
+    for (unsigned I = 1; I < Call.getNumOperands() - 1; ++I) {
+      Value *Index = Call.getOperand(I);
+      ConstantInt *CI = dyn_cast<ConstantInt>(Index);
+      Check(Index->getType()->isIntegerTy(),
+            "Index operand type must be an integer", &Call);
+
+      if (ArrayType *AT = dyn_cast<ArrayType>(T)) {
+        T = AT->getElementType();
+        if (CI && AT->getNumElements() != 0)
+          Check(CI->getZExtValue() < AT->getNumElements(),
+                "Indexing in an array should be inbounds", &Call);
----------------
Keenuts wrote:

What do you mean? Is it something like:
```c
void foo(i32 %index)
   if (%index != 3)
       return;
   structured_gep(ptr elementtype([2 x i32]) %src, i32 %index)
```

In this case, an optimization could replace `%index` with `i32 3` after the 
condition because that's the only possible value, and even if this is a valid 
transformation, we'd now fail IR validation because of the out of bounds?

https://github.com/llvm/llvm-project/pull/176145
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to