class C {
static const int number = 50;
static int arr[number];
};
Here's how it worked:
-GetTypeForDeclarator was called from both Sema::ActOnCXXMemberDeclarator and Sema::ActOnDeclarator.
-VariableArrayTypes are not uniqued so two VariableArrayTypes were created with the same DeclRefExpr.
-On exit they both tried to destroy that one DeclRefExpr.
The fix is not to use GetTypeForDeclarator from the Sema::ActOnCXXMemberDeclarator.
llvm-svn: 57313
- Modify BlockExpr to reference the BlockDecl.
This is "cleanup" necessary to improve our lookup semantics for blocks (to fix <rdar://problem/6272905> clang block rewriter: parameter to function not imported into block?).
Still some follow-up work to finish this (forthcoming).
llvm-svn: 57298
Additional benefit is that diagnostics are the same for both direct-initialization and copy-initialization.
In the case of "int x( expression );":
-The Init expression of VarDecl 'x' will be the expression inside the parentheses.
-VarDecl::hasCXXDirectInitializer for VarDecl 'x' will return true to let clients distinguish from "int x = expression ;".
llvm-svn: 57219
This is how this kind of initializers appear in the AST:
-The Init expression of the VarDecl is a functional type construction (of the VarDecl's type).
-The new VarDecl::hasCXXDirectInitializer() returns true.
e.g, for "int x(1);":
-VarDecl 'x' has Init with expression "int(1)" (CXXFunctionalCastExpr).
-hasCXXDirectInitializer() of VarDecl 'x' returns true.
A major benefit is that clients that don't particularly care about which exactly form was the initializer can handle both cases without special case code.
Note that codegening works now for "int x(1);" without any changes to CodeGen.
llvm-svn: 57178
condition as a constant even if the unevaluated side is a not a constant.
We don't do this when extensions are off, and we emit a warning when this
happens:
t.c:22:11: warning: expression is not a constant, but is accepted as one by GNU extensions
short t = __builtin_constant_p(5353) ? 42 : somefunc();
^ ~~~~~~~~~~
suggestions for improvement are welcome. This is obviously horrible, but
is required for real-world code.
llvm-svn: 57153
This is a temporary solution to help with the block rewriter (though it certainly has general utility).
Once DeclGroup's are implemented, this SourceLocation should be stored with it (since it applies to all the decls).
llvm-svn: 56985
- Enabled for builtins which are always constant expressions
(__builtin_huge_val*, __builtin_inf*, __builtin_constant_p,
__builtin_classify_type, __builtin___CFStringMakeConstantString).
Added Builtin::Context::isConstantExpr.
- Currently overly simply interface which only works for builtins
whose constantexprness does not depend on their arguments.
CallExpr::isBuiltinConstantExpr now takes an ASTContext argument.
llvm-svn: 56983
Long standing bug in Sema::ActOnInstanceMessage(). We now warn when messaging an "id" with multiple method signatures in scope. The diags are a little verbose, however they can be streamlined if necessary.
llvm-svn: 56843
- readonly and readwrite are mutually exclusive.
- assign, copy, and retain are mutually exclusive.
- copy and retain are invalid on non-object types.
- Warn about using default 'assign' property on object types
(attempting to follow gcc behavior).
llvm-svn: 56507
- For investigating warnings in system headers / builtins.
- Currently also enables the behavior that allows silent redefinition
of types in system headers. Conceptually these are separate but I
didn't feel it was worth two options (or changing LangOptions).
llvm-svn: 56163
- Follow C99 behavior of using other operand type when one of
operands is a null pointer constant.
- Fix overenthusiastic devolving of any Objective-C types to id:
o If either operand has an Objective-C object type then:
- If both operands are interfaces and either operand can be
assigned to the other, use that type as the composite type.
- Otherwise, if either type is id, use id as the composite type.
- Otherwise, warn about incompatible types and use id as the
composite type.
- Return handling of qualified idea to separate test following
general pointer type checking.
o Upgraded from old code to allow devolving to id (without warning,
which matches GCC).
- <rdar://problem/6212771>
Add test case for issues fixed above, XFAIL though because it exposed
a new issue in property handling.
llvm-svn: 56135
(1) Additional arguments to variadic methods should have default
promotions applied.
(2) Additional arguments to non-variadic methods were allowed.
llvm-svn: 56084
no method declaration was found.
- This was allowing arrays to pass "by value" among other things.
Add assert in CodeGen that arguments cannot have array type.
llvm-svn: 56080
The 'control' scope is the 'condition' scope of if/switch/while statements and the scope that contains the for-init-statement and 'condition' of a for statement.
e.g:
if (int x = 0 /*'control' scope*/) {
// x will be regarded as part of this substatement scope.
} else {
// and as part of this substatement scope too.
}
llvm-svn: 56020
- Replace string comparisons with pre-defined idents.
- Avoid calling isBuiltinObjCType() to avoid two checks.
- Remove isBuiltinObjCType(), since it was only used in Sema::MergeTypeDefDecl().
- Have Sema::MergeTypeDefDecl() set the new type.
This is a moidified version of an patch by David Chisnall.
llvm-svn: 55990
This change effects both RecordDecls and CXXRecordDecls, but does not effect EnumDecls (yet).
The motivation of this patch is as follows:
- Capture more source information, necessary for refactoring/rewriting clients.
- Pave the way to resolve ownership issues with RecordDecls with the forthcoming
addition of DeclGroups.
Current caveats:
- Until DeclGroups are in place, we will leak RecordDecls not explicitly
referenced by the AST. For example:
typedef struct { ... } x;
The RecordDecl for the struct will be leaked because the TypedefDecl doesn't
refer to it. This will be solved with DeclGroups.
- This patch also (temporarily) breaks CodeGen. More below.
High-level changes:
- As before, TagType still refers to a TagDecl, but it doesn't own it. When
a struct/union/class is first referenced, a RecordType and RecordDecl are
created for it, and the RecordType refers to that RecordDecl. Later, if
a new RecordDecl is created, the pointer to a RecordDecl in RecordType is
updated to point to the RecordDecl that defines the struct/union/class.
- TagDecl and RecordDecl now how a method 'getDefinition()' to return the
TagDecl*/RecordDecl* that refers to the TagDecl* that defines a particular
enum/struct/class/union. This is useful from going from a RecordDecl* that
defines a forward declaration to the RecordDecl* that provides the actual
definition. Note that this also works for EnumDecls, except that in this case
there is no distinction between forward declarations and definitions (yet).
- Clients should no longer assume that 'isDefinition()' returns true from a
RecordDecl if the corresponding struct/union/class has been defined.
isDefinition() only returns true if a particular RecordDecl is the defining
Decl. Use 'getDefinition()' instead to determine if a struct has been defined.
- The main changes to Sema happen in ActOnTag. To make the changes more
incremental, I split off the processing of enums and structs et al into two
code paths. Enums use the original code path (which is in ActOnTag) and
structs use the ActOnTagStruct. Eventually the two code paths will be merged,
but the idea was to preserve the original logic both for comparison and not to
change the logic for both enums and structs all at once.
- There is NO CHAINING of RecordDecls for the same RecordType. All RecordDecls
that correspond to the same type simply have a pointer to that type. If we
need to figure out what are all the RecordDecls for a given type we can build
a backmap.
- The diff in CXXRecordDecl.[cpp,h] is actually very small; it just mimics the
changes to RecordDecl. For some reason 'svn' marks the entire file as changed.
Why is CodeGen broken:
- Codegen assumes that there is an equivalence between RecordDecl* and
RecordType*. This was true before because we only created one RecordDecl* for
a given RecordType*, but it is no longer true. I believe this shouldn't be too
hard to change, but the patch was big enough as it is.
I have tested this patch on both the clang test suite, and by running the static analyzer over Postgresql and a large Apple-internal project (mix of Objective-C and C).
llvm-svn: 55839
The motivation behind this change is that chaining the RecordDecls is simply unnecessary. Once we create multiple RecordDecls for the same struct/union/class, clients that care about all the declarations of the same struct can build a back map by seeing which Decls refer to the same RecordType.
llvm-svn: 55821
Added a couple FIXME's wrt PointLikeType. If the author reads this, it would be great to get some background on this class (thanks in advance).
llvm-svn: 55778
- Now also searches for correct setter method.
- There are still some issues regarding validation of the setter
method and access of read-only properties.
llvm-svn: 55686
anywhere near correct in terms of missing cases and missing
diagnostics, but it's good enough to handle the uses in the
Linux system headers, which are currently a constant pain for compiling
applications on Linux.
llvm-svn: 55621
- warn about nonnull being applied to functions with no pointer arguments
- continue processing argument list in the attribute when we encounter a non-pointer parameter being marked as nonnull
- when no argument list is specified, only mark pointers as nonnull. This fixes PR 2732 and radar 6188814.
llvm-svn: 55610
- Change Obj-C runtime message API, drop the ObjCMessageExpr arg in
favor of just result type and selector. Necessary so it can be
reused in situations where we don't want to cons up an
ObjCMessageExpr.
- Update aggregate binary assignment to know about special property
ref lvalues.
- Add CodeGenFunction::EmitCallArg overload which takes an already
emitted rvalue.
Add CodeGenFunction::StoreComplexIntoAddr.
Disabled logic in Sema for parsing Objective-C dot-syntax that
accesses methods. This code does not search in the correct order and
the AST node has no way of properly representing its results.
Updated StmtDumper to print a bit more information about
ObjCPropertyRefExprs.
llvm-svn: 55561
- It is not clear that this is the right approach, but this is at
least consistent with how interfaces are handled.
- This means NeXT now emits the correct metadata for properties in
protocols.
- This currently introduces a spurious warning involving inherited
properties in protocols or categories; however, it also fixes some
situations where we were failing to emit a warning. I will scrub
this code tomorrow and fix this issue as well as number of other
missed warnings / error situations that appear to exist.
llvm-svn: 55407
- Change enum name to Kind.
- Change enum constants to English strings.
Also, fix getPropertyImplementation (which probably should be renamed)
llvm-svn: 55354
of RHSs to id type instead of void* if either has Objective-C object
type.
- This ensures the result can still be used in normal places an
object can be used, like a message send.
Add implicit conversions for ?: applied to qualified id types to
ensure that the RHSs are compatible.
- This prevents a codegen crash (creating invalid PHI nodes).
- Again, this relates to the fact that qualified id types have no
canonical types.
- Note that the implicit type casted to is incorrect, however this
doesn't currently cause problems because of the flexibility of the
id type.
Test cases for above.
llvm-svn: 55346
casting pointers to integers.
Eventually, we should check whether we can evaluate an expression
using Expr::tryEvaluate, and this codepath should be tightened to only
handle standard-compliant cases.
llvm-svn: 55331
-The Parser calls a new "ActOnCXXTypeConstructExpr" action.
-Sema, depending on the type and expressions number:
-If the type is a class, it will treat it as a class constructor. [TODO]
-If there's only one expression (i.e. "int(0.5)" ), creates a new "CXXFunctionalCastExpr" Expr node
-If there are no expressions (i.e "int()" ), creates a new "CXXZeroInitValueExpr" Expr node.
llvm-svn: 55177
testing compatibility. This is necessary for some constructs, like merging
redeclarations.
Also, there are some ObjC changes to make sure that
typesAreCompatible(a,b) == typesAreCompatible(b,a). I don't have any
ObjC code beyond the testsuite, so please tell me if there are any cases
where this doesn't behave as expected.
llvm-svn: 55158
- UsualUnaryConversions takes an Expr *& and may modify its argument,
this broke when it was refactored into Sema::CheckCastTypes. This
meant that we were missing implicit casts in some places.
- Seems pretty sad that this got through our tests.
llvm-svn: 55039
- Added as private members for each because it is not clear where to
put the common definition. Perhaps the IdentifierInfos all of these
"pseudo-keywords" should be collected into one place (this would
KnownFunctionIDs and Objective-C property IDs, for example).
Remove Token::isNamedIdentifier.
- There isn't a good reason to use strcmp when we have interned
strings, and there isn't a good reason to encourage clients to do
so.
llvm-svn: 54794
and put the caret on the ()'s. e.g. produces:
t.c:13:9: error: called object is not a function or function pointer
((B)a)();
~~~~~~^
instead of:
t.c:13:3: error: called object is not a function or function pointer
((B)a)();
^~~~~~~~
llvm-svn: 54775
The following case resulted in an invalid start location:
// start location not being set for ObjCProtocolDecl AST (when a forward reference is in scope).
@protocol Buggy;
@protocol Buggy
@optional
- whatever;
@end
llvm-svn: 54740
- Kill unnecessary #includes in .cpp files. This is an automatic
sweep so some things removed are actually used, but happen to be
included by a previous header. I tried to get rid of the obvious
examples and this was the easiest way to trim the #includes in one
fell swoop.
- We now return to regularly scheduled development.
llvm-svn: 54632
- Drop {Decl.h,DeclObjC.h,IdentifierTable.h} from Expr.h
- Moved Sema::getCurMethodDecl() out of line (dependent on
ObjCMethodDecl via dyn_cast).
llvm-svn: 54629
member count. The count returned by numStructUnionElements is the
number of initializers that will be consumed, not the number of members
to iterate through. Fixes PR2534.
llvm-svn: 54601
Even though the test case this fixes is in "tentative-decls.c", this bug didn't have anything to do with our handling of tentative definitions (which is what I first expected). In any event, this is a tricky area of the spec.
llvm-svn: 54583
- Move checking from MergeVarDecl->FinializeDeclaratorGroup. Since MergeVarDecl is called before the initializer is attacted, it can't be done there (this removes a long standing FIXME).
- Add Sema::isTentativeDefinition() and Sema::CheckForFileScopedRedefinitions().
- Remove FIXME's and touch-up test case.
Still some more work to do (forthcoming)...
llvm-svn: 54533
The motivation is that clients may either:
(a) query the ASTConsumer object after AST parsing to collect data/etc.
(b) reuse the ASTConsumer.
llvm-svn: 54502
scimark2 on Darwin.
- Added Sema support for asm-label on variables, which I forgot before.
- Update CodeGen to use GlobalDeclMap to determine if static Decls
require emission (instead of LLVM module name lookup). Important
since the Decl name and the LLVM module name can differ.
- <rdar://problem/6116729>
llvm-svn: 54388
- ActOnDeclarator now takes an additional parameter which is the
AsmLabel if used. Its unfortunate that this bubbles up this high,
but we cannot just lump it in as an attribute without mistakenly
*accepting* it as an attribute.
- The actual asm-label itself is, however, encoded as an AsmLabelAttr
on the FunctionDecl.
- Slightly improved parser error recovery on malformed asm-labels.
- CodeGen support still missing...
llvm-svn: 54339
- Follows emission scheme used by llvm-gcc, i.e. invent an id for
each label whose address is taken and replace each indirect goto by
a switch to each possible target.
- Currently we emit a switch for each indirect goto instead of
merging them as llvm-gcc does.
llvm-svn: 54318
move getAsArrayType into ASTContext instead of being a method on type.
This is required because getAsArrayType(const AT), where AT is a typedef
for "int[10]" needs to return ArrayType(const int, 10).
Fixing this greatly simplifies getArrayDecayedType, which is a good sign.
llvm-svn: 54317
First, fix canonical type handling of these, since protocol qualified id's are always
canonical. Next, enhance SemaType to actually make these when used (instead of int)
allowing them to actually be used when appropriate. Finally remove a bunch of logic
relating to the mishandling of canonical types with protocol-qual id's. This fixes
rdar://5986251
llvm-svn: 54083
problem with &&/||. 2) use canonical types for comparison instead
of raw types. 3) emit an ext-warn for a gnu extension.
Also simplify the code to make it less nested.
llvm-svn: 54068
(a) removes a bogus warning.
(b) removes an undesirable usage of the ObjCMessageExpr constructor that takes an IdentifierInfo * (which I will abolish).
llvm-svn: 54042
This fixes a critical rewriter bug (<rdar://problem/6096760> clang ObjC rewriter: 'self' not expected value in class method called with 'super').
Also added a couple FIXME's since I'm not happy with my fix to Sema. It would be nicer if the super handling for class/instance messages was the same (based on PreDefinedExpr).
llvm-svn: 53994
This change also fixes a subtle bug where the access control of an ivar would be initialized to garbage if we didn't have an explicit visibility specifier (e.g., @private).
llvm-svn: 53955
of a specific smallvector size.
Fix protocol lists to pass down proper location info, so we get diagnostics
like this:
t.m:3:35: error: cannot find protocol definition for 'NSCopying', referenced by 'NSWhatever'
@interface NSWhatever : NSObject <NSCopying>
^
instead of this:
t.m:3:44: error: cannot find protocol definition for 'NSCopying', referenced by 'NSWhatever'
@interface NSWhatever : NSObject <NSCopying>
^
Add a new IdentifierLocPair typedef which is just a pair<IdentifierInfo*, SourceLocation>
llvm-svn: 53883