[PATCH] D132712: [Clang] Fix assert in Sema::LookupTemplateName so that it does not attempt an unconditional cast to TagType

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 26 09:43:59 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG21dfe482e13e: [Clang] Fix assert in Sema::LookupTemplateName so that it does not attempt an… (authored by shafik).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132712/new/

https://reviews.llvm.org/D132712

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaCXX/member-expr.cpp


Index: clang/test/SemaCXX/member-expr.cpp
===================================================================
--- clang/test/SemaCXX/member-expr.cpp
+++ clang/test/SemaCXX/member-expr.cpp
@@ -228,3 +228,19 @@
         .i;  // expected-error {{member reference type 'S *' is a pointer; did you mean to use '->'}}
   }
 }
+
+namespace LookupTemplateNameAssert {
+void f() {}
+
+typedef int at[];
+const at& f2(){}
+
+void g() {
+  f().junk<int>(); // expected-error {{member reference base type 'void' is not a structure or union}}
+// expected-error at -1 {{expected '(' for function-style cast or type construction}}
+// expected-error at -2 {{expected expression}}
+  f2().junk<int>(); // expected-error {{member reference base type 'const at' (aka 'const int[]') is not a structure or union}}
+// expected-error at -1 {{expected '(' for function-style cast or type construction}}
+// expected-error at -2 {{expected expression}}
+}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -399,6 +399,7 @@
     LookupCtx = computeDeclContext(ObjectType);
     IsDependent = !LookupCtx && ObjectType->isDependentType();
     assert((IsDependent || !ObjectType->isIncompleteType() ||
+            !ObjectType->getAs<TagType>() ||
             ObjectType->castAs<TagType>()->isBeingDefined()) &&
            "Caller should have completed object type");
 
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -81,6 +81,9 @@
 - Fix a crash when generating code coverage information for an
   ``if consteval`` statement. This fixes
   `Issue 57377 <https://github.com/llvm/llvm-project/issues/57377>`_.
+- Fix assert that triggers a crash during template name lookup when a type was
+  incomplete but was not also a TagType. This fixes
+  `Issue 57387 <https://github.com/llvm/llvm-project/issues/57387>`_.
 
 
 Improvements to Clang's diagnostics


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132712.455947.patch
Type: text/x-patch
Size: 2077 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220826/4257a30b/attachment.bin>


More information about the cfe-commits mailing list