Skip to content

Conversation

@ahmedbougacha
Copy link
Member

@ahmedbougacha ahmedbougacha commented Jun 7, 2024

When we encounter two consecutive ptrauth intrinsics, we can already combine the inner matching sign + auth pair, e.g.:

  resign(sign(p,ks,ds),ks,ds,kr,dr) -> sign(p,kr,dr)

We can generalize that to ptrauth constants, which are effectively constant equivalents to ptrauth.sign, i.e.:

  resign(ptrauth(p,ks,ds),ks,ds,kr,dr) -> ptrauth(p,kr,dr)
  auth(ptrauth(p,k,d),k,d) -> p

While there, cleanup a redundant return after eraseInstFromFunction in the shared (intrinsic|constant)->intrinsic folding code.

When we encounter two consecutive ptrauth intrinsics, we can
already combine the inner matching sign + auth pair, e.g.:
  resign(sign(p,ks,ds),ks,ds,kr,dr) -> sign(p,kr,dr)

We can generalize that to ptrauth constants, which are effectively
constant equivalents to ptrauth.sign, i.e.:
  resign(ptrauth(p,ks,ds),ks,ds,kr,dr) -> ptrauth(p,kr,dr)
  auth(ptrauth(p,k,d),k,d) -> p

While there cleanup a redundant return after eraseInstFromFunction
in the shared (intrinsic|constant)->intrinsic folding code.
@ahmedbougacha ahmedbougacha force-pushed the users/ahmedbougacha/ptrauth-instcombine-constant-intrin branch from 02a5496 to 9dfe010 Compare June 11, 2024 23:54
@ahmedbougacha ahmedbougacha marked this pull request as ready for review June 12, 2024 00:03
@ahmedbougacha ahmedbougacha requested a review from nikic as a code owner June 12, 2024 00:03
@ahmedbougacha ahmedbougacha requested review from asl and kovdan01 June 12, 2024 00:04
@llvmbot
Copy link
Member

llvmbot commented Jun 12, 2024

@llvm/pr-subscribers-backend-aarch64

@llvm/pr-subscribers-llvm-transforms

Author: Ahmed Bougacha (ahmedbougacha)

Changes

When we encounter two consecutive ptrauth intrinsics, we can already combine the inner matching sign + auth pair, e.g.:

  resign(sign(p,ks,ds),ks,ds,kr,dr) -> sign(p,kr,dr)

We can generalize that to ptrauth constants, which are effectively constant equivalents to ptrauth.sign, i.e.:

  resign(ptrauth(p,ks,ds),ks,ds,kr,dr) -> ptrauth(p,kr,dr)
  auth(ptrauth(p,k,d),k,d) -> p

While there, cleanup a redundant return after eraseInstFromFunction in the shared (intrinsic|constant)->intrinsic folding code.


Full diff: https://github.com/llvm/llvm-project/pull/94705.diff

2 Files Affected:

  • (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+24-3)
  • (modified) llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll (+73)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 436cdbff75669..310514bea3ec1 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2643,13 +2643,14 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     // (sign|resign) + (auth|resign) can be folded by omitting the middle
     // sign+auth component if the key and discriminator match.
     bool NeedSign = II->getIntrinsicID() == Intrinsic::ptrauth_resign;
+    Value *Ptr = II->getArgOperand(0);
     Value *Key = II->getArgOperand(1);
     Value *Disc = II->getArgOperand(2);
 
     // AuthKey will be the key we need to end up authenticating against in
     // whatever we replace this sequence with.
     Value *AuthKey = nullptr, *AuthDisc = nullptr, *BasePtr;
