Commit Graph

617 Commits

Author SHA1 Message Date
Nuno Lopes ddcce0bb90 update calls to objectsize intrinsic to match LLVM r156473
add a test for -fbounds-checking code generation

llvm-svn: 156474
2012-05-09 15:53:34 +00:00
Nuno Lopes 3d6311d5f7 add -fbounds-checking option.
When enabled, clang generates bounds checks for array and pointers dereferences. Work to follow in LLVM's backend.

OK'ed by Chad; thanks for the review.

llvm-svn: 156431
2012-05-08 22:10:46 +00:00
Nuno Lopes f463abc0e7 remove code to add bound checks for simple array accesses, since those are already covered by the check with the objectsize builtin
remove the comparison of objectsize with -1. since it's an unsigned comparison, it will always succeed if objectsize returns -1, which is enough to have the check removed

llvm-svn: 156311
2012-05-07 17:57:00 +00:00
Ted Kremenek db74d0b28b Push variable declaration into nested scope (the only place where it is used). Found by static analyzer.
llvm-svn: 155922
2012-05-01 17:56:53 +00:00
John McCall c84ed6a336 Abstract the emission of global destructors into ABI-specific code
and only consider using __cxa_atexit in the Itanium logic.  The
default logic is to use atexit().

Emit "guarded" initializers in Microsoft mode unconditionally.
This is definitely not correct, but it's closer to correct than
just not emitting the initializer.

Based on a patch by Timur Iskhodzhanov!

llvm-svn: 155894
2012-05-01 06:13:13 +00:00
Duncan Sands 65229ed99a Adjust for LLVM name tweaks requested by Chandler.
llvm-svn: 154824
2012-04-16 16:29:47 +00:00
Eli Friedman 7f1ff60021 Propagate alignment on lvalues through EmitLValueForField. PR12395.
llvm-svn: 154789
2012-04-16 03:54:45 +00:00
Duncan Sands c720e78ebc Use MDBuilder to help with metadata creation.
llvm-svn: 154767
2012-04-15 18:04:54 +00:00
Duncan Sands 6fc461984a Rename "fpaccuracy" metadata to the more generic "fpmath". That's because I'm
thinking of generalizing it to be able to specify other freedoms beyond accuracy
(such as that NaN's don't have to be respected).  I'd like the 3.1 release (the
first one with this metadata) to have the more generic name already rather than
having to auto-upgrade it in 3.2.

llvm-svn: 154745
2012-04-14 12:37:26 +00:00
Anton Korobeynikov 4215ca7564 Step forward with supporting of ARM homogenous aggregates:
- Handle unions
  - Handle C++ classes

llvm-svn: 154664
2012-04-13 11:22:00 +00:00
Richard Smith d65cee9423 Implement __atomic_fetch_nand and __atomic_nand_fetch to complete our set of
GNU __atomic builtins.

llvm-svn: 154659
2012-04-13 06:31:38 +00:00
Richard Smith 01ba47d7b6 Implement the missing pieces needed to support libstdc++4.7's <atomic>:
__atomic_test_and_set, __atomic_clear, plus a pile of undocumented __GCC_*
predefined macros.

Implement library fallback for __atomic_is_lock_free and
__c11_atomic_is_lock_free, and implement __atomic_always_lock_free.

Contrary to their documentation, GCC's __atomic_fetch_add family don't
multiply the operand by sizeof(T) when operating on a pointer type.
libstdc++ relies on this quirk. Remove this handling for all but the
__c11_atomic_fetch_add and __c11_atomic_fetch_sub builtins.

Contrary to their documentation, __atomic_test_and_set and __atomic_clear
take a first argument of type 'volatile void *', not 'void *' or 'bool *',
and __atomic_is_lock_free and __atomic_always_lock_free have an argument
of type 'const volatile void *', not 'void *'.

With this change, libstdc++4.7's <atomic> passes libc++'s atomic test suite,
except for a couple of libstdc++ bugs and some cases where libc++'s test
suite tests for properties which implementations have latitude to vary.

llvm-svn: 154640
2012-04-13 00:45:38 +00:00
Douglas Gregor 298f43df14 Fix some i1/i8 confusion within _Atomic(bool) in IR generation, both
in general (such an atomic has boolean representation) and
specifically for IR generation of __c11_atomic_init. The latter also
means actually using initialization semantics for this initialization,
rather than just creating a store.

