Nico Weber [Mon, 9 Mar 2015 04:27:56 +0000 (04:27 +0000)]
Warn when jumping out of a __finally block via goto.
This only warns on direct gotos and indirect gotos with a unique label
(`goto *&&label;`). Jumping out ith a true indirect goto is already an error.
This isn't O(1), but goto statements are less common than continue, break, and
return. Also, the GetDeepestCommonScope() call in the same function does the
same amount of work, so this isn't worse than what's there in a complexity
sense, and it should be pretty fast in practice.
This is the last piece that was missing in r231623.
Nico Weber [Mon, 9 Mar 2015 03:17:15 +0000 (03:17 +0000)]
Fix a theoretical bug when ParseCompoundStatement() returns StmtError.
ParseCompoundStatement() currently never returns StmtError, but if it did,
Sema would keep the __finally scope on its stack indefinitely. Explicitly
add an error callback that clears it.
Nico Weber [Mon, 9 Mar 2015 02:47:59 +0000 (02:47 +0000)]
Warn when jumping out of a __finally block via continue, break, return, __leave.
Since continue, break, return are much more common than __finally, this tries
to keep the work for continue, break, return O(1). Sema keeps a stack of active
__finally scopes (to do this, ActOnSEHFinally() is split into
ActOnStartSEHFinally() and ActOnFinishSEHFinally()), and the various jump
statements then check if the current __finally scope (if present) is deeper
than then destination scope of the jump.
The same warning for goto statements is still missing.
Benjamin Kramer [Sat, 7 Mar 2015 13:37:13 +0000 (13:37 +0000)]
Reapply r231508 "CodeGen: Emit constant temporaries into read-only globals."
I disabled putting the new global into the same COMDAT as the function for now.
There's a fundamental problem when we inline references to the global but still
have the global in a COMDAT linked to the inlined function. Since this is only
an optimization there may be other versions of the COMDAT around that are
missing the new global and hell breaks loose at link time.
I hope the chromium build doesn't break this time :)
Much like we silence warnings about -flto in many cases to facilitate
simplicity in build systems, silence '-stdlib=libc++' when linking. Even
if we're not linking C++ code per-se, we may be passing this flag so
that when we are linking C++ code we pick up the desired standard
library. While most build systems already provide separate C and C++
compile flags, many conflate link flags. Sadly, CMake is among them
causing this warning in a libc++ selfhost.
Jordan Rose [Sat, 7 Mar 2015 05:47:24 +0000 (05:47 +0000)]
[analyzer] RetainCountChecker: CF properties are always manually retain-counted.
In theory we could assume a CF property is stored at +0 if there's not a custom
setter, but that's not really worth the complexity. What we do know is that a
CF property can't have ownership attributes, and so we shouldn't assume anything
about the ownership of the ivar.
Richard Smith [Sat, 7 Mar 2015 00:04:49 +0000 (00:04 +0000)]
Replace Sema's map of locally-scoped extern "C" declarations with a DeclContext
of extern "C" declarations. This is simpler and vastly more efficient for
modules builds (we no longer need to load *all* extern "C" declarations to
determine if we have a redeclaration).
Benjamin Kramer [Fri, 6 Mar 2015 20:00:03 +0000 (20:00 +0000)]
CodeGen: Emit constant temporaries into read-only globals.
Instead of creating a copy on the stack just stash them in a private
constant global. This saves both the copying overhead and the stack
space, and gives the optimizer more room to constant fold.
This tries to make array temporaries more similar to regular arrays,
they can't use the same logic because a temporary has no VarDecl to be
bound to so we roll our own version here.
The original use case for this optimization was code like
for (int i : {1, 2, 3, 4, 5, 6, 7, 8, 10})
foo(i);
where without this patch (assuming that the loop is not unrolled) we
would alloca an array on the stack, copy the 10 values over and
iterate on that. With this patch we put the array in .text use it
directly. Apart from that case this helps on virtually any passing of
a constant std::initializer_list as a function argument.
David Majnemer [Fri, 6 Mar 2015 18:53:55 +0000 (18:53 +0000)]
MS ABI: Insert copy-constructors into the CatchableType
Find all unambiguous public classes of the exception object's class type
and reference all of their copy constructors. Yes, this is not
conforming but it is necessary in order to implement their ABI. This is
because the copy constructor is actually referenced by the metadata
describing which catch handlers are eligible to handle the exception
object.
N.B. This doesn't yet handle the copy constructor closure case yet,
that work is ongoing.
Here (and it is probably not a totally infrequent case, it just works out that
"i < " is four spaces and so the four space extra indentation makes the
operator precedence confusing. So, this will now instead be formatted
as:
Richard Smith [Thu, 5 Mar 2015 23:24:12 +0000 (23:24 +0000)]
[modules] Rework merging of redeclaration chains on module import.
We used to save out and eagerly load a (potentially huge) table of merged
formerly-canonical declarations when we loaded each module. This was extremely
inefficient in the presence of large amounts of merging, and didn't actually
save any merging lookup work, because we still needed to perform name lookup to
check that our merged declaration lists were complete. This also resulted in a
loss of laziness -- even if we only needed an early declaration of an entity, we
would eagerly pull in all declarations that had been merged into it regardless.
We now store the relevant fragments of the table within the declarations
themselves. In detail:
* The first declaration of each entity within a module stores a list of first
declarations from imported modules that are merged into it.
* Loading that declaration pre-loads those other entities, so that they appear
earlier within the redeclaration chain.
* The name lookup tables list the most recent local lookup result, if there
is one, or all directly-imported lookup results if not.
[PATCH] Patch to fix the AST for vector splat from any
arithmetic type to a vector so that the arithmatic type
matches the vector element type. Without which it crashes
in Code Gen. rdar://20000762
Alexey Samsonov [Thu, 5 Mar 2015 21:57:35 +0000 (21:57 +0000)]
Revert "[UBSan] Split -fsanitize=shift into -fsanitize=shift-base and -fsanitize=shift-exponent."
It's not that easy. If we're only checking -fsanitize=shift-base we
still need to verify that exponent has sane value, otherwise
UBSan-inserted checks for base will contain undefined behavior
themselves.
David Majnemer [Thu, 5 Mar 2015 00:46:22 +0000 (00:46 +0000)]
MS ABI: Implement support for throwing a C++ exception
Throwing a C++ exception, under the MS ABI, is implemented using three
components:
- ThrowInfo structure which contains information like CV qualifiers,
what destructor to call and a pointer to the CatchableTypeArray.
- In a significant departure from the Itanium ABI, copying by-value
occurs in the runtime and not at the catch site. This means we need
to enumerate all possible types that this exception could be caught as
and encode the necessary information to convert from the exception
object's type to the catch handler's type. This includes complicated
derived to base conversions and the execution of copy-constructors.
N.B. This implementation doesn't support the execution of a
copy-constructor from within the runtime for now. Adding support for
that functionality is quite difficult due to things like default
argument expressions which may evaluate arbitrary code hiding in the
copy-constructor's parameters.
Reid Kleckner [Wed, 4 Mar 2015 19:24:16 +0000 (19:24 +0000)]
Fix test/CodeGen/builtins.c for platforms that don't lower sjlj
Opt in Win64 to supporting sjlj lowering. We have the backend lowering,
so I think this was just an oversight because WinX86_64TargetCodeGenInfo
doesn't inherit from X86_64TargetCodeGenInfo.
Toma Tabacu [Wed, 4 Mar 2015 14:24:25 +0000 (14:24 +0000)]
[IAS] Teach -cc1as about the 'target-abi' option.
Summary:
When using the IAS from clang, the 'target-abi' option gets passed to cc1as, but cc1as doesn't know about it and gives an "unknown argument" error.
This is fixed by adding the 'CC1AsOption' flag to the 'target-abi' option in CC1Options.td.
Seth Cantrell [Wed, 4 Mar 2015 03:12:10 +0000 (03:12 +0000)]
Add a format warning for "%p" with non-void* args
GCC -pedantic produces a format warning when the "%p" specifier is used with
arguments that are not void*. It's useful for portability to be able to
catch such warnings with clang as well. The warning is off by default in
both gcc and with this patch. This patch enables it either when extensions
are disabled with -pedantic, or with the specific flag -Wformat-pedantic.
The C99 and C11 specs do appear to require arguments corresponding to 'p'
specifiers to be void*: "If any argument is not the correct type for the
corresponding conversion specification, the behavior is undefined."
[7.19.6.1 p9], and of the 'p' format specifier "The argument shall be a
pointer to void." [7.19.6.1 p8]
Both printf and scanf format checking are covered.
Jacques Pienaar [Tue, 3 Mar 2015 23:58:09 +0000 (23:58 +0000)]
TypePrinter print __restrict if not in C99 mode
restrict is a keyword in C99 but not in C++ while clang accepts __restrict for C++ code. Modify the TypePrinter to print __restrict when not processing C99 code.
Printing restrict in C++ was problematic as printing the argument of
int f(int * __restrict a) { ... }
resulted in
int *restrict a
which is incorrect.
Anton Yartsev [Tue, 3 Mar 2015 22:58:46 +0000 (22:58 +0000)]
[analyzer] unix.Malloc: preserve AllocaRegion bound to __builtin_alloca().
Binding __builtin_alloca() return value to the symbolic value kills previous binding to a AllocaRegion established by the core.BuiltinFunctions checker. Other checkers may rely upon this information. Rollback handling of __builtin_alloca() to the way prior to r229850.
This test doesn't provide any value (it just checks that the frontend
produces exactly one compile unit), and it certainly isn't doing what
the comment says. Noticed via IRC review of my update to it in r231083.
Alexey Samsonov [Tue, 3 Mar 2015 22:15:35 +0000 (22:15 +0000)]
[UBSan] Split -fsanitize=shift into -fsanitize=shift-base and -fsanitize=shift-exponent.
-fsanitize=shift is now a group that includes both these checks, so
exisiting users should not be affected.
This change introduces two new UBSan kinds that sanitize only left-hand
side and right-hand side of shift operation. In practice, invalid
exponent value (negative or too large) tends to cause more portability
problems, including inconsistencies between different compilers, crashes
and inadequeate results on non-x86 architectures etc. That is,
-fsanitize=shift-exponent failures should generally be addressed first.
As a bonus, this change simplifies CodeGen implementation for emitting left
shift (separate checks for base and exponent are now merged by the
existing generic logic in EmitCheck()), and LLVM IR for these checks
(the number of basic blocks is reduced).
Bill Seurer [Tue, 3 Mar 2015 20:08:43 +0000 (20:08 +0000)]
[PowerPC]Activate "vector bool long long" (and alternate spellings) as a valid type for Altivec support for Power.
There are two test case updates for very basic testing. While I was editing cxx-altivec.cpp I also updated it to better match some other changes in altivec.c.
Note: "vector bool long" was not also added because its use is considered deprecated.
Dan Albert [Tue, 3 Mar 2015 18:24:57 +0000 (18:24 +0000)]
Don't force -pie for Android.
Summary:
There is no -no-pie flag that can override this, so making it default
to being on for Android means it is no longer possible to create
non-PIE executables on Android. While current versions of Android
support (and the most recent requires) PIE, ICS and earlier versions
of Android cannot run PIE executables, so this needs to be optional.
Hans Wennborg [Tue, 3 Mar 2015 17:30:50 +0000 (17:30 +0000)]
Migrate clang-format-vs plugin project to VS 2013
The plugin still works fine in versions starting from 2010,
but this was needed to make the project _build_ in VS 2013, which
is the blessed version for building LLVM projects these days.
[SDK modernizer]. Patch fixes driver's lack of
recognition of mernizer's -objcmt-migrate-property-dot-syntax
option with a new test in test/Driver. rdar://19994452
Manuel Klimek [Tue, 3 Mar 2015 14:54:25 +0000 (14:54 +0000)]
Make -Wuninitialized warn on pointer-to-member and comma operators.
`isTrackedVar` has been updated to also track records.
`DeclRefExpr`s appearing on the left side of a comma operator are
ignored, while those appearing on the right side are classified as
`Use`.
Daniel Jasper [Tue, 3 Mar 2015 13:59:49 +0000 (13:59 +0000)]
clang-format: Fix access to uninitialized memory.
With incomplete code, we aren't guaranteed to generated changes for
every token. In that case, we need to assume that even the very first
change can continue a preprocessor directive and initialize values
accordingly.
Daniel Jasper [Tue, 3 Mar 2015 10:02:53 +0000 (10:02 +0000)]
Revert r231008 (and dependent r231019).
As Chandler responded on the initial commit, just directly setting the
triple through -Xclang option to the driver creates havoc on other
platforms. The driver test should specifically go into test/Driver and
test the cc1 commandline itself.
David Majnemer [Tue, 3 Mar 2015 04:38:34 +0000 (04:38 +0000)]
Sema: Caught exception objects should be unqualified
The exception object should be unqualified. Using a qualified exception
object results in the wrong copy constructor getting called when the
catch handler executes.
Alexey Samsonov [Tue, 3 Mar 2015 00:14:32 +0000 (00:14 +0000)]
[Sanitizers] Remove duplication in sanitizer group definition. NFC.
There is no need to list sanitizers in both "UndefinedTrap" and
"Undefined" groups - it turns out using one group in a defintion
of another group "just works".
Reid Kleckner [Mon, 2 Mar 2015 22:42:58 +0000 (22:42 +0000)]
Remove shell requirements from tests that use 'cd'
Modules and Tooling tests in particular tend to want to change the cwd,
so we were missing test coverage in this area on Windows. It should now
be easier to write such portable tests.