r219590 - Fixed a problem in r19589.

Richard Smith richard at metafoo.co.uk
Wed Nov 12 13:22:52 PST 2014


On Thu, Oct 23, 2014 at 8:37 PM, Tyler Nowicki <tyler.nowicki at gmail.com>
wrote:

> Hi Richard,
>
> I will make the change you suggested. However, the first code I committed
> worked on my system (MSVS) but not on many others. I don't suppose you
> could suggest a syntax that is more portable?
>

See below.


> Sorry for the delayed response,
>

Likewise.


> Tyler
>
> On Sun, Oct 12, 2014 at 7:51 PM, Richard Smith <richard at metafoo.co.uk>
> wrote:
>
>> On Sun, Oct 12, 2014 at 2:28 PM, Tyler Nowicki <tyler.nowicki at gmail.com>
>> wrote:
>>
>>> Author: tnowicki
>>> Date: Sun Oct 12 16:28:02 2014
>>> New Revision: 219590
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=219590&view=rev
>>> Log:
>>> Fixed a problem in r19589.
>>>
>>> Several systems failed to compile the array allocation of the TokenArray.
>>>
>>> Modified:
>>>     cfe/trunk/lib/Parse/ParsePragma.cpp
>>>
>>> Modified: cfe/trunk/lib/Parse/ParsePragma.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParsePragma.cpp?rev=219590&r1=219589&r2=219590&view=diff
>>>
>>> ==============================================================================
>>> --- cfe/trunk/lib/Parse/ParsePragma.cpp (original)
>>> +++ cfe/trunk/lib/Parse/ParsePragma.cpp Sun Oct 12 16:28:02 2014
>>> @@ -1877,8 +1877,8 @@ static bool ParseLoopHintValue(Preproces
>>>    EOFTok.setLocation(Tok.getLocation());
>>>    ValueList.push_back(EOFTok); // Terminates expression for parsing.
>>>
>>> -  Token *TokenArray =
>>> -      new (PP.getPreprocessorAllocator()) Token[ValueList.size()];
>>> +  Token *TokenArray = (Token *)PP.getPreprocessorAllocator().Allocate(
>>> +      ValueList.size() * sizeof(Token), llvm::alignOf<Token>());
>>>
>>
>> You should placement-new an array of Tokens here, rather than assuming
>> that they don't need construction.
>>
>
Try this:

void *Buffer = PP.getPreprocessorAllocator().Allocate(
    ValueList.size() * sizeof(Token), llvm::alignOf<Token>());
Token *TokenArray = new (Buffer) Token[ValueList.size()];

(It looks like compilers were rejecting the old code because we only have a
normal placement new and not an array placement new for BumpPtrAllocator.
Another possible fix would be to add such a placement operator new[] and
revert this change.)

   std::copy(ValueList.begin(), ValueList.end(), TokenArray);
>>>    Info.Toks = TokenArray;
>>>    Info.TokSize = ValueList.size();
>>>
>>>
>>> _______________________________________________
>>> cfe-commits mailing list
>>> cfe-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20141112/ad3c0911/attachment.html>


More information about the cfe-commits mailing list