https://bugs.llvm.org/show_bug.cgi?id=44480

            Bug ID: 44480
           Summary: __FILE__ is modified whenever "#include __FILE__" is
                    encountered
           Product: clang
           Version: 9.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected],
                    [email protected]

Created attachment 22994
  --> https://bugs.llvm.org/attachment.cgi?id=22994&action=edit
Demonstration of how __FILE__ is modified

Clang's preprocessor appears to prepend "./" to __FILE__ every time it
encounters "#include __FILE__" in a source code.  This can be observed by how 3
different strings are printed for this code:

  #ifndef INCLUDE_GUARD
  #define INCLUDE_GUARD
  #include <stdio.h>
  int main(int argc, char **argv)
  {
      puts(__FILE__);
      #include __FILE__
      puts(__FILE__);
      #include __FILE__
      puts(__FILE__);
      return 0;
  }
  #endif

https://gcc.godbolt.org/z/JTx2Np

If a piece of code manages to #include itself a finite but large number of
times, "#include __FILE__" will eventually fail because __FILE__ contains a
string longer than what's supported by the local file system.

The preprocessor should just keep __FILE__ constant.  Clang 3.5.1 and earlier
and all versions of GCC has the expected behavior, Clang 3.6 and later appears
to modify __FILE__.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to