Skip to content

Commit 7b8f5f7

Browse files
committed
No longer hang on typeof of a function type
We were calling `isFunctionProtoType()` on a `ParsedType` rather than creating a valid semantic type first and calling the function on that. The call to `isFunctionProtoType()` would eventually call `getUnqualifiedDesugaredType()`, which loops indefinitely until we get a desugared type and a `ParsedType` will never finish desugaring. Fixes #64713
1 parent d425720 commit 7b8f5f7

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ Bug Fixes in This Version
144144
module may end up with members associated with the wrong declaration of the
145145
class, which can result in miscompiles in some cases.
146146
- Fix crash on use of a variadic overloaded operator.
147-
(`#42535 <https://github.com/llvm/llvm-project/issues/42535>`_)
147+
(`#42535 <https://github.com/llvm/llvm-project/issues/42535>_`)
148+
- Fix a hang on valid C code passing a function type as an argument to
149+
``typeof`` to form a function declaration.
150+
(`#64713 <https://github.com/llvm/llvm-project/issues/64713>_`)
148151

149152
Bug Fixes to Compiler Builtins
150153
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/lib/Sema/SemaDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9235,7 +9235,8 @@ static FunctionDecl *CreateNewFunctionDecl(Sema &SemaRef, Declarator &D,
92359235
bool HasPrototype =
92369236
(D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype) ||
92379237
(D.getDeclSpec().isTypeRep() &&
9238-
D.getDeclSpec().getRepAsType().get()->isFunctionProtoType()) ||
9238+
SemaRef.GetTypeFromParser(D.getDeclSpec().getRepAsType(), nullptr)
9239+
->isFunctionProtoType()) ||
92399240
(!R->getAsAdjusted<FunctionType>() && R->isFunctionProtoType());
92409241
assert(
92419242
(HasPrototype || !SemaRef.getLangOpts().requiresStrictPrototypes()) &&

clang/test/C/C2x/n2927.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,7 @@ extern typeof(D) C; // C has type "double[2]"
9090
typeof(D) D = { 5, 8.9, 0.1, 99 }; // D is now completed to "double[4]"
9191
extern double E[4];
9292
extern typeof(D) E; // E has type "double[4]" from D’s completed type
93+
94+
// GH64713 -- this used to trigger an infinite loop when creating the function
95+
// declaration for F from the function designator specified by typeof.
96+
typeof(int(int)) F; // F has type "int(int)"

0 commit comments

Comments
 (0)