[clang] [Clang] Support libstdc++ workarounds when using `-E` (PR #210802)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 24 07:30:13 PDT 2026
================
@@ -913,6 +913,48 @@ void Preprocessor::HandlePragmaHdrstop(Token &Tok) {
SkippingUntilPragmaHdrStop = false;
}
+bool Preprocessor::isPragmaSetPPStateMacro(IdentifierInfo *MacroName) {
+ return MacroName == Ident__GLIBCXX__;
+}
+
+void Preprocessor::HandlePragmaSetPPState(PragmaIntroducer Introducer,
+ Token &Tok) {
+ // Lex the macro name we want to set.
+ LexUnexpandedToken(Tok);
+ if (!Tok.getIdentifierInfo()) {
+ Diag(Tok.getLocation(), diag::err_pp_pragma_set_pp_state_expected_name);
+ return;
+ }
+
+ IdentifierInfo *MacroName = Tok.getIdentifierInfo();
+ if (!isPragmaSetPPStateMacro(MacroName)) {
+ Diag(Tok.getLocation(), diag::err_pp_pragma_set_pp_state_invalid_arg)
+ << MacroName;
+ return;
+ }
+
+ // Lex the integer argument.
+ Lex(Tok);
+ std::uint64_t Value;
+ if (!Tok.is(tok::numeric_constant) ||
+ !parseSimpleIntegerLiteral(Tok, Value)) {
+ Diag(Tok.getLocation(), diag::err_pp_pragma_set_pp_state_expected_int_after)
+ // Don't pass an IdentifierInfo* here to avoid quoting.
+ << MacroName->getName();
+ return;
+ }
+
+ // Update the state.
+ if (MacroName == Ident__GLIBCXX__) {
+ setStdLibCxxVersion(Value);
+ } else {
+ llvm_unreachable("forgot to handle a possible argument to __set_pp_state");
+ }
----------------
cor3ntin wrote:
And I think we are better off just looking at strings here - it's what we do elsewhere.
Comparing identifier info pointer makes sense where we do that very often - here we are likely to do it... a couple of times per TU at most
https://github.com/llvm/llvm-project/pull/210802
More information about the cfe-commits
mailing list