Anna Zaks [Thu, 2 Feb 2012 01:30:08 +0000 (01:30 +0000)]
[analyzer] Fix a false positive in the CFArrayCreate check that surfaces
the the code like this (due to x and &x being the same value but
different size):
Richard Smith [Thu, 2 Feb 2012 01:16:57 +0000 (01:16 +0000)]
constexpr:
* support the gcc __builtin_constant_p() ? ... : ... folding hack in C++11
* check for unspecified values in pointer comparisons and pointer subtractions
r149474 went a bit too far when combined with type caching. If we want
a full type go ahead and emit it if we currently only have a forward
declaration.
Fixes gdb bots for gdb1090.exp and call-ar-st.exp.
Douglas Gregor [Wed, 1 Feb 2012 21:00:38 +0000 (21:00 +0000)]
Make sure that imported definitions get completed before we add
anything into the corresponding DeclContext. Co-hacked with Sean;
fixes <rdar://problem/10768928>.
Douglas Gregor [Wed, 1 Feb 2012 17:04:21 +0000 (17:04 +0000)]
Introduce the lambda scope before determining explicit captures, which
cleans up and improves a few things:
- We get rid of the ugly dance of computing all of the captures in
data structures that clone those of CapturingScopeInfo, centralizing
the logic for accessing/updating these data structures
- We re-use the existing capture logic for 'this', which actually
works now.
Cleaned up some diagnostic wording in minor ways as well.
NAKAMURA Takumi [Wed, 1 Feb 2012 14:09:19 +0000 (14:09 +0000)]
test/Modules/compiler_builtins.m: Appease Cygwin to add -D__need_wint_t.
On Cygwin, at first, <stddef.h> is included without __need_wint_t.
Next, <stddef.h> is included with __need_wint_t, though Modules feature would not process <stddef.h> twice.
Then, wint_t is not found in system headers.
This already exists in the CMake build, which is part of what makes
building clang separately from llvm via cmake possible. This cleans up
that discrepancy between the build systems (and sets the groundwork
for configuring clang separately, too).
Richard Smith [Wed, 1 Feb 2012 08:10:20 +0000 (08:10 +0000)]
constexpr: check for overflow in pointer subtraction.
This is a mess. According to the C++11 standard, pointer subtraction only has
undefined behavior if the difference of the array indices does not fit into a
ptrdiff_t.
However, common implementations effectively perform a char* subtraction first,
and then divide the result by the element size, which can cause overflows in
some cases. Those cases are not considered to be undefined behavior by this
change; perhaps they should be.
The purpose of refactoring is to hide operand roles from SwitchInst user (programmer). If you want to play with operands directly, probably you will need lower level methods than SwitchInst ones (TerminatorInst or may be User). After this patch we can reorganize SwitchInst operands and successors as we want.
What was done:
1. Changed semantics of index inside the getCaseValue method:
getCaseValue(0) means "get first case", not a condition. Use getCondition() if you want to resolve the condition. I propose don't mix SwitchInst case indexing with low level indexing (TI successors indexing, User's operands indexing), since it may be dangerous.
2. By the same reason findCaseValue(ConstantInt*) returns actual number of case value. 0 means first case, not default. If there is no case with given value, ErrorIndex will returned.
3. Added getCaseSuccessor method. I propose to avoid usage of TerminatorInst::getSuccessor if you want to resolve case successor BB. Use getCaseSuccessor instead, since internal SwitchInst organization of operands/successors is hidden and may be changed in any moment.
4. Added resolveSuccessorIndex and resolveCaseIndex. The main purpose of these methods is to see how case successors are really mapped in TerminatorInst.
4.1 "resolveSuccessorIndex" was created if you need to level down from SwitchInst to TerminatorInst. It returns TerminatorInst's successor index for given case successor.
4.2 "resolveCaseIndex" converts low level successors index to case index that curresponds to the given successor.
Note: There are also related compatability fix patches for dragonegg, klee, llvm-gcc-4.0, llvm-gcc-4.2, safecode, clang.
Revert r149363 which was part a series of commits that were reverted in llvm
commit 149470. This fixes test/CodeGen/PR3589-freestanding-libcalls.c.
Original log:
ConstantArray::get() (for strings) is going away, use
ConstantDataArray::getString instead.
Many instances of ConstantArray::get() could be moved to
use more efficient ConstantDataArray methods that avoid a ton
of intermediate Constant*'s for each element (e.g.
GetConstantArrayFromStringLiteral). I don't plan on doing this
in the short-term though.
Richard Smith [Wed, 1 Feb 2012 04:40:02 +0000 (04:40 +0000)]
constexpr: Unlike other incomplete types, 'void' cannot possibly be completed as
a literal type. Disallow it as the return type of a constexpr function
declaration.
Douglas Gregor [Wed, 1 Feb 2012 01:18:43 +0000 (01:18 +0000)]
Improve checking of explicit captures in a C++11 lambda expression:
- Actually building the var -> capture mapping properly (there was an off-by-one error)
- Keeping track of the source location of each capture
- Minor QoI improvements, e.g, highlighing the prior capture if
there are multiple captures, pointing at the variable declaration we
found if we reject it.
As part of this, add standard citations for the various semantic
checks we perform, and note where we're not performing those checks as
we should.
objc-arc: In various diagnostics mention
CFBridgingRetain/CFBridgingRelease calls instead
of __bridge_retained/__bridge_transfer casts as preferred
way of moving cf objects to arc land. // rdar://10207950
arc migrator: Do not attempt to migrate to bridge casts which
cancel out each other. Leave it alone so users can take a look
(unmigrated code forces error diagnostic). // rdar://10521744
Douglas Gregor [Tue, 31 Jan 2012 21:57:50 +0000 (21:57 +0000)]
Split compiler builtin module into "stdlib" builtins and "intrinsic"
builds, and bring mm_alloc.h into the fold. Start playing some tricks
with these builtin modules to mirror the include_next tricks that the
headers already perform.
Bob Wilson [Tue, 31 Jan 2012 21:30:03 +0000 (21:30 +0000)]
Fix more fallout from the introduction of "macosx" and "ios" triples.
The Darwin toolchain constructor was assuming that all Darwin triples would
have an OS string starting with "darwin". Triples starting with "macosx"
would misinterpret the version number, and "ios" triples would completely
miss the version number (or worse) because the OS name is not 6 characters
long. We lose some sanity checking of triple strings here, since the
Triple.getOSVersion function doesn't do all the checking that the previous
code did, but this still seems like a step in the right direction.
Chris Lattner [Tue, 31 Jan 2012 18:53:44 +0000 (18:53 +0000)]
fix a crash on:
__has_builtin
in an empty file, as we were overwriting the EOF token. Overwriting an arbitrary token
never seems like a good idea in the error case. This fixes a bug reported on the GCC
list :)
Richard Smith [Tue, 31 Jan 2012 06:41:30 +0000 (06:41 +0000)]
constexpr: the result of a relational operator between pointers to void is
unspecified unless the pointers are equal; therefore, such a comparison is not
a constant expression unless the pointers are equal.
Chris Lattner [Tue, 31 Jan 2012 06:13:55 +0000 (06:13 +0000)]
ConstantArray::get() (for strings) is going away, use
ConstantDataArray::getString instead.
Many instances of ConstantArray::get() could be moved to
use more efficient ConstantDataArray methods that avoid a ton
of intermediate Constant*'s for each element (e.g.
GetConstantArrayFromStringLiteral). I don't plan on doing this
in the short-term though.
Ted Kremenek [Tue, 31 Jan 2012 05:37:48 +0000 (05:37 +0000)]
Don't warn about -Wshorten-64-to-32 in unreachable code. Fixes <rdar://problem/10759934>. Apparently this is a common idiom in Linux (among other places).
Richard Smith [Tue, 31 Jan 2012 04:08:20 +0000 (04:08 +0000)]
constexpr: catch a collection of integral undefined behaviors:
-INT_MIN and INT_MIN / -1
Shift by a negative or too large quantity
Left shift of negative value
Overflow in left shift
Convert ProgramStateRef to a smart pointer for managing the reference counts of ProgramStates. This leads to a slight memory
improvement, and a simplification of the logic for managing ProgramState objects.
# Please enter the commit message for your changes. Lines starting
Chandler Carruth [Tue, 31 Jan 2012 02:21:20 +0000 (02:21 +0000)]
Revert r149083 which is not the direction we're going in the Clang
driver based on discussions with Doug Gregor. There are several issues:
1) The patch was not reviewed prior to commit and there were review comments.
2) The design of the functionality (triple-prefixed tool invocation)
isn't the design we want for Clang going forward: it focuses on the
"user triple" rather than on the "toolchain triple", and forces that
bit of state into the API of every single toolchain instead of
handling it automatically in the common base classes.
3) The tests provided are not stable. They fail on a few Linux variants
(Gentoo among them) and on mingw32 and some other environments.
I *am* interested in the Clang driver being able to invoke
triple-prefixed tools, but we need to design that feature the right way.
This patch just extends the previous hack without fixing the underlying
problems with it. I'm working on a new design for this that I will mail
for review by tomorrow.
I am aware that this removes functionality that NetBSD relies on, but
this is ToT, not a release. This functionality hasn't been properly
designed, implemented, and tested yet. We can't "regress" until we get
something that really works, both with the immediate use cases and with
long term maintenance of the Clang driver.
For reference, the original commit log:
Keep track of the original target the user specified before
normalization. This used to be captured in DefaultTargetTriple and is
used for the (optional) $triple-$tool lookup for cross-compilation.
Do this properly by making it an attribute of the toolchain and use it
in combination with the computed triple as index for the toolchain
lookup.
Convert ProgramStateRef to a smart pointer for managing the reference counts of ProgramStates. This leads to a slight memory
improvement, and a simplification of the logic for managing ProgramState objects.
Richard Smith [Tue, 31 Jan 2012 01:47:46 +0000 (01:47 +0000)]
constexpr: remove integral conversion overflow checking introduced in r149286.
As Eli points out, this is implementation-defined, and the way we define it
makes this fine.
Ted Kremenek [Tue, 31 Jan 2012 00:57:20 +0000 (00:57 +0000)]
Convert ProgramStateRef to a smart pointer for managing the reference counts of ProgramStates. This leads to a slight memory
improvement, and a simplification of the logic for managing ProgramState objects.
Douglas Gregor [Mon, 30 Jan 2012 22:22:39 +0000 (22:22 +0000)]
Remove tgmath.h from the module map for now, because it currently causes a
cyclic module dependency due to its inclusion of math.h and
complex.h. I'll take another shot at it later.
objc-arc: Perform null check on receiver before sending methods which
consume one or more of their arguments. If not done, this will cause a leak
as method will not consume the argument when receiver is null.
In this patch, the null path releases consumed argument.
// rdar://10444474
Disable "non literal format string" for NSString that result from a macro expansion.
This is to prevent diagnostic when using NSLocalizedString or CFCopyLocalizedString
macros which are usually used in place of NS and CF strings literals.
John McCall [Mon, 30 Jan 2012 18:36:31 +0000 (18:36 +0000)]
Per discussion on cxx-abi-dev, don't drop leading zeroes from the
mangling of floating-point literals. I just went ahead and
reimplemented toString() here; if someone wants to generalize
the library routine to do this, or feels strongly that we should
be post-processing, please feel free.