================ @@ -0,0 +1,105 @@ +; Test that BasicAA conservatively returns MayAlias for local allocas in +; functions containing returns_twice calls (e.g. setjmp/sigsetjmp), to prevent +; miscompilation via longjmp re-entry paths invisible in the forward CFG. +; +; Reproduces: https://github.com/llvm/llvm-project/issues/198967 +; +; Without the fix, GVN incorrectly concludes that the store through %p_val +; (which may alias %i via a longjmp re-entry) cannot modify %i, then DSE +; eliminates the "store i32 13, ptr %i" as dead. The fix makes +; EarliestEscapeAnalysis conservatively bail out at the point where +; isNotCapturedBefore would otherwise return true, if the function contains +; any returns_twice call. + +; RUN: opt < %s -aa-pipeline=basic-aa -passes=gvn,dse -S | FileCheck %s + +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@x = external global i32 +@ii = external global i32 +@p = external global ptr + +declare void @redo() +declare void @checkpoint() #0 + +; Control case: function has the same CFG structure but calls no +; returns_twice function. GVN/DSE can legally eliminate "store i32 13, ptr %i" +; because in the forward CFG the only path to if.else does not pass through +; if.then (where &i is stored to @p). BasicAA correctly returns NoAlias for +; (%i, %p_val) here. +; +; Fix case CHECK directives are listed here so that CHECK-NOT is correctly +; scoped between the two CHECK-LABELs: it checks that the store is absent in +; bar_no_returns_twice and present in bar_with_returns_twice. +; +; CHECK-LABEL: define void @bar_no_returns_twice( +; CHECK-NOT: store i32 13, ptr %i +; CHECK-LABEL: define void @bar_with_returns_twice( +; CHECK: store i32 13, ptr %i +define void @bar_no_returns_twice() { +entry: + %i = alloca i32, align 4 + %x_val = load i32, ptr @x + %cond = icmp ne i32 %x_val, 0 + br i1 %cond, label %if.then, label %if.else + +if.then: + store ptr %i, ptr @p + call void @redo() + br label %if.end + +if.else: + ; Bug: without the fix, GVN sees "store i32 42, ptr %p_val" as + ; NoAlias with %i (the capture in if.then is not visible in the forward + ; CFG), so it forwards 13 through the load and DSE removes this store. ---------------- antoniofrighetto wrote:
Please drop this comment (not a bug if no returns-twice call?). https://github.com/llvm/llvm-project/pull/212297 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
