[cfe-commits] r44100 - in /cfe/trunk: Sema/Sema.h Sema/SemaDecl.cpp test/Sema/typedef-prototype.c

Chris Lattner sabre at nondot.org
Tue Nov 13 22:34:38 PST 2007


Author: lattner
Date: Wed Nov 14 00:34:38 2007
New Revision: 44100

URL: http://llvm.org/viewvc/llvm-project?rev=44100&view=rev
Log:
implement test/Sema/typedef-prototype.c, allowing code
to declare a function with a typedef:

typedef int unary_int_func(int arg);
unary_int_func add_one;

This patch contributed by Seo Sanghyeon!


Added:
    cfe/trunk/test/Sema/typedef-prototype.c
Modified:
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=44100&r1=44099&r2=44100&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Wed Nov 14 00:34:38 2007
@@ -224,7 +224,8 @@
                              DeclTy **Elements, unsigned NumElements);
 private:
   /// Subroutines of ActOnDeclarator()...
-  TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, ScopedDecl *LastDecl);
+  TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
+                                ScopedDecl *LastDecl);
   TypedefDecl *MergeTypeDefDecl(TypedefDecl *New, ScopedDecl *Old);
   FunctionDecl *MergeFunctionDecl(FunctionDecl *New, ScopedDecl *Old);
   VarDecl *MergeVarDecl(VarDecl *New, ScopedDecl *Old);

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

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Wed Nov 14 00:34:38 2007
@@ -572,8 +572,11 @@
   ScopedDecl *New;
   bool InvalidDecl = false;
   
+  QualType R = GetTypeForDeclarator(D, S);
+  assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
+
   if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
-    TypedefDecl *NewTD = ParseTypedefDecl(S, D, LastDeclarator);
+    TypedefDecl *NewTD = ParseTypedefDecl(S, D, R, LastDeclarator);
     if (!NewTD) return 0;
 
     // Handle attributes prior to checking for duplicates in MergeVarDecl
@@ -595,10 +598,7 @@
         InvalidDecl = true;
       }
     }
-  } else if (D.isFunctionDeclarator()) {
-    QualType R = GetTypeForDeclarator(D, S);
-    assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
-
+  } else if (R.getTypePtr()->isFunctionType()) {
     FunctionDecl::StorageClass SC = FunctionDecl::None;
     switch (D.getDeclSpec().getStorageClassSpec()) {
       default: assert(0 && "Unknown storage class!");
@@ -628,8 +628,6 @@
     }
     New = NewFD;
   } else {
-    QualType R = GetTypeForDeclarator(D, S);
-    assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
     if (R.getTypePtr()->isObjcInterfaceType()) {
       Diag(D.getIdentifierLoc(), diag::err_statically_allocated_object,
            D.getIdentifier()->getName());
@@ -1041,11 +1039,9 @@
 }
 
 
-TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D,
+TypedefDecl *Sema::ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
                                     ScopedDecl *LastDeclarator) {
   assert(D.getIdentifier() && "Wrong callback for declspec without declarator");
-  
-  QualType T = GetTypeForDeclarator(D, S);
   assert(!T.isNull() && "GetTypeForDeclarator() returned null type");
   
   // Scope manipulation handled by caller.

Added: cfe/trunk/test/Sema/typedef-prototype.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typedef-prototype.c?rev=44100&view=auto

==============================================================================
--- cfe/trunk/test/Sema/typedef-prototype.c (added)
+++ cfe/trunk/test/Sema/typedef-prototype.c Wed Nov 14 00:34:38 2007
@@ -0,0 +1,8 @@
+// RUN: clang -fsyntax-only -verify %s
+
+typedef int unary_int_func(int arg);
+unary_int_func add_one;
+
+int add_one(int arg) {
+  return arg + 1;
+}





More information about the cfe-commits mailing list