aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/Sema.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-12[AArch64] Add an error if SVE scalable vector types are used in a context ↵David Green1-0/+9
without sve This adds an error message if the isSVESizelessBuiltinType like __SVFloat32_t / __SVInt64_t / etc, which provide the backing for the svfloat32_t / svint64_t / etc ACLE types, are used in a function without SVE. The alternative is a crash in the backend, which is not capable of handling scalable vector types. When SVE is available, either through a -march=..+sve option or via a target(sve) attribute, nothing should change. Without the sve feature, this patch gives an error for any function arguments, return values and variable declarations involving the scalable types. Struct/class members and global variables already give an error. As this can be based on the current function target attributes, the error sometimes needs to be handled later than would otherwise if it was just based on the global target. Differential Revision: https://reviews.llvm.org/D131058
2022-12-27Reland "[AArch64] FMV support and necessary target features dependencies."Pavel Iliin1-0/+3
This relands commits e43924a75145d2f9e722f74b673145c3e62bfd07, a43f36142c501e2d3f4797ef938db4e0c5e0eeec, bf94eac6a3f7c5cd8941956d44c15524fa3751bd with MSan buildbot https://lab.llvm.org/buildbot/#/builders/5/builds/30139 use-of-uninitialized-value errors fixed. Differential Revision: https://reviews.llvm.org/D127812
2022-12-20Revert "[AArch64] FMV support and necessary target features dependencies."Mitch Phillips1-3/+0
This reverts commit e43924a75145d2f9e722f74b673145c3e62bfd07. Reason: Patch broke the MSan buildbots. More information is available on the original phabricator review: https://reviews.llvm.org/D127812
2022-12-20[AArch64] FMV support and necessary target features dependencies.Pavel Iliin1-0/+3
This is Function Multi Versioning (FMV) implementation for AArch64 target in accordance with Beta Arm C Language Extensions specification https://github.com/ARM-software/acle/blob/main/main/acle.md#function-multi-versioning It supports new "target_version" function attribute and extends existing "target_clones" one. Also missing dependencies for target features were added. Differential Revision: https://reviews.llvm.org/D127812
2022-12-16[clang][dataflow] Remove unused argument in getNullabilityDani Ferreira Franco Moura1-2/+2
This change will allow users to call getNullability() without providing an ASTContext. Reviewed By: gribozavr2 Differential Revision: https://reviews.llvm.org/D140104
2022-12-03[Sema] Use std::nullopt instead of None (NFC)Kazu Hirata1-2/+2
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-29[clang] Skip defaulted functions in zero-as-null-pointer-constant.Jens Massberg1-0/+6
The zero-as-null-pointer-constant check should not fire if it is inside a defaulted function, e.g. defaulted spaceship operators. Add C++20 tests with spaceship operators. Fixes #50221 Differential Revision: https://reviews.llvm.org/D138727
2022-10-31Revert "[clang] ASTImporter: Fix importing of va_list types and declarations"Matheus Izvekov1-20/+0
This reverts commit 5f820c0f55cd9d4f4520cc92eae0a1c4afe05a54. Apparently it breaks aarch64 buildbots. https://lab.llvm.org/buildbot#builders/188/builds/21591
2022-10-31[clang] ASTImporter: Fix importing of va_list types and declarationsMatheus Izvekov1-0/+20
This fixes a problem where __va_list_tag was not correctly imported, possibly leading to multiple definitions with different types. This adds __va_list_tag to it's proper scope, so that the ASTImporter can find it. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D136886
2022-09-28[C++2a] P0634r3: Down with typename!Nicolas Lesser1-0/+24
This patch implements P0634r3 that removes the need for 'typename' in certain contexts. For example, ``` template <typename T> using foo = T::type; // ok ``` This is also allowed in previous language versions as an extension, because I think it's pretty useful. :) Reviewed By: #clang-language-wg, erichkeane Differential Revision: https://reviews.llvm.org/D53847
2022-09-19[clang] Add support for #pragma strict_gs_checkDavid Majnemer1-3/+3
2022-09-07[Sema] Move Diags.isIgnored() checks off hot paths, it's not free. NFCSam McCall1-4/+5
This speeds up clangd's buildAST() (i.e. parsing with a preamble) by 5% on clangd/AST.cpp, by avoiding filling up the diagnostic state map with entries for all the files where templates are being instantiated from. (I would assume it has a similar effect on PCH and modules compiles). This approach is obviously pretty fragile, and we should find ways to make isIgnored() cheaper instead. But these changes in particular don't seem to make the code worse in any case. Differential Revision: https://reviews.llvm.org/D129683
2022-09-03[clang] Qualify auto in range-based for loops (NFC)Kazu Hirata1-2/+2
2022-09-02[NFC] Make MultiplexExternalSemaSource own sourcesChris Bieneman1-19/+13
This change refactors the MuiltiplexExternalSemaSource to take ownership of the underlying sources. As a result it makes a larger cleanup of external source ownership in Sema and the ChainedIncludesSource. Reviewed By: aaron.ballman, aprantl Differential Revision: https://reviews.llvm.org/D133158
2022-08-21[C++20][Modules] Improve handing of Private Module Fragment diagnostics.Iain Sandoe1-0/+27
This adds a check for exported inline functions, that there is a definition in the definition domain (which, in practice, can only be the module purview but before any PMF starts) since the PMF definition domain cannot contain exports. This is: [dcl.inline]/7 If an inline function or variable that is attached to a named module is declared in a definition domain, it shall be defined in that domain. The patch also amends diagnostic output by excluding the PMF sub-module from the set considered as sources of missing decls. There is no point in telling the user that the import of a PMF object is missing - since such objects are never reachable to an importer. We still show the definition (as unreachable), to help point out this. Differential Revision: https://reviews.llvm.org/D128328
2022-07-27[NFC] [C++20] [Modules] Use Sema::isCurrentModulePurview() to simplify the codesChuanqi Xu1-3/+1
2022-07-26[RISCV] Lazily add RVV C intrinsics.Kito Cheng1-0/+1
Leverage the method OpenCL uses that adds C intrinsics when the lookup failed. There is no need to define C intrinsics in the header file any more. It could help to avoid the large header file to speed up the compilation of RVV source code. Besides that, only the C intrinsics used by the users will be added into the declaration table. This patch is based on https://reviews.llvm.org/D103228 and inspired by OpenCL implementation. ### Experimental Results #### TL;DR: - Binary size of clang increase ~200k, which is +0.07% for debug build and +0.13% for release build. - Single file compilation speed up ~33x for debug build and ~8.5x for release build - Regression time reduce ~10% (`ninja check-all`, enable all targets) #### Header size change ``` | size | LoC | ------------------------------ Before | 4,434,725 | 69,749 | After | 6,140 | 162 | ``` #### Single File Compilation Time Testcase: ``` #include <riscv_vector.h> vint32m1_t test_vadd_vv_vfloat32m1_t(vint32m1_t op1, vint32m1_t op2, size_t vl) { return vadd(op1, op2, vl); } ``` ##### Debug build: Before: ``` real 0m19.352s user 0m19.252s sys 0m0.092s ``` After: ``` real 0m0.576s user 0m0.552s sys 0m0.024s ``` ~33x speed up for debug build ##### Release build: Before: ``` real 0m0.773s user 0m0.741s sys 0m0.032s ``` After: ``` real 0m0.092s user 0m0.080s sys 0m0.012s ``` ~8.5x speed up for release build #### Regression time Note: the failed case is `tools/llvm-debuginfod-find/debuginfod.test` which is unrelated to this patch. ##### Debug build Before: ``` Testing Time: 1358.38s Skipped : 11 Unsupported : 446 Passed : 75767 Expectedly Failed: 190 Failed : 1 ``` After ``` Testing Time: 1220.29s Skipped : 11 Unsupported : 446 Passed : 75767 Expectedly Failed: 190 Failed : 1 ``` ##### Release build Before: ``` Testing Time: 381.98s Skipped : 12 Unsupported : 1407 Passed : 74765 Expectedly Failed: 176 Failed : 1 ``` After: ``` Testing Time: 346.25s Skipped : 12 Unsupported : 1407 Passed : 74765 Expectedly Failed: 176 Failed : 1 ``` #### Binary size of clang ##### Debug build Before ``` text data bss dec hex filename 335261851 12726004 552812 348540667 14c64efb bin/clang ``` After ``` text data bss dec hex filename 335442803 12798708 552940 348794451 14ca2e53 bin/clang ``` +253K, +0.07% code size ##### Release build Before ``` text data bss dec hex filename 144123975 8374648 483140 152981763 91e5103 bin/clang ``` After ``` text data bss dec hex filename 144255762 8447296 483268 153186326 9217016 bin/clang ``` +204K, +0.13% Authored-by: Kito Cheng <kito.cheng@sifive.com> Co-Authored-by: Hsiangkai Wang <kai.wang@sifive.com> Reviewed By: khchen, aaron.ballman Differential Revision: https://reviews.llvm.org/D111617
2022-07-25Remove redundaunt virtual specifiers (NFC)Kazu Hirata1-3/+3
Identified with tidy-modernize-use-override.
2022-07-03[FPEnv] Allow CompoundStmt to keep FP optionsSerge Pavlov1-1/+2
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-2/+1
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-1/+2
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-29[Clang][Preprocessor] Fix inconsistent `FLT_EVAL_METHOD` when compiling vs ↵Egor Zhdan1-14/+1
preprocessing When running `clang -E -Ofast` on macOS, the `__FLT_EVAL_METHOD__` macro is `0`, which causes the following typedef to be emitted into the preprocessed source: `typedef float float_t`. However, when running `clang -c -Ofast`, `__FLT_EVAL_METHOD__` is `-1`, and `typedef long double float_t` is emitted. This causes build errors for certain projects, which are not reproducible when compiling from preprocessed source. The issue is that `__FLT_EVAL_METHOD__` is configured in `Sema::Sema` which is not executed when running in `-E` mode. This change moves that logic into the preprocessor initialization method, which is invoked correctly in `-E` mode. rdar://96134605 rdar://92748429 Differential Revision: https://reviews.llvm.org/D128814
2022-05-25[OpenMP] Add diagnostic for unterminated 'omp [begin] declare target'Mike Rice1-0/+1
Warns when end-of-file is reached without seeing all matching 'omp end declare target' directives. The diagnostic shows the location of the related begin directive. Differential Revision: https://reviews.llvm.org/D126331
2022-04-20Revert D119136 "[clang] Implement Change scope of lambda ↵Fangrui Song1-5/+3
trailing-return-type" and its follow-up This reverts commit 69dd89fdcbd846375a45e2fe3a88710887236d7a. This reverts commit 04000c2f928a7adc32138a664d167f01b642bef3. The current states breaks libstdc++ usage (https://reviews.llvm.org/D119136#3455423). The fixup has been reverted as it caused other valid code to be disallowed. I think we should start from the clean state by reverting all relevant commits.
2022-04-15[clang] Implement Change scope of lambda trailing-return-typeCorentin Jabot1-3/+5
Implement P2036R3. Captured variables by copy (explicitely or not), are deduced correctly at the point we know whether the lambda is mutable, and ill-formed before that. Up until now, the entire lambda declaration up to the start of the body would be parsed in the parent scope, such that capture would not be available to look up. The scoping is changed to have an outer lambda scope, followed by the lambda prototype and body. The lambda scope is necessary because there may be a template scope between the start of the lambda (to which we want to attach the captured variable) and the prototype scope. We also need to introduce a declaration context to attach the captured variable to (and several parts of clang assume captures are handled from the call operator context), before we know the type of the call operator. The order of operations is as follow: * Parse the init capture in the lambda's parent scope * Introduce a lambda scope * Create the lambda class and call operator * Add the init captures to the call operator context and the lambda scope. But the variables are not capured yet (because we don't know their type). Instead, explicit captures are stored in a temporary map that conserves the order of capture (for the purpose of having a stable order in the ast dumps). * A flag is set on LambdaScopeInfo to indicate that we have not yet injected the captures. * The parameters are parsed (in the parent context, as lambda mangling recurses in the parent context, we couldn't mangle a lambda that is attached to the context of a lambda whose type is not yet known). * The lambda qualifiers are parsed, at this point We can switch (for the second time) inside the lambda context, unset the flag indicating that we have not parsed the lambda qualifiers, record the lambda is mutable and capture the explicit variables. * We can parse the rest of the lambda type, transform the lambda and call operator's types and also transform the call operator to a template function decl where necessary. At this point, both captures and parameters can be injected in the body's scope. When trying to capture an implicit variable, if we are before the qualifiers of a lambda, we need to remember that the variables are still in the parent's context (rather than in the call operator's). Reviewed By: aaron.ballman, #clang-language-wg, ChuanqiXu Differential Revision: https://reviews.llvm.org/D119136
2022-04-13Revert "[clang] Implement Change scope of lambda trailing-return-type"Richard Smith1-5/+3
This reverts commit c729d5be781a8e80137c11ab28aa14d9ace148db. This change breaks thread safety annotations on lambdas.
2022-04-13[clang] Implement Change scope of lambda trailing-return-typeCorentin Jabot1-3/+5
Implement P2036R3. Captured variables by copy (explicitely or not), are deduced correctly at the point we know whether the lambda is mutable, and ill-formed before that. Up until now, the entire lambda declaration up to the start of the body would be parsed in the parent scope, such that captures would not be available to look up. The scoping is changed to have an outer lambda scope, followed by the lambda prototype and body. The lambda scope is necessary because there may be a template scope between the start of the lambda (to which we want to attach the captured variable) and the prototype scope. We also need to introduce a declaration context to attach the captured variable to (and several parts of clang assume captures are handled from the call operator context), before we know the type of the call operator. The order of operations is as follow: * Parse the init capture in the lambda's parent scope * Introduce a lambda scope * Create the lambda class and call operator * Add the init captures to the call operator context and the lambda scope. But the variables are not capured yet (because we don't know their type). Instead, explicit captures are stored in a temporary map that conserves the order of capture (for the purpose of having a stable order in the ast dumps). * A flag is set on LambdaScopeInfo to indicate that we have not yet injected the captures. * The parameters are parsed (in the parent context, as lambda mangling recurses in the parent context, we couldn't mangle a lambda that is attached to the context of a lambda whose type is not yet known). * The lambda qualifiers are parsed, at this point, we can switch (for the second time) inside the lambda context, unset the flag indicating that we have not parsed the lambda qualifiers, record the lambda is mutable and capture the explicit variables. * We can parse the rest of the lambda type, transform the lambda and call operator's types and also transform the call operator to a template function decl where necessary. At this point, both captures and parameters can be injected in the body's scope. When trying to capture an implicit variable, if we are before the qualifiers of a lambda, we need to remember that the variables are still in the parent's context (rather than in the call operator's). This is a recommit of adff142dc2 after a fix in d8d793f29b4 Reviewed By: aaron.ballman, #clang-language-wg, ChuanqiXu Differential Revision: https://reviews.llvm.org/D119136
2022-04-13Revert "[clang] Implement Change scope of lambda trailing-return-type"Mehdi Amini1-5/+3
This reverts commit adff142dc253d65b6560e420bba6b858d88d4a98. This broke clang bootstrap: it made existing C++ code in LLVM invalid: llvm/include/llvm/CodeGen/LiveInterval.h:630:53: error: captured variable 'Idx' cannot appear here [=](std::remove_reference_t<decltype(*Idx)> V, ^
2022-04-13[clang] Implement Change scope of lambda trailing-return-typeCorentin Jabot1-3/+5
Implement P2036R3. Captured variables by copy (explicitely or not), are deduced correctly at the point we know whether the lambda is mutable, and ill-formed before that. Up until now, the entire lambda declaration up to the start of the body would be parsed in the parent scope, such that capture would not be available to look up. The scoping is changed to have an outer lambda scope, followed by the lambda prototype and body. The lambda scope is necessary because there may be a template scope between the start of the lambda (to which we want to attach the captured variable) and the prototype scope. We also need to introduce a declaration context to attach the captured variable to (and several parts of clang assume captures are handled from the call operator context), before we know the type of the call operator. The order of operations is as follow: * Parse the init capture in the lambda's parent scope * Introduce a lambda scope * Create the lambda class and call operator * Add the init captures to the call operator context and the lambda scope. But the variables are not capured yet (because we don't know their type). Instead, explicit captures are stored in a temporary map that conserves the order of capture (for the purpose of having a stable order in the ast dumps). * A flag is set on LambdaScopeInfo to indicate that we have not yet injected the captures. * The parameters are parsed (in the parent context, as lambda mangling recurses in the parent context, we couldn't mangle a lambda that is attached to the context of a lambda whose type is not yet known). * The lambda qualifiers are parsed, at this point We can switch (for the second time) inside the lambda context, unset the flag indicating that we have not parsed the lambda qualifiers, record the lambda is mutable and capture the explicit variables. * We can parse the rest of the lambda type, transform the lambda and call operator's types and also transform the call operator to a template function decl where necessary. At this point, both captures and parameters can be injected in the body's scope. When trying to capture an implicit variable, if we are before the qualifiers of a lambda, we need to remember that the variables are still in the parent's context (rather than in the call operator's). Reviewed By: aaron.ballman, #clang-language-wg, ChuanqiXu Differential Revision: https://reviews.llvm.org/D119136
2022-03-28[Clang] Implement __builtin_source_location.James Y Knight1-2/+3
This builtin returns the address of a global instance of the `std::source_location::__impl` type, which must be defined (with an appropriate shape) before calling the builtin. It will be used to implement std::source_location in libc++ in a future change. The builtin is compatible with GCC's implementation, and libstdc++'s usage. An intentional divergence is that GCC declares the builtin's return type to be `const void*` (for ease-of-implementation reasons), while Clang uses the actual type, `const std::source_location::__impl*`. In order to support this new functionality, I've also added a new 'UnnamedGlobalConstantDecl'. This artificial Decl is modeled after MSGuidDecl, and is used to represent a generic concept of an lvalue constant with global scope, deduplicated by its value. It's possible that MSGuidDecl itself, or some of the other similar sorts of things in Clang might be able to be refactored onto this more-generic concept, but there's enough special-case weirdness in MSGuidDecl that I gave up attempting to share code there, at least for now. Finally, for compatibility with libstdc++'s <source_location> header, I've added a second exception to the "cannot cast from void* to T* in constant evaluation" rule. This seems a bit distasteful, but feels like the best available option. Reviewers: aaron.ballman, erichkeane Differential Revision: https://reviews.llvm.org/D120159
2022-03-25[C++20][Modules][HU 1/5] Introduce header units as a module type.Iain Sandoe1-3/+7
This is the first in a series of patches that introduce C++20 importable header units. These differ from clang header modules in that: (a) they are identifiable by an internal name (b) they represent the top level source for a single header - although that might include or import other headers. We name importable header units with the path by which they are specified (although that need not be the absolute path for the file). So "foo/bar.h" would have a name "foo/bar.h". Header units are made a separate module type so that we can deal with diagnosing places where they are permitted but a named module is not. Differential Revision: https://reviews.llvm.org/D121095
2022-03-24[Clang] Work with multiple pragmas weak before definitionHubert Tong1-8/+10
Update `WeakUndeclaredIdentifiers` to hold a collection of weak aliases per identifier instead of only one. This also allows the "used" state to be removed from `WeakInfo` because it is really only there as an alternative to removing processed map entries, and we can represent that using an empty set now. The serialization code is updated for the removal of the field. Additionally, a PCH test is added for the new functionality. The records are grouped by the "target" identifier, which was already being used as a key for lookup purposes. We also store only one record per alias name; combined, this means that diagnostics are grouped by the "target" and limited to one per alias (which should be acceptable). Fixes PR28611. Fixes llvm/llvm-project#28985. Reviewed By: aaron.ballman, cebowleratibm Differential Revision: https://reviews.llvm.org/D121927 Co-authored-by: Rachel Craik <rcraik@ca.ibm.com> Co-authored-by: Jamie Schmeiser <schmeise@ca.ibm.com>
2022-03-24[CUDA][HIP] Fix hostness check with -fopenmpYaxun (Sam) Liu1-6/+5
CUDA/HIP determines whether a function can be called based on the device/host attributes of callee and caller. Clang assumes the caller is CurContext. This is correct in most cases, however, it is not correct in OpenMP parallel region when CUDA/HIP program is compiled with -fopenmp. This causes incorrect overloading resolution and missed diagnostics. To get the correct caller, clang needs to chase the parent chain of DeclContext starting from CurContext until a function decl or a lambda decl is reached. Sema API is adapted to achieve that and used to determine the caller in hostness check. Reviewed by: Artem Belevich, Richard Smith Differential Revision: https://reviews.llvm.org/D121765
2022-03-17Currently the control of the eval-method is mixed with fast-math.Zahira Ammarguellat1-0/+6
FLT_EVAL_METHOD tells the user the precision at which, temporary results are evaluated but when fast-math is enabled, the numeric values are not guaranteed to match the source semantics, so the eval-method is meaningless. For example, the expression `x + y + z` has as source semantics `(x + y) + z`. FLT_EVAL_METHOD is telling the user at which precision `(x + y)` is evaluated. With fast-math enable the compiler can choose to evaluate the expression as `(y + z) + x`. The correct behavior is to set the FLT_EVAL_METHOD to `-1` to tell the user that the precision of the intermediate values is unknow. This patch is doing that. Differential Revision: https://reviews.llvm.org/D121122
2022-03-08Properly diagnose constant evaluation issues at TU scopeAaron Ballman1-0/+3
We were not creating an evaluation context for the TU scope, so we never popped an evaluation context for it. Popping the evaluation context triggers a number of diagnostics, including warnings about immediate invocations that we were previously missing. Note: I think we have an additional issue that we should solve, but not as part of this patch. I don't think Clang is properly modeling static initialization as happening before constant expression evaluation. I think structure members members are zero initialized per http://eel.is/c++draft/basic.start.static#1, https://eel.is/c++draft/basic.start.static#2.sentence-2, and http://eel.is/c++draft/dcl.init#general-6.2 and the new test case actually should be accepted. However, it's also worth noting that other compilers behave the way this patch makes Clang behave: https://godbolt.org/z/T7noqhdPr
2022-03-01[AST] Print NTTP args as string-literals when possibleZhihao Yuan1-0/+3
C++20 non-type template parameter prints `MyType<{{116, 104, 105, 115}}>` when the code is as simple as `MyType<"this">`. This patch prints `MyType<{"this"}>`, with one layer of braces preserved for the intermediate structural type to trigger CTAD. `StringLiteral` handles this case, but `StringLiteral` inside `APValue` code looks like a circular dependency. The proposed patch implements a cheap strategy to emit string literals in diagnostic messages only when they are readable and fall back to integer sequences. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D115031
2022-02-23Add support for floating-point option `ffp-eval-method` and forZahira Ammarguellat1-0/+21
`pragma clang fp eval_method`. Differential Revision: https://reviews.llvm.org/D109239
2022-02-18Revert "Add support for floating-point option `ffp-eval-method` and for"Florian Hahn1-21/+0
This reverts commit 32b73bc6ab8234b670c34d5ef999300e072cc706. This breaks builds on macOS in some configurations, because __FLT_EVAL_METHOD__ is set to an unexpected value. E.g. https://green.lab.llvm.org/green/job/clang-stage1-RA/28282/consoleFull#129538464349ba4694-19c4-4d7e-bec5-911270d8a58c More details available in the review thread https://reviews.llvm.org/D109239
2022-02-17Add support for floating-point option `ffp-eval-method` and forZahira Ammarguellat1-0/+21
`pragma clang fp eval_method`. https://reviews.llvm.org/D109239
2022-02-15Revert "Add support for floating-point option `ffp-eval-method` and for"Nico Weber1-21/+0
This reverts commit 4bafe65c2b2f1ce745894a509a6d80c87fb1c335. Breaks at least Misc/warning-flags.c, see comments on https://reviews.llvm.org/D109239
2022-02-15Add support for floating-point option `ffp-eval-method` and forZahira Ammarguellat1-0/+21
`pragma clang fp eval_method`.
2022-02-01[clang] Don't typo-fix an expression in a SFINAE context.Arthur O'Dwyer1-24/+28
If this is a SFINAE context, then continuing to look up names (in particular, to treat a non-function as a function, and then do ADL) might too-eagerly complete a type that it's not safe to complete right now. We should just say "okay, that's a substitution failure" and not do any more work than absolutely required. Fixes #52970. Differential Revision: https://reviews.llvm.org/D117603
2022-01-27Revert "[clang] Don't typo-fix an expression in a SFINAE context."Arthur O'Dwyer1-5/+0
This reverts commit 9be5f4d5afd9a1b6e88a268f6ea6eb282d77d9fe. I'm not sure if this caused https://lab.llvm.org/buildbot/#/builders/60/builds/6350 https://lab.llvm.org/buildbot/#/builders/119/builds/7433 but I'm acting as if it did.
2022-01-27[clang] Don't typo-fix an expression in a SFINAE context.Arthur O'Dwyer1-0/+5
If this is a SFINAE context, then continuing to look up names (in particular, to treat a non-function as a function, and then do ADL) might too-eagerly complete a type that it's not safe to complete right now. We should just say "okay, that's a substitution failure" and not do any more work than absolutely required. Fixes #52970. Differential Revision: https://reviews.llvm.org/D117603
2022-01-27[OpenCL] Add support of __opencl_c_device_enqueue feature macro.Anton Zabaznov1-4/+6
This feature requires support of __opencl_c_generic_address_space and __opencl_c_program_scope_global_variables so diagnostics for that is provided as well. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D115640
2022-01-12[clang] Remove redundant member initialization (NFC)Kazu Hirata1-1/+1
Identified with readability-redundant-member-init.
2022-01-12[Clang][Sema] Use VersionMap from SDKSettings for remapping tvOS and watchOS ↵Egor Zhdan1-2/+10
availability This makes the mapping between iOS & tvOS/watchOS versions more accurate. For example, iOS 9.3 now gets correctly mapped into tvOS 9.2 and not tvOS 9.3. Before this change, the incorrect mapping could cause excessive or missing warnings for code that specifies availability for iOS, but not for tvOS/watchOS. rdar://81491680 Differential Revision: https://reviews.llvm.org/D116822
2022-01-10Revert "[clang] Remove redundant member initialization (NFC)"Kazu Hirata1-1/+1
This reverts commit 80e2c587498a7b2bf14dde47a33a058da6e88a9a. The original patch causes a lot of warnings on gcc like: llvm-project/clang/include/clang/Basic/Diagnostic.h:1329:3: warning: base class ‘class clang::StreamingDiagnostic’ should be explicitly initialized in the copy constructor [-Wextra]
2022-01-09[clang] Remove redundant member initialization (NFC)Kazu Hirata1-1/+1
Identified with readability-redundant-member-init.