[llvm] 23aeadb - [Inline] Fix incorrect noalias metadata application (PR48209)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 11:53:12 PST 2020


Author: Nikita Popov
Date: 2020-11-18T20:52:58+01:00
New Revision: 23aeadb89df38406dc4d929d08286f7ce31040eb

URL: https://github.com/llvm/llvm-project/commit/23aeadb89df38406dc4d929d08286f7ce31040eb
DIFF: https://github.com/llvm/llvm-project/commit/23aeadb89df38406dc4d929d08286f7ce31040eb.diff

LOG: [Inline] Fix incorrect noalias metadata application (PR48209)

The VMap also contains a mapping from Argument => Instruction,
where the instruction is part of the original function, not the
inlined one. The code was assuming that all the instructions in
the VMap were inlined.

This was a pre-existing problem for the loop access metadata, but
was extended to the more common noalias metadata by
27f647d117087ca11959e232e6443f4aee31e966, thus causing miscompiles.

There is a similar assumption inside CloneAliasScopeMetadata(), so
that one likely needs to be fixed as well.

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/InlineFunction.cpp
    llvm/test/Transforms/Inline/pr48209.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 05e692915f2b..c16433cc5289 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -785,7 +785,9 @@ static void PropagateCallSiteMetadata(CallBase &CB, ValueToValueMapTy &VMap) {
 
   for (ValueToValueMapTy::iterator VMI = VMap.begin(), VMIE = VMap.end();
        VMI != VMIE; ++VMI) {
-    if (!VMI->second)
+    // Check that key is an instruction, to skip the Argument mapping, which
+    // points to an instruction in the original function, not the inlined one.
+    if (!VMI->second || !isa<Instruction>(VMI->first))
       continue;
 
     Instruction *NI = dyn_cast<Instruction>(VMI->second);

diff  --git a/llvm/test/Transforms/Inline/pr48209.ll b/llvm/test/Transforms/Inline/pr48209.ll
index c36a1729182a..94d33bec4fce 100644
--- a/llvm/test/Transforms/Inline/pr48209.ll
+++ b/llvm/test/Transforms/Inline/pr48209.ll
@@ -11,7 +11,7 @@ define internal void @inlined_function(i8* %arg) {
 ; TODO: This is a miscompile.
 define void @test(i8** %p) {
 ; CHECK-LABEL: @test(
-; CHECK-NEXT:    [[ARG:%.*]] = load i8*, i8** [[P:%.*]], align 8, !alias.scope !0, !noalias !0
+; CHECK-NEXT:    [[ARG:%.*]] = load i8*, i8** [[P:%.*]], align 8, !alias.scope !0
 ; CHECK-NEXT:    call void @external_function(i8* [[ARG]]), !noalias !0
 ; CHECK-NEXT:    ret void
 ;


        


More information about the llvm-commits mailing list