[cfe-commits] r49214 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/Basic/DiagnosticKinds.def lib/Sema/SemaDecl.cpp test/Sema/implicit-decl.c

Steve Naroff snaroff at apple.com
Fri Apr 4 07:32:10 PDT 2008


Author: snaroff
Date: Fri Apr  4 09:32:09 2008
New Revision: 49214

URL: http://llvm.org/viewvc/llvm-project?rev=49214&view=rev
Log:
Add explicit support for diagnosing implicit function decls.
Without this, the diagnostic is very confusing. The diag is now consistent with gcc as well.

Added:
    cfe/trunk/test/Sema/implicit-decl.c
Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=49214&r1=49213&r2=49214&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Fri Apr  4 09:32:09 2008
@@ -300,13 +300,15 @@
   // NOTE: VC++ treats enums as signed, avoid using the StorageClass enum
   unsigned SClass : 2;
   bool IsInline : 1;
+  bool IsImplicit : 1;
   
   FunctionDecl(ContextDecl *CD, SourceLocation L,
                IdentifierInfo *Id, QualType T,
                StorageClass S, bool isInline, ScopedDecl *PrevDecl)
     : ValueDecl(Function, CD, L, Id, T, PrevDecl), 
       ContextDecl(Function),
-      ParamInfo(0), Body(0), DeclChain(0), SClass(S), IsInline(isInline) {}
+      ParamInfo(0), Body(0), DeclChain(0), SClass(S), 
+      IsInline(isInline), IsImplicit(0) {}
   virtual ~FunctionDecl();
 public:
   static FunctionDecl *Create(ASTContext &C, ContextDecl *CD, SourceLocation L,
@@ -317,6 +319,9 @@
   Stmt *getBody() const { return Body; }
   void setBody(Stmt *B) { Body = B; }
   
+  bool isImplicit() { return IsImplicit; }
+  void setImplicit() { IsImplicit = true; }
+  
   ScopedDecl *getDeclChain() const { return DeclChain; }
   void setDeclChain(ScopedDecl *D) { DeclChain = D; }
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=49214&r1=49213&r2=49214&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Fri Apr  4 09:32:09 2008
@@ -443,6 +443,8 @@
      "duplicate declaration of method '%0'")
 DIAG(err_previous_declaration, ERROR,
      "previous declaration is here")
+DIAG(err_previous_implicit_declaration, ERROR,
+     "previous implicit declaration is here")
 DIAG(err_undeclared_protocol, ERROR,
      "cannot find protocol declaration for '%0'")
 DIAG(err_missing_sel_definition, ERROR,

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=49214&r1=49213&r2=49214&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Apr  4 09:32:09 2008
@@ -290,8 +290,13 @@
 
   // A function that has already been declared has been redeclared or defined
   // with a different type- show appropriate diagnostic
-  diag::kind PrevDiag = Old->getBody() ? diag::err_previous_definition :
-                                         diag::err_previous_declaration; 
+  diag::kind PrevDiag;
+  if (Old->getBody())
+    PrevDiag = diag::err_previous_definition;
+  else if (Old->isImplicit())
+    PrevDiag = diag::err_previous_implicit_declaration;
+  else
+    PrevDiag = diag::err_previous_declaration;
 
   // TODO: CHECK FOR CONFLICTS, multiple decls with same name in one scope.
   // TODO: This is totally simplistic.  It should handle merging functions
@@ -1181,7 +1186,10 @@
   while (S->getParent())
     S = S->getParent();
   
-  return dyn_cast<ScopedDecl>(static_cast<Decl*>(ActOnDeclarator(S, D, 0)));
+  FunctionDecl *FD = 
+    dyn_cast<FunctionDecl>(static_cast<Decl*>(ActOnDeclarator(S, D, 0)));
+  FD->setImplicit();
+  return FD;
 }
 
 

Added: cfe/trunk/test/Sema/implicit-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/implicit-decl.c?rev=49214&view=auto

==============================================================================
--- cfe/trunk/test/Sema/implicit-decl.c (added)
+++ cfe/trunk/test/Sema/implicit-decl.c Fri Apr  4 09:32:09 2008
@@ -0,0 +1,17 @@
+// RUN: clang %s -verify -fsyntax-only
+
+typedef int int32_t;
+typedef unsigned char Boolean;
+
+void func() {
+   int32_t *vector[16];
+   const char compDesc[16 + 1];
+   int32_t compCount = 0;
+   if (_CFCalendarDecomposeAbsoluteTimeV(compDesc, vector, compCount)) { // expected-error{{previous implicit declaration is here}}
+   }
+   return ((void *)0);
+}
+Boolean _CFCalendarDecomposeAbsoluteTimeV(const char *componentDesc, int32_t **vector, int32_t count) { // expected-error{{conflicting types for '_CFCalendarDecomposeAbsoluteTimeV'}}
+ return 0;
+}
+





More information about the cfe-commits mailing list