[llvm] [WIP][llubi] Add support for poison-generating/UB-implying attributes/metadata/operand bundles (PR #195339)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat May 2 09:39:12 PDT 2026
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/195339
>From 137005da1c1ab2e4392a1c0995f365b675f2505b Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sat, 2 May 2026 03:50:25 +0800
Subject: [PATCH 1/4] [llubi] Add support for poison-generating/UB-implying
attributes and metadata
---
llvm/tools/llubi/lib/Interpreter.cpp | 202 ++++++++++++++++++++++++++-
1 file changed, 196 insertions(+), 6 deletions(-)
diff --git a/llvm/tools/llubi/lib/Interpreter.cpp b/llvm/tools/llubi/lib/Interpreter.cpp
index 1f68051c617a0..7adc8fdf01513 100644
--- a/llvm/tools/llubi/lib/Interpreter.cpp
+++ b/llvm/tools/llubi/lib/Interpreter.cpp
@@ -64,6 +64,82 @@ static AnyValue mulNoWrap(const APInt &LHS, const APInt &RHS, bool HasNSW,
return Res;
}
+/// Visit the scalar values recursively. The callback function may modify the
+/// value in-place.
+static void forEachScalarValue(AnyValue &V,
+ function_ref<void(AnyValue &)> Visit) {
+ if (V.isNone())
+ return;
+
+ if (V.isAggregate()) {
+ for (auto &SubValue : V.asAggregate()) {
+ forEachScalarValue(SubValue, Visit);
+ }
+ return;
+ }
+
+ Visit(V);
+}
+
+static void applyRangeAttr(AnyValue &V, const ConstantRange &CR) {
+ forEachScalarValue(V, [&](AnyValue &Scalar) {
+ if (Scalar.isInteger() && !CR.contains(Scalar.asInteger()))
+ Scalar = AnyValue::poison();
+ });
+}
+
+static void applyNoFPClassAttr(AnyValue &V, FPClassTest NoFPClass) {
+ forEachScalarValue(V, [NoFPClass](AnyValue &Scalar) {
+ if (Scalar.isFloat() && (Scalar.asFloat().classify() & NoFPClass))
+ Scalar = AnyValue::poison();
+ });
+}
+
+static void applyNonNullAttr(AnyValue &V) {
+ forEachScalarValue(V, [](AnyValue &Scalar) {
+ if (Scalar.isPointer() && Scalar.asPointer().address().isZero())
+ Scalar = AnyValue::poison();
+ });
+}
+
+static void applyAlignAttr(AnyValue &V, Align Alignment) {
+ forEachScalarValue(V, [Alignment](AnyValue &Scalar) {
+ if (Scalar.isPointer() &&
+ Scalar.asPointer().address().countr_zero() >= Log2(Alignment))
+ Scalar = AnyValue::poison();
+ });
+}
+
+static bool applyNoUndefAttr(AnyValue &V) {
+ bool ContainsPoison = false;
+ forEachScalarValue(
+ V, [&](AnyValue &Scalar) { ContainsPoison |= Scalar.isPoison(); });
+ return ContainsPoison;
+}
+
+/// Assumes V is either a poison or a pointer.
+static bool applyDereferenceableBytesAttr(AnyValue &V, uint64_t Bytes,
+ bool OrNull) {
+ if (V.isPoison())
+ return true;
+
+ auto &Ptr = V.asPointer();
+ const APInt &PtrAddr = Ptr.address();
+ if (PtrAddr.isZero()) {
+ if (OrNull)
+ return false;
+ return true;
+ }
+ auto *MO = Ptr.getMemoryObject();
+ if (!MO)
+ return true;
+
+ // TODO: check read_provenance
+
+ return Bytes > MO->getSize() || PtrAddr.ult(MO->getAddress()) ||
+ PtrAddr.ugt(MO->getAddress() + MO->getSize() - Bytes);
+}
+
/// Instruction executor using the visitor pattern.
/// Unlike the Context class that manages the global state,
/// InstExecutor only maintains the state for call frames.
@@ -463,12 +539,18 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
}
void returnFromCallee() {
- // TODO: handle retval attributes (Attributes from known callee should be
- // applied if available).
- // TODO: handle metadata
auto &CB = cast<CallBase>(*CurrentFrame->PC);
CurrentFrame->CalleeArgs.clear();
AnyValue &RetVal = CurrentFrame->CalleeRetVal;
+ if (Type *RetTy = CB.getType(); !RetTy->isVoidTy()) {
+ // Handle attributes on the return value (Attributes from resolved callee
+ // should be applied if available).
+ AttributeSet AttrsAtCallSite = CB.getRetAttributes();
+ AttributeSet AttrsAtCallee =
+ CurrentFrame->ResolvedCallee->getAttributes().getRetAttrs();
+ handleAttributes(RetTy, RetVal, AttrsAtCallSite, AttrsAtCallee);
+ handleMetadata(RetTy, RetVal, CB);
+ }
setResult(CB, std::move(RetVal));
if (auto *II = dyn_cast<InvokeInst>(&CB))
@@ -913,10 +995,105 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
return AnyValue();
}
+ /// Handle both poison-generating and UB-implying attributes for parameters
+ /// and return values.
+ void handleAttributes(Type *Ty, AnyValue &V, AttributeSet AttrsAtCallSite,
+ AttributeSet AttrsAtCallee) {
+ if (Ty->isIntOrIntVectorTy()) {
+ if (auto CRAttr = AttrsAtCallSite.getAttribute(Attribute::Range);
+ CRAttr.isValid())
+ applyRangeAttr(V, CRAttr.getRange());
+ if (auto CRAttr = AttrsAtCallee.getAttribute(Attribute::Range);
+ CRAttr.isValid())
+ applyRangeAttr(V, CRAttr.getRange());
+ }
+ if (AttributeFuncs::isNoFPClassCompatibleType(Ty)) {
+ if (auto CRAttr = AttrsAtCallSite.getAttribute(Attribute::NoFPClass);
+ CRAttr.isValid())
+ applyNoFPClassAttr(V, CRAttr.getNoFPClass());
+ if (auto CRAttr = AttrsAtCallee.getAttribute(Attribute::NoFPClass);
+ CRAttr.isValid())
+ applyNoFPClassAttr(V, CRAttr.getNoFPClass());
+ }
+ if (Ty->isPtrOrPtrVectorTy()) {
+ if (AttrsAtCallSite.hasAttribute(Attribute::NonNull) ||
+ AttrsAtCallee.hasAttribute(Attribute::NonNull))
+ applyNonNullAttr(V);
+ if (MaybeAlign Align = AttrsAtCallSite.getAlignment())
+ applyAlignAttr(V, *Align);
+ if (MaybeAlign Align = AttrsAtCallee.getAlignment())
+ applyAlignAttr(V, *Align);
+ }
+ if ((AttrsAtCallSite.hasAttribute(Attribute::NoUndef) ||
+ AttrsAtCallee.hasAttribute(Attribute::NoUndef)) &&
+ applyNoUndefAttr(V)) {
+ reportImmediateUB("The value violates noundef attribute.");
+ return;
+ }
+ if (Ty->isPointerTy()) {
+ if (uint64_t DereferenceableBytes =
+ std::max(AttrsAtCallSite.getDereferenceableBytes(),
+ AttrsAtCallee.getDereferenceableBytes())) {
+ if (applyDereferenceableBytesAttr(V, DereferenceableBytes,
+ /*OrNull=*/false))
+ reportImmediateUB("The value violates dereferenceable attribute.");
+ } else if (uint64_t DereferenceableOrNullBytes =
+ std::max(AttrsAtCallSite.getDereferenceableOrNullBytes(),
+ AttrsAtCallee.getDereferenceableOrNullBytes())) {
+ if (applyDereferenceableBytesAttr(V, DereferenceableOrNullBytes,
+ /*OrNull=*/true))
+ reportImmediateUB("The value violates "
+ "dereferenceable_or_null attribute.");
+ }
+ }
+ }
+
+ /// Handle both poison-generating and UB-implying metadata on instructions.
+ void handleMetadata(Type *Ty, AnyValue &V, Instruction &I) {
+ auto ExtractFirstIntOperand = [](const MDNode *Node) {
+ return mdconst::extract<ConstantInt>(Node->getOperand(0))->getZExtValue();
+ };
+
+ if (Ty->isIntOrIntVectorTy()) {
+ if (MDNode *Ranges = I.getMetadata(LLVMContext::MD_range))
+ applyRangeAttr(V, getConstantRangeFromMetadata(*Ranges));
+ }
+ if (AttributeFuncs::isNoFPClassCompatibleType(Ty)) {
+ if (const MDNode *NoFPClass = I.getMetadata(LLVMContext::MD_nofpclass)) {
+ applyNoFPClassAttr(
+ V, static_cast<FPClassTest>(ExtractFirstIntOperand(NoFPClass)));
+ }
+ }
+ if (Ty->isPtrOrPtrVectorTy()) {
+ if (I.hasMetadata(LLVMContext::MD_nonnull))
+ applyNonNullAttr(V);
+ if (const MDNode *Alignment = I.getMetadata(LLVMContext::MD_align))
+ applyAlignAttr(V, Align(ExtractFirstIntOperand(Alignment)));
+ }
+ if (I.hasMetadata(LLVMContext::MD_noundef) && applyNoUndefAttr(V)) {
+ reportImmediateUB("The value violates !noundef metadata.");
+ return;
+ }
+ if (Ty->isPointerTy()) {
+ if (const MDNode *DereferenceableBytes =
+ I.getMetadata(LLVMContext::MD_dereferenceable)) {
+ if (applyDereferenceableBytesAttr(
+ V, ExtractFirstIntOperand(DereferenceableBytes),
+ /*OrNull=*/false))
+ reportImmediateUB("The value violates !dereferenceable metadata.");
+ } else if (const MDNode *DereferenceableOrNullBytes =
+ I.getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
+ if (applyDereferenceableBytesAttr(
+ V, ExtractFirstIntOperand(DereferenceableOrNullBytes),
+ /*OrNull=*/true))
+ reportImmediateUB("The value violates "
+ "!dereferenceable_or_null metadata.");
+ }
+ }
+ }
+
void enterCall(CallBase &CB) {
Function *Callee = CB.getCalledFunction();
- // TODO: handle parameter attributes (Attributes from known callee should be
- // applied if available).
// TODO: handle byval/initializes
auto &CalleeArgs = CurrentFrame->CalleeArgs;
assert(CalleeArgs.empty() &&
@@ -959,6 +1136,19 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
assert(
Callee->getFunctionType() == CB.getFunctionType() &&
"Expected the callee function type to match the call site signature.");
+
+ // Handle parameter attributes (Attributes from resolved callee should be
+ // applied if available).
+ for (auto [I, Arg] : enumerate(CB.args())) {
+ Type *ArgTy = Arg->getType();
+ AnyValue &ArgVal = CalleeArgs[I];
+ // CallBase::paramHasAttr also checks parameter attributes at known
+ // callee. We do it explicitly to avoid duplication.
+ AttributeSet AttrsAtCallSite = CB.getParamAttributes(I);
+ AttributeSet AttrsAtCallee = Callee->getAttributes().getParamAttrs(I);
+ handleAttributes(ArgTy, ArgVal, AttrsAtCallSite, AttrsAtCallee);
+ }
+
CurrentFrame->ResolvedCallee = Callee;
if (Callee->isIntrinsic()) {
CurrentFrame->CalleeRetVal = callIntrinsic(CB, CalleeArgs);
@@ -1378,7 +1568,7 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
auto RetVal =
load(getValue(LI.getPointerOperand()), LI.getAlign(), LI.getType());
// TODO: track volatile loads
- // TODO: handle metadata
+ handleMetadata(LI.getType(), RetVal, LI);
setResult(LI, std::move(RetVal));
}
>From 84d273dd0b674d4d1a9032557674d5a88d6f96b7 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sat, 2 May 2026 21:22:49 +0800
Subject: [PATCH 2/4] [llubi] Add support for assume operand bundles
---
llvm/tools/llubi/lib/Interpreter.cpp | 98 ++++++++++++++++++++++++----
1 file changed, 85 insertions(+), 13 deletions(-)
diff --git a/llvm/tools/llubi/lib/Interpreter.cpp b/llvm/tools/llubi/lib/Interpreter.cpp
index 7adc8fdf01513..43e87594a4126 100644
--- a/llvm/tools/llubi/lib/Interpreter.cpp
+++ b/llvm/tools/llubi/lib/Interpreter.cpp
@@ -96,18 +96,13 @@ static void applyNoFPClassAttr(AnyValue &V, FPClassTest NoFPClass) {
}
static void applyNonNullAttr(AnyValue &V) {
- forEachScalarValue(V, [](AnyValue &Scalar) {
- if (Scalar.isPointer() && Scalar.asPointer().address().isZero())
- Scalar = AnyValue::poison();
- });
+ if (V.isPointer() && V.asPointer().address().isZero())
+ V = AnyValue::poison();
}
static void applyAlignAttr(AnyValue &V, Align Alignment) {
- forEachScalarValue(V, [Alignment](AnyValue &Scalar) {
- if (Scalar.isPointer() &&
- Scalar.asPointer().address().countr_zero() >= Log2(Alignment))
- Scalar = AnyValue::poison();
- });
+ if (V.isPointer() && V.asPointer().address().countr_zero() < Log2(Alignment))
+ V = AnyValue::poison();
}
static bool applyNoUndefAttr(AnyValue &V) {
@@ -118,7 +113,7 @@ static bool applyNoUndefAttr(AnyValue &V) {
}
/// Assumes V is either a poison or a pointer.
-static bool applyDereferenceableBytesAttr(AnyValue &V, uint64_t Bytes,
+static bool applyDereferenceableBytesAttr(const AnyValue &V, uint64_t Bytes,
bool OrNull) {
if (V.isPoison())
return true;
@@ -458,6 +453,20 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
return Boolean == BooleanKind::True;
}
+ uint64_t getUInt64NonPoison(const AnyValue &V) {
+ if (V.isPoison()) {
+ reportImmediateUB("Unexpected poison integer value.");
+ return 0;
+ }
+ const APInt &C = V.asInteger();
+ if (!C.isIntN(64)) {
+ reportImmediateUB("The integer value is too large.");
+ return 0;
+ }
+
+ return C.getZExtValue();
+ }
+
public:
InstExecutor(Context &C, EventHandler &H, Function &F,
ArrayRef<AnyValue> Args, AnyValue &RetVal)
@@ -567,13 +576,76 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
case Intrinsic::assume:
switch (Args[0].asBoolean()) {
case BooleanKind::True:
+ for (unsigned Idx = 0; Idx < CB.getNumOperandBundles(); Idx++) {
+ CallBase::BundleOpInfo BOI =
+ CB.getBundleOpInfoForOperand(CB.arg_size() + Idx);
+ auto GetBundleArg = [&](uint32_t Offset) -> Value * {
+ return (CB.op_begin() + BOI.Begin + Offset)->get();
+ };
+ if (BOI.End == BOI.Begin)
+ 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(BOI.Tag->getKey());
+ 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 (BOI.End - BOI.Begin == 3)
+ Alignment = MinAlign(
+ Alignment, getUInt64NonPoison(getValue(GetBundleArg(2))));
+ if (!isPowerOf2_64(Alignment)) {
+ if (!WasOn.asPointer().address().isZero())
+ reportImmediateUB("Assume on nonnull pointer with a "
+ "non-power-of-two alignment.");
+ break;
+ }
+ if (WasOnPtr.address().countr_zero() < Log2_64(Alignment))
+ reportImmediateUB(
+ "The pointer address violates alignment assumption.");
+ break;
+ }
+ case Attribute::NonNull:
+ if (WasOnPtr.address().isZero())
+ reportImmediateUB(
+ "The pointer address violates nonnull assumption.");
+ break;
+ case Attribute::Dereferenceable:
+ case Attribute::DereferenceableOrNull: {
+ uint64_t DereferenceableBytes =
+ getUInt64NonPoison(getValue(GetBundleArg(1)));
+ if (applyDereferenceableBytesAttr(
+ WasOn, DereferenceableBytes,
+ Kind == Attribute::DereferenceableOrNull))
+ reportImmediateUB(Kind == Attribute::DereferenceableOrNull
+ ? "The pointer address violates "
+ "dereferenceable_or_null assumption."
+ : "The pointer address violates "
+ "dereferenceable assumption.");
+ break;
+ }
+ default:
+ // TODO: handle other operand bundles like separate_storage.
+ break;
+ }
+ }
break;
case BooleanKind::False:
case BooleanKind::Poison:
reportImmediateUB("Assume on false or poison condition.");
break;
}
- // TODO: handle llvm.assume with operand bundles
return AnyValue();
case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end: {
@@ -1015,7 +1087,7 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
CRAttr.isValid())
applyNoFPClassAttr(V, CRAttr.getNoFPClass());
}
- if (Ty->isPtrOrPtrVectorTy()) {
+ if (Ty->isPointerTy()) {
if (AttrsAtCallSite.hasAttribute(Attribute::NonNull) ||
AttrsAtCallee.hasAttribute(Attribute::NonNull))
applyNonNullAttr(V);
@@ -1064,7 +1136,7 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
V, static_cast<FPClassTest>(ExtractFirstIntOperand(NoFPClass)));
}
}
- if (Ty->isPtrOrPtrVectorTy()) {
+ if (Ty->isPointerTy()) {
if (I.hasMetadata(LLVMContext::MD_nonnull))
applyNonNullAttr(V);
if (const MDNode *Alignment = I.getMetadata(LLVMContext::MD_align))
>From a132bfbfb7c588313a810826b829e318b77fb68d Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sun, 3 May 2026 00:22:27 +0800
Subject: [PATCH 3/4] [llubi] Add tests.
---
llvm/test/tools/llubi/attributes.ll | 116 +++++++++++++++++++++++++++
llvm/tools/llubi/lib/Interpreter.cpp | 9 ++-
2 files changed, 123 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/tools/llubi/attributes.ll
diff --git a/llvm/test/tools/llubi/attributes.ll b/llvm/test/tools/llubi/attributes.ll
new file mode 100644
index 0000000000000..ffa7fd505476e
--- /dev/null
+++ b/llvm/test/tools/llubi/attributes.ll
@@ -0,0 +1,116 @@
+; RUN: llubi --verbose < %s 2>&1 | FileCheck %s
+
+define range(i32 0, 2) i32 @add_with_range(i32 range(i32 0, 2) %x) {
+ %add = add i32 %x, 1
+ ret i32 %add
+}
+
+define range(i32 0, 2) <4 x i32> @add_with_range_vec(<4 x i32> range(i32 0, 2) %x) {
+ %add = add <4 x i32> %x, splat(i32 1)
+ ret <4 x i32> %add
+}
+
+define nofpclass(nan) half @identity_nofpclass(half nofpclass(inf) %x) {
+ ret half %x
+}
+
+define nofpclass(nan) <4 x half> @identity_nofpclass_vec(<4 x half> nofpclass(inf) %x) {
+ ret <4 x half> %x
+}
+
+define nofpclass(nan) {<2 x half>, <2 x half>} @identity_nofpclass_agg({<2 x half>, <2 x half>} nofpclass(inf) %x) {
+ ret {<2 x half>, <2 x half>} %x
+}
+
+define nonnull ptr @gep_nonnull(ptr nonnull %p) {
+ %gep = getelementptr i8, ptr %p, i32 -1
+ ret ptr %gep
+}
+
+define ptr @gep(ptr %p) {
+ %gep = getelementptr i8, ptr %p, i32 -1
+ ret ptr %gep
+}
+
+define align 16 ptr @gep_align(ptr align 8 %p) {
+ %gep = getelementptr i8, ptr %p, i32 8
+ ret ptr %gep
+}
+
+define align 16 <4 x ptr> @gep_align_vec(<4 x ptr> align 8 %p) {
+ %gep = getelementptr i8, <4 x ptr> %p, i32 8
+ ret <4 x ptr> %gep
+}
+
+define noundef i32 @identity_noundef(i32 noundef %x) {
+ ret i32 %x
+}
+
+define noundef {i32, <2 x i32>, [2 x i32]} @identity_noundef_agg({i32, <2 x i32>, [2 x i32]} noundef %x) {
+ ret {i32, <2 x i32>, [2 x i32]} %x
+}
+
+define noundef dereferenceable(4) ptr @identity_dereferenceable(ptr noundef dereferenceable(4) %p) {
+ ret ptr %p
+}
+
+define noundef dereferenceable(1) ptr @identity_dereferenceable_single_byte(ptr noundef dereferenceable(1) %p) {
+ ret ptr %p
+}
+
+define noundef dereferenceable_or_null(1) ptr @identity_dereferenceable_or_null(ptr noundef dereferenceable_or_null(1) %p) {
+ ret ptr %p
+}
+
+define void @main() {
+ %range_valid = call i32 @add_with_range(i32 0)
+ %range_poison_input = call i32 @add_with_range(i32 poison)
+ %range_invalid_input = call i32 @add_with_range(i32 3)
+ %range_invalid_output = call i32 @add_with_range(i32 1)
+ %range_vec = call <4 x i32> @add_with_range_vec(<4 x i32> <i32 0, i32 poison, i32 3, i32 1>)
+ %range_intrinsic_valid = call i32 @llvm.ctpop.i32(i32 range(i32 1, 255) 15)
+ %range_intrinsic_invalid_input = call i32 @llvm.ctpop.i32(i32 range(i32 1, 255) 1500)
+ %range_intrinsic_invalid_output = call range(i32 1, 32) i32 @llvm.ctpop.i32(i32 0)
+ %range_intrinsic_vec = call range(i32 1, 32) <4 x i32> @llvm.ctpop.v4i32(<4 x i32> range(i32 1, 255) <i32 15, i32 1500, i32 0, i32 poison>)
+
+ %nofpclass_valid = call half @identity_nofpclass(half 1.0)
+ %nofpclass_poison_input = call half @identity_nofpclass(half poison)
+ %nofpclass_invalid_input = call half @identity_nofpclass(half 0xH7C00)
+ %nofpclass_invalid_output = call half @identity_nofpclass(half 0xH7E00)
+ %nofpclass_vec = call <4 x half> @identity_nofpclass_vec(<4 x half> <half 1.0, half poison, half 0xH7C00, half 0xH7E00>)
+ %nofpclass_callsite_invalid_input = call half @identity_nofpclass(half nofpclass(norm) 1.0)
+ %nofpclass_callsite_invalid_output = call nofpclass(norm) half @identity_nofpclass(half 1.0)
+ %nofpclass_agg = call {<2 x half>, <2 x half>} @identity_nofpclass_agg({<2 x half>, <2 x half>} {<2 x half> <half 1.0, half poison>, <2 x half> <half 0xH7C00, half 0xH7E00>})
+
+ %alloc = alloca i32
+ %ptr_one = getelementptr i8, ptr null, i32 1
+ %nonnull_valid = call ptr @gep_nonnull(ptr %alloc)
+ %nonnull_invalid_input = call ptr @gep_nonnull(ptr null)
+ %nonnull_invalid_output = call ptr @gep_nonnull(ptr %ptr_one)
+ %nonnull_callsite_valid = call nonnull ptr @gep(ptr nonnull %alloc)
+ %nonnull_callsite_invalid_input = call ptr @gep(ptr nonnull null)
+ %nonnull_callsite_invalid_output = call nonnull ptr @gep(ptr %ptr_one)
+
+ %align_valid = call ptr @gep_align(ptr %alloc)
+ %align_invalid_input = call ptr @gep_align(ptr %ptr_one)
+ %align_invalid_output = call ptr @gep_align(ptr null)
+ %ptr_vec_1 = insertelement <4 x ptr> poison, ptr %alloc, i32 0
+ %ptr_vec_2 = insertelement <4 x ptr> %ptr_vec_1, ptr %ptr_one, i32 1
+ %ptr_vec_3 = insertelement <4 x ptr> %ptr_vec_2, ptr null, i32 2
+ %align_vec = call <4 x ptr> @gep_align_vec(<4 x ptr> %ptr_vec_3)
+ %align_valid_mixed = call align 1 ptr @gep_align(ptr align 4 %alloc)
+ %align_invalid_mixed1 = call ptr @gep_align(ptr align 1024 %alloc)
+ %align_invalid_mixed2 = call align 1024 ptr @gep_align(ptr %alloc)
+
+ %noundef_valid = call noundef i32 @identity_noundef(i32 noundef 1)
+ %noundef_valid_agg = call noundef {i32, <2 x i32>, [2 x i32]} @identity_noundef_agg({i32, <2 x i32>, [2 x i32]} noundef zeroinitializer)
+
+ %deref_valid = call ptr @identity_dereferenceable(ptr %alloc)
+ %deref_valid_mixed = call dereferenceable(1) ptr @identity_dereferenceable(ptr dereferenceable(1) %alloc)
+ %gep = getelementptr i8, ptr %alloc, i32 3
+ %deref_valid_middle = call ptr @identity_dereferenceable_single_byte(ptr %gep)
+ %deref_or_null_valid1 = call ptr @identity_dereferenceable_or_null(ptr %alloc)
+ %deref_or_null_valid2 = call ptr @identity_dereferenceable_or_null(ptr null)
+ %deref_or_null_mixed = call dereferenceable_or_null(1) dereferenceable(1) ptr @identity_dereferenceable_or_null(ptr dereferenceable_or_null(1) dereferenceable(1) %alloc)
+ ret void
+}
diff --git a/llvm/tools/llubi/lib/Interpreter.cpp b/llvm/tools/llubi/lib/Interpreter.cpp
index 43e87594a4126..5b88c2422875d 100644
--- a/llvm/tools/llubi/lib/Interpreter.cpp
+++ b/llvm/tools/llubi/lib/Interpreter.cpp
@@ -101,8 +101,10 @@ static void applyNonNullAttr(AnyValue &V) {
}
static void applyAlignAttr(AnyValue &V, Align Alignment) {
- if (V.isPointer() && V.asPointer().address().countr_zero() < Log2(Alignment))
- V = AnyValue::poison();
+ forEachScalarValue(V, [Alignment](AnyValue &Scalar) {
+ if (Scalar.isPointer() && Scalar.asPointer().address().countr_zero() < Log2(Alignment))
+ Scalar = AnyValue::poison();
+ });
}
static bool applyNoUndefAttr(AnyValue &V) {
@@ -1091,6 +1093,8 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
if (AttrsAtCallSite.hasAttribute(Attribute::NonNull) ||
AttrsAtCallee.hasAttribute(Attribute::NonNull))
applyNonNullAttr(V);
+ }
+ if (Ty->isPtrOrPtrVectorTy()) {
if (MaybeAlign Align = AttrsAtCallSite.getAlignment())
applyAlignAttr(V, *Align);
if (MaybeAlign Align = AttrsAtCallee.getAlignment())
@@ -1139,6 +1143,7 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
if (Ty->isPointerTy()) {
if (I.hasMetadata(LLVMContext::MD_nonnull))
applyNonNullAttr(V);
+ // Unlike align attributes, !align is only defined for pointer types.
if (const MDNode *Alignment = I.getMetadata(LLVMContext::MD_align))
applyAlignAttr(V, Align(ExtractFirstIntOperand(Alignment)));
}
>From 89f7dfd07ff6835c8ebfcf1dc5f1bd24838ef8e6 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Sun, 3 May 2026 00:38:54 +0800
Subject: [PATCH 4/4] [llubi] Update tests.
---
llvm/test/tools/llubi/attributes.ll | 216 ++++++++++++++++++++++++++-
llvm/tools/llubi/lib/Interpreter.cpp | 6 +-
2 files changed, 217 insertions(+), 5 deletions(-)
diff --git a/llvm/test/tools/llubi/attributes.ll b/llvm/test/tools/llubi/attributes.ll
index ffa7fd505476e..af593c51d7c96 100644
--- a/llvm/test/tools/llubi/attributes.ll
+++ b/llvm/test/tools/llubi/attributes.ll
@@ -1,3 +1,4 @@
+; NOTE: Assertions have been autogenerated by utils/update_llubi_test_checks.py UTC_ARGS: --version 6
; RUN: llubi --verbose < %s 2>&1 | FileCheck %s
define range(i32 0, 2) i32 @add_with_range(i32 range(i32 0, 2) %x) {
@@ -62,6 +63,8 @@ define noundef dereferenceable_or_null(1) ptr @identity_dereferenceable_or_null(
ret ptr %p
}
+declare i32 @printf(ptr, ...)
+
define void @main() {
%range_valid = call i32 @add_with_range(i32 0)
%range_poison_input = call i32 @add_with_range(i32 poison)
@@ -72,7 +75,7 @@ define void @main() {
%range_intrinsic_invalid_input = call i32 @llvm.ctpop.i32(i32 range(i32 1, 255) 1500)
%range_intrinsic_invalid_output = call range(i32 1, 32) i32 @llvm.ctpop.i32(i32 0)
%range_intrinsic_vec = call range(i32 1, 32) <4 x i32> @llvm.ctpop.v4i32(<4 x i32> range(i32 1, 255) <i32 15, i32 1500, i32 0, i32 poison>)
-
+
%nofpclass_valid = call half @identity_nofpclass(half 1.0)
%nofpclass_poison_input = call half @identity_nofpclass(half poison)
%nofpclass_invalid_input = call half @identity_nofpclass(half 0xH7C00)
@@ -104,7 +107,7 @@ define void @main() {
%noundef_valid = call noundef i32 @identity_noundef(i32 noundef 1)
%noundef_valid_agg = call noundef {i32, <2 x i32>, [2 x i32]} @identity_noundef_agg({i32, <2 x i32>, [2 x i32]} noundef zeroinitializer)
-
+
%deref_valid = call ptr @identity_dereferenceable(ptr %alloc)
%deref_valid_mixed = call dereferenceable(1) ptr @identity_dereferenceable(ptr dereferenceable(1) %alloc)
%gep = getelementptr i8, ptr %alloc, i32 3
@@ -112,5 +115,214 @@ define void @main() {
%deref_or_null_valid1 = call ptr @identity_dereferenceable_or_null(ptr %alloc)
%deref_or_null_valid2 = call ptr @identity_dereferenceable_or_null(ptr null)
%deref_or_null_mixed = call dereferenceable_or_null(1) dereferenceable(1) ptr @identity_dereferenceable_or_null(ptr dereferenceable_or_null(1) dereferenceable(1) %alloc)
+
+ %fmt_n_out = alloca [6 x i8]
+ store [6 x i8] c"N=%d\0A\00", ptr %fmt_n_out
+ %res = call range(i32 0, 15) noundef i32 (ptr, ...) @printf(ptr noundef nonnull %fmt_n_out, i32 noundef range(i32 0, 15) 6)
ret void
}
+; CHECK: Entering function: main
+; CHECK-NEXT: Entering function: add_with_range
+; CHECK-NEXT: i32 %x = i32 0
+; CHECK-NEXT: %add = add i32 %x, 1 => i32 1
+; CHECK-NEXT: ret i32 %add
+; CHECK-NEXT: Exiting function: add_with_range
+; CHECK-NEXT: %range_valid = call i32 @add_with_range(i32 0) => i32 1
+; CHECK-NEXT: Entering function: add_with_range
+; CHECK-NEXT: i32 %x = poison
+; CHECK-NEXT: %add = add i32 %x, 1 => poison
+; CHECK-NEXT: ret i32 %add
+; CHECK-NEXT: Exiting function: add_with_range
+; CHECK-NEXT: %range_poison_input = call i32 @add_with_range(i32 poison) => poison
+; CHECK-NEXT: Entering function: add_with_range
+; CHECK-NEXT: i32 %x = poison
+; CHECK-NEXT: %add = add i32 %x, 1 => poison
+; CHECK-NEXT: ret i32 %add
+; CHECK-NEXT: Exiting function: add_with_range
+; CHECK-NEXT: %range_invalid_input = call i32 @add_with_range(i32 3) => poison
+; CHECK-NEXT: Entering function: add_with_range
+; CHECK-NEXT: i32 %x = i32 1
+; CHECK-NEXT: %add = add i32 %x, 1 => i32 2
+; CHECK-NEXT: ret i32 %add
+; CHECK-NEXT: Exiting function: add_with_range
+; CHECK-NEXT: %range_invalid_output = call i32 @add_with_range(i32 1) => poison
+; CHECK-NEXT: Entering function: add_with_range_vec
+; CHECK-NEXT: <4 x i32> %x = { i32 0, poison, poison, i32 1 }
+; CHECK-NEXT: %add = add <4 x i32> %x, splat (i32 1) => { i32 1, poison, poison, i32 2 }
+; CHECK-NEXT: ret <4 x i32> %add
+; CHECK-NEXT: Exiting function: add_with_range_vec
+; CHECK-NEXT: %range_vec = call <4 x i32> @add_with_range_vec(<4 x i32> <i32 0, i32 poison, i32 3, i32 1>) => { i32 1, poison, poison, poison }
+; CHECK-NEXT: %range_intrinsic_valid = call i32 @llvm.ctpop.i32(i32 range(i32 1, 255) 15) => i32 4
+; CHECK-NEXT: %range_intrinsic_invalid_input = call i32 @llvm.ctpop.i32(i32 range(i32 1, 255) 1500) => i32 7
+; CHECK-NEXT: %range_intrinsic_invalid_output = call range(i32 1, 32) i32 @llvm.ctpop.i32(i32 0) => poison
+; CHECK-NEXT: %range_intrinsic_vec = call range(i32 1, 32) <4 x i32> @llvm.ctpop.v4i32(<4 x i32> range(i32 1, 255) <i32 15, i32 1500, i32 0, i32 poison>) => { i32 4, i32 7, poison, poison }
+; CHECK-NEXT: Entering function: identity_nofpclass
+; CHECK-NEXT: half %x = half 1.000000e+00
+; CHECK-NEXT: ret half %x
+; CHECK-NEXT: Exiting function: identity_nofpclass
+; CHECK-NEXT: %nofpclass_valid = call half @identity_nofpclass(half 0xH3C00) => half 1.000000e+00
+; CHECK-NEXT: Entering function: identity_nofpclass
+; CHECK-NEXT: half %x = poison
+; CHECK-NEXT: ret half %x
+; CHECK-NEXT: Exiting function: identity_nofpclass
+; CHECK-NEXT: %nofpclass_poison_input = call half @identity_nofpclass(half poison) => poison
+; CHECK-NEXT: Entering function: identity_nofpclass
+; CHECK-NEXT: half %x = poison
+; CHECK-NEXT: ret half %x
+; CHECK-NEXT: Exiting function: identity_nofpclass
+; CHECK-NEXT: %nofpclass_invalid_input = call half @identity_nofpclass(half 0xH7C00) => poison
+; CHECK-NEXT: Entering function: identity_nofpclass
+; CHECK-NEXT: half %x = half NaN
+; CHECK-NEXT: ret half %x
+; CHECK-NEXT: Exiting function: identity_nofpclass
+; CHECK-NEXT: %nofpclass_invalid_output = call half @identity_nofpclass(half 0xH7E00) => poison
+; CHECK-NEXT: Entering function: identity_nofpclass_vec
+; CHECK-NEXT: <4 x half> %x = { half 1.000000e+00, poison, poison, half NaN }
+; CHECK-NEXT: ret <4 x half> %x
+; CHECK-NEXT: Exiting function: identity_nofpclass_vec
+; CHECK-NEXT: %nofpclass_vec = call <4 x half> @identity_nofpclass_vec(<4 x half> <half 0xH3C00, half poison, half 0xH7C00, half 0xH7E00>) => { half 1.000000e+00, poison, poison, poison }
+; CHECK-NEXT: Entering function: identity_nofpclass
+; CHECK-NEXT: half %x = poison
+; CHECK-NEXT: ret half %x
+; CHECK-NEXT: Exiting function: identity_nofpclass
+; CHECK-NEXT: %nofpclass_callsite_invalid_input = call half @identity_nofpclass(half nofpclass(norm) 0xH3C00) => poison
+; CHECK-NEXT: Entering function: identity_nofpclass
+; CHECK-NEXT: half %x = half 1.000000e+00
+; CHECK-NEXT: ret half %x
+; CHECK-NEXT: Exiting function: identity_nofpclass
+; CHECK-NEXT: %nofpclass_callsite_invalid_output = call nofpclass(norm) half @identity_nofpclass(half 0xH3C00) => poison
+; CHECK-NEXT: Entering function: identity_nofpclass_agg
+; CHECK-NEXT: { <2 x half>, <2 x half> } %x = { { half 1.000000e+00, poison }, { poison, half NaN } }
+; CHECK-NEXT: ret { <2 x half>, <2 x half> } %x
+; CHECK-NEXT: Exiting function: identity_nofpclass_agg
+; CHECK-NEXT: %nofpclass_agg = call { <2 x half>, <2 x half> } @identity_nofpclass_agg({ <2 x half>, <2 x half> } { <2 x half> <half 0xH3C00, half poison>, <2 x half> <half 0xH7C00, half 0xH7E00> }) => { { half 1.000000e+00, poison }, { poison, poison } }
+; CHECK-NEXT: %alloc = alloca i32, align 4 => ptr 0x8 [alloc]
+; CHECK-NEXT: %ptr_one = getelementptr i8, ptr null, i32 1 => ptr 0x1 [dangling]
+; CHECK-NEXT: Entering function: gep_nonnull
+; CHECK-NEXT: ptr %p = ptr 0x8 [alloc]
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 -1 => ptr 0x7 [alloc + -1]
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep_nonnull
+; CHECK-NEXT: %nonnull_valid = call ptr @gep_nonnull(ptr %alloc) => ptr 0x7 [alloc + -1]
+; CHECK-NEXT: Entering function: gep_nonnull
+; CHECK-NEXT: ptr %p = poison
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 -1 => poison
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep_nonnull
+; CHECK-NEXT: %nonnull_invalid_input = call ptr @gep_nonnull(ptr null) => poison
+; CHECK-NEXT: Entering function: gep_nonnull
+; CHECK-NEXT: ptr %p = ptr 0x1 [dangling]
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 -1 => ptr 0x0 [dangling]
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep_nonnull
+; CHECK-NEXT: %nonnull_invalid_output = call ptr @gep_nonnull(ptr %ptr_one) => poison
+; CHECK-NEXT: Entering function: gep
+; CHECK-NEXT: ptr %p = ptr 0x8 [alloc]
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 -1 => ptr 0x7 [alloc + -1]
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep
+; CHECK-NEXT: %nonnull_callsite_valid = call nonnull ptr @gep(ptr nonnull %alloc) => ptr 0x7 [alloc + -1]
+; CHECK-NEXT: Entering function: gep
+; CHECK-NEXT: ptr %p = poison
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 -1 => poison
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep
+; CHECK-NEXT: %nonnull_callsite_invalid_input = call ptr @gep(ptr nonnull null) => poison
+; CHECK-NEXT: Entering function: gep
+; CHECK-NEXT: ptr %p = ptr 0x1 [dangling]
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 -1 => ptr 0x0 [dangling]
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep
+; CHECK-NEXT: %nonnull_callsite_invalid_output = call nonnull ptr @gep(ptr %ptr_one) => poison
+; CHECK-NEXT: Entering function: gep_align
+; CHECK-NEXT: ptr %p = ptr 0x8 [alloc]
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 8 => ptr 0x10 [alloc + 8]
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep_align
+; CHECK-NEXT: %align_valid = call ptr @gep_align(ptr %alloc) => ptr 0x10 [alloc + 8]
+; CHECK-NEXT: Entering function: gep_align
+; CHECK-NEXT: ptr %p = poison
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 8 => poison
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep_align
+; CHECK-NEXT: %align_invalid_input = call ptr @gep_align(ptr %ptr_one) => poison
+; CHECK-NEXT: Entering function: gep_align
+; CHECK-NEXT: ptr %p = ptr 0x0 [dangling]
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 8 => ptr 0x8 [dangling]
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep_align
+; CHECK-NEXT: %align_invalid_output = call ptr @gep_align(ptr null) => poison
+; CHECK-NEXT: %ptr_vec_1 = insertelement <4 x ptr> poison, ptr %alloc, i32 0 => { ptr 0x8 [alloc], poison, poison, poison }
+; CHECK-NEXT: %ptr_vec_2 = insertelement <4 x ptr> %ptr_vec_1, ptr %ptr_one, i32 1 => { ptr 0x8 [alloc], ptr 0x1 [dangling], poison, poison }
+; CHECK-NEXT: %ptr_vec_3 = insertelement <4 x ptr> %ptr_vec_2, ptr null, i32 2 => { ptr 0x8 [alloc], ptr 0x1 [dangling], ptr 0x0 [dangling], poison }
+; CHECK-NEXT: Entering function: gep_align_vec
+; CHECK-NEXT: <4 x ptr> %p = { ptr 0x8 [alloc], poison, ptr 0x0 [dangling], poison }
+; CHECK-NEXT: %gep = getelementptr i8, <4 x ptr> %p, i32 8 => { ptr 0x10 [alloc + 8], poison, ptr 0x8 [dangling], poison }
+; CHECK-NEXT: ret <4 x ptr> %gep
+; CHECK-NEXT: Exiting function: gep_align_vec
+; CHECK-NEXT: %align_vec = call <4 x ptr> @gep_align_vec(<4 x ptr> %ptr_vec_3) => { ptr 0x10 [alloc + 8], poison, poison, poison }
+; CHECK-NEXT: Entering function: gep_align
+; CHECK-NEXT: ptr %p = ptr 0x8 [alloc]
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 8 => ptr 0x10 [alloc + 8]
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep_align
+; CHECK-NEXT: %align_valid_mixed = call align 1 ptr @gep_align(ptr align 4 %alloc) => ptr 0x10 [alloc + 8]
+; CHECK-NEXT: Entering function: gep_align
+; CHECK-NEXT: ptr %p = poison
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 8 => poison
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep_align
+; CHECK-NEXT: %align_invalid_mixed1 = call ptr @gep_align(ptr align 1024 %alloc) => poison
+; CHECK-NEXT: Entering function: gep_align
+; CHECK-NEXT: ptr %p = ptr 0x8 [alloc]
+; CHECK-NEXT: %gep = getelementptr i8, ptr %p, i32 8 => ptr 0x10 [alloc + 8]
+; CHECK-NEXT: ret ptr %gep
+; CHECK-NEXT: Exiting function: gep_align
+; CHECK-NEXT: %align_invalid_mixed2 = call align 1024 ptr @gep_align(ptr %alloc) => poison
+; CHECK-NEXT: Entering function: identity_noundef
+; CHECK-NEXT: i32 %x = i32 1
+; CHECK-NEXT: ret i32 %x
+; CHECK-NEXT: Exiting function: identity_noundef
+; CHECK-NEXT: %noundef_valid = call noundef i32 @identity_noundef(i32 noundef 1) => i32 1
+; CHECK-NEXT: Entering function: identity_noundef_agg
+; CHECK-NEXT: { i32, <2 x i32>, [2 x i32] } %x = { i32 0, { i32 0, i32 0 }, { i32 0, i32 0 } }
+; CHECK-NEXT: ret { i32, <2 x i32>, [2 x i32] } %x
+; CHECK-NEXT: Exiting function: identity_noundef_agg
+; CHECK-NEXT: %noundef_valid_agg = call noundef { i32, <2 x i32>, [2 x i32] } @identity_noundef_agg({ i32, <2 x i32>, [2 x i32] } noundef zeroinitializer) => { i32 0, { i32 0, i32 0 }, { i32 0, i32 0 } }
+; CHECK-NEXT: Entering function: identity_dereferenceable
+; CHECK-NEXT: ptr %p = ptr 0x8 [alloc]
+; CHECK-NEXT: ret ptr %p
+; CHECK-NEXT: Exiting function: identity_dereferenceable
+; CHECK-NEXT: %deref_valid = call ptr @identity_dereferenceable(ptr %alloc) => ptr 0x8 [alloc]
+; CHECK-NEXT: Entering function: identity_dereferenceable
+; CHECK-NEXT: ptr %p = ptr 0x8 [alloc]
+; CHECK-NEXT: ret ptr %p
+; CHECK-NEXT: Exiting function: identity_dereferenceable
+; CHECK-NEXT: %deref_valid_mixed = call dereferenceable(1) ptr @identity_dereferenceable(ptr dereferenceable(1) %alloc) => ptr 0x8 [alloc]
+; CHECK-NEXT: %gep = getelementptr i8, ptr %alloc, i32 3 => ptr 0xB [alloc + 3]
+; CHECK-NEXT: Entering function: identity_dereferenceable_single_byte
+; CHECK-NEXT: ptr %p = ptr 0xB [alloc + 3]
+; CHECK-NEXT: ret ptr %p
+; CHECK-NEXT: Exiting function: identity_dereferenceable_single_byte
+; CHECK-NEXT: %deref_valid_middle = call ptr @identity_dereferenceable_single_byte(ptr %gep) => ptr 0xB [alloc + 3]
+; CHECK-NEXT: Entering function: identity_dereferenceable_or_null
+; CHECK-NEXT: ptr %p = ptr 0x8 [alloc]
+; CHECK-NEXT: ret ptr %p
+; CHECK-NEXT: Exiting function: identity_dereferenceable_or_null
+; CHECK-NEXT: %deref_or_null_valid1 = call ptr @identity_dereferenceable_or_null(ptr %alloc) => ptr 0x8 [alloc]
+; CHECK-NEXT: Entering function: identity_dereferenceable_or_null
+; CHECK-NEXT: ptr %p = ptr 0x0 [dangling]
+; CHECK-NEXT: ret ptr %p
+; CHECK-NEXT: Exiting function: identity_dereferenceable_or_null
+; CHECK-NEXT: %deref_or_null_valid2 = call ptr @identity_dereferenceable_or_null(ptr null) => ptr 0x0 [dangling]
+; CHECK-NEXT: Entering function: identity_dereferenceable_or_null
+; CHECK-NEXT: ptr %p = ptr 0x8 [alloc]
+; CHECK-NEXT: ret ptr %p
+; CHECK-NEXT: Exiting function: identity_dereferenceable_or_null
+; CHECK-NEXT: %deref_or_null_mixed = call dereferenceable(1) dereferenceable_or_null(1) ptr @identity_dereferenceable_or_null(ptr dereferenceable(1) dereferenceable_or_null(1) %alloc) => ptr 0x8 [alloc]
+; CHECK-NEXT: %fmt_n_out = alloca [6 x i8], align 1 => ptr 0xC [fmt_n_out]
+; CHECK-NEXT: store [6 x i8] c"N=%d\0A\00", ptr %fmt_n_out, align 1
+; CHECK-NEXT: N=6
+; CHECK-NEXT: %res = call noundef range(i32 0, 15) i32 (ptr, ...) @printf(ptr noundef nonnull %fmt_n_out, i32 noundef range(i32 0, 15) 6) => i32 4
+; CHECK-NEXT: ret void
+; CHECK-NEXT: Exiting function: main
diff --git a/llvm/tools/llubi/lib/Interpreter.cpp b/llvm/tools/llubi/lib/Interpreter.cpp
index 5b88c2422875d..b939301f3bd90 100644
--- a/llvm/tools/llubi/lib/Interpreter.cpp
+++ b/llvm/tools/llubi/lib/Interpreter.cpp
@@ -72,9 +72,8 @@ static void forEachScalarValue(AnyValue &V,
return;
if (V.isAggregate()) {
- for (auto &SubValue : V.asAggregate()) {
+ for (auto &SubValue : V.asAggregate())
forEachScalarValue(SubValue, Visit);
- }
return;
}
@@ -102,7 +101,8 @@ static void applyNonNullAttr(AnyValue &V) {
static void applyAlignAttr(AnyValue &V, Align Alignment) {
forEachScalarValue(V, [Alignment](AnyValue &Scalar) {
- if (Scalar.isPointer() && Scalar.asPointer().address().countr_zero() < Log2(Alignment))
+ if (Scalar.isPointer() &&
+ Scalar.asPointer().address().countr_zero() < Log2(Alignment))
Scalar = AnyValue::poison();
});
}
More information about the llvm-commits
mailing list