aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2022-09-01[clang] cleanup -fstrict-flex-arrays implementationserge-sans-paille1-9/+3
This is a follow up to https://reviews.llvm.org/D126864, addressing some remaining comments. It also considers union with a single zero-length array field as FAM for each value of -fstrict-flex-arrays. Differential Revision: https://reviews.llvm.org/D132944
2022-09-01[clang][Sema] check default argument promotions for printfYingChi Long1-12/+37
The main focus of this patch is to make ArgType::matchesType check for possible default parameter promotions when the argType is not a pointer. If so, no warning will be given for `int`, `unsigned int` types as corresponding arguments to %hhd and %hd. However, the usage of %hhd corresponding to short is relatively rare, and it is more likely to be a misuse. This patch keeps the original behavior of clang like this as much as possible, while making it more convenient to consider the default arguments promotion. Fixes https://github.com/llvm/llvm-project/issues/57102 Reviewed By: aaron.ballman, nickdesaulniers, #clang-language-wg Differential Revision: https://reviews.llvm.org/D132568
2022-08-31Further update -Wbitfield-constant-conversion for 1-bit bitfieldAaron Ballman1-3/+17
https://reviews.llvm.org/D131255 (82afc9b169a67e8b8a1862fb9c41a2cd974d6691) began warning about conversion causing data loss for a single-bit bit-field. However, after landing the changes, there were reports about significant false positives from some code bases. This alters the approach taken in that patch by introducing a new warning group (-Wsingle-bit-bitfield-constant-conversion) which is grouped under -Wbitfield-constant-conversion to allow users to selectively disable the single-bit warning without losing the other constant conversion warnings. Differential Revision: https://reviews.llvm.org/D132851
2022-08-30[clang] Fix -Warray-bound interaction with -fstrict-flex-arrays=1serge-sans-paille1-1/+1
The test to check if an array was a FAM in the context of array bound checking and strict-flex-arrays=1 was inverted. As a by product, improve test coverage. Differential Revision: https://reviews.llvm.org/D132853
2022-08-14[Sema] Avoid isNullPointerConstant invocationJustin Stitt1-5/+6
DiagnoseNullConversion is needlessly calling isNullPointerConstant which is an expensive routine due to its calls to a constant evaluator -- which we don't need. Building the Linux Kernel (x86_64) with this fix has improved build times by ~2.1%. This is mainly due to the following methods no longer needing to be called anywhere near as often: 1) ExprConstant::CheckICE (reduced CPU cycles by ~90%) 2) IntExprEvaluator::VisitBinaryOperator (reduced CPU cycles by ~50%) Reviewed By: rtrieu, nickdesaulniers Differential Revision: https://reviews.llvm.org/D131532
2022-08-09Fix -Wbitfield-constant-conversion on 1-bit signed bitfieldShawn Zhong1-5/+0
A one-bit signed bit-field can only hold the values 0 and -1; this corrects the diagnostic behavior accordingly. Fixes #53253 Differential Revision: https://reviews.llvm.org/D131255
2022-08-08[clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-4/+4
With C++17 there is no Clang pedantic warning or MSVC C5051. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D131346
2022-08-05Removing redundant code; NFCAaron Ballman1-3/+0
The same predicate is checked on line 12962 just above the removed code.
2022-08-04[clang] change `auto` to `Expr` in last commit [NFC]YingChi Long1-1/+1
2022-08-04[clang] format string checking for conpile-time evaluated str literalYingChi Long1-1/+22
This patch enhances clang's ability to check compile-time determinable string literals as format strings, and can give FixIt hints at literals (unlike gcc). Issue https://github.com/llvm/llvm-project/issues/55805 mentiond two compile-time string cases. And this patch partially fixes one. ``` constexpr const char* foo() { return "%s %d"; } int main() { printf(foo(), "abc", "def"); return 0; } ``` This patch enables clang check format string for this: ``` <source>:4:24: warning: format specifies type 'int' but the argument has type 'const char *' [-Wformat] printf(foo(), "abc", "def"); ~~~~~ ^~~~~ <source>:2:42: note: format string is defined here constexpr const char *foo() { return "%s %d"; } ^~ %s 1 warning generated. ``` Reviewed By: aaron.ballman Signed-off-by: YingChi Long <me@inclyc.cn> Differential Revision: https://reviews.llvm.org/D130906
2022-07-27[clang] Implement ElaboratedType sugaring for types written bareMatheus Izvekov1-2/+2
Without this patch, clang will not wrap in an ElaboratedType node types written without a keyword and nested name qualifier, which goes against the intent that we should produce an AST which retains enough details to recover how things are written. The lack of this sugar is incompatible with the intent of the type printer default policy, which is to print types as written, but to fall back and print them fully qualified when they are desugared. An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still requires pointer alignment due to pre-existing bug in the TypeLoc buffer handling. --- Troubleshooting list to deal with any breakage seen with this patch: 1) The most likely effect one would see by this patch is a change in how a type is printed. The type printer will, by design and default, print types as written. There are customization options there, but not that many, and they mainly apply to how to print a type that we somehow failed to track how it was written. This patch fixes a problem where we failed to distinguish between a type that was written without any elaborated-type qualifiers, such as a 'struct'/'class' tags and name spacifiers such as 'std::', and one that has been stripped of any 'metadata' that identifies such, the so called canonical types. Example: ``` namespace foo { struct A {}; A a; }; ``` If one were to print the type of `foo::a`, prior to this patch, this would result in `foo::A`. This is how the type printer would have, by default, printed the canonical type of A as well. As soon as you add any name qualifiers to A, the type printer would suddenly start accurately printing the type as written. This patch will make it print it accurately even when written without qualifiers, so we will just print `A` for the initial example, as the user did not really write that `foo::` namespace qualifier. 2) This patch could expose a bug in some AST matcher. Matching types is harder to get right when there is sugar involved. For example, if you want to match a type against being a pointer to some type A, then you have to account for getting a type that is sugar for a pointer to A, or being a pointer to sugar to A, or both! Usually you would get the second part wrong, and this would work for a very simple test where you don't use any name qualifiers, but you would discover is broken when you do. The usual fix is to either use the matcher which strips sugar, which is annoying to use as for example if you match an N level pointer, you have to put N+1 such matchers in there, beginning to end and between all those levels. But in a lot of cases, if the property you want to match is present in the canonical type, it's easier and faster to just match on that... This goes with what is said in 1), if you want to match against the name of a type, and you want the name string to be something stable, perhaps matching on the name of the canonical type is the better choice. 3) This patch could expose a bug in how you get the source range of some TypeLoc. For some reason, a lot of code is using getLocalSourceRange(), which only looks at the given TypeLoc node. This patch introduces a new, and more common TypeLoc node which contains no source locations on itself. This is not an inovation here, and some other, more rare TypeLoc nodes could also have this property, but if you use getLocalSourceRange on them, it's not going to return any valid locations, because it doesn't have any. The right fix here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive into the inner TypeLoc to get the source range if it doesn't find it on the top level one. You can use getLocalSourceRange if you are really into micro-optimizations and you have some outside knowledge that the TypeLocs you are dealing with will always include some source location. 4) Exposed a bug somewhere in the use of the normal clang type class API, where you have some type, you want to see if that type is some particular kind, you try a `dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match. Again, like 2), this would usually have been tested poorly with some simple tests with no qualifications, and would have been broken had there been any other kind of type sugar, be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType. The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper into the type. Or use `getAsAdjusted` when dealing with TypeLocs. For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast. 5) It could be a bug in this patch perhaps. Let me know if you need any help! Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D112374
2022-07-18[clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible ↵serge-sans-paille1-10/+32
arrays Some code [0] consider that trailing arrays are flexible, whatever their size. Support for these legacy code has been introduced in f8f632498307d22e10fab0704548b270b15f1e1e but it prevents evaluation of __builtin_object_size and __builtin_dynamic_object_size in some legit cases. Introduce -fstrict-flex-arrays=<n> to have stricter conformance when it is desirable. n = 0: current behavior, any trailing array member is a flexible array. The default. n = 1: any trailing array member of undefined, 0 or 1 size is a flexible array member n = 2: any trailing array member of undefined or 0 size is a flexible array member This takes into account two specificities of clang: array bounds as macro id disqualify FAM, as well as non standard layout. Similar patch for gcc discuss here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [0] https://docs.freebsd.org/en/books/developers-handbook/sockets/#sockets-essential-functions
2022-07-14Revert "[clang] Implement ElaboratedType sugaring for types written bare"Jonas Devlieghere1-2/+2
This reverts commit 7c51f02effdbd0d5e12bfd26f9c3b2ab5687c93f because it stills breaks the LLDB tests. This was re-landed without addressing the issue or even agreement on how to address the issue. More details and discussion in https://reviews.llvm.org/D112374.
2022-07-15[clang] Implement ElaboratedType sugaring for types written bareMatheus Izvekov1-2/+2
Without this patch, clang will not wrap in an ElaboratedType node types written without a keyword and nested name qualifier, which goes against the intent that we should produce an AST which retains enough details to recover how things are written. The lack of this sugar is incompatible with the intent of the type printer default policy, which is to print types as written, but to fall back and print them fully qualified when they are desugared. An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still requires pointer alignment due to pre-existing bug in the TypeLoc buffer handling. --- Troubleshooting list to deal with any breakage seen with this patch: 1) The most likely effect one would see by this patch is a change in how a type is printed. The type printer will, by design and default, print types as written. There are customization options there, but not that many, and they mainly apply to how to print a type that we somehow failed to track how it was written. This patch fixes a problem where we failed to distinguish between a type that was written without any elaborated-type qualifiers, such as a 'struct'/'class' tags and name spacifiers such as 'std::', and one that has been stripped of any 'metadata' that identifies such, the so called canonical types. Example: ``` namespace foo { struct A {}; A a; }; ``` If one were to print the type of `foo::a`, prior to this patch, this would result in `foo::A`. This is how the type printer would have, by default, printed the canonical type of A as well. As soon as you add any name qualifiers to A, the type printer would suddenly start accurately printing the type as written. This patch will make it print it accurately even when written without qualifiers, so we will just print `A` for the initial example, as the user did not really write that `foo::` namespace qualifier. 2) This patch could expose a bug in some AST matcher. Matching types is harder to get right when there is sugar involved. For example, if you want to match a type against being a pointer to some type A, then you have to account for getting a type that is sugar for a pointer to A, or being a pointer to sugar to A, or both! Usually you would get the second part wrong, and this would work for a very simple test where you don't use any name qualifiers, but you would discover is broken when you do. The usual fix is to either use the matcher which strips sugar, which is annoying to use as for example if you match an N level pointer, you have to put N+1 such matchers in there, beginning to end and between all those levels. But in a lot of cases, if the property you want to match is present in the canonical type, it's easier and faster to just match on that... This goes with what is said in 1), if you want to match against the name of a type, and you want the name string to be something stable, perhaps matching on the name of the canonical type is the better choice. 3) This patch could exposed a bug in how you get the source range of some TypeLoc. For some reason, a lot of code is using getLocalSourceRange(), which only looks at the given TypeLoc node. This patch introduces a new, and more common TypeLoc node which contains no source locations on itself. This is not an inovation here, and some other, more rare TypeLoc nodes could also have this property, but if you use getLocalSourceRange on them, it's not going to return any valid locations, because it doesn't have any. The right fix here is to always use getSourceRange() or getBeginLoc/getEndLoc which will dive into the inner TypeLoc to get the source range if it doesn't find it on the top level one. You can use getLocalSourceRange if you are really into micro-optimizations and you have some outside knowledge that the TypeLocs you are dealing with will always include some source location. 4) Exposed a bug somewhere in the use of the normal clang type class API, where you have some type, you want to see if that type is some particular kind, you try a `dyn_cast` such as `dyn_cast<TypedefType>` and that fails because now you have an ElaboratedType which has a TypeDefType inside of it, which is what you wanted to match. Again, like 2), this would usually have been tested poorly with some simple tests with no qualifications, and would have been broken had there been any other kind of type sugar, be it an ElaboratedType or a TemplateSpecializationType or a SubstTemplateParmType. The usual fix here is to use `getAs` instead of `dyn_cast`, which will look deeper into the type. Or use `getAsAdjusted` when dealing with TypeLocs. For some reason the API is inconsistent there and on TypeLocs getAs behaves like a dyn_cast. 5) It could be a bug in this patch perhaps. Let me know if you need any help! Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D112374
2022-07-14[NFC] Move check for isEqualityOp to CheckFloatComparisonsErich Keane1-2/+5
So callers don't have to. Also, fix a clang-format/use of auto fix in CheckFloatComparisons.
2022-07-13[clang] Use value instead of getValue (NFC)Kazu Hirata1-1/+1
2022-07-13[Clang][Sema][AIX][PowerPC] Emit byval alignment warning only when struct is ↵Zarko Todorovski1-0/+40
passed to a function Previous warning went on whenever a struct with a struct member with alignment => 16 was declared. This led to too many false positives and led to diagnostic lit failures due to it being emitted too frequently. Only emit the warning when such a struct and that struct contains a member that has an alignment of 16 bytes is passed to a caller function since this is where the potential binary compatibility issue with XL 16.1.0 and older exists. Reviewed By: sfertile, aaron.ballman Differential Revision: https://reviews.llvm.org/D118350
2022-07-13Revert "[clang] Implement ElaboratedType sugaring for types written bare"Jonas Devlieghere1-2/+2
This reverts commit bdc6974f92304f4ed542241b9b89ba58ba6b20aa because it breaks all the LLDB tests that import the std module. import-std-module/array.TestArrayFromStdModule.py import-std-module/deque-basic.TestDequeFromStdModule.py import-std-module/deque-dbg-info-content.TestDbgInfoContentDequeFromStdModule.py import-std-module/forward_list.TestForwardListFromStdModule.py import-std-module/forward_list-dbg-info-content.TestDbgInfoContentForwardListFromStdModule.py import-std-module/list.TestListFromStdModule.py import-std-module/list-dbg-info-content.TestDbgInfoContentListFromStdModule.py import-std-module/queue.TestQueueFromStdModule.py import-std-module/stack.TestStackFromStdModule.py import-std-module/vector.TestVectorFromStdModule.py import-std-module/vector-bool.TestVectorBoolFromStdModule.py import-std-module/vector-dbg-info-content.TestDbgInfoContentVectorFromStdModule.py import-std-module/vector-of-vectors.TestVectorOfVectorsFromStdModule.py https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45301/
2022-07-13[clang] Implement ElaboratedType sugaring for types written bareMatheus Izvekov1-2/+2
Without this patch, clang will not wrap in an ElaboratedType node types written without a keyword and nested name qualifier, which goes against the intent that we should produce an AST which retains enough details to recover how things are written. The lack of this sugar is incompatible with the intent of the type printer default policy, which is to print types as written, but to fall back and print them fully qualified when they are desugared. An ElaboratedTypeLoc without keyword / NNS uses no storage by itself, but still requires pointer alignment due to pre-existing bug in the TypeLoc buffer handling. Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Differential Revision: https://reviews.llvm.org/D112374
2022-07-09[clang] Add a fixit for warn-self-assign if LHS is a field with the same ↵Nathan James1-9/+15
name as parameter on RHS Add a fix-it for the common case of setters/constructors using parameters with the same name as fields ```lang=c++ struct A{ int X; A(int X) { /*this->*/X = X; } void setX(int X) { /*this->*/X = X; }; ``` Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D129202
2022-07-08[objcxx] Fix `std::addressof` for `id`.zoecarver1-1/+1
Differential Revision: https://reviews.llvm.org/D129384
2022-07-05Allow non-variadic functions to be attributed with `__attribute__((format))`Félix Cloutier1-135/+200
Clang only allows you to use __attribute__((format)) on variadic functions. There are legit use cases for __attribute__((format)) on non-variadic functions, such as: (1) variadic templates ```c++ template<typename… Args> void print(const char *fmt, Args… &&args) __attribute__((format(1, 2))); // error: format attribute requires variadic function ``` (2) functions which take fixed arguments and a custom format: ```c++ void print_number_string(const char *fmt, unsigned number, const char *string) __attribute__((format(1, 2))); // ^error: format attribute requires variadic function void foo(void) { print_number_string(“%08x %s\n”, 0xdeadbeef, “hello”); print_number_string(“%d %s”, 0xcafebabe, “bar”); } ``` This change allows Clang users to attach __attribute__((format)) to non-variadic functions, including functions with C++ variadic templates. It replaces the error with a GCC compatibility warning and improves the type checker to ensure that received arrays are treated like pointers (this is a possibility in C++ since references to template types can bind to arrays). Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D112579 rdar://84629099
2022-06-29[clang][BPF] Update comment to include TYPE_MATCHDaniel Müller1-1/+1
D126838 added support for the TYPE_MATCH compile-once run-everywhere relocation to LLVM proper. On the clang side no changes are necessary, other than the adjustment of a comment to mention this relocation as well. This change takes care of that. Differential Revision: https://reviews.llvm.org/D126839
2022-06-29[Clang] Rename StringLiteral::isAscii() => isOrdinary() [NFC]Corentin Jabot1-6/+6
"Ascii" StringLiteral instances are actually narrow strings that are UTF-8 encoded and do not have an encoding prefix. (UTF8 StringLiteral are also UTF-8 encoded strings, but with the u8 prefix. To avoid possible confusion both with actuall ASCII strings, and with future works extending the set of literal encodings supported by clang, this rename StringLiteral::isAscii() to isOrdinary(), matching C++ standard terminology. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D128762
2022-06-27Revert "[clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of ↵Vitaly Buka1-3/+51
flexible arrays" This reverts D126864 and related fixes. This reverts commit 572b08790a69f955ae0cbb1b4a7d4a215f15dad9. This reverts commit 886715af962de2c92fac4bd37104450345711e4a.
2022-06-25[clang] Don't use Optional::hasValue (NFC)Kazu Hirata1-1/+1
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata1-2/+2
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
2022-06-24[clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible ↵serge-sans-paille1-51/+3
arrays Some code [0] consider that trailing arrays are flexible, whatever their size. Support for these legacy code has been introduced in f8f632498307d22e10fab0704548b270b15f1e1e but it prevents evaluation of __builtin_object_size and __builtin_dynamic_object_size in some legit cases. Introduce -fstrict-flex-arrays=<n> to have stricter conformance when it is desirable. n = 0: current behavior, any trailing array member is a flexible array. The default. n = 1: any trailing array member of undefined, 0 or 1 size is a flexible array member n = 2: any trailing array member of undefined or 0 size is a flexible array member n = 3: any trailing array member of undefined size is a flexible array member (strict c99 conformance) Similar patch for gcc discuss here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [0] https://docs.freebsd.org/en/books/developers-handbook/sockets/#sockets-essential-functions
2022-06-24clang: Tweak behaviour of warn_empty_while_body and warn_empty_if_bodyDmitri Gribenko1-1/+1
Use the if/while statement right paren location instead of the end of the condition expression to determine if the semicolon is on its own line, for the purpose of not warning about code like this: while (foo()) ; Using the condition location meant that we would also not report a warning on code like this: while (MACRO(a, b)); body(); The right paren loc wasn't stored in the AST or passed into Sema::ActOnIfStmt when this logic was first written. Reviewed By: rnk, gribozavr2 Differential Revision: https://reviews.llvm.org/D128406
2022-06-20[clang] Don't use Optional::getValue (NFC)Kazu Hirata1-5/+4
2022-06-16[PowerPC] Fixing implicit castings in altivec for -fno-lax-vector-conversionsMaryam Moghadas1-19/+0
XL considers different vector types to be incompatible with each other. For example assignment between variables of types vector float and vector long long or even vector signed int and vector unsigned int are diagnosed. clang, however does not diagnose such cases and does a simple bitcast between the two types. This could easily result in program errors. This patch is to fix the implicit casts in altivec.h so that there is no incompatible vector type errors whit -fno-lax-vector-conversions, this is the prerequisite patch to switch the default to -fno-lax-vector-conversions later. Reviewed By: nemanjai, amyk Differential Revision: https://reviews.llvm.org/D124093
2022-06-13[clang][AArch64][SVE] Implicit conversions for vector-scalar operationsDavid Truby1-0/+23
This patch allows the same implicit conversions for vector-scalar operations in SVE that are allowed for NEON. Depends on D126377 Reviewed By: c-rhodes Differential Revision: https://reviews.llvm.org/D126380
2022-06-10[clang] Convert for_each to range-based for loops (NFC)Kazu Hirata1-13/+11
2022-06-10[clang] Add support for __builtin_memset_inlineGuillaume Chatelet1-0/+11
In the same spirit as D73543 and in reply to https://reviews.llvm.org/D126768#3549920 this patch is adding support for `__builtin_memset_inline`. The idea is to get support from the compiler to easily write efficient memory function implementations. This patch could be split in two: - one for the LLVM part adding the `llvm.memset.inline.*` intrinsics. - and another one for the Clang part providing the instrinsic as a builtin. Differential Revision: https://reviews.llvm.org/D126903
2022-06-07Cleanup sema checking for buitlin_memcpy_inlineGuillaume Chatelet1-13/+0
2022-05-17[clang] Expose CoawaitExpr's operand in the ASTNathan Ridge1-0/+7
Previously the Expr returned by getOperand() was actually the subexpression common to the "ready", "suspend", and "resume" expressions, which often isn't just the operand but e.g. await_transform() called on the operand. It's important for the AST to expose the operand as written in the source for traversals and tools like clangd to work correctly. Fixes https://github.com/clangd/clangd/issues/939 Differential Revision: https://reviews.llvm.org/D115187
2022-05-16[Diagnostic] Warn if the size argument of memset is character literalChuanqi Xu1-1/+4
zero Closing https://github.com/llvm/llvm-project/issues/55402 Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D125521
2022-05-09Enum conversion warning when one signed and other unsigned.Micah Weston1-3/+4
Ensures an -Wenum-conversion warning happens when one of the enums is signed and the other is unsigned. Also adds a test file to verify these warnings. This warning would not happen since the -Wsign-conversion would make a diagnostic then return, never allowing the -Wenum-conversion checks. For example: C enum PE { P = -1 }; enum NE { N }; enum NE conv(enum PE E) { return E; } Before this would only create a diagnostic with -Wsign-conversion and never on -Wenum-conversion. Now it will create a diagnostic for both -Wsign-conversion and -Wenum-conversion. I could change it to just warn on -Wenum-conversion as that was what I initially did. Seeing PR35200 (or GitHub Issue 316268), I let both diagnostics check so that the sign conversion could generate a warning.
2022-05-09[Clang] Add integer mul reduction builtinSimon Pilgrim1-1/+2
Similar to the existing bitwise reduction builtins, this lowers to a llvm.vector.reduce.mul intrinsic call. For other reductions, we've tried to share builtins for float/integer vectors, but the fmul reduction intrinsic also take a starting value argument and can either do unordered or serialized, but not reduction-trees as specified for the builtins. However we address fmul support this shouldn't affect the integer case. Differential Revision: https://reviews.llvm.org/D117829
2022-05-05Reimplement `__builtin_dump_struct` in Sema.Richard Smith1-68/+333
Compared to the old implementation: * In C++, we only recurse into aggregate classes. * Unnamed bit-fields are not printed. * Constant evaluation is supported. * Proper conversion is done when passing arguments through `...`. * Additional arguments are supported and are injected prior to the format string; this directly supports use with `fprintf`, for example. * An arbitrary callable can be passed rather than only a function pointer. In particular, in C++, a function template or overload set is acceptable. * All text generated by Clang is printed via `%s` rather than directly; this avoids issues where Clang's pretty-printing output might itself contain a `%` character. * Fields of types that we don't know how to print are printed with a `"*%p"` format and passed by address to the print function. * No return value is produced. Reviewed By: aaron.ballman, erichkeane, yihanaa Differential Revision: https://reviews.llvm.org/D124221
2022-05-02[Clang] Add integer add reduction builtinSimon Pilgrim1-0/+2
Similar to the existing bitwise reduction builtins, this lowers to a llvm.vector.reduce.add intrinsic call. For other reductions, we've tried to share builtins for float/integer vectors, but the fadd reduction intrinsics also take a starting value argument and can either do unordered or serialized, but not reduction-trees as specified for the builtins. However we address fadd support this shouldn't affect the integer case. (Split off from D117829) Differential Revision: https://reviews.llvm.org/D124741
2022-04-20Treat `std::move`, `forward`, etc. as builtins.Richard Smith1-0/+26
This is extended to all `std::` functions that take a reference to a value and return a reference (or pointer) to that same value: `move`, `forward`, `move_if_noexcept`, `as_const`, `addressof`, and the libstdc++-specific function `__addressof`. We still require these functions to be declared before they can be used, but don't instantiate their definitions unless their addresses are taken. Instead, code generation, constant evaluation, and static analysis are given direct knowledge of their effect. This change aims to reduce various costs associated with these functions -- per-instantiation memory costs, compile time and memory costs due to creating out-of-line copies and inlining them, code size at -O0, and so on -- so that they are not substantially more expensive than a cast. Most of these improvements are very small, but I measured a 3% decrease in -O0 object file size for a simple C++ source file using the standard library after this change. We now automatically infer the `const` and `nothrow` attributes on these now-builtin functions, in particular meaning that we get a warning for an unused call to one of these functions. In C++20 onwards, we disallow taking the addresses of these functions, per the C++20 "addressable function" rule. In earlier language modes, a compatibility warning is produced but the address can still be taken. The same infrastructure is extended to the existing MSVC builtin `__GetExceptionInfo`, which is now only recognized in namespace `std` like it always should have been. This is a re-commit of fc3090109643af8d2da9822d0f99c84742b9c877, a571f82a50416b767fd3cce0fb5027bb5dfec58c, 64c045e25b8471bbb572bd29159c294a82a86a2, and de6ddaeef3aaa8a9ae3663c12cdb57d9afc0f906, and reverts aa643f455a5362de7189eac630050d2c8aefe8f2. This change also includes a workaround for users using libc++ 3.1 and earlier (!!), as apparently happens on AIX, where std::move sometimes returns by value. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D123345 Revert "Fixup D123950 to address revert of D123345" This reverts commit aa643f455a5362de7189eac630050d2c8aefe8f2.
2022-04-20Revert "Treat `std::move`, `forward`, etc. as builtins."David Tenty1-26/+0
This reverts commit b27430f9f46b88bcd54d992debc8d72e131e1bd0 as the parent https://reviews.llvm.org/D123345 breaks the AIX CI: https://lab.llvm.org/buildbot/#/builders/214/builds/819
2022-04-20Reland "[COFF, ARM64] Add __break intrinsic"Pengxuan Zheng1-0/+3
https://docs.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics?view=msvc-170 Reland after fixing the test failure. The failure was due to conflict with a change (D122983) which was merged right before this patch. Reviewed By: rnk, mstorsjo Differential Revision: https://reviews.llvm.org/D124032
2022-04-20Revert "[COFF, ARM64] Add __break intrinsic"Pengxuan Zheng1-3/+0
This reverts commit 8a9b4fb4aa6d2dde026d9ae08459aa9e7a1edb05.
2022-04-20[COFF, ARM64] Add __break intrinsicPengxuan Zheng1-0/+3
https://docs.microsoft.com/en-us/cpp/intrinsics/arm64-intrinsics?view=msvc-170 Reviewed By: rnk, mstorsjo Differential Revision: https://reviews.llvm.org/D124032
2022-04-20[clang][Sema] Fix typo in checkBuiltinArgument helperAlex Bradbury1-1/+1
The checkBuiltinArgument helper takes an integer ArgIndex and is documented as performing normal type-checking on that argument. However, it mistakenly hardcodes the argument index to zero when retrieving the argument from the call expression. This hadn't been noticed previously as all in-tree uses typecheck the 0th argument anyway.
2022-04-17Treat `std::move`, `forward`, etc. as builtins.Richard Smith1-0/+26
This is extended to all `std::` functions that take a reference to a value and return a reference (or pointer) to that same value: `move`, `forward`, `move_if_noexcept`, `as_const`, `addressof`, and the libstdc++-specific function `__addressof`. We still require these functions to be declared before they can be used, but don't instantiate their definitions unless their addresses are taken. Instead, code generation, constant evaluation, and static analysis are given direct knowledge of their effect. This change aims to reduce various costs associated with these functions -- per-instantiation memory costs, compile time and memory costs due to creating out-of-line copies and inlining them, code size at -O0, and so on -- so that they are not substantially more expensive than a cast. Most of these improvements are very small, but I measured a 3% decrease in -O0 object file size for a simple C++ source file using the standard library after this change. We now automatically infer the `const` and `nothrow` attributes on these now-builtin functions, in particular meaning that we get a warning for an unused call to one of these functions. In C++20 onwards, we disallow taking the addresses of these functions, per the C++20 "addressable function" rule. In earlier language modes, a compatibility warning is produced but the address can still be taken. The same infrastructure is extended to the existing MSVC builtin `__GetExceptionInfo`, which is now only recognized in namespace `std` like it always should have been. This is a re-commit of fc3090109643af8d2da9822d0f99c84742b9c877, a571f82a50416b767fd3cce0fb5027bb5dfec58c, and 64c045e25b8471bbb572bd29159c294a82a86a25 which were reverted in e75d8b70370435b0ad10388afba0df45fcf9bfcc due to a crasher bug where CodeGen would emit a builtin glvalue as an rvalue if it constant-folds. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D123345
2022-04-16Revert "Treat `std::move`, `forward`, and `move_if_noexcept` as builtins."Vitaly Buka1-26/+0
Revert "Extend support for std::move etc to also cover std::as_const and" Revert "Update test to handle opaque pointers flag flip." It crashes on libcxx tests https://lab.llvm.org/buildbot/#/builders/85/builds/8174 This reverts commit fc3090109643af8d2da9822d0f99c84742b9c877. This reverts commit a571f82a50416b767fd3cce0fb5027bb5dfec58c. This reverts commit 64c045e25b8471bbb572bd29159c294a82a86a25.