summaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/InitPreprocessor.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2025-11-03 07:50:25 -0500
committerGitHub <noreply@github.com>2025-11-03 07:50:25 -0500
commitdf1d786c460e0e47c9074f3533f098190ebfbc1b (patch)
tree0154a2150d37f9f81f3194657edd67c644d7a382 /clang/lib/Frontend/InitPreprocessor.cpp
parentef9ff15587cd0aa2676553b64ec3b11e36ebfd02 (diff)
[C2y] Support WG14 N3457, the __COUNTER__ macro (#162662)
This implements the parts of https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3457.htm which were adopted at the recent meeting in Brno. Clang already implemented `__COUNTER__`, but needed some changes for conformance. Specifically, we now diagnose when the macro is expanded more than 2147483647 times. Additionally, we now give the expected extension and pre-compat warnings for the feature. To support testing the limits, this also adds a -cc1-only option, `-finitial-counter-value=`, which lets you specify the initial value the `__COUNTER__` macro should expand to.
Diffstat (limited to 'clang/lib/Frontend/InitPreprocessor.cpp')
-rw-r--r--clang/lib/Frontend/InitPreprocessor.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 8602be1d8a17..ed3f1f93d25d 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1542,6 +1542,9 @@ void clang::InitializePreprocessor(Preprocessor &PP,
llvm::raw_string_ostream Predefines(PredefineBuffer);
MacroBuilder Builder(Predefines);
+ // Ensure that the initial value of __COUNTER__ is hooked up.
+ PP.setCounterValue(InitOpts.InitialCounterValue);
+
// Emit line markers for various builtin sections of the file. The 3 here
// marks <built-in> as being a system header, which suppresses warnings when
// the same macro is defined multiple times.