[LLVMbugs] [Bug 24344] New: Objective-C++ to C++ Rewriter produces ill-formed C++11 code

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Aug 3 14:26:16 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24344

            Bug ID: 24344
           Summary: Objective-C++ to C++ Rewriter produces ill-formed
                    C++11 code
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: charles_li at playstation.sony.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Hello Clang developers,

I came across this bug when running Clang lit tests on test/Rewriter folder 
with the default C++ standard dialect set to C++11.
When I ran the test, 32 tests failed. 
The list is appended to the bottom.
It appears that when rewriting Objective-C++ to C++, 
the rewriter will always generate C++03 code, 
even when -std=C++11 mode is requested.

Here is a reduced test case:
/*************************************************/
@interface Foo {
  int a;
}
@end

@implementation Foo
static void foo() {
}
@end
/*************************************************/


Rewriting this test to C++ then Compiling the C++ code produces the following.


$clang -cc1  -x objective-c++  -fms-extensions -rewrite-objc
-fobjc-runtime=macosx-fragile-10.5 t.mm -o t_gen.cpp -std=c++11
$clang -cc1  -Did="void*" -D"SEL=void*" -D"__declspec(X)=" t_gen.cpp -std=c++11

t_gen.cpp:104:5: warning: ISO C++11 does not allow conversion from string
literal to 'char *'
        ,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
           ^
t_gen.cpp:104:10: warning: ISO C++11 does not allow conversion from string
literal to 'char *'
        ,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
                ^
t_gen.cpp:104:15: error: non-constant-expression cannot be narrowed from type
'long long' to 'int' in initializer list
        ,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t_gen.cpp:77:40: note: expanded from macro '__OFFSETOFIVAR__'
#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t_gen.cpp:104:15: note: insert an explicit cast to silence this issue
        ,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     static_cast<int>(                   )
t_gen.cpp:77:40: note: expanded from macro '__OFFSETOFIVAR__'
#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)
                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t_gen.cpp:124:34: warning: ISO C++11 does not allow conversion from string
literal to 'char *'
        (struct _objc_class *)"Foo", 0, "Foo", 0,2, sizeof(struct _objc_class),
0, 0
                                        ^
t_gen.cpp:129:27: warning: ISO C++11 does not allow conversion from string
literal to 'char *'
        &_OBJC_METACLASS_Foo, 0, "Foo", 0,1,sizeof(struct Foo_IMPL), (struct
_objc_ivar_list *)&_OBJC_INSTANCE_VARIABLES_Foo
                                 ^
4 warnings and 1 error generated.


I noticed in the generated C++ file, macro __OFFSETOFIVAR__ returns type “long
long”.
While the value being initialized is “int ivar_offset”.

/*****************************************************************/
#define __OFFSETOFIVAR__(TYPE, MEMBER) ((long long) &((TYPE *)0)->MEMBER)

struct _objc_ivar {
        char *ivar_name;
        char *ivar_type;
        int ivar_offset;
};

static struct {
        int ivar_count;
        struct _objc_ivar ivar_list[1];
} _OBJC_INSTANCE_VARIABLES_Foo __attribute__ ((used, section ("__OBJC,
__instance_vars")))= {
        1
        ,{{"a", "i", __OFFSETOFIVAR__(struct Foo_IMPL, a)}
         }
};
/*****************************************************************/

Narrowing conversion inside an initializer list is unfortunately ill-form in
C++11 per [dcl.init.aggr] and [dcl.init.list].

Here is the full list of Clang Lit failures in the Rewriter folder that fail
due to the same reason.

Failing Tests (32):
    Clang :: Rewriter/modern-write-bf-abi.mm
    Clang :: Rewriter/objc-modern-property-bitfield.m
    Clang :: Rewriter/property-dot-syntax.mm
    Clang :: Rewriter/rewrite-block-literal-1.mm
    Clang :: Rewriter/rewrite-block-pointer.mm
    Clang :: Rewriter/rewrite-byref-in-nested-blocks.mm
    Clang :: Rewriter/rewrite-byref-vars.mm
    Clang :: Rewriter/rewrite-cast-ivar-modern-access.mm
    Clang :: Rewriter/rewrite-elaborated-type.mm
    Clang :: Rewriter/rewrite-foreach-in-block.mm
    Clang :: Rewriter/rewrite-foreach-protocol-id.m
    Clang :: Rewriter/rewrite-forward-class.m
    Clang :: Rewriter/rewrite-forward-class.mm
    Clang :: Rewriter/rewrite-ivar-use.m
    Clang :: Rewriter/rewrite-modern-atautoreleasepool.mm
    Clang :: Rewriter/rewrite-modern-block-ivar-call.mm
    Clang :: Rewriter/rewrite-modern-class.mm
    Clang :: Rewriter/rewrite-modern-default-property-synthesis.mm
    Clang :: Rewriter/rewrite-modern-extern-c-func-decl.mm
    Clang :: Rewriter/rewrite-modern-ivar-use.mm
    Clang :: Rewriter/rewrite-modern-ivars-2.mm
    Clang :: Rewriter/rewrite-modern-ivars.mm
    Clang :: Rewriter/rewrite-modern-nested-ivar.mm
    Clang :: Rewriter/rewrite-modern-throw.m
    Clang :: Rewriter/rewrite-nested-blocks-1.mm
    Clang :: Rewriter/rewrite-nested-blocks.mm
    Clang :: Rewriter/rewrite-nested-ivar.mm
    Clang :: Rewriter/rewrite-property-attributes.mm
    Clang :: Rewriter/rewrite-property-set-cfstring.mm
    Clang :: Rewriter/rewrite-protocol-property.mm
    Clang :: Rewriter/rewrite-user-defined-accessors.mm
    Clang :: Rewriter/rewrite-vararg.m

  Expected Passes    : 112
  Unexpected Failures: 32

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150803/d15fea96/attachment.html>


More information about the llvm-bugs mailing list