[llvm] d91bb2f - [AsmParser] Check whether use is callee when determining function type
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 5 01:13:02 PST 2024
Author: Nikita Popov
Date: 2024-02-05T10:12:54+01:00
New Revision: d91bb2fcd35e6fc8fe325d5da035295e34b146ca
URL: https://github.com/llvm/llvm-project/commit/d91bb2fcd35e6fc8fe325d5da035295e34b146ca
DIFF: https://github.com/llvm/llvm-project/commit/d91bb2fcd35e6fc8fe325d5da035295e34b146ca.diff
LOG: [AsmParser] Check whether use is callee when determining function type
The code ended up treating a use in a call argument as if it were
a call. Make sure this is actually the callee use.
Added:
Modified:
llvm/lib/AsmParser/LLParser.cpp
llvm/test/Assembler/incomplete-ir-declarations.ll
Removed:
################################################################################
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index f35898569e269..d5d4428bfbf9a 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -306,9 +306,9 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
for (const auto &[Name, Info] : make_early_inc_range(ForwardRefVals)) {
auto GetCommonFunctionType = [](Value *V) -> FunctionType * {
FunctionType *FTy = nullptr;
- for (User *U : V->users()) {
- auto *CB = dyn_cast<CallBase>(U);
- if (!CB || (FTy && FTy != CB->getFunctionType()))
+ for (Use &U : V->uses()) {
+ auto *CB = dyn_cast<CallBase>(U.getUser());
+ if (!CB || !CB->isCallee(&U) || (FTy && FTy != CB->getFunctionType()))
return nullptr;
FTy = CB->getFunctionType();
}
diff --git a/llvm/test/Assembler/incomplete-ir-declarations.ll b/llvm/test/Assembler/incomplete-ir-declarations.ll
index 6cdff80883c27..11f5e5fe6458b 100644
--- a/llvm/test/Assembler/incomplete-ir-declarations.ll
+++ b/llvm/test/Assembler/incomplete-ir-declarations.ll
@@ -4,6 +4,7 @@
; CHECK: @g1 = external global i8
; CHECK: @g2 = external global i8
; CHECK: @g3 = external global i8
+; CHECK: @g4 = external global i8
; CHECK: declare void @fn1(i32)
@@ -12,9 +13,10 @@ define ptr @test() {
call void @fn1(i32 1)
call void @fn2(i32 2)
call void @fn2(i32 2, i32 3)
- load i32, ptr @g1
- store i32 0, ptr @g1
- load i32, ptr @g1
- load i64, ptr @g2
- ret ptr @g3
+ call void @fn2(ptr @g1)
+ load i32, ptr @g2
+ store i32 0, ptr @g2
+ load i32, ptr @g3
+ load i64, ptr @g3
+ ret ptr @g4
}
More information about the llvm-commits
mailing list