[llvm] [llubi] Add support for poison-generating/UB-implying annotations (PR #195339)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun May 3 03:46:37 PDT 2026


================
@@ -484,13 +581,78 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
     case Intrinsic::assume:
       switch (Args[0].asBoolean()) {
       case BooleanKind::True:
+        for (unsigned Idx = 0; Idx < CB.getNumOperandBundles(); Idx++) {
+          OperandBundleUse OBU = CB.getOperandBundleAt(Idx);
+          auto GetBundleArg = [&](uint32_t Offset) -> Value * {
+            return OBU.Inputs[Offset];
+          };
+          if (OBU.Inputs.empty())
+            continue;
+          Value *WasOnVal = GetBundleArg(0);
+          // Bail out on unrecognized operand bundles.
+          if (!WasOnVal->getType()->isPointerTy())
+            continue;
+          const AnyValue &WasOn = getValue(WasOnVal);
+          if (WasOn.isPoison()) {
+            reportImmediateUB() << "Assume on poison pointer.";
+            break;
+          }
+          const Pointer &WasOnPtr = WasOn.asPointer();
+          Attribute::AttrKind Kind =
+              Attribute::getAttrKindFromName(OBU.getTagName());
+          switch (Kind) {
+          case Attribute::Alignment: {
+            // Alignment assumptions should have 2 or 3 arguments.
+            // If there are two integer arguments, use the largest power of 2
+            // that divides them as the alignment.
+            uint64_t Alignment = getUInt64NonPoison(getValue(GetBundleArg(1)));
+            if (OBU.Inputs.size() == 3)
+              Alignment = MinAlign(
+                  Alignment, getUInt64NonPoison(getValue(GetBundleArg(2))));
----------------
nikic wrote:

Hm, it looks like LangRef doesn't actually document the offset argument. But normally I'd expect offsets to be signed?

https://github.com/llvm/llvm-project/pull/195339


More information about the llvm-commits mailing list