[cfe-commits] r108019 - in /cfe/trunk: lib/Sema/TreeTransform.h test/CodeGenCXX/instantiate-blocks.cpp test/SemaCXX/instantiate-blocks.cpp

Douglas Gregor dgregor at apple.com
Sat Jul 10 16:45:17 PDT 2010



Sent from my iPhone

On Jul 10, 2010, at 10:50 AM, Fariborz Jahanian <fjahanian at apple.com> wrote:

> 
> On Jul 9, 2010, at 7:03 PM, Douglas Gregor wrote:
> 
>> 
>> 
>> Sent from my iPhone
>> 
>> On Jul 9, 2010, at 2:27 PM, Fariborz Jahanian <fjahanian at apple.com> wrote:
>> 
>>> Author: fjahanian
>>> Date: Fri Jul  9 16:27:28 2010
>>> New Revision: 108019
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=108019&view=rev
>>> Log:
>>> Instantiation of byref variable in
>>> block literal expression.
>>> 
>>> Added:
>>>  cfe/trunk/test/SemaCXX/instantiate-blocks.cpp
>>> Modified:
>>>  cfe/trunk/lib/Sema/TreeTransform.h
>>>  cfe/trunk/test/CodeGenCXX/instantiate-blocks.cpp
>>> 
>>> Modified: cfe/trunk/lib/Sema/TreeTransform.h
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/TreeTransform.h?rev=108019&r1=108018&r2=108019&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/lib/Sema/TreeTransform.h (original)
>>> +++ cfe/trunk/lib/Sema/TreeTransform.h Fri Jul  9 16:27:28 2010
>>> @@ -6279,6 +6279,10 @@
>>> if (!ND)
>>>   return SemaRef.ExprError();
>>> 
>>> +  // Is this instantiation of a __block variable?
>>> +  if (E->getDecl()->getAttr<BlocksAttr>())
>>> +    ND->addAttr(::new (SemaRef.Context) BlocksAttr(BlocksAttr::ByRef));
>>> +
>> 
>> It seems like this attribute should have been copied to the instantiated declaration when the VarDecl itself was created. Is that not the case?
> 
> Unlike our expectation it wasn't doing that. AFAIK, no other attributes are moved over either. But I will
> look further.

Sounds like a bug in that instantiation code, then. 
> 
> - Fariborz
> 
>> 
>> - Doug
>> 
>>> if (!getDerived().AlwaysRebuild() &&
>>>     ND == E->getDecl()) {
>>>   // Mark it referenced in the new context regardless.
>>> 
>>> Modified: cfe/trunk/test/CodeGenCXX/instantiate-blocks.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/instantiate-blocks.cpp?rev=108019&r1=108018&r2=108019&view=diff
>>> ==============================================================================
>>> --- cfe/trunk/test/CodeGenCXX/instantiate-blocks.cpp (original)
>>> +++ cfe/trunk/test/CodeGenCXX/instantiate-blocks.cpp Fri Jul  9 16:27:28 2010
>>> @@ -18,7 +18,11 @@
>>> template <typename T, typename T1> void foo(T t, T1 r)
>>> {
>>>   T block_arg;
>>> -    T1 (^block)(char, T, T1, double) =  ^ T1 (char ch, T arg, T1 arg2, double d1) { return block_arg+arg; };
>>> +    __block T1 byref_block_arg;
>>> +
>>> +    T1 (^block)(char, T, T1, double) =
>>> +    ^ T1 (char ch, T arg, T1 arg2, double d1) { byref_block_arg = arg2;
>>> +                                   return byref_block_arg + arg; };
>>> 
>>>   void (^block2)() = ^{};
>>> }
>>> 
>>> Added: cfe/trunk/test/SemaCXX/instantiate-blocks.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/instantiate-blocks.cpp?rev=108019&view=auto
>>> ==============================================================================
>>> --- cfe/trunk/test/SemaCXX/instantiate-blocks.cpp (added)
>>> +++ cfe/trunk/test/SemaCXX/instantiate-blocks.cpp Fri Jul  9 16:27:28 2010
>>> @@ -0,0 +1,19 @@
>>> +// RUN: %clang_cc1 -fblocks -fsyntax-only -verify %s
>>> +// rdar: // 6182276
>>> +
>>> +template <typename T, typename T1> void foo(T t, T1 r)
>>> +{
>>> +    T block_arg;
>>> +    __block T1 byref_block_arg;
>>> +
>>> +    T1 (^block)(T)  =  ^ T1 (T arg) {
>>> +         byref_block_arg = arg;
>>> +         block_arg = arg;    // expected-error {{variable is not assignable (missing __block type specifier)}}
>>> +         return block_arg+arg; };
>>> +}
>>> +
>>> +int main(void)
>>> +{
>>> +    foo(100, 'a');    // expected-note {{in instantiation of function template specialization 'foo<int, char>' requested here}}
>>> +}
>>> +
>>> 
>>> 
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> 



More information about the cfe-commits mailing list