aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/PPExpressions.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-03[Clang] Slightly tweak the code to try to fix a potential codegen issue in ↵Corentin Jabot1-14/+6
#142592
2025-06-03[Clang] Improve infrastructure for libstdc++ workarounds (Reland) (#142592)cor3ntin1-0/+53
Reland with debug traces to try to understand a bug that only happens on one CI configuration === This introduces a way detect the libstdc++ version, use that to enable workarounds. The version is cached. This should make it easier in the future to find and remove these hacks. I did not find the need for enabling a hack between or after specific versions, so it's left as a future exercise. We can extend this fature to other libraries as the need arise. ===
2025-06-03Revert "[Clang] Improve infrastructure for libstdc++ workarounds" (#142432)cor3ntin1-46/+0
Reverts llvm/llvm-project#141977 This causes CI failure that I am unable to reproduce. https://lab.llvm.org/buildbot/#/builders/168/builds/12688
2025-05-31[Clang] Improve infrastructure for libstdc++ workarounds (#141977)cor3ntin1-0/+46
This introduces a way detect the libstdc++ version, use that to enable workarounds. The version is cached. This should make it easier in the future to find and remove these hacks. I did not find the need for enabling a hack between or after specific versions, so it's left as a future exercise. We can extend this fature to other libraries as the need arise.
2025-05-05[clang] Provide to `PPCallbacks` full expression range even in single file ↵Volodymyr Sapsai1-5/+6
parse mode. (#138358) Restore the behavior existing prior to fe2eefc4718f57e1753f7bd51c158fc03d70b34f. Make reporting of unevaluated directive source range more consistent and with fewer assumptions. In case of a failed evaluation don't assume any specific token and don't assume correct `PPValue` range tracking.
2025-04-09[clang][index] Handle undefined function-like macros in single file parse ↵Jan Svoboda1-0/+10
mode (#135054) The single file parse mode is supposed to enter both branches of an `#if` directive whenever the condition contains undefined identifiers. This patch adds support for undefined function-like macros, where we would previously emit an error that doesn't make sense from end-user perspective. (I discovered this while working on a very similar feature that parses single module only and doesn't enter either `#if` branch when the condition contains undefined identifiers.)
2025-04-08Reject invalid integer constants in unevaluated preprocessor operands (#134884)Aaron Ballman1-3/+1
Clang was previously accepting invalid code like: ``` #if 1 ? 1 : 999999999999999999999 #endif ``` because the integer constant (which is too large to fit into any standard or extended integer type) was in an unevaluated branch of the conditional operator. Similar invalid code involving || or && was also accepted and is now rejected. Fixes #134658
2025-03-02[clang][diagnostics] add `-Wundef-true` warning option (#128265)isuckatcs1-3/+5
New option `-Wundef-true` added and enabled by default to warn when `true` is used in the C preprocessor without being defined before C23.
2024-11-16[Lex] Remove unused includes (NFC) (#116460)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-06-20Reland [clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (#95802)Mariya Podchishchaeva1-13/+36
This commit implements the entirety of the now-accepted [N3017 -Preprocessor Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and its sister C++ paper [p1967](https://wg21.link/p1967). It implements everything in the specification, and includes an implementation that drastically improves the time it takes to embed data in specific scenarios (the initialization of character type arrays). The mechanisms used to do this are used under the "as-if" rule, and in general when the system cannot detect it is initializing an array object in a variable declaration, will generate EmbedExpr AST node which will be expanded by AST consumers (CodeGen or constant expression evaluators) or expand embed directive as a comma expression. This reverts commit https://github.com/llvm/llvm-project/commit/682d461d5a231cee54d65910e6341769419a67d7. --------- Co-authored-by: The Phantom Derpstorm <phdofthehouse@gmail.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
2024-06-12Revert "✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C ↵Vitaly Buka1-36/+13
and Obj-C++ by-proxy)" (#95299) Reverts llvm/llvm-project#68620 Introduce or expose a memory leak and UB, see llvm/llvm-project#68620
2024-06-12[clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and ↵The Phantom Derpstorm1-13/+36
Obj-C++ by-proxy) (#68620) This commit implements the entirety of the now-accepted [N3017 - Preprocessor Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and its sister C++ paper [p1967](https://wg21.link/p1967). It implements everything in the specification, and includes an implementation that drastically improves the time it takes to embed data in specific scenarios (the initialization of character type arrays). The mechanisms used to do this are used under the "as-if" rule, and in general when the system cannot detect it is initializing an array object in a variable declaration, will generate EmbedExpr AST node which will be expanded by AST consumers (CodeGen or constant expression evaluators) or expand embed directive as a comma expression. --------- Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: H. Vetinari <h.vetinari@gmx.com> Co-authored-by: Podchishchaeva, Mariya <mariya.podchishchaeva@intel.com>
2024-04-22[BitInt] Expose a _BitInt literal suffix in C++ (#86586)js3241-4/+4
This exposes _BitInt literal suffixes __wb and u__wb as an extension in C++. There is a new Extension warning, and the tests are essentially the same as the existing _BitInt literal tests for C but with a few additional cases. Fixes #85223
2024-02-06[CLANG] Fix INF/NAN warning. (#80290)Zahira Ammarguellat1-1/+3
In https://github.com/llvm/llvm-project/pull/76873 a warning was added when the macros INFINITY and NAN are used in binary expressions when -menable-no-nans or -menable-no-infs are used. If the user uses an option that nullifies these two options, the warning will still be generated. This patch adds an additional information to the warning comment to let the user know about this. It also suppresses the warning when #ifdef INFINITY, #ifdef NAN, #ifdef NAN or #ifndef NAN are used in the code.
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-1/+1
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-08-11[C23] Rename C2x->C23 in diagnosticsAaron Ballman1-2/+2
This renames C2x to C23 in diagnostic identifiers and messages. The changes were made mechanically.
2023-08-11[C23] Rename C2x -> C23; NFCAaron Ballman1-2/+2
This does the rename for most internal uses of C2x, but does not rename or reword diagnostics (those will be done in a follow-up). I also updated standards references and citations to the final wording in the standard.
2023-07-10[NFC] Initialize pointer fields and remove needless null check.Sindhu Chittireddy1-1/+1
Reviewed here: https://reviews.llvm.org/D153589
2023-05-04[clang] Use -std=c++23 instead of -std=c++2bMark de Wever1-4/+4
During the ISO C++ Committee meeting plenary session the C++23 Standard has been voted as technical complete. This updates the reference to c++2b to c++23 and updates the __cplusplus macro. Drive-by fixes c++1z -> c++17 and c++2a -> c++20 when seen. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D149553
2022-12-02Use CTAD on llvm::SaveAndRestoreJan Svoboda1-1/+1
Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D139229
2022-05-13[clang][preprocessor] Fix unsigned-ness of utf8 char literalsTimm Bäder1-1/+10
UTF8 char literals are always unsigned. Fixes https://github.com/llvm/llvm-project/issues/54886 Differential Revision: https://reviews.llvm.org/D124996
2022-03-14Implement literal suffixes for _BitIntAaron Ballman1-0/+8
WG14 adopted N2775 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2775.pdf) at our Feb 2022 meeting. This paper adds a literal suffix for bit-precise types that automatically sizes the bit-precise type to be the smallest possible legal _BitInt type that can represent the literal value. The suffix chosen is wb (for a signed bit-precise type) which can be combined with the u suffix (for an unsigned bit-precise type). The preprocessor continues to operate as-if all integer types were intmax_t/uintmax_t, including bit-precise integer types. It is a constraint violation if the bit-precise literal is too large to fit within that type in the context of the preprocessor (when still using a pp-number preprocessing token), but it is not a constraint violation in other circumstances. This allows you to make bit-precise integer literals that are wider than what the preprocessor currently supports in order to initialize variables, etc.
2021-10-03Fixed warnings in target/parser codes produced by -Wbitwise-instead-of-logicalaDávid Bolvanský1-2/+2
2021-07-29Support macro deprecation #pragma clang deprecatedChris Bieneman1-0/+2
This patch adds `#pragma clang deprecated` to enable deprecation of preprocessor macros. The macro must be defined before `#pragma clang deprecated`. When deprecating a macro a custom message may be optionally provided. Warnings are emitted at the use site of a deprecated macro, and can be controlled via the `-Wdeprecated` warning group. This patch takes some rough inspiration and a few lines of code from https://reviews.llvm.org/D67935. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D106732
2021-06-11[ADT] Remove APInt/APSInt toString() std::string variantsSimon Pilgrim1-4/+4
<string> is currently the highest impact header in a clang+llvm build: https://commondatastorage.googleapis.com/chromium-browser-clang/llvm-include-analysis.html One of the most common places this is being included is the APInt.h header, which needs it for an old toString() implementation that returns std::string - an inefficient method compared to the SmallString versions that it actually wraps. This patch replaces these APInt/APSInt methods with a pair of llvm::toString() helpers inside StringExtras.h, adjusts users accordingly and removes the <string> from APInt.h - I was hoping that more of these users could be converted to use the SmallString methods, but it appears that most end up creating a std::string anyhow. I avoided trying to use the raw_ostream << operators as well as I didn't want to lose having the integer radix explicit in the code. Differential Revision: https://reviews.llvm.org/D103888
2021-03-31[C++2b] Support size_t literalsAnton Bikineev1-0/+8
This adds support for C++2b's z/uz suffixes for size_t literals (P0330).
2021-01-27Don't allow __VA_OPT__ to be detected by #ifdef.Richard Smith1-5/+0
More study has discovered this to not actually be useful: because current C++20 implementations reject `#ifdef __VA_OPT__`, this can't really be used as a feature-test mechanism. And it's not too hard to detect __VA_OPT__ without this, for example: #define THIRD_ARG(a, b, c, ...) c #define HAS_VA_OPT(...) THIRD_ARG(__VA_OPT__(,), 1, 0, ) #if HAS_VA_OPT(?) Partially reverts 0436ec2128c9775ba13b0308937238fc79673fdd.
2021-01-27Permit __VA_OPT__ in all language modes and allow it to be detected with #ifdef.Richard Smith1-0/+5
These changes are intended to give code a path to move away from the GNU ,##__VA_ARGS__ extension, which is non-conforming in some situations and which we'd like to disable in our conforming mode in those cases.
2020-07-09Refactored NumericLiteralParser to not require a PreprocessorDmitri Gribenko1-1/+3
Summary: We would like to use NumericLiteralParser in the implementation of the syntax tree builder, and plumbing a preprocessor there seems inconvenient and superfluous. Reviewers: eduucaldas Reviewed By: eduucaldas Subscribers: gribozavr2, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D83480
2020-06-30[clang][diagnostics] Add '-Wundef-prefix' warning optionZixu Wang1-2/+20
Summary: Add an `-Wundef-prefix=<arg1>,<arg2>...` option, which is similar to `-Wundef`, but only give warnings for undefined macros with the given prefixes. Reviewers: ributzka, steven_wu, cishida, bruno, arphaman, rsmith Reviewed By: ributzka, arphaman Subscribers: riccibruno, dexonsmith, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D80751 This patch was authored by Zixu Wang <zixu_wang@apple.com>
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2019-01-17Revert r351209 (which was a revert of r350891) with a fix.Aaron Ballman1-6/+14
The test case had a parse error that was causing the condition string to be misreported. We now have better fallback code for error cases. llvm-svn: 351470
2019-01-15Revert "Correct the source range returned from preprocessor callbacks."Benjamin Kramer1-5/+5
This reverts commit r350891. Also add a test case that would return an empty string with r350891. llvm-svn: 351209
2019-01-11Add an explicit initializer to silence a -Wmissing-field-initializers ↵Aaron Ballman1-1/+1
diagnostic; NFC. llvm-svn: 350912
2019-01-10Correct the source range returned from preprocessor callbacks.Aaron Ballman1-4/+4
This adjusts the source range passed in to the preprocessor callbacks to only include the condition range itself, rather than all of the conditionally skipped tokens. llvm-svn: 350891
2018-07-30Remove trailing spaceFangrui Song1-5/+5
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2018-05-01Implement P0482R2, support for char8_t type.Richard Smith1-1/+1
This is not yet part of any C++ working draft, and so is controlled by the flag -fchar8_t rather than a -std= flag. (The GCC implementation is controlled by a flag with the same name.) This implementation is experimental, and will be removed or revised substantially to match the proposal as it makes its way through the C++ committee. llvm-svn: 331244
2017-07-14Keep the IdentifierInfo in the Token for alternative operator keywordOlivier Goffart1-27/+32
The goal of this commit is to fix clang-format so it does not merge tokens when using the alternative spelling keywords. (eg: "not foo" should not become "notfoo") The problem is that Preprocessor::HandleIdentifier used to drop the identifier info from the token for these keyword. This means the first condition of TokenAnnotator::spaceRequiredBefore is not met. We could add explicit check for the spelling in that condition, but I think it is better to keep the IdentifierInfo and handle the operator keyword explicitly when needed. That actually leads to simpler code, and probably slightly more efficient as well. Another side effect of this change is that __identifier(and) will now work as one would expect, removing a FIXME from the MicrosoftExtensions.cpp test Differential Revision: https://reviews.llvm.org/D35172 llvm-svn: 308008
2017-06-20[preprocessor] When preprocessor option 'SingleFileParseMode' is enabled, ↵Argyrios Kyrtzidis1-9/+20
parse all directive blocks if the condition uses undefined macros This is useful for being able to parse the preprocessor directive blocks even if the header, that defined the macro that is checked, hasn't been included. Differential Revision: https://reviews.llvm.org/D34263 llvm-svn: 305797
2016-09-07Fix some Clang-tidy modernize-use-using and Include What You Use warnings; ↵Eugene Zelenko1-4/+13
other minor fixes. Differential revision: https://reviews.llvm.org/D24115 llvm-svn: 280870
2016-04-16Improve diagnostic for the case when a non-defined function-like macro is usedRichard Smith1-4/+26
in a preprocessor constant expression. llvm-svn: 266495
2016-02-18Remove use of builtin comma operator.Richard Trieu1-2/+4
Cleanup for upcoming Clang warning -Wcomma. No functionality change intended. llvm-svn: 261271
2016-01-19Add -Wexpansion-to-undefined: warn when using `defined` in a macro definition.Nico Weber1-2/+47
[cpp.cond]p4: Prior to evaluation, macro invocations in the list of preprocessing tokens that will become the controlling constant expression are replaced (except for those macro names modified by the 'defined' unary operator), just as in normal text. If the token 'defined' is generated as a result of this replacement process or use of the 'defined' unary operator does not match one of the two specified forms prior to macro replacement, the behavior is undefined. This isn't an idle threat, consider this program: #define FOO #define BAR defined(FOO) #if BAR ... #else ... #endif clang and gcc will pick the #if branch while Visual Studio will take the #else branch. Emit a warning about this undefined behavior. One problem is that this also applies to function-like macros. While the example above can be written like #if defined(FOO) && defined(BAR) #defined HAVE_FOO 1 #else #define HAVE_FOO 0 #endif there is no easy way to rewrite a function-like macro like `#define FOO(x) (defined __foo_##x && __foo_##x)`. Function-like macros like this are used in practice, and compilers seem to not have differing behavior in that case. So this a default-on warning only for object-like macros. For function-like macros, it is an extension warning that only shows up with `-pedantic`. (But it's undefined behavior in both cases.) llvm-svn: 258128
2015-11-14Use %select to merge similar diagnostics. NFCCraig Topper1-2/+2
llvm-svn: 253119
2015-10-04SourceRanges are small and trivially copyable, don't them by reference.Craig Topper1-1/+1
llvm-svn: 249259
2015-06-22Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko1-1/+1
llvm-svn: 240353
2015-06-22Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko1-1/+1
The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
2015-05-04Switch PPCallbacks to take the new MacroDefinition instead of ↵Richard Smith1-3/+1
MacroDirective*, in order to preserve full information on module macro expansion. llvm-svn: 236404
2015-05-04Rename MacroDefinition -> MacroDefinitionRecord, ↵Richard Smith1-2/+2
Preprocessor::MacroDefinition -> MacroDefinition. clang::MacroDefinition now models the currently-defined value of a macro. The previous MacroDefinition type, which represented a record of a macro definition directive for a detailed preprocessing record, is now called MacroDefinitionRecord. llvm-svn: 236400
2015-05-02clang-format function definition header. NFC.Yaron Keren1-2/+1
llvm-svn: 236390