aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/LangOptions.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-09-02[Clang] [C2y] Implement N3355 ‘Named Loops’ (#152870)Sirraide1-0/+1
This implements support for [named loops](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm) for C2y. When parsing a `LabelStmt`, we create the `LabeDecl` early before we parse the substatement; this label is then passed down to `ParseWhileStatement()` and friends, which then store it in the loop’s (or switch statement’s) `Scope`; when we encounter a `break/continue` statement, we perform a lookup for the label (and error if it doesn’t exist), and then walk the scope stack and check if there is a scope whose preceding label is the target label, which identifies the jump target. The feature is only supported in C2y mode, though a cc1-only option exists for testing (`-fnamed-loops`), which is mostly intended to try and make sure that we don’t have to refactor this entire implementation when/if we start supporting it in C++. --------- Co-authored-by: Balazs Benics <benicsbalazs@gmail.com>
2025-07-07[clang] Refactor `LangOptions` to specify compatibility as X macro arg (#146766)Jan Svoboda1-6/+9
This removes the `{BENIGN,COMPATIBLE}{,_ENUM,_VALUE}_LANGOPT` X macros controlling `LangOptions`. These are permutations of the base `LANGOPT`, `ENUM_LANGOPT` and `VALUE_LANGOPT` X macros that also carry the information of their effect on AST (and therefore module compatibility). Their functionality is now implemented by passing `Benign`, `Compatible` or `NotCompatible` argument to the base X macros and using C++17 `if constexpr` in the clients to achieve the same codegen. This PR solves this FIXME: ``` // FIXME: Clients should be able to more easily select whether they want // different levels of compatibility versus how to handle different kinds // of option. ``` The base X macros are preserved, since they are used in `LangOptions.h` to generate different kinds of field and function declarations for flags, values and enums, which can't be achieved with `if constexpr`. The new syntax also forces developers to think about compatibility when adding new language option, hopefully reducing the number of new options that are affecting by default even though they are benign or compatible. Note that the `BENIGN_` macros used to forward to their `COMPATIBLE_` counterparts. I don't think this ever kicked in, since there are no clients of the `.def` file that define `COMPATIBLE_` without also defining `BENIGN_`. However, this might be something downstream forks need to take care of by doing `if constexpr (CK::Compatibility == CK::Benign || CK::Compatibility == CK::Compatible)` in place of `#define COMPATIBLE_`.
2025-06-15[clang] Remove unused includes (NFC) (#144285)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-06[clang][NFC] rename FPOptions.def's macro to FP_OPTION (#138374)Oliver Hunt1-3/+3
While investigating the recent warnings around FEM_Indeterminate I noticed that the macro name for FPOptions.def was given the very generic name `OPTION`. This PR renames it to FP_OPTION instead.
2025-01-21[Clang] Remove 3-element vector load and store special handling (#104661)Shilei Tian1-0/+2
Clang uses a long-time special handling of the case where 3 element vector loads and stores are performed as 4 element, and then a shufflevector is used to extract the used elements. Odd sized vector codegen should now work reasonably well. This patch removes the compiler argument `-fpreserve-vec3-type` and adds a target hook to determine if the special handling of vector type is needed. --------- Co-authored-by: Matt Arsenault <Matthew.Arsenault@amd.com>
2024-10-28Remove support for RenderScript (#112916)Aaron Ballman1-2/+0
See https://discourse.llvm.org/t/rfc-deprecate-and-eventually-remove-renderscript-support/81284 for the RFC
2024-09-13[HLSL] Add HLSL 202y language mode (#108437)Chris B1-0/+2
This change adds a new HLSL 202y language mode. Currently HLSL 202y is planned to add `auto` and `constexpr`. This change updates extension diagnostics to state that lambadas are a "clang HLSL" extension (since we have no planned release yet to include them), and that `auto` is a HLSL 202y extension when used in earlier language modes. Note: This PR does temporarily work around some differences between HLSL 2021 and 202x in Clang by changing test cases to explicitly specify 202x. A subsequent PR will update 2021's language flags to match 202x.
2024-07-26Remove FiniteMathOnly and use only NoHonorINFs and NoHonorNANs. (#97342)Zahira Ammarguellat1-2/+2
Currently `__FINITE_MATH_ONLY__` is set when `FiniteMathOnly`. And `FiniteMathOnly` is set when `NoHonorInfs` && `NoHonorNans` is true. But what happens one of the latter flags is false? To avoid potential inconsistencies, the internal option `FiniteMathOnly` is removed option and the macro `__FINITE_MATH_ONLY__` is set when `NoHonorInfs` && `NoHonorNans`.
2024-07-10[Clang] Allow raw string literals in C as an extension (#88265)Sirraide1-0/+1
This enables raw R"" string literals in C in some language modes and adds an option to disable or enable them explicitly as an extension. Background: GCC supports raw string literals in C in `-gnuXY` modes starting with gnu99. This pr both enables raw string literals in gnu99 mode and later in C and adds an `-f[no-]raw-string-literals` flag to override this behaviour. The decision not to enable raw string literals in gnu89 mode, according to the GCC devs, is intentional as that mode is supposed to be used for ‘old code’ that they don’t want to break; we’ve decided to match GCC’s behaviour here as well. The `-fraw-string-literals` flag can additionally be used to enable raw string literals in modes where they aren’t enabled by default (such as c99—as opposed to gnu99—or even e.g. C++03); conversely, the negated flag can be used to disable them in any gnuXY modes that *do* provide them by default, or to override a previous flag. However, we do *not* support disabling raw string literals (or indeed either of these two options) in C++11 mode and later, because we don’t want to just start supporting disabling features that are actually part of the language in the general case. This fixes #85703.
2024-07-02[C2y] Add -std=c2y and -std=gnu2yAaron Ballman1-0/+1
This adds a language standard mode for the latest C standard. While WG14 is hoping for a three-year cycle, it is not clear that the next revision of C will be in 2026 and so a flag was not created for c26 specifically.
2024-05-11[clang] Use StringRef::operator== instead of StringRef::equals (NFC) (#91844)Kazu Hirata1-1/+1
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 24 under clang/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2023-08-11[C23] Rename C2x -> C23; NFCAaron Ballman1-3/+3
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-05-15Add C++26 compile flags.Erich Keane1-0/+1
Now that we've updated to C++23, we need to add C++26/C++2c command line flags, as discussed in https://discourse.llvm.org/t/rfc-lets-just-call-it-c-26-and-forget-about-the-c-2c-business-at-least-internally/70383 Differential Revision: https://reviews.llvm.org/D150450
2023-05-04[clang] Use -std=c++23 instead of -std=c++2bMark de Wever1-1/+1
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
2023-02-08[clang][deps] Ensure module invocation can be serializedBen Langmuir1-0/+8
When reseting modular options, propagate the values from certain options that have ImpliedBy relations instead of setting to the default. Also, verify in clang-scan-deps that the command line produced round trips exactly. Ideally we would automatically derive the set of options that need this kind of propagation, but for now there aren't very many impacted. rdar://105148590 Differential Revision: https://reviews.llvm.org/D143446
2022-07-03[FPEnv] Allow CompoundStmt to keep FP optionsSerge Pavlov1-0/+9
This is a recommit of b822efc7404bf09ccfdc1ab7657475026966c3b2, reverted in dc34d8df4c48b3a8f474360970cae8a58e6c84f0. The commit caused fails because the test ast-print-fp-pragmas.c did not specify particular target, and it failed on targets which do not support constrained intrinsics. The original commit message is below. AST does not have special nodes for pragmas. Instead a pragma modifies some state variables of Sema, which in turn results in modified attributes of AST nodes. This technique applies to floating point operations as well. Every AST node that can depend on FP options keeps current set of them. This technique works well for options like exception behavior or fast math options. They represent instructions to the compiler how to modify code generation for the affected nodes. However treatment of FP control modes has problems with this technique. Modifying FP control mode (like rounding direction) usually requires operations on hardware, like writing to control registers. It must be done prior to the first operation that depends on the control mode. In particular, such operations are required for implementation of `pragma STDC FENV_ROUND`, compiler should set up necessary rounding direction at the beginning of compound statement where the pragma occurs. As there is no representation for pragmas in AST, the code generation becomes a complicated task in this case. To solve this issue FP options are kept inside CompoundStmt. Unlike to FP options in expressions, these does not affect any operation on FP values, but only inform the codegen about the FP options that act in the body of the statement. As all pragmas that modify FP environment may occurs only at the start of compound statement or at global level, such solution works for all relevant pragmas. The options are kept as a difference from the options in the enclosing compound statement or default options, it helps codegen to set only changed control modes. Differential Revision: https://reviews.llvm.org/D123952
2022-07-01Revert "[FPEnv] Allow CompoundStmt to keep FP options"Serge Pavlov1-9/+0
On some buildbots test `ast-print-fp-pragmas.c` fails, need to investigate it. This reverts commit 0401fd12d4aa0553347fe34d666fb236d8719173. This reverts commit b822efc7404bf09ccfdc1ab7657475026966c3b2.
2022-07-01[FPEnv] Allow CompoundStmt to keep FP optionsSerge Pavlov1-0/+9
AST does not have special nodes for pragmas. Instead a pragma modifies some state variables of Sema, which in turn results in modified attributes of AST nodes. This technique applies to floating point operations as well. Every AST node that can depend on FP options keeps current set of them. This technique works well for options like exception behavior or fast math options. They represent instructions to the compiler how to modify code generation for the affected nodes. However treatment of FP control modes has problems with this technique. Modifying FP control mode (like rounding direction) usually requires operations on hardware, like writing to control registers. It must be done prior to the first operation that depends on the control mode. In particular, such operations are required for implementation of `pragma STDC FENV_ROUND`, compiler should set up necessary rounding direction at the beginning of compound statement where the pragma occurs. As there is no representation for pragmas in AST, the code generation becomes a complicated task in this case. To solve this issue FP options are kept inside CompoundStmt. Unlike to FP options in expressions, these does not affect any operation on FP values, but only inform the codegen about the FP options that act in the body of the statement. As all pragmas that modify FP environment may occurs only at the start of compound statement or at global level, such solution works for all relevant pragmas. The options are kept as a difference from the options in the enclosing compound statement or default options, it helps codegen to set only changed control modes. Differential Revision: https://reviews.llvm.org/D123952
2022-06-23[HLSL] Enable half type for hlsl.Xiang Li1-2/+2
HLSL supports half type. When enable-16bit-types is not set, half will be treated as float. When enable-16bit-types is set, half will be treated like real 16bit float type and map to llvm half type. Also change CXXABI to Microsoft to match dxc behavior. The mangle name for half is "$f16@" when half is treat as native half type and "$halff@" when treat as float. In AST, half is still half. The special thing is done at clang codeGen, when NativeHalfType is false, half will translated into float. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D124790
2022-05-31[HLSL] Enable vector types for hlsl.Xiang Li1-0/+2
Vector types in hlsl is using clang ext_vector_type. Declaration of vector types is in builtin header hlsl.h. hlsl.h will be included by default for hlsl shader. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D125052
2022-05-30Revert "[HLSL] Enable vector types for hlsl."Nico Weber1-2/+0
This reverts commit e576280380d3f5221cfcc14e9fabeacc8506a43c. Breaks tests on mac/arm, see comment on https://reviews.llvm.org/D125052 Also revert follow-up "[gn build] Port e576280380d3" This reverts commit 1e01b1ec72031fcaceb4e77e1c5c8e34f1e862e8.
2022-05-30[HLSL] Enable vector types for hlsl.Xiang Li1-0/+2
Vector types in hlsl is using clang ext_vector_type. Declaration of vector types is in builtin header hlsl.h. hlsl.h will be included by default for hlsl shader. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D125052
2022-05-11[clang] Add the flag -ffile-reproducibleAlan Zhao1-1/+1
When Clang generates the path prefix (i.e. the path of the directory where the file is) when generating FILE, __builtin_FILE(), and std::source_location, Clang uses the platform-specific path separator character of the build environment where Clang _itself_ is built. This leads to inconsistencies in Chrome builds where Clang running on non-Windows environments uses the forward slash (/) path separator while Clang running on Windows builds uses the backslash (\) path separator. To fix this, we add a flag -ffile-reproducible (and its inverse, -fno-file-reproducible) to have Clang use the target's platform-specific file separator character. Additionally, the existing flags -fmacro-prefix-map and -ffile-prefix-map now both imply -ffile-reproducible. This can be overriden by setting -fno-file-reproducible. [0]: https://crbug.com/1310767 Differential revision: https://reviews.llvm.org/D122766
2022-05-04Change the behavior of implicit int diagnosticsAaron Ballman1-1/+0
C89 allowed a type specifier to be elided with the resulting type being int, aka implicit int behavior. This feature was subsequently removed in C99 without a deprecation period, so implementations continued to support the feature. Now, as with implicit function declarations, is a good time to reevaluate the need for this support. This patch allows -Wimplicit-int to issue warnings in C89 mode (off by default), defaults the warning to an error in C99 through C17, and disables support for the feature entirely in C2x. It also removes a warning about missing declaration specifiers that really was just an implicit int warning in disguise and other minor related cleanups.
2022-04-13[clang] NFC, move CompilerInvocation::setLangDefaults to LangOptions.hHaojian Wu1-0/+120
The function is moved from clangFrontend to clangBasic, which allows tools (e.g. clang pseudoparser) which don't depend on clangFrontend to use. Differential Revision: https://reviews.llvm.org/D121375
2021-08-31[OpenCL] Defines helper function for kernel language compatible OpenCL versionJustas Janickas1-0/+10
This change defines a helper function getOpenCLCompatibleVersion() inside LangOptions class. The function contains mapping between C++ for OpenCL versions and their corresponding compatible OpenCL versions. This mapping function should be updated each time a new C++ for OpenCL language version is introduced. The helper function is expected to simplify conditions on OpenCL C and C++ for OpenCL versions inside compiler code. Code refactoring performed. Differential Revision: https://reviews.llvm.org/D108693
2021-08-20[OpenCL] Fix version reporting of C++ for OpenCL 2021Justas Janickas1-0/+2
C++ for OpenCL version 2021 and later are expected to consist of a major version number only. Therefore, a different constructor for `VersionTuple` needs to be called when reporting language version. Differential Revision: https://reviews.llvm.org/D108379
2021-08-13[OpenCL] Clang diagnostics allow reporting C++ for OpenCL version.Justas Janickas1-0/+10
Some Clang diagnostics could only report OpenCL C version. Because C++ for OpenCL can be used as an alternative to OpenCL C, the text for diagnostics should reflect that. Desrciptions modified for these diagnostics: `err_opencl_unknown_type_specifier` `warn_option_invalid_ocl_version` `err_attribute_requires_opencl_version` `warn_opencl_attr_deprecated_ignored` `ext_opencl_ext_vector_type_rgba_selector` Differential Revision: https://reviews.llvm.org/D107648
2021-08-04Apply -fmacro-prefix-map to __builtin_FILE()Pavel Asyutchenko1-0/+8
This matches the behavior of GCC. Patch does not change remapping logic itself, so adding one simple smoke test should be enough. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D107393
2021-02-22[clang][patch] Inclusive language, modify filename SanitizerBlacklist.h to ↵Melanie Blower1-1/+1
NoSanitizeList.h This patch responds to a comment from @vitalybuka in D96203: suggestion to do the change incrementally, and start by modifying this file name. I modified the file name and made the other changes that follow from that rename. Reviewers: vitalybuka, echristo, MaskRay, jansvoboda11, aaron.ballman Differential Revision: https://reviews.llvm.org/D96974
2021-01-26[clang][cli] Store LangStandard::Kind in LangOptionsJan Svoboda1-1/+1
The `LangStandard::Kind` parsed from command line arguments is used to set up some `LangOption` defaults, but isn't stored anywhere. To be able to generate `-std=` (in future patch), we need `CompilerInvocation` to not forget it. This patch demonstrates another use-case: using `LangStd` to set up defaults of marshalled options. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D95342
2020-09-02Revert "Move all fields of '-cc1' option related classes into def file ↵Douglas Yung1-2/+1
databases" This reverts commit c4a2a1307484cffe94a291c42572775411bac8d8. This commit was causing a test failure: http://lab.llvm.org:8011/builders/llvm-clang-win-x-armv7l/builds/1068
2020-09-02Move all fields of '-cc1' option related classes into def file databasesDaniel Grumberg1-1/+2
Once the new option parsing system is committed, this will allow to generate a check to ensure that correct command line generation happens Differential Revision: https://reviews.llvm.org/D86290
2020-06-27Reland D81869 "Modify FPFeatures to use delta not absolute settings"Melanie Blower1-3/+14
This reverts commit defd43a5b393bb63a902042adf578081b03b171d. with correction to solve msan report To solve https://bugs.llvm.org/show_bug.cgi?id=46166 where the floating point settings in PCH files aren't compatible, rewrite FPFeatures to use a delta in the settings rather than absolute settings. With this patch, these floating point options can be benign. Reviewers: rjmccall Differential Revision: https://reviews.llvm.org/D81869
2020-06-26Revert "Revert "Revert "Modify FPFeatures to use delta not absolute settings"""Melanie Blower1-14/+3
This reverts commit 9518763d710bfbbf9315fa88972c55898be44a0e. Memory sanitizer fails in CGFPOptionsRAII::CGFPOptionsRAII dtor
2020-06-26Revert "Revert "Modify FPFeatures to use delta not absolute settings""Melanie Blower1-3/+14
This reverts commit b55d723ed61052b77e720dcffecac43abe873186. Reapply Modify FPFeatures to use delta not absolute settings To solve https://bugs.llvm.org/show_bug.cgi?id=46166 where the floating point settings in PCH files aren't compatible, rewrite FPFeatures to use a delta in the settings rather than absolute settings. With this patch, these floating point options can be benign. Reviewers: rjmccall Differential Revision: https://reviews.llvm.org/D81869
2020-06-26Revert "Modify FPFeatures to use delta not absolute settings"Melanie Blower1-14/+3
This reverts commit 3a748cbf86cea3844fada04eeff4cc64b01f67e0. I'm reverting this commit because I forgot to format the commit message propertly. Sorry for the thrash.
2020-06-26Modify FPFeatures to use delta not absolute settingsMelanie Blower1-3/+14
2020-04-16LangOptions cannot depend on ASTContext, make it not use ASTContext directlyBenjamin Kramer1-5/+4
Fixes a layering violation introduced in 2ba4e3a4598b165245c581c506a813cd4a7dce33.
2020-04-15Move BinaryOperators.FPOptions to trailing storageMelanie Blower1-0/+10
Reviewers: rjmccall Differential Revision: https://reviews.llvm.org/D76384
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
2018-05-08[OpenCL] Factor out language version printingSven van Haastregt1-0/+5
Generate a printable OpenCL language version number in a single place and select between the OpenCL C or OpenCL C++ version accordingly. Differential Revision: https://reviews.llvm.org/D46382 llvm-svn: 331766
2018-02-16[Basic] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko1-4/+3
other minor fixes (NFC). llvm-svn: 325412
2017-06-01[Modules] Handle sanitizer feature mismatches when importing modulesVedant Kumar1-3/+1
This patch makes it an error to have a mismatch between the enabled sanitizers in a CU, and in any module being imported into the CU. Only mismatches between non-modular sanitizers are treated as errors. This patch also includes non-modular sanitizers in module hashes, in order to ensure module rebuilds occur when -fsanitize=X is toggled on and off for non-modular sanitizers, and to cut down on module rebuilds when the option is toggled for modular sanitizers. This fixes a longstanding issue with implicit modules and sanitizers, which Duncan originally diagnosed. When building with implicit modules it's possible to hit a scenario where modules are built without -fsanitize=address, and are subsequently imported into CUs with -fsanitize=address enabled. This causes strange failures at runtime. The case Duncan found affects libcxx, since its vector implementation behaves differently when ASan is enabled. Implicit module builds should "just work" when -fsanitize=X is toggled on and off across multiple compiler invocations, which is what this patch does. Differential Revision: https://reviews.llvm.org/D32724 llvm-svn: 304463
2017-03-30[XRay] Add -fxray-{always,never}-instrument= flags to clangDean Michael Berris1-0/+2
Summary: The -fxray-always-instrument= and -fxray-never-instrument= flags take filenames that are used to imbue the XRay instrumentation attributes using a whitelist mechanism (similar to the sanitizer special cases list). We use the same syntax and semantics as the sanitizer blacklists files in the implementation. As implemented, we respect the attributes that are already defined in the source file (i.e. those that have the [[clang::xray_{always,never}_instrument]] attributes) before applying the always/never instrument lists. Reviewers: rsmith, chandlerc Subscribers: jfb, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D30388 llvm-svn: 299041
2016-10-27Do not print include_next/pragma once warnings when input is a header.Erik Verbruggen1-1/+3
r276653 suppressed the pragma once warning when generating a PCH file. This patch extends that to any main file for which clang is told (with the -x option) that it's a header file. It will also suppress the warning "#include_next in primary source file". Differential Revision: http://reviews.llvm.org/D25989 llvm-svn: 285295
2016-10-10Use StringRef in LangOptions::isNoBuiltinFunc API (NFC)Mehdi Amini1-2/+1
llvm-svn: 283776
2016-02-19[modules] Flatten -fmodule-name= and -fmodule-implementation-of= into a singleRichard Smith1-1/+0
option. Previously these options could both be used to specify that you were compiling the implementation file of a module, with a different set of minor bugs in each case. This change removes -fmodule-implementation-of, and instead tracks a flag to determine whether we're currently building a module. -fmodule-name now behaves the same way that -fmodule-implementation-of previously did. llvm-svn: 261372
2016-01-06[Driver] Add support for -fno-builtin-foo options.Chad Rosier1-0/+8
Addresses PR4941 and rdar://6756912. http://reviews.llvm.org/D15195 llvm-svn: 256937
2015-02-04Allow to specify multiple -fsanitize-blacklist= arguments.Alexey Samsonov1-1/+1
Summary: Allow user to provide multiple blacklists by passing several -fsanitize-blacklist= options. These options now don't override default blacklist from Clang resource directory, which is always applied (which fixes PR22431). -fno-sanitize-blacklist option now disables all blacklists that were specified earlier in the command line (including the default one). This change depends on http://reviews.llvm.org/D7367. Test Plan: regression test suite Reviewers: timurrrr Subscribers: cfe-commits, kcc, pcc Differential Revision: http://reviews.llvm.org/D7368 llvm-svn: 228156