Nico Weber [Mon, 29 Dec 2014 21:56:22 +0000 (21:56 +0000)]
Crash even less on malformed attributes in an incorrect location.
This is a follow-up to r224915. This adds a bit more line noise to the tests
added in that revision to make sure the parser is ready for a toplevel decl
after each incorrect line. Use this to move the tests up to where they belong.
This uncovered that the early return was missing a call to
ActOnTagDefinitionError(), so add that. (Also fixes at least one of the crashes
on SLi's bot.)
Alexey Samsonov [Mon, 29 Dec 2014 21:28:15 +0000 (21:28 +0000)]
Fix use-after-destruction introduced in r224924.
getMainExecutable() returns a std::string, assigning its result
to StringRef immediately creates a dangling pointer. This was
detected by half-broken fast-MSan-bootstrap bot.
David Blaikie [Mon, 29 Dec 2014 18:18:45 +0000 (18:18 +0000)]
Reapply "DebugInfo: Generalize debug info location handling"
Originally committed in r224385 and reverted in r224441 due to concerns
this change might've introduced a crash. Turns out this change fixes the
crash introduced by one of my earlier more specific location handling
changes (those specific fixes are reverted by this patch, in favor of
the more general solution).
Original commit message:
This is a more scalable (fixed in mostly one place, rather than many
places that will need constant improvement/maintenance) solution to
several commits I've made recently to increase source fidelity for
subexpressions.
This resetting had to be done at the DebugLoc level (not the
SourceLocation level) to preserve scoping information (if the resetting
was done with CGDebugInfo::EmitLocation, it would've caused the tail end
of an expression's codegen to end up in a potentially different scope
than the start, even though it was at the same source location). The
drawback to this is that it might leave CGDebugInfo out of sync. Ideally
CGDebugInfo shouldn't have a duplicate sense of the current
SourceLocation, but for now it seems it does... - I don't think I'm
going to tackle removing that just now.
I expect this'll probably cause some more buildbot fallout & I'll
investigate that as it comes up.
Also these sort of improvements might be starting to show a weakness/bug
in LLVM's line table handling: we don't correctly emit is_stmt for
statements, we just put it on every line table entry. This means one
statement split over multiple lines appears as multiple 'statements' and
two statements on one line (without column info) are treated as one
statement.
I don't think we have any IR representation of statements that would
help us distinguish these cases and identify the beginning of each
statement - so that might be something we need to add (possibly to the
lexical scope chain - a scope for each statement). This does cause some
problems for GDB and possibly other DWARF consumers.
Chandler Carruth [Mon, 29 Dec 2014 13:29:38 +0000 (13:29 +0000)]
Effectively revert r151058 which caused Clang's unwind.h to defer to
libunwind in all cases when installed.
At the time, Clang's unwind.h didn't provide huge chunks of the
LSB-specified unwind interface, and was generally too aenemic to use for
real software. However, it has since then become a strict superset of
the APIs provided by libunwind on Linux. Notably, you cannot compile
llgo's libgo library against libunwind, but you can against Clang's
unwind.h. So let's just use our header. =] I've checked pretty
thoroughly for any incompatibilities, and I am not aware of any.
An open question is whether or not we should continue to munge
GNU_SOURCE here. I didn't touch that as it potentially has compatibility
implications on systems I cannot easily test -- Darwin. If a Darwin
maintainer can verify that this is in fact unnecessary and remove it,
cool. Until then, leaving it in makes this change a no-op there, and
only really relevant on Linux systems where it is pretty clearly the
right way to go.
Chandler Carruth [Mon, 29 Dec 2014 13:29:36 +0000 (13:29 +0000)]
Add a missing declaration to our unwind.h implementation. This is
necessary to be fully compatible with existing software that calls into
the linux unwind code. You can find documentation of this API and why it
exists in the discussion abot NPTL here:
https://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html
Chandler Carruth [Mon, 29 Dec 2014 12:09:08 +0000 (12:09 +0000)]
[multilib] Teach Clang's code about multilib by threading
a CLANG_LIBDIR_SUFFIX down from the build system and using that as part
of the default resource dir computation.
Without this, essentially nothing that uses the clang driver works when
building clang with a libdir suffix. This is probably the single biggest
missing piece of support for multilib as without this people could hack
clang to end up installed in the correct location, but it would then
fail to find its own basic resources. I know of at least one distro that
has some variation on this patch to hack around this; hopefully they'll
be able to use the libdir suffix functionality directly as the rest of
these bits land.
This required fixing a copy of the code to compute Clang's resource
directory that is buried inside of the frontend (!!!). It had bitrotted
significantly relative to the driver code. I've made it essentially
a clone of the driver code in order to keep tests (which use cc1
heavily) passing. This copy should probably just be removed and the
frontend taught to always rely on an explicit resource directory from
the driver, but that is a much more invasive change for another day.
I've also updated one test which actually encoded the resource directory
in its checked output to tolerate multilib suffixes.
Note that this relies on a prior LLVM commit to add a stub to the
autoconf build system for this variable.
Chandler Carruth [Mon, 29 Dec 2014 12:09:03 +0000 (12:09 +0000)]
[cmake] Teach the Clang CMake build to use LLVM_LIBDIR_SUFFIX for its
'lib' directories in the build. This variable is available now both as
part of the normal LLVM build an as part of a standalone build as I've
added it to the LLVMConfig.cmake output.
With this change we should at least put libraries into the multilib
directory correctly. It is the first step in getting Clang to be
reasonably multilib aware.
David Majnemer [Mon, 29 Dec 2014 10:29:53 +0000 (10:29 +0000)]
Sema: Permit array l-values in asm output operands
GCC permits array l-values in asm output operands even though they
aren't modifiable l-values. We used to permit it but this behavior
regressed in r224916.
Nico Weber [Mon, 29 Dec 2014 06:56:50 +0000 (06:56 +0000)]
Don't crash on malformed attributes in an incorrect location.
r168626 added nicer diagnostics for attributes in the wrong places, such as
after the `final` on a class. To do this, it added code that did high-level
pattern matching for e.g. 'final' 'alignas' '(' and then skipped until the
closing ')'. If it saw that, it then went down the regular class parsing
path and then called MaybeParseCXX11Attributes() to parse the attribute after
the 'final' using real attribute parsing code. On invalid attributes, the
real attribute parsing code could eat more tokens than the pattern matching
code and for example skip past the '{' starting the class, which would then
lead to an assert. To prevent this, check for a good state after calling
MaybeParseCXX11Attributes() (which morphed into CheckMisplacedCXX11Attribute()
in r175575) and bail out if things look bleak.
Craig Topper [Mon, 29 Dec 2014 06:41:12 +0000 (06:41 +0000)]
[x86] Put 'C' after 'i' on all the AVX-512 intrisics that take const ints. 'C' is a suffix modifier not a prefix modififier. Also put 'C' on the pointers in all of the gather instrinsics. I think they previously had one due to the misordering. I'm still thinking the 'iC' actually need to be a 'Ii' since they really require an ICE.
David Majnemer [Mon, 29 Dec 2014 05:17:46 +0000 (05:17 +0000)]
Sema: Don't crash when solitary :: token appears before { in struct def
hasDeclaratorForAnonDecl, getDeclaratorForAnonDecl and
getTypedefNameForAnonDecl are expected to handle the case where
NamedDeclOrQualifier holds the wrong type or nothing at all.
David Majnemer [Mon, 29 Dec 2014 02:14:26 +0000 (02:14 +0000)]
SemaCXX: Don't crash when annotation tokens show up before the tag name
Clang has a hack to accept definitions of structs with tag names which
have the same name as intrinsics. However, this hack didn't guard
against annotation tokens showing up in the token stream.
David Majnemer [Sun, 28 Dec 2014 23:46:59 +0000 (23:46 +0000)]
CodeGen: Optimize emssion of zeroinitialzied arrays
Create an ConstantAggregateZero upfront if we see that it is viable.
This saves us from having to manually push_back each and every
initializer and then looping back over them to determine if they are
'null'.
Nico Weber [Sun, 28 Dec 2014 23:24:02 +0000 (23:24 +0000)]
Don't crash on surprising tokens in default parameter template lists.
Fixes this snippet from SLi's afl fuzzer output:
class {
i (x = <, enum
This parsed i as a function, x as a paramter, and the stuff after < as a
template list. This then called TryConsumeDeclarationSpecifier() which
called TryAnnotateCXXScopeToken() without checking the preconditions of
this function. Check them before calling, like all other callers of
TryAnnotateCXXScopeToken() do.
A more readable reproducer that causes the same crash is
class {
void i(int x = MyTemplateClass<int, union int>::foo());
};
The reduced version used an eof token as surprising token, but kw_int works
just as well to repro and is easier to insert into a test file.
David Majnemer [Sun, 28 Dec 2014 22:28:32 +0000 (22:28 +0000)]
Parse: Don't crash when 'typename' shows up in an attribute
isDeclarationSpecifier performs error recovers which jostles the token
stream. Specifically, TryAnnotateTypeOrScopeToken will end up consuming
a typename token which will confuse the attribute parsing machinery as
we no-longer have something identifier-like.
David Majnemer [Sun, 28 Dec 2014 09:18:54 +0000 (09:18 +0000)]
Sema: Don't crash when an inject class name has a nested redefinition
We expected the type of a TagDecl to be a TagType, not an
InjectedClassNameType. Introduced a helper method, Type::getAsTagDecl,
to abstract away the difference; redefine Type::getAsCXXRecordDecl to be
in terms of it.
David Majnemer [Sun, 28 Dec 2014 07:42:49 +0000 (07:42 +0000)]
Lex: Don't let annotation tokens get into macro expansion
We'd let annotation tokens from '#pragma pack' and the like get inside a
function-like macro. This would lead to terror and mayhem; stop the
madness early.
Nico Weber [Sun, 28 Dec 2014 02:07:26 +0000 (02:07 +0000)]
Add stub sections about Parse, Sema, CodeGen to the internals manual.
I'd be interested if the paragraph on Parse not knowing much about AST is
something folks agree with. I think this used to be true after rjmccall removed
the Action interface in r112244 and I believe it's still true, but I'm not sure.
(For example, ParseOpenMP.cpp does include AST/StmtOpenMP.h. Other than that,
Parse not using AST nodes much seems to be still true, though.)
Nico Weber [Sat, 27 Dec 2014 22:14:15 +0000 (22:14 +0000)]
Objective-C: Serialize "more than one decl" state of ObjCMethodList.
This fixes PR21587, what r221933 fixed for regular programs is now also
fixed for decls coming from PCH files.
Use another bit from the count/bits uint16_t for storing the "more than one
decl" bit. This reduces the number of bits for the count from 14 to 13.
The selector with the most overloads in Cocoa.h has ~55 overloads, so 13 bits
should still be plenty. Since this changes the meaning of a serialized bit
pattern, also increase clang::serialization::VERSION_MAJOR.
Storing the "more than one decl" state of only the first overload isn't quite
correct, but Sema::AreMultipleMethodsInGlobalPool() currently only looks at
the state of the first overload so it's good enough for now.
Chandler Carruth [Sat, 27 Dec 2014 11:50:51 +0000 (11:50 +0000)]
[x86] Also add the missing type casts on the returns in the sha
intrinsic header file. Along with r224822, this should restore the build
bots to passing.
Craig Topper [Sat, 27 Dec 2014 06:59:57 +0000 (06:59 +0000)]
[x86] Add the (v)cmpps/pd/ss/sd builtins to match gcc. Use them in the sse intrinsic files.
This still lower to the same intrinsics as before.
This is preparation for bounds checking the immediate on the avx version of the builtin so we don't pass illegal immediates into the backend. Since SSE uses a smaller size immediate its not possible to bounds check when using a shared builtin. Rather than creating a clang specific builtin for the different immediate, I decided (after consulting with Chandler) that it was better to match gcc.
David Majnemer [Fri, 26 Dec 2014 06:06:56 +0000 (06:06 +0000)]
Sema: Qualify getPrintable's Expr argument
getPrintable has an overload which takes a bool. This means that const
qualified Exprs would get forwarded to the bool overload instead of the
Expr overload.
Nico Weber [Tue, 23 Dec 2014 22:55:34 +0000 (22:55 +0000)]
clang-cl: Various changes to /Zc: handling.
* /Zc:trigraphs and /Zc:trigraphs- are now honored
* /Zc:strictStrings is now honored
* /Zc:auto is now honored/ignored (clang does the Right Thing for this already)
Also add a dedicated test for the various /Zc: flags.
clang-cl doesn't always agree with cl.exe on the default values for /Zc flags.
For example, I think clang always behaves as if /Zc:inline is passed, and
warns if the user explicitly passes /Zc:inline-
Nico Weber [Mon, 22 Dec 2014 18:35:03 +0000 (18:35 +0000)]
Disable trigraphs in microsoft mode by default. Matches cl.exe.
The default value of Opts.Trigraphs now no longer depends solely on the
language input kind, so move the code out of setLangDefaults(). Also make
sure that Opts.MSVCCompat is set before the Trigraph code runs.
Nico Weber [Mon, 22 Dec 2014 18:13:07 +0000 (18:13 +0000)]
Rename test.cc files to test.cpp.
The lit.cfg files only add .cpp to suffixes, so these tests used to never run,
oops. (Also tweak to of these tests in minor ways to make the actually pass.)
Bob Wilson [Sun, 21 Dec 2014 07:00:00 +0000 (07:00 +0000)]
Reapply "Change -save-temps to emit unoptimized bitcode files."
This reapplies r224503 along with a fix for compiling Fortran by having the
clang driver invoke gcc (see r224546, where it was reverted). I have added
a testcase for that as well.
Original commit message:
It is often convenient to use -save-temps to collect the intermediate
results of a compilation, e.g., when triaging a bug report. Besides the
temporary files for preprocessed source and assembly code, this adds the
unoptimized bitcode files as well.
This adds a new BackendJobAction, which is mostly mechanical, to run after
the CompileJobAction. When not using -save-temps, the BackendJobAction is
combined into one job with the CompileJobAction, similar to the way the
integrated assembler is handled. I've implemented this entirely as a
driver change, so under the hood, it is just using -disable-llvm-optzns
to get the unoptimized bitcode.
Based in part on a patch by Steven Wu.
rdar://problem/18909437
Richard Trieu [Sat, 20 Dec 2014 03:03:32 +0000 (03:03 +0000)]
Fix a bunch of integer template argument problems in template type diffing.
Reverts most of the changes from r168005. Since template arguments have proper
conversions now, no extending of integers is needed. Further, since the
integers are the correct size now, use APSInt::operator== instead of
APSInt::hasSameValue since operator== will check the size and signness match.
Prior to one comparison of APSInt's, check that both are valid. Previous, one
could be uninitialized. Also changed APInt to APSInt in GetInt. This
occassionally produced a sign flip, which will now be caught by operator==.
Richard Trieu [Sat, 20 Dec 2014 02:42:08 +0000 (02:42 +0000)]
Fix for PR21758
When a non-type template argument expression needs a conversion to change it
into the argument type, preserve that information by remaking the
TemplateArgument with an expression that has those conversions. Also a small
fix to template type diffing to handle the extra conversions in some cases.
Aaron Ballman [Sat, 20 Dec 2014 01:54:07 +0000 (01:54 +0000)]
Removing an outdated FIXME; try block attributes are parsed with the rest of the statement attributes (as per the standard), and function-try-blocks may not have attributes. NFC.
Nico Weber [Fri, 19 Dec 2014 23:52:45 +0000 (23:52 +0000)]
Don't drop attributes when checking explicit specializations.
Consider a template class with attributes on a method, and an explicit
specialization of that method:
template <int>
struct A {
void foo() final;
};
template <>
void A<0>::foo() {}
In this example, the attribute is `final`, but it might also be an
__attribute__((visibility("foo"))), noreturn, inline, etc. clang's current
behavior is to strip all attributes, which for some attributes is wrong
(the snippet above allows a subclass of A<0> to override the final method, for
example) and for others disagrees with gcc.
So stop dropping attributes. r95845 added this code without a test case, and
r176728 added the code for dropping attributes on parameters (with tests, but
they still pass).
As an additional wrinkle, do drop dllimport and dllexport, since that's how
these two attributes work. (This is covered by existing tests.)
Fixes PR21942.
The approach is by Richard Smith, initial analysis and typing was done by me.
With this, clang also matches GCC and EDG on all attributes Richard tested.
Alexey Samsonov [Fri, 19 Dec 2014 18:41:43 +0000 (18:41 +0000)]
Allow to disable all sanitizers with "-fno-sanitize=all" option.
Summary:
This patch adds "all" sanitizer group. A shortcut "-fno-sanitize=all"
can be used to disable all sanitizers for a given source file.
"-fsanitize=all" option makes no sense, and will produce an error.
This group can also be useful when we add "-fsanitize-recover=<list>"
options (patch in http://reviews.llvm.org/D6302), as it would allow
to conveniently enable/disable recovery for all specified sanitizers.
Aaron Ballman [Fri, 19 Dec 2014 16:42:04 +0000 (16:42 +0000)]
Attributes accepting an EnumArgument are allowed to pass a string literal, or an identifier. VariadicEnumArguments now behave consistently instead of only accepting a string literal.
This change affects the only attribute accepting a variadic enumeration: callable_when.
[c Sema]. Patch fixes pointer-bool-conversion warning on C code
when source range is incorrect causing the warning to be
issued when it should not because expression is in a macro.
rdar://19256338
Reid Kleckner [Thu, 18 Dec 2014 23:07:04 +0000 (23:07 +0000)]
Revert "Change -save-temps to emit unoptimized bitcode files."
This reverts commit r224503.
It broke compilation of fortran through the Clang driver. Previously
`clang -c t.f` would invoke `gcc t.f` and `clang -cc1as`, but now it
tries to call `clang -cc1 t.f` which fails for obvious reasons.
Reid Kleckner [Thu, 18 Dec 2014 18:17:42 +0000 (18:17 +0000)]
Revert "Don't build invalid AST nodes during recovery"
This reverts commit r224451. It caused us to reject some valid existing
code.
This code appears to run in non-error cases as well as error cases. If
the scope of a DependentScopeDeclRefExpr is still incomplete it probably
means we still have more instantiation to do.
Yaron Keren [Thu, 18 Dec 2014 12:13:14 +0000 (12:13 +0000)]
Enabling this test again on mingw. The problem seems to happen when
two identical module.modulemap are available on the include path and
so should be fixed in the mingw driver include dies, when we'll have it.
Serge Pavlov [Thu, 18 Dec 2014 11:14:21 +0000 (11:14 +0000)]
Fixed warnings on redefine keywords and reserved ids.
Repared support for warnings -Wkeyword-macro and -Wreserved-id-macro.
The warning -Wkeyword-macro now is not issued in patterns that are used
in configuration scripts:
#define inline
also for 'const', 'extern' and 'static'. If macro repalcement is identical
to macro name, the warning also is not issued:
#define volatile volatile
And finally if macro replacement is also a keyword identical to the replaced
one but decorated with leading/trailing underscores:
David Majnemer [Thu, 18 Dec 2014 09:57:31 +0000 (09:57 +0000)]
Parse: Don't parse after the eof has been consumed
ParseCXXNonStaticMemberInitializer stashes away all the tokens for the
initializer and an additional EOF token to denote where the initializer
ends. However, it is possible for ParseLexedMemberInitializer to get
its hands on the "real" EOF token; since the two tokens are
indistinguishable, we end up consuming the EOF and descend into madness.
Instead, make it possible to tell which EOF token we are looking at.
Alexey Bataev [Thu, 18 Dec 2014 06:54:53 +0000 (06:54 +0000)]
Fix for PR21915: assert on multidimensional VLA in function arguments.
Fixed assertion on type checking for arguments and parameters on function call if arguments are pointers to VLA
Differential Revision: http://reviews.llvm.org/D6655
Bob Wilson [Thu, 18 Dec 2014 06:08:26 +0000 (06:08 +0000)]
Change -save-temps to emit unoptimized bitcode files.
It is often convenient to use -save-temps to collect the intermediate
results of a compilation, e.g., when triaging a bug report. Besides the
temporary files for preprocessed source and assembly code, this adds the
unoptimized bitcode files as well.
This adds a new BackendJobAction, which is mostly mechanical, to run after
the CompileJobAction. When not using -save-temps, the BackendJobAction is
combined into one job with the CompileJobAction, similar to the way the
integrated assembler is handled. I've implemented this entirely as a
driver change, so under the hood, it is just using -disable-llvm-optzns
to get the unoptimized bitcode.
Based in part on a patch by Steven Wu.
rdar://problem/18909437
Eric Christopher [Thu, 18 Dec 2014 02:08:55 +0000 (02:08 +0000)]
Make sure that arm-linux-gnu is still the apcs-gnu ABI when we
use clang -cc1 matching the front end and backend. Fix up a couple
of tests that were testing aapcs for arm-linux-gnu.
The test that removes the aapcs abi calling convention removes
them because the default triple matches what the backend uses
for the calling convention there and so it doesn't need to be
explicitly stated - see the code in TargetInfo.cpp.