Skip to content

[Clang][Sema] Fix crash when using name of UnresolvedUsingValueDecl with template arguments #83842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 5, 2024

Conversation

sdkrystian
Copy link
Member

@sdkrystian sdkrystian commented Mar 4, 2024

The following snippet causes a crash (godbolt link):

template<typename T>
struct A : T {
  using T::f;
  void f();

  void g() {
    f<int>(); // crash here
  }
};

This happens because we cast the result of getAsTemplateNameDecl as a TemplateDecl in Sema::ClassifyName, which we cannot do for an UnresolvedUsingValueDecl. I believe the correct thing to do here is create an OverloadedTemplateName, since it may instantiate to a using declaration naming any number of declarations. This patch fixes the crash by considering a name to be that of a template if any function declaration is found per [temp.names] p3.3.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 4, 2024
@sdkrystian sdkrystian requested a review from erichkeane March 4, 2024 13:38
@llvmbot
Copy link
Member

llvmbot commented Mar 4, 2024

@llvm/pr-subscribers-clang

Author: Krystian Stasiowski (sdkrystian)

Changes

The following snippet causes a crash (godbolt link):

template&lt;typename T&gt;
struct A : T {
  using T::f;
  void f();

  void g() {
    f&lt;int&gt;(); // crash here
  }
};

This happens because we cast the result of getAsTemplateNameDecl as a TemplateDecl in Sema::ClassifyName, which we cannot do for an UnresolvedUsingValueDecl. I believe the correct thing to do here is to create an OverloadedTemplateName.


Full diff: https://github.com/llvm/llvm-project/pull/83842.diff

