[cfe-dev] Define new pragma in Clang

Daniel Dunbar daniel at zuster.org
Thu Jan 21 10:45:50 CST 2010


Hi Alexandra,

Its hard for me to know the problem without seeing the patch/crash. It
looks like clang is crashing when it tries to index into a SmallVector
out-of-bounds. I suggest you run clang in a debugger and see what code
is doing this, which will probably give a clue as to the problem.

 - Daniel

On Thu, Jan 21, 2010 at 1:11 AM, Alexandra <xinfinity_a at yahoo.com> wrote:
>
>> Generally you would need to do something like:
>>  1. Add a pragma handler, which has a callback on the actions interface.
>>  2. Add a sema implementation of the callback, which sets some
>> internal bit in the Sema object.
>>  3. Add a new bit to the 'for' statement, to specify whether this it
>> had #pragma optimize set.
>>  4. Modify codegin to emit the metadata based on that bit.
>>
>>  - Daniel
>>
>> > Thank you.
>> >
>> >
>> > _______________________________________________
>> > cfe-dev mailing list
>> > cfe-dev at ...
>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>> >
>>
>
>
> Thank you, your hints were very helpful. Still I encountered one more problem
> regarding pragmas. I have added two pragmas that work very well, if I add one at
> a time in my source code that I use to test clang. Nevertheless, the compiler
> crashes if I insert both pragmas in the test source code.
> What I have done is:
> 1 install a fresh copy of llvm + clang
> 2 modify clang to understand pragma 1 and pragma 2
> 3 write a test.cpp without any pragma => clang works fine
> 4 write a test1.cpp containing pragma 1 => clang works fine
> 5 write a test2.cpp containing pragma 2 => clang works fine
> 6 write a test12.cpp containing pragma 1 and pragma 2 => clang crashes
>
> It understands correctly the pragma and creates the AST, but crashes with:
>
> clang-cc: /llvm/ADT/SmallVector.h:124: T&
> llvm::SmallVectorImpl<T>::operator[](unsigned int) [with T = std::pair<unsigned
> int, llvm::TrackingVH<llvm::MDNode> >]: Assertion `Begin + idx < End' failed.
>
> 0.      Program arguments: clang-cc inputCode.cpp -emit-llvm
> 1.      <eof> parser at end of file
> 2.      Per-module optimization passes
> 3.      Running pass 'Print module to stderr' on module 'inputCode.cpp'.
> Aborted (core dumped)
>
> However, I do not modify the passes at all and the AST seems to be correctly
> created, since when test1.cpp and test2.cpp are compiled, it works.
>
> Any idea would be appreciated. My guess is that there is a problem with the AST,
> since printing the module causes a crash. But still, the other passes run before
> were successful and additionally, it doesn't crash when only one pragma is added.
>
> Thank you,
> Alexandra
>
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list