Commit Graph

23967 Commits

Author SHA1 Message Date
David Majnemer 4d2de1b03f Sema: Don't dyn_cast a null pointer in CheckUsingDeclQualifier
This code was written with the intent that a pointer could be null but
we dyn_cast'd it anyway.  Change the dyn_cast to a dyn_cast_or_null.

This fixes PR21933.

llvm-svn: 224411
2014-12-17 02:41:36 +00:00
David Majnemer 6ca445e0dd Parse: Consume tokens more carefully in CheckForLParenAfterColonColon
We would consume the lparen even if it wasn't followed by an identifier
or a star-identifier pair.

This fixes PR21815.

llvm-svn: 224403
2014-12-17 01:39:22 +00:00
Richard Smith b9be608f2d Add missing testcase from r224388.
llvm-svn: 224401
2014-12-17 01:08:39 +00:00
Anna Zaks 87d404d458 [CallGraph] Make sure the edges are not missed due to re-declarations
A patch by Daniel DeFreez!

We were previously dropping edges on re-declarations. Store the
canonical declarations in the graph to ensure that different
references to the same function end up reflected with the same call graph
node.

(Note, this might lead to performance fluctuation because call graph
is used to determine the function analysis order.)

llvm-svn: 224398
2014-12-17 00:34:07 +00:00
David Blaikie 0317bc9e55 PR21909: Don't try (and crash) to generate debug info for explicit instantiations of explicit specializations.
llvm-svn: 224394
2014-12-16 23:49:18 +00:00
Richard Smith d52186ff5a DR1684: a constexpr member function need not be a member of a literal class type.
llvm-svn: 224388
2014-12-16 23:12:52 +00:00
Kaelyn Takata 938204aa02 Try typo correction on all initialization arguments and be less
pessimistic about when to do so.

This also fixes PR21905 as the initialization argument was no longer
viewed as being type dependent due to the TypoExpr being type-cast.

llvm-svn: 224386
2014-12-16 23:07:00 +00:00
David Blaikie bf22a4eaee DebugInfo: Generalize debug info location handling
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.

llvm-svn: 224385
2014-12-16 22:49:17 +00:00
Nick Lewycky 4d59b77883 Look at whether TransformTypos returned a different Expr instead of looking at the number of uncorrected typos before and after. Correcting one typo may produce an expression with another TypoExpr in it, leading to matching counts even though a typo was corrected.
Fixes PR21925!

llvm-svn: 224380
2014-12-16 22:02:06 +00:00
Rafael Espindola fd8de1c3ae Fix handling of invalid -O options.
We were checking the value after truncating it to a bitfield.

Thanks to Yunzhong Gao for noticing it.

llvm-svn: 224378
2014-12-16 21:57:03 +00:00
Nick Lewycky 246532627e Add a new flag, -fspell-checking-limit=<number> to control how many times we'll do spell checking. Note that spell checking will change the produced AST, so we don't automatically change this value when someone sets -ferror-limit=. With this, merge test typo-correction-pt2.cpp into typo-correction.cpp.
Remove Sema::UnqualifiedTyposCorrected, a cache of corrected typos. It would only cache typo corrections that didn't provide ValidateCandidate of which there were few left, and it had a bug when we had the same identifier spelled wrong twice. See the last two tests in typo-correction.cpp for cases this fires.

llvm-svn: 224375
2014-12-16 21:39:02 +00:00
Nico Weber 92c14bb2ff Move -Wkeyword-macro into -pedantic, remove -Wreserved-id-macro.
As discussed on the post-commit review thread for r224012, -Wkeyword-macro fires
mostly on headers trying to set up portable defines and doesn't find much bad
stuff in practice.  But [macro.names]p2 does disallow defining or undefining
keywords, override and final, and alignas, so keep the warning but move it
into -pedantic.

-Wreserved-id-macro warns on

    #define __need_size_t

which is more or less public api for glibc headers. Since this warning isn't
motivated by a standard, remove it.

(See also r223114 for a previous follow-up to r224012.)

llvm-svn: 224371
2014-12-16 21:16:10 +00:00
Rafael Espindola ce4757b8e7 Put static local variables of inline functions in the function comdat.
The variable (and the GV) is only ever used if the function is. Putting it
in the function's comdat make it easier for the linker to discard them.

The motivating example is

