summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExpr.cpp
AgeCommit message (Collapse)Author
2014-11-11[OPENMP] Codegen for threadprivate variablesAlexey Bataev
For all threadprivate variables which have constructor/destructor emit call to void __kmpc_threadprivate_register(ident_t * <Current Location>, void *<Original Global Addr>, kmpc_ctor <Constructor>, kmpc_cctor NULL, kmpc_dtor <Destructor>); In expressions all references to such variables are replaced by calls to void *__kmpc_threadprivate_cached(ident_t *<Current Location>, kmp_int32 <Current Thread Id>, void *<Original Global Addr>, size_t <Size of Data>, void ***<Pointer to autogenerated cache – array of private copies of threadprivate variable>); Test test/OpenMP/threadprivate_codegen.cpp checks that codegen is correct. Also it checks that codegen is correct after serialization/deserialization and one of passes verifies debug info. Differential Revision: http://reviews.llvm.org/D4002 llvm-svn: 221663
2014-11-11CGExpr.cpp: Suppress a warning. [-Wunused-variable]NAKAMURA Takumi
llvm-svn: 221655
2014-11-10Propagate SanitizerKind into CodeGenFunction::EmitCheck() call.Alexey Samsonov
Make sure CodeGenFunction::EmitCheck() knows which sanitizer it emits check for. Make CheckRecoverableKind enum an implementation detail and move it away from header. Currently CheckRecoverableKind is determined by the type of sanitizer ("unreachable" and "return" are unrecoverable, "vptr" is always-recoverable, all the rest are recoverable). This will change in future if we allow to specify which sanitizers are recoverable, and which are not by -fsanitize-recover= flag. No functionality change. llvm-svn: 221635
2014-11-07Introduce a SanitizerKind enum to LangOptions.Alexey Samsonov
Use the bitmask to store the set of enabled sanitizers instead of a bitfield. On the negative side, it makes syntax for querying the set of enabled sanitizers a bit more clunky. On the positive side, we will be able to use SanitizerKind to eventually implement the new semantics for -fsanitize-recover= flag, that would allow us to make some sanitizers recoverable, and some non-recoverable. No functionality change. llvm-svn: 221558
2014-10-30Get rid of SanitizerOptions::Disabled global. NFC.Alexey Samsonov
SanitizerOptions is not even a POD now, so having global variable of this type, is not nice. Instead, provide a regular constructor and clear() method, and let each CodeGenFunction has its own copy of SanitizerOptions it uses. llvm-svn: 220920
2014-10-24CodeGen: correct materialize temporary aggregates in ARC modeSaleem Abdulrasool
Avoid an assertion when materializing a lifetime type aggregate temporary. When performing CodeGen for ObjC++, we could generate a lifetime-only aggregate temporary by using an initializer list (which is effectively an array). We would reach through the temporary expression, fishing out the inner expression. If this expression was a lifetime expression, we would attempt to emit this as a scalar. This would eventually result in an assertion as the emission would eventually assert that the expression being emitted has a scalar evaluation kind. Add a case to handle the aggregate expressions. Use the EmitAggExpr to emit the aggregate expression rather than the EmitScalarInit. Addresses PR21347. llvm-svn: 220590
2014-10-24CodeGen: trivial conversion to range based loopSaleem Abdulrasool
Switch to a range-based for loop. NFC. llvm-svn: 220587
2014-10-17SanitizerBlacklist: blacklist functions by their source location.Alexey Samsonov
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
2014-10-15Moving CGF::EmitAlignmentAssumption to IRBuilderHal Finkel
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
2014-10-13Sanitize upcasts and conversion to virtual base.Alexey Samsonov
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
2014-10-10Revert r218865 because it introduced PR21236, a crash in codegen emitting ↵Nick Lewycky
the try block. llvm-svn: 219470
2014-10-09Fix for bug http://llvm.org/PR17427.Alexey Bataev
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
2014-10-08Fix IRGen for referencing a static local before emitting its declReid Kleckner
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
2014-10-05MS ABI: Implement thread_local for global variablesDavid Majnemer
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
2014-10-02Emit lifetime.start / lifetime.end markers for unnamed temporary objects.Arnaud A. de Grandmaison
This will give more information to the optimizers so that they can reuse stack slots and reduce stack usage. llvm-svn: 218865
2014-09-11Merge GetAddrOfCXXConstructor and GetAddrOfCXXDonstructor. NFC.Rafael Espindola
llvm-svn: 217598
2014-09-08Implement nonnull-attribute sanitizerAlexey Samsonov
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
2014-09-07Add __builtin_assume and __builtin_assume_aligned using @llvm.assume.Hal Finkel
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
2014-08-28Kill one of EmitCallArgs overloads. NFC.Alexey Samsonov
llvm-svn: 216635
2014-08-27Simplify creation of a bunch of ArrayRefs by using None, makeArrayRef or ↵Craig Topper
just letting them be implicitly created. llvm-svn: 216528
2014-08-21Pass expressions instead of argument ranges to EmitCall/EmitCXXConstructorCall.Alexey Samsonov
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
2014-08-19ext_vector IRGen. Patch to allow indexing into Fariborz Jahanian
ext_vector_type's 'hi/lo' components when used as lvalue. rdar://18031917 pr20697 llvm-svn: 215991
2014-08-01[Sanitizer] Introduce SanitizerMetadata class.Alexey Samsonov
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
2014-07-29Revert "Emit column debug information for loads"Tobias Grosser
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
2014-07-29Emit column debug information for loadsTobias Grosser
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
2014-07-21Revert "Emit lifetime.start / lifetime.end markers for unnamed temporary ↵Arnaud A. de Grandmaison
objects." This commit did break the sanitizer-x86 bot. Revert it while investigating. llvm-svn: 213579
2014-07-21Emit lifetime.start / lifetime.end markers for unnamed temporary objects.Arnaud A. de Grandmaison
This will give more information to the optimizers so that they can reuse stack slots. llvm-svn: 213576
2014-07-18[UBsan] Skip -fsanitize=vptr instrumentations when the pointer value is null.Alexey Samsonov
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
2014-07-18Make sure globals created by UBSan are not instrumented by ASan.Alexey Samsonov
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
2014-07-18Revert "Emit lifetime.start / lifetime.end markers for unnamed temporary ↵Arnaud A. de Grandmaison
objects." This reverts commit dbf785a6432f78a8ec229665876647c4cc610d3d, while I qm investigating a buildbot failure. llvm-svn: 213380
2014-07-18Emit lifetime.start / lifetime.end markers for unnamed temporary objects.Arnaud A. de Grandmaison
This will give more information to the optimizers so that they can reuse stack slots. llvm-svn: 213379
2014-07-17[UBSan] Add !nosanitize metadata to the code generated by UBSan.Alexey Samsonov
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
2014-07-10[UBSan] Introduce type-based blacklisting.Alexey Samsonov
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
2014-07-07[Sanitizer] Remove brittle cache variable and slightly simplify blacklisting ↵Alexey Samsonov
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
2014-06-20Don't crash when emitting a glvalue conditional where one arm is aRichard Smith
throw-expression. Based on a patch by Marius Wachtler! llvm-svn: 211388
2014-06-12Use StringRef to simplify code. No functional change.Craig Topper
llvm-svn: 210751
2014-06-12Use ArrayRef in some function parameters instead of a pointer and count. No ↵Craig Topper
functional change. llvm-svn: 210750
2014-06-09[C++11] Use 'nullptr'.Craig Topper
llvm-svn: 210448
2014-06-05Mangle predefined string constants names to merge them at link-timeAlexey Samsonov
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
2014-06-05Add pointer types to global named registerRenato Golin
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
2014-06-04Formatting cleanup.Richard Smith
llvm-svn: 210219
2014-05-31[CodeGen] Don't cast and use SizeTy instead of Int32Ty when constructing ↵Michael J. Spencer
{extract,insert} vector element instructions. llvm-svn: 209942
2014-05-27Revert small change to EmitDeclRefLValueRenato Golin
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
2014-05-23[MS-ABI] Implements MS-compatible RTTIWarren Hunt
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
2014-05-21[C++11] Use 'nullptr'. CodeGen edition.Craig Topper
llvm-svn: 209272
2014-05-20Clean up language and grammar.Eric Christopher
Based on a patch by jfcaron3@gmail.com! PR19806 llvm-svn: 209215
2014-05-19Using SmallString and correct addr varRenato Golin
llvm-svn: 209180
2014-05-19Fix usage of string when StringRef was neededRenato Golin
Also adding a variable to the test, so release bots match %1. This should also calm the gdb buildbot. . llvm-svn: 209171
2014-05-19Non-allocatable Global Named RegisterRenato Golin
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
2014-05-10Add FIXME describing the limitation of using column info to disambiguate ↵David Blaikie
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