summaryrefslogtreecommitdiff
path: root/clang/test/Preprocessor/has_attribute.cpp
AgeCommit message (Collapse)Author
2025-04-15[clang] Clear `NeedsCleaning` flag after `ExpandBuiltinMacro` (#133574)marius doerner
After builtin macro expansion in `Preprocessor::ExpandBuiltinMacro` the result token may have the `Token::NeedsCleaning` flag set which causes an assertion failure later on when the lexer retrieves the spelling of the token in `getSpellingSlow`. This commit adds an `Tok.clearFlag(Token::NeedsCleaning)` call to the end of `ExpandBuiltinMacro`. Closes #128384
2024-03-01[Clang] Fix __has_cpp_attribute and C++11 attributes with arguments in C++03 ↵Nikolas Klauser
(#83065) The values for `__has_cpp_attribute` don't have to be guarded behind `LangOpts.CPlusPlus` because `__has_cpp_attribute` isn't available if Clang isn't in a C++ mode. Fixes #82995
2023-10-10[clang] Fix several issues in the generated AttrHasAttributeImpl.incSergei Barannikov
1. The generated file contained a lot of duplicate switch cases, e.g.: ``` switch (Syntax) { case AttributeCommonInfo::Syntax::AS_GNU: return llvm::StringSwitch<int>(Name) ... .Case("error", 1) .Case("warning", 1) .Case("error", 1) .Case("warning", 1) ``` 2. Some attributes were listed in wrong places, e.g.: ``` case AttributeCommonInfo::Syntax::AS_CXX11: { if (ScopeName == "") { return llvm::StringSwitch<int>(Name) ... .Case("warn_unused_result", LangOpts.CPlusPlus11 ? 201907 : 0) ``` `warn_unused_result` is a non-standard attribute and should not be available as [[warn_unused_result]]. 3. Some attributes had the wrong version, e.g.: ``` case AttributeCommonInfo::Syntax::AS_CXX11: { } else if (ScopeName == "gnu") { return llvm::StringSwitch<int>(Name) ... .Case("fallthrough", LangOpts.CPlusPlus11 ? 201603 : 0) ``` [[gnu::fallthrough]] is a non-standard spelling and should not have the standard version. Instead, __has_cpp_attribute should return 1 for it. There is another issue with attributes that share spellings, e.g.: ``` .Case("interrupt", true && (T.getArch() == llvm::Triple::arm || ...) ? 1 : 0) .Case("interrupt", true && (T.getArch() == llvm::Triple::avr) ? 1 : 0) ... .Case("interrupt", true && (T.getArch() == llvm::Triple::riscv32 || ...) ? 1 : 0) ``` As can be seen, __has_attribute(interrupt) would only return true for ARM targets. This patch does not address this issue. Differential Revision: https://reviews.llvm.org/D159393
2023-09-28Recommit "Implement [[msvc::no_unique_address]] (#65675)" (#67199)Amy Huang
This implements the [[msvc::no_unique_address]] attribute. There is not ABI compatibility in this patch because the attribute is relatively new and there's still some uncertainty in the MSVC version. The recommit changes the attribute definitions so that instead of making two separate attributes for no_unique_address and msvc::no_unique_address, it modifies the attributes tablegen emitter to allow spellings to be target-specific. This reverts commit 71f9e7695b87298f9855d8890f0e6a3b89381eb5.
2023-09-22Revert "Implement [[msvc::no_unique_address]] (#65675)" (#67198)Amy Huang
This reverts commit 4a55d426967b9c70f5dea7b3a389e11393a4f4c4. Reverting because this breaks sphinx documentation, and even with it fixed the format of the attribute makes the no_unique_address documentation show up twice.
2023-09-22Implement [[msvc::no_unique_address]] (#65675)Amy Huang
This implements the [[msvc::no_unique_address]] attribute. There is not ABI compatibility in this patch because the attribute is relatively new and there's still some uncertainty in the MSVC version. Bug: https://github.com/llvm/llvm-project/issues/49358 Also see https://reviews.llvm.org/D157762.
2021-10-17Lex arguments for __has_cpp_attribute and friends as expanded tokensAaron Ballman
The C and C++ standards require the argument to __has_cpp_attribute and __has_c_attribute to be expanded ([cpp.cond]p5). It would make little sense to expand the argument to those operators but not expand the argument to __has_attribute and __has_declspec, so those were both also changed in this patch. Note that it might make sense for the other builtins to also expand their argument, but it wasn't as clear to me whether the behavior would be correct there, and so they were left for a future revision.
2020-10-18[Sema, CodeGen] Implement [[likely]] and [[unlikely]] in SwitchStmtMark de Wever
This implements the likelihood attribute for the switch statement. Based on the discussion in D85091 and D86559 it only handles the attribute when placed on the case labels or the default labels. It also marks the likelihood attribute as feature complete. There are more QoI patches in the pipeline. Differential Revision: https://reviews.llvm.org/D89210
2020-09-09Implements [[likely]] and [[unlikely]] in IfStmt.Mark de Wever
This is the initial part of the implementation of the C++20 likelihood attributes. It handles the attributes in an if statement. Differential Revision: https://reviews.llvm.org/D85091
2019-08-15Allow standards-based attributes to have leading and trailing underscores.Aaron Ballman
This gives library implementers a way to use standards-based attributes that do not conflict with user-defined macros of the same name. Attributes in C2x require this behavior normatively (C2x 6.7.11p4), but there's no reason to not have the same behavior in C++, especially given that such attributes may be used by a C library consumed by a C++ compilation. llvm-svn: 369033
2019-07-25Implement P1771Erich Keane
As passed in the Cologne meeting and treated by Core as a DR, [[nodiscard]] was applied to constructors so that they can be diagnosed in cases where the user forgets a variable name for a type. The intent is to enable the library to start using this on the constructors of scope_guard/lock_guard. Differential Revision: https://reviews.llvm.org/D64914 llvm-svn: 367027
2019-07-22Revert the change to the [[nodiscard]] feature test macro value.Aaron Ballman
This value only gets bumped once both P1301 and P1771 are implemented. llvm-svn: 366682
2019-07-20Implement P1301R4, which allows specifying an optional message on the ↵Aaron Ballman
[[nodiscard]] attribute. This also bumps the attribute feature test value and introduces the notion of a C++2a extension warning. llvm-svn: 366626
2019-06-21Fix has_attribute.cpp test on Windows after r364102Reid Kleckner
llvm-svn: 364108
2019-06-21Fix __has_cpp_attribute expansion to produce trailing L and (whereRichard Smith
necessary) leading whitespace. Simplify unit test and extend to cover no_unique_address attribute. llvm-svn: 364102
2018-11-09Introduce the _Clang scoped attribute token.Aaron Ballman
Currently, we only accept clang as the scoped attribute identifier for double square bracket attributes provided by Clang, but this has the potential to conflict with user-defined macros. To help alleviate these concerns, this introduces the _Clang scoped attribute identifier as an alias for clang. It also introduces a warning with a fixit on the off chance someone attempts to use __clang__ as the scoped attribute (which is a predefined compiler identification macro). llvm-svn: 346521
2018-10-24Support accepting __gnu__ as a scoped attribute namespace that aliases to gnu.Aaron Ballman
This is useful in libstdc++ to avoid clashes with identifiers in the user's namespace. llvm-svn: 345132
2016-03-08Define __has_cpp_attribute(fallthrough) to a more reasonable value. (What ↵Richard Smith
year is it?!) llvm-svn: 262887
2014-12-05Added a new preprocessor macro: __has_declspec_attribute. This can be used ↵Aaron Ballman
as a way to determine whether Clang supports a __declspec spelling for a given attribute, similar to __has_attribute and __has_cpp_attribute. llvm-svn: 223467
2014-11-20Convert CR+LF -> LF in a test fileTimur Iskhodzhanov
llvm-svn: 222429
2014-11-20Avoid earlier test interfering with later one.Richard Smith
llvm-svn: 222403
2014-11-14Complete support for the SD-6 standing document (based off N4200) with ↵Aaron Ballman
support for __has_cpp_attribute. llvm-svn: 221991