Skip to content

Commit 3a7043d

Browse files
authored
New PASTA patches for LLVM15 (#993)
1 parent 0125110 commit 3a7043d

File tree

2 files changed

+53
-26
lines changed

2 files changed

+53
-26
lines changed

ports/llvm-15/0025-PASTA-patches.patch

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
From acd4d5b98e11f32059c63e3fa3bdd1690f9a36c3 Mon Sep 17 00:00:00 2001
1+
From 6b7b31df2a614557d3c86fed4779535f3f782f19 Mon Sep 17 00:00:00 2001
22
From: Peter Goodman <[email protected]>
33
Date: Mon, 14 Nov 2022 14:51:27 -0500
44
Subject: [PATCH] Patches for PASTA
55

66
---
77
clang/include/clang/Lex/PPCallbacks.h | 120 +++++++++++
88
clang/include/clang/Lex/Preprocessor.h | 46 ++--
9-
clang/include/clang/Lex/TokenLexer.h | 5 +-
9+
clang/include/clang/Lex/TokenLexer.h | 7 +-
1010
clang/lib/Lex/PPDirectives.cpp | 147 +++++++++----
1111
clang/lib/Lex/PPExpressions.cpp | 28 +++
1212
clang/lib/Lex/PPLexerChange.cpp | 38 ++++
1313
clang/lib/Lex/PPMacroExpansion.cpp | 285 ++++++++++++++++++++++++-
1414
clang/lib/Lex/Pragma.cpp | 59 +++++
1515
clang/lib/Lex/Preprocessor.cpp | 43 +++-
16-
clang/lib/Lex/TokenLexer.cpp | 36 +++-
16+
clang/lib/Lex/TokenLexer.cpp | 39 +++-
1717
clang/lib/Parse/ParseTemplate.cpp | 7 +
18-
11 files changed, 737 insertions(+), 77 deletions(-)
18+
11 files changed, 740 insertions(+), 79 deletions(-)
1919

2020
diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h
2121
index 045df8711..cba195cff 100644
@@ -269,7 +269,7 @@ index 7c5df0506..643f7216f 100644
269269
// Conditional Inclusion.
270270
void HandleIfdefDirective(Token &Result, const Token &HashToken,
271271
diff --git a/clang/include/clang/Lex/TokenLexer.h b/clang/include/clang/Lex/TokenLexer.h
272-
index 4d229ae61..35fae6c58 100644
272+
index 4d229ae61..923107b84 100644
273273
--- a/clang/include/clang/Lex/TokenLexer.h
274274
+++ b/clang/include/clang/Lex/TokenLexer.h
275275
@@ -13,7 +13,7 @@
@@ -291,6 +291,15 @@ index 4d229ae61..35fae6c58 100644
291291
/// This is the pointer to an array of tokens that the macro is
292292
/// defined to, with arguments expanded for function-like macros. If this is
293293
/// a token stream, these are the tokens we are returning. This points into
294+
@@ -98,7 +101,7 @@ class TokenLexer {
295+
296+
/// When true, the produced tokens have Token::IsReinjected flag set.
297+
/// See the flag documentation for details.
298+
- bool IsReinject : 1;
299+
+ bool IsReinject; // PASTA PATCH
300+
301+
public:
302+
/// Create a TokenLexer for the specified macro with the specified actual
294303
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
295304
index 9a8fd4391..b20144c12 100644
296305
--- a/clang/lib/Lex/PPDirectives.cpp
@@ -1554,7 +1563,7 @@ index 5310db3c8..31f31736a 100644
15541563

15551564
if (Result.is(tok::unknown) && TheModuleLoader.HadFatalFailure)
15561565
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp
1557-
index efda6d004..a4a33b091 100644
1566+
index efda6d004..4e8c9b78d 100644
15581567
--- a/clang/lib/Lex/TokenLexer.cpp
15591568
+++ b/clang/lib/Lex/TokenLexer.cpp
15601569
@@ -41,6 +41,8 @@ void TokenLexer::Init(Token &Tok, SourceLocation ELEnd, MacroInfo *MI,
@@ -1566,7 +1575,7 @@ index efda6d004..a4a33b091 100644
15661575
Macro = MI;
15671576
ActualArgs = Actuals;
15681577
CurTokenIdx = 0;
1569-
@@ -80,8 +82,34 @@ void TokenLexer::Init(Token &Tok, SourceLocation ELEnd, MacroInfo *MI,
1578+
@@ -80,8 +82,33 @@ void TokenLexer::Init(Token &Tok, SourceLocation ELEnd, MacroInfo *MI,
15701579

15711580
// If this is a function-like macro, expand the arguments and change
15721581
// Tokens to point to the expanded tokens.
@@ -1575,34 +1584,51 @@ index efda6d004..a4a33b091 100644
15751584
+ auto Callbacks = PP.getPPCallbacks();
15761585
+ if (ActualArgs && Callbacks) {
15771586
+ unsigned NumArgs = ActualArgs->getNumMacroArguments();
1578-
+ bool PreExpanded = false;
1587+
+ if (NumArgs && Macro->isVariadic() && ActualArgs->isVarargsElidedUse()) {
1588+
+ NumArgs -= 1u; // Last argument is `VariadicArgIndex`.
1589+
+ }
1590+
+
1591+
+ // In theory we only need to pre-expand what needs pre-expansion. In
1592+
+ // practice, Clang goes and sometimes requests pre-expansion for the
1593+
+ // sake of figuring out __VA_OPT__ stuff, via the
1594+
+ // `MacroArgs::invokedWithVariadicArgument` function.
1595+
+ Callbacks->Event(MacroNameTok, PPCallbacks::BeginPreArgumentExpansion,
1596+
+ reinterpret_cast<uintptr_t>(Macro));
1597+
+
1598+
+ // Pre expand each argument, which internally caches the results.
15791599
+ for (unsigned ArgNo = 0; ArgNo < NumArgs; ++ArgNo) {
1580-
+ const Token *ArgTok = ActualArgs->getUnexpArgument(ArgNo);
1581-
+ if (!ActualArgs->ArgNeedsPreexpansion(ArgTok, PP)) {
1582-
+ continue;
1583-
+ }
1584-
+
1585-
+ // Only pre-expand the argument if it could possibly need it. This
1586-
+ // avoids some work in common cases. We also want to ensure that we do
1587-
+ // pre-expansion in the order in which the arguments appear.
1588-
+ if (!PreExpanded) {
1589-
+ PreExpanded = true;
1590-
+ Callbacks->Event(MacroNameTok, PPCallbacks::BeginPreArgumentExpansion,
1591-
+ reinterpret_cast<uintptr_t>(Macro));
1592-
+ }
1600+
+ Callbacks->Event(MacroNameTok, PPCallbacks::BeginMacroCallArgument, 0);
15931601
+ (void) ActualArgs->getPreExpArgument(ArgNo, PP);
1602+
+ Callbacks->Event(MacroNameTok, PPCallbacks::EndMacroCallArgument, 0);
15941603
+ }
1595-
+ if (PreExpanded) {
1596-
+ Callbacks->Event(MacroNameTok, PPCallbacks::EndPreArgumentExpansion,
1597-
+ reinterpret_cast<uintptr_t>(Macro));
1598-
+ }
1604+
+
1605+
+ Callbacks->Event(MacroNameTok, PPCallbacks::EndPreArgumentExpansion,
1606+
+ reinterpret_cast<uintptr_t>(Macro));
15991607
+ }
16001608
ExpandFunctionArguments();
16011609
+ } // PASTA PATCH
16021610

16031611
// Mark the macro as currently disabled, so that it is not recursively
16041612
// expanded. The macro must be disabled only after argument pre-expansion of
1605-
@@ -625,6 +653,12 @@ bool TokenLexer::Lex(Token &Tok) {
1613+
@@ -251,6 +278,8 @@ void TokenLexer::ExpandFunctionArguments() {
1614+
1615+
VAOptExpansionContext VCtx(PP);
1616+
1617+
+ auto Callbacks = PP.getPPCallbacks(); // PASTA PATCH
1618+
+
1619+
for (unsigned I = 0, E = NumTokens; I != E; ++I) {
1620+
const Token &CurTok = Tokens[I];
1621+
// We don't want a space for the next token after a paste
1622+
@@ -451,7 +480,7 @@ void TokenLexer::ExpandFunctionArguments() {
1623+
// Only preexpand the argument if it could possibly need it. This
1624+
// avoids some work in common cases.
1625+
const Token *ArgTok = ActualArgs->getUnexpArgument(ArgNo);
1626+
- if (ActualArgs->ArgNeedsPreexpansion(ArgTok, PP))
1627+
+ if (Callbacks || ActualArgs->ArgNeedsPreexpansion(ArgTok, PP)) // PASTA PATCH
1628+
ResultArgToks = &ActualArgs->getPreExpArgument(ArgNo, PP)[0];
1629+
else
1630+
ResultArgToks = ArgTok; // Use non-preexpanded tokens.
1631+
@@ -625,6 +654,12 @@ bool TokenLexer::Lex(Token &Tok) {
16061632
// that it is no longer being expanded.
16071633
if (Macro) Macro->EnableMacro();
16081634

ports/llvm-15/vcpkg.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "llvm-15",
33
"version": "15.0.5",
4+
"port-version": 2,
45
"description": "The LLVM Compiler Infrastructure.",
56
"homepage": "https://llvm.org",
67
"license": "Apache-2.0",

0 commit comments

Comments
 (0)