On a related note, make sure we actually put in non-atomic-to-atomic
conversions when performing an implicit conversion sequence. IR
generation is far too kind here, but we still want the ASTs to make
sense.

llvm-svn: 154612
2012-04-12 20:42:30 +00:00
Richard Smith feea883de4 Implement support for 18 of the GNU-compatible __atomic builtins.
This is not quite sufficient for libstdc++'s <atomic>: we still need
__atomic_test_and_set and __atomic_clear, and may need a more complete
__atomic_is_lock_free implementation.

We are also missing an implementation of __atomic_always_lock_free,
__atomic_nand_fetch, and __atomic_fetch_nand, but those aren't needed
for libstdc++.

llvm-svn: 154579
2012-04-12 05:08:17 +00:00
David Chisnall eb9496efc7 Make __atomic_init() (soon to be __c11_atomic_init()) work with non-scalar types.
llvm-svn: 154507
2012-04-11 17:24:05 +00:00
Duncan Sands e81111ca71 Express the number of ULPs in fpaccuracy metadata as a real rather than a
rational number, eg as 2.5 rather than 5, 2.  OK'd by Peter Collingbourne.

llvm-svn: 154388
2012-04-10 08:23:07 +00:00
David Chisnall db365f38ea Call out to GCC-compatible runtime functions for atomic ops that we can't use
LLVM intrinsics for.

I have an implementation of these functions, which wants to go in a libgcc_s
equivalent in compiler-rt.  It's currently here:

http://people.freebsd.org/~theraven/atomic.c

It will be committed to compiler-rt as soon as I work out where would be a
sensible place to put it...

llvm-svn: 153666
2012-03-29 18:01:11 +00:00
Chad Rosier 615ed1a3a6 Revert r153613 as it's causing large compile-time regressions on the nightly testers.
llvm-svn: 153660
2012-03-29 17:37:10 +00:00
John McCall 1a0877f99d When we can't prove that the target of an aggregate copy is
a complete object, the memcpy needs to use the data size of
the structure instead of its sizeof() value.  Fixes PR12204.

llvm-svn: 153613
2012-03-28 23:30:44 +00:00
Chandler Carruth 8b4140d712 Move the emission of strict enum range metadata behind a flag (the same
flag as GCC uses: -fstrict-enums). There is a *lot* of code making
unwarranted assumptions about the underlying type of enums, and it
doesn't seem entirely reasonable to eagerly break all of it.

Much more importantly, the current state of affairs is *very* good at
optimizing based upon this information, which causes failures that are
very distant from the actual enum. Before we push for enabling this by
default, I think we need to implement -fcatch-undefined-behavior support
for instrumenting and trapping whenever we store or load a value outside
of the range. That way we can track down the misbehaving code very
quickly.

I discussed this with Rafael, and currently the only important cases he
is aware of are the bool range-based optimizations which are staying
hard enabled. We've not seen any issue with those either, and they are
much more important for performance.

llvm-svn: 153550
2012-03-27 23:58:37 +00:00
Rafael Espindola 5c0034a7c6 Add back r153360 with a fix for enums that cover all the 32 bit values.
Thanks to NAKAMURA Takumi for finding it!

llvm-svn: 153383
2012-03-24 16:50:34 +00:00
NAKAMURA Takumi 2681efcc95 Revert r153360 (and r153380), "Second part of PR12251. Produce the range metadata in clang for booleans and".
For i686 targets (eg. cygwin), I saw "Range must not be empty!" in verifier.

It produces (i32)[0x80000000:0x80000000) from (uint64_t)[0xFFFFFFFF80000000ULL:0x0000000080000000ULL), for signed i32 on MDNode::Range.

llvm-svn: 153382
2012-03-24 14:43:42 +00:00
Rafael Espindola 54355820e8 Second part of PR12251. Produce the range metadata in clang for booleans and
c++ enums.

llvm-svn: 153360
2012-03-24 00:28:06 +00:00
Eli Friedman 610bb87e17 Make sure we correctly set the alignment for vector loads and stores associated with vector element lvalues. Patch by Kevin Schoedel (with some minor modifications by me).
llvm-svn: 153285
2012-03-22 22:36:39 +00:00
David Blaikie bbafb8a745 Unify naming of LangOptions variable/get function across the Clang stack (Lex to AST).
The member variable is always "LangOpts" and the member function is always "getLangOpts".

