Skip to content

Commit 729272f

Browse files
usama54321tru
authored andcommitted
[CodeGen][UBSan] Handle sugared QualTypes correctly in
getUBSanFunctionTypeHash. getUBSanFunctionTypeHash checks if a Type is a FunctionNoPrototype by calling isa<FunctionNoProtoType>(). This does not work correctly when the Type is wrapped in a sugar type such as an AttributedType. This patch fixes this by using isFunctionNoProtoType() function which removes sugar and returns the expected result. The added test is a sanity check that the compiler no longer crashes during compilation. It also compares the hash with and without the function attribute for both FunctionNoProtoType and FunctionProtoType. The hash remains the same for FunctionNoProtoType even with the addition of an attribute. rdar://113144087 Differential Revision: https://reviews.llvm.org/D157445 (cherry picked from commit 9afc57d)
1 parent cd119b3 commit 729272f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ llvm::ConstantInt *
572572
CodeGenFunction::getUBSanFunctionTypeHash(QualType Ty) const {
573573
// Remove any (C++17) exception specifications, to allow calling e.g. a
574574
// noexcept function through a non-noexcept pointer.
575-
if (!isa<FunctionNoProtoType>(Ty))
575+
if (!Ty->isFunctionNoProtoType())
576576
Ty = getContext().getFunctionTypeWithExceptionSpec(Ty, EST_None);
577577
std::string Mangled;
578578
llvm::raw_string_ostream Out(Mangled);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %clang_cc1 -S -triple x86_64 -std=c17 -fsanitize=function %s -o - | FileCheck %s --check-prefixes=CHECK
2+
3+
// CHECK: .long 248076293
4+
void __attribute__((ms_abi)) f(void) {}
5+
6+
// CHECK: .long 905068220
7+
void g(void) {}
8+
9+
// CHECK: .long 1717976574
10+
void __attribute__((ms_abi)) f_no_prototype() {}
11+
12+
// CHECK: .long 1717976574
13+
void g_no_prototype() {}

0 commit comments

Comments
 (0)