aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/LangOptions.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2014-11-11[Sanitizer] Refactor sanitizer options in LangOptions.Alexey Samsonov1-18/+1
Get rid of ugly SanitizerOptions class thrust into LangOptions: * Make SanitizeAddressFieldPadding a regular language option, and rely on default behavior to initialize/reset it. * Make SanitizerBlacklistFile a regular member LangOptions. * Introduce the helper class "SanitizerSet" to represent the set of enabled sanitizers and make it a member of LangOptions. It is exactly the entity we want to cache and modify in CodeGenFunction, for instance. We'd also be able to reuse SanitizerSet in CodeGenOptions for storing the set of recoverable sanitizers, and in the Driver to represent the set of sanitizers turned on/off by the commandline flags. No functionality change. llvm-svn: 221653
2014-11-07Introduce a SanitizerKind enum to LangOptions.Alexey Samsonov1-4/+11
Use the bitmask to store the set of enabled sanitizers instead of a bitfield. On the negative side, it makes syntax for querying the set of enabled sanitizers a bit more clunky. On the positive side, we will be able to use SanitizerKind to eventually implement the new semantics for -fsanitize-recover= flag, that would allow us to make some sanitizers recoverable, and some non-recoverable. No functionality change. llvm-svn: 221558
2014-10-30Get rid of SanitizerOptions::Disabled global. NFC.Alexey Samsonov1-4/+11
SanitizerOptions is not even a POD now, so having global variable of this type, is not nice. Instead, provide a regular constructor and clear() method, and let each CodeGenFunction has its own copy of SanitizerOptions it uses. llvm-svn: 220920
2014-07-23Add stopgap option -fmodule-implementation-of <name>Ben Langmuir1-0/+1
This flag specifies that we are building an implementation file of the module <name>, preventing importing <name> as a module. This does not consider this to be the 'current module' for the purposes of doing modular checks like decluse or non-modular-include warnings, unlike -fmodule-name. This is needed as a stopgap until: 1) we can resolve relative includes to a VFS-mapped module (or can safely import a header textually and as part of a module) and ideally 2) we can safely do incremental rebuilding when implementation files import submodules. llvm-svn: 213767
2013-02-07Add a *San + modules FIXME.Richard Smith1-0/+2
llvm-svn: 174565
2013-01-18[ubsan] Add support for -fsanitize-blacklistWill Dietz1-1/+7
llvm-svn: 172808
2011-11-15Add a -cc1-level option -fmodule-name=<name>, which will be used whenDouglas Gregor1-0/+2
building modules. llvm-svn: 144680
2011-09-15Teach LangOptions::resetNonModularOptions to actually do what it says it doesDouglas Gregor1-0/+3
llvm-svn: 139791
2011-09-13When building a module on-demand, clear out the "non-modular" languageDouglas Gregor1-0/+6
and preprocessor options (such as macro definitions) first. llvm-svn: 139638
2011-09-13Switch LangOptions over to a .def file that describes header of theDouglas Gregor1-0/+21
language options. Use that .def file to declare the LangOptions class and initialize all of its members, eliminating a source of annoying initialization bugs. AST serialization changes are next up. llvm-svn: 139605
2009-04-22Remove the serialization code that predates precompiledDouglas Gregor1-60/+0
headers. Future approaches to (de-)serializing ASTs will be based on the PCH infrastructure. llvm-svn: 69828
2008-04-29Add -fobjc-gc and -fobjc-gc-only options to the driver.Ted Kremenek1-1/+3
Add corresponding enum in LangOptions. llvm-svn: 50387
2008-03-15Make a major restructuring of the clang tree: introduce a top-levelChris Lattner1-0/+58
lib dir and move all the libraries into it. This follows the main llvm tree, and allows the libraries to be built in parallel. The top level now enforces that all the libs are built before Driver, but we don't care what order the libs are built in. This speeds up parallel builds, particularly incremental ones. llvm-svn: 48402