[cfe-dev] Bug in SourceManager::isInTheSameTranslationUnit ?

Gábor Márton via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 14 07:51:13 PDT 2018


In some cases it is possible that one sourceLocation has a file with
relative path and the other sourceLocation has the same file but with
absolute path. In these cases we fail to recognize that the
sourceLocations are for the same TU.

E.g.:
```
(gdb) p LB
$2 = {static npos = 18446744073709551615,
  Data = 0x6a70b8
"./sources-root/local/scratch/repos/ML66/ml66_nps/nps/bns_app_src/platform/eqm/lich/src/Alarm.cc",
Length = 95}
(gdb) p RB
$3 = {static npos = 18446744073709551615,
  Data = 0x2429dc8
"/home/egbomrt/WORK/DebugCrashes/CodeChecker_log/reports/bns__2017_11_16__15_34_00/failed/Alarm.cc_7817343c04f25df6faf81ba12c6298da/sources-root/local/scratch/repos/ML66/ml66_nps/nps/bns_app_src/platfo"...,
  Length = 224}
(gdb) p InSameTU
$4 = {first = false, second = false}
```

The side effect of this bug is that we can't dump some of the
declarations because in `SourceManager::isBeforeInTranslationUnit` we
reach an unreachable point. This is really frustrating during
debugging:
```
(gdb) p ((RecordDecl*)ToDC)->dump()
ClassTemplatePartialSpecializationDecl 0x1f1f650
</home/egbomrt/WORK/DebugCrashes/CodeChecker_log/reports/bns__2017_11_16__15_34_00/failed/Alarm.cc_7817343c04f25df6faf81ba12c6298da/sources-root/proj/tn/build/toolchain/e5500/R1A03/montavista/tools/powerpc64-gnu/powerpc64-montavista-linux-gnu/include/c++/4.7.0/tuple:50:3,
line:51:12> col:12 struct __add_c_ref
|-TemplateArgument type 'type-parameter-0-0 &'Unsortable locations found
UNREACHABLE executed at
../../git/llvm/tools/clang/lib/Basic/SourceManager.cpp:2057!

Program received signal SIGABRT, Aborted.
```

One quickfix is this:
```
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -2061,6 +2061,7 @@ bool
SourceManager::isBeforeInTranslationUnit(SourceLocation LHS,
       return LIsScratch;
     return LOffs.second < ROffs.second;
   }
+  return LB < RB;
   llvm_unreachable("Unsortable locations found");
 }
```

This is of course not the real solution.

Would it be possible to make both paths absolute in
isBeforeInTranslationUnit? Or it just would add other difficulties?

Thanks,
Gabor



More information about the cfe-dev mailing list