[cfe-commits] r39372 - in /cfe/cfe/trunk: AST/SemaDecl.cpp Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj
Steve Naroff
snaroff at apple.com
Wed Jul 11 09:43:43 PDT 2007
Author: snaroff
Date: Wed Jul 11 11:43:43 2007
New Revision: 39372
URL: http://llvm.org/viewvc/llvm-project?rev=39372&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
- Finished up incomplete type analysis for varibles (in Sema::ParseDeclarator()).
- Added many spec refs, since this area is confusing (for top level decls
in particular).
- Added a FIXME to MergeVarDecl()...it needs to be taught about tentative
definitions. As a result, we currently issue some bogus diagnostics.
Modified:
cfe/cfe/trunk/AST/SemaDecl.cpp
cfe/cfe/trunk/Sema/SemaDecl.cpp
cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39372&r1=39371&r2=39372&view=diff
==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:43:43 2007
@@ -188,6 +188,9 @@
/// and scope as a previous declaration 'Old'. Figure out how to resolve this
/// situation, merging decls or emitting diagnostics as appropriate.
///
+/// FIXME: Need to carefully consider tentative definition rules (C99 6.9.2p2).
+/// For example, we incorrectly complain about i1, i4 from C99 6.9.2p4.
+///
VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
// Verify the old decl was also a variable.
VarDecl *Old = dyn_cast<VarDecl>(OldD);
@@ -270,17 +273,31 @@
case DeclSpec::SCS_auto: SC = ObjectDecl::Auto; break;
case DeclSpec::SCS_register: SC = ObjectDecl::Register; break;
}
- // C99 6.9.2p3: If the declaration of an identifier for an object is a
- // tentative definition and has internal linkage, the declared type shall
- // not be an incomplete type.
- if ((S->getParent() == 0 && !Init && SC == ObjectDecl::None) ||
- SC == ObjectDecl::Static) {
- // FIXME: need a check for internal linkage.
- if (R->isIncompleteType()) {
- Diag(D.getIdentifierLoc(), diag::err_typecheck_decl_incomplete_type, R);
- return 0;
+ if (S->getParent() == 0) {
+ // File scope. C99 6.9.2p2: A declaration of an identifier for and
+ // object that has file scope without an initializer, and without a
+ // storage-class specifier or with the storage-class specifier "static",
+ // constitutes a tentative definition. Note: A tentative definition with
+ // external linkage is valid (C99 6.2.2p5).
+ if (!Init && SC == ObjectDecl::Static) {
+ // C99 6.9.2p3: If the declaration of an identifier for an object is
+ // a tentative definition and has internal linkage (C99 6.2.2p3), the
+ // declared type shall not be an incomplete type.
+ if (R->isIncompleteType()) {
+ Diag(D.getIdentifierLoc(), diag::err_typecheck_decl_incomplete_type, R);
+ return 0;
+ }
}
- }
+ } else {
+ // Block scope. C99 6.7p7: If an identifier for an object is declared with
+ // no linkage (C99 6.2.2p6), the type for the object shall be complete...
+ if (SC != ObjectDecl::Extern) {
+ if (R->isIncompleteType()) {
+ Diag(D.getIdentifierLoc(), diag::err_typecheck_decl_incomplete_type, R);
+ return 0;
+ }
+ }
+ }
VarDecl *NewVD = new VarDecl(D.getIdentifierLoc(), II, R, SC);
// Merge the decl with the existing one if appropriate.
Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39372&r1=39371&r2=39372&view=diff
==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:43:43 2007
@@ -188,6 +188,9 @@
/// and scope as a previous declaration 'Old'. Figure out how to resolve this
/// situation, merging decls or emitting diagnostics as appropriate.
///
+/// FIXME: Need to carefully consider tentative definition rules (C99 6.9.2p2).
+/// For example, we incorrectly complain about i1, i4 from C99 6.9.2p4.
+///
VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
// Verify the old decl was also a variable.
VarDecl *Old = dyn_cast<VarDecl>(OldD);
@@ -270,17 +273,31 @@
case DeclSpec::SCS_auto: SC = ObjectDecl::Auto; break;
case DeclSpec::SCS_register: SC = ObjectDecl::Register; break;
}
- // C99 6.9.2p3: If the declaration of an identifier for an object is a
- // tentative definition and has internal linkage, the declared type shall
- // not be an incomplete type.
- if ((S->getParent() == 0 && !Init && SC == ObjectDecl::None) ||
- SC == ObjectDecl::Static) {
- // FIXME: need a check for internal linkage.
- if (R->isIncompleteType()) {
- Diag(D.getIdentifierLoc(), diag::err_typecheck_decl_incomplete_type, R);
- return 0;
+ if (S->getParent() == 0) {
+ // File scope. C99 6.9.2p2: A declaration of an identifier for and
+ // object that has file scope without an initializer, and without a
+ // storage-class specifier or with the storage-class specifier "static",
+ // constitutes a tentative definition. Note: A tentative definition with
+ // external linkage is valid (C99 6.2.2p5).
+ if (!Init && SC == ObjectDecl::Static) {
+ // C99 6.9.2p3: If the declaration of an identifier for an object is
+ // a tentative definition and has internal linkage (C99 6.2.2p3), the
+ // declared type shall not be an incomplete type.
+ if (R->isIncompleteType()) {
+ Diag(D.getIdentifierLoc(), diag::err_typecheck_decl_incomplete_type, R);
+ return 0;
+ }
}
- }
+ } else {
+ // Block scope. C99 6.7p7: If an identifier for an object is declared with
+ // no linkage (C99 6.2.2p6), the type for the object shall be complete...
+ if (SC != ObjectDecl::Extern) {
+ if (R->isIncompleteType()) {
+ Diag(D.getIdentifierLoc(), diag::err_typecheck_decl_incomplete_type, R);
+ return 0;
+ }
+ }
+ }
VarDecl *NewVD = new VarDecl(D.getIdentifierLoc(), II, R, SC);
// Merge the decl with the existing one if appropriate.
Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=39372&r1=39371&r2=39372&view=diff
==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:43:43 2007
@@ -96,6 +96,23 @@
DED7D9E50A5257F6003AD0FB /* ScratchBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DED7D9E40A5257F6003AD0FB /* ScratchBuffer.cpp */; };
/* End PBXBuildFile section */
+/* Begin PBXBuildStyle section */
+ 8435EC6D0BAA4095007CD940 /* Development */ = {
+ isa = PBXBuildStyle;
+ buildSettings = {
+ COPY_PHASE_STRIP = NO;
+ };
+ name = Development;
+ };
+ 8435EC6E0BAA4095007CD940 /* Deployment */ = {
+ isa = PBXBuildStyle;
+ buildSettings = {
+ COPY_PHASE_STRIP = YES;
+ };
+ name = Deployment;
+ };
+/* End PBXBuildStyle section */
+
/* Begin PBXCopyFilesBuildPhase section */
8DD76F690486A84900D96B5E /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
@@ -483,12 +500,15 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB923508733DC60010E9CD /* Build configuration list for PBXProject "clang" */;
- compatibilityVersion = "Xcode 2.4";
+ buildSettings = {
+ };
+ buildStyles = (
+ 8435EC6D0BAA4095007CD940 /* Development */,
+ 8435EC6E0BAA4095007CD940 /* Deployment */,
+ );
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* clang */;
projectDirPath = "";
- projectRoot = "";
- shouldCheckCompatibility = 1;
targets = (
8DD76F620486A84900D96B5E /* clang */,
);
More information about the cfe-commits
mailing list