[PATCH] D157445: [CodeGen][UBSan] getUBSanFunctionTypeHash does not handle the attributed function case correctly, leading to an assertion failure. This patch desugars the QualType if it is of AttributedType.

Usama Hameed via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 9 11:58:00 PDT 2023


usama54321 updated this revision to Diff 548723.
usama54321 added a comment.

Fix commit message and description, and added comment explaining the test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157445/new/

https://reviews.llvm.org/D157445

Files:
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGen/ubsan-function-attributed.c


Index: clang/test/CodeGen/ubsan-function-attributed.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/ubsan-function-attributed.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -std=c17 -fsanitize=function %s -o /dev/null
+
+//Make sure compiler does not crash inside getUBSanFunctionTypeHash while compiling this
+long __attribute__((ms_abi)) f() {}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -570,6 +570,9 @@
 
 llvm::ConstantInt *
 CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
+  if (isa<AttributedType>(Ty))
+    Ty = Ty.getDesugaredType(getContext());
+
   // Remove any (C++17) exception specifications, to allow calling e.g. a
   // noexcept function through a non-noexcept pointer.
   if (!isa<FunctionNoProtoType>(Ty))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157445.548723.patch
Type: text/x-patch
Size: 975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230809/af540d13/attachment.bin>


More information about the cfe-commits mailing list