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();



Attachment: PrefixFTAttr.patch
Description: PrefixFTAttr.patch

 
 
Benoit Belley
Sr Principal Developer
M&E-Product Development Group    
 
Autodesk Canada Inc. 
10 Rue Duke
Montreal, Quebec  H3C 2L7 
Canada
 
Direct 514 954-7154
 
 

<<attachment: image002.gif>>

 

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to