Skip to content

Commit 0e0ec98

Browse files
committed
Revert "[C2y] Support WG14 N3457, the __COUNTER__ macro (llvm#162662)"
This reverts commit df1d786.
1 parent 8d8e9eb commit 0e0ec98

File tree

17 files changed

+18
-132
lines changed

17 files changed

+18
-132
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,7 @@ Builtin Macros
382382

383383
``__COUNTER__``
384384
Defined to an integer value that starts at zero and is incremented each time
385-
the ``__COUNTER__`` macro is expanded. This is a standard feature in C2y but
386-
is an extension in earlier language modes and in C++. This macro can only be
387-
expanded 2147483647 times at most.
385+
the ``__COUNTER__`` macro is expanded.
388386

389387
``__INCLUDE_LEVEL__``
390388
Defined to an integral value that is the include depth of the file currently
@@ -1820,7 +1818,6 @@ Octal literals prefixed with ``0o`` or ``0O`` C
18201818
``_Countof`` (N3369, N3469) C2y C89
18211819
``_Generic`` with a type operand (N3260) C2y C89, C++
18221820
``++``/``--`` on ``_Complex`` value (N3259) C2y C89, C++
1823-
``__COUNTER__`` (N3457) C2y C89, C++
18241821
============================================= ================================ ============= =============
18251822

18261823
Builtin type aliases

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,6 @@ C2y Feature Support
196196
function or variable within an extern inline function is no longer a
197197
constraint per `WG14 N3622 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3622.txt>`_.
198198
- Clang now supports `N3355 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm>`_ Named Loops.
199-
- Clang's implementation of ``__COUNTER__`` was updated to conform to
200-
`WG14 N3457 <https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3457.htm>`_.
201-
This includes adding pedantic warnings for the feature being an extension in
202-
other language modes as well as an error when the counter is expanded more
203-
than 2147483647 times.
204199

205200
C23 Feature Support
206201
^^^^^^^^^^^^^^^^^^^

clang/include/clang/Basic/DiagnosticLexKinds.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,6 @@ def err_unterminated___pragma : Error<"missing terminating ')' character">;
9090

9191
def err_conflict_marker : Error<"version control conflict marker in file">;
9292

93-
def err_counter_overflow : Error<
94-
"'__COUNTER__' value cannot exceed 2'147'483'647">;
95-
def ext_counter : Extension<
96-
"'__COUNTER__' is a C2y extension">, InGroup<C2y>;
97-
def warn_counter : Warning<
98-
"'__COUNTER__' is incompatible with standards before C2y">,
99-
InGroup<CPre2yCompat>, DefaultIgnore;
100-
10193
def err_raw_delim_too_long : Error<
10294
"raw string delimiter longer than 16 characters"
10395
"; use PREFIX( )PREFIX to delimit raw string">;

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8628,10 +8628,6 @@ def aligned_alloc_unavailable : Flag<["-"], "faligned-alloc-unavailable">,
86288628
MarshallingInfoFlag<LangOpts<"AlignedAllocationUnavailable">>,
86298629
ShouldParseIf<faligned_allocation.KeyPath>;
86308630

8631-
def finitial_counter_value_EQ : Joined<["-"], "finitial-counter-value=">,
8632-
HelpText<"Sets the initial value for __COUNTER__, defaults to 0.">,
8633-
MarshallingInfoInt<PreprocessorOpts<"InitialCounterValue">, "0">;
8634-
86358631
} // let Visibility = [CC1Option]
86368632

86378633
//===----------------------------------------------------------------------===//

