[clang] [Clang] Report an error and crash on source location exhaustion in macros (PR #69908)

Ilya Biryukov via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 23 05:02:19 PDT 2023


================
@@ -663,10 +663,15 @@ SourceManager::createExpansionLocImpl(const ExpansionInfo &Info,
     return SourceLocation::getMacroLoc(LoadedOffset);
   }
   LocalSLocEntryTable.push_back(SLocEntry::get(NextLocalOffset, Info));
-  // FIXME: Produce a proper diagnostic for this case.
-  assert(NextLocalOffset + Length + 1 > NextLocalOffset &&
-         NextLocalOffset + Length + 1 <= CurrentLoadedOffset &&
-         "Ran out of source locations!");
+  if (NextLocalOffset + Length + 1 <= NextLocalOffset ||
+      NextLocalOffset + Length + 1 > CurrentLoadedOffset) {
+    Diag.Report(Info.getSpellingLoc(), diag::err_expansions_too_large);
+    // FIXME: call `noteSLocAddressSpaceUsage` to report details to users.
----------------
ilya-biryukov wrote:

Another caveat: `Info.getSpellingLoc` can sometimes return one of the expansion locations and this causes the diagnostic printing to run indefinitely too!

So I had to report an error with invalid `SourceLocation()`. The crash stack trace helpfully points at tokens that were being processed, so it does give some context.

https://github.com/llvm/llvm-project/pull/69908


More information about the cfe-commits mailing list