summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExpr.cpp
AgeCommit message (Collapse)Author
2017-04-14[ubsan] Don't check alignment if the alignment is 1Vedant Kumar
If a pointer is 1-byte aligned, there's no use in checking its alignment. Somewhat surprisingly, ubsan can spend a significant amount of time doing just that! This loosely depends on D30283. Testing: check-clang, check-ubsan, and a stage2 ubsan build. Differential Revision: https://reviews.llvm.org/D30285 llvm-svn: 300371
2017-04-14[ubsan] Reduce alignment checking of C++ object pointersVedant Kumar
This patch teaches ubsan to insert an alignment check for the 'this' pointer at the start of each method/lambda. This allows clang to emit significantly fewer alignment checks overall, because if 'this' is aligned, so are its fields. This is essentially the same thing r295515 does, but for the alignment check instead of the null check. One difference is that we keep the alignment checks on member expressions where the base is a DeclRefExpr. There's an opportunity to diagnose unaligned accesses in this situation (as pointed out by Eli, see PR32630). Testing: check-clang, check-ubsan, and a stage2 ubsan build. Along with the patch from D30285, this roughly halves the amount of alignment checks we emit when compiling X86FastISel.cpp. Here are the numbers from patched/unpatched clangs based on r298160. ------------------------------------------ | Setup | # of alignment checks | ------------------------------------------ | unpatched, -O0 | 24326 | | patched, -O0 | 12717 | (-47.7%) ------------------------------------------ Differential Revision: https://reviews.llvm.org/D30283 llvm-svn: 300370
2017-04-10Update for AllocaInst construction changesMatt Arsenault
llvm-svn: 299889
2017-04-07[cfi] Emit __cfi_check stub in the frontend.Evgeniy Stepanov
Previously __cfi_check was created in LTO optimization pipeline, which means LLD has no way of knowing about the existence of this symbol without rescanning the LTO output object. As a result, LLD fails to export __cfi_check, even when given --export-dynamic-symbol flag. llvm-svn: 299806
2017-04-04Preserve vec3 type.Jin-Gu Kang
Summary: Preserve vec3 type with CodeGen option. Reviewers: Anastasia, bruno Reviewed By: Anastasia Subscribers: bruno, ahatanak, cfe-commits Differential Revision: https://reviews.llvm.org/D30810 llvm-svn: 299445
2017-03-21Let llvm.objectsize be conservative with null pointersGeorge Burgess IV
D28494 adds another parameter to @llvm.objectsize. Clang needs to be sure to pass that third arg whenever applicable. llvm-svn: 298431
2017-03-21Update Clang for LLVM rename AttributeSet -> AttributeListReid Kleckner
llvm-svn: 298394
2017-03-09Retry: [ubsan] Detect UB loads from bitfieldsVedant Kumar
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
2017-03-09Revert "[ubsan] Detect UB loads from bitfields"Vedant Kumar
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
2017-03-08[ubsan] Detect UB loads from bitfieldsVedant Kumar
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
2017-03-06Don't assume cleanup emission preserves dominance in expr evaluationReid Kleckner
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
2017-02-27[ubsan] Factor out logic to emit a range check. NFC.Vedant Kumar
This is a readability improvement, but it will also help prep an upcoming patch to detect UB loads from bitfields. llvm-svn: 296374
2017-02-23Rename a helper function, NFC.Vedant Kumar
llvm-svn: 295918
2017-02-17Retry^2: [ubsan] Reduce null checking of C++ object pointers (PR27581)Vedant Kumar
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
2017-02-17[ubsan] Pass a set of checks to skip to EmitTypeCheck() (NFC)Vedant Kumar
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
2017-02-17Revert "Retry: [ubsan] Reduce null checking of C++ object pointers (PR27581)"Vedant Kumar
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
2017-02-17Retry: [ubsan] Reduce null checking of C++ object pointers (PR27581)Vedant Kumar
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
2017-02-17Revert "[ubsan] Reduce null checking of C++ object pointers (PR27581)"Vedant Kumar
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
2017-02-17[ubsan] Reduce null checking of C++ object pointers (PR27581)Vedant Kumar
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
2017-01-06[ubsan] Minimize size of data for type_mismatch (Redo of D19667)Filipe Cabecinhas
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
2016-12-23Fix problems in "[OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare ↵Egor Churaev
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
2016-12-15CodeGen: ubsan is built static on windows, give handlers local storageSaleem Abdulrasool
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
2016-12-13CodeGen: clean up -Wpedantic warning (NFC)Saleem Abdulrasool
lib/CodeGen/CGExpr.cpp:2511:2: warning: extra ';' [-Wpedantic] }; ^ Clean up warning from gcc 6. llvm-svn: 289514
2016-12-12Avoid use of std::to_string. NFC.Vedant Kumar
Apparently this routine isn't available on some Android platforms. See the mailing list thread re: D21695. llvm-svn: 289452
2016-12-12[Fix] Add missing include from r289444.Filipe Cabecinhas
llvm-svn: 289446
2016-12-12[clang] Version support for UBSan handlersFilipe Cabecinhas
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
2016-12-09[ubsan] Treat ObjC's BOOL as if its range is always {0, 1}Vedant Kumar
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
2016-12-06[c++17] P0135R1: Guaranteed copy elision.Richard Smith
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
2016-11-16Improve handling of __FUNCTION__ and other predefined expression for ↵Mehdi Amini
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
2016-11-15Revert "Improve handling of __FUNCTION__ and other predefined expression for ↵Mehdi Amini
Objective-C Blocks" This reverts commit r287039, tests are broken. llvm-svn: 287043
2016-11-15Improve handling of __FUNCTION__ and other predefined expression for ↵Mehdi Amini
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
2016-11-07[OPENMP] Fixed codegen for __real/__imag expressions in atomicAlexey Bataev
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
2016-11-07[OPENMP] Fixed capturing of VLA variables.Alexey Bataev
After some changes in codegen capturing of VLA variables in OpenMP regions was broken, causing compiler crash. Patch fixes this issue. llvm-svn: 286103
2016-11-07Revert "[OPENMP] Fixed capturing of VLA variables."Diana Picus
This reverts commit r286098 because the modified test breaks on many of the buildbots. llvm-svn: 286102
2016-11-07[OPENMP] Fixed capturing of VLA variables.Alexey Bataev
After some changes in codegen capturing of VLA variables in OpenMP regions was broken, causing compiler crash. Patch fixes this issue. llvm-svn: 286098
2016-10-26Refactor call emission to package the function pointer together withJohn McCall
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
2016-10-18[CodeGen][ObjC] Do not call objc_storeStrong when initializing aAkira Hatanaka
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
2016-10-04[ubsan] Disable bounds-check for flexible array ivarsVedant Kumar
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
2016-09-29Switch to a different workaround for unimplementability of P0145R3 in MS ABIs.Richard Smith
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
2016-09-28Re-commit r282556, reverted in r282564, with a fix to CallArgList::addFrom toRichard Smith
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
2016-09-28Revert r282556. This change made several bots unhappy.Richard Smith
llvm-svn: 282564
2016-09-27P0145R3 (C++17 evaluation order tweaks): evaluate the right-hand side ofRichard Smith
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
2016-09-27Remove default argument from lambda to appease old MSVC.Richard Smith
llvm-svn: 282464
2016-09-26P0145R3 (C++17 evaluation order tweaks): consistently emit the LHS of arrayRichard Smith
subscripting before the RHS, regardless of which is the base and which is the index. llvm-svn: 282453
2016-09-13Update Clang for D20147 ("DebugInfo: New metadata representation for global ↵Peter Collingbourne
variables.") Differential Revision: http://reviews.llvm.org/D20415 llvm-svn: 281285
2016-09-09Update clang for D21514. NFCAmaury Sechet
Summary: As per title. Reviewers: ahatanak, bkramer, whitequark, mehdi_amini, void Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D21515 llvm-svn: 281018
2016-08-15P0217R3: code generation support for decomposition declarations.Richard Smith
llvm-svn: 278642
2016-07-28[OpenCL] Generate opaque type for sampler_t and function call for the ↵Yaxun Liu
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
2016-07-08[CodeGen] Use llvm::Type::getVectorNumElements instead of casting to ↵Craig Topper
llvm::VectorType and calling getNumElements. This is equivalent and shorter. llvm-svn: 274823
2016-07-01[Temporary, Lifetime] Add lifetime marks for temporariesTim Shen
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