Reviewed by Chris Lattner

llvm-svn: 152536
2012-03-11 07:00:24 +00:00
John McCall 113bee0536 Remove BlockDeclRefExpr and introduce a bit on DeclRefExpr to
track whether the referenced declaration comes from an enclosing
local context.  I'm amenable to suggestions about the exact meaning
of this bit.

llvm-svn: 152491
2012-03-10 09:33:50 +00:00
John McCall 7133505936 Unify the BlockDeclRefExpr and DeclRefExpr paths so that
we correctly emit loads of BlockDeclRefExprs even when they
don't qualify as ODR-uses.  I think I'm adequately convinced
that BlockDeclRefExpr can die.

llvm-svn: 152479
2012-03-10 03:05:10 +00:00
Richard Smith c67fdd4eb9 AST representation for user-defined literals, plus just enough of semantic
analysis to make the AST representation testable. They are represented by a
new UserDefinedLiteral AST node, which is a sugared CallExpr. All semantic
properties, including full CodeGen support, are achieved for free by this
representation.

UserDefinedLiterals can never be dependent, so no custom instantiation
behavior is required. They are mangled as if they were direct calls to the
underlying literal operator. This matches g++'s apparent behavior (but not its
actual mangling, which is broken for literal-operator-ids).

User-defined *string* literals are now fully-operational, but the semantic
analysis is quite hacky and needs more work. No other forms of user-defined
literal are created yet, but the AST support for them is present.

This patch committed after midnight because we had already hit the quota for
new kinds of literal yesterday.

llvm-svn: 152211
2012-03-07 08:35:16 +00:00
Douglas Gregor ed90df3800 Generate an AST for the conversion from a lambda closure type to a
block pointer that returns a block literal which captures (by copy)
the lambda closure itself. Some aspects of the block literal are left
unspecified, namely the capture variable (which doesn't actually
exist) and the body (which will be filled in by IRgen because it can't
be written as an AST).

Because we're switching to this model, this patch also eliminates
tracking the copy-initialization expression for the block capture of
the conversion function, since that information is now embedded in the
synthesized block literal. -1 side tables FTW.

llvm-svn: 151131
2012-02-22 05:02:47 +00:00
Richard Smith 0b6b8e490c Fix wrong-code bug: __imag on a scalar lvalue should produce a zero rvalue,
rather than an lvalue referring to the scalar.

llvm-svn: 150889
2012-02-18 20:53:32 +00:00
John McCall a729c62b81 Whether an argument is required (in contrast with being an
optional argument passed through the variadic ellipsis)
potentially affects how we need to lower it.  Propagate
this information down to the various getFunctionInfo(...)
overloads on CodeGenTypes.  Furthermore, rename those
overloads to clarify their distinct purposes, and make
sure we're calling the right one in the right place.
This has a nice side-effect of making it easier to construct
a function type, since the 'variadic' bit is no longer
separable.

This shouldn't really change anything for our existing
platforms, with one minor exception --- we should now call
variadic ObjC methods with the ... in the "right place"
(see the test case), which I guess matters for anyone
running GNUStep on MIPS.  Mostly it's just a substantial
clean-up.

