[cfe-dev] Assert in SourceManager::getFileIDSlow()
Chris Lattner
clattner at apple.com
Tue Aug 25 23:32:31 PDT 2009
On Aug 25, 2009, at 12:30 PM, Alexei Svitkine wrote:
> Some more details:
>
> The input being parsed doesn't have to start with a function
> declaration to trigger this assert.
>
> Also, removing the assert in question makes ccons work correctly. Any
> chance this could be fixed?
>
> (If it could also be added to the clang 1.0 branch, that would be
> really appreciated.)
>
> Thanks! (Patch is attached.)
Alexei, I don't follow why this is safe or how you're triggering it.
The SourceManager sets up the "Source Location namespace" very
carefully and "0" is not a valid "offset". 0 is a sentinel that
indicates a default constructed source location. I think you need to
change your client to something like this:
>> clang::SourceLocation Loc = FD->getTypeSpecStartLoc();
>> if (Loc.isValid() && SM->isFromMainFile(Loc)) {
-Chris
>
> -Alexei
>
> On Tue, Aug 25, 2009 at 2:00 PM, Alexei
> Svitkine<alexei.svitkine at gmail.com> wrote:
>> Hi,
>>
>> My code is triggering the assert:
>>
>> assert(SLocOffset && "Invalid FileID");
>>
>> In SourceManager::getFileIDSlow().
>>
>> It happens as a result of calling SM->isFromMainFile(Loc) in some
>> ASTConsumer code that looks like:
>>
>> void HandleTopLevelDecl(clang::DeclGroupRef D) {
>> for (clang::DeclGroupRef::iterator I = D.begin(), E = D.end(); I !
>> = E; ++I) {
>> if (clang::FunctionDecl *FD = dyn_cast<clang::FunctionDecl>(*I)) {
>> clang::SourceLocation Loc = FD->getTypeSpecStartLoc();
>> if (SM->isFromMainFile(Loc)) {
>> // ...
>> }
>> }
>> }
>> }
>>
>> (The input that is being parsed begins with a function declaration.)
>>
>> I am not sure how old this issue is, but it makes ccons unusable
>> (which is quite a shame, since I hoped ccons could work fine with the
>> clang 1.0 release). Any advice would be appreciated.
>>
>> -Alexei
>>
> <sm_assert_fix.diff>_______________________________________________
> 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