diff options
author | Kees Cook <kees@kernel.org> | 2025-03-12 09:50:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-12 09:50:50 -0700 |
commit | ea2e66aa8b6e363b89df66dc44275a0d7ecd70ce (patch) | |
tree | 6164c6009a050fa650451f12904d512c3dab7fcc /llvm/lib/IR/Constants.cpp | |
parent | dd181af9506d515186ce510ce2f0e5dc291563f6 (diff) | |
download | llvm-ea2e66aa8b6e363b89df66dc44275a0d7ecd70ce.zip llvm-ea2e66aa8b6e363b89df66dc44275a0d7ecd70ce.tar.gz llvm-ea2e66aa8b6e363b89df66dc44275a0d7ecd70ce.tar.bz2 |
[LLVM][ConstantFold] Undefined values are not constant (#130713)
llvm.is.constant (and therefore Clang's __builtin_constant_p()) need to
report undefined values as non-constant or future DCE choices end up
making no sense. This was encountered while building the Linux kernel
which uses __builtin_constant_p() while trying to evaluate if it is safe
to use a compile-time constant resolution for string lengths or if it
must kick over to a full runtime call to strlen(). Obviously an
undefined variable cannot be known at compile-time, so
__builtin_constant_p() needs to return false. This change will also mean
that Clang will match GCC's behavior under the same conditions.
Fixes #130649
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 9e3e739..36f4136 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -841,6 +841,8 @@ Constant *Constant::mergeUndefsWith(Constant *C, Constant *Other) { } bool Constant::isManifestConstant() const { + if (isa<UndefValue>(this)) + return false; if (isa<ConstantData>(this)) return true; if (isa<ConstantAggregate>(this) || isa<ConstantExpr>(this)) { |