llvm-svn: 150788
2012-02-17 03:33:10 +00:00
John McCall c62bb39142 Split reinterpret_casts of member pointers out from CK_BitCast; this
is general goodness because representations of member pointers are
not always equivalent across member pointer types on all ABIs
(even though this isn't really standard-endorsed).

Take advantage of the new information to teach IR-generation how
to do these reinterprets in constant initializers.  Make sure this
works when intermingled with hierarchy conversions (although
this is not part of our motivating use case).  Doing this in the
constant-evaluator would probably have been better, but that would
require a *lot* of extra structure in the representation of
constant member pointers:  you'd really have to track an arbitrary
chain of hierarchy conversions and reinterpretations in order to
get this right.  Ultimately, this seems less complex.  I also
wasn't quite sure how to extend the constant evaluator to handle
foldings that we don't actually want to treat as extended
constant expressions.

llvm-svn: 150551
2012-02-15 01:22:51 +00:00
Benjamin Kramer 8001f7467a Use a simpler (and more efficient) pattern to pad vectors.
llvm-svn: 150475
2012-02-14 12:06:21 +00:00
Eli Friedman 9fbeba0d8e Basic support for referring to captured variables from lambdas. Some simple examples seem to work. Tests coming up soon.
llvm-svn: 150293
2012-02-11 02:57:39 +00:00
Eli Friedman c370a7eec7 Refactor lambda IRGen so AggExprEmitter::VisitLambdaExpr does the right thing.
llvm-svn: 150146
2012-02-09 03:32:31 +00:00
Eli Friedman 0cfd5bd67f Basic IRGen for LambdaExprs with captures.
llvm-svn: 150141
2012-02-09 03:19:12 +00:00
Eli Friedman 5bc1712940 A little bit of lambda IRGen.
llvm-svn: 150058
2012-02-08 05:34:55 +00:00
Chris Lattner ece0409a1a simplify a bunch of code to use the well-known LLVM IR types computed by CodeGenModule.
llvm-svn: 149943
2012-02-07 00:39:47 +00:00
Dylan Noblesmith 2c1dd2716a Basic: import SmallString<> into clang namespace
(I was going to fix the TODO about DenseMap too, but
that would break self-host right now. See PR11922.)

llvm-svn: 149799
2012-02-05 02:13:05 +00:00
Chris Lattner 595ba3a141 Simplify code by using the new getAggregateElement method that got added
recently.  This also conveniently gets clang ready for a change about to
land in mainline.

llvm-svn: 149225
2012-01-30 06:20:36 +00:00
Peter Collingbourne 1425b4556a Use function pointers, rather than references, to pass Destroyers
around, in the process cleaning up the various gcc/msvc compiler
workarounds.

llvm-svn: 149036
2012-01-26 03:33:36 +00:00
NAKAMURA Takumi ccca11a3de Fixup r148926, for -Asserts.
llvm-svn: 148943
2012-01-25 08:58:21 +00:00
Chris Lattner 2d6b7b91b9 reapply r148902:
"use the new ConstantVector::getSplat method where it makes sense."

Also simplify a bunch of code to use the Builder->getInt32 instead
of doing it the hard and ugly way.  Much more progress could be made
here, but I don't plan to do it.

llvm-svn: 148926
2012-01-25 05:34:41 +00:00
Eli Friedman 5995489d27 Fix a crash for an edge case of the GNU ?: extension.
llvm-svn: 148923
2012-01-25 05:04:17 +00:00
Argyrios Kyrtzidis 5a25297c5e Revert 148902 which was part of 148901 which was reverted in r148906.
Original log:
 use the new ConstantVector::getSplat method where it makes sense.

llvm-svn: 148907
2012-01-25 02:58:12 +00:00
Chris Lattner c558d7d176 use the new ConstantVector::getSplat method where it makes sense.
llvm-svn: 148902
2012-01-25 02:06:10 +00:00
Eli Friedman 5720e34955 Add an assertion that our use-marking actually covers all uses of a variable. The assertion doesn't cover quite as much as it should, but it's a good start, at least.
llvm-svn: 148625
2012-01-21 04:52:58 +00:00
David Blaikie e4d798f078 More dead code removal (using -Wunreachable-code)
llvm-svn: 148577
2012-01-20 21:50:17 +00:00
David Chisnall fa35df628a Some improvements to the handling of C11 atomic types:
- Add atomic-to/from-nonatomic cast types
- Emit atomic operations for arithmetic on atomic types
- Emit non-atomic stores for initialisation of atomic types, but atomic stores and loads for every other store / load
- Add a __atomic_init() intrinsic which does a non-atomic store to an _Atomic() type.  This is needed for the corresponding C11 stdatomic.h function.
- Enables the relevant __has_feature() checks.  The feature isn't 100% complete yet, but it's done enough that we want people testing it.

Still to do:

- Make the arithmetic operations on atomic types (e.g. Atomic(int) foo = 1; foo++;) use the correct LLVM intrinsic if one exists, not a loop with a cmpxchg.
- Add a signal fence builtin
- Properly set the fenv state in atomic operations on floating point values
- Correctly handle things like _Atomic(_Complex double) which are too large for an atomic cmpxchg on some platforms (this requires working out what 'correctly' means in this context)
- Fix the many remaining corner cases

llvm-svn: 148242
2012-01-16 17:27:18 +00:00
Chris Lattner 36bc4f41bc implement rdar://10639962 by keeping track of increased alignment
information even in subscripting operations.

llvm-svn: 147557
2012-01-04 22:35:55 +00:00