aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/IdentifierTable.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-31[Basic] Remove unused includes (NFC) (#142295)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-02Simplify implementation; NFCAaron Ballman1-16/+2
Suggestion came via post-commit review feedback
2025-05-02[C] Diagnose use of C++ keywords in C (#137234)Aaron Ballman1-5/+43
This adds a new diagnostic group, -Wc++-keyword, which is off by default and grouped under -Wc++-compat. The diagnostic catches use of C++ keywords in C code. This change additionally fixes an issue with -Wreserved-identifier not diagnosing use of reserved identifiers in function parameter lists in a function declaration which is not a definition. Fixes https://github.com/llvm/llvm-project/issues/21898
2024-10-11Turn `-Wdeprecated-literal-operator` on by default (#111027)Erich Keane1-0/+3
It would be nice to see what our users think about this change, as this is something that WG21/EWG quite wants to fix a handful of questionable issues with UB. Depending on the outcome of this after being committed, we might instead suggest EWG undeprecate this, and require a bit of 'magic' from the lexer. Additionally, this patch makes it so we emit this diagnostic ALSO in cases where the literal name is reserved. It doesn't make sense to limit that. --------- Co-authored-by: Vlad Serebrennikov <serebrennikov.vladislav@gmail.com>
2024-08-08[SystemZ][z/OS] __ptr32 support for z/OS (#101696)Abhina Sree1-7/+11
Enabling __ptr32 keyword to support in Clang for z/OS. It is represented by addrspace(1) in LLVM IR. Unlike existing implementation, __ptr32 is not mangled into symbol names for z/OS.
2024-08-07[NFC] Format TokenKey enum (#101700)Abhina Sree1-43/+43
This is to fix the white-space formatting of the TokenKey enum
2024-07-22Revert "[Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros" ↵yronglin1-2/+1
(#99838) Reverts llvm/llvm-project#90574
2024-07-20[Clang] Implement P3034R1 Module Declarations Shouldn’t be Macros (#90574)yronglin1-1/+2
This PR implement [P3034R1 Module Declarations Shouldn’t be Macros](https://wg21.link/P3034R1), and refactor the convoluted state machines in module name lexical analysis. --------- Signed-off-by: yronglin <yronglin777@gmail.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2024-06-20Reland [clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (#95802)Mariya Podchishchaeva1-2/+3
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-3/+2
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-2/+3
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-11[NFC][Clang] Improve const correctness for IdentifierInfo (#79365)Bill Wendling1-7/+9
The IdentifierInfo isn't typically modified. Use 'const' wherever possible.
2024-02-14[clang][NFC] Use "notable" for "interesting" identifiers in `IdentifierInfo` ↵Vlad Serebrennikov1-9/+9
(#81542) This patch expands notion of "interesting" in `IdentifierInto` it to also cover ObjC keywords and builtins, which matches notion of "interesting" in serialization layer. What was previously "interesting" in `IdentifierInto` is now called "notable". Beyond clearing confusion between serialization and the rest of the compiler, it also resolved a naming problem: ObjC keywords, notable identifiers, and builtin IDs are all stored in the same bit-field. Now we can use "interesting" to name it and its corresponding type, instead of `ObjCKeywordOrInterestingOrBuiltin` abomination.
2023-12-27[clang] Use StringRef::ltrim (NFC)Kazu Hirata1-2/+1
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-2/+2
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-11-13[clang] Remove fixed point arithmetic error (#71884)PiJoules1-1/+4
Prior to this, clang would always report ``` compile with '-ffixed-point' to enable fixed point types ``` whenever it sees `_Accum`, `_Fract`, or `_Sat` when fixed point arithmetic is not enabled. This can break existing code that uses these as variable names and doesn't use fixed point arithmetic like in some microsoft headers (https://github.com/llvm/llvm-project/pull/67750#issuecomment-1775264907). Fixed point should not raise this error for these cases, so this removes the error altogether and defaults to the usual error clang gives where it can see these keywords as either unknown types or regular variables.
2023-10-25[clang][NFC] Refactor `Selector` to use `PointerIntPair` inside (#69916)Vlad Serebrennikov1-58/+1
Refactor `uintptr_t` inside of `clang::Selector` that holds a pointer to `IdentifierInfo` or `MultiKeywordSelector` and `IdentifierInfoFlag` enum into `PointerIntPair`. This is a part of `PointerIntPair` migration outlined in https://github.com/llvm/llvm-project/issues/69835. Unlike `uintpt_t`, `PointerIntPair` required pointee types to be complete, so I had to shuffle definitions of `MultiKeywordSelector` and `detail::DeclarationNameExtra` around to make them complete at `Selector`. Also, there were outdated specializations of `PointerLikeTypeTraits` for `IdentifierInfo *`, which are no longer needed, because `alignof` that primary template use works just fine. Not just that, but they declared that `IdentifierInfo *` has only 1 spare lower bit, but today they are 8-byte aligned.
2023-09-14[NFC] Minimize header includes (#66339)Bill Wendling1-3/+1
Minimize the headers included in header files to reduce the number of files that need recompiled after a change.
2023-08-11[C23] Rename C2x->C23 in diagnosticsAaron Ballman1-1/+1
This renames C2x to C23 in diagnostic identifiers and messages. The changes were made mechanically.
2023-08-11[C23] Rename C2x -> C23; NFCAaron Ballman1-4/+4
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-19[Clang] Add warnings for CWG2521Po-yao Chang1-0/+13
1. Teach -Wuser-defined-literals to warn on using double underscores in literal suffix identifiers. 2. Add -Wdeprecated-literal-operator to warn about the use of the first grammar production of literal-operator-id, which defaults to off for now. Differential Revision: https://reviews.llvm.org/D152632
2023-06-22[clang] Add a namespace for interesting identifiers.Zahira Ammarguellat1-0/+13
Differential Revision: https://reviews.llvm.org/D146148
2023-06-08Fix namespace of operator<< defnSam McCall1-1/+2
2023-05-08Reland "Give NullabilityKind a printing operator<<"Sam McCall1-0/+14
This reverts commit 5326c9e480d70e16c2504cb5143524aff3ee2605. The problem that caused the revert was downstream (missing dep in user of clang).
2023-05-05Revert "Give NullabilityKind a printing operator<<"Caroline Tice1-14/+0
This reverts commit 0a532207b8696d81e46017f444bd2257347f129b. This breaks several of our tests. Have given reproducers to author. Reverting this until author can fix the issue.
2023-05-04Give NullabilityKind a printing operator<<Sam McCall1-0/+14
This is more useful for debug/test than getNullabilitySpelling: - default form has uglifying underscores - non-default form crashes on NullableResult - both return unhelpfully verbose strings for Unspecified - operator<< works with gtest, formatv, etc Differential Revision: https://reviews.llvm.org/D149650
2023-02-16[Modules] Remove -fmodules-tsChuanqi Xu1-1/+1
As the diagnostic message shows, we should remove -fmodules-ts flag in clang/llvm17. Since clang/llvm16 is already branched. We can remove the depreacared flag now.
2022-09-21[HLSL] Support cbuffer/tbuffer for hlsl.Xiang Li1-1/+4
This is first part for support cbuffer/tbuffer. The format for cbuffer/tbuffer is BufferType [Name] [: register(b#)] { VariableDeclaration [: packoffset(c#.xyzw)]; ... }; More details at https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-constants New keyword 'cbuffer' and 'tbuffer' are added. New AST node HLSLBufferDecl is added. Build AST for simple cbuffer/tbuffer without attribute support. The special thing is variables declared inside cbuffer is exposed into global scope. So isTransparentContext should return true for HLSLBuffer. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D129883
2022-08-26Fix the lldb test botsAaron Ballman1-19/+23
This addresses an accidental change in behavior from 41667a8b9b624e282e7c08fadf7091223728d1c1 to get the bots back to green. However, I think there's an issue with LLDB assuming it's valid to enable support for keywords in language modes that don't support the keyword (as other parts of Clang are not expecting to be able to do that). This should fix (and others): https://lab.llvm.org/buildbot/#/builders/68/builds/38374
2022-08-26[Basic] Drop header-only dependency from Basic to LexBenjamin Kramer1-0/+1
It's still a bit weird for IdentifierTable to depend on Lex diagnostics, but we can get away with including the enum info that's in Basic already.
2022-08-26Diagnosing the Future KeywordsMuhammad Usman Shahid1-31/+58
The patch diagnoses an identifier as a future keyword if it exists in a future language mode, such as: int restrict; in C modes earlier than C99. We now give a warning to the user that such an identifier is a future keyword. Handles keywords from C as well as C++. Differential Revision: https://reviews.llvm.org/D131683
2022-08-03Fix char8_t in C mode regression from fb65b179Erich Keane1-1/+2
When doing that NFC refactor, I'd messed up how char8_t was reported, which resulted in it being considered a 'future' keyword, without the corresponding diagnostic, which lead to an assert. This patch corrects the char8_t to ONLY be future in C++ mode.
2022-08-03[NFCI] Refactor how KeywordStatus is calculatedErich Keane1-55/+122
The getKeywordStatus function is a horrible mess of inter-dependent 'if' statements that depend significantly on the ORDER of the checks. This patch removes the dependency on order by checking each set-flag only once. It does this by looping through each of the set bits, and checks each individual flag for its effect, then combines them at the end. This might slow down startup performance slightly, as there are only a few hundred keywords, and a vast majority will only get checked 1x still. This patch ALSO removes the KEYWORD_CONCEPTS flag, because it has since become synonymous with C++20. Differential Revision: https://reviews.llvm.org/D131007
2022-05-11[clang] Fix KEYALLYaxun (Sam) Liu1-2/+3
Update KEYALL to cover KEYCUDA. Introduce KEYMAX and a generic way to update KEYALL. Reviewed by: Dan Liew Differential Revision: https://reviews.llvm.org/D125396
2022-05-10[CUDA][HIP] support __noinline__ as keywordYaxun (Sam) Liu1-0/+3
CUDA/HIP programs use __noinline__ like a keyword e.g. __noinline__ void foo() {} since __noinline__ is defined as a macro __attribute__((noinline)) in CUDA/HIP runtime header files. However, gcc and clang supports __attribute__((__noinline__)) the same as __attribute__((noinline)). Some C++ libraries use __attribute__((__noinline__)) in their header files. When CUDA/HIP programs include such header files, clang will emit error about invalid attributes. This patch fixes this issue by supporting __noinline__ as a keyword, so that CUDA/HIP runtime could remove the macro definition. Reviewed by: Aaron Ballman, Artem Belevich Differential Revision: https://reviews.llvm.org/D124866
2022-01-26[CodeCompletion][clangd] Clean __uglified parameter names in completion & hoverSam McCall1-0/+8
Underscore-uglified identifiers are used in standard library implementations to guard against collisions with macros, and they hurt readability considerably. (Consider `push_back(Tp_ &&__value)` vs `push_back(Tp value)`. When we're describing an interface, the exact names of parameters are not critical so we can drop these prefixes. This patch adds a new PrintingPolicy flag that can applies this stripping when recursively printing pieces of AST. We set it in code completion/signature help, and in clangd's hover display. All three features also do a bit of manual poking at names, so fix up those too. Fixes https://github.com/clangd/clangd/issues/736 Differential Revision: https://reviews.llvm.org/D116387
2021-05-27Correct the 'KEYALL' mask.Erich Keane1-1/+1
It should technically be a 1, since we are only setting the first bit.
2021-05-27Reimplement __builtin_unique_stable_name-Erich Keane1-1/+4
The original version of this was reverted, and @rjmcall provided some advice to architect a new solution. This is that solution. This implements a builtin to provide a unique name that is stable across compilations of this TU for the purposes of implementing the library component of the unnamed kernel feature of SYCL. It does this by running the Itanium mangler with a few modifications. Because it is somewhat common to wrap non-kernel-related lambdas in macros that aren't present on the device (such as for logging), this uniquely generates an ID for all lambdas involved in the naming of a kernel. It uses the lambda-mangling number to do this, except replaces this with its own number (starting at 10000 for readabililty reasons) for lambdas used to name a kernel. Additionally, this implements itself as constexpr with a slight catch: if a name would be invalidated by the use of this lambda in a later kernel invocation, it is diagnosed as an error (see the Sema tests). Differential Revision: https://reviews.llvm.org/D103112
2021-05-27Add support for #elifdef and #elifndefAaron Ballman1-0/+2
WG14 adopted N2645 and WG21 EWG has accepted P2334 in principle (still subject to full EWG vote + CWG review + plenary vote), which add support for #elifdef as shorthand for #elif defined and #elifndef as shorthand for #elif !defined. This patch adds support for the new preprocessor directives.
2021-05-04Introduce -Wreserved-identifierserge-sans-paille1-0/+33
Warn when a declaration uses an identifier that doesn't obey the reserved identifier rule from C and/or C++. Differential Revision: https://reviews.llvm.org/D93095
2021-03-15Allow __ieee128 as an alias to __float128 on ppcserge-sans-paille1-0/+3
This matches gcc behavior. Differential Revision: https://reviews.llvm.org/D97846
2020-12-07[clang] Add a new nullability annotation for swift async: _Nullable_resultErik Pilkington1-0/+5
_Nullable_result generally like _Nullable, except when being imported into a swift async method. rdar://70106409 Differential revision: https://reviews.llvm.org/D92495
2020-06-26Revert rGf0bab7875e78e01c149d12302dcc4b6d4c43e25c - "Triple.h - reduce ↵Simon Pilgrim1-1/+0
Twine.h include to forward declarations. NFC." This causes ICEs on the clang-ppc64be buildbots and I've limited ability to triage the problem.
2020-06-26Triple.h - reduce Twine.h include to forward declarations. NFC.Simon Pilgrim1-0/+1
Move include down to a number of other files that had an implicit dependency on the Twine class.
2020-05-07Add static assert to ID Table to make sure aux targets work right.Erich Keane1-0/+7
I discovered that the limit on possible builtins managed by this ObjCOrBuiltin variable is too low when combining large targets, since aux-targets are appended to the targets list. A runtime assert exists for this, however this patch creates a static-assert as well. The logic for said static-assert is to make sure we have the room for the aux-target and target to both be the largest list, which makes sure we have room for all possible combinations. I also incremented the number of bits by 1, since I discovered this currently broken. The current bit-count was 36, so this doesn't increase any size.
2020-04-28Make -fno-char8_t disable the char8_t keyword, even in C++20.Richard Smith1-0/+2
This fixes a regression introduced in r354736, and makes our behavior compatible with that of Clang 8 and GCC.
2020-04-21C++2a -> C++20 in some identifiers; NFC.Aaron Ballman1-5/+5
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer1-2/+2
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2020-01-24[Concepts] Deprecate -fconcepts-ts, enable Concepts under -std=c++2aSaar Raz1-1/+1
Now with concepts support merged and mostly complete, we do not need -fconcepts-ts (which was also misleading as we were not implementing the TS) and can enable concepts features under C++2a. A warning will be generated if users still attempt to use -fconcepts-ts.
2019-08-14[Sema][ObjC] Fix a -Wformat false positive with localizedStringForKeyErik Pilkington1-0/+15
Only honour format_arg attributes on -[NSBundle localizedStringForKey] when its argument has a format specifier in it, otherwise its likely to just be a key to fetch localized strings. Fixes rdar://23622446 Differential revision: https://reviews.llvm.org/D27165 llvm-svn: 368878