[all-commits] [llvm/llvm-project] bf6986: [clang] GCC directive extension extension: Hash NN...

Nathan Sidwell via All-commits all-commits at lists.llvm.org
Tue Nov 9 07:31:42 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bf6986d99eaa68ad850eb335cb3f98fe6406ccd0
      https://github.com/llvm/llvm-project/commit/bf6986d99eaa68ad850eb335cb3f98fe6406ccd0
  Author: Nathan Sidwell <nathan at acm.org>
  Date:   2021-11-09 (Tue, 09 Nov 2021)

  Changed paths:
    M clang/docs/LanguageExtensions.rst
    M clang/lib/Basic/SourceManager.cpp
    M clang/lib/Lex/PPDirectives.cpp
    M clang/test/Preprocessor/line-directive.c

  Log Message:
  -----------
  [clang] GCC directive extension extension: Hash NNN lines

Some time back I extended GCC's '# NNN' line marker semantics.
Specifically popping to a blank filename will restore the filename to
that of the popped-to include.  Restore to line 5 of including file
(escaped BOL #'s to avoid git eliding them):

\# 5 "" 2

Added documentation for this line control extension.

This was useful in developing modules tests, but turned out to also be
useful with machine-generated source code.  Specifically, a generated
include file that itself includes fragments from elsewhere.  The
ability to pop to the generated include file -- with its full path
prefix -- is useful for diagnostic & debug purposes.  For instance
something like:

// Machine generated -- DO NOT EDIT
Type Var = {
\# 7 "encoded.dsl" 1 // push to snippet-container
{snippet, of, code}
\# 6 " 2 // Restore to machined-generated source
,
};

// user-code
...
\#include "dsl.h"
...

That pop to "" will restore the filename to '..includepath../dsl.h',
which is better than restoring to plain "dsl.h".

Differential Revision: https://reviews.llvm.org/D113425




More information about the All-commits mailing list