[clang] [clang][CUDA/HIP] Fix parsing of `operator<<<...>` (PR #218384)
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 24 08:53:32 PDT 2026
================
@@ -2485,6 +2485,30 @@ bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
Actions.CodeCompletion().CodeCompleteOperatorName(getCurScope());
return true;
}
+ case tok::lesslessless: {
+ // For CUDA, the Lexer will greedily merge all three <<< in operator<<<
+ // which, in fact, can be a valid template specialization of operator<<,
+ // and will never be a valid kernel launch expression, so split.
+ bool CachingTokens = PP.IsPreviousCachedToken(Tok);
+ // If there was a cache, we should update it when doing token split.
+ // The code below never does.
+ assert(!CachingTokens && "No cache expected");
+
+ SourceLocation TokLoc = Tok.getLocation();
+ unsigned LessLessLength = Lexer::getTokenPrefixLength(
+ TokLoc, /*CharNo=*/2, PP.getSourceManager(), getLangOpts());
+
+ SourceLocation LessLoc = PP.SplitToken(TokLoc, LessLessLength);
+ unsigned OldLength = Tok.getLength();
+
+ Tok.setKind(tok::less);
+ Tok.setLength(OldLength - LessLessLength);
+ Tok.setLocation(LessLoc);
----------------
yxsamliu wrote:
`SplitToken` returns the location for the `<<` prefix, but it is assigned to the remaining `<` here. Should `SymbolLocations` use this location and `Tok` start after the first two characters? Please also add a source-location test that checks the template `<` points to the third character.
https://github.com/llvm/llvm-project/pull/218384
More information about the cfe-commits
mailing list