Skip to content

Commit

Permalink
No longer hang on typeof of a function type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AaronBallman committed Aug 17, 2023
1 parent d425720 commit 7b8f5f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ Bug Fixes in This Version
module may end up with members associated with the wrong declaration of the
class, which can result in miscompiles in some cases.
- Fix crash on use of a variadic overloaded operator.
(`#42535 <https://github.com/llvm/llvm-project/issues/42535>`_)
(`#42535 <https://github.com/llvm/llvm-project/issues/42535>_`)
- Fix a hang on valid C code passing a function type as an argument to
``typeof`` to form a function declaration.
(`#64713 <https://github.com/llvm/llvm-project/issues/64713>_`)

Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9235,7 +9235,8 @@ static FunctionDecl *CreateNewFunctionDecl(Sema &SemaRef, Declarator &D,
bool HasPrototype =
(D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype) ||
(D.getDeclSpec().isTypeRep() &&
D.getDeclSpec().getRepAsType().get()->isFunctionProtoType()) ||
SemaRef.GetTypeFromParser(D.getDeclSpec().getRepAsType(), nullptr)
->isFunctionProtoType()) ||
(!R->getAsAdjusted<FunctionType>() && R->isFunctionProtoType());
assert(
(HasPrototype || !SemaRef.getLangOpts().requiresStrictPrototypes()) &&
Expand Down
4 changes: 4 additions & 0 deletions clang/test/C/C2x/n2927.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ extern typeof(D) C; // C has type "double[2]"
typeof(D) D = { 5, 8.9, 0.1, 99 }; // D is now completed to "double[4]"
extern double E[4];
extern typeof(D) E; // E has type "double[4]" from D’s completed type

// GH64713 -- this used to trigger an infinite loop when creating the function
// declaration for F from the function designator specified by typeof.
typeof(int(int)) F; // F has type "int(int)"

0 comments on commit 7b8f5f7

Please sign in to comment.