[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
Tue Aug 8 14:50:32 PDT 2023


usama54321 created this revision.
Herald added a project: All.
usama54321 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

rdar://113144087


Repository:
  rG LLVM Github Monorepo

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,3 @@
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -std=c17 -fsanitize=function %s -o /dev/null
+
+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.548363.patch
Type: text/x-patch
Size: 885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230808/236666ca/attachment-0001.bin>


More information about the cfe-commits mailing list