aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib
diff options
context:
space:
mode:
authoryonghong-song <yhs@fb.com>2025-03-11 11:23:53 -0700
committerGitHub <noreply@github.com>2025-03-11 11:23:53 -0700
commit5686786c550c6da6d1169b9bffc31cece1161902 (patch)
treedcd170f5a27498749ebbd910fb7939469ce7ee88 /llvm/lib
parent313e2ef93eb2cb257e643c87916df8471ff01fd8 (diff)
downloadllvm-5686786c550c6da6d1169b9bffc31cece1161902.zip
llvm-5686786c550c6da6d1169b9bffc31cece1161902.tar.gz
llvm-5686786c550c6da6d1169b9bffc31cece1161902.tar.bz2
[BPF] Fix BitCast Assertion with NonZero AddrSpace (#130722)
Alexei reported a bpf selftest failure with recent llvm for bpf prog file progs/arena_spin_lock.c. The failure only happens when clang is built with cmake option LLVM_ENABLE_ASSERTIONS=ON. The error message looks like: ``` clang: /home/yhs/work/yhs/llvm-project/llvm/lib/IR/Instructions.cpp:3460: llvm::BitCastInst::BitCastInst(Value *, Type *, const Twine &, InsertPosition): Assertion `castIsValid(getOpcode(), S, Ty) && "Illegal BitCast"' failed. ``` Further investigation shows that the problem is triggered in BPF/BPFAbstractMemberAccess.cpp for code ``` auto *BCInst = new BitCastInst(Base, PointerType::getUnqual(BB->getContext())); ``` For the above BitCastInst, Since 'Base' has non-zero AddrSapce, the compiler expects the type also has the same AddrSpace. But the above PointerType::getUnqual(...) does not have AddrSpace and hence causes the assertion failure. Providing the proper AddrSpace for the BitCast type fixed the issue. Co-authored-by: Yonghong Song <yonghong.song@linux.dev>
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
index 646d577..77ed246 100644
--- a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
+++ b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp
@@ -1113,8 +1113,9 @@ bool BPFAbstractMemberAccess::transformGEPChain(CallInst *Call,
Call->getIterator());
// Generate a BitCast
- auto *BCInst =
- new BitCastInst(Base, PointerType::getUnqual(BB->getContext()));
+ auto *BCInst = new BitCastInst(
+ Base, PointerType::get(BB->getContext(),
+ Base->getType()->getPointerAddressSpace()));
BCInst->insertBefore(Call->getIterator());
// Generate a GetElementPtr