Index: include/clang/Basic/DiagnosticLexKinds.td =================================================================== --- include/clang/Basic/DiagnosticLexKinds.td +++ include/clang/Basic/DiagnosticLexKinds.td @@ -326,6 +326,8 @@ def warn_pp_objc_macro_redef_ignored : Warning< "ignoring redefinition of Objective-C qualifier macro">, InGroup>; +def warn_pp_macro_deprecated : Warning<"%0 is deprecated">, + InGroup; def pp_invalid_string_literal : Warning< "invalid string literal, ignoring final '\\'">; Index: lib/Lex/PPMacroExpansion.cpp =================================================================== --- lib/Lex/PPMacroExpansion.cpp +++ lib/Lex/PPMacroExpansion.cpp @@ -513,6 +513,18 @@ // Notice that this macro has been used. markMacroAsUsed(MI); + // C17 7.31.8p2 + // If the macro is named ATOMIC_VAR_INIT and it came from the stdatomic.h + // header file, diagnose it as being deprecated. This macro does not exist + // in C++, so do not trigger a deprecation warning in that language mode. + if (!getLangOpts().CPlusPlus && + Identifier.getIdentifierInfo()->isStr("ATOMIC_VAR_INIT") && + llvm::sys::path::filename(getSourceManager().getFilename( + M.getLocalDirective()->getLocation())) == "stdatomic.h") { + Diag(Identifier, diag::warn_pp_macro_deprecated) + << Identifier.getIdentifierInfo(); + } + // Remember where the token is expanded. SourceLocation ExpandLoc = Identifier.getLocation(); SourceRange ExpansionRange(ExpandLoc, ExpansionEnd); Index: test/Preprocessor/Inputs/atomic_var_init/stdatomic.h =================================================================== --- test/Preprocessor/Inputs/atomic_var_init/stdatomic.h +++ test/Preprocessor/Inputs/atomic_var_init/stdatomic.h @@ -0,0 +1 @@ +#define ATOMIC_VAR_INIT(x) (x) Index: test/Preprocessor/atomic_var_init.c =================================================================== --- test/Preprocessor/atomic_var_init.c +++ test/Preprocessor/atomic_var_init.c @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 %s -fsyntax-only -verify -Wdeprecated -isystem Inputs/atomic_var_init + +// Do not diagnose if the macro is not defined in stdatomic.h because it could +// be a user-defined macro instead then. +#define ATOMIC_VAR_INIT(x) (x) +_Atomic int a = ATOMIC_VAR_INIT(12); +#undef ATOMIC_VAR_INIT + +// Diagnose use of the macro from stdatomic.h +#include +_Atomic int i = ATOMIC_VAR_INIT(12); // expected-warning {{'ATOMIC_VAR_INIT' is deprecated}} + +#define FOO(x) ATOMIC_VAR_INIT(x) +_Atomic int j = FOO(12); // expected-warning {{'ATOMIC_VAR_INIT' is deprecated}} + +// Do not diagnose use in conditional inclusion directives. +#ifdef ATOMIC_VAR_INIT +#elif defined(ATOMIC_VAR_INIT) +#endif +