-    if (auto CI = dyn_cast<CallBase>(II->getArgOperand(0))) {
+    if (auto *CI = dyn_cast<CallBase>(Ptr)) {
       BasePtr = CI->getArgOperand(0);
       if (CI->getIntrinsicID() == Intrinsic::ptrauth_sign) {
         if (CI->getArgOperand(1) != Key || CI->getArgOperand(2) != Disc)
@@ -2661,6 +2662,27 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
         AuthDisc = CI->getArgOperand(2);
       } else
         break;
+    } else if (auto *PtrToInt = dyn_cast<PtrToIntOperator>(Ptr)) {
+      // ptrauth constants are equivalent to a call to @llvm.ptrauth.sign for
+      // our purposes, so check for that too.
+      auto *CPA = dyn_cast<ConstantPtrAuth>(PtrToInt->getOperand(0));
+      if (!CPA || !CPA->isKnownCompatibleWith(Key, Disc, DL))
+        break;
+
+      // resign(ptrauth(p,ks,ds),ks,ds,kr,dr) -> ptrauth(p,kr,dr)
+      if (NeedSign && isa<ConstantInt>(II->getArgOperand(4))) {
+        auto *SignKey = cast<ConstantInt>(II->getArgOperand(3));
+        auto *SignDisc = cast<ConstantInt>(II->getArgOperand(4));
+        auto *SignAddrDisc = ConstantPointerNull::get(Builder.getPtrTy());
+        auto *NewCPA = ConstantPtrAuth::get(CPA->getPointer(), SignKey,
+                                            SignDisc, SignAddrDisc);
+        replaceInstUsesWith(
+            *II, ConstantExpr::getPointerCast(NewCPA, II->getType()));
+        return eraseInstFromFunction(*II);
+      }
+
+      // auth(ptrauth(p,k,d),k,d) -> p
+      BasePtr = Builder.CreatePtrToInt(CPA->getPointer(), II->getType());
     } else
       break;
 
@@ -2677,8 +2699,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     } else {
       // sign(0) + auth(0) = nop
       replaceInstUsesWith(*II, BasePtr);
-      eraseInstFromFunction(*II);
-      return nullptr;
+      return eraseInstFromFunction(*II);
     }
 
     SmallVector<Value *, 4> CallArgs;
diff --git a/llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll b/llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll
index da0f724abfde4..3e894739f4e34 100644
--- a/llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll
+++ b/llvm/test/Transforms/InstCombine/ptrauth-intrinsics.ll
@@ -12,6 +12,26 @@ define i64 @test_ptrauth_nop(ptr %p) {
   ret i64 %authed
 }
 
