[cfe-dev] Assert in SourceManager::getFileIDSlow()

Alexei Svitkine alexei.svitkine at gmail.com
Tue Aug 25 12:30:47 PDT 2009


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

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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sm_assert_fix.diff
Type: application/octet-stream
Size: 626 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20090825/36a5333c/attachment.obj>


More information about the cfe-dev mailing list