Skip to content

[PAC] Fix a crash when signing a pointer to a function with an incomplete enum parameter #99595

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3222,14 +3222,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: {
Expand Down
7 changes: 7 additions & 0 deletions clang/test/CodeGen/ptrauth-function-type-discriminator.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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
Expand Down
Loading