[clang] 7b8f5f7 - No longer hang on typeof of a function type

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 17 04:15:51 PDT 2023


Author: Aaron Ballman
Date: 2023-08-17T07:15:30-04:00
New Revision: 7b8f5f7df71c48b281163e88054c84c06364023d

URL: https://github.com/llvm/llvm-project/commit/7b8f5f7df71c48b281163e88054c84c06364023d
DIFF: https://github.com/llvm/llvm-project/commit/7b8f5f7df71c48b281163e88054c84c06364023d.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 02b897bcd0a68e..064b4556f354a2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -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
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3c2c7575ed9980..8e5920b8babeb2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -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()) &&

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 cfe-commits mailing list