summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExpr.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Retry: [ubsan] Detect UB loads from bitfieldsVedant Kumar2017-03-091-3/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | It's possible to load out-of-range values from bitfields backed by a boolean or an enum. Check for UB loads from bitfields. This is the motivating example: struct S { BOOL b : 1; // Signed ObjC BOOL. }; S s; s.b = 1; // This is actually stored as -1. if (s.b == 1) // Evaluates to false, -1 != 1. ... Changes since the original commit: - Single-bit bools are a special case (see CGF::EmitFromMemory), and we can't avoid dealing with them when loading from a bitfield. Don't try to insert a check in this case. Differential Revision: https://reviews.llvm.org/D30423 llvm-svn: 297389
* Revert "[ubsan] Detect UB loads from bitfields"Vedant Kumar2017-03-091-4/+3
| | | | | | | | This reverts commit r297298. It breaks the self-host on this bot: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/962/steps/build%20clang%2Fubsan/logs/stdio llvm-svn: 297331
* [ubsan] Detect UB loads from bitfieldsVedant Kumar2017-03-081-3/+4
| | | | | | | | | | | | | | | | | | | | It's possible to load out-of-range values from bitfields backed by a boolean or an enum. Check for UB loads from bitfields. This is the motivating example: struct S { BOOL b : 1; // Signed ObjC BOOL. }; S s; s.b = 1; // This is actually stored as -1. if (s.b == 1) // Evaluates to false, -1 != 1. ... Differential Revision: https://reviews.llvm.org/D30423 llvm-svn: 297298
* Don't assume cleanup emission preserves dominance in expr evaluationReid Kleckner2017-03-061-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Because of the existence branches out of GNU statement expressions, it is possible that emitting cleanups for a full expression may cause the new insertion point to not be dominated by the result of the inner expression. Consider this example: struct Foo { Foo(); ~Foo(); int x; }; int g(Foo, int); int f(bool cond) { int n = g(Foo(), ({ if (cond) return 0; 42; })); return n; } Before this change, result of the call to 'g' did not dominate its use in the store to 'n'. The early return exit from the statement expression branches to a shared cleanup block, which ends in a switch between the fallthrough destination (the assignment to 'n') or the function exit block. This change solves the problem by spilling and reloading expression evaluation results when any of the active cleanups have branches. I audited the other call sites of enterFullExpression, and they don't appear to keep and Values live across the site of the cleanup, except in ARC code. I wasn't able to create a test case for ARC that exhibits this problem, though. Reviewers: rjmccall, rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D30590 llvm-svn: 297084
* [ubsan] Factor out logic to emit a range check. NFC.Vedant Kumar2017-02-271-29/+43
| | | | | | | This is a readability improvement, but it will also help prep an upcoming patch to detect UB loads from bitfields. llvm-svn: 296374
* Rename a helper function, NFC.Vedant Kumar2017-02-231-3/+3
| | | | llvm-svn: 295918
* Retry^2: [ubsan] Reduce null checking of C++ object pointers (PR27581)Vedant Kumar2017-02-171-3/+38
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch teaches ubsan to insert exactly one null check for the 'this' pointer per method/lambda. Previously, given a load of a member variable from an instance method ('this->x'), ubsan would insert a null check for 'this', and another null check for '&this->x', before allowing the load to occur. Similarly, given a call to a method from another method bound to the same instance ('this->foo()'), ubsan would a redundant null check for 'this'. There is also a redundant null check in the case where the object pointer is a reference ('Ref.foo()'). This patch teaches ubsan to remove the redundant null checks identified above. Testing: check-clang, check-ubsan, and a stage2 ubsan build. I also compiled X86FastISel.cpp with -fsanitize=null using patched/unpatched clangs based on r293572. Here are the number of null checks emitted: ------------------------------------- | Setup | # of null checks | ------------------------------------- | unpatched, -O0 | 21767 | | patched, -O0 | 10758 | ------------------------------------- Changes since the initial commit: - Don't introduce any unintentional object-size or alignment checks. - Don't rely on IRGen of C labels in the test. Differential Revision: https://reviews.llvm.org/D29530 llvm-svn: 295515
* [ubsan] Pass a set of checks to skip to EmitTypeCheck() (NFC)Vedant Kumar2017-02-171-4/+9
| | | | | | | | | | | CodeGenFunction::EmitTypeCheck accepts a bool flag which controls whether or not null checks are emitted. Make this a bit more flexible by changing the bool to a SanitizerSet. Needed for an upcoming change which deals with a scenario in which we only want to emit null checks. llvm-svn: 295514
* Revert "Retry: [ubsan] Reduce null checking of C++ object pointers (PR27581)"Vedant Kumar2017-02-171-35/+3
| | | | | | | | This reverts commit r295401. It breaks the ubsan self-host. It inserts object size checks once per C++ method which fire when the structure is empty. llvm-svn: 295494
* Retry: [ubsan] Reduce null checking of C++ object pointers (PR27581)Vedant Kumar2017-02-171-3/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch teaches ubsan to insert exactly one null check for the 'this' pointer per method/lambda. Previously, given a load of a member variable from an instance method ('this->x'), ubsan would insert a null check for 'this', and another null check for '&this->x', before allowing the load to occur. Similarly, given a call to a method from another method bound to the same instance ('this->foo()'), ubsan would a redundant null check for 'this'. There is also a redundant null check in the case where the object pointer is a reference ('Ref.foo()'). This patch teaches ubsan to remove the redundant null checks identified above. Testing: check-clang and check-ubsan. I also compiled X86FastISel.cpp with -fsanitize=null using patched/unpatched clangs based on r293572. Here are the number of null checks emitted: ------------------------------------- | Setup | # of null checks | ------------------------------------- | unpatched, -O0 | 21767 | | patched, -O0 | 10758 | ------------------------------------- Changes since the initial commit: don't rely on IRGen of C labels in the test. Differential Revision: https://reviews.llvm.org/D29530 llvm-svn: 295401
* Revert "[ubsan] Reduce null checking of C++ object pointers (PR27581)"Vedant Kumar2017-02-171-35/+3
| | | | | | | | | | This reverts commit r295391. It breaks this bot: http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/1898 I need to not rely on labels in the IR test. llvm-svn: 295396
* [ubsan] Reduce null checking of C++ object pointers (PR27581)Vedant Kumar2017-02-171-3/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch teaches ubsan to insert exactly one null check for the 'this' pointer per method/lambda. Previously, given a load of a member variable from an instance method ('this->x'), ubsan would insert a null check for 'this', and another null check for '&this->x', before allowing the load to occur. Similarly, given a call to a method from another method bound to the same instance ('this->foo()'), ubsan would a redundant null check for 'this'. There is also a redundant null check in the case where the object pointer is a reference ('Ref.foo()'). This patch teaches ubsan to remove the redundant null checks identified above. Testing: check-clang and check-ubsan. I also compiled X86FastISel.cpp with -fsanitize=null using patched/unpatched clangs based on r293572. Here are the number of null checks emitted: ------------------------------------- | Setup | # of null checks | ------------------------------------- | unpatched, -O0 | 21767 | | patched, -O0 | 10758 | ------------------------------------- Differential Revision: https://reviews.llvm.org/D29530 llvm-svn: 295391
* [ubsan] Minimize size of data for type_mismatch (Redo of D19667)Filipe Cabecinhas2017-01-061-5/+6
| | | | | | | | | | | | | | | | | | Summary: This patch makes the type_mismatch static data 7 bytes smaller (and it ends up being 16 bytes smaller due to alignment restrictions, at least on some x86-64 environments). It revs up the type_mismatch handler version since we're breaking binary compatibility. I will soon post a patch for the compiler-rt side. Reviewers: rsmith, kcc, vitalybuka, pgousseau, gbedwell Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D28242 llvm-svn: 291236
* Fix problems in "[OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare ↵Egor Churaev2016-12-231-0/+2
| | | | | | | | | | | | | | operand." Summary: Fixed warnings in commit: https://reviews.llvm.org/rL290171 Reviewers: djasper, Anastasia Subscribers: yaxunl, cfe-commits, bader Differential Revision: https://reviews.llvm.org/D27981 llvm-svn: 290431
* CodeGen: ubsan is built static on windows, give handlers local storageSaleem Abdulrasool2016-12-151-1/+2
| | | | | | | | | The UBSAN runtime is built static on Windows. This requires that we give local storage always. This impacts Windows where the linker would otherwise have to generate a thunk to access the symbol via the IAT. This should repair the windows clang build bots. llvm-svn: 289829
* CodeGen: clean up -Wpedantic warning (NFC)Saleem Abdulrasool2016-12-131-1/+1
| | | | | | | | | | lib/CodeGen/CGExpr.cpp:2511:2: warning: extra ';' [-Wpedantic] }; ^ Clean up warning from gcc 6. llvm-svn: 289514
* Avoid use of std::to_string. NFC.Vedant Kumar2016-12-121-1/+1
| | | | | | | Apparently this routine isn't available on some Android platforms. See the mailing list thread re: D21695. llvm-svn: 289452
* [Fix] Add missing include from r289444.Filipe Cabecinhas2016-12-121-0/+2
| | | | llvm-svn: 289446
* [clang] Version support for UBSan handlersFilipe Cabecinhas2016-12-121-16/+38
| | | | | | | | | | | | | | | | | | | | | | This adds a way for us to version any UBSan handler by itself. The patch overrides D21289 for a better implementation (we're able to rev up a single handler). After this, then we can land a slight modification of D19667+D19668. We probably don't want to keep all the versions in compiler-rt (maybe we want to deprecate on one release and remove the old handler on the next one?), but with this patch we will loudly fail to compile when mixing incompatible handler calls, instead of silently compiling and then providing bad error messages. Reviewers: kcc, samsonov, rsmith, vsk Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D21695 llvm-svn: 289444
* [ubsan] Treat ObjC's BOOL as if its range is always {0, 1}Vedant Kumar2016-12-091-7/+8
| | | | | | | | | | | | | | On some Apple platforms, the ObjC BOOL type is defined as a signed char. When performing instrumentation for -fsanitize=bool, we'd like to treat the range of BOOL like it's always {0, 1}. While we can't change clang's IRGen for char-backed BOOL's due to ABI compatibility concerns, we can teach ubsan to catch potential abuses of this type. rdar://problem/29502773 Differential Revision: https://reviews.llvm.org/D27607 llvm-svn: 289290
* [c++17] P0135R1: Guaranteed copy elision.Richard Smith2016-12-061-1/+1
| | | | | | | | When an object of class type is initialized from a prvalue of the same type (ignoring cv qualifications), use the prvalue to initialize the object directly instead of inserting a redundant elidable call to a copy constructor. llvm-svn: 288866
* Improve handling of __FUNCTION__ and other predefined expression for ↵Mehdi Amini2016-11-161-3/+13
| | | | | | | | | | | | | | Objective-C Blocks Instead of always displaying the mangled name, try to do better and get something closer to regular functions. Recommit r287039 (that was reverted in r287039) with a tweak to be more generic, and test fixes! Differential Revision: https://reviews.llvm.org/D26522 llvm-svn: 287085
* Revert "Improve handling of __FUNCTION__ and other predefined expression for ↵Mehdi Amini2016-11-151-13/+3
| | | | | | | | Objective-C Blocks" This reverts commit r287039, tests are broken. llvm-svn: 287043
* Improve handling of __FUNCTION__ and other predefined expression for ↵Mehdi Amini2016-11-151-3/+13
| | | | | | | | | | | Objective-C Blocks Instead of always displaying the mangled name, try to do better and get something closer to regular functions. Differential Revision: https://reviews.llvm.org/D26522 llvm-svn: 287039
* [OPENMP] Fixed codegen for __real/__imag expressions in atomicAlexey Bataev2016-11-071-2/+4
| | | | | | | | | | | | constructs. For __real/__imag unary expressions clang emits lvalue with the associated type from the original complex expression, but not the underlying builtin integer or float type. This causes crash in codegen for atomic constructs, if __real/__imag expression are used in atomic constructs. llvm-svn: 286129
* [OPENMP] Fixed capturing of VLA variables.Alexey Bataev2016-11-071-6/+5
| | | | | | After some changes in codegen capturing of VLA variables in OpenMP regions was broken, causing compiler crash. Patch fixes this issue. llvm-svn: 286103
* Revert "[OPENMP] Fixed capturing of VLA variables."Diana Picus2016-11-071-5/+6
| | | | | | | This reverts commit r286098 because the modified test breaks on many of the buildbots. llvm-svn: 286102
* [OPENMP] Fixed capturing of VLA variables.Alexey Bataev2016-11-071-6/+5
| | | | | | | After some changes in codegen capturing of VLA variables in OpenMP regions was broken, causing compiler crash. Patch fixes this issue. llvm-svn: 286098
* Refactor call emission to package the function pointer together withJohn McCall2016-10-261-76/+104
| | | | | | | | | | | abstract information about the callee. NFC. The goal here is to make it easier to recognize indirect calls and trigger additional logic in certain cases. That logic will come in a later patch; in the meantime, I felt that this was a significant improvement to the code. llvm-svn: 285258
* [CodeGen][ObjC] Do not call objc_storeStrong when initializing aAkira Hatanaka2016-10-181-1/+9
| | | | | | | | | | | | | | | | | | constexpr variable. When compiling a constexpr NSString initialized with an objective-c string literal, CodeGen emits objc_storeStrong on an uninitialized alloca, which causes a crash. This patch folds the code in EmitScalarInit into EmitStoreThroughLValue and fixes the crash by calling objc_retain on the string instead of using objc_storeStrong. rdar://problem/28562009 Differential Revision: https://reviews.llvm.org/D25547 llvm-svn: 284516
* [ubsan] Disable bounds-check for flexible array ivarsVedant Kumar2016-10-041-0/+2
| | | | | | | | | This eliminates a class of false positives for -fsanitize=array-bounds on instrumented ObjC projects. Differential Revision: https://reviews.llvm.org/D22227 llvm-svn: 283249
* Switch to a different workaround for unimplementability of P0145R3 in MS ABIs.Richard Smith2016-09-291-7/+25
| | | | | | | | | | | | | | | | | | | Instead of ignoring the evaluation order rule, ignore the "destroy parameters in reverse construction order" rule for the small number of problematic cases. This only causes incorrect behavior in the rare case where both parameters to an overloaded operator <<, >>, ->*, &&, ||, or comma are of class type with non-trivial destructor, and the program is depending on those parameters being destroyed in reverse construction order. We could do a little better here by reversing the order of parameter destruction for those functions (and reversing the argument evaluation order for all direct calls, not just those with operator syntax), but that is not a complete solution to the problem, as the same situation can be reached by an indirect function call. Approach reviewed off-line by rnk. llvm-svn: 282777
* Re-commit r282556, reverted in r282564, with a fix to CallArgList::addFrom toRichard Smith2016-09-281-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | function correctly when targeting MS ABIs (this appears to have never mattered prior to this change). Update test case to always cover both 32-bit and 64-bit Windows ABIs, since they behave somewhat differently from each other here. Update test case to also cover operators , && and ||, which it appears are also affected by P0145R3 (they're not explicitly called out by the design document, but this is the emergent behavior of the existing wording). Original commit message: P0145R3 (C++17 evaluation order tweaks): evaluate the right-hand side of assignment and compound-assignment operators before the left-hand side. (Even if it's an overloaded operator.) This completes the implementation of P0145R3 + P0400R0 for all targets except Windows, where the evaluation order guarantees for <<, >>, and ->* are unimplementable as the ABI requires the function arguments are evaluated from right to left (because parameter destructors are run from left to right in the callee). llvm-svn: 282619
* Revert r282556. This change made several bots unhappy.Richard Smith2016-09-281-10/+1
| | | | llvm-svn: 282564
* P0145R3 (C++17 evaluation order tweaks): evaluate the right-hand side ofRichard Smith2016-09-271-1/+10
| | | | | | | | | | | | | assignment and compound-assignment operators before the left-hand side. (Even if it's an overloaded operator.) This completes the implementation of P0145R3 + P0400R0 for all targets except Windows, where the evaluation order guarantees for <<, >>, and ->* are unimplementable as the ABI requires the function arguments are evaluated from right to left (because parameter destructors are run from left to right in the callee). llvm-svn: 282556
* Remove default argument from lambda to appease old MSVC.Richard Smith2016-09-271-1/+1
| | | | llvm-svn: 282464
* P0145R3 (C++17 evaluation order tweaks): consistently emit the LHS of arrayRichard Smith2016-09-261-15/+35
| | | | | | | subscripting before the RHS, regardless of which is the base and which is the index. llvm-svn: 282453
* Update Clang for D20147 ("DebugInfo: New metadata representation for global ↵Peter Collingbourne2016-09-131-2/+2
| | | | | | | | variables.") Differential Revision: http://reviews.llvm.org/D20415 llvm-svn: 281285
* Update clang for D21514. NFCAmaury Sechet2016-09-091-4/+5
| | | | | | | | | | | | Summary: As per title. Reviewers: ahatanak, bkramer, whitequark, mehdi_amini, void Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D21515 llvm-svn: 281018
* P0217R3: code generation support for decomposition declarations.Richard Smith2016-08-151-0/+6
| | | | llvm-svn: 278642
* [OpenCL] Generate opaque type for sampler_t and function call for the ↵Yaxun Liu2016-07-281-0/+1
| | | | | | | | | | | | | | | | initializer Currently Clang use int32 to represent sampler_t, which have been a source of issue for some backends, because in some backends sampler_t cannot be represented by int32. They have to depend on kernel argument metadata and use IPA to find the sampler arguments and global variables and transform them to target specific sampler type. This patch uses opaque pointer type opencl.sampler_t* for sampler_t. For each use of file-scope sampler variable, it generates a function call of __translate_sampler_initializer. For each initialization of function-scope sampler variable, it generates a function call of __translate_sampler_initializer. Each builtin library can implement its own __translate_sampler_initializer(). Since the real sampler type tends to be architecture dependent, allowing it to be initialized by a library function simplifies backend design. A typical implementation of __translate_sampler_initializer could be a table lookup of real sampler literal values. Since its argument is always a literal, the returned pointer is known at compile time and easily optimized to finally become some literal values directly put into image read instructions. This patch is partially based on Alexey Sotkin's work in Khronos Clang (https://github.com/KhronosGroup/SPIR/commit/3d4eec61623502fc306e8c67c9868be2b136e42b). Differential Revision: https://reviews.llvm.org/D21567 llvm-svn: 277024
* [CodeGen] Use llvm::Type::getVectorNumElements instead of casting to ↵Craig Topper2016-07-081-2/+1
| | | | | | llvm::VectorType and calling getNumElements. This is equivalent and shorter. llvm-svn: 274823
* [Temporary, Lifetime] Add lifetime marks for temporariesTim Shen2016-07-011-1/+19
| | | | | | | | | With all MaterializeTemporaryExprs coming with a ExprWithCleanups, it's easy to add correct lifetime.end marks into the right RunCleanupsScope. Differential Revision: http://reviews.llvm.org/D20499 llvm-svn: 274385
* CodeGen: Update Clang to use the new type metadata.Peter Collingbourne2016-06-241-9/+8
| | | | | | Differential Revision: http://reviews.llvm.org/D21054 llvm-svn: 273730
* Update clang for D20348Peter Collingbourne2016-06-141-3/+3
| | | | | | Differential Revision: http://reviews.llvm.org/D20339 llvm-svn: 272710
* [MS Volatile] Don't make volatile loads/stores to underaligned objects atomicDavid Majnemer2016-05-241-8/+7
| | | | | | | | | | Underaligned atomic LValues require libcalls which MSVC doesn't have. MSVC doesn't seem to consider such operations as requiring a barrier anyway. This fixes PR27843. llvm-svn: 270576
* [ObjC][CodeGen] Remove an assert that is no longer correct.Akira Hatanaka2016-05-131-3/+10
| | | | | | | | | | | | | | | | | | clang asserts when compiling the following code because r231508 made changes to promote constant temporary arrays and records to globals with constant initializers: std::vector<NSString*> strs = {@"a", @"b"}; This commit changes the code to return early if the object returned by createReferenceTemporary is a global variable with an initializer. rdar://problem/25504992 rdar://problem/25955179 Differential Revision: http://reviews.llvm.org/D20045 llvm-svn: 269385
* [ubsan] Add -fsanitize-undefined-strip-path-components=NFilipe Cabecinhas2016-05-121-1/+28
| | | | | | | | | | | | | | | | | | | Summary: This option allows the user to control how much of the file name is emitted by UBSan. Tuning this option allows one to save space in the resulting binary, which is helpful for restricted execution environments. With a positive N, UBSan skips the first N path components. With a negative N, UBSan only keeps the last N path components. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19666 llvm-svn: 269309
* Fix argument expansion of reference fields of structsReid Kleckner2016-05-021-0/+4
| | | | | | | | | | | | | | | | | | | r268261 made Clang "expand" more struct arguments on Windows. It removed the check for 'RD->isCLike()', which was preventing us from attempting to expand structs with reference type fields. Our expansion code was attempting to load and pass each field of the type in turn. We were accidentally doing one to many loads on reference type fields. On the function prologue side, we can use EmitLValueForFieldInitialization, which obviously gets the address of the field. On the call side, I tweaked EmitRValueForField directly, since this is the only use of this method. Fixes PR27607 llvm-svn: 268321
* Remove redundant conditions of the form (A || (!A && B)) -> (A || B)Benjamin Kramer2016-04-111-1/+1
| | | | | | Found by cppcheck! PR27286 PR27287 PR27288 PR27289 llvm-svn: 265918
OpenPOWER on IntegriCloud