summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen/CGExpr.cpp
Commit message (Collapse)AuthorAgeFilesLines
* SanitizerBlacklist: blacklist functions by their source location.Alexey Samsonov2014-10-171-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit changes the way we blacklist functions in ASan, TSan, MSan and UBSan. We used to treat function as "blacklisted" and turned off instrumentation in it in two cases: 1) Function is explicitly blacklisted by its mangled name. This part is not changed. 2) Function is located in llvm::Module, whose identifier is contained in the list of blacklisted sources. This is completely wrong, as llvm::Module may not correspond to the actual source file function is defined in. Also, function can be defined in a header, in which case user had to blacklist the .cpp file this header was #include'd into, not the header itself. Such functions could cause other problems - for instance, if the header was included in multiple source files, compiled separately and linked into a single executable, we could end up with both instrumented and non-instrumented version of the same function participating in the same link. After this change we will make blacklisting decision based on the SourceLocation of a function definition. If a function is not explicitly defined in the source file, (for example, the function is compiler-generated and responsible for initialization/destruction of a global variable), then it will be blacklisted if the corresponding global variable is defined in blacklisted source file, and will be instrumented otherwise. After this commit, the active users of blacklist files may have to revisit them. This is a backwards-incompatible change, but I don't think it's possible or makes sense to support the old incorrect behavior. I plan to make similar change for blacklisting GlobalVariables (which is ASan-specific). llvm-svn: 219997
* Moving CGF::EmitAlignmentAssumption to IRBuilderHal Finkel2014-10-151-29/+0
| | | | | | | | The functionality contained in CodeGenFunction::EmitAlignmentAssumption has been moved to IRBuilder (so that it can also be used by LLVM-level code). Remove this now-duplicate implementation in favor of the IRBuilder code. llvm-svn: 219877
* Sanitize upcasts and conversion to virtual base.Alexey Samsonov2014-10-131-11/+13
| | | | | | | | | | | This change adds UBSan check to upcasts. Namely, when we perform derived-to-base conversion, we: 1) check that the pointer-to-derived has suitable alignment and underlying storage, if this pointer is non-null. 2) if vptr-sanitizer is enabled, and we perform conversion to virtual base, we check that pointer-to-derived has a matching vptr. llvm-svn: 219642
* Revert r218865 because it introduced PR21236, a crash in codegen emitting ↵Nick Lewycky2014-10-101-27/+11
| | | | | | the try block. llvm-svn: 219470
* Fix for bug http://llvm.org/PR17427.Alexey Bataev2014-10-091-79/+12
| | | | | | | | Assertion failed: "Computed __func__ length differs from type!" Reworked PredefinedExpr representation with internal StringLiteral field for function declaration. Differential Revision: http://reviews.llvm.org/D5365 llvm-svn: 219393
* Fix IRGen for referencing a static local before emitting its declReid Kleckner2014-10-081-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Previously CodeGen assumed that static locals were emitted before they could be accessed, which is true for automatic storage duration locals. However, it is possible to have CodeGen emit a nested function that uses a static local before emitting the function that defines the static local, breaking that assumption. Fix it by creating the static local upon access and ensuring that the deferred function body gets emitted. We may not be able to emit the initializer properly from outside the function body, so don't try. Fixes PR18020. See also previous attempts to fix static locals in PR6769 and PR7101. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4787 llvm-svn: 219265
* MS ABI: Implement thread_local for global variablesDavid Majnemer2014-10-051-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This add support for the C++11 feature, thread_local global variables. The ABI Clang implements is an improvement of the MSVC ABI. Sadly, further improvements could be made but not without sacrificing ABI compatibility. The feature is implemented as follows: - All thread_local initialization routines are pointed to from the .CRT$XDU section. - All non-weak thread_local variables have their initialization routines call from a single function instead of getting their own .CRT$XDU section entry. This is done to open up optimization opportunities to the compiler. - All weak thread_local variables have their own .CRT$XDU section entry. This entry is in a COMDAT with the global variable it is initializing; this ensures that we will initialize the global exactly once. - Destructors are registered in the initialization function using __tlregdtor. Differential Revision: http://reviews.llvm.org/D5597 llvm-svn: 219074
* Emit lifetime.start / lifetime.end markers for unnamed temporary objects.Arnaud A. de Grandmaison2014-10-021-11/+27
| | | | | | | This will give more information to the optimizers so that they can reuse stack slots and reduce stack usage. llvm-svn: 218865
* Merge GetAddrOfCXXConstructor and GetAddrOfCXXDonstructor. NFC.Rafael Espindola2014-09-111-2/+2
| | | | llvm-svn: 217598
* Implement nonnull-attribute sanitizerAlexey Samsonov2014-09-081-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch implements a new UBSan check, which verifies that function arguments declared to be nonnull with __attribute__((nonnull)) are actually nonnull in runtime. To implement this check, we pass FunctionDecl to CodeGenFunction::EmitCallArgs (where applicable) and if function declaration has nonnull attribute specified for a certain formal parameter, we compare the corresponding RValue to null as soon as it's calculated. Test Plan: regression test suite Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits, rnk Differential Revision: http://reviews.llvm.org/D5082 llvm-svn: 217389
* Add __builtin_assume and __builtin_assume_aligned using @llvm.assume.Hal Finkel2014-09-071-0/+28
| | | | | | | | | | | This makes use of the recently-added @llvm.assume intrinsic to implement a __builtin_assume(bool) intrinsic (to provide additional information to the optimizer). This hooks up __assume in MS-compatibility mode to mirror __builtin_assume (the semantics have been intentionally kept compatible), and implements GCC's __builtin_assume_aligned as assume((p - o) & mask == 0). LLVM now contains special logic to deal with assumptions of this form. llvm-svn: 217349
* Kill one of EmitCallArgs overloads. NFC.Alexey Samsonov2014-08-281-1/+1
| | | | llvm-svn: 216635
* Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or ↵Craig Topper2014-08-271-1/+1
| | | | | | just letting them be implicitly created. llvm-svn: 216528
* Pass expressions instead of argument ranges to EmitCall/EmitCXXConstructorCall.Alexey Samsonov2014-08-211-9/+6
| | | | | | | | | | | | | | | | | | | | | | | Summary: This is a first small step towards passing generic "Expr" instead of ArgBeg/ArgEnd pair into EmitCallArgs() family of methods. Having "Expr" will allow us to get the corresponding FunctionDecl and its ParmVarDecls, thus allowing us to alter CodeGen depending on the function/parameter attributes. No functionality change. Test Plan: regression test suite Reviewers: rnk Reviewed By: rnk Subscribers: aemerson, cfe-commits Differential Revision: http://reviews.llvm.org/D4915 llvm-svn: 216214
* ext_vector IRGen. Patch to allow indexing into Fariborz Jahanian2014-08-191-3/+35
| | | | | | | ext_vector_type's 'hi/lo' components when used as lvalue. rdar://18031917 pr20697 llvm-svn: 215991
* [Sanitizer] Introduce SanitizerMetadata class.Alexey Samsonov2014-08-011-3/+3
| | | | | | | | | | | | | | It is responsible for generating metadata consumed by sanitizer instrumentation passes in the backend. Move several methods from CodeGenModule to SanitizerMetadata. For now the class is stateless, but soon it won't be the case. Instead of creating globals providing source-level information to ASan, we will create metadata nodes/strings which will be turned into actual global variables in the backend (if needed). No functionality change. llvm-svn: 214564
* Revert "Emit column debug information for loads"Tobias Grosser2014-07-291-3/+0
| | | | | | | | | | | | | | | | This broke the following gdb tests: gdb.base__annota1.exp gdb.base__consecutive.exp gdb.python__py-symtab.exp gdb.reverse__consecutive-precsave.exp gdb.reverse__consecutive-reverse.exp I will look into this. This reverts commit 214162. llvm-svn: 214163
* Emit column debug information for loadsTobias Grosser2014-07-291-0/+3
| | | | | | | | | This allows us to give more precise diagnostics. Diego kindly tested the impact on debug info size: "The increase on average debug sizes is 0.1%. The total file size increase is ~0%." llvm-svn: 214162
* Revert "Emit lifetime.start / lifetime.end markers for unnamed temporary ↵Arnaud A. de Grandmaison2014-07-211-25/+0
| | | | | | | | | objects." This commit did break the sanitizer-x86 bot. Revert it while investigating. llvm-svn: 213579
* Emit lifetime.start / lifetime.end markers for unnamed temporary objects.Arnaud A. de Grandmaison2014-07-211-0/+25
| | | | | | This will give more information to the optimizers so that they can reuse stack slots. llvm-svn: 213576
* [UBsan] Skip -fsanitize=vptr instrumentations when the pointer value is null.Alexey Samsonov2014-07-181-1/+1
| | | | | | | | | | Otherwise -fsanitize=vptr causes the program to crash when it downcasts a null pointer. Reviewed in http://reviews.llvm.org/D4412. Patch by Byoungyoung Lee! llvm-svn: 213393
* Make sure globals created by UBSan are not instrumented by ASan.Alexey Samsonov2014-07-181-6/+17
| | | | | | | | | | | | | | | | | | | | | | Summary: This change adds description of globals created by UBSan instrumentation (UBSan handlers, type descriptors, filenames) to llvm.asan.globals metadata, effectively "blacklisting" them. This can dramatically decrease the data section in binaries built with UBSan+ASan, as UBSan tends to create a lot of handlers, and ASan instrumentation increases the global size to at least 64 bytes. Test Plan: clang regression test suite Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits, byoungyoung, kcc Differential Revision: http://reviews.llvm.org/D4575 llvm-svn: 213392
* Revert "Emit lifetime.start / lifetime.end markers for unnamed temporary ↵Arnaud A. de Grandmaison2014-07-181-15/+0
| | | | | | | | | objects." This reverts commit dbf785a6432f78a8ec229665876647c4cc610d3d, while I qm investigating a buildbot failure. llvm-svn: 213380
* Emit lifetime.start / lifetime.end markers for unnamed temporary objects.Arnaud A. de Grandmaison2014-07-181-0/+15
| | | | | | This will give more information to the optimizers so that they can reuse stack slots. llvm-svn: 213379
* [UBSan] Add !nosanitize metadata to the code generated by UBSan.Alexey Samsonov2014-07-171-0/+6
| | | | | | | | | | This is used to mark the instructions emitted by Clang to implement variety of UBSan checks. Generally, we don't want to instrument these instructions with another sanitizers (like ASan). Reviewed in http://reviews.llvm.org/D4544 llvm-svn: 213291
* [UBSan] Introduce type-based blacklisting.Alexey Samsonov2014-07-101-38/+42
| | | | | | | | | Teach UBSan vptr checker to ignore technically invalud down-casts on blacklisted types. Based on http://reviews.llvm.org/D4407 by Byoungyoung Lee! llvm-svn: 212770
* [Sanitizer] Remove brittle cache variable and slightly simplify blacklisting ↵Alexey Samsonov2014-07-071-3/+8
| | | | | | | | | | | | code. Now CodeGenFunction is responsible for looking at sanitizer blacklist (in CodeGenFunction::StartFunction) and turning off instrumentation, if necessary. No functionality change. llvm-svn: 212501
* Don't crash when emitting a glvalue conditional where one arm is aRichard Smith2014-06-201-10/+32
| | | | | | throw-expression. Based on a patch by Marius Wachtler! llvm-svn: 211388
* Use StringRef to simplify code. No functional change.Craig Topper2014-06-121-1/+1
| | | | llvm-svn: 210751
* Use ArrayRef in some function parameters instead of a pointer and count. No ↵Craig Topper2014-06-121-1/+1
| | | | | | functional change. llvm-svn: 210750
* [C++11] Use 'nullptr'.Craig Topper2014-06-091-1/+1
| | | | llvm-svn: 210448
* Mangle predefined string constants names to merge them at link-timeAlexey Samsonov2014-06-051-30/+6
| | | | | | | | | | | | | | | | | | | | | Summary: This change generalizes the code used to create global LLVM variables referencing predefined strings (e.g. __FUNCTION__): now it just calls GetAddrOfConstantStringFromLiteral method. As a result, global variables for these predefined strings may get mangled names and linkonce_odr linkage. Fix the test accordingly. Test Plan: clang regression tests Reviewers: majnemer Reviewed By: majnemer Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4023 llvm-svn: 210284
* Add pointer types to global named registerRenato Golin2014-06-051-5/+25
| | | | | | | | | | This patch adds support for pointer types in global named registers variables. It'll be lowered as a pair of read/write_register and inttoptr/ptrtoint calls. Also adds some early checks on types on SemaDecl to avoid the assert. Tests changed accordingly. (PR19837) llvm-svn: 210274
* Formatting cleanup.Richard Smith2014-06-041-10/+9
| | | | llvm-svn: 210219
* [CodeGen] Don't cast and use SizeTy instead of Int32Ty when constructing ↵Michael J. Spencer2014-05-311-3/+2
| | | | | | {extract,insert} vector element instructions. llvm-svn: 209942
* Revert small change to EmitDeclRefLValueRenato Golin2014-05-271-9/+8
| | | | | | | That small change, although it looked harmless, it made emitting the LValue on the PHI node without the proper cast. Reverting it fixes PR19841. llvm-svn: 209663
* [MS-ABI] Implements MS-compatible RTTIWarren Hunt2014-05-231-2/+2
| | | | | | | | | | | | | Enables the emission of MS-compatible RTTI data structures for use with typeid, dynamic_cast and exceptions. Does not implement dynamic_cast or exceptions. As an artiface, typeid works in some cases but proper support an testing will coming in a subsequent patch. majnemer has fuzzed the results. Test cases included. Differential Revision: http://reviews.llvm.org/D3833 llvm-svn: 209523
* [C++11] Use 'nullptr'. CodeGen edition.Craig Topper2014-05-211-17/+17
| | | | llvm-svn: 209272
* Clean up language and grammar.Eric Christopher2014-05-201-1/+1
| | | | | | | Based on a patch by jfcaron3@gmail.com! PR19806 llvm-svn: 209215
* Using SmallString and correct addr varRenato Golin2014-05-191-3/+5
| | | | llvm-svn: 209180
* Fix usage of string when StringRef was neededRenato Golin2014-05-191-1/+3
| | | | | | | | | Also adding a variable to the test, so release bots match %1. This should also calm the gdb buildbot. . llvm-svn: 209171
* Non-allocatable Global Named RegisterRenato Golin2014-05-191-2/+58
| | | | | | | | | | | | | This patch implements global named registers in Clang, lowering to the just created intrinsics in LLVM (@llvm.read/write_register). A new type of LValue had to be created (Register), which just adds support to carry the metadata node containing the name of the register. Two new methods to emit loads and stores interoperate with another to emit the named metadata node. No guarantees are being made and only non-allocatable global variable named registers are being supported. Local named register support is unchanged. llvm-svn: 209149
* Add FIXME describing the limitation of using column info to disambiguate ↵David Blaikie2014-05-101-0/+8
| | | | | | | | | | | | | | | | | | | | inlining. Also tidy up, simplify, and extend the test coverage to demonstrate the limitations. This test should now fail if the bugs are fixed (& hopefully whoever ends up in this situation sees the FIXMEs and realizes that the test needs to be updated to positively test their change that has fixed some or all of these issues). I do wonder whether I could demonstrate breakage without a macro here, but any way I slice it I can't think of a way to get two calls to the same function on the same line/column in non-macro C++ - implicit conversions happen at the same location as an explicit function, but you'd never get an implicit conversion on the result of an explicit call to the same implicit conversion operator (since the value is already converted to the desired result)... llvm-svn: 208468
* Use auto to avoid duplicating the type.Rafael Espindola2014-05-091-64/+58
| | | | llvm-svn: 208374
* Add support for MSVC's __FUNCSIG__Reid Kleckner2014-04-081-21/+13
| | | | | | | | | | | It is very similar to GCC's __PRETTY_FUNCTION__, except it prints the calling convention. Reviewers: majnemer Differential Revision: http://reviews.llvm.org/D3311 llvm-svn: 205780
* PR19254: If a thread_local data member of a class is accessed via member accessRichard Smith2014-03-261-7/+8
| | | | | | syntax, don't forget to run its initializer. llvm-svn: 204869
* Sema: Do not assert when dereferencing member pointer using virtual ↵David Majnemer2014-02-201-3/+3
| | | | | | | | | | | | | | inheritance with an incomplete class type The MS ABI requires that we determine the vbptr offset if have a virtual inheritance model. Instead, raise an error pointing to the diagnostic when this happens. This fixes PR18583. Differential Revision: http://llvm-reviews.chandlerc.com/D2842 llvm-svn: 201824
* Change PGO instrumentation to compute counts in a separate AST traversal.Bob Wilson2014-02-171-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, we made one traversal of the AST prior to codegen to assign counters to the ASTs and then propagated the count values during codegen. This patch now adds a separate AST traversal prior to codegen for the -fprofile-instr-use option to propagate the count values. The counts are then saved in a map from which they can be retrieved during codegen. This new approach has several advantages: 1. It gets rid of a lot of extra PGO-related code that had previously been added to codegen. 2. It fixes a serious bug. My original implementation (which was mailed to the list but never committed) used 3 counters for every loop. Justin improved it to move 2 of those counters into the less-frequently executed breaks and continues, but that turned out to produce wrong count values in some cases. The solution requires visiting a loop body before the condition so that the count for the condition properly includes the break and continue counts. Changing codegen to visit a loop body first would be a fairly invasive change, but with a separate AST traversal, it is easy to control the order of traversal. I've added a testcase (provided by Justin) to make sure this works correctly. 3. It improves the instrumentation overhead, reducing the number of counters for a loop from 3 to 1. We no longer need dedicated counters for breaks and continues, since we can just use the propagated count values when visiting breaks and continues. To make this work, I needed to make a change to the way we count case statements, going back to my original approach of not including the fall-through in the counter values. This was necessary because there isn't always an AST node that can be used to record the fall-through count. Now case statements are handled the same as default statements, with the fall-through paths branching over the counter increments. While I was at it, I also went back to using this approach for do-loops -- omitting the fall-through count into the loop body simplifies some of the calculations and make them behave the same as other loops. Whenever we start using this instrumentation for coverage, we'll need to add the fall-through counts into the counter values. llvm-svn: 201528
* Rename getResultType() on function and method declarations to getReturnType()Alp Toker2014-01-251-2/+2
| | | | | | | | | | | | | | | A return type is the declared or deduced part of the function type specified in the declaration. A result type is the (potentially adjusted) type of the value of an expression that calls the function. Rule of thumb: * Declarations have return types and parameters. * Expressions have result types and arguments. llvm-svn: 200082
* CodeGen: Rename adjustFallThroughCount -> adjustForControlFlowJustin Bogner2014-01-131-2/+2
| | | | | | | | adjustFallThroughCount isn't a good name, and the documentation was even worse. This commit attempts to clarify what it's for and when to use it. llvm-svn: 199139
OpenPOWER on IntegriCloud