Skip to content

Commit 311d8fe

Browse files
committed
[GlobalOpt] Bail out for ConstantPtrAuth in isSimpleEnoughtToCommit.
Bail out for ConstantPtrAuth constants in isSimpleEnoughValueToCommitHelper to prevent crash in cast<ConstantExpr> below.
1 parent 77347d6 commit 311d8fe

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

llvm/lib/Transforms/Utils/Evaluator.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ isSimpleEnoughValueToCommitHelper(Constant *C,
7474
return true;
7575
}
7676

77+
if (isa<ConstantPtrAuth>(C))
78+
return false;
79+
7780
// We don't know exactly what relocations are allowed in constant expressions,
7881
// so we allow &global+constantoffset, which is safe and uniformly supported
7982
// across targets.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 5
2+
; RUN: opt -p globalopt -S %s | FileCheck %s
3+
4+
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @ctor, ptr null }]
5+
6+
@foo = internal global ptr null
7+
8+
declare void @user(ptr)
9+
10+
;.
11+
; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @ctor, ptr null }]
12+
; CHECK: @foo = internal global ptr null
13+
;.
14+
define void @ctor() {
15+
; CHECK-LABEL: define void @ctor() {
16+
; CHECK-NEXT: [[ENTRY:.*:]]
17+
; CHECK-NEXT: [[DST:%.*]] = alloca ptr, align 8
18+
; CHECK-NEXT: store ptr ptrauth (ptr @foo, i32 0), ptr [[DST]], align 8
19+
; CHECK-NEXT: call void @user(ptr [[DST]])
20+
; CHECK-NEXT: ret void
21+
;
22+
entry:
23+
%dst = alloca ptr, align 8
24+
store ptr ptrauth (ptr @foo, i32 0), ptr %dst, align 8
25+
call void @user(ptr %dst)
26+
ret void
27+
}

0 commit comments

Comments
 (0)