[cfe-commits] [PATCH] "Prefix" FunctionType attributes on C++ constructors, destructors and conversion operators are ignored.

Benoit Belley Benoit.Belley at autodesk.com
Wed Sep 15 11:26:41 PDT 2010


Hi everyone,

The attached patch fixes a problem where "prefix" FunctionType attributes on C++ constructors, destructors and conversion operators are being ignored.

My first change is in TypeXML.def. It augments the -ast-print-xml functionality to print the noreturn and regparm FunctionType attributes. This functionality allows me to demonstrate the issue.

If we compile the following code, making use of "postfix" FunctionType attributes:

————————————————————————————————————
void f() __attribute__((noreturn));

struct A
{
    A() __attribute__((noreturn)) ;
    ~A() __attribute__((noreturn)) ;
    operator int() __attribute__((noreturn)) ;
    void foo() __attribute__((noreturn)) ;
};
————————————————————————————————————

$ clang++ -cc1 -ast-print-xml foo.cpp

and looked at the foo.xml output, we will see that the FuntionType of all 5 declared functions have the noreturn attribute set.


But, if we compile the following code, making use of "prefix" FunctionType attributes:

————————————————————————————————————
__attribute__((noreturn)) void f();

struct A
{
    __attribute__((noreturn)) A();
    __attribute__((noreturn)) ~A();
    __attribute__((noreturn)) operator int();
    __attribute__((noreturn)) void foo();
};

————————————————————————————————————

$ clang++ -cc1 -ast-print-xml foo.cpp

and looked at the foo.xml output, we will see that only the FuntionType of the f() and foo() function have the noreturn attribute set. The constructor, destructor and conversion operator are all missing the noreturn function attribute.

The problem also occurs with the other FunctionType attributes (calling conventions, register parameters, etc...).

The solution that I have found is to move the code scanning for DeclSpec attributes from the ConvertDeclSpecToType() function (which is only invoked on non-special functions) to the GetTypeForDeclarator() function (which is invoked for all types of functions).

I have verified that all Clang unit tests pass after my changes.

BTW, what would the appropriate approach for creating a unit test for testing this functionality ?

Benoit


Index: include/clang/Frontend/TypeXML.def
===================================================================
--- include/clang/Frontend/TypeXML.def	(revision 113840)
+++ include/clang/Frontend/TypeXML.def	(working copy)
@@ -130,6 +130,8 @@
   ID_ATTRIBUTE_XML
   ATTRIBUTE_XML(getResultType(), "result_type")
   ATTRIBUTE_OPT_XML(isVariadic(), "variadic")
+  ATTRIBUTE_XML(getRegParmType(), "regparm")
+  ATTRIBUTE_OPT_XML(getNoReturnAttr(), "noreturn")
   ATTRIBUTE_ENUM_XML(getCallConv(), "call_conv")
 	  ENUM_XML(CC_Default, "")
 	  ENUM_XML(CC_C, "C")
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp	(revision 113840)
+++ lib/Sema/SemaType.cpp	(working copy)
@@ -395,11 +395,6 @@
   assert(DS.getTypeSpecComplex() != DeclSpec::TSC_imaginary &&
          "FIXME: imaginary types not supported yet!");
 
-  // See if there are any attributes on the declspec that apply to the type (as
-  // opposed to the decl).
-  if (const AttributeList *AL = DS.getAttributes())
-    ProcessTypeAttributeList(TheSema, Result, true, AL, Delayed);
-
   // Apply const/volatile/restrict qualifiers to T.
   if (unsigned TypeQuals = DS.getTypeQualifiers()) {
 
@@ -994,6 +989,11 @@
     break;
   }
   
+  // See if there are any attributes on the declspec that apply to the type (as
+  // opposed to the decl).
+  if (const AttributeList *AL = D.getDeclSpec().getAttributes())
+    ProcessTypeAttributeList(*this, T, true, AL, FnAttrsFromDeclSpec);
+
   if (T.isNull())
     return Context.getNullTypeSourceInfo();



-------------- next part --------------
A non-text attachment was scrubbed...
Name: PrefixFTAttr.patch
Type: application/octet-stream
Size: 1621 bytes
Desc: PrefixFTAttr.patch
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100915/21e3b5ef/attachment.obj>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ATT00001.txt
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100915/21e3b5ef/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image002.gif
Type: image/gif
Size: 651 bytes
Desc: image002.gif
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100915/21e3b5ef/attachment.gif>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ATT00002.txt
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20100915/21e3b5ef/attachment-0001.txt>


More information about the cfe-commits mailing list