struct S {
  static const int x;
};
// const int S::x = 42;
inline const int *f() {
  static const int y = S::x;
  return &y;
}
const int *g() { return f(); }

With S::x commented out, _ZZ1fvE1y is a variable with a guard variable
that is initialized by f.

With S::x present, _ZZ1fvE1y is a constant.

llvm-svn: 224369
2014-12-16 21:00:30 +00:00
Jacques Pienaar 5bdd67778f Consider calls from implict host device functions as valid in SemaCUDA.
In SemaCUDA all implicit functions were considered host device, this led to
errors such as the following code snippet failing to compile:

struct Copyable {
  const Copyable& operator=(const Copyable& x) { return *this; }
};

struct Simple {
  Copyable b;
};

void foo() {
  Simple a, b;

  a = b;
}

Above the implicit copy assignment operator was inferred as host device but
there was only a host assignment copy defined which is an error in device
compilation mode.

Differential Revision: http://reviews.llvm.org/D6565

llvm-svn: 224358
2014-12-16 20:12:38 +00:00
Alexey Bataev f841bd9fcd [OPENMP] Bugfix for processing of global variables in OpenMP regions.
Currently, if global variable is marked as a private OpenMP variable, the compiler crashes in debug version or generates incorrect code in release version. It happens because in the OpenMP region the original global variable is used instead of the generated private copy. It happens because currently globals variables are not captured in the OpenMP region.
This patch adds capturing of global variables iff private copy of the global variable must be used in the OpenMP region.
Differential Revision: http://reviews.llvm.org/D6259

llvm-svn: 224323
2014-12-16 07:00:22 +00:00
David Majnemer e7029bce82 Sema: Don't crash converting to bool from _Atomic
Turning our _Atomic L-value into an R-value removes its _Atomic-ness.
However, we didn't update our 'FromType' which made
ScalarTypeToBooleanCastKind think we were trying to pass it a
non-scalar.

This fixes PR21836.

llvm-svn: 224322
2014-12-16 06:31:17 +00:00
Nick Lewycky f0202ca775 Improve handling of value dependent expressions in __attribute__((enable_if)), both in the condition expression and at the call site. Fixes PR20988!
llvm-svn: 224320
2014-12-16 06:12:01 +00:00
David Majnemer 9963adeaef AST: Fix the linkage of static vars in fn template specializations
We that static variables in function template specializations were
externally visible.  The manglers assumed that externally visible static
variables were numbered in Sema.  We would end up mangling static
variables in the same specialization with the same mangling number which
would give all of them the same name.

This fixes PR21904.

llvm-svn: 224316
2014-12-16 04:52:14 +00:00
David Majnemer e64941fa60 Sema: Check value dependent casts when possible
We know that const_cast<char *>((void)Something) is ill-formed, even if
'Something' is dependent because you can't cast from void to a pointer
type.

This fixes PR21845.

llvm-svn: 224299
2014-12-16 00:46:30 +00:00
Reid Kleckner d61a311010 Diagnose function template definitions inside functions
The parser can only be tricked into parsing a function template
definition by inserting a typename keyword before the function template
declaration. This used to make us crash, and now it's fixed.

While here, remove an unneeded boolean parameter from ParseDeclGroup.
This boolean always corresponded to non-typedef declarators at file
scope. ParseDeclGroup already has precise diagnostics for the function
definition typedef case, so we can let that through.

Fixes PR21839.

llvm-svn: 224287
2014-12-15 23:16:32 +00:00
Reid Kleckner aac43c6a77 Handle errors in lambda prototype instantiation correctly
Previously we would attempt to build a TypeSourceInfo for a null type,
and then we would forget to pop the function scope before returning an
error.

Reviewers: rsmith

Differential Revision: http://reviews.llvm.org/D6665

llvm-svn: 224271
2014-12-15 21:07:16 +00:00
Daniel Marjamaki 368590094a Sema: Cleanup and improve string-plus-char checking.
Patch by Anders Rönnholm

llvm-svn: 224268
2014-12-15 20:22:33 +00:00
Adrian Prantl 98f1f27810 Update this testcase for the new metadata assembler syntax.
llvm-svn: 224262
2014-12-15 19:25:33 +00:00
Duncan P. N. Exon Smith b3a66691f8 IR: Make metadata typeless in assembly, clang side
Match LLVM changes from r224257.

