[PATCH] D152570: [clang] Apply -fmacro-prefix-map to anonymous tags in template arguments

2023-06-15 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 531931.
dankm added a comment.

Update release notes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp
  clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp


Index: clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple 
-fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:[[#@LINE-1]]:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -511,6 +511,8 @@
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
   (`#50244 _`).
+- Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at ./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:[[#@LINE-1]]:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -511,6 +511,8 @@
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
   (`#50244 _`).
+- Apply ``-fmacro-prefix-map`` to anonymous tags in template arguments
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Apply -fmacro-prefix-map to anonymous tags in template arguments

2023-06-15 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

Thanks, I'll update the release notes & description right away.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Apply -fmacro-prefix-map to anonymous tags in template arguments

2023-06-13 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

@MaskRay if this meets your approval, are you able to commit it for me?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix filename remapping in template arguments

2023-06-12 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

Maybe for the description something like:

  Apply -fmacro-prefix-map to anonymous tags in template arguments

Do I need to mention TypePrinter?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix filename remapping in template arguments

2023-06-12 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 530763.
dankm added a comment.

Renamed & cleaned up unit tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp
  clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp


Index: clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple 
-fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:[[#@LINE-1]]:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -497,6 +497,8 @@
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
   (`#50244 _`).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/macro-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple %itanium_abi_triple -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at ./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:[[#@LINE-1]]:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -497,6 +497,8 @@
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
   (`#50244 _`).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix filename remapping in template arguments

2023-06-12 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

Avoiding "Fix" in the description is a good suggestion. Whether it's a bugfix 
or not is a matter of perspective, and what's really happening here is I'm 
adjusting compliant implementation defined behavior, not really fixing it.




Comment at: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp:1
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd 
-fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+

MaskRay wrote:
> You can use `-triple x86_64` to test generic ELF behavior, if you don't want 
> to write `linux-gnu` :)
> 
> For this test, perhaps `-triple %itanium_abi_triple` is better (coverage for 
> non-x86 targets).
Generic ELF (or rather Itanium ABI) is probably fine, I just found Windows 
didn't work, so used the platform I was testing on. But I like the itanium abi 
triple suggestion.



Comment at: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp:2
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd 
-fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template

MaskRay wrote:
> For the new test file, I was thinking of 
> https://maskray.me/blog/2021-08-08-toolchain-testing#the-test-checks-at-the-wrong-layer#i-dont-know-an-existing-test-can-be-enhanced.
> 
> The main C++ test `CodeGenCXX/predefined-expr.cpp` does not say about 
> `__PRETTY_FUNCTION__` in its filename, so a new file seems fine.
> 
> If we are going to retain this new test, I think `macro-prefix-map-` is a 
> better prefix. 
> `-fmacro-prefix-map=` is more specific to `-ffile-prefix-map=`.
Yes, I was just quickly thinking of a new filename; macro-prefix-map makes more 
sense to me too. I'll rename the file.



Comment at: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp:11
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+

MaskRay wrote:
> 10 should be replaced with `[[#@LINE-1]]` so that adding more tests will not 
> easily make this stale.
Thanks, I was looking for how to do that. Not too familiar with filecheck and 
lit.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix filename remapping in template arguments

2023-06-12 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 530638.
dankm added a comment.

Fix unit tests on windows


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp
  clang/test/CodeGenCXX/file-prefix-map-lambda.cpp


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd 
-fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -497,6 +497,8 @@
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
   (`#50244 _`).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-freebsd -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at ./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -497,6 +497,8 @@
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
   (`#50244 _`).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix filename remapping in template arguments

2023-06-12 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 530563.
dankm added a comment.

Rebase and hopefully fix builds.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp
  clang/test/CodeGenCXX/file-prefix-map-lambda.cpp


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s 
-emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -497,6 +497,8 @@
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
   (`#50244 _`).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at ./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -497,6 +497,8 @@
 - CallExpr built for C error-recovery now is always type-dependent. Fixes a
   crash when we encounter a unresolved TypoExpr during diagnostic emission.
   (`#50244 _`).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix file mapping template arguments

2023-06-09 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 530070.
dankm added a comment.

Fix typo in release notes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp
  clang/test/CodeGenCXX/file-prefix-map-lambda.cpp


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s 
-emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at ./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments not respecting ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix file mapping template arguments

2023-06-09 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 530069.
dankm added a comment.

Added unit test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp
  clang/test/CodeGenCXX/file-prefix-map-lambda.cpp


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s 
-emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private 
unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/file-prefix-map-lambda.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fmacro-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+template
+auto lambdatest(f&& cb) {
+  const char *s = __PRETTY_FUNCTION__;
+  return s;
+}
+
+int main() {
+  auto *s = lambdatest([](){});
+// CHECK: @"__PRETTY_FUNCTION__._Z10lambdatestIZ4mainE3$_0EDaOT_" = private unnamed_addr constant [{{[0-9]+}} x i8] c"auto lambdatest(f &&) [f = (lambda at ./UNLIKELY_PATH/empty{{/|}}{{.*}}.cpp:10:24)]\00", align 1
+
+  return 0;
+}
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(LO) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix file mapping template arguments

2023-06-09 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/lib/AST/Expr.cpp:791
+public:
+  PrettyCallbacks(const LangOptions ) : LO(L) {}
+  std::string remapPath(StringRef Path) const override {

shafik wrote:
> This may not be a well known idiom but is widely used within llvm.
Makes sense, I was going for unambiguity between the class's member name and 
the constructor argument name, but if it's widely used that's fine. I'll add 
that change when I add unit tests.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152570/new/

https://reviews.llvm.org/D152570

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152570: [clang] Fix file mapping template arguments

2023-06-09 Thread Dan McGregor via Phabricator via cfe-commits
dankm created this revision.
Herald added a project: All.
dankm added a comment.
dankm updated this revision to Diff 530046.
dankm published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I still need to make a unit test for this. Should be more-or-less a cleaned up 
version of the testcase in https://github.com/llvm/llvm-project/issues/63219.


dankm added a comment.

Add release notes.


dankm added a comment.

Despite needing unit tests, I'd like some eyes on this change.


When expanding template arguments for pretty function printing,
such as for __PRETTY_FUNCTION__, apply macro-prefix-map remapping
for lambda names.

Fixes https://github.com/llvm/llvm-project/issues/63219


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152570

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Expr.cpp


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(L) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -786,7 +786,21 @@
 Out << "static ";
 }
 
+class PrettyCallbacks final : public PrintingCallbacks {
+public:
+  PrettyCallbacks(const LangOptions ) : LO(L) {}
+  std::string remapPath(StringRef Path) const override {
+SmallString<128> p(Path);
+LO.remapPathPrefix(p);
+return std::string(p);
+  }
+
+private:
+  const LangOptions 
+};
 PrintingPolicy Policy(Context.getLangOpts());
+PrettyCallbacks PrettyCB(Context.getLangOpts());
+Policy.Callbacks = 
 std::string Proto;
 llvm::raw_string_ostream POut(Proto);
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -492,6 +492,8 @@
   (`See patch `_).
 - Fix crash when passing a value larger then 64 bits to the aligned attribute.
   (`#50534 `_).
+- Fix lambdas in template arguments ``-fmacro-prefix-map``
+  (`#63219 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-28 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D149272#4306103 , @aaron.ballman 
wrote:

> LGTM, but please add a release note when landing.

Thanks, I do not have permission to land, are you able to?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-28 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 518050.
dankm added a comment.

Rebase & add add release note.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclarationName.cpp
  clang/test/CodeGen/debug-prefix-map.cpp


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const 
{
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix lambdas and other anonymous function names not respecting 
``-fdebug-prefix-map``
+  (`#62192 `_)
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at ./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const {
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -338,6 +338,8 @@
 - Fix crash when attempting to perform parenthesized initialization of an
   aggregate with a base class with only non-public constructors.
   (`#62296 `_)
+- Fix lambdas and other anonymous function names not respecting ``-fdebug-prefix-map``
+  (`#62192 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149193: [Driver] Add -dumpdir and change -gsplit-dwarf .dwo names for linking

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

I certainly like the idea. I'll spend some time later looking at the 
implementation, but from a quick glance it looks good.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149193/new/

https://reviews.llvm.org/D149193

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148975: -fdebug-prefix-map=: make the last win when multiple prefixes match

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D148975#4296895 , @MaskRay wrote:

> Thank you! I feel that specifying multiple `-fdebug-prefix-map=` is a very 
> uncommon situation, so a release note entry is likely overkill.
> I updated the HelpText, though.

The Yocto project and my WIP changes against FreeBSD both specify multiple 
`-fdebug-prefix-map=` options, but neither depend on the longest-match first 
semantics. They did at one point, but GCC behaved differently.

So, I suppose this LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148975/new/

https://reviews.llvm.org/D148975

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 517595.
dankm added a comment.

Correct test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

Files:
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclarationName.cpp
  clang/test/CodeGen/debug-prefix-map.cpp


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone 
-fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const 
{
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S %s -emit-llvm -o - | FileCheck %s
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK: !DISubprogram(name: "(unnamed struct at ./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const {
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:1
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+

dankm wrote:
> aaron.ballman wrote:
> > I'm taking a guess at correcting the RUN line here, but more tweaks may be 
> > needed. Basically, `%clang++` isn't a thing, so this test fails. Most of 
> > our tests should be testing `%clang_cc1` to test the frontend invocation, 
> > but some of the debug prefix map tests use `%clang` to test the driver 
> > functionality. I don't think there's a need to test the driver here, so I 
> > went with `%clang_cc1`. I'm not 100% certain whether `-debug-info-kind=` is 
> > necessary or not, but the other tests seem to be using that, which may be 
> > worth paying attention to.
> > 
> > Finally, there's no need to have a custom check prefix for `FileCheck`, the 
> > builtin `CHECK` prefix suffices.
> Okay, noted about clang++, it did work for me locally, but that doesn't mean 
> it's correct. Good point about only testing the frontend action, the driver 
> test is unnecessary.
> 
> The custom check prefix is just a cut & paste artefact from copying from the 
> C version of the debug-prefix-map test, originally I was going to update that 
> test to a C++ file but opted later for just creating a new test.
Ah, I see now it failed on the windows build in my test. Neat.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-27 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/test/CodeGen/debug-prefix-map.cpp:1
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+

aaron.ballman wrote:
> I'm taking a guess at correcting the RUN line here, but more tweaks may be 
> needed. Basically, `%clang++` isn't a thing, so this test fails. Most of our 
> tests should be testing `%clang_cc1` to test the frontend invocation, but 
> some of the debug prefix map tests use `%clang` to test the driver 
> functionality. I don't think there's a need to test the driver here, so I 
> went with `%clang_cc1`. I'm not 100% certain whether `-debug-info-kind=` is 
> necessary or not, but the other tests seem to be using that, which may be 
> worth paying attention to.
> 
> Finally, there's no need to have a custom check prefix for `FileCheck`, the 
> builtin `CHECK` prefix suffices.
Okay, noted about clang++, it did work for me locally, but that doesn't mean 
it's correct. Good point about only testing the frontend action, the driver 
test is unnecessary.

The custom check prefix is just a cut & paste artefact from copying from the C 
version of the debug-prefix-map test, originally I was going to update that 
test to a C++ file but opted later for just creating a new test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D149272#4301103 , @raj.khem wrote:

> This would fix https://github.com/llvm/llvm-project/issues/62192

Thanks. I didn't know that was created.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 517427.
dankm added a comment.

And restore original change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

Files:
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclarationName.cpp
  clang/test/CodeGen/debug-prefix-map.cpp


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK-REL: !DISubprogram(name: "(unnamed struct at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const 
{
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK-REL: !DISubprogram(name: "(unnamed struct at ./UNLIKELY_PATH/empty{{/|}}{{.*}}",
Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const {
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 517426.
dankm added a comment.

Add test case


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

Files:
  clang/test/CodeGen/debug-prefix-map.cpp


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s 
-emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK-REL: !DISubprogram(name: "(unnamed struct at 
./UNLIKELY_PATH/empty{{/|}}{{.*}}",


Index: clang/test/CodeGen/debug-prefix-map.cpp
===
--- /dev/null
+++ clang/test/CodeGen/debug-prefix-map.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang++ -g -fdebug-prefix-map=%p=./UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-REL
+
+struct alignas(64) an {
+  struct {
+unsigned char x{0};
+  } arr[64];
+};
+
+struct an *pan = new an;
+
+// CHECK-REL: !DISubprogram(name: "(unnamed struct at ./UNLIKELY_PATH/empty{{/|}}{{.*}}",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

Hoorat for me. I just managed to produce a reduced test case. That'll be added 
to the review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/lib/AST/DeclarationName.cpp:119-125
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
+  InjTy->getDecl()->printName(OS, Policy);

aaron.ballman wrote:
> This isn't the right way to go about this -- the diagnostic engine knows how 
> to print a `NamedDecl` when given one, and that's what should be fixed. (We 
> pass in a `NamedDecl` all over the place -- it's preferred to passing in a 
> string.)
> 
> https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/AST/ASTDiagnostic.cpp#L460
>  is one place where that happens, and 
> https://github.com/llvm/llvm-project/blob/b893368fd4fdf40b7778df8d0b17312def1a8156/clang/lib/Basic/Diagnostic.cpp#L1060
>  is another, so I'd start investigating from there.
Maybe I could have been more clear in my description of the problem; it's not 
diagnostics. It's naming in the output. With -ffile-prefix-map in use and 
without this change I see this:

```
% strings lib/x86_64-dankm-freebsd13.2/libc++.so.1.0|grep barrier.cpp
std::__1::__barrier_algorithm_base::__state_t::(unnamed struct at 
/home/dan/llvm/llvm-wip/libcxx/src/barrier.cpp:24:9)
```

when I expect (and get with this change):

```
% strings lib/x86_64-dankm-freebsd13.2/libc++.so.1.0|grep barrier.cpp
std::__1::__barrier_algorithm_base::__state_t::(unnamed struct at 
/llvm-root/libcxx/src/barrier.cpp:24:9)
```

It looks like every other call in the DeclarationName::print function preserves 
the policy, these weren't. As far as I can tell, this is the only place this is 
used.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

This fixes and issue I wasn't able to reduce. Some lambdas wound up with the 
real filename in their name, rather than the remapped path from 
-ffile-prefix-map.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149272/new/

https://reviews.llvm.org/D149272

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149272: [clang] Call printName to get name of Decl

2023-04-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm created this revision.
dankm added a reviewer: MaskRay.
Herald added a project: All.
dankm requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Rather than sending a name directly to the stream, use printName
to preserve any PrintingPolicy. This ensures that names are properly
affected by path remapping.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149272

Files:
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclarationName.cpp


Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const 
{
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {


Index: clang/lib/AST/DeclarationName.cpp
===
--- clang/lib/AST/DeclarationName.cpp
+++ clang/lib/AST/DeclarationName.cpp
@@ -117,12 +117,12 @@
   Policy.adjustForCPlusPlus();
 
   if (const RecordType *ClassRec = ClassType->getAs()) {
-OS << *ClassRec->getDecl();
+ClassRec->getDecl()->printName(OS, Policy);
 return;
   }
   if (Policy.SuppressTemplateArgsInCXXConstructors) {
 if (auto *InjTy = ClassType->getAs()) {
-  OS << *InjTy->getDecl();
+  InjTy->getDecl()->printName(OS, Policy);
   return;
 }
   }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -1635,8 +1635,8 @@
   llvm_unreachable("unknown module kind");
 }
 
-void NamedDecl::printName(raw_ostream , const PrintingPolicy&) const {
-  OS << Name;
+void NamedDecl::printName(raw_ostream , const PrintingPolicy ) const {
+  Name.print(OS, Policy);
 }
 
 void NamedDecl::printName(raw_ostream ) const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136554: Implement CWG2631

2022-12-12 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:9688
+}
+return llvm::None;
+  }

llvm::None has been deprecated in favour of std::nullopt.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D136554/new/

https://reviews.llvm.org/D136554

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135284: [Driver] allow target override containing . in executable name

2022-10-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

Thanks! Since I don't have privileges to push, can you do that on my behalf?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135284/new/

https://reviews.llvm.org/D135284

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135284: [Driver] select alternative target containing . in executable name

2022-10-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D135284#3886471 , @MaskRay wrote:

> In D135284#3886469 , @dankm wrote:
>
>> Thanks for the feedback. I've added a testcase for this, I'll push that 
>> change and update the summary.
>
> Did you upload a new patch to the differential? I cannot see it.

I hadn't. I posted that comment and then pushed a new patch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135284/new/

https://reviews.llvm.org/D135284

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135284: [Driver] select alternative target containing . in executable name

2022-10-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 470918.
dankm added a comment.

Added a simple testcase, and updated commit message.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135284/new/

https://reviews.llvm.org/D135284

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/target-override.c


Index: clang/test/Driver/target-override.c
===
--- clang/test/Driver/target-override.c
+++ clang/test/Driver/target-override.c
@@ -3,6 +3,7 @@
 
 // RUN: rm -rf %t && mkdir %t
 // RUN: ln -s %clang %t/i386-clang
+// RUN: ln -s %clang %t/x86_64-pc-freebsd13.1-clang
 
 // Check if invocation of "foo-clang" adds option "-target foo".
 //
@@ -13,3 +14,8 @@
 //
 // RUN: %t/i386-clang -c --target=x86_64 -### %s 2>&1 | FileCheck 
-check-prefix CHECK-TG2 %s
 // CHECK-TG2: Target: x86_64
+
+// Check if invocation of "arch-vendor-osX.Y-clang" adds option "-target 
arch-vendor-osX.Y".
+//
+// RUN: %t/x86_64-pc-freebsd13.1-clang -c -### %s 2>&1 | FileCheck 
-check-prefix CHECK-TG3 %s
+// CHECK-TG3: Target: x86_64-pc-freebsd13.1
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -198,7 +198,7 @@
 /// Normalize the program name from argv[0] by stripping the file extension if
 /// present and lower-casing the string on Windows.
 static std::string normalizeProgramName(llvm::StringRef Argv0) {
-  std::string ProgName = std::string(llvm::sys::path::stem(Argv0));
+  std::string ProgName = std::string(llvm::sys::path::filename(Argv0));
   if (is_style_windows(llvm::sys::path::Style::native)) {
 // Transform to lowercase for case insensitive file systems.
 std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
@@ -217,6 +217,13 @@
   // added via -target as implicit first argument.
   const DriverSuffix *DS = FindDriverSuffix(ProgName, Pos);
 
+  if (!DS && ProgName.endswith(".exe")) {
+// Try again after stripping the executable suffix:
+// clang++.exe -> clang++
+ProgName = ProgName.drop_back(StringRef(".exe").size());
+DS = FindDriverSuffix(ProgName, Pos);
+  }
+
   if (!DS) {
 // Try again after stripping any trailing version number:
 // clang++3.5 -> clang++


Index: clang/test/Driver/target-override.c
===
--- clang/test/Driver/target-override.c
+++ clang/test/Driver/target-override.c
@@ -3,6 +3,7 @@
 
 // RUN: rm -rf %t && mkdir %t
 // RUN: ln -s %clang %t/i386-clang
+// RUN: ln -s %clang %t/x86_64-pc-freebsd13.1-clang
 
 // Check if invocation of "foo-clang" adds option "-target foo".
 //
@@ -13,3 +14,8 @@
 //
 // RUN: %t/i386-clang -c --target=x86_64 -### %s 2>&1 | FileCheck -check-prefix CHECK-TG2 %s
 // CHECK-TG2: Target: x86_64
+
+// Check if invocation of "arch-vendor-osX.Y-clang" adds option "-target arch-vendor-osX.Y".
+//
+// RUN: %t/x86_64-pc-freebsd13.1-clang -c -### %s 2>&1 | FileCheck -check-prefix CHECK-TG3 %s
+// CHECK-TG3: Target: x86_64-pc-freebsd13.1
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -198,7 +198,7 @@
 /// Normalize the program name from argv[0] by stripping the file extension if
 /// present and lower-casing the string on Windows.
 static std::string normalizeProgramName(llvm::StringRef Argv0) {
-  std::string ProgName = std::string(llvm::sys::path::stem(Argv0));
+  std::string ProgName = std::string(llvm::sys::path::filename(Argv0));
   if (is_style_windows(llvm::sys::path::Style::native)) {
 // Transform to lowercase for case insensitive file systems.
 std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
@@ -217,6 +217,13 @@
   // added via -target as implicit first argument.
   const DriverSuffix *DS = FindDriverSuffix(ProgName, Pos);
 
+  if (!DS && ProgName.endswith(".exe")) {
+// Try again after stripping the executable suffix:
+// clang++.exe -> clang++
+ProgName = ProgName.drop_back(StringRef(".exe").size());
+DS = FindDriverSuffix(ProgName, Pos);
+  }
+
   if (!DS) {
 // Try again after stripping any trailing version number:
 // clang++3.5 -> clang++
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135284: [Driver] select alternative target containing . in executable name

2022-10-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

Thanks for the feedback. I've added a testcase for this, I'll push that change 
and update the summary.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D135284/new/

https://reviews.llvm.org/D135284

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135284: RFC: [Driver] select alternative target containing . in executable name

2022-10-05 Thread Dan McGregor via Phabricator via cfe-commits
dankm created this revision.
Herald added subscribers: pengfei, krytarowski, arichardson, emaste.
Herald added a project: All.
dankm added reviewers: echristo, zarko.
dankm added a comment.
dankm published this revision for review.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

I'd like comments on this approach to handle target names with a . in them. My 
assumption is that the way it was done (by finding the filename stem) was to 
strip any ".exe" string on Windows, but there may be other reasons.


The gcc compatible driver has support for selecting an alternative
target based on the driver's executable name, for instance
x86_64-unknown-linux-gnu-clang will set the target to linux on x86_64.

Previously, this failed when the target contains a minor version, for
example x86_64-unknown-freebsd13.1, so instead of finding the file's
stem, use the whole file name, but strip off any '.exe' from the tail.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135284

Files:
  clang/lib/Driver/ToolChain.cpp


Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -198,7 +198,7 @@
 /// Normalize the program name from argv[0] by stripping the file extension if
 /// present and lower-casing the string on Windows.
 static std::string normalizeProgramName(llvm::StringRef Argv0) {
-  std::string ProgName = std::string(llvm::sys::path::stem(Argv0));
+  std::string ProgName = std::string(llvm::sys::path::filename(Argv0));
   if (is_style_windows(llvm::sys::path::Style::native)) {
 // Transform to lowercase for case insensitive file systems.
 std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
@@ -217,6 +217,13 @@
   // added via -target as implicit first argument.
   const DriverSuffix *DS = FindDriverSuffix(ProgName, Pos);
 
+  if (!DS && ProgName.endswith(".exe")) {
+// Try again after stripping the executable suffix:
+// clang++.exe -> clang++
+ProgName = ProgName.drop_back(StringRef(".exe").size());
+DS = FindDriverSuffix(ProgName, Pos);
+  }
+
   if (!DS) {
 // Try again after stripping any trailing version number:
 // clang++3.5 -> clang++


Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -198,7 +198,7 @@
 /// Normalize the program name from argv[0] by stripping the file extension if
 /// present and lower-casing the string on Windows.
 static std::string normalizeProgramName(llvm::StringRef Argv0) {
-  std::string ProgName = std::string(llvm::sys::path::stem(Argv0));
+  std::string ProgName = std::string(llvm::sys::path::filename(Argv0));
   if (is_style_windows(llvm::sys::path::Style::native)) {
 // Transform to lowercase for case insensitive file systems.
 std::transform(ProgName.begin(), ProgName.end(), ProgName.begin(),
@@ -217,6 +217,13 @@
   // added via -target as implicit first argument.
   const DriverSuffix *DS = FindDriverSuffix(ProgName, Pos);
 
+  if (!DS && ProgName.endswith(".exe")) {
+// Try again after stripping the executable suffix:
+// clang++.exe -> clang++
+ProgName = ProgName.drop_back(StringRef(".exe").size());
+DS = FindDriverSuffix(ProgName, Pos);
+  }
+
   if (!DS) {
 // Try again after stripping any trailing version number:
 // clang++3.5 -> clang++
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-11-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D49466#1760860 , @MaskRay wrote:

> Add back remapDIPath that was unintentionally deleted by D69213 
> , caught by a test.
>
> Small adjustment of the code


Right. Can't believe I missed that. Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-11-26 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

Ping?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-11-18 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D49466#1681534 , @phosek wrote:

> @dankm is it OK if we take over this change to push it forward?


At this point sure. Unless it's accepted as-is now, then I don't have a commit 
bit to finish it off.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-11-18 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 229837.
dankm added a comment.

- Address feedback from @Lekensteyn


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/CodeGen/debug-prefix-map.c
  clang/test/Driver/debug-prefix-map.S
  clang/test/Driver/debug-prefix-map.c
  clang/test/Preprocessor/file_test.c
  clang/test/Preprocessor/file_test.h
  llvm/include/llvm/Support/Path.h
  llvm/lib/Support/Path.cpp
  llvm/unittests/Support/Path.cpp

Index: llvm/unittests/Support/Path.cpp
===
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -1230,7 +1230,9 @@
 TEST(Support, ReplacePathPrefix) {
   SmallString<64> Path1("/foo");
   SmallString<64> Path2("/old/foo");
+  SmallString<64> Path3("/oldnew/foo");
   SmallString<64> OldPrefix("/old");
+  SmallString<64> OldPrefixSep("/old/");
   SmallString<64> NewPrefix("/new");
   SmallString<64> NewPrefix2("/longernew");
   SmallString<64> EmptyPrefix("");
@@ -1250,6 +1252,33 @@
   Path = Path2;
   path::replace_path_prefix(Path, OldPrefix, EmptyPrefix);
   EXPECT_EQ(Path, "/foo");
+  Path = Path2;
+  path::replace_path_prefix(Path, OldPrefix, EmptyPrefix, true);
+  EXPECT_EQ(Path, "foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix, false);
+  EXPECT_EQ(Path, "/newnew/foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix, true);
+  EXPECT_EQ(Path, "/oldnew/foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
+  EXPECT_EQ(Path, "/oldnew/foo");
+  Path = Path1;
+  path::replace_path_prefix(Path, EmptyPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new/foo");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new");
+  Path = OldPrefixSep;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new/");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, false);
+  EXPECT_EQ(Path, "/old");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
+  EXPECT_EQ(Path, "/new");
 }
 
 TEST_F(FileSystemTest, OpenFileForRead) {
Index: llvm/lib/Support/Path.cpp
===
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -496,27 +496,50 @@
   path.append(ext.begin(), ext.end());
 }
 
-void replace_path_prefix(SmallVectorImpl ,
+bool replace_path_prefix(SmallVectorImpl ,
  const StringRef , const StringRef ,
- Style style) {
+ Style style, bool strict) {
   if (OldPrefix.empty() && NewPrefix.empty())
-return;
+return false;
 
   StringRef OrigPath(Path.begin(), Path.size());
-  if (!OrigPath.startswith(OldPrefix))
-return;
+  StringRef OldPrefixDir;
+
+  if (!strict && OldPrefix.size() > OrigPath.size())
+return false;
+
+  // Ensure OldPrefixDir does not have a trailing separator.
+  if (!OldPrefix.empty() && is_separator(OldPrefix.back()))
+OldPrefixDir = parent_path(OldPrefix, style);
+  else
+OldPrefixDir = OldPrefix;
+
+  if (!OrigPath.startswith(OldPrefixDir))
+return false;
+
+  if (OrigPath.size() > OldPrefixDir.size())
+if (!is_separator(OrigPath[OldPrefixDir.size()], style) && strict)
+  return false;
 
   // If prefixes have the same size we can simply copy the new one over.
-  if (OldPrefix.size() == NewPrefix.size()) {
+  if (OldPrefixDir.size() == NewPrefix.size() && !strict) {
 llvm::copy(NewPrefix, Path.begin());
-return;
+return true;
   }
 
-  StringRef RelPath = OrigPath.substr(OldPrefix.size());
+  StringRef RelPath = OrigPath.substr(OldPrefixDir.size());
   SmallString<256> NewPath;
   path::append(NewPath, style, NewPrefix);
-  path::append(NewPath, style, RelPath);
+  if (!RelPath.empty()) {
+if (!is_separator(RelPath[0], style) || !strict)
+  path::append(NewPath, style, RelPath);
+else
+  path::append(NewPath, style, relative_path(RelPath, style));
+  }
+
   Path.swap(NewPath);
+
+  return true;
 }
 
 void native(const Twine , SmallVectorImpl , Style style) {
Index: llvm/include/llvm/Support/Path.h
===
--- llvm/include/llvm/Support/Path.h
+++ llvm/include/llvm/Support/Path.h
@@ -152,18 +152,33 @@
 ///
 /// @code
 ///   /foo, /old, /new => /foo
+///   /old, /old, /new => /new
+///   /old, 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-11-18 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

Whoops. There are extra changes here I didn't mean to submit :/


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-11-18 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 229835.
dankm added a comment.
Herald added subscribers: lldb-commits, mgorny.
Herald added a project: LLDB.

- Address feedback from @Lekensteyn


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/CodeGen/debug-prefix-map.c
  clang/test/Driver/debug-prefix-map.S
  clang/test/Driver/debug-prefix-map.c
  clang/test/Preprocessor/file_test.c
  clang/test/Preprocessor/file_test.h
  lld/Common/CMakeLists.txt
  lldb/source/CMakeLists.txt
  llvm/include/llvm/Support/Path.h
  llvm/lib/Support/Path.cpp
  llvm/unittests/Support/Path.cpp

Index: llvm/unittests/Support/Path.cpp
===
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -1230,7 +1230,9 @@
 TEST(Support, ReplacePathPrefix) {
   SmallString<64> Path1("/foo");
   SmallString<64> Path2("/old/foo");
+  SmallString<64> Path3("/oldnew/foo");
   SmallString<64> OldPrefix("/old");
+  SmallString<64> OldPrefixSep("/old/");
   SmallString<64> NewPrefix("/new");
   SmallString<64> NewPrefix2("/longernew");
   SmallString<64> EmptyPrefix("");
@@ -1250,6 +1252,33 @@
   Path = Path2;
   path::replace_path_prefix(Path, OldPrefix, EmptyPrefix);
   EXPECT_EQ(Path, "/foo");
+  Path = Path2;
+  path::replace_path_prefix(Path, OldPrefix, EmptyPrefix, true);
+  EXPECT_EQ(Path, "foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix, false);
+  EXPECT_EQ(Path, "/newnew/foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix, true);
+  EXPECT_EQ(Path, "/oldnew/foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
+  EXPECT_EQ(Path, "/oldnew/foo");
+  Path = Path1;
+  path::replace_path_prefix(Path, EmptyPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new/foo");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new");
+  Path = OldPrefixSep;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new/");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, false);
+  EXPECT_EQ(Path, "/old");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
+  EXPECT_EQ(Path, "/new");
 }
 
 TEST_F(FileSystemTest, OpenFileForRead) {
Index: llvm/lib/Support/Path.cpp
===
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -496,27 +496,50 @@
   path.append(ext.begin(), ext.end());
 }
 
-void replace_path_prefix(SmallVectorImpl ,
+bool replace_path_prefix(SmallVectorImpl ,
  const StringRef , const StringRef ,
- Style style) {
+ Style style, bool strict) {
   if (OldPrefix.empty() && NewPrefix.empty())
-return;
+return false;
 
   StringRef OrigPath(Path.begin(), Path.size());
-  if (!OrigPath.startswith(OldPrefix))
-return;
+  StringRef OldPrefixDir;
+
+  if (!strict && OldPrefix.size() > OrigPath.size())
+return false;
+
+  // Ensure OldPrefixDir does not have a trailing separator.
+  if (!OldPrefix.empty() && is_separator(OldPrefix.back()))
+OldPrefixDir = parent_path(OldPrefix, style);
+  else
+OldPrefixDir = OldPrefix;
+
+  if (!OrigPath.startswith(OldPrefixDir))
+return false;
+
+  if (OrigPath.size() > OldPrefixDir.size())
+if (!is_separator(OrigPath[OldPrefixDir.size()], style) && strict)
+  return false;
 
   // If prefixes have the same size we can simply copy the new one over.
-  if (OldPrefix.size() == NewPrefix.size()) {
+  if (OldPrefixDir.size() == NewPrefix.size() && !strict) {
 llvm::copy(NewPrefix, Path.begin());
-return;
+return true;
   }
 
-  StringRef RelPath = OrigPath.substr(OldPrefix.size());
+  StringRef RelPath = OrigPath.substr(OldPrefixDir.size());
   SmallString<256> NewPath;
   path::append(NewPath, style, NewPrefix);
-  path::append(NewPath, style, RelPath);
+  if (!RelPath.empty()) {
+if (!is_separator(RelPath[0], style) || !strict)
+  path::append(NewPath, style, RelPath);
+else
+  path::append(NewPath, style, relative_path(RelPath, style));
+  }
+
   Path.swap(NewPath);
+
+  return true;
 }
 
 void native(const Twine , SmallVectorImpl , Style style) {
Index: llvm/include/llvm/Support/Path.h
===
--- llvm/include/llvm/Support/Path.h
+++ 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-11-18 Thread Dan McGregor via Phabricator via cfe-commits
dankm marked an inline comment as done.
dankm added inline comments.



Comment at: clang/test/Driver/debug-prefix-map.c:8
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s 
-check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s 
-check-prefix CHECK-MACRO-SIMPLE
+

Lekensteyn wrote:
> What about combining these two tests? The command is the same, maybe you 
> could have a new `-check-prefix` to reduce the number of invocations? 
> Likewise for the cases below.
The tests will need more thinking, you're probably right, but I don't have much 
time to work on this at the moment. How do you feel about addressing this in 
the future?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-11-17 Thread Dan McGregor via Phabricator via cfe-commits
dankm marked 2 inline comments as done.
dankm added inline comments.



Comment at: llvm/include/llvm/Support/Path.h:172
+/// @param style The path separator style
+/// @param strict Strict prefix path checking
+/// @result true if \a Path begins with OldPrefix

Lekensteyn wrote:
> "strict checking" is ambiguous on its own. What about something like:
> 
> If strict is true, a directory separator following \a OldPrefix will also 
> be stripped. Otherwise, directory separators will only be matched and 
> stripped when present in \a OldPrefix.
> 
> Or whatever semantics you would like to assign to "strict mode".
Thanks. I like your wording, and I've used it in the incoming patch.



Comment at: llvm/include/llvm/Support/Path.h:181
+  return replace_path_prefix(Path, OldPrefix, NewPrefix, style, strict);
+}
 

Lekensteyn wrote:
> Why have a variant with the parameters swapped, is it common in LLVM to have 
> such convenience wrappers?
> 
> Why not require callers to pass `Style::native` whenever they want to modify 
> "strict"?
Works for me. I did that to make my call sites somewhat more readable. It'll be 
changed too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65556: Phabricator D49466

2019-08-08 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D65556#1610001 , @lebedev.ri wrote:

> Please fix patch title and description


Sorry, I'm going to delete this. It was supposed to be a new patchset on D49466 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65556/new/

https://reviews.llvm.org/D65556



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-07-31 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 212723.
dankm added a comment.
Herald added subscribers: llvm-commits, ormris, hiraditya.
Herald added a project: LLVM.

Latest changes. I've been sitting on these for months, so I don't remember all 
that changed. The path remapping contract changed somewhat, and it's now based 
on the git monorepo.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/CodeGen/debug-prefix-map.c
  clang/test/Driver/debug-prefix-map.S
  clang/test/Driver/debug-prefix-map.c
  clang/test/Preprocessor/file_test.c
  clang/test/Preprocessor/file_test.h
  llvm/include/llvm/Support/Path.h
  llvm/lib/Support/Path.cpp
  llvm/unittests/Support/Path.cpp

Index: llvm/unittests/Support/Path.cpp
===
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -1219,7 +1219,9 @@
 TEST(Support, ReplacePathPrefix) {
   SmallString<64> Path1("/foo");
   SmallString<64> Path2("/old/foo");
+  SmallString<64> Path3("/oldnew/foo");
   SmallString<64> OldPrefix("/old");
+  SmallString<64> OldPrefixSep("/old/");
   SmallString<64> NewPrefix("/new");
   SmallString<64> NewPrefix2("/longernew");
   SmallString<64> EmptyPrefix("");
@@ -1239,6 +1241,33 @@
   Path = Path2;
   path::replace_path_prefix(Path, OldPrefix, EmptyPrefix);
   EXPECT_EQ(Path, "/foo");
+  Path = Path2;
+  path::replace_path_prefix(Path, OldPrefix, EmptyPrefix, true);
+  EXPECT_EQ(Path, "foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix, false);
+  EXPECT_EQ(Path, "/newnew/foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix, true);
+  EXPECT_EQ(Path, "/oldnew/foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
+  EXPECT_EQ(Path, "/oldnew/foo");
+  Path = Path1;
+  path::replace_path_prefix(Path, EmptyPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new/foo");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new");
+  Path = OldPrefixSep;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new/");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, false);
+  EXPECT_EQ(Path, "/old");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
+  EXPECT_EQ(Path, "/new");
 }
 
 TEST_F(FileSystemTest, OpenFileForRead) {
Index: llvm/lib/Support/Path.cpp
===
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -496,27 +496,53 @@
   path.append(ext.begin(), ext.end());
 }
 
-void replace_path_prefix(SmallVectorImpl ,
+bool replace_path_prefix(SmallVectorImpl ,
  const StringRef , const StringRef ,
- Style style) {
+ Style style, bool strict) {
   if (OldPrefix.empty() && NewPrefix.empty())
-return;
+return false;
 
   StringRef OrigPath(Path.begin(), Path.size());
-  if (!OrigPath.startswith(OldPrefix))
-return;
+  StringRef OldPrefixDir;
+
+  if (!strict && OldPrefix.size() > OrigPath.size())
+return false;
+
+  if (!strict && OldPrefix.size() > OrigPath.size())
+return false;
+
+  // Ensure OldPrefixDir does not have a trailing separator.
+  if (!OldPrefix.empty() && is_separator(OldPrefix.back()))
+OldPrefixDir = parent_path(OldPrefix, style);
+  else
+OldPrefixDir = OldPrefix;
+
+  if (!OrigPath.startswith(OldPrefixDir))
+return false;
+
+  if (OrigPath.size() > OldPrefixDir.size())
+if (!is_separator(OrigPath[OldPrefixDir.size()], style) && strict)
+  return false;
 
   // If prefixes have the same size we can simply copy the new one over.
-  if (OldPrefix.size() == NewPrefix.size()) {
+  if (OldPrefixDir.size() == NewPrefix.size() && !strict) {
 llvm::copy(NewPrefix, Path.begin());
-return;
+return true;
   }
 
-  StringRef RelPath = OrigPath.substr(OldPrefix.size());
+  StringRef RelPath = OrigPath.substr(OldPrefixDir.size());
   SmallString<256> NewPath;
   path::append(NewPath, style, NewPrefix);
-  path::append(NewPath, style, RelPath);
+  if (!RelPath.empty()) {
+if (!is_separator(RelPath[0], style) || !strict)
+  path::append(NewPath, style, RelPath);
+else
+  path::append(NewPath, style, relative_path(RelPath, style));
+  }
+
   Path.swap(NewPath);
+
+  return true;
 }
 
 void native(const Twine , SmallVectorImpl , Style 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-07-31 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D49466#1586140 , @manojgupta wrote:

> @dankm are you still working on this patch?


Yes, I've been afk for a bit due to family circumstances, but I just uploaded 
more.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65556: Phabricator D49466

2019-07-31 Thread Dan McGregor via Phabricator via cfe-commits
dankm created this revision.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya, emaste.
Herald added projects: clang, LLVM.

path prefix mapping: enforce path matching

Force the prefix string to match a complete prefix in the
path to remap, and strip any trailing path separators from
the resulting path.

Allows -ffile-prefix-map=/a=b /a/test.c to be remapped to b/test.c
and -ffile-prefix-map==/fake_prefix /a/test.c to become
/fake_prefix/a/test.c.

Likewise, -ffile-prefix-map=/a= /a/test.c becomes test.c instead of
/test.c. For the latter you'd use -ffile-prefix-map=/a=/.

Merge remote-tracking branch 'llvm/master' into D49466 


Do not remap MainFileName twice.

Merge remote-tracking branch 'llvm/master' into D49466 


Path: enhance prefix mapping

Return true when a path is remapped, and allow replacing the
original path entirely.

Break on first match.

Merge remote-tracking branch 'llvm/master' into D49466 


Style fix

Unit test updates

Clean up path handling some more

Rewrite path prefix replacement

Add a bunch of tests for odd corner cases.

Merge remote-tracking branch 'llvm/master' into D49466 


Address path feedback

Use new flag in clang

Get contract in order


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65556

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Lex/PreprocessorOptions.h
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/CodeGen/debug-prefix-map.c
  clang/test/Driver/debug-prefix-map.S
  clang/test/Driver/debug-prefix-map.c
  clang/test/Preprocessor/file_test.c
  clang/test/Preprocessor/file_test.h
  llvm/include/llvm/Support/Path.h
  llvm/lib/Support/Path.cpp
  llvm/unittests/Support/Path.cpp

Index: llvm/unittests/Support/Path.cpp
===
--- llvm/unittests/Support/Path.cpp
+++ llvm/unittests/Support/Path.cpp
@@ -1219,7 +1219,9 @@
 TEST(Support, ReplacePathPrefix) {
   SmallString<64> Path1("/foo");
   SmallString<64> Path2("/old/foo");
+  SmallString<64> Path3("/oldnew/foo");
   SmallString<64> OldPrefix("/old");
+  SmallString<64> OldPrefixSep("/old/");
   SmallString<64> NewPrefix("/new");
   SmallString<64> NewPrefix2("/longernew");
   SmallString<64> EmptyPrefix("");
@@ -1239,6 +1241,33 @@
   Path = Path2;
   path::replace_path_prefix(Path, OldPrefix, EmptyPrefix);
   EXPECT_EQ(Path, "/foo");
+  Path = Path2;
+  path::replace_path_prefix(Path, OldPrefix, EmptyPrefix, true);
+  EXPECT_EQ(Path, "foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix, false);
+  EXPECT_EQ(Path, "/newnew/foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix, true);
+  EXPECT_EQ(Path, "/oldnew/foo");
+  Path = Path3;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
+  EXPECT_EQ(Path, "/oldnew/foo");
+  Path = Path1;
+  path::replace_path_prefix(Path, EmptyPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new/foo");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new");
+  Path = OldPrefixSep;
+  path::replace_path_prefix(Path, OldPrefix, NewPrefix);
+  EXPECT_EQ(Path, "/new/");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, false);
+  EXPECT_EQ(Path, "/old");
+  Path = OldPrefix;
+  path::replace_path_prefix(Path, OldPrefixSep, NewPrefix, true);
+  EXPECT_EQ(Path, "/new");
 }
 
 TEST_F(FileSystemTest, OpenFileForRead) {
Index: llvm/lib/Support/Path.cpp
===
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -496,27 +496,53 @@
   path.append(ext.begin(), ext.end());
 }
 
-void replace_path_prefix(SmallVectorImpl ,
+bool replace_path_prefix(SmallVectorImpl ,
  const StringRef , const StringRef ,
- Style style) {
+ Style style, bool strict) {
   if (OldPrefix.empty() && NewPrefix.empty())
-return;
+return false;
 
   StringRef OrigPath(Path.begin(), Path.size());
-  if (!OrigPath.startswith(OldPrefix))
-return;
+  StringRef OldPrefixDir;
+
+  if (!strict && OldPrefix.size() > OrigPath.size())
+return false;
+
+  if (!strict && OldPrefix.size() > OrigPath.size())
+return false;
+
+  // Ensure OldPrefixDir does not have a trailing separator.
+  if (!OldPrefix.empty() && is_separator(OldPrefix.back()))
+OldPrefixDir = parent_path(OldPrefix, style);
+  else
+OldPrefixDir = OldPrefix;
+
+  if (!OrigPath.startswith(OldPrefixDir))
+return false;
+
+  if 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-16 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 182121.
dankm added a comment.

Move trailing path separator stripping back to Clang.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/FreeBSD.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/debug-prefix-map.c
  test/Driver/debug-prefix-map.S
  test/Driver/debug-prefix-map.c
  test/Preprocessor/file_test.c
  test/Preprocessor/file_test.h

Index: test/Preprocessor/file_test.h
===
--- /dev/null
+++ test/Preprocessor/file_test.h
@@ -0,0 +1,2 @@
+filename: __FILE__
+basefile: __BASE_FILE__
Index: test/Preprocessor/file_test.c
===
--- /dev/null
+++ test/Preprocessor/file_test.c
@@ -0,0 +1,22 @@
+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
+
+filename: __FILE__
+#include "file_test.h"
+
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK-NOT: filename:
+
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL-NOT: filename:
+
+// CHECK-REMOVE: filename: "file_test.c"
+// CHECK-REMOVE: filename: "file_test.h"
+// CHECK-REMOVE: basefile: "file_test.c"
+// CHECK-REMOVE-NOT: filename:
Index: test/Driver/debug-prefix-map.c
===
--- test/Driver/debug-prefix-map.c
+++ test/Driver/debug-prefix-map.c
@@ -1,9 +1,28 @@
-// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-INVALID
-// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-SIMPLE
-// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-COMPLEX
-// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-EMPTY
+// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-INVALID
+// RUN: %clang -### -fmacro-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-INVALID
+// RUN: %clang -### -ffile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-FILE-INVALID
 
-// CHECK-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
-// CHECK-SIMPLE: fdebug-prefix-map=old=new
-// CHECK-COMPLEX: fdebug-prefix-map=old=n=ew
-// CHECK-EMPTY: fdebug-prefix-map=old=
+// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -fmacro-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+
+// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -fmacro-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+
+// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -fmacro-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+
+// CHECK-DEBUG-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
+// CHECK-MACRO-INVALID: error: invalid argument 'old' to -fmacro-prefix-map
+// CHECK-FILE-INVALID: error: invalid argument 'old' to -ffile-prefix-map
+// CHECK-DEBUG-SIMPLE: fdebug-prefix-map=old=new
+// CHECK-MACRO-SIMPLE: fmacro-prefix-map=old=new
+// CHECK-DEBUG-COMPLEX: fdebug-prefix-map=old=n=ew
+// CHECK-MACRO-COMPLEX: fmacro-prefix-map=old=n=ew
+// CHECK-DEBUG-EMPTY: 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-16 Thread Dan McGregor via Phabricator via cfe-commits
dankm marked an inline comment as done.
dankm added a comment.

Sure, I'll (eventually) make a separate review.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-16 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 182047.
dankm added a comment.

Undo accidental change.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/FreeBSD.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/debug-prefix-map.c
  test/Driver/debug-prefix-map.S
  test/Driver/debug-prefix-map.c
  test/Preprocessor/file_test.c
  test/Preprocessor/file_test.h

Index: test/Preprocessor/file_test.h
===
--- /dev/null
+++ test/Preprocessor/file_test.h
@@ -0,0 +1,2 @@
+filename: __FILE__
+basefile: __BASE_FILE__
Index: test/Preprocessor/file_test.c
===
--- /dev/null
+++ test/Preprocessor/file_test.c
@@ -0,0 +1,22 @@
+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
+
+filename: __FILE__
+#include "file_test.h"
+
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK-NOT: filename:
+
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL-NOT: filename:
+
+// CHECK-REMOVE: filename: "file_test.c"
+// CHECK-REMOVE: filename: "file_test.h"
+// CHECK-REMOVE: basefile: "file_test.c"
+// CHECK-REMOVE-NOT: filename:
Index: test/Driver/debug-prefix-map.c
===
--- test/Driver/debug-prefix-map.c
+++ test/Driver/debug-prefix-map.c
@@ -1,9 +1,28 @@
-// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-INVALID
-// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-SIMPLE
-// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-COMPLEX
-// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-EMPTY
+// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-INVALID
+// RUN: %clang -### -fmacro-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-INVALID
+// RUN: %clang -### -ffile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-FILE-INVALID
 
-// CHECK-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
-// CHECK-SIMPLE: fdebug-prefix-map=old=new
-// CHECK-COMPLEX: fdebug-prefix-map=old=n=ew
-// CHECK-EMPTY: fdebug-prefix-map=old=
+// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -fmacro-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+
+// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -fmacro-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+
+// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -fmacro-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+
+// CHECK-DEBUG-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
+// CHECK-MACRO-INVALID: error: invalid argument 'old' to -fmacro-prefix-map
+// CHECK-FILE-INVALID: error: invalid argument 'old' to -ffile-prefix-map
+// CHECK-DEBUG-SIMPLE: fdebug-prefix-map=old=new
+// CHECK-MACRO-SIMPLE: fmacro-prefix-map=old=new
+// CHECK-DEBUG-COMPLEX: fdebug-prefix-map=old=n=ew
+// CHECK-MACRO-COMPLEX: fmacro-prefix-map=old=n=ew
+// CHECK-DEBUG-EMPTY: fdebug-prefix-map=old=
+// 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-16 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 182037.
dankm added a comment.

Update style.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/FreeBSD.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/debug-prefix-map.c
  test/Driver/debug-prefix-map.S
  test/Driver/debug-prefix-map.c
  test/Preprocessor/file_test.c
  test/Preprocessor/file_test.h

Index: test/Preprocessor/file_test.h
===
--- /dev/null
+++ test/Preprocessor/file_test.h
@@ -0,0 +1,2 @@
+filename: __FILE__
+basefile: __BASE_FILE__
Index: test/Preprocessor/file_test.c
===
--- /dev/null
+++ test/Preprocessor/file_test.c
@@ -0,0 +1,22 @@
+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
+
+filename: __FILE__
+#include "file_test.h"
+
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK-NOT: filename:
+
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL-NOT: filename:
+
+// CHECK-REMOVE: filename: "file_test.c"
+// CHECK-REMOVE: filename: "file_test.h"
+// CHECK-REMOVE: basefile: "file_test.c"
+// CHECK-REMOVE-NOT: filename:
Index: test/Driver/debug-prefix-map.c
===
--- test/Driver/debug-prefix-map.c
+++ test/Driver/debug-prefix-map.c
@@ -1,9 +1,28 @@
-// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-INVALID
-// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-SIMPLE
-// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-COMPLEX
-// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-EMPTY
+// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-INVALID
+// RUN: %clang -### -fmacro-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-INVALID
+// RUN: %clang -### -ffile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-FILE-INVALID
 
-// CHECK-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
-// CHECK-SIMPLE: fdebug-prefix-map=old=new
-// CHECK-COMPLEX: fdebug-prefix-map=old=n=ew
-// CHECK-EMPTY: fdebug-prefix-map=old=
+// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -fmacro-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+
+// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -fmacro-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+
+// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -fmacro-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+
+// CHECK-DEBUG-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
+// CHECK-MACRO-INVALID: error: invalid argument 'old' to -fmacro-prefix-map
+// CHECK-FILE-INVALID: error: invalid argument 'old' to -ffile-prefix-map
+// CHECK-DEBUG-SIMPLE: fdebug-prefix-map=old=new
+// CHECK-MACRO-SIMPLE: fmacro-prefix-map=old=new
+// CHECK-DEBUG-COMPLEX: fdebug-prefix-map=old=n=ew
+// CHECK-MACRO-COMPLEX: fmacro-prefix-map=old=n=ew
+// CHECK-DEBUG-EMPTY: fdebug-prefix-map=old=
+// CHECK-MACRO-EMPTY: 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-16 Thread Dan McGregor via Phabricator via cfe-commits
dankm marked an inline comment as done.
dankm added a comment.

  I'll update the style nit, and spend some non-tired time on the string 
remapping. Thanks




Comment at: lib/CodeGen/CGDebugInfo.cpp:607
   llvm::DIFile *CUFile = DBuilder.createFile(
-  remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
+  MainFileName, remapDIPath(getCurrentDirname()), CSInfo,
   getSource(SM, SM.getMainFileID()));

Lekensteyn wrote:
> Any reason for dropping `remapDIPath` here? Wouldn't this result in the full 
> path being included even when using:
> 
> clang -fdebug-prefix-map=/full/path/= /full/path/source.c
Whoops. That probably shouldn't have been included this round. This is a 
bugfix. MainFileName is already remapped from earlier in this function, this 
keeps it from remapping twice if you have an empty old prefix.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-15 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 181964.
dankm marked an inline comment as done.
dankm added a comment.

Enforce path mapping. This requires LLVM review D56769 
.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/FreeBSD.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/debug-prefix-map.c
  test/Driver/debug-prefix-map.S
  test/Driver/debug-prefix-map.c
  test/Preprocessor/file_test.c
  test/Preprocessor/file_test.h

Index: test/Preprocessor/file_test.h
===
--- /dev/null
+++ test/Preprocessor/file_test.h
@@ -0,0 +1,2 @@
+filename: __FILE__
+basefile: __BASE_FILE__
Index: test/Preprocessor/file_test.c
===
--- /dev/null
+++ test/Preprocessor/file_test.c
@@ -0,0 +1,22 @@
+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
+
+filename: __FILE__
+#include "file_test.h"
+
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK-NOT: filename:
+
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL-NOT: filename:
+
+// CHECK-REMOVE: filename: "file_test.c"
+// CHECK-REMOVE: filename: "file_test.h"
+// CHECK-REMOVE: basefile: "file_test.c"
+// CHECK-REMOVE-NOT: filename:
Index: test/Driver/debug-prefix-map.c
===
--- test/Driver/debug-prefix-map.c
+++ test/Driver/debug-prefix-map.c
@@ -1,9 +1,28 @@
-// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-INVALID
-// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-SIMPLE
-// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-COMPLEX
-// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-EMPTY
+// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-INVALID
+// RUN: %clang -### -fmacro-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-INVALID
+// RUN: %clang -### -ffile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-FILE-INVALID
 
-// CHECK-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
-// CHECK-SIMPLE: fdebug-prefix-map=old=new
-// CHECK-COMPLEX: fdebug-prefix-map=old=n=ew
-// CHECK-EMPTY: fdebug-prefix-map=old=
+// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -fmacro-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+
+// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -fmacro-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+
+// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -fmacro-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+
+// CHECK-DEBUG-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
+// CHECK-MACRO-INVALID: error: invalid argument 'old' to -fmacro-prefix-map
+// CHECK-FILE-INVALID: error: invalid argument 'old' to -ffile-prefix-map
+// CHECK-DEBUG-SIMPLE: fdebug-prefix-map=old=new
+// CHECK-MACRO-SIMPLE: fmacro-prefix-map=old=new
+// CHECK-DEBUG-COMPLEX: fdebug-prefix-map=old=n=ew
+// 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-14 Thread Dan McGregor via Phabricator via cfe-commits
dankm marked 3 inline comments as done.
dankm added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:612
+if (Map.find('=') == StringRef::npos)
+  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
+else

Lekensteyn wrote:
> joerg wrote:
> > I'd prefer the bailout style here, i.e. `if (...) { D.diag(...); continue }`
> Wouldn't using `if (...) { D.diag(...); continue; }` also skip the 
> `A->claim()` call? Presumably that could result in spurious errors as well 
> about unused arguments?
It would, and did. I had @joerg's suggestion in an earlier patch on this review.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-14 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 181562.
dankm added a comment.

Restored original test case file names.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/FreeBSD.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/debug-prefix-map.c
  test/Driver/debug-prefix-map.S
  test/Driver/debug-prefix-map.c
  test/Preprocessor/file_test.c
  test/Preprocessor/file_test.h

Index: test/Preprocessor/file_test.h
===
--- /dev/null
+++ test/Preprocessor/file_test.h
@@ -0,0 +1,2 @@
+filename: __FILE__
+basefile: __BASE_FILE__
Index: test/Preprocessor/file_test.c
===
--- /dev/null
+++ test/Preprocessor/file_test.c
@@ -0,0 +1,22 @@
+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
+
+filename: __FILE__
+#include "file_test.h"
+
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK-NOT: filename:
+
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL-NOT: filename:
+
+// CHECK-REMOVE: filename: "file_test.c"
+// CHECK-REMOVE: filename: "file_test.h"
+// CHECK-REMOVE: basefile: "file_test.c"
+// CHECK-REMOVE-NOT: filename:
Index: test/Driver/debug-prefix-map.c
===
--- test/Driver/debug-prefix-map.c
+++ test/Driver/debug-prefix-map.c
@@ -1,9 +1,28 @@
-// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-INVALID
-// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-SIMPLE
-// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-COMPLEX
-// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-EMPTY
+// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-INVALID
+// RUN: %clang -### -fmacro-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-INVALID
+// RUN: %clang -### -ffile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-FILE-INVALID
 
-// CHECK-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
-// CHECK-SIMPLE: fdebug-prefix-map=old=new
-// CHECK-COMPLEX: fdebug-prefix-map=old=n=ew
-// CHECK-EMPTY: fdebug-prefix-map=old=
+// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -fmacro-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+
+// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -fmacro-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+
+// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -fmacro-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+
+// CHECK-DEBUG-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
+// CHECK-MACRO-INVALID: error: invalid argument 'old' to -fmacro-prefix-map
+// CHECK-FILE-INVALID: error: invalid argument 'old' to -ffile-prefix-map
+// CHECK-DEBUG-SIMPLE: fdebug-prefix-map=old=new
+// CHECK-MACRO-SIMPLE: fmacro-prefix-map=old=new
+// CHECK-DEBUG-COMPLEX: fdebug-prefix-map=old=n=ew
+// CHECK-MACRO-COMPLEX: fmacro-prefix-map=old=n=ew
+// CHECK-DEBUG-EMPTY: fdebug-prefix-map=old=
+// CHECK-MACRO-EMPTY: 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-11 Thread Dan McGregor via Phabricator via cfe-commits
dankm marked 4 inline comments as done.
dankm added a comment.

In D49466#1354468 , @Lekensteyn wrote:

> Could you add more tests to check the error message for bad options (missing 
> `=`):
>
>   -fdebug-prefix-map=bad
>   -fmacro-prefix-map=bad
>   -ffile-prefix-map=bad
>


Some more got added with the latest diff

> FWIW, GCC emits two errors for `-ffile-prefix-map=bad`.

Yes, this does too. It looked odd to me, but it's not a huge deal.

> Another edge case is `-ffile-prefix-map==foo/`, GCC currently uses this to 
> prepend `foo/` to every path. Not sure if that is intentional, but that is 
> the current behavior (one which is also replicated by this patch I believe).

Yes, with this patch it does that for file-prefix-map and macro-prefix-map. It 
already did that (sort-of) for debug-prefix-map, but seems to add it twice for 
some debugging information, but I'll fix that later since it's done that since 
at least version 5.0.

> Could you also mark review comments that are completed as "done"? It should 
> make the diff easier to read (I hope) :)

Yes, I tried to do that with this comment. I'm new to phabricator.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-11 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 181363.
dankm added a comment.

renamed err_drv_invalid_argument_to_prefix_map to 
err_drv_invalid_argument_to_option
added more frontend tests for macro-prefix-map and file-prefix-map.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/FreeBSD.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/debug-prefix-map.c
  test/Driver/debug-prefix-map.S
  test/Driver/debug-prefix-map.c
  test/Driver/prefix-map.S
  test/Driver/prefix-map.c
  test/Preprocessor/file_test.c
  test/Preprocessor/file_test.h

Index: test/Preprocessor/file_test.h
===
--- /dev/null
+++ test/Preprocessor/file_test.h
@@ -0,0 +1,2 @@
+filename: __FILE__
+basefile: __BASE_FILE__
Index: test/Preprocessor/file_test.c
===
--- /dev/null
+++ test/Preprocessor/file_test.c
@@ -0,0 +1,22 @@
+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
+
+filename: __FILE__
+#include "file_test.h"
+
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK-NOT: filename:
+
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL-NOT: filename:
+
+// CHECK-REMOVE: filename: "file_test.c"
+// CHECK-REMOVE: filename: "file_test.h"
+// CHECK-REMOVE: basefile: "file_test.c"
+// CHECK-REMOVE-NOT: filename:
Index: test/Driver/prefix-map.c
===
--- /dev/null
+++ test/Driver/prefix-map.c
@@ -0,0 +1,28 @@
+// RUN: %clang -### -fdebug-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-INVALID
+// RUN: %clang -### -fmacro-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-INVALID
+// RUN: %clang -### -ffile-prefix-map=old %s 2>&1 | FileCheck %s -check-prefix CHECK-FILE-INVALID
+
+// RUN: %clang -### -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -fmacro-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-SIMPLE
+// RUN: %clang -### -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-SIMPLE
+
+// RUN: %clang -### -fdebug-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -fmacro-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-COMPLEX
+// RUN: %clang -### -ffile-prefix-map=old=n=ew %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-COMPLEX
+
+// RUN: %clang -### -fdebug-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -fmacro-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-DEBUG-EMPTY
+// RUN: %clang -### -ffile-prefix-map=old= %s 2>&1 | FileCheck %s -check-prefix CHECK-MACRO-EMPTY
+
+// CHECK-DEBUG-INVALID: error: invalid argument 'old' to -fdebug-prefix-map
+// CHECK-MACRO-INVALID: error: invalid argument 'old' to -fmacro-prefix-map
+// CHECK-FILE-INVALID: error: invalid argument 'old' to -ffile-prefix-map
+// CHECK-DEBUG-SIMPLE: fdebug-prefix-map=old=new
+// CHECK-MACRO-SIMPLE: fmacro-prefix-map=old=new
+// CHECK-DEBUG-COMPLEX: fdebug-prefix-map=old=n=ew
+// CHECK-MACRO-COMPLEX: fmacro-prefix-map=old=n=ew
+// CHECK-DEBUG-EMPTY: fdebug-prefix-map=old=
+// CHECK-MACRO-EMPTY: fmacro-prefix-map=old=
Index: test/Driver/prefix-map.S
===
--- /dev/null
+++ test/Driver/prefix-map.S
@@ -0,0 +1,7 @@
+// RUN: %clang -### -g -fdebug-prefix-map=old=new %s 2>&1 | FileCheck %s
+// RUN: %clang -### -g -ffile-prefix-map=old=new %s 2>&1 | FileCheck %s
+
+// CHECK: cc1as
+// CHECK-SAME: -fdebug-prefix-map=old=new
+
+// More tests for this flag in debug-prefix-map.c.
Index: 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-11 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 181293.
dankm added a comment.

Made diagnostics for file-prefix-map display the actual option name.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/FreeBSD.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/debug-prefix-map.c
  test/Preprocessor/file_test.c
  test/Preprocessor/file_test.h

Index: test/Preprocessor/file_test.h
===
--- /dev/null
+++ test/Preprocessor/file_test.h
@@ -0,0 +1,2 @@
+filename: __FILE__
+basefile: __BASE_FILE__
Index: test/Preprocessor/file_test.c
===
--- /dev/null
+++ test/Preprocessor/file_test.c
@@ -0,0 +1,22 @@
+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
+
+filename: __FILE__
+#include "file_test.h"
+
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK-NOT: filename:
+
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL-NOT: filename:
+
+// CHECK-REMOVE: filename: "file_test.c"
+// CHECK-REMOVE: filename: "file_test.h"
+// CHECK-REMOVE: basefile: "file_test.c"
+// CHECK-REMOVE-NOT: filename:
Index: test/CodeGen/debug-prefix-map.c
===
--- test/CodeGen/debug-prefix-map.c
+++ test/CodeGen/debug-prefix-map.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s -check-prefix CHECK-EVIL
 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -main-file-name debug-prefix-map.c | FileCheck %s
 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -fdebug-compilation-dir %p | FileCheck %s -check-prefix CHECK-COMPILATION-DIR
+// RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
 
 #include "Inputs/stdio.h"
 
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -29,6 +29,7 @@
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorLexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -1456,6 +1457,16 @@
   return TI.getTriple().getEnvironment() == Env.getEnvironment();
 }
 
+static void remapMacroPath(
+SmallString<128> ,
+const std::map>
+) {
+  for (const auto  : MacroPrefixMap)
+if (Path.startswith(Entry.first)) {
+  Path = (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
+}
+}
+
 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
 /// as a builtin macro, handle it and return the next token as 'Tok'.
 void Preprocessor::ExpandBuiltinMacro(Token ) {
@@ -1523,6 +1534,7 @@
 if (PLoc.isValid()) {
   FN += PLoc.getFilename();
   Lexer::Stringify(FN);
+  remapMacroPath(FN, PPOpts->MacroPrefixMap);
   OS << '"' << FN << '"';
 }
 Tok.setKind(tok::string_literal);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -3090,6 +3090,9 @@
   for (const auto *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
 Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
 
+  for (const auto  : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ))
+Opts.MacroPrefixMap.insert(StringRef(A).split('='));
+
   if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {
 StringRef Value(A->getValue());
 size_t Comma = Value.find(',');
Index: lib/Driver/ToolChains/Gnu.cpp

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-11 Thread Dan McGregor via Phabricator via cfe-commits
dankm marked 2 inline comments as done.
dankm added a comment.

In D49466#1354238 , @Lekensteyn wrote:

> It would be nice to have this for Clang 8.0, the branch date is within 5 days 
> :)


Yup, that's why I'm ignoring a new baby for this :)




Comment at: lib/Driver/ToolChains/Clang.cpp:617
 if (Map.find('=') == StringRef::npos)
-  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
+  D.Diag(diag::err_drv_invalid_argument_to_prefix_map) << Map << "debug";
 else

Lekensteyn wrote:
> For `clang -ffile-prefix-map=foo`, wouldn't this report `invalid argument 
> 'foo' to -fdebug-prefix-map`? If so, perhaps some method of `A` or 
> `A->getOption()` can be used?
Yes, it would seem so. It looks like A->getOption().getName() can be used.



Comment at: test/Preprocessor/file_test.c:5
+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s 
--check-prefix CHECK-REMOVE
+//This is a comment
+

Lekensteyn wrote:
> Any reason to keep this comment?
Ha. No. That's from when I started writing this test. It can go away.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-11 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D49466#1353437 , @alxu wrote:

> FYI, according to my comment on D49652 , 
> assuming I checked it correctly, gcc applies the maps in reverse order of 
> command line specification, not sorted order. It seems unlikely that anyone 
> is actually depending on the order though.


Yeah, I noticed that, but it appears to be undefined by GCC's documentation. I 
agree with review D49652 , but I also want to 
get this in before 8.0 branches, even if it's not ideal.

Right now we apply them in strict alphabetical order, switching to reverse 
order lets one map /objdir/ to / while remapping /objdir/ to 
/some/other/dir, which is my use case.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-10 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 181151.
dankm added a comment.

Added unit tests for the prefix remapping.

Switched the sorting on the prefix map, so that /sub gets remapped 
before  if both are specified.

I intend to do a more invasive change after this review to unify path prefix 
remapping.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/CodeGen/CGDebugInfo.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Driver/ToolChains/FreeBSD.cpp
  lib/Driver/ToolChains/Gnu.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/CodeGen/debug-prefix-map.c
  test/Preprocessor/file_test.c
  test/Preprocessor/file_test.h

Index: test/Preprocessor/file_test.h
===
--- /dev/null
+++ test/Preprocessor/file_test.h
@@ -0,0 +1,2 @@
+filename: __FILE__
+basefile: __BASE_FILE__
Index: test/Preprocessor/file_test.c
===
--- /dev/null
+++ test/Preprocessor/file_test.c
@@ -0,0 +1,23 @@
+// RUN: %clang -E -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH/empty -c -o - %s | FileCheck %s
+// RUN: %clang -E -fmacro-prefix-map=%p=/UNLIKELY_PATH=empty -c -o - %s | FileCheck %s -check-prefix CHECK-EVIL
+// RUN: %clang -E -fmacro-prefix-map=%p/= -c -o - %s | FileCheck %s --check-prefix CHECK-REMOVE
+//This is a comment
+
+filename: __FILE__
+#include "file_test.h"
+
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK: filename: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.h"
+// CHECK: basefile: "/UNLIKELY_PATH/empty{{[/\\]}}file_test.c"
+// CHECK-NOT: filename:
+
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL: filename: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.h"
+// CHECK-EVIL: basefile: "/UNLIKELY_PATH=empty{{[/\\]}}file_test.c"
+// CHECK-EVIL-NOT: filename:
+
+// CHECK-REMOVE: filename: "file_test.c"
+// CHECK-REMOVE: filename: "file_test.h"
+// CHECK-REMOVE: basefile: "file_test.c"
+// CHECK-REMOVE-NOT: filename:
Index: test/CodeGen/debug-prefix-map.c
===
--- test/CodeGen/debug-prefix-map.c
+++ test/CodeGen/debug-prefix-map.c
@@ -2,6 +2,8 @@
 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH=empty %s -emit-llvm -o - | FileCheck %s -check-prefix CHECK-EVIL
 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -main-file-name debug-prefix-map.c | FileCheck %s
 // RUN: %clang_cc1 -debug-info-kind=standalone -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty %s -emit-llvm -o - -fdebug-compilation-dir %p | FileCheck %s -check-prefix CHECK-COMPILATION-DIR
+// RUN: %clang -g -fdebug-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang -g -ffile-prefix-map=%p=/UNLIKELY_PATH/empty -S -c %s -emit-llvm -o - | FileCheck %s
 
 #include "Inputs/stdio.h"
 
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -29,6 +29,7 @@
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorLexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
@@ -1456,6 +1457,16 @@
   return TI.getTriple().getEnvironment() == Env.getEnvironment();
 }
 
+static void remapMacroPath(
+SmallString<128> ,
+const std::map>
+) {
+  for (const auto  : MacroPrefixMap)
+if (Path.startswith(Entry.first)) {
+  Path = (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
+}
+}
+
 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
 /// as a builtin macro, handle it and return the next token as 'Tok'.
 void Preprocessor::ExpandBuiltinMacro(Token ) {
@@ -1523,6 +1534,7 @@
 if (PLoc.isValid()) {
   FN += PLoc.getFilename();
   Lexer::Stringify(FN);
+  remapMacroPath(FN, PPOpts->MacroPrefixMap);
   OS << '"' << FN << '"';
 }
 Tok.setKind(tok::string_literal);
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -3090,6 +3090,9 @@
   for (const auto *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
 Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
 
+  for (const auto  : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ))
+Opts.MacroPrefixMap.insert(StringRef(A).split('='));
+
   if (const Arg *A = 

[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-10 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: lib/Lex/PPMacroExpansion.cpp:1460
+  for (const auto  : MacroPrefixMap)
+if (Path.startswith(Entry.first))
+  return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();

Lekensteyn wrote:
> joerg wrote:
> > Lekensteyn wrote:
> > > dankm wrote:
> > > > dankm wrote:
> > > > > joerg wrote:
> > > > > > This doesn't handle directory vs string prefix prefix correctly, 
> > > > > > does it? At the very least, it should have a test case :)
> > > > > Good catch. I expect not. But on the other hand, it's exactly what 
> > > > > debug-prefix-map does :)
> > > > > 
> > > > > I'll add test cases in a future review. My first goal was getting 
> > > > > something sort-of working.
> > > > There should be a test, but apparently the debug prefix map code also 
> > > > does this.
> > > > 
> > > > What do you think the correct behaviour should be? a string prefix, or 
> > > > a directory prefix?
> > > It should be a string prefix (like GCC)
> > I disagree. I consider it a bug in GCC that it is a string prefix. It's 
> > quite inconsistent as well.
> I agree with you, it should have been a directory prefix but GCC implements 
> it as a string prefix although the GCC documents it as:
> "-fdebug-prefix-map=old=new When compiling files residing in **directory 
> old**, record debugging information describing them as if the files resided 
> in **directory new** instead."
> 
> If you decide to fix `-fmacro-prefix-map` to use a directory prefix match, 
> then the `-fdebug-prefix-map` should also be fixed for consistency. What 
> about implementing the (buggy) GCC-compatible behavior first and then fixing 
> both cases in a future patch? (I don't mind when the buggy behavior is fixed, 
> I just want to see this functionality moving forward.)
> 
> Another edge case that I ran into is when using the option to drop 
> directories. When using `-ffile-prefix-map=/src=`, the command `cd /src && cc 
> /src/foo.c` would have `__FILE__` equal to `/foo.c`. As a native "fix", one 
> would try `-ffile-prefix-map=/src/=` which indeed produces `__FILE__` equal 
> to `foo.c`.
> 
> Matching with a trailing slash however fails to correctly remap some debug 
> information, namely `DW_AT_comp_dir`. This contains the working directory 
> (`/src`) which is not matched by `/src/`. By using a proper directory prefix 
> match, this would be nicely fixed.
Yes, I'm going to submit my code with tests, and hoist the prefix remapping 
(for debug-prefix-map and macro-prefix-map) into a common location. Most 
probably part of Path.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2019-01-10 Thread Dan McGregor via Phabricator via cfe-commits
dankm added a comment.

In D49466#1296790 , @ChristophBerg 
wrote:

> PostgreSQL 11 is now using LLVM to do JITing of SQL expressions. We'd need 
> this feature to strip the build directory off the .bc bitcode files so the 
> .deb packages build reproducibly.
>  @dankm: Are you still working on this? What can we do to help getting this 
> move forward?


I am. I'm about to push a new review. Sorry I missed this earlier.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D49466/new/

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-map and -ffile-prefix-map

2018-07-19 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 156295.
dankm retitled this revision from "Initial implementation of 
-fmacro-prefix-mapand -ffile-prefix-map" to "Initial implementation of 
-fmacro-prefix-map and -ffile-prefix-map".
dankm edited the summary of this revision.

Repository:
  rC Clang

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp

Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -28,6 +28,7 @@
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorLexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Lex/PTHLexer.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -1453,6 +1454,16 @@
   return TI.getTriple().getEnvironment() == Env.getEnvironment();
 }
 
+static void remapMacroPath(SmallString<128> ,
+   const std::map ) {
+  for (const auto  : MacroPrefixMap)
+if (Path.startswith(Entry.first)) {
+  Path = (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
+	  return;
+	}
+}
+
 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
 /// as a builtin macro, handle it and return the next token as 'Tok'.
 void Preprocessor::ExpandBuiltinMacro(Token ) {
@@ -1519,6 +1530,7 @@
 SmallString<128> FN;
 if (PLoc.isValid()) {
   FN += PLoc.getFilename();
+  remapMacroPath(FN, PPOpts->MacroPrefixMap);
   Lexer::Stringify(FN);
   OS << '"' << FN << '"';
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2847,6 +2847,9 @@
   for (const auto *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
 Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
 
+  for (const auto  : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ))
+Opts.MacroPrefixMap.insert(StringRef(A).split('='));
+
   if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {
 StringRef Value(A->getValue());
 size_t Comma = Value.find(',');
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -606,12 +606,28 @@
 
 /// Add a CC1 and CC1AS option to specify the debug file path prefix map.
 static void addDebugPrefixMapArg(const Driver , const ArgList , ArgStringList ) {
-  for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
+  for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
+options::OPT_fdebug_prefix_map_EQ)) {
 StringRef Map = A->getValue();
-if (Map.find('=') == StringRef::npos)
-  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
-else
-  CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
+if (Map.find('=') == StringRef::npos) {
+  D.Diag(diag::err_drv_invalid_argument_to_prefix_map) << Map << "debug";
+  continue;
+}
+CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
+A->claim();
+  }
+}
+
+/// Add a CC1 option to specify the macro file path prefix map.
+static void addMacroPrefixMapArg(const Driver , const ArgList , ArgStringList ) {
+  for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
+options::OPT_fmacro_prefix_map_EQ)) {
+StringRef Map = A->getValue();
+if (Map.find('=') == StringRef::npos) {
+  D.Diag(diag::err_drv_invalid_argument_to_prefix_map) << Map << "macro";
+  continue;
+}
+CmdArgs.push_back(Args.MakeArgString("-fmacro-prefix-map=" + Map));
 A->claim();
   }
 }
@@ -1223,6 +1239,8 @@
 // For IAMCU add special include arguments.
 getToolChain().AddIAMCUIncludeArgs(Args, CmdArgs);
   }
+
+  addMacroPrefixMapArg(D, Args, CmdArgs);
 }
 
 // FIXME: Move to target hook.
Index: include/clang/Lex/PreprocessorOptions.h
===
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -167,6 +167,9 @@
   /// build it again.
   std::shared_ptr FailedModules;
 
+  /// A prefix map for __FILE__ and __BASEFILE__
+  std::map MacroPrefixMap;
+
 public:
   PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
 
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1755,10 +1755,16 @@
   Flags<[CC1Option]>, HelpText<"Provide minimal debug info in the object/executable to 

[PATCH] D49466: Initial implementation of -fmacro-prefix-mapand -ffile-prefix-map

2018-07-19 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: include/clang/Lex/PreprocessorOptions.h:171
+  /// A prefix map for __FILE__ and __BASEFILE__
+  std::map MacroPrefixMap;
+

erichkeane wrote:
> erichkeane wrote:
> > It seems this can be StringRefs as well.
> Did you miss this one?  Or is there a good reason these cannot be stringrefs?
I didn't miss it. StringRefs here don't survive. The function that adds them to 
the map creates temporary strings, that go away once that function ends causing 
StringRefs to dangle. std::string keeps copies.



Comment at: lib/Driver/ToolChains/Clang.cpp:616
+}
 else
   CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));

erichkeane wrote:
> With the continue above, 'else' is unnecessary/against coding standard.
Next diff will have that.



Comment at: lib/Lex/PPMacroExpansion.cpp:1457
 
+static std::string remapMacroPath(StringRef Path,
+   const std::map Did clang-format do this formatting?  It looks REALLY weird...
No, that's my text editor. I'll fix it.



Comment at: lib/Lex/PPMacroExpansion.cpp:1532
   FN += PLoc.getFilename();
+  // TODO remap macro prefix here
+  FN = remapMacroPath(FN, PPOpts->MacroPrefixMap);

erichkeane wrote:
> First, comments end in a period.  Second, isn't that what the next line does?
Yes, old comment is old ;)



Comment at: lib/Lex/PPMacroExpansion.cpp:1460
+  for (const auto  : MacroPrefixMap)
+if (Path.startswith(Entry.first))
+  return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();

dankm wrote:
> joerg wrote:
> > This doesn't handle directory vs string prefix prefix correctly, does it? 
> > At the very least, it should have a test case :)
> Good catch. I expect not. But on the other hand, it's exactly what 
> debug-prefix-map does :)
> 
> I'll add test cases in a future review. My first goal was getting something 
> sort-of working.
There should be a test, but apparently the debug prefix map code also does this.

What do you think the correct behaviour should be? a string prefix, or a 
directory prefix?



Comment at: lib/Lex/PPMacroExpansion.cpp:1528
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
-SmallString<128> FN;
+std::string FN;
 if (PLoc.isValid()) {

erichkeane wrote:
> dankm wrote:
> > erichkeane wrote:
> > > This change shouldn't be necessary, SmallString is still likely the right 
> > > answer here.
> > I tried that long ago. It didn't work, I don't remember exactly why. But I 
> > agree that SmallString should be enough. I'll dig more.
> Just noting to handle this before approval.
Yup, with some changes to remapMacroPath SmallString works fine.


Repository:
  rC Clang

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-mapand -ffile-prefix-map

2018-07-18 Thread Dan McGregor via Phabricator via cfe-commits
dankm updated this revision to Diff 156164.
dankm retitled this revision from "Initial implementation of -fmacro-prefix-map
and -ffile-prefix-map" to "Initial implementation of -fmacro-prefix-mapand 
-ffile-prefix-map".
dankm added a comment.

Address some of the comments by erichkeane and joerg.


Repository:
  rC Clang

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp

Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -28,6 +28,7 @@
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorLexer.h"
+#include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Lex/PTHLexer.h"
 #include "clang/Lex/Token.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -1453,6 +1454,15 @@
   return TI.getTriple().getEnvironment() == Env.getEnvironment();
 }
 
+static std::string remapMacroPath(StringRef Path,
+   const std::map ) {
+  for (const auto  : MacroPrefixMap)
+if (Path.startswith(Entry.first))
+  return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
+  return Path.str();
+}
+
 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
 /// as a builtin macro, handle it and return the next token as 'Tok'.
 void Preprocessor::ExpandBuiltinMacro(Token ) {
@@ -1516,9 +1526,11 @@
 }
 
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
-SmallString<128> FN;
+std::string FN;
 if (PLoc.isValid()) {
   FN += PLoc.getFilename();
+  // TODO remap macro prefix here
+  FN = remapMacroPath(FN, PPOpts->MacroPrefixMap);
   Lexer::Stringify(FN);
   OS << '"' << FN << '"';
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2845,6 +2845,9 @@
   for (const auto *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
 Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
 
+  for (const auto  : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ))
+Opts.MacroPrefixMap.insert(StringRef(A).split('='));
+
   if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {
 StringRef Value(A->getValue());
 size_t Comma = Value.find(',');
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -606,16 +606,34 @@
 
 /// Add a CC1 and CC1AS option to specify the debug file path prefix map.
 static void addDebugPrefixMapArg(const Driver , const ArgList , ArgStringList ) {
-  for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
+  for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
+options::OPT_fdebug_prefix_map_EQ)) {
 StringRef Map = A->getValue();
-if (Map.find('=') == StringRef::npos)
+if (Map.find('=') == StringRef::npos) {
   D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
+  continue;
+}
 else
   CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
 A->claim();
   }
 }
 
+/// Add a CC1 option to specify the macro file path prefix map.
+static void addMacroPrefixMapArg(const Driver , const ArgList , ArgStringList ) {
+  for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ,
+options::OPT_fmacro_prefix_map_EQ)) {
+StringRef Map = A->getValue();
+if (Map.find('=') == StringRef::npos) {
+  D.Diag(diag::err_drv_invalid_argument_to_fmacro_prefix_map) << Map;
+  continue;
+}
+else
+  CmdArgs.push_back(Args.MakeArgString("-fmacro-prefix-map=" + Map));
+A->claim();
+  }
+}
+
 /// Vectorize at all optimization levels greater than 1 except for -Oz.
 /// For -Oz the loop vectorizer is disable, while the slp vectorizer is enabled.
 static bool shouldEnableVectorizerAtOLevel(const ArgList , bool isSlpVec) {
@@ -1223,6 +1241,8 @@
 // For IAMCU add special include arguments.
 getToolChain().AddIAMCUIncludeArgs(Args, CmdArgs);
   }
+
+  addMacroPrefixMapArg(D, Args, CmdArgs);
 }
 
 // FIXME: Move to target hook.
Index: include/clang/Lex/PreprocessorOptions.h
===
--- include/clang/Lex/PreprocessorOptions.h
+++ include/clang/Lex/PreprocessorOptions.h
@@ -167,6 +167,9 @@
   /// build it again.
   std::shared_ptr FailedModules;
 
+  /// A prefix map for __FILE__ and __BASEFILE__
+  std::map MacroPrefixMap;
+
 public:
   PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
 
Index: 

[PATCH] D49466: Initial implementation of -fmacro-prefix-mapand -ffile-prefix-map

2018-07-18 Thread Dan McGregor via Phabricator via cfe-commits
dankm added inline comments.



Comment at: lib/Driver/ToolChains/Clang.cpp:609
 static void addDebugPrefixMapArg(const Driver , const ArgList , 
ArgStringList ) {
+  for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ)) {
+StringRef Map = A->getValue();

joerg wrote:
> I find it confusing that `-ffile_prefix_map` implies `-fdebug-prefix-map`. 
> I'm not sure that is desirable in every case. It seems better to have a 
> combined option that explicitly does both.
-ffile-prefix-map is the combined option. -fmacro-prefix-map is the 
preprocessor option, and -fdebug-prefix-map is the codegen option.



Comment at: lib/Driver/ToolChains/Clang.cpp:628
+/// Add a CC1 option to specify the macro file path prefix map.
+static void addMacroPrefixMapArg(const Driver , const ArgList , 
ArgStringList ) {
+  for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ)) {

joerg wrote:
> erichkeane wrote:
> > See advice above.
> > 
> > Additionally/alternatively, I wonder if these two functions could be 
> > trivially combined.
> Or at least the for loop could be refactored into a small helper function 
> that takes the option name, output option and error as argument.
Good ideas. I'll look into them.



Comment at: lib/Driver/ToolChains/Clang.cpp:1255
+
+  addMacroPrefixMapArg(D, Args, CmdArgs);
 }

erichkeane wrote:
> Is there a good reason for this to not live with the call to 
> addDebugPrefixMapArg?
Mostly because this is the function that adds preprocessor specific options. 
There's no other reason why it couldn't be done alongside addDebugPrefixMapArg 
in this file.



Comment at: lib/Frontend/CompilerInvocation.cpp:2848
 
+  for (const auto  : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ))
+  {

erichkeane wrote:
> Again, this is so much like the debug-prefix otpion, it should probably just 
> be right next to it.
> 
> Additionally, we don't use curley brackets on single-line bodies.
This is here because it's a preprocessor option. This function handles those. 
The DebugPrefixMap handling is a codegen option.



Comment at: lib/Lex/PPMacroExpansion.cpp:1457
+static std::string remapMacroPath(StringRef Path,
+   llvm::SmallDenseMap ) {

erichkeane wrote:
> make MacroPrefixMap const.
I shall.



Comment at: lib/Lex/PPMacroExpansion.cpp:1460
+  for (const auto  : MacroPrefixMap)
+if (Path.startswith(Entry.first))
+  return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();

joerg wrote:
> This doesn't handle directory vs string prefix prefix correctly, does it? At 
> the very least, it should have a test case :)
Good catch. I expect not. But on the other hand, it's exactly what 
debug-prefix-map does :)

I'll add test cases in a future review. My first goal was getting something 
sort-of working.



Comment at: lib/Lex/PPMacroExpansion.cpp:1528
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
-SmallString<128> FN;
+std::string FN;
 if (PLoc.isValid()) {

erichkeane wrote:
> This change shouldn't be necessary, SmallString is still likely the right 
> answer here.
I tried that long ago. It didn't work, I don't remember exactly why. But I 
agree that SmallString should be enough. I'll dig more.



Comment at: lib/Lex/Preprocessor.cpp:160
+
+  for (const auto  : this->PPOpts->MacroPrefixMap)
+MacroPrefixMap[KV.first] = KV.second;

erichkeane wrote:
> I'm unconvinced that this is necessary.  ExpandBuiltinMacro is in 
> Preprocessor, so it has access to PPOpts directly.
It has access to PPOpts, but the implementation file doesn't have a full 
definition of PreprocessorOptions. I could add that to this file, then this 
becomes redundant.


Repository:
  rC Clang

https://reviews.llvm.org/D49466



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D49466: Initial implementation of -fmacro-prefix-mapand -ffile-prefix-map

2018-07-17 Thread Dan McGregor via Phabricator via cfe-commits
dankm created this revision.
Herald added a subscriber: cfe-commits.

GCC 8 implements -fmacro-prefix-map. Like -fdebug-prefix-map
it replaces a string prefix for the __FILE__ macro.
-ffile-prefix-map is the union of -fdebug-prefix-map and
-fmacro-prefix-map


Repository:
  rC Clang

https://reviews.llvm.org/D49466

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/Options.td
  include/clang/Lex/Preprocessor.h
  include/clang/Lex/PreprocessorOptions.h
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Lex/PPMacroExpansion.cpp
  lib/Lex/Preprocessor.cpp

Index: lib/Lex/Preprocessor.cpp
===
--- lib/Lex/Preprocessor.cpp
+++ lib/Lex/Preprocessor.cpp
@@ -156,6 +156,9 @@
 
   if (this->PPOpts->GeneratePreamble)
 PreambleConditionalStack.startRecording();
+
+  for (const auto  : this->PPOpts->MacroPrefixMap)
+MacroPrefixMap[KV.first] = KV.second;
 }
 
 Preprocessor::~Preprocessor() {
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -1453,6 +1453,15 @@
   return TI.getTriple().getEnvironment() == Env.getEnvironment();
 }
 
+static std::string remapMacroPath(StringRef Path,
+   llvm::SmallDenseMap ) {
+  for (const auto  : MacroPrefixMap)
+if (Path.startswith(Entry.first))
+  return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
+  return Path.str();
+}
+
 /// ExpandBuiltinMacro - If an identifier token is read that is to be expanded
 /// as a builtin macro, handle it and return the next token as 'Tok'.
 void Preprocessor::ExpandBuiltinMacro(Token ) {
@@ -1516,9 +1525,11 @@
 }
 
 // Escape this filename.  Turn '\' -> '\\' '"' -> '\"'
-SmallString<128> FN;
+std::string FN;
 if (PLoc.isValid()) {
   FN += PLoc.getFilename();
+  // TODO remap macro prefix here
+  FN = remapMacroPath(FN, MacroPrefixMap);
   Lexer::Stringify(FN);
   OS << '"' << FN << '"';
 }
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -2845,6 +2845,11 @@
   for (const auto *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
 Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
 
+  for (const auto  : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ))
+  {
+Opts.MacroPrefixMap.insert(StringRef(A).split('='));
+  }
+
   if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {
 StringRef Value(A->getValue());
 size_t Comma = Value.find(',');
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -606,6 +606,14 @@
 
 /// Add a CC1 and CC1AS option to specify the debug file path prefix map.
 static void addDebugPrefixMapArg(const Driver , const ArgList , ArgStringList ) {
+  for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ)) {
+StringRef Map = A->getValue();
+if (Map.find('=') == StringRef::npos)
+  D.Diag(diag::err_drv_invalid_argument_to_fdebug_prefix_map) << Map;
+else
+  CmdArgs.push_back(Args.MakeArgString("-fdebug-prefix-map=" + Map));
+A->claim();
+  }
   for (const Arg *A : Args.filtered(options::OPT_fdebug_prefix_map_EQ)) {
 StringRef Map = A->getValue();
 if (Map.find('=') == StringRef::npos)
@@ -616,6 +624,26 @@
   }
 }
 
+/// Add a CC1 option to specify the macro file path prefix map.
+static void addMacroPrefixMapArg(const Driver , const ArgList , ArgStringList ) {
+  for (const Arg *A : Args.filtered(options::OPT_ffile_prefix_map_EQ)) {
+StringRef Map = A->getValue();
+if (Map.find('=') == StringRef::npos)
+  D.Diag(diag::err_drv_invalid_argument_to_fmacro_prefix_map) << Map;
+else
+  CmdArgs.push_back(Args.MakeArgString("-fmacro-prefix-map=" + Map));
+A->claim();
+  }
+  for (const Arg *A : Args.filtered(options::OPT_fmacro_prefix_map_EQ)) {
+StringRef Map = A->getValue();
+if (Map.find('=') == StringRef::npos)
+  D.Diag(diag::err_drv_invalid_argument_to_fmacro_prefix_map) << Map;
+else
+  CmdArgs.push_back(Args.MakeArgString("-fmacro-prefix-map=" + Map));
+A->claim();
+  }
+}
+
 /// Vectorize at all optimization levels greater than 1 except for -Oz.
 /// For -Oz the loop vectorizer is disable, while the slp vectorizer is enabled.
 static bool shouldEnableVectorizerAtOLevel(const ArgList , bool isSlpVec) {
@@ -1223,6 +1251,8 @@
 // For IAMCU add special include arguments.
 getToolChain().AddIAMCUIncludeArgs(Args, CmdArgs);
   }
+
+  addMacroPrefixMapArg(D, Args, CmdArgs);
 }
 
 // FIXME: Move to target hook.
Index: include/clang/Lex/PreprocessorOptions.h