[clang] [PAC] Fix a crash when signing a pointer to a function with an incomplete enum parameter (PR #99595)
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 18 18:09:43 PDT 2024
https://github.com/ahatanak created https://github.com/llvm/llvm-project/pull/99595
Use type int as the underlying type when the enum type is incomplete.
>From 14612f84704edbcc3b3bcb20d6e114890e1c3998 Mon Sep 17 00:00:00 2001
From: Akira Hatanaka <ahatanak at gmail.com>
Date: Thu, 18 Jul 2024 17:59:46 -0700
Subject: [PATCH] [PAC] Fix a crash when signing a pointer to a function with
an incomplete enum parameter
Use type int as the underlying type when the enum type is incomplete.
---
clang/lib/AST/ASTContext.cpp | 6 ++++--
clang/test/CodeGen/ptrauth-function-type-discriminator.c | 7 +++++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index a8e599f7ebe04..9eb529c29bebb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -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: {
diff --git a/clang/test/CodeGen/ptrauth-function-type-discriminator.c b/clang/test/CodeGen/ptrauth-function-type-discriminator.c
index 5dea48fe5915b..54634ed528fb3 100644
--- a/clang/test/CodeGen/ptrauth-function-type-discriminator.c
+++ b/clang/test/CodeGen/ptrauth-function-type-discriminator.c
@@ -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
More information about the cfe-commits
mailing list