llvm-svn: 224259
2014-12-15 19:10:08 +00:00
Paul Robinson 30e41fb4da Warn when attribute 'optnone' conflicts with attributes on a
different declaration of the same function.

llvm-svn: 224256
2014-12-15 18:57:28 +00:00
David Majnemer 7e21745e22 Sema: Don't diagnose string + int if the int is value dependent
Don't send a value dependent expression into the expression evaluator,
HandleSizeof would crash.  Making HandleSizeof handle dependent types
would noisily warn about the operation even if everything turns out OK
after instantiation.

This fixes PR21848.

llvm-svn: 224240
2014-12-15 10:00:35 +00:00
David Majnemer d616362fe3 Preprocessor: Recover instead of mutating a token in ExpandBuiltinMacro
We would CreateString on arbitrary garbage instead of just skipping to
the end of the builtin macro.  Eventually, this would cause us to crash
because we would end up replacing the contents of a character token with
a numeric literal.

This fixes PR21825.

llvm-svn: 224238
2014-12-15 09:03:58 +00:00
David Majnemer 418ad3ff10 Sema: Don't leave switch stack inconsistent when recovering
We would exit Sema::ActOnFinishSwitchStmt early if we didn't have a
body.  This would leave an extra SwitchStmt on the SwitchStack.

This fixes PR21841.

llvm-svn: 224237
2014-12-15 07:46:12 +00:00
Alexander Musman 51eb1308bd Test for 'omp for' (for r224233).
llvm-svn: 224234
2014-12-15 07:08:38 +00:00
David Majnemer ecabbc52d5 Parse: Don't reorder tokens using ConsumeToken
ConsumeToken doesn't work with special tokens.  Instead, just use PP.Lex
to eat the token.

This fixes PR21817.

llvm-svn: 224232
2014-12-15 07:00:05 +00:00
Alexey Bataev a47ae907e8 Fixed test/CodeGen/atomic_ops.c for compatibility with hexagon target
llvm-svn: 224231
2014-12-15 06:12:42 +00:00
Alexey Bataev 452d8e1133 Bugfix for Codegen of atomic load/store/other ops.
Currently clang fires assertions on x86-64 on any atomic operations for long double operands. Patch fixes codegen for such operations.
Differential Revision: http://reviews.llvm.org/D6499

llvm-svn: 224230
2014-12-15 05:25:25 +00:00
Alexey Bataev 583b076223 MSVC: A wide string literal from L#macro_arg in a macro
Clang should form a wide string literal from L#macro_arg in a function-like macro in -fms-compatibility mode.
Fix for http://llvm.org/PR9984.
Differential Revision: http://reviews.llvm.org/D6604

llvm-svn: 224228
2014-12-15 04:18:11 +00:00
David Blaikie 09f12fa1ca DebugInfo: More accurate line information for placement new.
This actually came up as a break in UBSan tests (look for a follow-up
commit to this one to see the UBSan test fallout) when I tried a broader
fix to location information.

I have some other ideas about how to do that broader change & will keep
looking into it.

llvm-svn: 224221
2014-12-14 18:48:18 +00:00
David Majnemer 17e2633cd6 CodeGen: Compound literals with funny types shouldn't crash
CodeGen assumed that a compound literal with array type should have a
corresponding LLVM IR array type.

We had two bugs in this area:
- Zero sized arrays in compound literals would lead to the creation of
  an opaque type.  This is unnecessary, we should just create an array
  type with a bound of zero.
- Funny record types (like unions) lead to exotic IR types for compound
  literals.  In this case, CodeGen must be prepared to deal with the
  possibility that it might not have an array IR type.

This fixes PR21912.

llvm-svn: 224219
2014-12-14 12:16:43 +00:00
David Majnemer 8c92b87cd0 AST: Limit zero-sized constexpr behavior to array types
Restricting this "extension" to array types maximizes our standards
conformance while not miscompiling real-world programs.

llvm-svn: 224215
2014-12-14 08:40:47 +00:00
David Majnemer 5a54977ea8 Lex: Don't crash if both conflict markers are on the same line
We would check if the terminator marker is on a newline.  However, the
logic would end up out-of-bounds if the terminator marker immediately
follows the start marker.

This fixes PR21820.

llvm-svn: 224210
2014-12-14 04:53:11 +00:00
John McCall 578a1f8c6d If a non-template constructor instantiated to X(X),
ignore it during overload resolution when initializing
X from a value of type cv X.

