[llvm-branch-commits] [clang] daced85 - No longer hang on typeof of a function type

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 21 22:51:33 PDT 2023


Author: Aaron Ballman
Date: 2023-08-22T07:48:14+02:00
New Revision: daced851f0a659e4934d00fc7920e8c787379c7d

URL: https://github.com/llvm/llvm-project/commit/daced851f0a659e4934d00fc7920e8c787379c7d
DIFF: https://github.com/llvm/llvm-project/commit/daced851f0a659e4934d00fc7920e8c787379c7d.diff

LOG: 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 https://github.com/llvm/llvm-project/issues/64713

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaDecl.cpp
    clang/test/C/C2x/n2927.c

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e8bcaf520bc95e..bb34988c3b612e 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -477,6 +477,7 @@ Bug Fixes in This Version
   instantiated in one module and whose definition is instantiated in another
   module may end up with members associated with the wrong declaration of the
   class, which can result in miscompiles in some cases.
+<<<<<<< HEAD
 
 - Added a new diagnostic warning group
   ``-Wdeprecated-redundant-constexpr-static-def``, under the existing
@@ -700,6 +701,11 @@ Bug Fixes in This Version
   (`#64005 <https://github.com/llvm/llvm-project/issues/64005>_`)
 - Fix crash on nested templated class with template function call.
   (`#61159 <https://github.com/llvm/llvm-project/issues/61159>_`)
+- Fix crash on use of a variadic overloaded operator.
+  (`#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
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index a4bf5792847092..21b5781a71cddd 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9154,7 +9154,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()) &&

diff  --git a/clang/test/C/C2x/n2927.c b/clang/test/C/C2x/n2927.c
index 0ece6da88c5c6a..57a77f841025cd 100644
--- a/clang/test/C/C2x/n2927.c
+++ b/clang/test/C/C2x/n2927.c
@@ -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)"


        


More information about the llvm-branch-commits mailing list