Skip to content

Commit d463617

Browse files
authored
[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.
1 parent cf50a84 commit d463617

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3223,14 +3223,16 @@ static void encodeTypeForFunctionPointerAuth(const ASTContext &Ctx,
32233223
OS << "<objc_object>";
32243224
return;
32253225

3226-
case Type::Enum:
3226+
case Type::Enum: {
32273227
// C11 6.7.2.2p4:
32283228
// Each enumerated type shall be compatible with char, a signed integer
32293229
// type, or an unsigned integer type.
32303230
//
32313231
// So we have to treat enum types as integers.
3232+
QualType UnderlyingType = cast<EnumType>(T)->getDecl()->getIntegerType();
32323233
return encodeTypeForFunctionPointerAuth(
3233-
Ctx, OS, cast<EnumType>(T)->getDecl()->getIntegerType());
3234+
Ctx, OS, UnderlyingType.isNull() ? Ctx.IntTy : UnderlyingType);
3235+
}
32343236

32353237
case Type::FunctionNoProto:
32363238
case Type::FunctionProto: {

clang/test/CodeGen/ptrauth-function-type-discriminator.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ void (*test_constant_null)(int) = 0;
3030
// CHECK: @test_constant_cast = global ptr ptrauth (ptr @f, i32 0, i64 2712)
3131
void (*test_constant_cast)(int) = (void (*)(int))f;
3232

33+
#ifndef __cplusplus
34+
// CHECKC: @enum_func_ptr = global ptr ptrauth (ptr @enum_func, i32 0, i64 2712)
35+
enum Enum0;
36+
void enum_func(enum Enum0);
37+
void (*enum_func_ptr)(enum Enum0) = enum_func;
38+
#endif
39+
3340
// CHECK: @test_opaque = global ptr ptrauth (ptr @f, i32 0)
3441
void *test_opaque =
3542
#ifdef __cplusplus

0 commit comments

Comments
 (0)