Previously, our rule here only ignored specializations
of constructor templates.  That's probably because the
standard says that constructors are outright ill-formed
if their first parameter is literally X and they're
callable with one argument.  However, Clang only
enforces that prohibition against non-implicit
instantiations; I'm not sure why, but it seems to be
deliberate.  Given that, the most sensible thing to
do is to just ignore the "illegal" constructor
regardless of where it came from.

Also, stop ignoring such constructors silently:
print a note explaining why they're being ignored.

Fixes <rdar://19199836>.

llvm-svn: 224205
2014-12-14 01:46:53 +00:00
David Majnemer 706f315e65 Sema: attribute((annotate)) must have at least one argument
Sema::handleAnnotateAttr expects that some basic validation is done on
the given AttributeList.  However, ProcessAccessDeclAttributeList called
it directly.  Instead, pass the list to ProcessDeclAttribute.

This fixes PR21847.

llvm-svn: 224204
2014-12-14 01:05:01 +00:00
Hans Wennborg 1fda216122 clang-cl: Fix handling of the /volatile flag (PR21893)
The /volatile:iso flag is our default behaviour, so it can be ignored.

Parse /volatile:ms as unsupported.

llvm-svn: 224202
2014-12-13 22:44:46 +00:00
Hans Wennborg a41faeddb9 clang-cl: ignore /cgthreads (PR21894)
llvm-svn: 224201
2014-12-13 22:24:16 +00:00
Hans Wennborg 951f1ccc98 clang-cl: Make /Gd ignored instead of unsupported
/Gd is the default calling convention setting, so we don't
need to take any action.

llvm-svn: 224200
2014-12-13 22:13:23 +00:00
Hans Wennborg 92391ceb9a clang-cl: Add unsupported /Gv option (PR21892)
We don't currently support any of the calling convention options.

llvm-svn: 224199
2014-12-13 22:06:23 +00:00
David Majnemer 87ff66ccc7 Parse: MS property members cannot have an in-class initializer
We would crash trying to treat a property member as a field.  These
shoudl be forbidden anyway, reject programs which contain them.

This fixes PR21840.

llvm-svn: 224193
2014-12-13 11:34:16 +00:00
David Majnemer 2887ad35c5 Sema: Constexpr functions must have return statements which have an expr
clang lets programmers be pretty cavalier when it comes to void return
statements in functions which have non-void return types.  However, we
cannot be so forgiving in constexpr functions: evaluation will go off
the rails very quickly.

Instead, keep the return statement in the AST but mark the function as
invalid.  Doing so gives us nice diagnostics while making constexpr
evaluation halt.

This fixes PR21859.

llvm-svn: 224189
2014-12-13 08:12:56 +00:00
Will Wilson 67c41ba0dd Pretty print support for template arg enum constants
llvm-svn: 224184
2014-12-13 04:31:07 +00:00
Nick Lewycky 01ad4ae72b Fix two small bugs in typo correction. One assertion failure building member expressions because the lookup finds a different name than the original, fixed by updating the LookupResult's name with the name of the found decl. Second is that we also diagnose delayed typo exprs in the index of an array subscript expression.
The testcase shows a third bug with a FIXME in it.

llvm-svn: 224183
2014-12-13 02:54:28 +00:00
Reid Kleckner a9e65ba19d Implement feedback on r224172 in PR21899
Based on suggestions from Kaelyn.

llvm-svn: 224173
2014-12-13 01:11:23 +00:00
Reid Kleckner a7fe33e0f6 Typo correction: Ignore temporary binding exprs after overload resolution
Transformation of a CallExpr doesn't always result in a new CallExpr.

Fixes PR21899.

llvm-svn: 224172
2014-12-13 00:53:10 +00:00
Peter Collingbourne f770683f14 Implement the __builtin_call_with_static_chain GNU extension.
The extension has the following syntax:

  __builtin_call_with_static_chain(Call, Chain)
  where Call must be a function call expression and Chain must be of pointer type

This extension performs a function call Call with a static chain pointer
Chain passed to the callee in a designated register. This is useful for
calling foreign language functions whose ABI uses static chain pointers
(e.g. to implement closures).

Differential Revision: http://reviews.llvm.org/D6332

llvm-svn: 224167
2014-12-12 23:41:25 +00:00