summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprScalar.cpp
AgeCommit message (Collapse)Author
2013-11-08Remove an incorrect optimization inside Clang's IRGen. Its check to determineNick Lewycky
whether we can safely lower a conditional operator to select was insufficient. I've left a large comment in place to explaining the sort of problems that this transform can encounter in clang in the hopes of discouraging others from reimplementing it wrongly again in the future. (The test should also help with that, but it's easy to work around any single test I might add and think that your particular implementation doesn't miscompile any code.) llvm-svn: 194289
2013-10-22Split -fsanitize=bounds to -fsanitize=array-bounds (for the frontend-insertedRichard Smith
check using the ubsan runtime) and -fsanitize=local-bounds (for the middle-end check which inserts traps). Remove -fsanitize=local-bounds from -fsanitize=undefined. It does not produce useful diagnostics and has false positives (PR17635), and is not a good compromise position between UBSan's checks and ASan's checks. Map -fbounds-checking to -fsanitize=local-bounds to restore Clang's historical behavior for that flag. llvm-svn: 193205
2013-10-02Thread a SourceLocation into the EmitCheck for "load_invalid_value". This occursNick Lewycky
when scalars are loaded / undergo lvalue-to-rvalue conversion. llvm-svn: 191808
2013-09-18Add the intrinsic __builtin_convertvectorHal Finkel
LLVM supports applying conversion instructions to vectors of the same number of elements (fptrunc, fptosi, etc.) but there had been no way for a Clang user to cause such instructions to be generated when using builtin vector types. C-style casting on vectors is already defined in terms of bitcasts, and so cannot be used for these conversions as well (without leading to a very confusing set of semantics). As a result, this adds a __builtin_convertvector intrinsic (patterned after the OpenCL __builtin_astype intrinsic). This is intended to aid the creation of vector intrinsic headers that create generic IR instead of target-dependent intrinsics (in other words, this is a generic _mm_cvtepi32_ps). As noted in the documentation, the action of __builtin_convertvector is defined in terms of the action of a C-style cast on each vector element. llvm-svn: 190915
2013-08-08UBSan: Fix alignment checks emitted in downcasts.Filipe Cabecinhas
Summary: UBSan was checking for alignment of the derived class on the pointer to the base class, before converting. With some class hierarchies, this could generate false positives. Added test-case. llvm-svn: 187948
2013-08-03Add support for passing -1 to __builtin_shufflevector to signify an ↵Craig Topper
undefined element value to match IR capabilities. llvm-svn: 187694
2013-08-01Remove more odd code that tries to account for an off by 1 problem in vec3 ↵Craig Topper
shuffles that doesn't really exist. llvm-svn: 187561
2013-08-01Fix to handle all non-power-of-2 vector sizes in the mask form of ↵Craig Topper
_builtin_shuffle_vector. Previously a 2-bit mask was used to mask each element of a vec6 mask before doing the extracts instead of 3-bit mask necessary to cover 0-5. vec3 was the only non-power-of-2 that worked correctly because a +1 conditionally added before calculating floor(log2(elements)). llvm-svn: 187560
2013-08-01Remove broken and unnecessary vec3 handling from VisitShuffleVectorExpr.Craig Topper
llvm-svn: 187558
2013-07-27Fix formatting. No functional change.Craig Topper
llvm-svn: 187294
2013-07-26Remove trailing whitespace.Craig Topper
llvm-svn: 187190
2013-07-20Make IgnoreParens() look through ChooseExprs.Eli Friedman
This is the same way GenericSelectionExpr works, and it's generally a more consistent approach. A large part of this patch is devoted to caching the value of the condition of a ChooseExpr; it's needed to avoid threading an ASTContext into IgnoreParens(). Fixes <rdar://problem/14438917>. llvm-svn: 186738
2013-07-16Make Expr::isConstantInitializer match IRGen.Eli Friedman
Sema needs to be able to accurately determine what will be emitted as a constant initializer and what will not, so we get accurate errors in C and accurate -Wglobal-constructors warnings in C++. This makes Expr::isConstantInitializer match CGExprConstant as closely as possible. llvm-svn: 186464
2013-07-13PR16214, PR14467: DebugInfo: use "RequireCompleteType" to decide when to ↵David Blaikie
emit the full definition of a type in -flimit-debug-info This simplifies the core benefit of -flimit-debug-info by taking a more systematic approach to avoid emitting debug info definitions for types that only require declarations. The previous ad-hoc approach (3 cases removed in this patch) had many holes. The general approach (adding a bit to TagDecl and callback through ASTConsumer) has been discussed with Richard Smith - though always open to revision. llvm-svn: 186262
2013-06-12Add support for complex compound assignments where the LHS is a scalar.Eli Friedman
Fixes <rdar://problem/11224126> and PR12790. llvm-svn: 183821
2013-06-10Make sure we don't emit invalid IR for StmtExprs with complex cleanups.Eli Friedman
Fixes <rdar://problem/14074868>. llvm-svn: 183699
2013-04-20C++1y: Allow aggregates to have default initializers.Richard Smith
Add a CXXDefaultInitExpr, analogous to CXXDefaultArgExpr, and use it both in CXXCtorInitializers and in InitListExprs to represent a default initializer. There's an additional complication here: because the default initializer can refer to the initialized object via its 'this' pointer, we need to make sure that 'this' points to the right thing within the evaluation. llvm-svn: 179958
2013-04-16Standardize accesses to the TargetInfo in IR-gen.John McCall
Patch by Stephen Lin! llvm-svn: 179638
2013-03-27UBSan: Don't diagnose inf/nan conversions between floating-point types. It's ↵Richard Smith
far from clear whether these have undefined behavior, and these checks are helping no-one. Keep the double->float overflow warnings, though, since those are useful in practice, even though it's unclear whether such operations have defined behavior. llvm-svn: 178194
2013-03-19PR15383: When -fsanitize=float-cast-overflow checks a float-to-int conversion,Richard Smith
it wasn't taking into account that the float should be truncated *before* the range check happens. Thus (unsigned)-0.99 and (unsigned char)255.9 have defined behavior and should not be trapped. llvm-svn: 177362
2013-03-07Change hasAggregateLLVMType, which conflates complex andJohn McCall
aggregate types in a profoundly wrong way that has to be worked around in every call site, to getEvaluationKind, which classifies and distinguishes between all of these cases. Also, normalize the API for loading and storing complexes. I'm working on a larger patch and wanted to pull these changes out, but it would have be annoying to detangle them from each other. llvm-svn: 176656
2013-03-03Improve C11 atomics support:David Chisnall
- Generate atomicrmw operations in most of the cases when it's sensible to do so. - Don't crash in several common cases (and hopefully don't crash in more of them). - Add some better tests. We now generate significantly better code for things like: _Atomic(int) x; ... x++; On MIPS, this now generates a 4-instruction ll/sc loop, where previously it generated about 30 instructions in two nested loops. On x86-64, we generate a single lock incl, instead of a lock cmpxchgl loop (one instruction instead of ten). llvm-svn: 176420
2013-02-28Use the actual ABI-determined C calling convention for runtimeJohn McCall
calls and declarations. LLVM has a default CC determined by the target triple. This is not always the actual default CC for the ABI we've been asked to target, and so we sometimes find ourselves annotating all user functions with an explicit calling convention. Since these calling conventions usually agree for the simple set of argument types passed to most runtime functions, using the LLVM-default CC in principle has no effect. However, the LLVM optimizer goes into histrionics if it sees this kind of formal CC mismatch, since it has no concept of CC compatibility. Therefore, if this module happens to define the "runtime" function, or got LTO'ed with such a definition, we can miscompile; so it's quite important to get this right. Defining runtime functions locally is quite common in embedded applications. llvm-svn: 176286
2013-02-25[ubsan] Emit single check for left shift.Will Dietz
Avoids warning twice on same shift. llvm-svn: 176056
2013-02-23ubsan: Emit bounds checks for array indexing, vector indexing, and (in ↵Richard Smith
really simple cases) pointer arithmetic. This augments the existing bounds checking with language-level array bounds information. llvm-svn: 175949
2013-02-21Add support to Sema and CodeGen for floating point vector types in OpenCL.Joey Gouly
llvm-svn: 175734
2013-02-13ubsan: Add checking for invalid downcasts. Per [expr.static.cast]p2 and p11,Richard Smith
base-to-derived casts have undefined behavior if the object is not actually an instance of the derived type. llvm-svn: 175078
2013-01-29[ubsan] Implement the -fcatch-undefined-behavior flag using a trappingChad Rosier
implementation; this is much more inline with the original implementation (i.e., pre-ubsan) and does not require run-time library support. The trapping implementation can be invoked using either '-fcatch-undefined-behavior' or '-fsanitize=undefined-trap -fsanitize-undefined-trap-on-error', with the latter being preferred. Eventually, the -fcatch-undefined-behavior' flag will be removed. llvm-svn: 173848
2013-01-23Add a new LangOpt NativeHalfType. This option allows for native half/fp16Joey Gouly
operations (as opposed to storage only half/fp16). Also add some semantic checks for OpenCL half types. llvm-svn: 173254
2013-01-20Implement OpenCL event_t as Clang builtin type, including event_t related ↵Guy Benyei
OpenCL restrictions (OpenCL 1.2 spec 6.9) llvm-svn: 172973
2013-01-18[ubsan] Add support for -fsanitize-blacklistWill Dietz
llvm-svn: 172808
2013-01-12Remove useless 'llvm::' qualifier from names like StringRef and others that areDmitri Gribenko
brought into 'clang' namespace by clang/Basic/LLVM.h llvm-svn: 172323
2013-01-10Testing with a full OpenCL compiler (based on clang) reveals r71734 missedDavid Tweed
difference between type widths of a vector and the width of one of its elements in the case of vector shifts. Use correct witdth in the vector case. llvm-svn: 172047
2013-01-07[ubsan] Use correct type for compound assignment ops.Will Dietz
llvm-svn: 171801
2013-01-07Scalar shifts in the OpenCL specification (as of v. 1.2) are defined to beDavid Tweed
with respect to the lower "left-hand-side bitwidth" bits, even when negative); see OpenCL spec 6.3j. This patch both implements this behaviour in the code generator and "constant folding" bits of Sema, and also prevents tests to detect undefinedness in terms of the weaker C99 or C++ specifications from being applied. llvm-svn: 171755
2013-01-02Rewrite #includes for llvm/Foo.h to llvm/IR/Foo.h as appropriate toChandler Carruth
reflect the migration in r171366. Re-sort the #include lines to reflect the new paths. llvm-svn: 171369
2013-01-01Simplify vector splat code. No functionality change.Benjamin Kramer
llvm-svn: 171350
2012-12-21Reinstate r170806, reverted in r170835, with a fix use i1 instead of i8 for ↵Richard Smith
a value-initialized bool! llvm-svn: 170837
2012-12-21Revert r170806, "Fix some bugs where we would sometimes use 0, not -1, when ↵NAKAMURA Takumi
emitting a null constant of type pointer-to-data-member." It broke stage2. llvm-svn: 170835
2012-12-20Fix some bugs where we would sometimes use 0, not -1, when emitting a null ↵Richard Smith
constant of type pointer-to-data-member. llvm-svn: 170806
2012-12-04Sort all of Clang's files under 'lib', and fix up the broken headersChandler Carruth
uncovered. This required manually correcting all of the incorrect main-module headers I could find, and running the new llvm/utils/sort_includes.py script over the files. I also manually added quite a few missing headers that were uncovered by shuffling the order or moving headers up to be main-module-headers. llvm-svn: 169237
2012-12-02[ubsan] Add flag to enable recovery from checks when possible.Will Dietz
llvm-svn: 169114
2012-11-27Add -fsanitize=integer for reporting suspicious integer behaviors.Will Dietz
Introduces new sanitizer "unsigned-integer-overflow". llvm-svn: 168701
2012-11-15Make -ffp-contract a codegen option, rather than a laguage option. This makesLang Hames
more sense anyway - it determines how expressions are codegen'd. It also ensures that -ffp-contract=fast has the intended effect when compiling LLVM IR. llvm-svn: 168027
2012-11-06Classify the INT_MIN/-1 check as -fsanitize=signed-integer-overflow, not as ↵Richard Smith
-fsanitize=divide-by-zero. llvm-svn: 167433
2012-11-05Use the individual -fsanitize=<...> arguments to control which of the UBSanRichard Smith
checks to enable. Remove frontend support for -fcatch-undefined-behavior, -faddress-sanitizer and -fthread-sanitizer now that they don't do anything. llvm-svn: 167413
2012-11-01Simplify: replace getContext().getLangOpts() with just getLangOpts().Richard Smith
llvm-svn: 167261
2012-11-01Clean up misapplication of diff.Richard Smith
llvm-svn: 167260
2012-11-01Split emission of -ftrapv checks and -fcatch-undefined-behavior checks intoRichard Smith
separate functions, since they share essentially no code. llvm-svn: 167259
2012-11-01Remove divison-by-zero checks from -ftrapv. These checks were incompatible withRichard Smith
g++'s -ftrapv, failed to call the -ftrapv overflow handler, and are still available under -fcatch-undefined-behavior. llvm-svn: 167258