[CodeGen][UBSan] Handle sugared QualTypes correctly in
authorusama hameed <u_hameed@apple.com>
Tue, 8 Aug 2023 21:49:48 +0000 (14:49 -0700)
committerTobias Hieta <tobias@hieta.se>
Tue, 22 Aug 2023 05:43:40 +0000 (07:43 +0200)
commit729272fb0e172ca9e9cab9091470b790a9a582e3
tree670406666d064bd6fd7ae3ed2db570ac5b7c20cb
parentcd119b354a934575aa0c8f84ac71a7be1f3def7f
[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 9afc57dcb2e5cd36ca1ddf0fee3efa958bfd4c2a)
clang/lib/CodeGen/CodeGenFunction.cpp
clang/test/CodeGen/ubsan-function-attributed.c [new file with mode: 0644]