3 Files Affected:

  • (modified) clang/lib/AST/ASTContext.cpp (+2-1)
  • (modified) clang/lib/Sema/SemaDecl.cpp (+2-1)
  • (added) clang/test/SemaTemplate/unqual-unresolved-using-value.cpp (+24)
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5a8fae76a43a4d..28dd69b8e45758 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -9200,7 +9200,8 @@ TemplateName
 ASTContext::getOverloadedTemplateName(UnresolvedSetIterator Begin,
                                       UnresolvedSetIterator End) const {
   unsigned size = End - Begin;
-  assert(size > 1 && "set is not overloaded!");
+  assert((size == 1 && isa<UnresolvedUsingValueDecl>(*Begin)) ||
+         size > 1 && "set is not overloaded!");
 
   void *memory = Allocate(sizeof(OverloadedTemplateStorage) +
                           size * sizeof(FunctionTemplateDecl*));
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 9fdd8eb236d1ee..c62e4ce7d0f9c4 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1115,7 +1115,8 @@ Sema::NameClassification Sema::ClassifyName(Scope *S, CXXScopeSpec &SS,
     bool IsFunctionTemplate;
     bool IsVarTemplate;
     TemplateName Template;
-    if (Result.end() - Result.begin() > 1) {
+
+    if ((Result.end() - Result.begin() > 1) || Result.isUnresolvableResult()) {
       IsFunctionTemplate = true;
       Template = Context.getOverloadedTemplateName(Result.begin(),
                                                    Result.end());
diff --git a/clang/test/SemaTemplate/unqual-unresolved-using-value.cpp b/clang/test/SemaTemplate/unqual-unresolved-using-value.cpp
new file mode 100644
index 00000000000000..7c45342adce783
--- /dev/null
+++ b/clang/test/SemaTemplate/unqual-unresolved-using-value.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+template<typename T>
+struct A : T {
+  using T::f;
+  using T::g;
+
+  void f();
+  void g();
+
+  void h() {
+    f<int>();
+    g<int>(); // expected-error{{no member named 'g' in 'A<B>'}}
+  }
+};
+
+struct B {
+  template<typename T>
+  void f();
+
+  void g();
+};
+
+template struct A<B>; // expected-note{{in instantiation of member function 'A<B>::h' requested here}}

@sdkrystian
Copy link
Member Author

sdkrystian commented Mar 4, 2024

Actually, I don't think the proposed fix here is quite right. If we only find an UnresolvedUsingValueDecl, then we shouldn't assume the name is a template per [temp.names] p3.3... I'll come up with a new fix.

@sdkrystian sdkrystian force-pushed the fix-using-templ-crash branch from 9a464d3 to de29206 Compare March 4, 2024 17:08
@sdkrystian
Copy link
Member Author

sdkrystian commented Mar 4, 2024

Updated with new fix (still need a release note)

Copy link

github-actions bot commented Mar 4, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@sdkrystian sdkrystian force-pushed the fix-using-templ-crash branch from de29206 to 763c7d0 Compare March 4, 2024 17:11
@erichkeane
Copy link
Collaborator

Updated with new fix (still need a release note)

Please update the patch message in github (which should allow editing) to reflect the new approach.

Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems right to me, modulo the release note/updated commit message.

@sdkrystian sdkrystian force-pushed the fix-using-templ-crash branch from fcd5980 to 6b93bef Compare March 5, 2024 13:29
@sdkrystian sdkrystian merged commit a642eb8 into llvm:main Mar 5, 2024
@wlei-llvm
Copy link
Contributor

Hi:
We hit a crash/assertion, and bisected to this. Here is the stack dump:

clang++: /home/wlei/local/upstream/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = clang::CXXRecordDecl, From = clang::DeclContext]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /home/wlei/local/upstream/llvm-build/bin/clang++ @/tmp/fbcc.xxbvookk/compiler.argsfile
1.	fbcode/multifeed/ranking/user_profile/GFIHCountsMap.cpp:633:55: current parser token ')'
2.	fbcode/multifeed/ranking/user_profile/GFIHCountsMap.cpp:26:1: parsing namespace 'facebook'
3.	fbcode/multifeed/ranking/user_profile/GFIHCountsMap.cpp:622:29: parsing function body 'facebook::multifeed::ranking::GFIHCountsMap::getTotalAggregationIfConfigured'
4.	fbcode/multifeed/ranking/user_profile/GFIHCountsMap.cpp:622:29: in compound statement ('{}')
 #0 0x00007f25c2bf9588 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/wlei/local/upstream/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x00007f25c2bf7630 llvm::sys::RunSignalHandlers() /home/wlei/local/upstream/llvm-project/llvm/lib/Support/Signals.cpp:106:18
 #2 0x00007f25c2bf8c41 llvm::sys::CleanupOnSignal(unsigned long) /home/wlei/local/upstream/llvm-project/llvm/lib/Support/Unix/Signals.inc:0:3
 #3 0x00007f25c2b3f908 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /home/wlei/local/upstream/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 #4 0x00007f25c2b3f908 CrashRecoverySignalHandler(int) /home/wlei/local/upstream/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:390:51
 #5 0x00007f25c7612d20 __restore_rt (/lib64/libpthread.so.0+0x12d20)
 #6 0x00007f25c1a4e52f raise (/lib64/libc.so.6+0x4e52f)
 #7 0x00007f25c1a21e65 abort (/lib64/libc.so.6+0x21e65)
 #8 0x00007f25c1a21d39 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d39)
 #9 0x00007f25c1a46e86 (/lib64/libc.so.6+0x46e86)
#10 0x00007f25bf3a934c FindDeclaringClass(clang::NamedDecl*) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaAccess.cpp:0:0
#11 0x00007f25bf3a9265 (anonymous namespace)::AccessTarget::initialize() /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaAccess.cpp:267:24
#12 0x00007f25bf3a686c clang::sema::AccessedEntity::isQuiet() const /home/wlei/local/upstream/llvm-project/clang/include/clang/Sema/DelayedDiagnostic.h:75:50
#13 0x00007f25bf3a686c clang::sema::AccessedEntity::setDiag(unsigned int) /home/wlei/local/upstream/llvm-project/clang/include/clang/Sema/DelayedDiagnostic.h:104:5
#14 0x00007f25bf3a686c clang::Sema::CheckUnresolvedLookupAccess(clang::UnresolvedLookupExpr*, clang::DeclAccessPair) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaAccess.cpp:1567:10
#15 0x00007f25bfa98e83 clang::DeclarationNameInfo::getLoc() const /home/wlei/local/upstream/llvm-project/clang/include/clang/AST/DeclarationName.h:797:42
#16 0x00007f25bfa98e83 clang::OverloadExpr::getNameLoc() const /home/wlei/local/upstream/llvm-project/clang/include/clang/AST/ExprCXX.h:3078:55
#17 0x00007f25bfa98e83 FinishOverloadedCallExpr(clang::Sema&, clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, clang::OverloadCandidateSet*, clang::OverloadCandidate**, clang::OverloadingResult, bool) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaOverload.cpp:14062:47
#18 0x00007f25bfa98c8f clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaOverload.cpp:14200:10
#19 0x00007f25bf70511d clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaExpr.cpp:7276:16
#20 0x00007f25bf720e6b clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaExpr.cpp:7167:7
#21 0x00007f25c2d59dca clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:2181:23
#22 0x00007f25c2d5af8a clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:1890:7
#23 0x00007f25c2d56e2b clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:693:20
#24 0x00007f25c2d56e2b clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:176:20
#25 0x00007f25c2d63a8a clang::Parser::ParseExpressionList(llvm::SmallVectorImpl<clang::Expr*>&, llvm::function_ref<void ()>, bool, bool) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:0:14
#26 0x00007f25c2d1f05b clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseDecl.cpp:2751:21
#27 0x00007f25c2d1c1dd clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseDecl.cpp:2414:7
#28 0x00007f25c2d1b34d clang::Parser::ParseSimpleDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, bool, clang::Parser::ForRangeInit*, clang::SourceLocation*) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseDecl.cpp:0:10
#29 0x00007f25c2d1ad8f clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseDecl.cpp:0:0
#30 0x00007f25c2dc5004 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseStmt.cpp:0:16
#31 0x00007f25c2dc4462 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseStmt.cpp:118:20

Is this a known issue or any thing obvious to fix? If not, I will try to get a reduced reproducer.

@sdkrystian
Copy link
Member Author

@wlei-llvm Not a known issue... could you provide a repro? I'll look into this in the meantime.

@bgra8
Copy link
Contributor

bgra8 commented Mar 8, 2024

@sdkrystian we, at google, bisected lots (~1k) of clang crashes to this revision. Looks to me Facebook code is also impacted.

We need some time to provide a repro. Until then can you please revert?

sdkrystian added a commit to sdkrystian/llvm-project that referenced this pull request Mar 8, 2024
…ueDecl with template arguments (llvm#83842)"

This reverts commit a642eb8.
sdkrystian added a commit that referenced this pull request Mar 8, 2024
…ueDecl with template arguments (#83842)" (#84457)

This reverts commit a642eb8 (see #83842)
@sdkrystian
Copy link
Member Author

@bgra8 Reverted. Any sort of repro would be appreciated :)

@bgra8
Copy link
Contributor

bgra8 commented Mar 8, 2024

Thanks a lot @sdkrystian ! We have a reducer session running! We'll post here when we have it!

@wlei-llvm
Copy link
Contributor

Here is the repro from our side. It's reduced by creduce, there are some unrelated error, the assertion is the real issue.

typedef a;
template < typename b, b c > struct d {
  static constexpr b e = c;
};
typedef d< bool, true > f;
typedef d< bool, false > g;
template < bool, typename, typename > struct aa;
template < typename... > struct h;
template < typename i, typename j, typename ab, typename... k >
struct h< i, j, ab, k... >
    : aa< i::e, i, h<> >::l {};
template < typename > struct ad : g {};
template < typename b >
struct ae : ad<  b  >{};
template < typename ai, typename aj,
           bool = h< ae< ai >,  aj ,
                          aj  >::e >
class ak {
  template < typename >
  static f al(int);
public:
  typedef decltype(al< aj >(0)) l;
};
template < typename ai, typename aj >
struct am : ak< ai, aj >::l {};
template < bool , typename az, typename >
struct aa {
  typedef az l;
}template < typename ai, typename aj >
constexpr bool bj = am< ai, aj >::e;
template < typename bx, typename by >
concept bz =
    bj< bx , by >;
      template < typename... > class cy
template < typename m >
concept n =
    bz<  m , m > 
 template < typename b >
concept o =
    n<  b  >
template < a , typename > struct tuple_element;
template < typename p, typename r >
class cy< p, r > {};
template < a q, typename... t >
__tuple_element_t< q, cy<> > get( cy< t... > ) ;
class s ;
template < class w > class u {
  w begin() ;
};
template < typename x > class v {
  using y = x
   ;
  using dp = decltype(static_cast< y (*)() >(
      nullptr)()[{}])
      ;
  dp operator*()
}
template < typename x >
struct dr {
  using ds = x::dt;
  using dp = u< ds >;
}template < o x > class du {
  using   dr< x >
  ::dp;
}
enum class dy
class dz 
template < typename eb > struct ec : eb ;
template < typename... ed >
struct ee
     :ec< cy< ed... > > {};
template < o... ej > class ek {
public:
  using el = a;
  using dw =
      ee<  ej ... >;
  using dt = v< ek >
   ;
  dw operator[](el ) ;
};
class  {
  using eo =
       s ;
  using ep =
      ek< eo,  dz  >;
  using eq = du< ep >::dp;
  eq get(dy cat) {
  auto es = get(cat)
  auto et = es.begin();
  get< 0 >(*et)

@wlei-llvm
Copy link
Contributor

clang++ -std=gnu++20  test.cpp

clang-18: /../llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = clang::CXXRecordDecl, From = clang::DeclContext]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.

1.	test.bk.10.cpp:90:15: current parser token ')'
2.	test.bk.10.cpp:81:1: parsing struct/union/class body '(unnamed class at test.bk.10.cpp:81:1)'
3.	test.bk.10.cpp:87:18: parsing function body '(anonymous class)::get'
4.	test.bk.10.cpp:87:18: in compound statement ('{}')
 #0 0x00007fb54bdf9588 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/wlei/local/upstream/llvm-project/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x00007fb54bdf7630 llvm::sys::RunSignalHandlers() /home/wlei/local/upstream/llvm-project/llvm/lib/Support/Signals.cpp:106:18
 #2 0x00007fb54bdf9c5d SignalHandler(int) /home/wlei/local/upstream/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007fb550812d20 __restore_rt (/lib64/libpthread.so.0+0x12d20)
 #4 0x00007fb54ac4e52f raise (/lib64/libc.so.6+0x4e52f)
 #5 0x00007fb54ac21e65 abort (/lib64/libc.so.6+0x21e65)
 #6 0x00007fb54ac21d39 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21d39)
 #7 0x00007fb54ac46e86 (/lib64/libc.so.6+0x46e86)
 #8 0x00007fb5485a934c FindDeclaringClass(clang::NamedDecl*) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaAccess.cpp:0:0
 #9 0x00007fb5485a9265 (anonymous namespace)::AccessTarget::initialize() /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaAccess.cpp:267:24
#10 0x00007fb5485a686c clang::sema::AccessedEntity::isQuiet() const /home/wlei/local/upstream/llvm-project/clang/include/clang/Sema/DelayedDiagnostic.h:75:50
#11 0x00007fb5485a686c clang::sema::AccessedEntity::setDiag(unsigned int) /home/wlei/local/upstream/llvm-project/clang/include/clang/Sema/DelayedDiagnostic.h:104:5
#12 0x00007fb5485a686c clang::Sema::CheckUnresolvedLookupAccess(clang::UnresolvedLookupExpr*, clang::DeclAccessPair) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaAccess.cpp:1567:10
#13 0x00007fb548c98e83 clang::DeclarationNameInfo::getLoc() const /home/wlei/local/upstream/llvm-project/clang/include/clang/AST/DeclarationName.h:797:42
#14 0x00007fb548c98e83 clang::OverloadExpr::getNameLoc() const /home/wlei/local/upstream/llvm-project/clang/include/clang/AST/ExprCXX.h:3078:55
#15 0x00007fb548c98e83 FinishOverloadedCallExpr(clang::Sema&, clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, clang::OverloadCandidateSet*, clang::OverloadCandidate**, clang::OverloadingResult, bool) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaOverload.cpp:14062:47
#16 0x00007fb548c98c8f clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*, clang::UnresolvedLookupExpr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaOverload.cpp:14200:10
#17 0x00007fb54890511d clang::Sema::BuildCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool, bool) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaExpr.cpp:7276:16
#18 0x00007fb548920e6b clang::Sema::ActOnCallExpr(clang::Scope*, clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*) /home/wlei/local/upstream/llvm-project/clang/lib/Sema/SemaExpr.cpp:7167:7
#19 0x00007fb54bf59dca clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*, true>) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:2181:23
#20 0x00007fb54bf5af8a clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, bool&, clang::Parser::TypeCastState, bool, bool*) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:1890:7
#21 0x00007fb54bf56e2b clang::Parser::ParseCastExpression(clang::Parser::CastParseKind, bool, clang::Parser::TypeCastState, bool, bool*) /home/wlei/local/upstream/llvm-project/clang/lib/Parse/ParseExpr.cpp:693:20
#22 0x00007fb54bf56e2b clang::Parser:

@sdkrystian
Copy link
Member Author

sdkrystian commented Mar 11, 2024

@wlei-llvm Thank you! I've reduced the repro to this:

struct A { };

template<typename T>
void f(A);

struct B {
  void f();

  void g() {
    f<A>(A());
  }
};

@sdkrystian
Copy link
Member Author

sdkrystian commented Mar 11, 2024

So, it seems that this crash occurs because we filter out all non-template functions, which will trigger ADL if the only class member we found was a non-template function. The current behavior (without this patch applied) isn't correct either, since we clear all lookup results (which triggers ADL).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants