Skip to content

Commit f098322

Browse files
committed
Strip qualifiers when evaluating a reference as an rvalue
1 parent 73a2422 commit f098322

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,7 +1750,7 @@ CodeGenFunction::tryEmitAsConstant(DeclRefExpr *refExpr) {
17501750
if (CEK != CEK_AsReferenceOnly &&
17511751
refExpr->EvaluateAsRValue(result, getContext())) {
17521752
resultIsReference = false;
1753-
resultType = refExpr->getType();
1753+
resultType = refExpr->getType().getUnqualifiedType();
17541754

17551755
// Otherwise, try to evaluate as an l-value.
17561756
} else if (CEK != CEK_AsValueOnly &&

clang/test/CodeGen/ptrauth-qualifier-function.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// RUN: %clang_cc1 %s -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s
2-
// RUN: %clang_cc1 -xc++ %s -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck %s
2+
// RUN: %clang_cc1 -xc++ %s -fptrauth-function-pointer-type-discrimination -triple arm64e-apple-ios13 -fptrauth-calls -fptrauth-intrinsics -disable-llvm-passes -emit-llvm -o- | FileCheck --check-prefixes=CHECK,CHECK-CXX %s
33

44
#ifdef __cplusplus
55
extern "C" {
66
#endif
77

88
void (*fptr)(void);
99
void (* __ptrauth(0, 0, 42) f2ptr_42_discm)(int);
10+
void f(int);
11+
void (* const __ptrauth(0, 0, 42) f_const_ptr)(int) = &f;
1012

1113
// CHECK-LABEL: define void @test_assign_to_qualified
1214
void test_assign_to_qualified() {
@@ -70,6 +72,24 @@ void test_assign_from_qualified() {
7072
// CHECK-NEXT store void ()* [[FPTR10]], void ()** @f2ptr_42_discm
7173
}
7274

75+
// CHECK-LABEL: define void @test_const_ptr_function_call()
76+
void test_const_ptr_function_call(void) {
77+
f_const_ptr(1);
78+
79+
// CHECK: call void ptrauth (ptr @f, i32 0, i64 2712)(i32 noundef 1) [ "ptrauth"(i32 0, i64 2712) ]
80+
}
81+
7382
#ifdef __cplusplus
83+
void (* get_fptr(void))(int);
84+
void (* __ptrauth(0, 0, 42) f_const_ptr2)(int) = get_fptr();
85+
void (* const __ptrauth(0, 0, 42) &f_ref)(int) = f_const_ptr2;
86+
87+
// CHECK-CXX-LABEL: define void @test_const_ptr_ref_function_call()
88+
void test_const_ptr_ref_function_call(void) {
89+
f_ref(1);
90+
91+
// CHECK-CXX: %[[V0:.*]] = load ptr, ptr @f_const_ptr2, align 8
92+
// CHECK-CXX: call void %[[V0]](i32 noundef 1) [ "ptrauth"(i32 0, i64 42) ]
93+
}
7494
}
7595
#endif

0 commit comments

Comments
 (0)