+declare void @foo()
+
+define i64 @test_ptrauth_nop_constant() {
+; CHECK-LABEL: @test_ptrauth_nop_constant(
+; CHECK-NEXT:    ret i64 ptrtoint (ptr @foo to i64)
+;
+  %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 1234)
+  ret i64 %authed
+}
+
+define i64 @test_ptrauth_nop_constant_addrdisc() {
+; CHECK-LABEL: @test_ptrauth_nop_constant_addrdisc(
+; CHECK-NEXT:    ret i64 ptrtoint (ptr @foo to i64)
+;
+  %addr = ptrtoint void()* @foo to i64
+  %blended = call i64 @llvm.ptrauth.blend(i64 %addr, i64 1234)
+  %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 %blended)
+  ret i64 %authed
+}
+
 define i64 @test_ptrauth_nop_mismatch(ptr %p) {
 ; CHECK-LABEL: @test_ptrauth_nop_mismatch(
 ; CHECK-NEXT:    [[TMP0:%.*]] = ptrtoint ptr [[P:%.*]] to i64
@@ -87,6 +107,59 @@ define i64 @test_ptrauth_resign_auth_mismatch(ptr %p) {
   ret i64 %authed
 }
 
+define i64 @test_ptrauth_nop_constant_mismatch() {
+; CHECK-LABEL: @test_ptrauth_nop_constant_mismatch(
+; CHECK-NEXT:    [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 12)
+; CHECK-NEXT:    ret i64 [[AUTHED]]
+;
+  %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 12)
+  ret i64 %authed
+}
+
+define i64 @test_ptrauth_nop_constant_mismatch_key() {
+; CHECK-LABEL: @test_ptrauth_nop_constant_mismatch_key(
+; CHECK-NEXT:    [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234) to i64), i32 0, i64 1234)
+; CHECK-NEXT:    ret i64 [[AUTHED]]
+;
+  %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 0, i64 1234)
+  ret i64 %authed
+}
+
+define i64 @test_ptrauth_nop_constant_addrdisc_mismatch() {
+; CHECK-LABEL: @test_ptrauth_nop_constant_addrdisc_mismatch(
+; CHECK-NEXT:    [[BLENDED:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @foo to i64), i64 12)
+; CHECK-NEXT:    [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 [[BLENDED]])
+; CHECK-NEXT:    ret i64 [[AUTHED]]
+;
+  %addr = ptrtoint ptr @foo to i64
+  %blended = call i64 @llvm.ptrauth.blend(i64 %addr, i64 12)
+  %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 %blended)
+  ret i64 %authed
+}
+
+define i64 @test_ptrauth_nop_constant_addrdisc_mismatch2() {
+; CHECK-LABEL: @test_ptrauth_nop_constant_addrdisc_mismatch2(
+; CHECK-NEXT:    [[BLENDED:%.*]] = call i64 @llvm.ptrauth.blend(i64 ptrtoint (ptr @test_ptrauth_nop to i64), i64 1234)
+; CHECK-NEXT:    [[AUTHED:%.*]] = call i64 @llvm.ptrauth.auth(i64 ptrtoint (ptr ptrauth (ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 [[BLENDED]])
+; CHECK-NEXT:    ret i64 [[AUTHED]]
+;
+  %addr = ptrtoint ptr @test_ptrauth_nop to i64
+  %blended = call i64 @llvm.ptrauth.blend(i64 %addr, i64 1234)
+  %authed = call i64 @llvm.ptrauth.auth(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234, ptr @foo) to i64), i32 1, i64 %blended)
+  ret i64 %authed
+}
+
+define i64 @test_ptrauth_resign_ptrauth_constant(ptr %p) {
+; CHECK-LABEL: @test_ptrauth_resign_ptrauth_constant(
+; CHECK-NEXT:    ret i64 ptrtoint (ptr ptrauth (ptr @foo, i32 0, i64 42) to i64)
+;
+
+  %tmp0 = ptrtoint ptr %p to i64
+  %authed = call i64 @llvm.ptrauth.resign(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 1234, i32 0, i64 42)
+  ret i64 %authed
+}
+
 declare i64 @llvm.ptrauth.auth(i64, i32, i64)
 declare i64 @llvm.ptrauth.sign(i64, i32, i64)
 declare i64 @llvm.ptrauth.resign(i64, i32, i64, i32, i64)
+declare i64 @llvm.ptrauth.blend(i64, i64)

auto *NewCPA = ConstantPtrAuth::get(CPA->getPointer(), SignKey,
SignDisc, SignAddrDisc);
replaceInstUsesWith(
*II, ConstantExpr::getPointerCast(NewCPA, II->getType()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this getPointerCast() needed? If so, I think it's missing test coverage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh I thought this was another remnant of typed pointers, but this one is indeed needed, to reconcile the i64-centric ptrauth intrinsics with ptrs in ptr contexts elsewhere, i.e. the ptrtoint in:

; CHECK-NEXT:    ret i64 ptrtoint (ptr ptrauth (ptr @foo, i32 0, i64 42) to i64)

  %tmp0 = ptrtoint ptr %p to i64
  %authed = call i64 @llvm.ptrauth.resign(i64 ptrtoint(ptr ptrauth(ptr @foo, i32 1, i64 1234) to i64), i32 1, i64 1234, i32 0, i64 42)
  ret i64 %authed

Copy link
Contributor

@kovdan01 kovdan01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor nits - the changes look reasonable, so I'm happy with them if no other objections are covered by reviewers.

- don't reuse fn in test
- const
@ahmedbougacha ahmedbougacha merged commit 34e5a71 into llvm:main Jun 27, 2024
@ahmedbougacha ahmedbougacha deleted the users/ahmedbougacha/ptrauth-instcombine-constant-intrin branch June 27, 2024 01:54
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 27, 2024

LLVM Buildbot has detected a new failure on builder sanitizer-x86_64-linux running on sanitizer-buildbot2 while building llvm at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/66/builds/644

Here is the relevant piece of the build log for the reference:

Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure)
...
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/i386-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m32', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-Wthread-safety', '-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 9980 tests, 80 workers --
Testing: 
FAIL: libFuzzer-i386-static-libcxx-Linux :: fuzzer-leak.test (1 of 9980)
******************** TEST 'libFuzzer-i386-static-libcxx-Linux :: fuzzer-leak.test' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang    -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/LeakTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest
+ /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/LeakTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest
RUN: at line 4: /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang    -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/ThreadedLeakTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-ThreadedLeakTest
+ /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/ThreadedLeakTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-ThreadedLeakTest
RUN: at line 5: /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang    -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/LeakTimeoutTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTimeoutTest
+ /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/LeakTimeoutTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTimeoutTest
RUN: at line 7: rm -rf /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus && mkdir -p /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
+ rm -rf /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
+ mkdir -p /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
RUN: at line 8: not  /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=100000 -detect_leaks=1 /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test --check-prefix=LEAK_DURING
+ not /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=100000 -detect_leaks=1 /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test --check-prefix=LEAK_DURING
RUN: at line 17: /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=0 /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
+ /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=0 /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 2382369292
INFO: Loaded 1 modules   (4 inline 8-bit counters): 4 [0x567ad828, 0x567ad82c), 
INFO: Loaded 1 PC tables (4 PCs): 4 [0x567ad82c,0x567ad84c), 
INFO:        0 files found in /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
INFO: A corpus is not provided, starting from an empty corpus
#2	INITED cov: 2 ft: 2 corp: 1/1b exec/s: 0 rss: 33Mb
#2	DONE   cov: 2 ft: 2 corp: 1/1b lim: 4 exec/s: 0 rss: 33Mb
Done 2 runs in 0 second(s)
RUN: at line 19: not  /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=0 -detect_leaks=1 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test --check-prefix=LEAK_IN_CORPUS
+ not /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=0 -detect_leaks=1 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test --check-prefix=LEAK_IN_CORPUS
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test:21:17: error: LEAK_IN_CORPUS: expected string not found in input
LEAK_IN_CORPUS: INFO: a leak has been found in the initial corpus.
                ^
<stdin>:13:55: note: scanning from here
==2130184==ERROR: LeakSanitizer: detected memory leaks
                                                      ^
Step 9 (test compiler-rt gcc) failure: test compiler-rt gcc (failure)
...
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/i386-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m32', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-Wthread-safety', '-Wthread-safety-reference', '-Wthread-safety-beta', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/lit.common.cfg.py:60: warning: Path reported by clang does not exist: "/b/sanitizer-x86_64-linux/build/build_gcc/lib/clang/19/lib/x86_64-unknown-linux-gnu". This path was found by running ['/b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang', '--target=x86_64-unknown-linux-gnu', '-m64', '-print-runtime-dir'].
llvm-lit: /b/sanitizer-x86_64-linux/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds.
-- Testing: 9980 tests, 80 workers --
Testing: 
FAIL: libFuzzer-i386-static-libcxx-Linux :: fuzzer-leak.test (1 of 9980)
******************** TEST 'libFuzzer-i386-static-libcxx-Linux :: fuzzer-leak.test' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang    -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/LeakTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest
+ /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/LeakTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest
RUN: at line 4: /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang    -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/ThreadedLeakTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-ThreadedLeakTest
+ /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/ThreadedLeakTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-ThreadedLeakTest
RUN: at line 5: /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang    -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta   --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/LeakTimeoutTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTimeoutTest
+ /b/sanitizer-x86_64-linux/build/build_gcc/./bin/clang -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta --driver-mode=g++ -O2 -gline-tables-only -fsanitize=address,fuzzer -I/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/lib/fuzzer -m32 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/LeakTimeoutTest.cpp -o /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTimeoutTest
RUN: at line 7: rm -rf /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus && mkdir -p /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
+ rm -rf /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
+ mkdir -p /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
RUN: at line 8: not  /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=100000 -detect_leaks=1 /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test --check-prefix=LEAK_DURING
+ not /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=100000 -detect_leaks=1 /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test --check-prefix=LEAK_DURING
RUN: at line 17: /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=0 /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
+ /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=0 /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
INFO: Running with entropic power schedule (0xFF, 100).
INFO: Seed: 2382369292
INFO: Loaded 1 modules   (4 inline 8-bit counters): 4 [0x567ad828, 0x567ad82c), 
INFO: Loaded 1 PC tables (4 PCs): 4 [0x567ad82c,0x567ad84c), 
INFO:        0 files found in /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-corpus
INFO: -max_len is not provided; libFuzzer will not generate inputs larger than 4096 bytes
INFO: A corpus is not provided, starting from an empty corpus
#2	INITED cov: 2 ft: 2 corp: 1/1b exec/s: 0 rss: 33Mb
#2	DONE   cov: 2 ft: 2 corp: 1/1b lim: 4 exec/s: 0 rss: 33Mb
Done 2 runs in 0 second(s)
RUN: at line 19: not  /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=0 -detect_leaks=1 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer 2>&1 | FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test --check-prefix=LEAK_IN_CORPUS
+ not /b/sanitizer-x86_64-linux/build/build_gcc/runtimes/runtimes-bins/compiler-rt/test/fuzzer/I386StaticLibcxxLinuxConfig/Output/fuzzer-leak.test.tmp-LeakTest -runs=0 -detect_leaks=1 /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer
+ FileCheck /b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test --check-prefix=LEAK_IN_CORPUS
/b/sanitizer-x86_64-linux/build/llvm-project/compiler-rt/test/fuzzer/fuzzer-leak.test:21:17: error: LEAK_IN_CORPUS: expected string not found in input
LEAK_IN_CORPUS: INFO: a leak has been found in the initial corpus.
                ^
<stdin>:13:55: note: scanning from here
==2130184==ERROR: LeakSanitizer: detected memory leaks
                                                      ^

cpiaseque pushed a commit to cpiaseque/llvm-project that referenced this pull request Jul 3, 2024
…m#94705)

When we encounter two consecutive ptrauth intrinsics, we can already
combine the inner matching sign + auth pair, e.g.:
  resign(sign(p,ks,ds),ks,ds,kr,dr) -> sign(p,kr,dr)

We can generalize that to ptrauth constants, which are effectively
constant equivalents to ptrauth.sign, i.e.:
  resign(ptrauth(p,ks,ds),ks,ds,kr,dr) -> ptrauth(p,kr,dr)
  auth(ptrauth(p,k,d),k,d) -> p

While there, cleanup a redundant return after eraseInstFromFunction in
the shared (intrinsic|constant)->intrinsic folding code.
AlexisPerry pushed a commit to llvm-project-tlp/llvm-project that referenced this pull request Jul 9, 2024
…m#94705)

When we encounter two consecutive ptrauth intrinsics, we can already
combine the inner matching sign + auth pair, e.g.:
  resign(sign(p,ks,ds),ks,ds,kr,dr) -> sign(p,kr,dr)

We can generalize that to ptrauth constants, which are effectively
constant equivalents to ptrauth.sign, i.e.:
  resign(ptrauth(p,ks,ds),ks,ds,kr,dr) -> ptrauth(p,kr,dr)
  auth(ptrauth(p,k,d),k,d) -> p

While there, cleanup a redundant return after eraseInstFromFunction in
the shared (intrinsic|constant)->intrinsic folding code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants