[clang] d463617 - [PAC] Fix a crash when signing a pointer to a function with an incomplete enum parameter (#99595)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 19 08:28:32 PDT 2024
Author: Akira Hatanaka
Date: 2024-07-19T08:28:29-07:00
New Revision: d463617d7772c5e3275cf8c4a8a21d17b3d03d86
URL: https://github.com/llvm/llvm-project/commit/d463617d7772c5e3275cf8c4a8a21d17b3d03d86
DIFF: https://github.com/llvm/llvm-project/commit/d463617d7772c5e3275cf8c4a8a21d17b3d03d86.diff
LOG: [PAC] Fix a crash when signing a pointer to a function with an incomplete enum parameter (#99595)
Use int as the underlying type when the enum type is incomplete.
Added:
Modified:
clang/lib/AST/ASTContext.cpp
clang/test/CodeGen/ptrauth-function-type-discriminator.c
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 98ce88eb6a9fd..90bcbea072e39 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3223,14 +3223,16 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
OS << "<objc_object>";
return;
- case Type::Enum:
+ case Type::Enum: {
// C11 6.7.2.2p4:
// Each enumerated type shall be compatible with char, a signed integer
// type, or an unsigned integer type.
//
// So we have to treat enum types as integers.
+ QualType UnderlyingType = cast<EnumType>(T)->getDecl()->getIntegerType();
return encodeTypeForFunctionPointerAuth(
- Ctx, OS, cast<EnumType>(T)->getDecl()->getIntegerType());
+ Ctx, OS, UnderlyingType.isNull() ? Ctx.IntTy : UnderlyingType);
+ }
case Type::FunctionNoProto:
case Type::FunctionProto: {
diff --git a/clang/test/CodeGen/ptrauth-function-type-discriminator.c b/clang/test/CodeGen/ptrauth-function-type-discriminator.c
index 58717015adb6c..0952c1abf6c07 100644
--- a/clang/test/CodeGen/ptrauth-function-type-discriminator.c
+++ b/clang/test/CodeGen/ptrauth-function-type-discriminator.c
@@ -30,6 +30,13 @@ void (*test_constant_null)(int) = 0;
// CHECK: @test_constant_cast = global ptr ptrauth (ptr @f, i32 0, i64 2712)
void (*test_constant_cast)(int) = (void (*)(int))f;
+#ifndef __cplusplus
+// CHECKC: @enum_func_ptr = global ptr ptrauth (ptr @enum_func, i32 0, i64 2712)
+enum Enum0;
+void enum_func(enum Enum0);
+void (*enum_func_ptr)(enum Enum0) = enum_func;
+#endif
+
// CHECK: @test_opaque = global ptr ptrauth (ptr @f, i32 0)
void *test_opaque =
#ifdef __cplusplus
More information about the cfe-commits
mailing list