Douglas Gregor [Fri, 5 Feb 2010 22:49:09 +0000 (22:49 +0000)]
Fix a bogus assertion after adjusting the type of a substituted
non-type template argument for a non-type template parameter of
pointer type. Fixes PR6244.
Douglas Gregor [Fri, 5 Feb 2010 22:40:03 +0000 (22:40 +0000)]
Cope with finding the "instantiated" declaration when we are
type-checking within a template definition. In this case, the
"instantiated" declaration is just the declaration itself, found
within the current instantiation. Fixes PR6239.
John McCall [Fri, 5 Feb 2010 21:31:56 +0000 (21:31 +0000)]
Standardize the parsing of function type attributes in a way that
follows (as conservatively as possible) gcc's current behavior: attributes
written on return types that don't apply there are applied to the function
instead, etc. Only parse CC attributes as type attributes, not as decl attributes;
don't accepet noreturn as a decl attribute on ValueDecls, either (it still
needs to apply to other decls, like blocks). Consistently consume CC/noreturn
information throughout codegen; enforce this by removing their default values
in CodeGenTypes::getFunctionInfo().
Ted Kremenek [Fri, 5 Feb 2010 21:28:51 +0000 (21:28 +0000)]
Add guard in RewriteObjC::HandleTopLevelSingleDecl() to not do
anything when Sema has issued an error. This matches the behavior in
RewriteObjC::HandleTranslationUnit().
Douglas Gregor [Fri, 5 Feb 2010 19:54:12 +0000 (19:54 +0000)]
Fix two issues with the substitution of template template parameters
when instantiating the declaration of a member template:
- Only check if the have a template template argument at a specific position
when we already know that we have template arguments at that level;
otherwise, we're substituting for a level-reduced template template
parameter.
- When trying to find an instantiated declaration for a template
template parameter, look into the instantiated scope. This was a
typo, where we had two checks for TemplateTypeParmDecl, one of
which should have been a TemplateTemplateParmDecl.
With these changes, tramp3d-v4 passes -fsyntax-only.
Douglas Gregor [Fri, 5 Feb 2010 19:11:37 +0000 (19:11 +0000)]
When we're parsing an expression that may have looked like a
declaration, we can end up with template-id annotation tokens for
types that have not been converted into type annotation tokens. When
this is the case, translate the template-id into a type and parse as
an expression.
Charles Davis [Fri, 5 Feb 2010 18:13:10 +0000 (18:13 +0000)]
Now that we store calling conventions in the types, use them instead of
getting the calling convention from the target function, which may or may not
exist. Fixes PR5280.
Douglas Gregor [Fri, 5 Feb 2010 17:54:41 +0000 (17:54 +0000)]
Initial skeleton of an AST "importer", which will take AST elements from
one context and import them into another context, merging them
according to language-specific rules. This is a skeleton. It doesn't
work, it isn't testable, but I want it in version control.
Daniel Dunbar [Fri, 5 Feb 2010 17:51:33 +0000 (17:51 +0000)]
IRgen: Use hasAggregateLLVMType instead of isSingleValueType() for cases that
need to deal with aggregates specially; this is consistent with the rest of IRgen.
Also, simplify EmitParmDecl and don't worry about using Decl::getNameAsString.
Douglas Gregor [Fri, 5 Feb 2010 07:56:11 +0000 (07:56 +0000)]
A dependent initializer with zero arguments should return a NULL
initializer (for no initialization) rather than a ParenListExpr with
zero arguments in it.
Douglas Gregor [Fri, 5 Feb 2010 07:33:43 +0000 (07:33 +0000)]
Default function arguments for function template specializations
always come from the primary template, so gather the instantiation
template arguments from the primary template.
Douglas Gregor [Fri, 5 Feb 2010 07:07:10 +0000 (07:07 +0000)]
Teach C++ name lookup that it's okay to look in a scope without a
context. This happens fairly rarely (which is why we got away with
this bug). Fixes PR6184, where we skipped over the template parameter
scope while tentatively parsing.
Douglas Gregor [Thu, 4 Feb 2010 23:42:48 +0000 (23:42 +0000)]
Fix a crash with ill-formed code within a method in an ill-formed
category implementation, which showed up during (attempted) typo
correction. Fixes <rdar://problem/7605289>.
John McCall [Thu, 4 Feb 2010 22:26:26 +0000 (22:26 +0000)]
Extract a common structure for holding information about the definition
of a C++ record. Exposed a lot of problems where various routines were
silently doing The Wrong Thing (or The Acceptable Thing in The Wrong Order)
when presented with a non-definition. Also cuts down on memory usage.
Douglas Gregor [Thu, 4 Feb 2010 18:10:26 +0000 (18:10 +0000)]
Fix an obscure crash found in the Boost.MPL test suite, along with a
ton of potential crashes of the same kind. The fundamental problem is
that type creation was following a dangerous pattern when using its
FoldingSets:
1) Use FindNodeOrInsertPos to see if the type is available
2) If not, and we aren't looking at a canonical type, build the
canonical type
3) Build and insert the new node into the FoldingSet
The problem here is that building the canonical type can, in very rare
circumstances, force the hash table inside the FoldingSet to
reallocate. That invalidates the insertion position we computed in
step 1, and in step 3 we end up inserting the new node into the wrong
place. BOOM!
I've audited all of ASTContext, fixing this problem everywhere I found
it. The vast majority of wrong code was C++-specific (and *ahem*
written by me), so I also audited other major folding sets in the C++
code (e.g., template specializations), but found no other instances of
this problem.
which means that we pass 99.96% of all tests :) The resulting 27 tests are all LLVMC tests and seem to be because of differences in the clang and gcc drivers.
Douglas Gregor [Thu, 4 Feb 2010 17:21:48 +0000 (17:21 +0000)]
When substituting the template argument for a pointer non-type
template parameter, perform array/function decay (if needed), take the
address of the argument (if needed), perform qualification conversions
(if needed), and remove any top-level cv-qualifiers from the resulting
expression. Fixes PR6226.
Ted Kremenek [Thu, 4 Feb 2010 07:27:39 +0000 (07:27 +0000)]
Convert flags in FormatSpecifier to be bitfields instead of doing
direct bit manipulation. This is is less error prone, and fixes a bug
in the handling of the LeadingZeroes flag as pointed out by Cristian
Draghici.
Ted Kremenek [Thu, 4 Feb 2010 00:47:48 +0000 (00:47 +0000)]
static analyzer: handle casts of a function to a function pointer with
a different return type. While we don't emit any errors (yet), at
least we avoid cases where we might crash because of an assertion
failure later on (when the return type differs from what is expected).
Anders Carlsson [Wed, 3 Feb 2010 21:58:41 +0000 (21:58 +0000)]
Don't try to fold DeclRefExprs that point to ParmVarDecls. This had the side-effect of always folding the expression to the default argument of the parameter. For example:
void f(int a = 10) {
return a;
}
would always return 10, regardless of the passed in argument.
This fixes another 600 test failures. We're now down to only 137 failures!
Chris Lattner [Wed, 3 Feb 2010 21:06:21 +0000 (21:06 +0000)]
don't inform comment handlers about comments in #if 0 blocks,
doing so invalidates the file guard optimization and is not
in the spirit of "#if 0" because it is supposed to completely
skip everything, even if it isn't lexically valid. Patch by
Abramo Bagnara!
Douglas Gregor [Wed, 3 Feb 2010 21:02:30 +0000 (21:02 +0000)]
Define two types to be "compatible" in C++ if they are the same, and
remove some age-old FIXMEs and C++ workarounds within the
type-compatibility logic.
Douglas Gregor [Wed, 3 Feb 2010 19:27:29 +0000 (19:27 +0000)]
When determining whether a function without a prototype is compatible
with a function with a prototype, treat parameters of enumeration type
based on the enumeration type's promotion type.
Teach the allocation function overload handling to deal with templates, and
prevent a crash on templates when looking for an existing declaration of the
predefined global operators. This fixes PR5918.
Added an easy test case for the overload handling, but testing the crash is
a bit trickier. Created a new test that can use multiple runs with a define to
trigger which test case is used so we can test this type of issue.
Fix PR6149 by looking at the qualifiers on the referred to type for non-type
reference template arguments. Adds test cases for the cv-quals of reference
arguments.
Douglas Gregor [Wed, 3 Feb 2010 09:33:45 +0000 (09:33 +0000)]
When a function or variable somehow depends on a type or declaration
that is in an anonymous namespace, give that function or variable
internal linkage.
This change models an oddity of the C++ standard, where names declared
in an anonymous namespace have external linkage but, because anonymous
namespace are really "uniquely-named" namespaces, the names cannot be
referenced from other translation units. That means that they have
external linkage for semantic analysis, but the only sensible
implementation for code generation is to give them internal
linkage. We now model this notion via the UniqueExternalLinkage
linkage type. There are several changes here:
- Extended NamedDecl::getLinkage() to produce UniqueExternalLinkage
when the declaration is in an anonymous namespace.
- Added Type::getLinkage() to determine the linkage of a type, which
is defined as the minimum linkage of the types (when we're dealing
with a compound type that is not a struct/class/union).
- Extended NamedDecl::getLinkage() to consider the linkage of the
template arguments and template parameters of function template
specializations and class template specializations.
- Taught code generation to rely on NamedDecl::getLinkage() when
determining the linkage of variables and functions, also
considering the linkage of the types of those variables and
functions (C++ only). Map UniqueExternalLinkage to internal
linkage, taking out the explicit checks for
isInAnonymousNamespace().
This fixes much of PR5792, which, as discovered by Anders Carlsson, is
actually the reason behind the pass-manager assertion that causes the
majority of clang-on-clang regression test failures. With this fix,
Clang-built-Clang+LLVM passes 88% of its regression tests (up from
67%). The specific numbers are:
Still to do:
- Improve testing
- Check whether we should allow the presence of types with
InternalLinkage (in addition to UniqueExternalLinkage) given
variables/functions internal linkage in C++, as mentioned in
PR5792.
- Determine how expensive the getLinkage() calls are in practice;
consider caching the result in NamedDecl.
- Assess the feasibility of Chris's idea in comment #1 of PR5792.