clang/include/clang/Lex/Preprocessor.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class Preprocessor {
226226
LangOptions::FPEvalMethodKind::FEM_UnsetOnCommandLine;
227227

228228
// Next __COUNTER__ value, starts at 0.
229-
uint32_t CounterValue = 0;
229+
unsigned CounterValue = 0;
230230

231231
enum {
232232
/// Maximum depth of \#includes.
@@ -2421,8 +2421,8 @@ class Preprocessor {
24212421
bool SawDateOrTime() const {
24222422
return DATELoc != SourceLocation() || TIMELoc != SourceLocation();
24232423
}
2424-
uint32_t getCounterValue() const { return CounterValue; }
2425-
void setCounterValue(uint32_t V) { CounterValue = V; }
2424+
unsigned getCounterValue() const { return CounterValue; }
2425+
void setCounterValue(unsigned V) { CounterValue = V; }
24262426

24272427
LangOptions::FPEvalMethodKind getCurrentFPEvalMethod() const {
24282428
assert(CurrentFPEvalMethod != LangOptions::FEM_UnsetOnCommandLine &&

clang/include/clang/Lex/PreprocessorOptions.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ class PreprocessorOptions {
198198
/// If set, the UNIX timestamp specified by SOURCE_DATE_EPOCH.
199199
std::optional<uint64_t> SourceDateEpoch;
200200

201-
/// The initial value for __COUNTER__; typically is zero but can be set via a
202-
/// -cc1 flag for testing purposes.
203-
uint32_t InitialCounterValue = 0;
204-
205201
public:
206202
PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
207203

clang/include/clang/Serialization/ASTReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ class ASTReaderListener {
220220
}
221221

222222
/// Receives __COUNTER__ value.
223-
virtual void ReadCounter(const serialization::ModuleFile &M, uint32_t Value) {
224-
}
223+
virtual void ReadCounter(const serialization::ModuleFile &M,
224+
unsigned Value) {}
225225

226226
/// This is called for each AST file loaded.
227227
virtual void visitModuleFile(StringRef Filename,
@@ -312,7 +312,7 @@ class ChainedASTReaderListener : public ASTReaderListener {
312312
bool Complain,
313313
std::string &SuggestedPredefines) override;
314314

315-
void ReadCounter(const serialization::ModuleFile &M, uint32_t Value) override;
315+
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
316316
bool needsInputFileVisitation() override;
317317
bool needsSystemInputFileVisitation() override;
318318
void visitModuleFile(StringRef Filename,
@@ -352,7 +352,7 @@ class PCHValidator : public ASTReaderListener {
352352
StringRef ModuleFilename,
353353
StringRef SpecificModuleCachePath,
354354
bool Complain) override;
355-
void ReadCounter(const serialization::ModuleFile &M, uint32_t Value) override;
355+
void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
356356
};
357357

358358
/// ASTReaderListenter implementation to set SuggestedPredefines of

clang/lib/Frontend/ASTUnit.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,14 @@ class ASTInfoCollector : public ASTReaderListener {
518518
LangOptions &LangOpts;
519519
CodeGenOptions &CodeGenOpts;
520520
TargetOptions &TargetOpts;
521-
uint32_t &Counter;
521+
unsigned &Counter;
522522

523523
public:
524524
ASTInfoCollector(HeaderSearchOptions &HSOpts,
525525
std::string &SpecificModuleCachePath,
526526
PreprocessorOptions &PPOpts, LangOptions &LangOpts,
527527
CodeGenOptions &CodeGenOpts, TargetOptions &TargetOpts,
528-
uint32_t &Counter)
528+
unsigned &Counter)
529529
: HSOpts(HSOpts), SpecificModuleCachePath(SpecificModuleCachePath),
530530
PPOpts(PPOpts), LangOpts(LangOpts), CodeGenOpts(CodeGenOpts),
531531
TargetOpts(TargetOpts), Counter(Counter) {}
@@ -577,7 +577,7 @@ class ASTInfoCollector : public ASTReaderListener {
577577
}
578578

579579
void ReadCounter(const serialization::ModuleFile &M,
580-
uint32_t NewCounter) override {
580+
unsigned NewCounter) override {
581581
Counter = NewCounter;
582582
}
583583
};

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,9 +1545,6 @@ void clang::InitializePreprocessor(Preprocessor &PP,
15451545
llvm::raw_string_ostream Predefines(PredefineBuffer);
15461546
MacroBuilder Builder(Predefines);
15471547

1548-
// Ensure that the initial value of __COUNTER__ is hooked up.
1549-
PP.setCounterValue(InitOpts.InitialCounterValue);
1550-
15511548
// Emit line markers for various builtin sections of the file. The 3 here
15521549
// marks <built-in> as being a system header, which suppresses warnings when
15531550
// the same macro is defined multiple times.

clang/lib/Lex/PPMacroExpansion.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,19 +1735,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
17351735
Diag(getLastFPEvalPragmaLocation(), diag::note_pragma_entered_here);
17361736
}
17371737
} else if (II == Ident__COUNTER__) {
1738-
Diag(Tok.getLocation(),
1739-
getLangOpts().C2y ? diag::warn_counter : diag::ext_counter);
1740-
// __COUNTER__ expands to a simple numeric value that must be less than
1741-
// 2147483647.
1742-
constexpr uint32_t MaxPosValue = std::numeric_limits<int32_t>::max();
1743-
if (CounterValue > MaxPosValue) {
1744-
Diag(Tok.getLocation(), diag::err_counter_overflow);
1745-
// Retain the maximal value so we don't issue conversion-related
1746-
// diagnostics by overflowing into a long long. While this does produce
1747-
// a duplicate value, there's no way to ignore this error so there's no
1748-
// translation anyway.
1749-
CounterValue = MaxPosValue;
1750-
}
1738+
// __COUNTER__ expands to a simple numeric value.
17511739
OS << CounterValue++;
17521740
Tok.setKind(tok::numeric_constant);
17531741
} else if (II == Ident__has_feature) {

0 commit comments

Comments
 (0)