[clang-tools-extra] [clang-tidy] Optimize realpath in readability-identifier-naming (PR #92659)

2024-05-23 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin approved this pull request.


https://github.com/llvm/llvm-project/pull/92659
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Modules] Enable MS Windows test for implicit-module-no-timestamp.cpp (PR #91738)

2024-05-11 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin approved this pull request.


https://github.com/llvm/llvm-project/pull/91738
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Modules] Enable MS Windows test for implicit-module-no-timestamp.cpp (PR #91738)

2024-05-11 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin reopened 
https://github.com/llvm/llvm-project/pull/91738
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Modules] Enable MS Windows test for implicit-module-no-timestamp.cpp (PR #91738)

2024-05-11 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin closed 
https://github.com/llvm/llvm-project/pull/91738
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix Hungarian Prefix in readability-identifier-naming (PR #84236)

2024-03-08 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin approved this pull request.


https://github.com/llvm/llvm-project/pull/84236
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix Hungarian Prefix in readability-identifier-naming (PR #84236)

2024-03-08 Thread Dmitry Polukhin via cfe-commits


@@ -229,7 +229,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-identifier-naming
   ` check in 
`GetConfigPerFile`
-  mode by resolving symbolic links to header files.
+  mode by resolving symbolic links to header files. Fixed handling of Hungarian

dmpolukhin wrote:

OK, if you think it makes Release Notes more readable.

https://github.com/llvm/llvm-project/pull/84236
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix Hungarian Prefix in readability-identifier-naming (PR #84236)

2024-03-07 Thread Dmitry Polukhin via cfe-commits


@@ -229,7 +229,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-identifier-naming
   ` check in 
`GetConfigPerFile`
-  mode by resolving symbolic links to header files.
+  mode by resolving symbolic links to header files. Fixed handling of Hungarian

dmpolukhin wrote:

> One entry per check. One sentence per change.

I don't think it is common practice, see 
https://releases.llvm.org/17.0.1/tools/clang/tools/extra/docs/ReleaseNotes.html 
I see 6 entries about `readability-identifier-naming`. Does it change recently 
and documented somewhere?

https://github.com/llvm/llvm-project/pull/84236
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix Hungarian Prefix in readability-identifier-naming (PR #84236)

2024-03-07 Thread Dmitry Polukhin via cfe-commits


@@ -229,7 +229,8 @@ Changes in existing checks
 
 - Improved :doc:`readability-identifier-naming
   ` check in 
`GetConfigPerFile`
-  mode by resolving symbolic links to header files.
+  mode by resolving symbolic links to header files. Fixed handling of Hungarian

dmpolukhin wrote:

I think it should be separate item in Release notes unrelated to symlinks.

https://github.com/llvm/llvm-project/pull/84236
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Fix Hungarian Prefix in readability-identifier-naming (PR #84236)

2024-03-07 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

I'm not an expert in Hungarian naming but from what I know changes looks good 
to me. Just nit in release notes.

https://github.com/llvm/llvm-project/pull/84236
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-19 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin closed 
https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/81985

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH 1/3] [clang-tidy][readability-identifier-naming] Resolve
 symlinks for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
new file mode 100644
index 00..72926bff908df8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
@@ -0,0 +1,15 @@
+// Specify `-std=c++20` to run test only once becuase test expects changes
+// in the header file so it fails if runs multiple times with different
+// `-std` flags as check_clang_tidy doesn by default.
+//
+// RUN: rm 

[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/81985

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH 1/3] [clang-tidy][readability-identifier-naming] Resolve
 symlinks for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
new file mode 100644
index 00..72926bff908df8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
@@ -0,0 +1,15 @@
+// Specify `-std=c++20` to run test only once becuase test expects changes
+// in the header file so it fails if runs multiple times with different
+// `-std` flags as check_clang_tidy doesn by default.
+//
+// RUN: rm 

[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

> This problem seems like it should be handled globally, not in a single 
> specific check. IIUC any check that reads options from the .clang-tidy file 
> is affected.

Yes, but the majority of checks ignores the problem but 
`readability-identifier-naming` handles styles per file so improving logic here 
makes sense to me. About general issue with checks being selected by main file 
there are several discussions as far as I know without clear direction that all 
agreed.

> What build system are you using, bazel? We use it and don't have any 
> problems. If your build system creates a sandbox, you need to make sure 
> clang-tidy is also executed from within that sandbox.

I'm talking about Buck in some configurations but I think Bazel also should be 
affected. Projects with more unified styles usually significantly less affected 
because .clang-tidy config in higher level can be found and used in some cases.

https://github.com/llvm/llvm-project/pull/81985
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/81985

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH 1/2] [clang-tidy][readability-identifier-naming] Resolve
 symlinks for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
new file mode 100644
index 00..72926bff908df8
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp
@@ -0,0 +1,15 @@
+// Specify `-std=c++20` to run test only once becuase test expects changes
+// in the header file so it fails if runs multiple times with different
+// `-std` flags as check_clang_tidy doesn by default.
+//
+// RUN: rm 

[clang-tools-extra] [clang-tidy][readability-identifier-naming] Resolve symlinks for checking style for file (PR #81985)

2024-02-16 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin created 
https://github.com/llvm/llvm-project/pull/81985

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools

>From ddafb4672e1a481d4a9556ebe31ca9a07e1f3569 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Fri, 16 Feb 2024 03:51:07 -0800
Subject: [PATCH] [clang-tidy][readability-identifier-naming] Resolve symlinks
 for checking style for file

Summary:
Some build systems create symlinks in a temporary build directory for headers 
in the source tree for isolation purposes. These symlinks prevent 
`readability-identifier-naming` detecting issues and applying fixes. Without 
this fix clang-tidy is checking .clang-tidy config file in a temporary 
directory instead of source source location.

If you think this change may have undesired results, I can add an option to 
activate it only when users enable symlink resolution explicitly.

Test Plan: check-clang-tools
---
 .../readability/IdentifierNamingCheck.cpp |  7 +--
 .../Inputs/identifier-naming/symlink/build/test.h |  1 +
 .../identifier-naming/symlink/include/.clang-tidy |  4 
 .../identifier-naming/symlink/include/test.h  |  1 +
 .../readability/identifier-naming-symlink.cpp | 15 +++
 5 files changed, 26 insertions(+), 2 deletions(-)
 create mode 12 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming-symlink.cpp

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 5db9e99ab23708..335c3de25b861b 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -1408,13 +1408,16 @@ const IdentifierNamingCheck::FileStyle &
 IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
   if (!GetConfigPerFile)
 return *MainFileStyle;
-  StringRef Parent = llvm::sys::path::parent_path(FileName);
+
+  SmallString<128> RealFileName;
+  llvm::sys::fs::real_path(FileName, RealFileName);
+  StringRef Parent = llvm::sys::path::parent_path(RealFileName);
   auto Iter = NamingStylesCache.find(Parent);
   if (Iter != NamingStylesCache.end())
 return Iter->getValue();
 
   llvm::StringRef CheckName = getID();
-  ClangTidyOptions Options = Context->getOptionsForFile(FileName);
+  ClangTidyOptions Options = Context->getOptionsForFile(RealFileName);
   if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
 auto It = NamingStylesCache.try_emplace(
 Parent,
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
new file mode 12
index 00..de218fbfa4662a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/build/test.h
@@ -0,0 +1 @@
+../include/test.h
\ No newline at end of file
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
new file mode 100644
index 00..296550f3aab1eb
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/.clang-tidy
@@ -0,0 +1,4 @@
+Checks: readability-identifier-naming
+CheckOptions:
+  readability-identifier-naming.GlobalConstantCase: CamelCase
+  readability-identifier-naming.GlobalConstantPrefix: k
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
new file mode 100644
index 00..f3560e4e50b9ed
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/Inputs/identifier-naming/symlink/include/test.h
@@ -0,0 +1 @@
+const int global_const = 5;
diff --git 

[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-08 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

> So the intent of the current ordering was to allow creating a toolchain by 
> placing the libc++ headers alongside Clang, as is typically done (and 
> exceptionally not done on Apple platforms). On Apple platforms, you basically 
> always specify a sysroot, either explicitly or implicitly (via env vars). You 
> have to, since the SDK is where you find everything you need to compile even 
> the most basic program (like our libc headers).

@ldionne thank you for explaining the reasoning behind the decision. 
Unfortunately, it makes the life of a non-system compilers and clang-tools much 
more complicated on Apple platforms. They usually don’t have system headers 
shipped with them so they rely on one provided in SDK. My interest in this 
issue started from clang-tidy that was not able to find cxxabi.h in the path 
specified with -isysroot due to the new order introduced in 
https://reviews.llvm.org/D89001. But it seems my use case will be broken anyway 
if SDK stops providing libc++ headers. Is it the eventual future? If it is the 
case, checking -sysroot first will be only a temporary solution. I still think 
that it makes sense for the time being but also we need to think about a long 
term solution for non-system compilers and clang-tools. Perhaps it should be 
configured at build time if you are building the system default compiler or 
additional tools shipped separately.

https://github.com/llvm/llvm-project/pull/80524
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-07 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

@ldionne if downstream is catching upstream, I would love to discuss rationale 
behind ignoring command line option. I asked this question several times and 
haven't got answer. Original [diff](https://reviews.llvm.org/D89001) that 
introduced this behavior also didn't explain why new behavior is "intended" and 
better than old one. Instead of resolving case of two headers it actually 
prevents finding header that exists and path is specified in command line.

https://github.com/llvm/llvm-project/pull/80524
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-05 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

@ldionne what about fixing upstream behavior to match actual system compiler 
behavior now and when/as soon as we have new behavior in Apple compiler fix it 
again in newer clang versions? Moreover as I pointed out Apple compiler 
behavior is problematic for clang-tools and clangd because it basically ignores 
option passed in command line.

https://github.com/llvm/llvm-project/pull/80524
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Match -isysroot behaviour with system compiler on Darwin (PR #80524)

2024-02-05 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

@ldionne I also haven't see Apple compiler that matches upstream behavior. In 
https://reviews.llvm.org/D157283#4648242, you mentioned that "Xcode 15 RC" 
should be such compiler and checked it and couple version after that and none 
of them matched upstream so I decided to wait and forgot about the issue. 
@drodriguez thank you for rising it again!

https://github.com/llvm/llvm-project/pull/80524
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2024-02-05 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

Pushed as https://github.com/llvm/llvm-project/pull/79466

https://github.com/llvm/llvm-project/pull/70801
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2024-02-05 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin closed 
https://github.com/llvm/llvm-project/pull/70801
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [clang-tools-extra] Apply format only if --format is specified (PR #79466)

2024-02-05 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin closed 
https://github.com/llvm/llvm-project/pull/79466
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang-tools-extra] Apply format only if --format is specified (PR #79466)

2024-02-01 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

@AaronBallman @bcardosolopes please take a look.

https://github.com/llvm/llvm-project/pull/79466
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [clang-tools-extra] Apply format only if --format is specified (PR #79466)

2024-02-01 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/79466

>From 67a266e7bc5682d5f674c0424858ba86f7c9a192 Mon Sep 17 00:00:00 2001
From: Kugan <34810920+kug...@users.noreply.github.com>
Date: Tue, 31 Oct 2023 12:12:10 +
Subject: [PATCH] Apply format only if --format is specified

clang-apply-replacements used to apply format even without --format is 
specified. This because, methods like createReplacementsForHeaders only takes 
the Spec.Style and would re-order the headers even when it was not requested. 
The fix is to set up Spec.Style only if --format is provided.

Also added note to ReleaseNotes.rst

Based on https://github.com/llvm/llvm-project/pull/70801
---
 .../tool/ClangApplyReplacementsMain.cpp|  2 +-
 clang-tools-extra/docs/ReleaseNotes.rst|  7 +++
 .../Inputs/format_header/no.cpp| 10 ++
 .../Inputs/format_header/no.yaml   | 14 ++
 .../Inputs/format_header/yes.cpp   | 10 ++
 .../Inputs/format_header/yes.yaml  | 14 ++
 .../clang-apply-replacements/format-header.cpp | 13 +
 7 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.cpp
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.yaml
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.cpp
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.yaml
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/format-header.cpp

diff --git 
a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
 
b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
index 9331898bf2570..68b5743c6540f 100644
--- 
a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ 
b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -141,9 +141,9 @@ int main(int argc, char **argv) {
 
   tooling::ApplyChangesSpec Spec;
   Spec.Cleanup = true;
-  Spec.Style = FormatStyle;
   Spec.Format = DoFormat ? tooling::ApplyChangesSpec::kAll
  : tooling::ApplyChangesSpec::kNone;
+  Spec.Style = DoFormat ? FormatStyle : format::getNoStyle();
 
   for (const auto  : Changes) {
 FileEntryRef Entry = FileChange.first;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fd2cba4e4f463..228c9c1762321 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -109,6 +109,13 @@ Changes in existing checks
 Removed checks
 ^^
 
+Miscellaneous
+^
+
+- Fixed incorrect apply format in clang-apply-repalcements when no `--format`
+  option is specified. Now clang-apply-repalcements applies format only with
+  the option.
+
 Improvements to include-fixer
 -
 
diff --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.cpp 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.cpp
new file mode 100644
index 0..140e266200b72
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.cpp
@@ -0,0 +1,10 @@
+#include 
+// CHECK: #include 
+// CHECK-NEXT: #include 
+// CHECK-NEXT: #include "bar.h"
+#include 
+#include "foo.h"
+#include "bar.h"
+
+void foo() {
+}
diff --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.yaml 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.yaml
new file mode 100644
index 0..172b5ee1f1ac5
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.yaml
@@ -0,0 +1,14 @@
+---
+MainSourceFile:  no.cpp
+Diagnostics:
+  - DiagnosticName:  test-header-format
+DiagnosticMessage:
+  Message: Fix
+  FilePath: $(path)/no.cpp
+  FileOffset: 36
+  Replacements:
+- FilePath:$(path)/no.cpp
+  Offset:  36
+  Length:  17
+  ReplacementText: ""
+...
diff --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.cpp 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.cpp
new file mode 100644
index 0..20e6b90c39b63
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.cpp
@@ -0,0 +1,10 @@
+#include 
+// CHECK: #include "bar.h"
+// CHECK-NEXT: #include 
+// CHECK-NEXT: #include 
+#include 
+#include "foo.h"
+#include "bar.h"
+
+void foo() {
+}
diff --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.yaml 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.yaml
new file mode 100644
index 

[clang-tools-extra] Apply format only if --format is specified (PR #79466)

2024-01-25 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin created 
https://github.com/llvm/llvm-project/pull/79466

clang-apply-replacements used to apply format even without --format is 
specified. This because, methods like createReplacementsForHeaders only takes 
the Spec.Style and would re-order the headers even when it was not requested. 
The fix is to set up Spec.Style only if --format is provided.

Also added note to ReleaseNotes.rst

Based on https://github.com/llvm/llvm-project/pull/70801

>From 67a266e7bc5682d5f674c0424858ba86f7c9a192 Mon Sep 17 00:00:00 2001
From: Kugan <34810920+kug...@users.noreply.github.com>
Date: Tue, 31 Oct 2023 12:12:10 +
Subject: [PATCH] Apply format only if --format is specified

clang-apply-replacements used to apply format even without --format is 
specified. This because, methods like createReplacementsForHeaders only takes 
the Spec.Style and would re-order the headers even when it was not requested. 
The fix is to set up Spec.Style only if --format is provided.

Also added note to ReleaseNotes.rst

Based on https://github.com/llvm/llvm-project/pull/70801
---
 .../tool/ClangApplyReplacementsMain.cpp|  2 +-
 clang-tools-extra/docs/ReleaseNotes.rst|  7 +++
 .../Inputs/format_header/no.cpp| 10 ++
 .../Inputs/format_header/no.yaml   | 14 ++
 .../Inputs/format_header/yes.cpp   | 10 ++
 .../Inputs/format_header/yes.yaml  | 14 ++
 .../clang-apply-replacements/format-header.cpp | 13 +
 7 files changed, 69 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.cpp
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.yaml
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.cpp
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.yaml
 create mode 100644 
clang-tools-extra/test/clang-apply-replacements/format-header.cpp

diff --git 
a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
 
b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
index 9331898bf2570e6..68b5743c6540f8a 100644
--- 
a/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
+++ 
b/clang-tools-extra/clang-apply-replacements/tool/ClangApplyReplacementsMain.cpp
@@ -141,9 +141,9 @@ int main(int argc, char **argv) {
 
   tooling::ApplyChangesSpec Spec;
   Spec.Cleanup = true;
-  Spec.Style = FormatStyle;
   Spec.Format = DoFormat ? tooling::ApplyChangesSpec::kAll
  : tooling::ApplyChangesSpec::kNone;
+  Spec.Style = DoFormat ? FormatStyle : format::getNoStyle();
 
   for (const auto  : Changes) {
 FileEntryRef Entry = FileChange.first;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fd2cba4e4f463be..228c9c176232161 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -109,6 +109,13 @@ Changes in existing checks
 Removed checks
 ^^
 
+Miscellaneous
+^
+
+- Fixed incorrect apply format in clang-apply-repalcements when no `--format`
+  option is specified. Now clang-apply-repalcements applies format only with
+  the option.
+
 Improvements to include-fixer
 -
 
diff --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.cpp 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.cpp
new file mode 100644
index 000..140e266200b72f4
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.cpp
@@ -0,0 +1,10 @@
+#include 
+// CHECK: #include 
+// CHECK-NEXT: #include 
+// CHECK-NEXT: #include "bar.h"
+#include 
+#include "foo.h"
+#include "bar.h"
+
+void foo() {
+}
diff --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.yaml 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.yaml
new file mode 100644
index 000..172b5ee1f1ac5a1
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/no.yaml
@@ -0,0 +1,14 @@
+---
+MainSourceFile:  no.cpp
+Diagnostics:
+  - DiagnosticName:  test-header-format
+DiagnosticMessage:
+  Message: Fix
+  FilePath: $(path)/no.cpp
+  FileOffset: 36
+  Replacements:
+- FilePath:$(path)/no.cpp
+  Offset:  36
+  Length:  17
+  ReplacementText: ""
+...
diff --git 
a/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.cpp 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/format_header/yes.cpp
new file mode 100644
index 000..20e6b90c39b6393
--- /dev/null
+++ 

[clang-tools-extra] [clang-apply-replacements] Apply format only if --format is specified (PR #70801)

2024-01-18 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

@kuganv do you have cycles to work on this issue? If not, I can commandeer this 
pull requests and update release notes. Please let me know what is your 
preference.

https://github.com/llvm/llvm-project/pull/70801
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Expand response files before CDB interpolation (PR #75753)

2023-12-18 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/75753

>From 957951483dab19b0982a5dbe7d5370bd9061d931 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Sun, 17 Dec 2023 14:11:11 -0800
Subject: [PATCH 1/3] [clangd] Expand response files before CDB interpolation

Summary:

After https://reviews.llvm.org/D143436 response files stopped working
with CDB interpolation. It has happened because interpolation removes
all unknwn flags and extra input files. Response file is treated as an
extra input because it is not a flag. Moreover inference needs full
command line for driver mode and file type detection so all response
files have to be expanded for correct inference.

This patch implements the simplest approach that add extra response file
expansion before inference. Response file expansion in CommandMangler
keep working for CDB pushed via LSP and will do nothing if all response
files are already expanded.

Test Plan: TBD

Reviewers:

Subscribers:

Tasks: https://github.com/llvm/llvm-project/issues/69690

Tags:
---
 .../clangd/GlobalCompilationDatabase.cpp  | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index d1833759917a30..03ac1aa132d0bf 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -244,7 +244,16 @@ static std::unique_ptr
 parseJSON(PathRef Path, llvm::StringRef Data, std::string ) {
   if (auto CDB = tooling::JSONCompilationDatabase::loadFromBuffer(
   Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
-return tooling::inferMissingCompileCommands(std::move(CDB));
+// FS used for expanding response files.
+// FIXME: ExpandResponseFilesDatabase appears not to provide the usual
+// thread-safety guarantees, as the access to FS is not locked!
+// For now, use the real FS, which is known to be threadsafe (if we don't
+// use/change working directory, which ExpandResponseFilesDatabase 
doesn't).
+// NOTE: response files have to be expanded before inference because 
inference
+// needs full command line to check/fix driver mode and file type.
+auto FS = llvm::vfs::getRealFileSystem();
+return tooling::inferMissingCompileCommands(
+expandResponseFiles(std::move(CDB), std::move(FS)));
   }
   return nullptr;
 }

>From f4b1a02354fa5085caf50a460363e75e10afc3bb Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Sun, 17 Dec 2023 14:11:11 -0800
Subject: [PATCH 2/3] [clangd] Expand response files before CDB interpolation

Summary:

After https://reviews.llvm.org/D143436 response files stopped working
with CDB interpolation. It has happened because interpolation removes
all unknwn flags and extra input files. Response file is treated as an
extra input because it is not a flag. Moreover inference needs full
command line for driver mode and file type detection so all response
files have to be expanded for correct inference.

This patch partially reverts D143436 and add additional response file
expansion in OverlayCDB for CDBs pushed via LSP.

Test Plan: unittests

Reviewers:

Subscribers:

Tasks: https://github.com/llvm/llvm-project/issues/69690

Tags:
---
 clang-tools-extra/clangd/CompileCommands.cpp  | 15 --
 clang-tools-extra/clangd/CompileCommands.h|  3 --
 .../clangd/GlobalCompilationDatabase.cpp  | 24 +++--
 .../clangd/unittests/CompileCommandsTests.cpp | 15 --
 .../GlobalCompilationDatabaseTests.cpp| 53 +++
 5 files changed, 74 insertions(+), 36 deletions(-)

diff --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index f43ce928463b90..f4e8e7e74a3bee 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -28,7 +28,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
-#include "llvm/TargetParser/Host.h"
 #include 
 #include 
 #include 
@@ -187,12 +186,6 @@ static std::string resolveDriver(llvm::StringRef Driver, 
bool FollowSymlink,
 
 } // namespace
 
-CommandMangler::CommandMangler() {
-  Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
-  ? llvm::cl::TokenizeWindowsCommandLine
-  : llvm::cl::TokenizeGNUCommandLine;
-}
-
 CommandMangler CommandMangler::detect() {
   CommandMangler Result;
   Result.ClangPath = detectClangPath();
@@ -213,14 +206,6 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
   if (Cmd.empty())
 return;
 
-  // FS used for expanding response files.
-  // FIXME: ExpandResponseFiles appears not to provide the usual
-  // thread-safety guarantees, as the access to FS is not locked!
-  // For now, use the real FS, which is known to be threadsafe (if we don't
-  // use/change 

[clang-tools-extra] [clangd] Expand response files before CDB interpolation (PR #75753)

2023-12-18 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin edited 
https://github.com/llvm/llvm-project/pull/75753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Expand response files before CDB interpolation (PR #75753)

2023-12-18 Thread Dmitry Polukhin via cfe-commits

dmpolukhin wrote:

@HighCommander4 PTAL

https://github.com/llvm/llvm-project/pull/75753
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Expand response files before CDB interpolation (PR #75753)

2023-12-18 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin updated 
https://github.com/llvm/llvm-project/pull/75753

>From 957951483dab19b0982a5dbe7d5370bd9061d931 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Sun, 17 Dec 2023 14:11:11 -0800
Subject: [PATCH 1/2] [clangd] Expand response files before CDB interpolation

Summary:

After https://reviews.llvm.org/D143436 response files stopped working
with CDB interpolation. It has happened because interpolation removes
all unknwn flags and extra input files. Response file is treated as an
extra input because it is not a flag. Moreover inference needs full
command line for driver mode and file type detection so all response
files have to be expanded for correct inference.

This patch implements the simplest approach that add extra response file
expansion before inference. Response file expansion in CommandMangler
keep working for CDB pushed via LSP and will do nothing if all response
files are already expanded.

Test Plan: TBD

Reviewers:

Subscribers:

Tasks: https://github.com/llvm/llvm-project/issues/69690

Tags:
---
 .../clangd/GlobalCompilationDatabase.cpp  | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index d1833759917a30..03ac1aa132d0bf 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -244,7 +244,16 @@ static std::unique_ptr
 parseJSON(PathRef Path, llvm::StringRef Data, std::string ) {
   if (auto CDB = tooling::JSONCompilationDatabase::loadFromBuffer(
   Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
-return tooling::inferMissingCompileCommands(std::move(CDB));
+// FS used for expanding response files.
+// FIXME: ExpandResponseFilesDatabase appears not to provide the usual
+// thread-safety guarantees, as the access to FS is not locked!
+// For now, use the real FS, which is known to be threadsafe (if we don't
+// use/change working directory, which ExpandResponseFilesDatabase 
doesn't).
+// NOTE: response files have to be expanded before inference because 
inference
+// needs full command line to check/fix driver mode and file type.
+auto FS = llvm::vfs::getRealFileSystem();
+return tooling::inferMissingCompileCommands(
+expandResponseFiles(std::move(CDB), std::move(FS)));
   }
   return nullptr;
 }

>From f4b1a02354fa5085caf50a460363e75e10afc3bb Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Sun, 17 Dec 2023 14:11:11 -0800
Subject: [PATCH 2/2] [clangd] Expand response files before CDB interpolation

Summary:

After https://reviews.llvm.org/D143436 response files stopped working
with CDB interpolation. It has happened because interpolation removes
all unknwn flags and extra input files. Response file is treated as an
extra input because it is not a flag. Moreover inference needs full
command line for driver mode and file type detection so all response
files have to be expanded for correct inference.

This patch partially reverts D143436 and add additional response file
expansion in OverlayCDB for CDBs pushed via LSP.

Test Plan: unittests

Reviewers:

Subscribers:

Tasks: https://github.com/llvm/llvm-project/issues/69690

Tags:
---
 clang-tools-extra/clangd/CompileCommands.cpp  | 15 --
 clang-tools-extra/clangd/CompileCommands.h|  3 --
 .../clangd/GlobalCompilationDatabase.cpp  | 24 +++--
 .../clangd/unittests/CompileCommandsTests.cpp | 15 --
 .../GlobalCompilationDatabaseTests.cpp| 53 +++
 5 files changed, 74 insertions(+), 36 deletions(-)

diff --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index f43ce928463b90..f4e8e7e74a3bee 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -28,7 +28,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
-#include "llvm/TargetParser/Host.h"
 #include 
 #include 
 #include 
@@ -187,12 +186,6 @@ static std::string resolveDriver(llvm::StringRef Driver, 
bool FollowSymlink,
 
 } // namespace
 
-CommandMangler::CommandMangler() {
-  Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
-  ? llvm::cl::TokenizeWindowsCommandLine
-  : llvm::cl::TokenizeGNUCommandLine;
-}
-
 CommandMangler CommandMangler::detect() {
   CommandMangler Result;
   Result.ClangPath = detectClangPath();
@@ -213,14 +206,6 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
   if (Cmd.empty())
 return;
 
-  // FS used for expanding response files.
-  // FIXME: ExpandResponseFiles appears not to provide the usual
-  // thread-safety guarantees, as the access to FS is not locked!
-  // For now, use the real FS, which is known to be threadsafe (if we don't
-  // use/change 

[clang-tools-extra] [clangd] Expand response files before CDB interpolation (PR #75753)

2023-12-17 Thread Dmitry Polukhin via cfe-commits

https://github.com/dmpolukhin created 
https://github.com/llvm/llvm-project/pull/75753

Summary:

After https://reviews.llvm.org/D143436 response files stopped working with CDB 
interpolation. It has happened because interpolation removes all unknwn flags 
and extra input files. Response file is treated as an extra input because it is 
not a flag. Moreover inference needs full command line for driver mode and file 
type detection so all response files have to be expanded for correct inference.

This patch implements the simplest approach that add extra response file 
expansion before inference. Response file expansion in CommandMangler keep 
working for CDB pushed via LSP and will do nothing if all response files are 
already expanded.

Test Plan: TBD

Reviewers:

Subscribers:

Tasks: https://github.com/llvm/llvm-project/issues/69690

Tags:

>From 957951483dab19b0982a5dbe7d5370bd9061d931 Mon Sep 17 00:00:00 2001
From: Dmitry Polukhin 
Date: Sun, 17 Dec 2023 14:11:11 -0800
Subject: [PATCH] [clangd] Expand response files before CDB interpolation

Summary:

After https://reviews.llvm.org/D143436 response files stopped working
with CDB interpolation. It has happened because interpolation removes
all unknwn flags and extra input files. Response file is treated as an
extra input because it is not a flag. Moreover inference needs full
command line for driver mode and file type detection so all response
files have to be expanded for correct inference.

This patch implements the simplest approach that add extra response file
expansion before inference. Response file expansion in CommandMangler
keep working for CDB pushed via LSP and will do nothing if all response
files are already expanded.

Test Plan: TBD

Reviewers:

Subscribers:

Tasks: https://github.com/llvm/llvm-project/issues/69690

Tags:
---
 .../clangd/GlobalCompilationDatabase.cpp  | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp 
b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
index d1833759917a30..03ac1aa132d0bf 100644
--- a/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
+++ b/clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
@@ -244,7 +244,16 @@ static std::unique_ptr
 parseJSON(PathRef Path, llvm::StringRef Data, std::string ) {
   if (auto CDB = tooling::JSONCompilationDatabase::loadFromBuffer(
   Data, Error, tooling::JSONCommandLineSyntax::AutoDetect)) {
-return tooling::inferMissingCompileCommands(std::move(CDB));
+// FS used for expanding response files.
+// FIXME: ExpandResponseFilesDatabase appears not to provide the usual
+// thread-safety guarantees, as the access to FS is not locked!
+// For now, use the real FS, which is known to be threadsafe (if we don't
+// use/change working directory, which ExpandResponseFilesDatabase 
doesn't).
+// NOTE: response files have to be expanded before inference because 
inference
+// needs full command line to check/fix driver mode and file type.
+auto FS = llvm::vfs::getRealFileSystem();
+return tooling::inferMissingCompileCommands(
+expandResponseFiles(std::move(CDB), std::move(FS)));
   }
   return nullptr;
 }

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


[clang] f24aa69 - [clang] Match -isysroot behaviour with system compiler on Darwin

2023-08-23 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2023-08-23T18:10:18+01:00
New Revision: f24aa691aa4f25291db8f7c61c6e9007288859e7

URL: 
https://github.com/llvm/llvm-project/commit/f24aa691aa4f25291db8f7c61c6e9007288859e7
DIFF: 
https://github.com/llvm/llvm-project/commit/f24aa691aa4f25291db8f7c61c6e9007288859e7.diff

LOG: [clang] Match -isysroot behaviour with system compiler on Darwin

See discussion in https://reviews.llvm.org/D89001

I updated test to match actual behavior of
/Applications/Xcode_14.3.1_14E300b.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
after that modified upstream to match the test.

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-header-search-libcxx.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index e45424a5f712a0..5d8f006252fd9d 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2465,8 +2465,7 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
   //Also check whether this is used for setting library search paths.
   ToolChain::AddClangCXXStdlibIncludeArgs(DriverArgs, CC1Args);
 
-  if (DriverArgs.hasArg(options::OPT_nostdinc, options::OPT_nostdlibinc,
-options::OPT_nostdincxx))
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc, options::OPT_nostdincxx))
 return;
 
   llvm::SmallString<128> Sysroot = GetEffectiveSysroot(DriverArgs);
@@ -2474,8 +2473,8 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
   switch (GetCXXStdlibType(DriverArgs)) {
   case ToolChain::CST_Libcxx: {
 // On Darwin, libc++ can be installed in one of the following two places:
-// 1. Alongside the compiler in /include/c++/v1
-// 2. In a SDK (or a custom sysroot) in /usr/include/c++/v1
+// 1. In a SDK (or a custom sysroot) in /usr/include/c++/v1
+// 2. Alongside the compiler in /include/c++/v1
 //
 // The precendence of paths is as listed above, i.e. we take the first path
 // that exists. Also note that we never include libc++ twice -- we take the
@@ -2483,6 +2482,17 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
 // include_next could break).
 
 // Check for (1)
+llvm::SmallString<128> SysrootUsr = Sysroot;
+llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
+if (getVFS().exists(SysrootUsr)) {
+  addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
+  return;
+} else if (DriverArgs.hasArg(options::OPT_v)) {
+  llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
+   << "\"\n";
+}
+
+// Otherwise, check for (2)
 // Get from '/bin' to '/include/c++/v1'.
 // Note that InstallBin can be relative, so we use '..' instead of
 // parent_path.
@@ -2497,17 +2507,6 @@ void DarwinClang::AddClangCXXStdlibIncludeArgs(
<< "\"\n";
 }
 
-// Otherwise, check for (2)
-llvm::SmallString<128> SysrootUsr = Sysroot;
-llvm::sys::path::append(SysrootUsr, "usr", "include", "c++", "v1");
-if (getVFS().exists(SysrootUsr)) {
-  addSystemInclude(DriverArgs, CC1Args, SysrootUsr);
-  return;
-} else if (DriverArgs.hasArg(options::OPT_v)) {
-  llvm::errs() << "ignoring nonexistent directory \"" << SysrootUsr
-   << "\"\n";
-}
-
 // Otherwise, don't add any path.
 break;
   }

diff  --git a/clang/test/Driver/darwin-header-search-libcxx.cpp 
b/clang/test/Driver/darwin-header-search-libcxx.cpp
index cc8ec9ceb89b3a..4929511cd00af6 100644
--- a/clang/test/Driver/darwin-header-search-libcxx.cpp
+++ b/clang/test/Driver/darwin-header-search-libcxx.cpp
@@ -53,7 +53,7 @@
 // CHECK-LIBCXX-SYSROOT-1-NOT: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
 
 // Check with both headers in the sysroot and headers alongside the 
installation
-// (the headers in the toolchain should be preferred over the  
headers).
+// (the  headers should be preferred over the headers in the 
toolchain).
 // Ensure that both -isysroot and --sysroot work, and that isysroot has 
precedence
 // over --sysroot.
 //
@@ -89,10 +89,10 @@
 // RUN:   --check-prefix=CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1 %s
 //
 // CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-cc1"
-// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
-// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" 
"[[SYSROOT]]/usr/include/c++/v1"
+// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1: "-internal-isystem" 
"[[SYSROOT]]/usr/include/c++/v1"
+// CHECK-LIBCXX-SYSROOT_AND_TOOLCHAIN-1-NOT: "-internal-isystem" 
"[[TOOLCHAIN]]/usr/bin/../include/c++/v1"
 
-// Make sure that using -nostdinc, -nostdinc++ or -nostdlib will drop both the 
toolchain
+// Make sure that using 

[clang] 6d9fcc2 - [clang][clangd] Don't crash/assert on -gsplit-dwarf=single without output

2023-07-12 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2023-07-12T00:57:41-07:00
New Revision: 6d9fcc2ad874e4ee9b94eef4b85ffece18e501b1

URL: 
https://github.com/llvm/llvm-project/commit/6d9fcc2ad874e4ee9b94eef4b85ffece18e501b1
DIFF: 
https://github.com/llvm/llvm-project/commit/6d9fcc2ad874e4ee9b94eef4b85ffece18e501b1.diff

LOG: [clang][clangd] Don't crash/assert on -gsplit-dwarf=single without output

The crash happens in clang::driver::tools::SplitDebugName when Output is
InputInfo::Nothing. It doesn't happen with standalone clang driver because
output is created in Driver::BuildJobsForActionNoCache.

Example backtrace:
```
* thread #1, name = 'clangd', stop reason = hit program assert
  * frame #0: 0x75c4eacf libc.so.6`raise + 271
frame #1: 0x75c21ea5 libc.so.6`abort + 295
frame #2: 0x75c21d79 libc.so.6`__assert_fail_base.cold.0 + 15
frame #3: 0x75c47426 libc.so.6`__assert_fail + 70
frame #4: 0x5dc0923c 
clangd`clang::driver::InputInfo::getFilename(this=0x7fff9398) const at 
InputInfo.h:84:5
frame #5: 0x5dcd0d8d 
clangd`clang::driver::tools::SplitDebugName(JA=0x5f6c6a50, 
Args=0x5f6d0b80, Input=0x7fff9678, Output=0x7fff9398) 
at CommonArgs.cpp:1275:40
frame #6: 0x5dc955a5 
clangd`clang::driver::tools::Clang::ConstructJob(this=0x5f6c69d0, 
C=0x5f6c64a0, JA=0x5f6c6a50, Output=0x7fff9398, 
Inputs=0x7fff9668, Args=0x5f6d0b80, 
LinkingOutput=0x) const at Clang.cpp:5690:33
frame #7: 0x5dbf6b54 
clangd`clang::driver::Driver::BuildJobsForActionNoCache(this=0x7fffb5e0,
 C=0x5f6c64a0, A=0x5f6c6a50, TC=0x5f6c4be0, 
BoundArch=(Data = 0x, Length = 0), AtTopLevel=true, 
MultipleArchs=false, LinkingOutput=0x, CachedResults=size=1, 
TargetDeviceOffloadKind=OFK_None) const at Driver.cpp:5618:10
frame #8: 0x5dbf4ef0 
clangd`clang::driver::Driver::BuildJobsForAction(this=0x7fffb5e0, 
C=0x5f6c64a0, A=0x5f6c6a50, TC=0x5f6c4be0, 
BoundArch=(Data = 0x, Length = 0), AtTopLevel=true, 
MultipleArchs=false, LinkingOutput=0x, CachedResults=size=1, 
TargetDeviceOffloadKind=OFK_None) const at Driver.cpp:5306:26
frame #9: 0x5dbeb590 
clangd`clang::driver::Driver::BuildJobs(this=0x7fffb5e0, 
C=0x5f6c64a0) const at Driver.cpp:4844:5
frame #10: 0x5dbe6b0f 
clangd`clang::driver::Driver::BuildCompilation(this=0x7fffb5e0, 
ArgList=ArrayRef @ 0x7fffb268) at Driver.cpp:1496:3
frame #11: 0x5b0cc0d9 
clangd`clang::createInvocation(ArgList=ArrayRef @ 
0x7fffbb38, Opts=CreateInvocationOptions @ 0x7fffbb90) at 
CreateInvocationFromCommandLine.cpp:53:52
frame #12: 0x5b378e7b 
clangd`clang::clangd::buildCompilerInvocation(Inputs=0x7fffca58, 
D=0x7fffc158, CC1Args=size=0) at Compiler.cpp:116:44
frame #13: 0x5895a6c8 clangd`clang::clangd::(anonymous 
namespace)::Checker::buildInvocation(this=0x7fffc760, 
TFS=0x7fffe570, Contents= Has Value=false ) at Check.cpp:212:9
frame #14: 0x58959cec clangd`clang::clangd::check(File=(Data = 
"build/test.cpp", Length = 64), TFS=0x7fffe570, 
Opts=0x7fffe600) at Check.cpp:486:34
frame #15: 0x5892164a clangd`main(argc=4, argv=0x7fffecd8) 
at ClangdMain.cpp:993:12
frame #16: 0x75c3ad85 libc.so.6`__libc_start_main + 229
frame #17: 0x585bbe9e clangd`_start + 46
```

Test Plan: ninja ClangDriverTests && 
tools/clang/unittests/Driver/ClangDriverTests

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 3dcbd5b8deb8d7..649d7ddcf8997a 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1274,7 +1274,7 @@ const char *tools::SplitDebugName(const JobAction , 
const ArgList ,
 F += ".dwo";
   };
   if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
-if (StringRef(A->getValue()) == "single")
+if (StringRef(A->getValue()) == "single" && Output.isFilename())
   return Args.MakeArgString(Output.getFilename());
 
   SmallString<128> T;

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index 4ddeadac2103f4..8d3853a7b4a6de 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -367,6 +367,16 @@ TEST(ToolChainTest, PostCallback) {
   EXPECT_TRUE(CallbackHasCalled);
 }
 
+TEST(CompilerInvocation, SplitSwarfSingleCrash) {

[clang] d60d345 - [clangd] Move standard options adaptor to CommandMangler

2023-03-17 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2023-03-17T03:10:36-07:00
New Revision: d60d3455eb2b375d026a4aa74c4ba0c38f5d323c

URL: 
https://github.com/llvm/llvm-project/commit/d60d3455eb2b375d026a4aa74c4ba0c38f5d323c
DIFF: 
https://github.com/llvm/llvm-project/commit/d60d3455eb2b375d026a4aa74c4ba0c38f5d323c.diff

LOG: [clangd] Move standard options adaptor to CommandMangler

There is a discrepancy between how clangd processes CDB loaded from
JSON file on disk and pushed via LSP. Thus the same CDB pushed via
LSP protocol may not work as expected. Some difference between these two
paths is expected but we still need to insert driver mode and target from
binary name and expand response files.

Test Plan: check-clang-tools

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/CompileCommands.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/unittests/CMakeLists.txt
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang/include/clang/Testing/CommandLineArgs.h
clang/include/clang/Tooling/Tooling.h
clang/lib/Testing/CommandLineArgs.cpp
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/lib/Tooling/Tooling.cpp
clang/unittests/Tooling/ToolingTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index bcd39b2d38ba5..39b180e002a68 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -14,6 +14,7 @@
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -27,6 +28,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
+#include "llvm/TargetParser/Host.h"
 #include 
 #include 
 #include 
@@ -185,6 +187,12 @@ static std::string resolveDriver(llvm::StringRef Driver, 
bool FollowSymlink,
 
 } // namespace
 
+CommandMangler::CommandMangler() {
+  Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
+  ? llvm::cl::TokenizeWindowsCommandLine
+  : llvm::cl::TokenizeGNUCommandLine;
+}
+
 CommandMangler CommandMangler::detect() {
   CommandMangler Result;
   Result.ClangPath = detectClangPath();
@@ -201,9 +209,18 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
   trace::Span S("AdjustCompileFlags");
   // Most of the modifications below assumes the Cmd starts with a driver name.
   // We might consider injecting a generic driver name like "cc" or "c++", but
-  // a Cmd missing the driver is probably rare enough in practice and errnous.
+  // a Cmd missing the driver is probably rare enough in practice and 
erroneous.
   if (Cmd.empty())
 return;
+
+  // FS used for expanding response files.
+  // FIXME: ExpandResponseFiles appears not to provide the usual
+  // thread-safety guarantees, as the access to FS is not locked!
+  // For now, use the real FS, which is known to be threadsafe (if we don't
+  // use/change working directory, which ExpandResponseFiles doesn't).
+  auto FS = llvm::vfs::getRealFileSystem();
+  tooling::addExpandedResponseFiles(Cmd, Command.Directory, Tokenizer, *FS);
+
   auto  = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
   llvm::SmallVector OriginalArgs;
@@ -212,7 +229,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
 OriginalArgs.push_back(S.c_str());
   bool IsCLMode = driver::IsClangCL(driver::getDriverMode(
   OriginalArgs[0], llvm::ArrayRef(OriginalArgs).slice(1)));
-  // ParseArgs propagates missig arg/opt counts on error, but preserves
+  // ParseArgs propagates missing arg/opt counts on error, but preserves
   // everything it could parse in ArgList. So we just ignore those counts.
   unsigned IgnoredCount;
   // Drop the executable name, as ParseArgs doesn't expect it. This means
@@ -307,12 +324,16 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
   //necessary for the system include extractor to identify the file type
   //  - AFTER applying CompileFlags.Edits, because the name of the compiler
   //that needs to be invoked may come from the CompileFlags->Compiler key
+  //  - BEFORE addTargetAndModeForProgramName(), because gcc doesn't support
+  //the target flag that might be added.
   //  - BEFORE resolveDriver() because that can mess up the driver path,
   //e.g. changing gcc to /path/to/clang/bin/gcc
   if (SystemIncludeExtractor) {
 SystemIncludeExtractor(Command, File);
   }
 
+  tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
+
   // Check whether the 

[clang] b293c62 - [clang][Lexer] Fix crash/assert clang::HeaderSearch::search_dir_nth

2023-03-16 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2023-03-16T02:19:11-07:00
New Revision: b293c6280d06f49c5ca7290855911341ab0bdffa

URL: 
https://github.com/llvm/llvm-project/commit/b293c6280d06f49c5ca7290855911341ab0bdffa
DIFF: 
https://github.com/llvm/llvm-project/commit/b293c6280d06f49c5ca7290855911341ab0bdffa.diff

LOG: [clang][Lexer] Fix crash/assert clang::HeaderSearch::search_dir_nth

The issue was introduced in D135801. When there are only header maps in the 
SearchDirs,
the out of bounds value is assigned to FirstNonHeaderMapSearchDirIdx.

Test Plan: check-clang

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

Added: 
clang/test/Preprocessor/Inputs/header-search-crash/foo.hmap.json
clang/test/Preprocessor/header-search-crash.c

Modified: 
clang/lib/Lex/HeaderSearch.cpp

Removed: 




diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 074c147ba3c54..5a7357a5ada43 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -378,15 +378,17 @@ void HeaderSearch::indexInitialHeaderMaps() {
   llvm::StringMap Index(SearchDirs.size());
 
   // Iterate over all filename keys and associate them with the index i.
-  unsigned i = 0;
-  for (; i != SearchDirs.size(); ++i) {
+  for (unsigned i = 0; i != SearchDirs.size(); ++i) {
 auto  = SearchDirs[i];
 
 // We're concerned with only the initial contiguous run of header
 // maps within SearchDirs, which can be 99% of SearchDirs when
 // SearchDirs.size() is ~1.
-if (!Dir.isHeaderMap())
+if (!Dir.isHeaderMap()) {
+  SearchDirHeaderMapIndex = std::move(Index);
+  FirstNonHeaderMapSearchDirIdx = i;
   break;
+}
 
 // Give earlier keys precedence over identical later keys.
 auto Callback = [&](StringRef Filename) {
@@ -394,9 +396,6 @@ void HeaderSearch::indexInitialHeaderMaps() {
 };
 Dir.getHeaderMap()->forEachKey(Callback);
   }
-
-  SearchDirHeaderMapIndex = std::move(Index);
-  FirstNonHeaderMapSearchDirIdx = i;
 }
 
 
//===--===//
@@ -1929,7 +1928,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
 llvm::StringRef File, llvm::StringRef WorkingDir, llvm::StringRef MainFile,
 bool *IsSystem) {
   using namespace llvm::sys;
-  
+
   llvm::SmallString<32> FilePath = File;
   // remove_dots switches to backslashes on windows as a side-effect!
   // We always want to suggest forward slashes for includes.

diff  --git a/clang/test/Preprocessor/Inputs/header-search-crash/foo.hmap.json 
b/clang/test/Preprocessor/Inputs/header-search-crash/foo.hmap.json
new file mode 100644
index 0..ccfd911f0f7fd
--- /dev/null
+++ b/clang/test/Preprocessor/Inputs/header-search-crash/foo.hmap.json
@@ -0,0 +1,6 @@
+{
+  "mappings" :
+{
+ "Foo.h" : "Foo/Foo.h"
+}
+}

diff  --git a/clang/test/Preprocessor/header-search-crash.c 
b/clang/test/Preprocessor/header-search-crash.c
new file mode 100644
index 0..8c04216d18ba1
--- /dev/null
+++ b/clang/test/Preprocessor/header-search-crash.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: %hmaptool write %S/Inputs/header-search-crash/foo.hmap.json %t/foo.hmap
+// RUN: %clang -cc1 -E %s -I %t/foo.hmap -verify
+
+#include "MissingHeader.h" // expected-error {{'MissingHeader.h' file not 
found}}



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


[clang-tools-extra] 2a84c53 - Revert "[clangd] Move standard options adaptor to CommandMangler"

2023-03-13 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2023-03-13T07:00:56-07:00
New Revision: 2a84c53ccdc015a7f53a144aa4f7c0dddf839604

URL: 
https://github.com/llvm/llvm-project/commit/2a84c53ccdc015a7f53a144aa4f7c0dddf839604
DIFF: 
https://github.com/llvm/llvm-project/commit/2a84c53ccdc015a7f53a144aa4f7c0dddf839604.diff

LOG: Revert "[clangd] Move standard options adaptor to CommandMangler"

This reverts commit 34de7da6246cdfa6ff6f3d3c514583cddc0a10ec.

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/CompileCommands.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang/include/clang/Tooling/Tooling.h
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/lib/Tooling/Tooling.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index 39b180e002a68..bcd39b2d38ba5 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -14,7 +14,6 @@
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/CompilationDatabase.h"
-#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -28,7 +27,6 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
-#include "llvm/TargetParser/Host.h"
 #include 
 #include 
 #include 
@@ -187,12 +185,6 @@ static std::string resolveDriver(llvm::StringRef Driver, 
bool FollowSymlink,
 
 } // namespace
 
-CommandMangler::CommandMangler() {
-  Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
-  ? llvm::cl::TokenizeWindowsCommandLine
-  : llvm::cl::TokenizeGNUCommandLine;
-}
-
 CommandMangler CommandMangler::detect() {
   CommandMangler Result;
   Result.ClangPath = detectClangPath();
@@ -209,18 +201,9 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
   trace::Span S("AdjustCompileFlags");
   // Most of the modifications below assumes the Cmd starts with a driver name.
   // We might consider injecting a generic driver name like "cc" or "c++", but
-  // a Cmd missing the driver is probably rare enough in practice and 
erroneous.
+  // a Cmd missing the driver is probably rare enough in practice and errnous.
   if (Cmd.empty())
 return;
-
-  // FS used for expanding response files.
-  // FIXME: ExpandResponseFiles appears not to provide the usual
-  // thread-safety guarantees, as the access to FS is not locked!
-  // For now, use the real FS, which is known to be threadsafe (if we don't
-  // use/change working directory, which ExpandResponseFiles doesn't).
-  auto FS = llvm::vfs::getRealFileSystem();
-  tooling::addExpandedResponseFiles(Cmd, Command.Directory, Tokenizer, *FS);
-
   auto  = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
   llvm::SmallVector OriginalArgs;
@@ -229,7 +212,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
 OriginalArgs.push_back(S.c_str());
   bool IsCLMode = driver::IsClangCL(driver::getDriverMode(
   OriginalArgs[0], llvm::ArrayRef(OriginalArgs).slice(1)));
-  // ParseArgs propagates missing arg/opt counts on error, but preserves
+  // ParseArgs propagates missig arg/opt counts on error, but preserves
   // everything it could parse in ArgList. So we just ignore those counts.
   unsigned IgnoredCount;
   // Drop the executable name, as ParseArgs doesn't expect it. This means
@@ -324,16 +307,12 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
   //necessary for the system include extractor to identify the file type
   //  - AFTER applying CompileFlags.Edits, because the name of the compiler
   //that needs to be invoked may come from the CompileFlags->Compiler key
-  //  - BEFORE addTargetAndModeForProgramName(), because gcc doesn't support
-  //the target flag that might be added.
   //  - BEFORE resolveDriver() because that can mess up the driver path,
   //e.g. changing gcc to /path/to/clang/bin/gcc
   if (SystemIncludeExtractor) {
 SystemIncludeExtractor(Command, File);
   }
 
-  tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
-
   // Check whether the flag exists, either as -flag or -flag=*
   auto Has = [&](llvm::StringRef Flag) {
 for (llvm::StringRef Arg : Cmd) {

diff  --git a/clang-tools-extra/clangd/CompileCommands.h 
b/clang-tools-extra/clangd/CompileCommands.h
index 1b37f44f0b9db..eb318d18baf63 100644
--- a/clang-tools-extra/clangd/CompileCommands.h
+++ b/clang-tools-extra/clangd/CompileCommands.h
@@ -12,7 +12,6 @@
 #include "support/Threading.h"
 #include "llvm/ADT/StringMap.h"
 

[clang] 34de7da - [clangd] Move standard options adaptor to CommandMangler

2023-03-13 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2023-03-13T06:08:22-07:00
New Revision: 34de7da6246cdfa6ff6f3d3c514583cddc0a10ec

URL: 
https://github.com/llvm/llvm-project/commit/34de7da6246cdfa6ff6f3d3c514583cddc0a10ec
DIFF: 
https://github.com/llvm/llvm-project/commit/34de7da6246cdfa6ff6f3d3c514583cddc0a10ec.diff

LOG: [clangd] Move standard options adaptor to CommandMangler

There is a discrepancy between how clangd processes CDB loaded from
JSON file on disk and pushed via LSP. Thus the same CDB pushed via
LSP protocol may not work as expected. Some difference between these two
paths is expected but we still need to insert driver mode and target from
binary name and expand response files.

Test Plan: check-clang-tools

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

Added: 


Modified: 
clang-tools-extra/clangd/CompileCommands.cpp
clang-tools-extra/clangd/CompileCommands.h
clang-tools-extra/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/clangd/test/did-change-configuration-params.test
clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
clang/include/clang/Tooling/Tooling.h
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/lib/Tooling/Tooling.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index bcd39b2d38ba5..39b180e002a68 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -14,6 +14,7 @@
 #include "clang/Driver/Options.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Tooling/CompilationDatabase.h"
+#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
@@ -27,6 +28,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
+#include "llvm/TargetParser/Host.h"
 #include 
 #include 
 #include 
@@ -185,6 +187,12 @@ static std::string resolveDriver(llvm::StringRef Driver, 
bool FollowSymlink,
 
 } // namespace
 
+CommandMangler::CommandMangler() {
+  Tokenizer = llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
+  ? llvm::cl::TokenizeWindowsCommandLine
+  : llvm::cl::TokenizeGNUCommandLine;
+}
+
 CommandMangler CommandMangler::detect() {
   CommandMangler Result;
   Result.ClangPath = detectClangPath();
@@ -201,9 +209,18 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
   trace::Span S("AdjustCompileFlags");
   // Most of the modifications below assumes the Cmd starts with a driver name.
   // We might consider injecting a generic driver name like "cc" or "c++", but
-  // a Cmd missing the driver is probably rare enough in practice and errnous.
+  // a Cmd missing the driver is probably rare enough in practice and 
erroneous.
   if (Cmd.empty())
 return;
+
+  // FS used for expanding response files.
+  // FIXME: ExpandResponseFiles appears not to provide the usual
+  // thread-safety guarantees, as the access to FS is not locked!
+  // For now, use the real FS, which is known to be threadsafe (if we don't
+  // use/change working directory, which ExpandResponseFiles doesn't).
+  auto FS = llvm::vfs::getRealFileSystem();
+  tooling::addExpandedResponseFiles(Cmd, Command.Directory, Tokenizer, *FS);
+
   auto  = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
   llvm::SmallVector OriginalArgs;
@@ -212,7 +229,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
 OriginalArgs.push_back(S.c_str());
   bool IsCLMode = driver::IsClangCL(driver::getDriverMode(
   OriginalArgs[0], llvm::ArrayRef(OriginalArgs).slice(1)));
-  // ParseArgs propagates missig arg/opt counts on error, but preserves
+  // ParseArgs propagates missing arg/opt counts on error, but preserves
   // everything it could parse in ArgList. So we just ignore those counts.
   unsigned IgnoredCount;
   // Drop the executable name, as ParseArgs doesn't expect it. This means
@@ -307,12 +324,16 @@ void CommandMangler::operator()(tooling::CompileCommand 
,
   //necessary for the system include extractor to identify the file type
   //  - AFTER applying CompileFlags.Edits, because the name of the compiler
   //that needs to be invoked may come from the CompileFlags->Compiler key
+  //  - BEFORE addTargetAndModeForProgramName(), because gcc doesn't support
+  //the target flag that might be added.
   //  - BEFORE resolveDriver() because that can mess up the driver path,
   //e.g. changing gcc to /path/to/clang/bin/gcc
   if (SystemIncludeExtractor) {
 SystemIncludeExtractor(Command, File);
   }
 
+  tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
+
   // Check whether the flag exists, either as -flag or -flag=*
   auto Has = [&](llvm::StringRef Flag) {
 for (llvm::StringRef Arg : Cmd) 

[clang-tools-extra] 5d12b13 - [clang-tidy] Dump effective diagnostics level in YAML output

2022-10-12 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2022-10-12T02:03:56-07:00
New Revision: 5d12b13b0b26bc58b02ee23c369da8b83240cceb

URL: 
https://github.com/llvm/llvm-project/commit/5d12b13b0b26bc58b02ee23c369da8b83240cceb
DIFF: 
https://github.com/llvm/llvm-project/commit/5d12b13b0b26bc58b02ee23c369da8b83240cceb.diff

LOG: [clang-tidy] Dump effective diagnostics level in YAML output

Before this patch YAML output had default diagnostic level instead of effective 
level reported to the user on stdout. Wrapper scripts for clang-tidy usually 
use YAML output and they pick wrong diagnostics level without this patch.

Test Plan: check-clang-tools

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
index d455473673b09..1660d976ff0be 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -403,6 +403,8 @@ void ClangTidyDiagnosticConsumer::HandleDiagnostic(
 
 bool IsWarningAsError = DiagLevel == DiagnosticsEngine::Warning &&
 Context.treatAsError(CheckName);
+if (IsWarningAsError)
+  Level = ClangTidyError::Error;
 Errors.emplace_back(CheckName, Level, Context.getCurrentBuildDirectory(),
 IsWarningAsError);
   }

diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
index 16ad4f175cab9..ca2184332f9a4 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
@@ -1,5 +1,5 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t-input.cpp
-// RUN: not clang-tidy %t-input.cpp 
-checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes,clang-diagnostic-zero-length-array'
 -export-fixes=%t.yaml -- -Wmissing-prototypes -Wzero-length-array > %t.msg 2>&1
+// RUN: not clang-tidy %t-input.cpp 
-checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes,clang-diagnostic-zero-length-array'
 
--warnings-as-errors='clang-diagnostic-missing-prototypes,google-explicit-constructor'
 -export-fixes=%t.yaml -- -Wmissing-prototypes -Wzero-length-array > %t.msg 2>&1
 // RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s 
-implicit-check-not='{{warning|error|note}}:'
 // RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s
 #define X(n) void n ## n() {}
@@ -10,9 +10,10 @@ int b[0];
 void test(x);
 struct Foo {
   member;
+  Foo(int) {}
 };
 
-// CHECK-MESSAGES: -input.cpp:2:1: warning: no previous prototype for function 
'ff' [clang-diagnostic-missing-prototypes]
+// CHECK-MESSAGES: -input.cpp:2:1: error: no previous prototype for function 
'ff' [clang-diagnostic-missing-prototypes,-warnings-as-errors]
 // CHECK-MESSAGES: -input.cpp:1:19: note: expanded from macro 'X'
 // CHECK-MESSAGES: {{^}}note: expanded from here{{$}}
 // CHECK-MESSAGES: -input.cpp:2:1: note: declare 'static' if the function is 
not intended to be used outside of this translation unit
@@ -21,6 +22,7 @@ struct Foo {
 // CHECK-MESSAGES: -input.cpp:4:7: warning: zero size arrays are an extension 
[clang-diagnostic-zero-length-array]
 // CHECK-MESSAGES: -input.cpp:6:11: error: unknown type name 'x' 
[clang-diagnostic-error]
 // CHECK-MESSAGES: -input.cpp:8:3: error: a type specifier is required for all 
declarations [clang-diagnostic-error]
+// CHECK-MESSAGES: -input.cpp:9:3: error: single-argument constructors must be 
marked explicit to avoid unintentional implicit conversions 
[google-explicit-constructor,-warnings-as-errors]
 
 // CHECK-YAML: ---
 // CHECK-YAML-NEXT: MainSourceFile:  '{{.*}}-input.cpp'
@@ -52,7 +54,7 @@ struct Foo {
 // CHECK-YAML-NEXT: FilePath:'{{.*}}-input.cpp'
 // CHECK-YAML-NEXT: FileOffset:  13
 // CHECK-YAML-NEXT: Replacements:[]
-// CHECK-YAML-NEXT: Level:   Warning
+// CHECK-YAML-NEXT: Level:   Error
 // CHECK-YAML-NEXT: BuildDirectory:  '{{.*}}'
 // CHECK-YAML-NEXT:   - DiagnosticName:  clang-diagnostic-error
 // CHECK-YAML-NEXT: DiagnosticMessage:
@@ -94,4 +96,16 @@ struct Foo {
 // CHECK-YAML-NEXT:   Replacements:[]
 // CHECK-YAML-NEXT: Level:   Error
 // CHECK-YAML-NEXT: BuildDirectory:  '{{.*}}'
+// CHECK-YAML-NEXT:   - DiagnosticName:  google-explicit-constructor
+// CHECK-YAML-NEXT: DiagnosticMessage:
+// CHECK-YAML-NEXT:   Message: single-argument constructors must 
be marked explicit to avoid unintentional implicit conversions
+// 

[clang] 41dbee1 - [clang] Update ReleaseNotes about a crash fix (Issue 53628)

2022-09-20 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2022-09-20T02:05:36-07:00
New Revision: 41dbee1e66937fe7d579b73d30dc790cd79b8738

URL: 
https://github.com/llvm/llvm-project/commit/41dbee1e66937fe7d579b73d30dc790cd79b8738
DIFF: 
https://github.com/llvm/llvm-project/commit/41dbee1e66937fe7d579b73d30dc790cd79b8738.diff

LOG: [clang] Update ReleaseNotes about a crash fix (Issue 53628)

Update ReleaseNotes about a crash fix (Issue 53628)

Test Plan: none

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1744a8b6f84b..5d6b53b3a4fc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -155,6 +155,9 @@ Bug Fixes
   This is the suggested resolution to CWG DR2628.
   `Issue 57646 `_
   `Issue 43829 `_
+- Fixed a crash in C++20 mode in Clang and Clangd when compile source
+  with compilation errors.
+  `Issue 53628 `_
 
 
 Improvements to Clang's diagnostics



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


[clang] 133b6d7 - [clang][C++20] Fix clang/clangd assert/crash after compilation errors

2022-09-17 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2022-09-17T07:37:19-07:00
New Revision: 133b6d7db90d9b52b01e8e09e1aa8fb8d2da0f9d

URL: 
https://github.com/llvm/llvm-project/commit/133b6d7db90d9b52b01e8e09e1aa8fb8d2da0f9d
DIFF: 
https://github.com/llvm/llvm-project/commit/133b6d7db90d9b52b01e8e09e1aa8fb8d2da0f9d.diff

LOG: [clang][C++20] Fix clang/clangd assert/crash after compilation errors

After compilation errors, expression a transformation result may not be usable.
It triggers an assert in RemoveNestedImmediateInvocation and SIGSEGV in case of
builds without asserts. This issue significantly affects clangd because source
may not be valid during typing. Tests cases that I attached was reduce from huge
C++ translation unit.

Test Plan: check-clang

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

Added: 
clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp

Modified: 
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e53c88b283b8..b49b7ce45cf4 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17624,9 +17624,13 @@ static void RemoveNestedImmediateInvocation(
 Transformer.AllowSkippingFirstCXXConstructExpr = false;
 
   ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr());
-  assert(Res.isUsable());
-  Res = SemaRef.MaybeCreateExprWithCleanups(Res);
-  It->getPointer()->setSubExpr(Res.get());
+  // The result may not be usable in case of previous compilation errors.
+  // In this case evaluation of the expression may result in crash so just
+  // don't do anything further with the result.
+  if (Res.isUsable()) {
+Res = SemaRef.MaybeCreateExprWithCleanups(Res);
+It->getPointer()->setSubExpr(Res.get());
+  }
 }
 
 static void

diff  --git a/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp 
b/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
new file mode 100644
index ..26faf2bc1c06
--- /dev/null
+++ b/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
@@ -0,0 +1,11 @@
+// RUN: not %clang_cc1 -fsyntax-only -verify -std=gnu++20 -ferror-limit 19 %s
+// Creduced test case for the crash in RemoveNestedImmediateInvocation after 
compliation errros.
+
+a, class b {   template < typename c>  
   consteval b(c
+} template  using d = b;
+auto e(d<>) -> int:;
+}
+f
+}
+g() {
+auto h = "":(::i(e(h))



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


[clang] 8eaa05d - [clang] SIGSEGV at DeduceTemplateArgumentsByTypeMatch

2021-07-30 Thread Dmitry Polukhin via cfe-commits

Author: Ivan Murashko
Date: 2021-07-30T12:40:38+03:00
New Revision: 8eaa05d06161db69e68ff2a5f4c8e3545a4e8080

URL: 
https://github.com/llvm/llvm-project/commit/8eaa05d06161db69e68ff2a5f4c8e3545a4e8080
DIFF: 
https://github.com/llvm/llvm-project/commit/8eaa05d06161db69e68ff2a5f4c8e3545a4e8080.diff

LOG: [clang] SIGSEGV at DeduceTemplateArgumentsByTypeMatch

There is a SIGSEGV at `DeduceTemplateArgumentsByTypeMatch`. The bug 
[#51171](https://bugs.llvm.org/show_bug.cgi?id=51171) was filled. The 
reproducer can be found at the bug description.

LIT test for the issue was added:
```
./bin/llvm-lit -v ../clang/test/SemaCXX/pr51171-crash.cpp
```

The debug stack trace is below:
```
 #0 0x055afcb9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
/home/ivanmurashko/local/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:22
 #1 0x055afd70 PrintStackTraceSignalHandler(void*) 
/home/ivanmurashko/local/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
 #2 0x055add2d llvm::sys::RunSignalHandlers() 
/home/ivanmurashko/local/llvm-project/llvm/lib/Support/Signals.cpp:97:20
 #3 0x055af701 SignalHandler(int) 
/home/ivanmurashko/local/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
 #4 0x77bc2b20 __restore_rt sigaction.c:0:0
 #5 0x766a337f raise (/lib64/libc.so.6+0x3737f)
 #6 0x7668ddb5 abort (/lib64/libc.so.6+0x21db5)
 #7 0x7668dc89 _nl_load_domain.cold.0 loadmsgcat.c:0:0
 #8 0x7669ba76 .annobin___GI___assert_fail.end assert.c:0:0
 #9 0x0594b210 clang::QualType::getCommonPtr() const 
/home/ivanmurashko/local/llvm-project/clang/include/clang/AST/Type.h:684:5
#10 0x05a12ca6 clang::QualType::getCanonicalType() const 
/home/ivanmurashko/local/llvm-project/clang/include/clang/AST/Type.h:6467:36
#11 0x05a137a6 clang::ASTContext::getCanonicalType(clang::QualType) 
const 
/home/ivanmurashko/local/llvm-project/clang/include/clang/AST/ASTContext.h:2433:58
#12 0x09204584 DeduceTemplateArgumentsByTypeMatch(clang::Sema&, 
clang::TemplateParameterList*, clang::QualType, clang::QualType, 
clang::sema::TemplateDeductionInfo&, 
llvm::SmallVectorImpl&, unsigned int, bool, 
bool) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaTemplateDeduction.cpp:1355:54
#13 0x0920df0d 
clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, 
clang::TemplateArgumentListInfo*, clang::QualType, clang::FunctionDecl*&, 
clang::sema::TemplateDeductionInfo&, bool) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaTemplateDeduction.cpp:4354:47
#14 0x09012b09 (anonymous 
namespace)::AddressOfFunctionResolver::AddMatchingTemplateFunction(clang::FunctionTemplateDecl*,
 clang::DeclAccessPair const&) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:12026:38
#15 0x09013030 (anonymous 
namespace)::AddressOfFunctionResolver::FindAllFunctionsThatMatchTargetTypeExactly()
 /home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:12119:9
#16 0x09012679 (anonymous 
namespace)::AddressOfFunctionResolver::AddressOfFunctionResolver(clang::Sema&, 
clang::Expr*, clang::QualType const&, bool) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:11931:5
#17 0x09013c91 
clang::Sema::ResolveAddressOfOverloadedFunction(clang::Expr*, clang::QualType, 
bool, clang::DeclAccessPair&, bool*) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:12286:42
#18 0x08fed85d IsStandardConversion(clang::Sema&, clang::Expr*, 
clang::QualType, bool, clang::StandardConversionSequence&, bool, bool) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:1712:49
#19 0x08fec8ea TryImplicitConversion(clang::Sema&, clang::Expr*, 
clang::QualType, bool, clang::Sema::AllowedExplicit, bool, bool, bool, bool) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:1433:27
#20 0x08ff90ba TryCopyInitialization(clang::Sema&, clang::Expr*, 
clang::QualType, bool, bool, bool, bool) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:5273:71
#21 0x090024fb clang::Sema::AddBuiltinCandidate(clang::QualType*, 
llvm::ArrayRef, clang::OverloadCandidateSet&, bool, unsigned int) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:7755:32
#22 0x0900513f (anonymous 
namespace)::BuiltinOperatorOverloadBuilder::addGenericBinaryArithmeticOverloads()
 /home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:8633:30
#23 0x09007624 
clang::Sema::AddBuiltinOperatorCandidates(clang::OverloadedOperatorKind, 
clang::SourceLocation, llvm::ArrayRef, 
clang::OverloadCandidateSet&) 
/home/ivanmurashko/local/llvm-project/clang/lib/Sema/SemaOverload.cpp:9205:51
#24 0x09018734 
clang::Sema::LookupOverloadedBinOp(clang::OverloadCandidateSet&, 
clang::OverloadedOperatorKind, clang::UnresolvedSetImpl const&, 
llvm::ArrayRef, bool) 

[clang] fceaf86 - [clang] Fix UB when string.front() is used for the empty string

2021-06-30 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2021-06-30T01:07:47-07:00
New Revision: fceaf8621179aa758c44f3eaee02d789abfd455b

URL: 
https://github.com/llvm/llvm-project/commit/fceaf8621179aa758c44f3eaee02d789abfd455b
DIFF: 
https://github.com/llvm/llvm-project/commit/fceaf8621179aa758c44f3eaee02d789abfd455b.diff

LOG: [clang] Fix UB when string.front() is used for the empty string

Compilation database might have empty string as a command line argument.
But ExpandResponseFilesDatabase::expand doesn't expect this and assumes
that string.front() can be used for any argument. It is undefined behaviour if
string is empty. With debug build mode it causes crash in clangd.

Test Plan: check-clang

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

Added: 


Modified: 
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp 
b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
index a825370afcf56..29787b8a88942 100644
--- a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@ class ExpandResponseFilesDatabase : public 
CompilationDatabase {
   Argv.reserve(Cmd.CommandLine.size());
   for (auto  : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;

diff  --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 9a04de32c852d..218a352f86f06 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@ class MemDBTest : public ::testing::Test {
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto *It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@ TEST_F(ExpandResponseFilesTest, ExpandResponseFiles) {
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang



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


[clang-tools-extra] 47d138c - [clang-tidy] LIT test fix for Remark diagnostic

2021-06-11 Thread Dmitry Polukhin via cfe-commits

Author: Ivan Murashko
Date: 2021-06-11T02:02:36-07:00
New Revision: 47d138c93992f779a5dd0810b0e7402e043df61d

URL: 
https://github.com/llvm/llvm-project/commit/47d138c93992f779a5dd0810b0e7402e043df61d
DIFF: 
https://github.com/llvm/llvm-project/commit/47d138c93992f779a5dd0810b0e7402e043df61d.diff

LOG: [clang-tidy] LIT test fix for Remark diagnostic

There is a followup fix for a unit test introduced at D102906. The test file 
was placed into a temp folder and test assumed that it would be visible without 
the full path specification.

This behaviour can be changed in future and it would be good to specify full 
path to the file at the test.

Test Plan:
```
ninja check-clang-tools
```

Reviewed By: DmitryPolukhin

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

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp

Removed: 




diff  --git a/clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp
index 0e9fb46e3e1cb..909bc94aa4ab4 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/remarks.cpp
@@ -2,14 +2,13 @@
 // RUN: cp -r %S/Inputs/remarks %t
 // RUN: cp %s %t/t.cpp
 
-// RUN: clang-tidy 
-checks='-*,modernize-use-override,clang-diagnostic-module-import' t.cpp -- \
+// RUN: clang-tidy 
-checks='-*,modernize-use-override,clang-diagnostic-module-import' %t/t.cpp -- \
 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \
 // RUN: -fsyntax-only \
 // RUN: -I%S/Inputs/remarks \
 // RUN: -working-directory=%t \
-// RUN: -Rmodule-build -Rmodule-import t.cpp 2>&1 |\
+// RUN: -Rmodule-build -Rmodule-import 2>&1 |\
 // RUN: FileCheck %s -implicit-check-not "remark:"
 
 #include "A.h"
 // CHECK: remark: importing module 'A' from {{.*}} 
[clang-diagnostic-module-import]
-



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


[clang] aa0d717 - [clang] NFC: test for undefined behaviour in RawComment::getFormattedText()

2021-06-07 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2021-06-07T03:05:00-07:00
New Revision: aa0d7179bbb3fd24bc9eb1fd6203565dbd50e8d8

URL: 
https://github.com/llvm/llvm-project/commit/aa0d7179bbb3fd24bc9eb1fd6203565dbd50e8d8
DIFF: 
https://github.com/llvm/llvm-project/commit/aa0d7179bbb3fd24bc9eb1fd6203565dbd50e8d8.diff

LOG: [clang] NFC: test for undefined behaviour in RawComment::getFormattedText()

This diff adds testcase for the issue fixed in https://reviews.llvm.org/D77468
but regression test was not added in the diff. On Clang 9 it caused
crash in cland during code completion.

Test Plan: check-clang-unit

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

Added: 


Modified: 
clang/unittests/AST/CommentTextTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/CommentTextTest.cpp 
b/clang/unittests/AST/CommentTextTest.cpp
index 3de6758e45b6e..b697828698d85 100644
--- a/clang/unittests/AST/CommentTextTest.cpp
+++ b/clang/unittests/AST/CommentTextTest.cpp
@@ -124,4 +124,11 @@ R"cpp(
   // clang-format on
 }
 
+TEST_F(CommentTextTest, EmptyFormattedText) {
+  // Test that empty formatted text doesn't cause crash.
+  const char *ExpectedOutput = "";
+  auto Formatted = formatComment("//!<");
+  EXPECT_EQ(ExpectedOutput, Formatted);
+}
+
 } // namespace clang



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


[clang] 178ad93 - [clang][clangd] Use reverse header map lookup in suggestPathToFileForDiagnostics

2021-06-03 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2021-06-03T01:37:55-07:00
New Revision: 178ad93e3f1f2381f05baea300873ee5998ac288

URL: 
https://github.com/llvm/llvm-project/commit/178ad93e3f1f2381f05baea300873ee5998ac288
DIFF: 
https://github.com/llvm/llvm-project/commit/178ad93e3f1f2381f05baea300873ee5998ac288.diff

LOG: [clang][clangd] Use reverse header map lookup in 
suggestPathToFileForDiagnostics

Summary:
suggestPathToFileForDiagnostics is actively used in clangd for converting
an absolute path to a header file to a header name as it should be spelled
in the sources. Current approach converts absolute path to relative path.
This diff implements missing logic that makes a reverse lookup from the
relative path to the key in the header map that should be used in the sources.

Prerequisite diff: https://reviews.llvm.org/D103229

Test Plan: check-clang

Reviewers: dexonsmith, bruno, rsmith

Subscribers: cfe-commits

Tasks:

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Lex/HeaderMap.h
clang/lib/Lex/HeaderMap.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/unittests/Lex/HeaderSearchTest.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/HeaderMap.h 
b/clang/include/clang/Lex/HeaderMap.h
index accb061e51ba3..53108b00bd16d 100644
--- a/clang/include/clang/Lex/HeaderMap.h
+++ b/clang/include/clang/Lex/HeaderMap.h
@@ -16,6 +16,7 @@
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LLVM.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include 
@@ -29,6 +30,7 @@ struct HMapHeader;
 class HeaderMapImpl {
   std::unique_ptr FileBuffer;
   bool NeedsBSwap;
+  mutable llvm::StringMap ReverseMap;
 
 public:
   HeaderMapImpl(std::unique_ptr File, bool 
NeedsBSwap)
@@ -48,6 +50,9 @@ class HeaderMapImpl {
   /// Print the contents of this headermap to stderr.
   void dump() const;
 
+  /// Return key for specifed path.
+  StringRef reverseLookupFilename(StringRef DestPath) const;
+
 private:
   unsigned getEndianAdjustedWord(unsigned X) const;
   const HMapHeader () const;
@@ -79,9 +84,10 @@ class HeaderMap : private HeaderMapImpl {
   /// ".." and a filename "../file.h" this would be "../../file.h".
   Optional LookupFile(StringRef Filename, FileManager ) const;
 
-  using HeaderMapImpl::lookupFilename;
-  using HeaderMapImpl::getFileName;
   using HeaderMapImpl::dump;
+  using HeaderMapImpl::getFileName;
+  using HeaderMapImpl::lookupFilename;
+  using HeaderMapImpl::reverseLookupFilename;
 };
 
 } // end namespace clang.

diff  --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index d44ef29c05d13..4b60cfa7b52dd 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -240,3 +240,32 @@ StringRef HeaderMapImpl::lookupFilename(StringRef Filename,
 return StringRef(DestPath.begin(), DestPath.size());
   }
 }
+
+StringRef HeaderMapImpl::reverseLookupFilename(StringRef DestPath) const {
+  if (!ReverseMap.empty())
+return ReverseMap.lookup(DestPath);
+
+  const HMapHeader  = getHeader();
+  unsigned NumBuckets = getEndianAdjustedWord(Hdr.NumBuckets);
+  StringRef RetKey;
+  for (unsigned i = 0; i != NumBuckets; ++i) {
+HMapBucket B = getBucket(i);
+if (B.Key == HMAP_EmptyBucketKey)
+  continue;
+
+Optional Key = getString(B.Key);
+Optional Prefix = getString(B.Prefix);
+Optional Suffix = getString(B.Suffix);
+if (LLVM_LIKELY(Key && Prefix && Suffix)) {
+  SmallVector Buf;
+  Buf.append(Prefix->begin(), Prefix->end());
+  Buf.append(Suffix->begin(), Suffix->end());
+  StringRef Value(Buf.begin(), Buf.size());
+  ReverseMap[Value] = *Key;
+
+  if (DestPath == Value)
+RetKey = *Key;
+}
+  }
+  return RetKey;
+}

diff  --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 99c92e91aad51..9970c3c99a27f 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -1834,7 +1834,7 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
   };
 
   for (unsigned I = 0; I != SearchDirs.size(); ++I) {
-// FIXME: Support this search within frameworks and header maps.
+// FIXME: Support this search within frameworks.
 if (!SearchDirs[I].isNormalDir())
   continue;
 
@@ -1848,6 +1848,19 @@ std::string 
HeaderSearch::suggestPathToFileForDiagnostics(
   if (!BestPrefixLength && CheckDir(path::parent_path(MainFile)) && IsSystem)
 *IsSystem = false;
 
+  // Try resolving resulting filename via reverse search in header maps,
+  // key from header name is user prefered name for the include file.
+  StringRef Filename = File.drop_front(BestPrefixLength);
+  for (unsigned I = 0; I != SearchDirs.size(); ++I) {
+if (!SearchDirs[I].isHeaderMap())
+  continue;
 
-  return 

[clang] 37b530a - [clang] NFC: split HeaderMapTest to have re-usable header map implementation for testing

2021-05-31 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2021-05-31T01:57:36-07:00
New Revision: 37b530a2ea8bdc28a22a3f8ca701455fb7febdea

URL: 
https://github.com/llvm/llvm-project/commit/37b530a2ea8bdc28a22a3f8ca701455fb7febdea
DIFF: 
https://github.com/llvm/llvm-project/commit/37b530a2ea8bdc28a22a3f8ca701455fb7febdea.diff

LOG: [clang] NFC: split HeaderMapTest to have re-usable header map 
implementation for testing

NFC changes required for https://reviews.llvm.org/D103142

Test Plan: check-clang

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

Added: 
clang/unittests/Lex/HeaderMapTestUtils.h

Modified: 
clang/unittests/Lex/HeaderMapTest.cpp

Removed: 




diff  --git a/clang/unittests/Lex/HeaderMapTest.cpp 
b/clang/unittests/Lex/HeaderMapTest.cpp
index c18ce79ef58f0..4220edb2908e0 100644
--- a/clang/unittests/Lex/HeaderMapTest.cpp
+++ b/clang/unittests/Lex/HeaderMapTest.cpp
@@ -6,89 +6,17 @@
 //
 //===--===//
 
-#include "clang/Basic/CharInfo.h"
-#include "clang/Lex/HeaderMap.h"
-#include "clang/Lex/HeaderMapTypes.h"
+#include "HeaderMapTestUtils.h"
 #include "llvm/ADT/SmallString.h"
-#include "llvm/Support/SwapByteOrder.h"
 #include "gtest/gtest.h"
-#include 
 #include 
 
 using namespace clang;
 using namespace llvm;
+using namespace clang::test;
 
 namespace {
 
-// Lay out a header file for testing.
-template  struct MapFile {
-  HMapHeader Header;
-  HMapBucket Buckets[NumBuckets];
-  unsigned char Bytes[NumBytes];
-
-  void init() {
-memset(this, 0, sizeof(MapFile));
-Header.Magic = HMAP_HeaderMagicNumber;
-Header.Version = HMAP_HeaderVersion;
-Header.NumBuckets = NumBuckets;
-Header.StringsOffset = sizeof(Header) + sizeof(Buckets);
-  }
-
-  void swapBytes() {
-using llvm::sys::getSwappedBytes;
-Header.Magic = getSwappedBytes(Header.Magic);
-Header.Version = getSwappedBytes(Header.Version);
-Header.NumBuckets = getSwappedBytes(Header.NumBuckets);
-Header.StringsOffset = getSwappedBytes(Header.StringsOffset);
-  }
-
-  std::unique_ptr getBuffer() const {
-return MemoryBuffer::getMemBuffer(
-StringRef(reinterpret_cast(this), sizeof(MapFile)),
-"header",
-/* RequresNullTerminator */ false);
-  }
-};
-
-// The header map hash function.
-static inline unsigned getHash(StringRef Str) {
-  unsigned Result = 0;
-  for (char C : Str)
-Result += toLowercase(C) * 13;
-  return Result;
-}
-
-template  struct FileMaker {
-  FileTy 
-  unsigned SI = 1;
-  unsigned BI = 0;
-  FileMaker(FileTy ) : File(File) {}
-
-  unsigned addString(StringRef S) {
-assert(SI + S.size() + 1 <= sizeof(File.Bytes));
-std::copy(S.begin(), S.end(), File.Bytes + SI);
-auto OldSI = SI;
-SI += S.size() + 1;
-return OldSI;
-  }
-  void addBucket(unsigned Hash, unsigned Key, unsigned Prefix, unsigned 
Suffix) {
-assert(!(File.Header.NumBuckets & (File.Header.NumBuckets - 1)));
-unsigned I = Hash & (File.Header.NumBuckets - 1);
-do {
-  if (!File.Buckets[I].Key) {
-File.Buckets[I].Key = Key;
-File.Buckets[I].Prefix = Prefix;
-File.Buckets[I].Suffix = Suffix;
-++File.Header.NumEntries;
-return;
-  }
-  ++I;
-  I &= File.Header.NumBuckets - 1;
-} while (I != (Hash & (File.Header.NumBuckets - 1)));
-llvm_unreachable("no empty buckets");
-  }
-};
-
 TEST(HeaderMapTest, checkHeaderEmpty) {
   bool NeedsSwap;
   ASSERT_FALSE(HeaderMapImpl::checkHeader(
@@ -98,7 +26,7 @@ TEST(HeaderMapTest, checkHeaderEmpty) {
 }
 
 TEST(HeaderMapTest, checkHeaderMagic) {
-  MapFile<1, 1> File;
+  HMapFileMock<1, 1> File;
   File.init();
   File.Header.Magic = 0;
   bool NeedsSwap;
@@ -106,7 +34,7 @@ TEST(HeaderMapTest, checkHeaderMagic) {
 }
 
 TEST(HeaderMapTest, checkHeaderReserved) {
-  MapFile<1, 1> File;
+  HMapFileMock<1, 1> File;
   File.init();
   File.Header.Reserved = 1;
   bool NeedsSwap;
@@ -114,7 +42,7 @@ TEST(HeaderMapTest, checkHeaderReserved) {
 }
 
 TEST(HeaderMapTest, checkHeaderVersion) {
-  MapFile<1, 1> File;
+  HMapFileMock<1, 1> File;
   File.init();
   ++File.Header.Version;
   bool NeedsSwap;
@@ -122,7 +50,7 @@ TEST(HeaderMapTest, checkHeaderVersion) {
 }
 
 TEST(HeaderMapTest, checkHeaderValidButEmpty) {
-  MapFile<1, 1> File;
+  HMapFileMock<1, 1> File;
   File.init();
   bool NeedsSwap;
   ASSERT_TRUE(HeaderMapImpl::checkHeader(*File.getBuffer(), NeedsSwap));
@@ -134,7 +62,7 @@ TEST(HeaderMapTest, checkHeaderValidButEmpty) {
 }
 
 TEST(HeaderMapTest, checkHeader3Buckets) {
-  MapFile<3, 1> File;
+  HMapFileMock<3, 1> File;
   ASSERT_EQ(3 * sizeof(HMapBucket), sizeof(File.Buckets));
 
   File.init();
@@ -144,7 +72,7 @@ TEST(HeaderMapTest, checkHeader3Buckets) {
 
 TEST(HeaderMapTest, checkHeader0Buckets) {
   // Create with 1 bucket to avoid 0-sized arrays.
-  MapFile<1, 1> File;
+  HMapFileMock<1, 1> File;
   File.init();
   

[clang-tools-extra] 338d162 - [clang-tidy] Ignore all spaces in the list of checks

2021-03-24 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2021-03-24T06:43:13-07:00
New Revision: 338d16275571df4d841609d7e12bcb310b3a95e6

URL: 
https://github.com/llvm/llvm-project/commit/338d16275571df4d841609d7e12bcb310b3a95e6
DIFF: 
https://github.com/llvm/llvm-project/commit/338d16275571df4d841609d7e12bcb310b3a95e6.diff

LOG: [clang-tidy] Ignore all spaces in the list of checks

This diff patch fixes issue with new line character after check name and before 
comma. Also ignores all other types of spaces like TAB.

Test Plan: ninja check-clang-tools

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

Added: 

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file-spaces

Modified: 
clang-tools-extra/clang-tidy/GlobList.cpp
clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/GlobList.cpp 
b/clang-tools-extra/clang-tidy/GlobList.cpp
index 43945fcdc074..863bb4672852 100644
--- a/clang-tools-extra/clang-tidy/GlobList.cpp
+++ b/clang-tools-extra/clang-tidy/GlobList.cpp
@@ -15,7 +15,7 @@ using namespace tidy;
 // Returns true if GlobList starts with the negative indicator ('-'), removes 
it
 // from the GlobList.
 static bool consumeNegativeIndicator(StringRef ) {
-  GlobList = GlobList.trim(" \r\n");
+  GlobList = GlobList.trim();
   if (GlobList.startswith("-")) {
 GlobList = GlobList.substr(1);
 return true;
@@ -27,7 +27,7 @@ static bool consumeNegativeIndicator(StringRef ) {
 // removes it and the trailing comma from the GlobList.
 static llvm::Regex consumeGlob(StringRef ) {
   StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find(','));
-  StringRef Glob = UntrimmedGlob.trim(' ');
+  StringRef Glob = UntrimmedGlob.trim();
   GlobList = GlobList.substr(UntrimmedGlob.size() + 1);
   SmallString<128> RegexText("^");
   StringRef MetaChars("()^$|*+?.[]\\{}");

diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file-spaces
 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file-spaces
new file mode 100644
index ..4aa1f846ade6
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file-spaces
@@ -0,0 +1,9 @@
+Checks: "
+  -*
+  ,
+  hicpp-uppercase-literal-suffix
+  ,hicpp-use-auto
+
+
+  ,  hicpp-use-emplace
+"

diff  --git a/clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp
index 49028d198f75..16b216a1d4f6 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp
@@ -1,2 +1,8 @@
 // RUN: clang-tidy -config-file=%S/Inputs/config-file/config-file -dump-config 
-- | FileCheck %s -check-prefix=CHECK-BASE
 // CHECK-BASE: Checks: {{.*}}hicpp-uppercase-literal-suffix
+// RUN: clang-tidy -config-file=%S/Inputs/config-file/config-file-spaces 
--list-checks -- | FileCheck %s -check-prefix=CHECK-SPACES
+// CHECK-SPACES: Enabled checks:
+// CHECK-SPACES-NEXT: hicpp-uppercase-literal-suffix
+// CHECK-SPACES-NEXT: hicpp-use-auto
+// CHECK-SPACES-NEXT: hicpp-use-emplace
+// CHECK-SPACES-EMPTY:



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


[clang-tools-extra] da55af7 - [clang-tidy] Enable modernize-concat-nested-namespaces also on headers

2021-03-15 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2021-03-15T07:32:45-07:00
New Revision: da55af7f1d348c133774d8e8117d60462363fef5

URL: 
https://github.com/llvm/llvm-project/commit/da55af7f1d348c133774d8e8117d60462363fef5
DIFF: 
https://github.com/llvm/llvm-project/commit/da55af7f1d348c133774d8e8117d60462363fef5.diff

LOG: [clang-tidy] Enable modernize-concat-nested-namespaces also on headers

For some reason the initial implementation of the check had an explicit check
for the main file to avoid being applied in headers. This diff removes this
check and add a test for the check on a header.

Similar approach was proposed in D61989 but review there got stuck.

Test Plan: added new test case

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

Added: 

clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h

Modified: 
clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp

clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
index 83c3fac949ba..e55b260060ce 100644
--- a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -82,9 +82,6 @@ void ConcatNestedNamespacesCheck::check(
   if (!locationsInSameFile(Sources, ND.getBeginLoc(), ND.getRBraceLoc()))
 return;
 
-  if (!Sources.isInMainFile(ND.getBeginLoc()))
-return;
-
   if (anonymousOrInlineNamespace(ND))
 return;
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
new file mode 100644
index ..752b33718dca
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
@@ -0,0 +1,8 @@
+namespace nn1 {
+namespace nn2 {
+// CHECK-FIXES: namespace nn1::nn2
+void t();
+} // namespace nn2
+} // namespace nn1
+// CHECK-FIXES: void t();
+// CHECK-FIXES-NEXT: } // namespace nn1

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
index dcde32d0f069..7c13c1c61cf2 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/modernize-concat-nested-namespaces.cpp
@@ -1,4 +1,13 @@
-// RUN: %check_clang_tidy -std=c++17-or-later %s 
modernize-concat-nested-namespaces %t
+// RUN: cp 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t 
-- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 -check-prefix=CHECK-FIXES
+// Restore header file and re-run with c++20:
+// RUN: cp 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 %T/modernize-concat-nested-namespaces.h
+// RUN: %check_clang_tidy -std=c++20 %s modernize-concat-nested-namespaces %t 
-- -header-filter=".*" -- -I %T
+// RUN: FileCheck -input-file=%T/modernize-concat-nested-namespaces.h 
%S/Inputs/modernize-concat-nested-namespaces/modernize-concat-nested-namespaces.h
 -check-prefix=CHECK-FIXES
+
+#include "modernize-concat-nested-namespaces.h"
+// CHECK-MESSAGES-DAG: modernize-concat-nested-namespaces.h:1:1: warning: 
nested namespaces can be concatenated [modernize-concat-nested-namespaces]
 
 namespace n1 {}
 
@@ -27,7 +36,7 @@ void t();
 
 namespace n9 {
 namespace n10 {
-// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: nested namespaces can be 
concatenated [modernize-concat-nested-namespaces]
+// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be 
concatenated [modernize-concat-nested-namespaces]
 // CHECK-FIXES: namespace n9::n10
 void t();
 } // namespace n10
@@ -36,7 +45,7 @@ void t();
 
 namespace n11 {
 namespace n12 {
-// CHECK-MESSAGES: :[[@LINE-2]]:1: warning: nested namespaces can be 
concatenated [modernize-concat-nested-namespaces]
+// CHECK-MESSAGES-DAG: :[[@LINE-2]]:1: warning: nested namespaces can be 
concatenated [modernize-concat-nested-namespaces]
 // CHECK-FIXES: namespace n11::n12
 namespace n13 {
 void t();
@@ -60,7 +69,7 @@ void t();
 namespace n18 {
 namespace n19 {
 namespace n20 {
-// CHECK-MESSAGES: :[[@LINE-3]]:1: warning: nested namespaces can be 
concatenated 

[clang-tools-extra] d6a468d - [clang-tidy] adding "--config-file=" to specify custom config file.

2020-11-03 Thread Dmitry Polukhin via cfe-commits

Author: Hiral Oza
Date: 2020-11-03T11:59:46Z
New Revision: d6a468d622b2d48c40c47290aa54d6d910c5a6bf

URL: 
https://github.com/llvm/llvm-project/commit/d6a468d622b2d48c40c47290aa54d6d910c5a6bf
DIFF: 
https://github.com/llvm/llvm-project/commit/d6a468d622b2d48c40c47290aa54d6d910c5a6bf.diff

LOG: [clang-tidy] adding "--config-file=" to specify custom config 
file.

Let clang-tidy to read config from specified file.
Example:
$ clang-tidy --config-file=/some/path/myTidyConfig --list-checks --
...this will read config from '/some/path/myTidyConfig'.

ClangTidyMain.cpp reads ConfigFile into string and then assigned read data to 
'Config' i.e. makes like '--config' code flow internally.

May speed-up tidy runtime since now it will just look-up 
instead of searching ".clang-tidy" in parent-dir(s).

Directly specifying config path helps setting build dependencies.

Thanks to @DmitryPolukhin for valuable suggestion. This patch now propose
change only in ClangTidyMain.cpp.

Reviewed By: DmitryPolukhin

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

Added: 

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file
clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp

Modified: 
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index e248c04ea570..e0465665d6a0 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -168,6 +168,16 @@ each source file in its parent directories.
 )"),
cl::init(""), cl::cat(ClangTidyCategory));
 
+static cl::opt ConfigFile("config-file", cl::desc(R"(
+Specify the path of .clang-tidy or custom config file:
+ e.g. --config-file=/some/path/myTidyConfigFile
+This option internally works exactly the same way as
+ --config option after reading specified config file.
+Use either --config-file or --config, not both.
+)"),
+   cl::init(""),
+   cl::cat(ClangTidyCategory));
+
 static cl::opt DumpConfig("dump-config", cl::desc(R"(
 Dumps configuration in the YAML format to
 stdout. This option can be used along with a
@@ -302,19 +312,41 @@ static std::unique_ptr 
createOptionsProvider(
   if (UseColor.getNumOccurrences() > 0)
 OverrideOptions.UseColor = UseColor;
 
-  if (!Config.empty()) {
-if (llvm::ErrorOr ParsedConfig =
-parseConfiguration(Config)) {
+  auto LoadConfig = [&](StringRef Configuration)
+  -> std::unique_ptr {
+llvm::ErrorOr ParsedConfig =
+parseConfiguration(Configuration);
+if (ParsedConfig)
   return std::make_unique(
   GlobalOptions,
   ClangTidyOptions::getDefaults().mergeWith(DefaultOptions, 0),
   *ParsedConfig, OverrideOptions, std::move(FS));
-} else {
-  llvm::errs() << "Error: invalid configuration specified.\n"
-   << ParsedConfig.getError().message() << "\n";
+llvm::errs() << "Error: invalid configuration specified.\n"
+ << ParsedConfig.getError().message() << "\n";
+return nullptr;
+  };
+
+  if (ConfigFile.getNumOccurrences() > 0) {
+if (Config.getNumOccurrences() > 0) {
+  llvm::errs() << "Error: --config-file and --config are "
+  "mutually exclusive. Specify only one.\n";
   return nullptr;
 }
+
+llvm::ErrorOr> Text =
+llvm::MemoryBuffer::getFile(ConfigFile.c_str());
+if (std::error_code EC = Text.getError()) {
+  llvm::errs() << "Error: can't read config-file '" << ConfigFile
+   << "': " << EC.message() << "\n";
+  return nullptr;
+}
+
+return LoadConfig((*Text)->getBuffer());
   }
+
+  if (Config.getNumOccurrences() > 0)
+return LoadConfig(Config);
+
   return std::make_unique(GlobalOptions, DefaultOptions,
 OverrideOptions, 
std::move(FS));
 }

diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file
 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file
new file mode 100644
index ..23bb65e0155b
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-file/config-file
@@ -0,0 +1 @@
+Checks: "-*,hicpp-uppercase-literal-suffix"

diff  --git a/clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp
new file mode 100644
index ..49028d198f75
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/config-file.cpp
@@ -0,0 +1,2 @@
+// RUN: clang-tidy -config-file=%S/Inputs/config-file/config-file -dump-config 
-- | FileCheck %s -check-prefix=CHECK-BASE
+// CHECK-BASE: 

[clang-tools-extra] 55a2dee - [clang-tidy] Fix redefinition of module in the same module.modulemap file

2020-10-23 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-10-23T13:20:18+01:00
New Revision: 55a2deed075b87646db62abc7bcd476541eda403

URL: 
https://github.com/llvm/llvm-project/commit/55a2deed075b87646db62abc7bcd476541eda403
DIFF: 
https://github.com/llvm/llvm-project/commit/55a2deed075b87646db62abc7bcd476541eda403.diff

LOG: [clang-tidy] Fix redefinition of module in the same module.modulemap file

In memory VFS cannot handle aceesssing the same file with different paths.
This diff just stops using VFS for modulemap files.

Fixes PR47839

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp 
b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index 4299baedd79f..9e693b62e50d 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -13,13 +13,22 @@
 #include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Serialization/ASTReader.h"
 
+#define DEBUG_TYPE "clang-tidy"
+
 namespace clang {
 namespace tooling {
 
 class ExpandModularHeadersPPCallbacks::FileRecorder {
 public:
   /// Records that a given file entry is needed for replaying callbacks.
-  void addNecessaryFile(const FileEntry *File) { FilesToRecord.insert(File); }
+  void addNecessaryFile(const FileEntry *File) {
+// Don't record modulemap files because it breaks same file detection.
+if (!(File->getName().endswith("module.modulemap") ||
+  File->getName().endswith("module.private.modulemap") ||
+  File->getName().endswith("module.map") ||
+  File->getName().endswith("module_private.map")))
+  FilesToRecord.insert(File);
+  }
 
   /// Records content for a file and adds it to the FileSystem.
   void recordFileContent(const FileEntry *File,
@@ -44,8 +53,8 @@ class ExpandModularHeadersPPCallbacks::FileRecorder {
   /// `FilesToRecord` should be empty.
   void checkAllFilesRecorded() {
 for (auto FileEntry : FilesToRecord)
-  llvm::errs() << "Did not record contents for input file: "
-   << FileEntry->getName() << "\n";
+  LLVM_DEBUG(llvm::dbgs() << "Did not record contents for input file: "
+  << FileEntry->getName() << "\n");
   }
 
 private:



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


[clang] 9e7fddb - [yaml][clang-tidy] Fix multiline YAML serialization

2020-07-09 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-07-09T02:41:58-07:00
New Revision: 9e7fddbd36f567217255c1df1cb816b79f0250af

URL: 
https://github.com/llvm/llvm-project/commit/9e7fddbd36f567217255c1df1cb816b79f0250af
DIFF: 
https://github.com/llvm/llvm-project/commit/9e7fddbd36f567217255c1df1cb816b79f0250af.diff

LOG: [yaml][clang-tidy] Fix multiline YAML serialization

Summary:
New line duplication logic introduced in https://reviews.llvm.org/D63482
has two issues: (1) there is no logic that removes duplicate newlines
when clang-apply-replacment reads YAML and (2) in general such logic
should be applied to all strings and should happen on string
serialization level instead in YAML parser.

This diff changes multiline strings quotation from single quote `'` to
double `"`. It solves problems with internal newlines because now they are
escaped. Also double quotation solves the problem with leading whitespace after
newline. In case of single quotation YAML parsers should remove leading
whitespace according to specification. In case of double quotation these
leading are internal space and they are preserved. There is no way to
instruct YAML parsers to preserve leading whitespaces after newline so
double quotation is the only viable option that solves all problems at
once.

Test Plan: check-all

Reviewers: gribozavr, mgehre, yvvan

Subscribers: xazax.hun, hiraditya, cfe-commits, llvm-commits

Tags: #clang-tools-extra, #clang, #llvm

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

Added: 


Modified: 
clang/include/clang/Tooling/ReplacementsYaml.h
clang/unittests/Tooling/ReplacementsYamlTest.cpp
llvm/include/llvm/Support/YAMLTraits.h
llvm/lib/Support/YAMLTraits.cpp
llvm/test/Transforms/LowerMatrixIntrinsics/remarks-shared-subtrees.ll
llvm/unittests/Support/YAMLIOTest.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/ReplacementsYaml.h 
b/clang/include/clang/Tooling/ReplacementsYaml.h
index 2e3e401652e2..83e35d623255 100644
--- a/clang/include/clang/Tooling/ReplacementsYaml.h
+++ b/clang/include/clang/Tooling/ReplacementsYaml.h
@@ -35,13 +35,7 @@ template <> struct 
MappingTraits {
 
 NormalizedReplacement(const IO &, const clang::tooling::Replacement )
 : FilePath(R.getFilePath()), Offset(R.getOffset()),
-  Length(R.getLength()), ReplacementText(R.getReplacementText()) {
-  size_t lineBreakPos = ReplacementText.find('\n');
-  while (lineBreakPos != std::string::npos) {
-ReplacementText.replace(lineBreakPos, 1, "\n\n");
-lineBreakPos = ReplacementText.find('\n', lineBreakPos + 2);
-  }
-}
+  Length(R.getLength()), ReplacementText(R.getReplacementText()) {}
 
 clang::tooling::Replacement denormalize(const IO &) {
   return clang::tooling::Replacement(FilePath, Offset, Length,

diff  --git a/clang/unittests/Tooling/ReplacementsYamlTest.cpp 
b/clang/unittests/Tooling/ReplacementsYamlTest.cpp
index c8fe9c4db412..3328d9bad55c 100644
--- a/clang/unittests/Tooling/ReplacementsYamlTest.cpp
+++ b/clang/unittests/Tooling/ReplacementsYamlTest.cpp
@@ -65,7 +65,7 @@ TEST(ReplacementsYamlTest, serializesNewLines) {
"  - FilePath:'/path/to/file1.h'\n"
"Offset:  0\n"
"Length:  0\n"
-   "ReplacementText: '#include \n\n'\n"
+   "ReplacementText: \"#include \\n\"\n"
"...\n",
YamlContentStream.str().c_str());
 }

diff  --git a/llvm/include/llvm/Support/YAMLTraits.h 
b/llvm/include/llvm/Support/YAMLTraits.h
index f93f36037679..44e34a4a09b4 100644
--- a/llvm/include/llvm/Support/YAMLTraits.h
+++ b/llvm/include/llvm/Support/YAMLTraits.h
@@ -649,24 +649,25 @@ inline bool isBool(StringRef S) {
 inline QuotingType needsQuotes(StringRef S) {
   if (S.empty())
 return QuotingType::Single;
+
+  QuotingType MaxQuotingNeeded = QuotingType::None;
   if (isSpace(static_cast(S.front())) ||
   isSpace(static_cast(S.back(
-return QuotingType::Single;
+MaxQuotingNeeded = QuotingType::Single;
   if (isNull(S))
-return QuotingType::Single;
+MaxQuotingNeeded = QuotingType::Single;
   if (isBool(S))
-return QuotingType::Single;
+MaxQuotingNeeded = QuotingType::Single;
   if (isNumeric(S))
-return QuotingType::Single;
+MaxQuotingNeeded = QuotingType::Single;
 
   // 7.3.3 Plain Style
   // Plain scalars must not begin with most indicators, as this would cause
   // ambiguity with other YAML constructs.
   static constexpr char Indicators[] = R"(-?:\,[]{}#&*!|>'"%@`)";
   if (S.find_first_of(Indicators) == 0)
-return QuotingType::Single;
+MaxQuotingNeeded = QuotingType::Single;
 
-  QuotingType MaxQuotingNeeded = QuotingType::None;
   for (unsigned char C : S) {
 // Alphanum is safe.
 if (isAlnum(C))
@@ -684,11 +685,11 @@ inline QuotingType needsQuotes(StringRef S) {
 

[clang] c98c94d - [clang-tidy] Add diagnostics level to YAML output

2020-06-15 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-06-15T07:40:53-07:00
New Revision: c98c94d85f8591c22f369e8f35142379ba27bb33

URL: 
https://github.com/llvm/llvm-project/commit/c98c94d85f8591c22f369e8f35142379ba27bb33
DIFF: 
https://github.com/llvm/llvm-project/commit/c98c94d85f8591c22f369e8f35142379ba27bb33.diff

LOG: [clang-tidy] Add diagnostics level to YAML output

Summary:
Also added BuildDirectory for completness and removed unused `Fix`.

Test Plan: check-all

Reviewers: alexfh, gribozavr2

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra, #clang

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

Added: 


Modified: 
clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
clang/include/clang/Tooling/DiagnosticsYaml.h
clang/unittests/Tooling/DiagnosticsYamlTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
index eb77be8fbdb0..13d7684597e5 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/export-diagnostics.cpp
@@ -1,15 +1,17 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t-input.cpp
-// RUN: clang-tidy %t-input.cpp 
-checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes' 
-export-fixes=%t.yaml -- -Wmissing-prototypes > %t.msg 2>&1
+// RUN: not clang-tidy %t-input.cpp 
-checks='-*,google-explicit-constructor,clang-diagnostic-missing-prototypes' 
-export-fixes=%t.yaml -- -Wmissing-prototypes > %t.msg 2>&1
 // RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s 
-implicit-check-not='{{warning|error|note}}:'
 // RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s
 #define X(n) void n ## n() {}
 X(f)
+int a[-1];
 
 // CHECK-MESSAGES: -input.cpp:2:1: warning: no previous prototype for function 
'ff' [clang-diagnostic-missing-prototypes]
 // CHECK-MESSAGES: -input.cpp:1:19: note: expanded from macro 'X'
 // CHECK-MESSAGES: {{^}}note: expanded from here{{$}}
 // CHECK-MESSAGES: -input.cpp:2:1: note: declare 'static' if the function is 
not intended to be used outside of this translation unit
 // CHECK-MESSAGES: -input.cpp:1:14: note: expanded from macro 'X'
+// CHECK-MESSAGES: -input.cpp:3:7: error: 'a' declared as an array with a 
negative size [clang-diagnostic-error]
 
 // CHECK-YAML: ---
 // CHECK-YAML-NEXT: MainSourceFile:  '{{.*}}-input.cpp'
@@ -42,4 +44,18 @@ X(f)
 // CHECK-YAML-NEXT: FilePath:'{{.*}}-input.cpp'
 // CHECK-YAML-NEXT: FileOffset:  13
 // CHECK-YAML-NEXT: Replacements:[]
+// CHECK-YAML-NEXT: Level:   Warning
+// CHECK-YAML-NEXT: BuildDirectory:  '{{.*}}'
+// CHECK-YAML-NEXT:   - DiagnosticName:  clang-diagnostic-error
+// CHECK-YAML-NEXT: DiagnosticMessage:
+// CHECK-YAML-NEXT:   Message: '''a'' declared as an array with a 
negative size'
+// CHECK-YAML-NEXT:   FilePath:'{{.*}}-input.cpp'
+// CHECK-YAML-NEXT:   FileOffset:  41
+// CHECK-YAML-NEXT:   Replacements:[]
+// CHECK-YAML-NEXT: Level:   Error
+// CHECK-YAML-NEXT: BuildDirectory:  '{{.*}}'
+// CHECK-YAML-NEXT: Ranges:
+// CHECK-YAML-NEXT:  - FilePath:'{{.*}}-input.cpp'
+// CHECK-YAML-NEXT: FileOffset:  41
+// CHECK-YAML-NEXT: Length:  1
 // CHECK-YAML-NEXT: ...

diff  --git a/clang/include/clang/Tooling/DiagnosticsYaml.h 
b/clang/include/clang/Tooling/DiagnosticsYaml.h
index 38e49645dbb8..38fbcfc1da95 100644
--- a/clang/include/clang/Tooling/DiagnosticsYaml.h
+++ b/clang/include/clang/Tooling/DiagnosticsYaml.h
@@ -77,7 +77,6 @@ template <> struct MappingTraits {
 
 std::string DiagnosticName;
 clang::tooling::DiagnosticMessage Message;
-llvm::StringMap Fix;
 SmallVector Notes;
 clang::tooling::Diagnostic::Level DiagLevel;
 std::string BuildDirectory;
@@ -90,9 +89,9 @@ template <> struct MappingTraits {
 Io.mapRequired("DiagnosticName", Keys->DiagnosticName);
 Io.mapRequired("DiagnosticMessage", Keys->Message);
 Io.mapOptional("Notes", Keys->Notes);
+Io.mapOptional("Level", Keys->DiagLevel);
+Io.mapOptional("BuildDirectory", Keys->BuildDirectory);
 Io.mapOptional("Ranges", Keys->Ranges);
-
-// FIXME: Export properly all the 
diff erent fields.
   }
 };
 
@@ -104,6 +103,14 @@ template <> struct 
MappingTraits {
 Io.mapRequired("Diagnostics", Doc.Diagnostics);
   }
 };
+
+template <> struct ScalarEnumerationTraits {
+  static void enumeration(IO , clang::tooling::Diagnostic::Level ) {
+IO.enumCase(Value, "Warning", clang::tooling::Diagnostic::Warning);
+IO.enumCase(Value, "Error", clang::tooling::Diagnostic::Error);
+  }
+};
+
 } // end namespace yaml
 } // end namespace llvm
 

diff  --git 

[clang] a7afb21 - [clang][AST] Support AST files larger than 512M

2020-04-17 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-04-17T06:17:33-07:00
New Revision: a7afb211dc460bd4cfb2542ad1f9b05876b57ba1

URL: 
https://github.com/llvm/llvm-project/commit/a7afb211dc460bd4cfb2542ad1f9b05876b57ba1
DIFF: 
https://github.com/llvm/llvm-project/commit/a7afb211dc460bd4cfb2542ad1f9b05876b57ba1.diff

LOG: [clang][AST] Support AST files larger than 512M

Summary:
Clang uses 32-bit integers for storing bit offsets from the beginning of
the file that results in 512M limit on AST file. This diff replaces
absolute offsets with relative offsets from the beginning of
corresponding data structure when it is possible. And uses 64-bit
offsets for DeclOffests and TypeOffssts because these coder AST
section may easily exceeds 512M alone.

This diff breaks AST file format compatibility so VERSION_MAJOR bumped.

Test Plan:
Existing clang AST serialization tests
Tested on clangd with ~700M and ~900M preamble files
check-clang with ubsan

Reviewers: rsmith, dexonsmith

Subscribers: ilya-biryukov, kadircet, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/include/clang/Serialization/ModuleFile.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 323edfbf8126..d5a27f487fa9 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -41,7 +41,7 @@ namespace serialization {
 /// Version 4 of AST files also requires that the version control branch 
and
 /// revision match exactly, since there is no backward compatibility of
 /// AST files at this time.
-const unsigned VERSION_MAJOR = 9;
+const unsigned VERSION_MAJOR = 10;
 
 /// AST file minor version number supported by this version of
 /// Clang.
@@ -181,7 +181,7 @@ namespace serialization {
   /// Raw source location of end of range.
   unsigned End;
 
-  /// Offset in the AST file.
+  /// Offset in the AST file relative to ModuleFile::MacroOffsetsBase.
   uint32_t BitOffset;
 
   PPEntityOffset(SourceRange R, uint32_t BitOffset)
@@ -216,17 +216,41 @@ namespace serialization {
   }
 };
 
-/// Source range/offset of a preprocessed entity.
+/// Offset in the AST file. Use splitted 64-bit integer into low/high
+/// parts to keep structure alignment 32-bit (it is important because
+/// blobs in bitstream are 32-bit aligned). This structure is serialized
+/// "as is" to the AST file.
+struct UnderalignedInt64 {
+  uint32_t BitOffsetLow = 0;
+  uint32_t BitOffsetHigh = 0;
+
+  UnderalignedInt64() = default;
+  UnderalignedInt64(uint64_t BitOffset) { setBitOffset(BitOffset); }
+
+  void setBitOffset(uint64_t Offset) {
+BitOffsetLow = Offset;
+BitOffsetHigh = Offset >> 32;
+  }
+
+  uint64_t getBitOffset() const {
+return BitOffsetLow | (uint64_t(BitOffsetHigh) << 32);
+  }
+};
+
+/// Source location and bit offset of a declaration.
 struct DeclOffset {
   /// Raw source location.
   unsigned Loc = 0;
 
-  /// Offset in the AST file.
-  uint32_t BitOffset = 0;
+  /// Offset in the AST file. Keep structure alignment 32-bit and avoid
+  /// padding gap because undefined value in the padding affects AST hash.
+  UnderalignedInt64 BitOffset;
 
   DeclOffset() = default;
-  DeclOffset(SourceLocation Loc, uint32_t BitOffset)
-: Loc(Loc.getRawEncoding()), BitOffset(BitOffset) {}
+  DeclOffset(SourceLocation Loc, uint64_t BitOffset) {
+setLocation(Loc);
+setBitOffset(BitOffset);
+  }
 
   void setLocation(SourceLocation L) {
 Loc = L.getRawEncoding();
@@ -235,6 +259,14 @@ namespace serialization {
   SourceLocation getLocation() const {
 return SourceLocation::getFromRawEncoding(Loc);
   }
+
+  void setBitOffset(uint64_t Offset) {
+BitOffset.setBitOffset(Offset);
+  }
+
+  uint64_t getBitOffset() const {
+return BitOffset.getBitOffset();
+  }
 };
 
 /// The number of predefined preprocessed entity IDs.

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 94645fff9f93..11a537fad5d5 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -723,9 +723,10 @@ class ASTReader
 
   struct PendingMacroInfo {
 ModuleFile *M;
-uint64_t MacroDirectivesOffset;
+/// 

[clang] a8f85da - Revert "[clang][AST] Support AST files larger than 512M"

2020-04-16 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-04-16T09:09:38-07:00
New Revision: a8f85da9f538a400dfea00e4954e403bf5f3269c

URL: 
https://github.com/llvm/llvm-project/commit/a8f85da9f538a400dfea00e4954e403bf5f3269c
DIFF: 
https://github.com/llvm/llvm-project/commit/a8f85da9f538a400dfea00e4954e403bf5f3269c.diff

LOG: Revert "[clang][AST] Support AST files larger than 512M"

Bitcode file alignment is only 32-bit so 64-bit offsets need
special handling.
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28:
 runtime error: load of misaligned address 0x7fca2bcfe54c for type 'const 
uint64_t' (aka 'const unsigned long'), which requires 8 byte alignment
0x7fca2bcfe54c: note: pointer points here
  00 00 00 00 5a a6 01 00  00 00 00 00 19 a7 01 00  00 00 00 00 48 a7 01 00  00 
00 00 00 7d a7 01 00
  ^
#0 0x3be2fe4 in clang::ASTReader::TypeCursorForIndex(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6327:28
#1 0x3be30a0 in clang::ASTReader::readTypeRecord(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6348:24
#2 0x3bd3d4a in clang::ASTReader::GetType(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:6985:26
#3 0x3c5d9ae in clang::ASTDeclReader::Visit(clang::Decl*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp:533:31
#4 0x3c91cac in clang::ASTReader::ReadDeclRecord(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReaderDecl.cpp:4045:10
#5 0x3bd4fb1 in clang::ASTReader::GetDecl(unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:7352:5
#6 0x3bce2f9 in 
clang::ASTReader::ReadASTBlock(clang::serialization::ModuleFile&, unsigned int) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:3625:22
#7 0x3bd6d75 in clang::ASTReader::ReadAST(llvm::StringRef, 
clang::serialization::ModuleKind, clang::SourceLocation, unsigned int, 
llvm::SmallVectorImpl*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Serialization/ASTReader.cpp:4230:32
#8 0x3a6b415 in 
clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, 
llvm::StringRef, bool, bool, clang::Preprocessor&, clang::InMemoryModuleCache&, 
clang::ASTContext&, clang::PCHContainerReader const&, 
llvm::ArrayRef >, 
llvm::ArrayRef >, void*, bool, 
bool, bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:539:19
#9 0x3a6b00e in 
clang::CompilerInstance::createPCHExternalASTSource(llvm::StringRef, bool, 
bool, void*, bool) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:501:18
#10 0x3abac80 in 
clang::FrontendAction::BeginSourceFile(clang::CompilerInstance&, 
clang::FrontendInputFile const&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/FrontendAction.cpp:865:12
#11 0x3a6e61c in 
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:972:13
#12 0x3ba74bf in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:282:25
#13 0xa3f753 in cc1_main(llvm::ArrayRef, char const*, void*) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/driver/cc1_main.cpp:240:15
#14 0xa3a68a in ExecuteCC1Tool(llvm::SmallVectorImpl&) 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/driver/driver.cpp:330:12
#15 0xa37f31 in main 
/b/sanitizer-x86_64-linux-fast/build/llvm-project/clang/tools/driver/driver.cpp:407:12
#16 0x7fca2a7032e0 in __libc_start_main 
(/lib/x86_64-linux-gnu/libc.so.6+0x202e0)
#17 0xa21029 in _start 
(/b/sanitizer-x86_64-linux-fast/build/llvm_build_ubsan/bin/clang-11+0xa21029)

This reverts commit 30d5946db95fa465d7ee6caceb2b1ff191e3727c.

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/include/clang/Serialization/ModuleFile.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 198d8e3b4fed..323edfbf8126 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -41,7 +41,7 @@ namespace serialization {
 /// Version 4 of AST files also requires 

[clang] 30d5946 - [clang][AST] Support AST files larger than 512M

2020-04-16 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-04-16T07:27:43-07:00
New Revision: 30d5946db95fa465d7ee6caceb2b1ff191e3727c

URL: 
https://github.com/llvm/llvm-project/commit/30d5946db95fa465d7ee6caceb2b1ff191e3727c
DIFF: 
https://github.com/llvm/llvm-project/commit/30d5946db95fa465d7ee6caceb2b1ff191e3727c.diff

LOG: [clang][AST] Support AST files larger than 512M

Summary:
Clang uses 32-bit integers for storing bit offsets from the beginning of
the file that results in 512M limit on AST file. This diff replaces
absolute offsets with relative offsets from the beginning of
corresponding data structure when it is possible. And uses 64-bit
offsets for DeclOffests and TypeOffssts because these coder AST
section may easily exceeds 512M alone.

This diff breaks AST file format compatibility so VERSION_MAJOR bumped.

Test Plan:
Existing clang AST serialization tests
Tested on clangd with ~700M and ~900M preamble files

Reviewers: rsmith, dexonsmith

Subscribers: ilya-biryukov, kadircet, usaxena95, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Serialization/ASTBitCodes.h
clang/include/clang/Serialization/ASTReader.h
clang/include/clang/Serialization/ASTWriter.h
clang/include/clang/Serialization/ModuleFile.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 323edfbf8126..198d8e3b4fed 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -41,7 +41,7 @@ namespace serialization {
 /// Version 4 of AST files also requires that the version control branch 
and
 /// revision match exactly, since there is no backward compatibility of
 /// AST files at this time.
-const unsigned VERSION_MAJOR = 9;
+const unsigned VERSION_MAJOR = 10;
 
 /// AST file minor version number supported by this version of
 /// Clang.
@@ -181,7 +181,7 @@ namespace serialization {
   /// Raw source location of end of range.
   unsigned End;
 
-  /// Offset in the AST file.
+  /// Offset in the AST file relative to ModuleFile::MacroOffsetsBase.
   uint32_t BitOffset;
 
   PPEntityOffset(SourceRange R, uint32_t BitOffset)
@@ -221,12 +221,18 @@ namespace serialization {
   /// Raw source location.
   unsigned Loc = 0;
 
-  /// Offset in the AST file.
-  uint32_t BitOffset = 0;
+  /// Offset in the AST file. Split 64-bit integer into low/high parts
+  /// to keep structure alignment 32-bit and don't have padding gap.
+  /// This structure is serialized "as is" to the AST file and undefined
+  /// value in the padding affects AST hash.
+  uint32_t BitOffsetLow = 0;
+  uint32_t BitOffsetHigh = 0;
 
   DeclOffset() = default;
-  DeclOffset(SourceLocation Loc, uint32_t BitOffset)
-: Loc(Loc.getRawEncoding()), BitOffset(BitOffset) {}
+  DeclOffset(SourceLocation Loc, uint64_t BitOffset) {
+setLocation(Loc);
+setBitOffset(BitOffset);
+  }
 
   void setLocation(SourceLocation L) {
 Loc = L.getRawEncoding();
@@ -235,6 +241,15 @@ namespace serialization {
   SourceLocation getLocation() const {
 return SourceLocation::getFromRawEncoding(Loc);
   }
+
+  void setBitOffset(uint64_t Offset) {
+BitOffsetLow = Offset;
+BitOffsetHigh = Offset >> 32;
+  }
+
+  uint64_t getBitOffset() const {
+return BitOffsetLow | (uint64_t(BitOffsetHigh) << 32);
+  }
 };
 
 /// The number of predefined preprocessed entity IDs.

diff  --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index 94645fff9f93..11a537fad5d5 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -723,9 +723,10 @@ class ASTReader
 
   struct PendingMacroInfo {
 ModuleFile *M;
-uint64_t MacroDirectivesOffset;
+/// Offset relative to ModuleFile::MacroOffsetsBase.
+uint32_t MacroDirectivesOffset;
 
-PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
+PendingMacroInfo(ModuleFile *M, uint32_t MacroDirectivesOffset)
 : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
   };
 
@@ -2205,7 +2206,7 @@ class ASTReader
   /// \param MacroDirectivesOffset Offset of the serialized macro directive
   /// history.
   void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
-   uint64_t MacroDirectivesOffset);
+   uint32_t MacroDirectivesOffset);
 
   /// Read the set of macros defined by this external macro source.
   void ReadDefinedMacros() 

[clang-tools-extra] cb1ee34 - [clang-tidy] Optional inheritance of file configs from parent directories 

2020-04-15 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-04-15T06:41:31-07:00
New Revision: cb1ee34e9d32fce84613827693a8ed3aff1d36cf

URL: 
https://github.com/llvm/llvm-project/commit/cb1ee34e9d32fce84613827693a8ed3aff1d36cf
DIFF: 
https://github.com/llvm/llvm-project/commit/cb1ee34e9d32fce84613827693a8ed3aff1d36cf.diff

LOG: [clang-tidy] Optional inheritance of file configs from parent directories 

Summary:
Without this patch clang-tidy stops finding file configs on the nearest
.clang-tidy file. In some cases it is not very convenient because it
results in common parts duplication into every child .clang-tidy file.
This diff adds optional config inheritance from the parent directories
config files.

Test Plan:

Added test cases in existing config test.

Reviewers: alexfh, gribozavr2, klimek, hokein

Subscribers: njames93, arphaman, xazax.hun, aheejin, cfe-commits

Tags: #clang, #clang-tools-extra

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

Added: 

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/3/.clang-tidy

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/.clang-tidy

clang-tools-extra/test/clang-tidy/infrastructure/Inputs/config-files/4/44/.clang-tidy

Modified: 
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/clang-tidy/ClangTidyOptions.h
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/docs/clang-tidy/index.rst
clang-tools-extra/test/clang-tidy/infrastructure/config-files.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 05594f191a5f..367fa3dda5cf 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -328,7 +328,9 @@ static void setStaticAnalyzerCheckerOpts(const 
ClangTidyOptions ,
 StringRef OptName(Opt.first);
 if (!OptName.startswith(AnalyzerPrefix))
   continue;
-AnalyzerOptions->Config[OptName.substr(AnalyzerPrefix.size())] = 
Opt.second;
+// Analyzer options are always local options so we can ignore priority.
+AnalyzerOptions->Config[OptName.substr(AnalyzerPrefix.size())] =
+Opt.second.Value;
   }
 }
 

diff  --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index aadf372cda1a..7ddf054a21a9 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -72,19 +72,20 @@ llvm::Expected
 ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
   const auto  = CheckOptions.find(NamePrefix + LocalName.str());
   if (Iter != CheckOptions.end())
-return Iter->second;
+return Iter->second.Value;
   return llvm::make_error((NamePrefix + LocalName).str());
 }
 
 llvm::Expected
 ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const {
-  auto Iter = CheckOptions.find(NamePrefix + LocalName.str());
-  if (Iter != CheckOptions.end())
-return Iter->second;
-  // Fallback to global setting, if present.
-  Iter = CheckOptions.find(LocalName.str());
-  if (Iter != CheckOptions.end())
-return Iter->second;
+  auto IterLocal = CheckOptions.find(NamePrefix + LocalName.str());
+  auto IterGlobal = CheckOptions.find(LocalName.str());
+  if (IterLocal != CheckOptions.end() &&
+  (IterGlobal == CheckOptions.end() ||
+   IterLocal->second.Priority >= IterGlobal->second.Priority))
+return IterLocal->second.Value;
+  if (IterGlobal != CheckOptions.end())
+return IterGlobal->second.Value;
   return llvm::make_error((NamePrefix + LocalName).str());
 }
 
@@ -123,17 +124,15 @@ bool ClangTidyCheck::OptionsView::get(StringRef 
LocalName,
 template <>
 llvm::Expected
 ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const 
{
-  llvm::Expected ValueOr = get(LocalName);
-  bool IsGlobal = false;
-  if (!ValueOr) {
-llvm::consumeError(ValueOr.takeError());
-ValueOr = getLocalOrGlobal(LocalName);
-IsGlobal = true;
-  }
-  if (!ValueOr)
-return ValueOr.takeError();
-  return getAsBool(*ValueOr, IsGlobal ? llvm::Twine(LocalName)
-  : (NamePrefix + LocalName));
+  auto IterLocal = CheckOptions.find(NamePrefix + LocalName.str());
+  auto IterGlobal = CheckOptions.find(LocalName.str());
+  if (IterLocal != CheckOptions.end() &&
+  (IterGlobal == CheckOptions.end() ||
+   IterLocal->second.Priority >= IterGlobal->second.Priority))
+return getAsBool(IterLocal->second.Value, NamePrefix + LocalName);
+  if (IterGlobal != CheckOptions.end())
+return getAsBool(IterGlobal->second.Value, llvm::Twine(LocalName));
+  

[clang-tools-extra] 3f8b100 - [clang-tidy] Add library for clang-tidy main function

2020-01-24 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-01-24T13:00:45-08:00
New Revision: 3f8b100e94b5c848843fa91c9782d9d4df4bb026

URL: 
https://github.com/llvm/llvm-project/commit/3f8b100e94b5c848843fa91c9782d9d4df4bb026
DIFF: 
https://github.com/llvm/llvm-project/commit/3f8b100e94b5c848843fa91c9782d9d4df4bb026.diff

LOG: [clang-tidy] Add library for clang-tidy main function

Summary:
This library allows to create clang-tidy tools with custom checks outside of 
llvm repo
using prebuilt clang release tarball.

Test Plan:
Checked that clang-tidy works as before. New library exists in istall dir.

Reviewers: smeenai, gribozavr, stephanemoore

Subscribers: mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra, #clang

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

Added: 
clang-tools-extra/clang-tidy/tool/ClangTidyMain.h
clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp

Modified: 
clang-tools-extra/clang-tidy/tool/CMakeLists.txt
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/tool/CMakeLists.txt
index 073749a7d836..0cd15ddb4653 100644
--- a/clang-tools-extra/clang-tidy/tool/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/tool/CMakeLists.txt
@@ -5,8 +5,24 @@ set(LLVM_LINK_COMPONENTS
   support
   )
 
-add_clang_tool(clang-tidy
+# Needed by LLVM's CMake checks because this file defines multiple targets.
+set(LLVM_OPTIONAL_SOURCES ClangTidyMain.cpp ClangTidyToolMain.cpp)
+
+add_clang_library(clangTidyMain
   ClangTidyMain.cpp
+
+  LINK_LIBS
+  clangAST
+  clangASTMatchers
+  clangBasic
+  clangTidy
+  ${ALL_CLANG_TIDY_CHECKS}
+  clangTooling
+  clangToolingCore
+  )
+
+add_clang_tool(clang-tidy
+  ClangTidyToolMain.cpp
   )
 add_dependencies(clang-tidy
   clang-resource-headers
@@ -22,6 +38,7 @@ clang_target_link_libraries(clang-tidy
 target_link_libraries(clang-tidy
   PRIVATE
   clangTidy
+  clangTidyMain
   ${ALL_CLANG_TIDY_CHECKS}
   )
 

diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index ad6182def20d..c6927cc6bd98 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -14,6 +14,7 @@
 ///
 
//===--===//
 
+#include "ClangTidyMain.h"
 #include "../ClangTidy.h"
 #include "../ClangTidyForceLinker.h"
 #include "../GlobList.h"
@@ -327,7 +328,7 @@ getVfsFromFile(const std::string ,
   return FS;
 }
 
-static int clangTidyMain(int argc, const char **argv) {
+int clangTidyMain(int argc, const char **argv) {
   llvm::InitLLVM X(argc, argv);
   CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
 cl::ZeroOrMore);
@@ -488,7 +489,3 @@ static int clangTidyMain(int argc, const char **argv) {
 
 } // namespace tidy
 } // namespace clang
-
-int main(int argc, const char **argv) {
-  return clang::tidy::clangTidyMain(argc, argv);
-}

diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h
new file mode 100644
index ..f87f84b66aca
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.h
@@ -0,0 +1,23 @@
+//===--- tools/extra/clang-tidy/ClangTidyMain.h - Clang tidy tool ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+///  \file This file declares the main function for the clang-tidy tool.
+///
+///  This tool uses the Clang Tooling infrastructure, see
+///http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
+///  for details on setting it up with LLVM source tree.
+///
+//===--===//
+
+namespace clang {
+namespace tidy {
+
+int clangTidyMain(int argc, const char **argv);
+
+} // namespace tidy
+} // namespace clang

diff  --git a/clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp
new file mode 100644
index ..eb7fde7b8e07
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp
@@ -0,0 +1,21 @@
+//===--- tools/extra/clang-tidy/ClangTidyToolMain.cpp - Clang tidy tool 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+///  \file This file contains clang-tidy tool entry point main function.

[clang-tools-extra] 301a437 - [clang-tidy] Add clang-tidy headers to clang distribution

2020-01-23 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2020-01-23T16:29:08-08:00
New Revision: 301a437250b03de021e6da12a8e4a927ef48881e

URL: 
https://github.com/llvm/llvm-project/commit/301a437250b03de021e6da12a8e4a927ef48881e
DIFF: 
https://github.com/llvm/llvm-project/commit/301a437250b03de021e6da12a8e4a927ef48881e.diff

LOG: [clang-tidy] Add clang-tidy headers to clang distribution

Summary:
Clang releases include static libraries for clang-tidy but corresponding
headers are missing in the tarball so these libraries are almost useless.
Clang-tidy libraries can be useful for build custom clang-tidy with
custom checks outside of llvm repo.

List of clang-tidy libraries included in clang 9.0.1 release:
lib/libclangTidyMPIModule.a
lib/libclangTidyPlugin.a
lib/libclangTidyBoostModule.a
lib/libclangTidyCERTModule.a
lib/libclangTidyAndroidModule.a
lib/libclangTidyPortabilityModule.a
lib/libclangTidyPerformanceModule.a
lib/libclangTidyOpenMPModule.a
lib/libclangTidyBugproneModule.a
lib/libclangTidyZirconModule.a
lib/libclangTidyCppCoreGuidelinesModule.a
lib/libclangTidyGoogleModule.a
lib/libclangTidyUtils.a
lib/libclangTidyHICPPModule.a
lib/libclangTidyModernizeModule.a
lib/libclangTidyLLVMModule.a
lib/libclangTidyAbseilModule.a
lib/libclangTidyReadabilityModule.a
lib/libclangTidyFuchsiaModule.a
lib/libclangTidyMiscModule.a
lib/libclangTidy.a
lib/libclangTidyObjCModule.a

Reviewers: smeenai, jdoerfert, alexfh, hokein, aaron.ballman

Subscribers: mgehre, mgorny, xazax.hun, cfe-commits

Tags: #clang-tools-extra, #clang

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/CMakeLists.txt
index 6dadb2717711..20800cf93750 100644
--- a/clang-tools-extra/clang-tidy/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/CMakeLists.txt
@@ -94,3 +94,19 @@ set(ALL_CLANG_TIDY_CHECKS ${ALL_CLANG_TIDY_CHECKS} 
PARENT_SCOPE)
 add_subdirectory(plugin)
 add_subdirectory(tool)
 add_subdirectory(utils)
+
+if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
+  install(DIRECTORY .
+DESTINATION include/clang-tidy
+COMPONENT clang-tidy-headers
+FILES_MATCHING
+PATTERN "*.h"
+)
+  add_custom_target(clang-tidy-headers)
+  set_target_properties(clang-tidy-headers PROPERTIES FOLDER "Misc")
+  if(NOT LLVM_ENABLE_IDE)
+add_llvm_install_targets(install-clang-tidy-headers
+ DEPENDS clang-tidy-headers
+ COMPONENT clang-tidy-headers)
+  endif()
+endif()



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


r305377 - Fix for Itanium mangler issue with templates

2017-06-14 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Wed Jun 14 04:47:47 2017
New Revision: 305377

URL: http://llvm.org/viewvc/llvm-project?rev=305377=rev
Log:
Fix for Itanium mangler issue with templates

Patch by Serge Preis

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

Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=305377=305376=305377=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Wed Jun 14 04:47:47 2017
@@ -4550,9 +4550,11 @@ CXXNameMangler::makeFunctionReturnTypeTa
 
   const FunctionProtoType *Proto =
   cast(FD->getType()->getAs());
+  FunctionTypeDepthState saved = TrackReturnTypeTags.FunctionTypeDepth.push();
   TrackReturnTypeTags.FunctionTypeDepth.enterResultType();
   TrackReturnTypeTags.mangleType(Proto->getReturnType());
   TrackReturnTypeTags.FunctionTypeDepth.leaveResultType();
+  TrackReturnTypeTags.FunctionTypeDepth.pop(saved);
 
   return TrackReturnTypeTags.AbiTagsRoot.getSortedUniqueUsedAbiTags();
 }


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


[PATCH] D24932: Fix PR 30440

2016-10-05 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin accepted this revision.
DmitryPolukhin added a comment.
This revision is now accepted and ready to land.

I think we need to fix this regression.


Repository:
  rL LLVM

https://reviews.llvm.org/D24932



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


Re: [PATCH] D24932: Fix PR 30440

2016-09-26 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

LGTM, added Richard in case he has something to add.


Repository:
  rL LLVM

https://reviews.llvm.org/D24932



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


Re: [PATCH] D24704: PR30401: Fix substitutions for functions with abi_tag

2016-09-21 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin closed this revision.
DmitryPolukhin added a comment.

Committed as https://reviews.llvm.org/rL282059


https://reviews.llvm.org/D24704



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


r282059 - PR30401: Fix substitutions for functions with abi_tag

2016-09-21 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Wed Sep 21 03:27:03 2016
New Revision: 282059

URL: http://llvm.org/viewvc/llvm-project?rev=282059=rev
Log:
PR30401: Fix substitutions for functions with abi_tag

Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=282059=282058=282059=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Wed Sep 21 03:27:03 2016
@@ -405,12 +405,14 @@ public:
   CXXNameMangler(CXXNameMangler , raw_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(false),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),
+Substitutions(Outer.Substitutions) {}
 
   CXXNameMangler(CXXNameMangler , llvm::raw_null_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(true),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),
+Substitutions(Outer.Substitutions) {}
 
 #if MANGLE_CHECKER
   ~CXXNameMangler() {
@@ -458,6 +460,8 @@ private:
   void addSubstitution(QualType T);
   void addSubstitution(TemplateName Template);
   void addSubstitution(uintptr_t Ptr);
+  // Destructive copy substitutions from other mangler.
+  void extendSubstitutions(CXXNameMangler* Other);
 
   void mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
   bool recursive = false);
@@ -685,6 +689,10 @@ void CXXNameMangler::mangleFunctionEncod
   // Output name with implicit tags and function encoding from temporary 
buffer.
   mangleNameWithAbiTags(FD, );
   Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
+
+  // Function encoding could create new substitutions so we have to add
+  // temp mangled substitutions to main mangler.
+  extendSubstitutions();
 }
 
 void CXXNameMangler::mangleFunctionEncodingBareType(const FunctionDecl *FD) {
@@ -4426,6 +4434,14 @@ void CXXNameMangler::addSubstitution(uin
   Substitutions[Ptr] = SeqID++;
 }
 
+void CXXNameMangler::extendSubstitutions(CXXNameMangler* Other) {
+  assert(Other->SeqID >= SeqID && "Must be superset of substitutions!");
+  if (Other->SeqID > SeqID) {
+Substitutions.swap(Other->Substitutions);
+SeqID = Other->SeqID;
+  }
+}
+
 CXXNameMangler::AbiTagList
 CXXNameMangler::makeFunctionReturnTypeTags(const FunctionDecl *FD) {
   // When derived abi tags are disabled there is no need to make any list.

Modified: cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp?rev=282059=282058=282059=diff
==
--- cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp Wed Sep 21 03:27:03 2016
@@ -203,3 +203,19 @@ void f18_test() {
 }
 // A18::operator A[abi:A][abi:B]() but GCC adds the same tags twice!
 // CHECK-DAG: define linkonce_odr {{.+}} @_ZN3A18cv1AB1AB1BEv(
+
+namespace N19 {
+  class A {};
+  class __attribute__((abi_tag("B"))) B {};
+  class D {};
+  class F {};
+
+  template
+  class C {};
+
+  B foo(A, D);
+}
+void f19_test(N19::C, N19::F, N19::D) {
+}
+// f19_test(N19::C, N19::F, N19::D)
+// CHECK-DAG: define void 
@_Z8f19_testN3N191CINS_1AEXadL_ZNS_3fooB1BES1_NS_1DENS_1FES2_(


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


Re: [PATCH] D24704: PR30401: Fix substitutions for functions with abi_tag

2016-09-20 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

Richard, please take another look.


https://reviews.llvm.org/D24704



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


Re: [PATCH] D24704: PR30401: Fix substitutions for functions with abi_tag

2016-09-19 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 71778.
DmitryPolukhin marked an inline comment as done.

https://reviews.llvm.org/D24704

Files:
  lib/AST/ItaniumMangle.cpp
  test/CodeGenCXX/mangle-abi-tag.cpp

Index: test/CodeGenCXX/mangle-abi-tag.cpp
===
--- test/CodeGenCXX/mangle-abi-tag.cpp
+++ test/CodeGenCXX/mangle-abi-tag.cpp
@@ -203,3 +203,19 @@
 }
 // A18::operator A[abi:A][abi:B]() but GCC adds the same tags twice!
 // CHECK-DAG: define linkonce_odr {{.+}} @_ZN3A18cv1AB1AB1BEv(
+
+namespace N19 {
+  class A {};
+  class __attribute__((abi_tag("B"))) B {};
+  class D {};
+  class F {};
+
+  template
+  class C {};
+
+  B foo(A, D);
+}
+void f19_test(N19::C, N19::F, N19::D) {
+}
+// f19_test(N19::C, N19::F, N19::D)
+// CHECK-DAG: define void 
@_Z8f19_testN3N191CINS_1AEXadL_ZNS_3fooB1BES1_NS_1DENS_1FES2_(
Index: lib/AST/ItaniumMangle.cpp
===
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -405,12 +405,14 @@
   CXXNameMangler(CXXNameMangler , raw_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(false),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),
+Substitutions(Outer.Substitutions) {}
 
   CXXNameMangler(CXXNameMangler , llvm::raw_null_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(true),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),
+Substitutions(Outer.Substitutions) {}
 
 #if MANGLE_CHECKER
   ~CXXNameMangler() {
@@ -458,6 +460,8 @@
   void addSubstitution(QualType T);
   void addSubstitution(TemplateName Template);
   void addSubstitution(uintptr_t Ptr);
+  // Destructive copy substitutions from other mangler.
+  void extendSubstitutions(CXXNameMangler* Other);
 
   void mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
   bool recursive = false);
@@ -685,6 +689,10 @@
   // Output name with implicit tags and function encoding from temporary 
buffer.
   mangleNameWithAbiTags(FD, );
   Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
+
+  // Function encoding could create new substitutions so we have to add
+  // temp mangled substitutions to main mangler.
+  extendSubstitutions();
 }
 
 void CXXNameMangler::mangleFunctionEncodingBareType(const FunctionDecl *FD) {
@@ -4426,6 +4434,14 @@
   Substitutions[Ptr] = SeqID++;
 }
 
+void CXXNameMangler::extendSubstitutions(CXXNameMangler* Other) {
+  assert(Other->SeqID >= SeqID && "Must be superset of substitutions!");
+  if (Other->SeqID > SeqID) {
+Substitutions.swap(Other->Substitutions);
+SeqID = Other->SeqID;
+  }
+}
+
 CXXNameMangler::AbiTagList
 CXXNameMangler::makeFunctionReturnTypeTags(const FunctionDecl *FD) {
   // When derived abi tags are disabled there is no need to make any list.


Index: test/CodeGenCXX/mangle-abi-tag.cpp
===
--- test/CodeGenCXX/mangle-abi-tag.cpp
+++ test/CodeGenCXX/mangle-abi-tag.cpp
@@ -203,3 +203,19 @@
 }
 // A18::operator A[abi:A][abi:B]() but GCC adds the same tags twice!
 // CHECK-DAG: define linkonce_odr {{.+}} @_ZN3A18cv1AB1AB1BEv(
+
+namespace N19 {
+  class A {};
+  class __attribute__((abi_tag("B"))) B {};
+  class D {};
+  class F {};
+
+  template
+  class C {};
+
+  B foo(A, D);
+}
+void f19_test(N19::C, N19::F, N19::D) {
+}
+// f19_test(N19::C, N19::F, N19::D)
+// CHECK-DAG: define void @_Z8f19_testN3N191CINS_1AEXadL_ZNS_3fooB1BES1_NS_1DENS_1FES2_(
Index: lib/AST/ItaniumMangle.cpp
===
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -405,12 +405,14 @@
   CXXNameMangler(CXXNameMangler , raw_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(false),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),
+Substitutions(Outer.Substitutions) {}
 
   CXXNameMangler(CXXNameMangler , llvm::raw_null_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(true),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),
+Substitutions(Outer.Substitutions) {}
 
 #if MANGLE_CHECKER
   ~CXXNameMangler() {
@@ -458,6 +460,8 @@
   void addSubstitution(QualType T);
   void addSubstitution(TemplateName Template);
   void addSubstitution(uintptr_t Ptr);
+  // Destructive copy substitutions from other mangler.
+  void 

Re: [PATCH] D24704: PR30401: Fix substitutions for functions with abi_tag

2016-09-19 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added inline comments.


Comment at: lib/AST/ItaniumMangle.cpp:668
@@ -664,3 +667,3 @@
   llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
   CXXNameMangler FunctionEncodingMangler(*this, FunctionEncodingStream);
   // Output name of the function.

rsmith wrote:
> DmitryPolukhin wrote:
> > rsmith wrote:
> > > Maybe it'd be simpler to just override the output stream here rather than 
> > > creating a new mangler?
> > I'm not sure that it is simpler because it will also require substitutions 
> > save/restore for name mangling (mangleNameWithAbiTags) to produce the same 
> > substitutions twice (without implicate abi_tags and later with implicit 
> > abi_tags). IMHO, it is almost identical approaches but current one is a bit 
> > cleaner because it copies explicitly everything required from temp to outer 
> > mangler.
> I think we'd want to override the output stream to write to a temporary 
> buffer at the point when we would otherwise write out the ABI tags, to avoid 
> needing to save/restore any substitutions. But I agree, that seems more 
> invasive than what you're doing here. I'll leave this up to you.
It is significant redesign and additional complexity to remember which exactly 
ABI tags we would like to rewrite later (it may not be the first call of 
writeAbiTags for current mangler). I would keep it as is.


https://reviews.llvm.org/D24704



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


Re: [PATCH] D24704: PR30401: Fix substitutions for functions with abi_tag

2016-09-18 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added inline comments.


Comment at: lib/AST/ItaniumMangle.cpp:668
@@ -664,3 +667,3 @@
   llvm::raw_svector_ostream FunctionEncodingStream(FunctionEncodingBuf);
   CXXNameMangler FunctionEncodingMangler(*this, FunctionEncodingStream);
   // Output name of the function.

rsmith wrote:
> Maybe it'd be simpler to just override the output stream here rather than 
> creating a new mangler?
I'm not sure that it is simpler because it will also require substitutions 
save/restore for name mangling (mangleNameWithAbiTags) to produce the same 
substitutions twice (without implicate abi_tags and later with implicit 
abi_tags). IMHO, it is almost identical approaches but current one is a bit 
cleaner because it copies explicitly everything required from temp to outer 
mangler.


https://reviews.llvm.org/D24704



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


[PATCH] D24704: PR30401: Fix substitutions for functions with abi_tag

2016-09-18 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added a reviewer: rsmith.
DmitryPolukhin added subscribers: cfe-commits, andreybokhanko.

Recursive mangling should use all existing substitutions and newly created 
substitutions should be copied outer mangler.

This patch should fix PR30401 and related cases but unfortunately it is ABI 
breaking change for Clang backward compatibility (I hope it is rare case in 
practice). Perhaps this patch will have to be back ported to 3.9.

https://reviews.llvm.org/D24704

Files:
  lib/AST/ItaniumMangle.cpp
  test/CodeGenCXX/mangle-abi-tag.cpp

Index: test/CodeGenCXX/mangle-abi-tag.cpp
===
--- test/CodeGenCXX/mangle-abi-tag.cpp
+++ test/CodeGenCXX/mangle-abi-tag.cpp
@@ -203,3 +203,19 @@
 }
 // A18::operator A[abi:A][abi:B]() but GCC adds the same tags twice!
 // CHECK-DAG: define linkonce_odr {{.+}} @_ZN3A18cv1AB1AB1BEv(
+
+namespace N19 {
+  class A {};
+  class __attribute__((abi_tag("B"))) B {};
+  class D {};
+  class F {};
+
+  template
+  class C {};
+
+  B foo(A, D);
+}
+void f19_test(N19::C, N19::F, N19::D) {
+}
+// f19_test(N19::C, N19::F, N19::D)
+// CHECK-DAG: define void 
@_Z8f19_testN3N191CINS_1AEXadL_ZNS_3fooB1BES1_NS_1DENS_1FES2_(
Index: lib/AST/ItaniumMangle.cpp
===
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -405,12 +405,14 @@
   CXXNameMangler(CXXNameMangler , raw_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(false),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),
+Substitutions(Outer.Substitutions) {}
 
   CXXNameMangler(CXXNameMangler , llvm::raw_null_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(true),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),
+Substitutions(Outer.Substitutions) {}
 
 #if MANGLE_CHECKER
   ~CXXNameMangler() {
@@ -458,6 +460,7 @@
   void addSubstitution(QualType T);
   void addSubstitution(TemplateName Template);
   void addSubstitution(uintptr_t Ptr);
+  void extendSubstitutions(const CXXNameMangler& Other);
 
   void mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
   bool recursive = false);
@@ -685,6 +688,10 @@
   // Output name with implicit tags and function encoding from temporary 
buffer.
   mangleNameWithAbiTags(FD, );
   Out << FunctionEncodingStream.str().substr(EncodingPositionStart);
+
+  // Function encoding could create new substitutions so we have to add
+  // temp mangled substitutions to main mangler.
+  extendSubstitutions(FunctionEncodingMangler);
 }
 
 void CXXNameMangler::mangleFunctionEncodingBareType(const FunctionDecl *FD) {
@@ -4426,6 +4433,14 @@
   Substitutions[Ptr] = SeqID++;
 }
 
+void CXXNameMangler::extendSubstitutions(const CXXNameMangler& Other) {
+  assert(Other.SeqID >= SeqID && "Must be superset of substitutions!");
+  if (Other.SeqID > SeqID) {
+Substitutions = Other.Substitutions;
+SeqID = Other.SeqID;
+  }
+}
+
 CXXNameMangler::AbiTagList
 CXXNameMangler::makeFunctionReturnTypeTags(const FunctionDecl *FD) {
   // When derived abi tags are disabled there is no need to make any list.


Index: test/CodeGenCXX/mangle-abi-tag.cpp
===
--- test/CodeGenCXX/mangle-abi-tag.cpp
+++ test/CodeGenCXX/mangle-abi-tag.cpp
@@ -203,3 +203,19 @@
 }
 // A18::operator A[abi:A][abi:B]() but GCC adds the same tags twice!
 // CHECK-DAG: define linkonce_odr {{.+}} @_ZN3A18cv1AB1AB1BEv(
+
+namespace N19 {
+  class A {};
+  class __attribute__((abi_tag("B"))) B {};
+  class D {};
+  class F {};
+
+  template
+  class C {};
+
+  B foo(A, D);
+}
+void f19_test(N19::C, N19::F, N19::D) {
+}
+// f19_test(N19::C, N19::F, N19::D)
+// CHECK-DAG: define void @_Z8f19_testN3N191CINS_1AEXadL_ZNS_3fooB1BES1_NS_1DENS_1FES2_(
Index: lib/AST/ItaniumMangle.cpp
===
--- lib/AST/ItaniumMangle.cpp
+++ lib/AST/ItaniumMangle.cpp
@@ -405,12 +405,14 @@
   CXXNameMangler(CXXNameMangler , raw_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(false),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),
+Substitutions(Outer.Substitutions) {}
 
   CXXNameMangler(CXXNameMangler , llvm::raw_null_ostream _)
   : Context(Outer.Context), Out(Out_), NullOut(true),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), 

r275974 - Fix for failing bot sanitizer-x86_64-linux-fast after r275970

2016-07-19 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Tue Jul 19 08:35:15 2016
New Revision: 275974

URL: http://llvm.org/viewvc/llvm-project?rev=275974=rev
Log:
Fix for failing bot sanitizer-x86_64-linux-fast after r275970

More info 
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/14774/steps/check-clang%20msan/logs/stdio

Modified:
cfe/trunk/include/clang/Sema/Overload.h

Modified: cfe/trunk/include/clang/Sema/Overload.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=275974=275973=275974=diff
==
--- cfe/trunk/include/clang/Sema/Overload.h (original)
+++ cfe/trunk/include/clang/Sema/Overload.h Tue Jul 19 08:35:15 2016
@@ -429,9 +429,7 @@ namespace clang {
 
 ImplicitConversionSequence()
 : ConversionKind(Uninitialized), StdInitializerListElement(false) {
-  Standard.First = ICK_Identity;
-  Standard.Second = ICK_Identity;
-  Standard.Third = ICK_Identity;
+  Standard.setAsIdentityConversion();
 }
 ~ImplicitConversionSequence() {
   destruct();


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


Re: [PATCH] D21228: Deprecated (legacy) string literal conversion to 'char *' causes strange overloading resolution

2016-07-19 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a subscriber: DmitryPolukhin.
DmitryPolukhin closed this revision.
DmitryPolukhin added a comment.

Committed as https://reviews.llvm.org/rL275970


https://reviews.llvm.org/D21228



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


r275970 - Deprecated (legacy) string literal conversion to 'char *' causes strange overloading resolution

2016-07-19 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Tue Jul 19 06:29:16 2016
New Revision: 275970

URL: http://llvm.org/viewvc/llvm-project?rev=275970=rev
Log:
Deprecated (legacy) string literal conversion to 'char *' causes strange 
overloading resolution

It's a patch for PR28050. Seems like overloading resolution wipes out
the first standard conversion sequence (before user-defined conversion)
in case of deprecated string literal conversion.

Differential revision: https://reviews.llvm.org/D21228

Patch by Alexander Makarov

Added:
cfe/trunk/test/SemaCXX/pr28050.cpp   (with props)
Modified:
cfe/trunk/include/clang/Sema/Overload.h
cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/Sema/Overload.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=275970=275969=275970=diff
==
--- cfe/trunk/include/clang/Sema/Overload.h (original)
+++ cfe/trunk/include/clang/Sema/Overload.h Tue Jul 19 06:29:16 2016
@@ -428,8 +428,11 @@ namespace clang {
 };
 
 ImplicitConversionSequence()
-  : ConversionKind(Uninitialized), StdInitializerListElement(false)
-{}
+: ConversionKind(Uninitialized), StdInitializerListElement(false) {
+  Standard.First = ICK_Identity;
+  Standard.Second = ICK_Identity;
+  Standard.Third = ICK_Identity;
+}
 ~ImplicitConversionSequence() {
   destruct();
 }

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=275970=275969=275970=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Jul 19 06:29:16 2016
@@ -1199,7 +1199,6 @@ TryUserDefinedConversion(Sema , Expr *
   case OR_Success:
   case OR_Deleted:
 ICS.setUserDefined();
-ICS.UserDefined.Before.setAsIdentityConversion();
 // C++ [over.ics.user]p4:
 //   A conversion of an expression of class type to the same class
 //   type is given Exact Match rank, and a conversion of an
@@ -4540,7 +4539,6 @@ TryReferenceInit(Sema , Expr *Init, Qu
   return ICS;
 }
 
-ICS.UserDefined.Before.setAsIdentityConversion();
 ICS.UserDefined.After.ReferenceBinding = true;
 ICS.UserDefined.After.IsLvalueReference = !isRValRef;
 ICS.UserDefined.After.BindsToFunctionLvalue = false;

Added: cfe/trunk/test/SemaCXX/pr28050.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/pr28050.cpp?rev=275970=auto
==
--- cfe/trunk/test/SemaCXX/pr28050.cpp (added)
+++ cfe/trunk/test/SemaCXX/pr28050.cpp Tue Jul 19 06:29:16 2016
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -std=c++11 %s -fsyntax-only
+//
+// expected-no-diagnostics
+
+class A {
+public:
+  A(char *s) {}
+  A(A &&) = delete;
+};
+
+int main() { A a("OK"); }

Propchange: cfe/trunk/test/SemaCXX/pr28050.cpp
--
svn:eol-style = native

Propchange: cfe/trunk/test/SemaCXX/pr28050.cpp
--
svn:keywords = "Author Date Id Rev URL"

Propchange: cfe/trunk/test/SemaCXX/pr28050.cpp
--
svn:mime-type = text/plain


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


Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-19 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added inline comments.


Comment at: test/CodeGenCXX/dllimport-rtti.cpp:7
@@ -6,3 +6,1 @@
 } s;
-// MSVC: [[VF_S:.*]] = private unnamed_addr constant [2 x i8*]
-// MSVC-DAG: @"\01??_SS@@6B@" = unnamed_addr alias i8*, getelementptr inbounds 
([2 x i8*], [2 x i8*]* [[VF_S]], i32 0, i32 1)

rnk wrote:
> I would've expected this to remain the same, since the implicit default ctor 
> of 'S' is constexpr by default in C++14. It seems a lot better to emit a 
> local vftable here and get static initialization for 's' than dynamic 
> initialization.
The context of evaluation of the whole expression is not constexpr so this case 
can be done both ways. But implemented approach is how MSVC behaves in this 
case. MSVC has very predictable behavior when local vftable is used - only when 
class has virtual d-tor. Current Clang behavior is also very consistent - 
always use local vftable. But this patch makes it hard to predict which table 
will be used - it becomes use context sensitive instead of depending only on 
class declaration. Therefore different translation units could use different 
tables and it could cause strange artifacts. Using dllimported classes in pure 
constexpr case in my experience is very rare case so it was kind of fine but 
implicit constructors much more common case.

Also thinking more about my patch I realized that fix in MayBeEmittedEagerly 
doesn't work if dllimported class is a member of non-imported class so actual 
fix would require traversing for all base classes and members for the type.

So my proposal is to keep things as is for now and abandon this patch if you 
have no objection.


https://reviews.llvm.org/D22034



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


Re: [PATCH] D21970: Add attribute abi_tag to the release notes

2016-07-19 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

Hi Hans, it seems that you've just created release branch for 3.9 and this 
patch should go directly to the branch, right? If so could you please commit 
this patch for me because I'm working with git-svn and there is no instruction 
how to work with release LLVM branches from git so I'm worry that my setup 
could break things. I'm absolutely fine with moving abi_tag above --build-id. 
Thanks!


https://reviews.llvm.org/D21970



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


Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-14 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 63950.
DmitryPolukhin marked 2 inline comments as done.
DmitryPolukhin added a comment.

- defer var generation if their type is class with dllimport.


http://reviews.llvm.org/D22034

Files:
  include/clang/AST/DeclCXX.h
  lib/AST/DeclCXX.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGenCXX/dllimport-rtti.cpp
  test/CodeGenCXX/dllimport.cpp

Index: test/CodeGenCXX/dllimport.cpp
===
--- test/CodeGenCXX/dllimport.cpp
+++ test/CodeGenCXX/dllimport.cpp
@@ -620,9 +620,31 @@
 struct __declspec(dllimport) W { virtual void foo() {} };
 USECLASS(W)
 // vftable:
-// MO1-DAG: @"\01??_SW@@6B@" = linkonce_odr unnamed_addr constant [1 x i8*] [i8* bitcast (void (%struct.W*)* @"\01?foo@W@@UAEXXZ" to i8*)]
+// MO1-DAG: @"\01??_7W@@6B@" = external dllimport unnamed_addr constant [1 x i8*]
 // GO1-DAG: @_ZTV1W = available_externally dllimport unnamed_addr constant [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.W*)* @_ZN1W3fooEv to i8*)]
 
+struct __declspec(dllimport) W2 {
+  virtual ~W2();
+  virtual void foo() {}
+};
+USECLASS(W2)
+// vftable:
+// MO1-DAG: @"\01??_SW2@@6B@" = linkonce_odr unnamed_addr constant [2 x i8*]
+// GO1-DAG: @_ZTV2W2 = external dllimport unnamed_addr constant [5 x i8*]
+
+struct __declspec(dllimport) W3 {
+  virtual void fn() const {
+  }
+  constexpr W3() = default;
+};
+
+W3 w3;
+W3& w3r = w3;
+
+constexpr W3 cw3;
+const W3  = cw3;
+// MO1-DAG: @"\01??_SW3@@6B@" = linkonce_odr unnamed_addr constant [1 x i8*]
+
 struct __declspec(dllimport) KeyFuncClass {
   constexpr KeyFuncClass() {}
   virtual void foo();
Index: test/CodeGenCXX/dllimport-rtti.cpp
===
--- test/CodeGenCXX/dllimport-rtti.cpp
+++ test/CodeGenCXX/dllimport-rtti.cpp
@@ -4,16 +4,25 @@
 struct __declspec(dllimport) S {
   virtual void f() {}
 } s;
-// MSVC: [[VF_S:.*]] = private unnamed_addr constant [2 x i8*]
-// MSVC-DAG: @"\01??_SS@@6B@" = unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* [[VF_S]], i32 0, i32 1)
+// MSVC-DAG: @"\01??_7S@@6B@" = external dllimport unnamed_addr constant [2 x i8*]
 // MSVC-DAG: @"\01??_R0?AUS@@@8" = linkonce_odr
 // MSVC-DAG: @"\01??_R1A@?0A@EA@S@@8" = linkonce_odr
 // MSVC-DAG: @"\01??_R2S@@8" = linkonce_odr
 // MSVC-DAG: @"\01??_R3S@@8" = linkonce_odr
 
 // GNU-DAG: @_ZTV1S = available_externally dllimport
 // GNU-DAG: @_ZTI1S = external dllimport
 
+struct __declspec(dllimport) S2 {
+  virtual void f() {}
+  virtual ~S2() {}
+} s2;
+// MSVC-DAG: [[VF_S2:.*]] = private unnamed_addr constant [3 x i8*] [i8* bitcast (%rtti.CompleteObjectLocator* @"\01??_R4S2@@6B@" to i8*)
+// MSVC-DAG: @"\01??_SS2@@6B@" = unnamed_addr alias i8*, getelementptr inbounds ([3 x i8*], [3 x i8*]* [[VF_S2]], i32 0, i32 1)
+// MSVC-DAG: @"\01??_R0?AUS2@@@8" = linkonce_odr
+// MSVC-DAG: @"\01??_R1A@?0A@EA@S2@@8" = linkonce_odr
+// MSVC-DAG: @"\01??_R2S2@@8" = linkonce_odr
+
 struct U : S {
 } u;
 
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -4809,6 +4809,17 @@
 }
   }
 
+  if (!ClassExported) {
+if (Class->getTemplateSpecializationKind() != TSK_Undeclared)
+  Class->setNeedLocalVFTable();
+if (const CXXDestructorDecl *Destructor = Class->getDestructor()) {
+  // Classes with dllimport attribute needs local vftable if they have
+  // virtual d-tor.
+  if (Destructor->isVirtual())
+Class->setNeedLocalVFTable();
+}
+  }
+
   if (ClassExported)
 DelayedDllExportClasses.push_back(Class);
 }
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1670,9 +1670,13 @@
   //
   // Because of this unique behavior, we maintain this logic here instead of
   // getVTableLinkage.
-  llvm::GlobalValue::LinkageTypes VFTableLinkage =
-  RD->hasAttr() ? llvm::GlobalValue::LinkOnceODRLinkage
-   : CGM.getVTableLinkage(RD);
+  llvm::GlobalValue::LinkageTypes VFTableLinkage = CGM.getVTableLinkage(RD);
+  if (RD->hasAttr()) {
+if (RD->getNeedLocalVFTable())
+  VFTableLinkage = llvm::GlobalValue::LinkOnceODRLinkage;
+else
+  VFTableLinkage = llvm::GlobalValue::ExternalLinkage;
+  }
   bool VFTableComesFromAnotherTU =
   llvm::GlobalValue::isAvailableExternallyLinkage(VFTableLinkage) ||
   llvm::GlobalValue::isExternalLinkage(VFTableLinkage);
@@ -1745,7 +1749,9 @@
   if (C)
 VTable->setComdat(C);
 
-  if (RD->hasAttr())
+  if (RD->hasAttr() && !RD->getNeedLocalVFTable())
+VFTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+  else if 

Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-14 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

In http://reviews.llvm.org/D22034#482925, @majnemer wrote:

> A flag on CXXRecordDecl which is sensitive to the most recent expression 
> evaluation might not be the best way to go.
>  Perhaps we should be able to use the VFTableBuilder to build imported and 
> local vftables for the same vftable? Not entirely sure though...


The flag can be only set to true, there is no way to reset it false. So by the 
end of translation unit it should have proper value and many things are 
deferred until the end of translation unit (like 
CodeGenModule::EmitDeferredVTables). But your example shows that normal var 
generation is not deferred, I missed it. Deferring var generation in 
CodeGenModule::MayBeEmittedEagerly seems to work fine.


http://reviews.llvm.org/D22034



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


Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-13 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 63793.
DmitryPolukhin added a comment.

Sorry for delay with patch rework, PTAL!

- added local vftable for constexpr
- added use of imported vftable


http://reviews.llvm.org/D22034

Files:
  include/clang/AST/DeclCXX.h
  lib/AST/DeclCXX.cpp
  lib/AST/ExprConstant.cpp
  lib/AST/MicrosoftMangle.cpp
  lib/CodeGen/CGVTables.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGenCXX/dllimport-rtti.cpp
  test/CodeGenCXX/dllimport.cpp

Index: test/CodeGenCXX/dllimport.cpp
===
--- test/CodeGenCXX/dllimport.cpp
+++ test/CodeGenCXX/dllimport.cpp
@@ -620,9 +620,28 @@
 struct __declspec(dllimport) W { virtual void foo() {} };
 USECLASS(W)
 // vftable:
-// MO1-DAG: @"\01??_SW@@6B@" = linkonce_odr unnamed_addr constant [1 x i8*] [i8* bitcast (void (%struct.W*)* @"\01?foo@W@@UAEXXZ" to i8*)]
+// MO1-DAG: @"\01??_7W@@6B@" = external dllimport unnamed_addr constant [1 x i8*]
 // GO1-DAG: @_ZTV1W = available_externally dllimport unnamed_addr constant [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.W*)* @_ZN1W3fooEv to i8*)]
 
+struct __declspec(dllimport) W2 {
+  virtual ~W2();
+  virtual void foo() {}
+};
+USECLASS(W2)
+// vftable:
+// MO1-DAG: @"\01??_SW2@@6B@" = linkonce_odr unnamed_addr constant [2 x i8*]
+// GO1-DAG: @_ZTV2W2 = external dllimport unnamed_addr constant [5 x i8*]
+
+struct __declspec(dllimport) W3 {
+  virtual void fn() const {
+  }
+  constexpr W3() = default;
+};
+
+constexpr W3 w3;
+const W3  = w3;
+// MO1-DAG: @"\01??_SW3@@6B@" = linkonce_odr unnamed_addr constant [1 x i8*]
+
 struct __declspec(dllimport) KeyFuncClass {
   constexpr KeyFuncClass() {}
   virtual void foo();
Index: test/CodeGenCXX/dllimport-rtti.cpp
===
--- test/CodeGenCXX/dllimport-rtti.cpp
+++ test/CodeGenCXX/dllimport-rtti.cpp
@@ -4,16 +4,25 @@
 struct __declspec(dllimport) S {
   virtual void f() {}
 } s;
-// MSVC: [[VF_S:.*]] = private unnamed_addr constant [2 x i8*]
-// MSVC-DAG: @"\01??_SS@@6B@" = unnamed_addr alias i8*, getelementptr inbounds ([2 x i8*], [2 x i8*]* [[VF_S]], i32 0, i32 1)
+// MSVC-DAG: @"\01??_7S@@6B@" = external dllimport unnamed_addr constant [2 x i8*]
 // MSVC-DAG: @"\01??_R0?AUS@@@8" = linkonce_odr
 // MSVC-DAG: @"\01??_R1A@?0A@EA@S@@8" = linkonce_odr
 // MSVC-DAG: @"\01??_R2S@@8" = linkonce_odr
 // MSVC-DAG: @"\01??_R3S@@8" = linkonce_odr
 
 // GNU-DAG: @_ZTV1S = available_externally dllimport
 // GNU-DAG: @_ZTI1S = external dllimport
 
+struct __declspec(dllimport) S2 {
+  virtual void f() {}
+  virtual ~S2() {}
+} s2;
+// MSVC-DAG: [[VF_S2:.*]] = private unnamed_addr constant [3 x i8*]
+// MSVC-DAG: @"\01??_SS2@@6B@" = unnamed_addr alias i8*, getelementptr inbounds ([3 x i8*], [3 x i8*]* [[VF_S2]], i32 0, i32 1)
+// MSVC-DAG: @"\01??_R0?AUS2@@@8" = linkonce_odr
+// MSVC-DAG: @"\01??_R1A@?0A@EA@S2@@8" = linkonce_odr
+// MSVC-DAG: @"\01??_R2S2@@8" = linkonce_odr
+
 struct U : S {
 } u;
 
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -4809,6 +4809,17 @@
 }
   }
 
+  if (!ClassExported) {
+if (Class->getTemplateSpecializationKind() != TSK_Undeclared)
+  Class->setNeedLocalVFTable();
+if (const CXXDestructorDecl *Destructor = Class->getDestructor()) {
+  // Classes with dllimport attribute needs local vftable if they have
+  // virtual d-tor.
+  if (Destructor->isVirtual())
+Class->setNeedLocalVFTable();
+}
+  }
+
   if (ClassExported)
 DelayedDllExportClasses.push_back(Class);
 }
Index: lib/CodeGen/MicrosoftCXXABI.cpp
===
--- lib/CodeGen/MicrosoftCXXABI.cpp
+++ lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1670,9 +1670,13 @@
   //
   // Because of this unique behavior, we maintain this logic here instead of
   // getVTableLinkage.
-  llvm::GlobalValue::LinkageTypes VFTableLinkage =
-  RD->hasAttr() ? llvm::GlobalValue::LinkOnceODRLinkage
-   : CGM.getVTableLinkage(RD);
+  llvm::GlobalValue::LinkageTypes VFTableLinkage = CGM.getVTableLinkage(RD);
+  if (RD->hasAttr()) {
+if (RD->getNeedLocalVFTable())
+  VFTableLinkage = llvm::GlobalValue::LinkOnceODRLinkage;
+else
+  VFTableLinkage = llvm::GlobalValue::ExternalLinkage;
+  }
   bool VFTableComesFromAnotherTU =
   llvm::GlobalValue::isAvailableExternallyLinkage(VFTableLinkage) ||
   llvm::GlobalValue::isExternalLinkage(VFTableLinkage);
@@ -1745,7 +1749,9 @@
   if (C)
 VTable->setComdat(C);
 
-  if (RD->hasAttr())
+  if (RD->hasAttr() && !RD->getNeedLocalVFTable())
+VFTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
+  else if (RD->hasAttr())
 VFTable->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
 
   VFTablesMap[ID] = VFTable;
Index: 

Re: [PATCH] D21970: Add attribute abi_tag to the release notes

2016-07-12 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

Friendly ping, PTAL!


http://reviews.llvm.org/D21970



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


Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-07 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

In http://reviews.llvm.org/D22034#475603, @majnemer wrote:

> Thinking about this some more, it is possible for clang to emit code that 
> will make everybody happy:
>
> If a class is being constructed in a constexpr context and all the vftable 
> entries it references are marked import, emit local vftables and reference 
> them in the object.  If a vftable entry it references is not marked import, 
> report an error.
>
> If a class is constructed via operator new and all the vftable entries it 
> references are marked import, emit local vftables and store it in the object 
> after the constructors run.  If a vftable entry it references is not marked 
> import, report an error.
>
> If a class is constructed via a local or global variable and all the vftable 
> entries it references are marked import, create a `dllimport 
> available_externally` vftable.  Otherwise create a normal `dllimport 
> external` vftable.
>
> I believe this behavior captures the best behavior across the spectrum of 
> functionality we all care about: it supports devirtualization, constexpr and 
> importing classes which don't have all their vftable methods exported.


I'll try to implement this approach except for special handling for 
constriction via new that seems to be out of scope for this issue and can be 
implemented independent later. Small addition, I think there is no sense to 
check if vftable references to entry that is not marked as dllimport. Linker 
will do this work for us and in some cases function may come from libraries 
(static or dynamic) but in the source may not be properly marked as dllimport 
(it is the behavior that MSVC does check it in compiler and relays on linker).


http://reviews.llvm.org/D22034



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


Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-06 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

In http://reviews.llvm.org/D22034#475551, @majnemer wrote:

> In http://reviews.llvm.org/D22034#475540, @DmitryPolukhin wrote:
>
> > Here is B::foo is not exported but required to build vftable for D.
>
>
> What happens if D also had a virtual destructor?


It seems that in this case MSVC never inline x-tors so there is no problem with 
using local vftable. I don't propose to do the same inline decisions like MSVC 
does so Clang may need/use different set of exported members and MSVC depending 
on optimization levels and other things may change these sets. But it seems 
that never use exported vftable is not aligned with ABI. MSVC seems to be very 
consistent about uses exported vftable when it is possible.


http://reviews.llvm.org/D22034



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


Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-06 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

In http://reviews.llvm.org/D22034#475331, @majnemer wrote:

> Wait, can you give an example of MSVC exporting a vftable but not all the 
> virtual methods (other than the deleting destructor)?  I don't believe I've 
> ever come across an example of this.


It is possible in code like this:
class B {

  virtual void foo();

public:

  virtual void bar();

};

class __declspec(dllexport) D : public B {
public:

  virtual void bar();

};

void B::foo() {}
void B::bar() {}
void D::bar() {}

Here is B::foo is not exported but required to build vftable for D. Also user 
may want to explicitly control what should be exported from his library and may 
decide to remove some functions from exported interface.


http://reviews.llvm.org/D22034



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


Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-06 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

In http://reviews.llvm.org/D22034#474985, @majnemer wrote:

> In http://reviews.llvm.org/D22034#474937, @DmitryPolukhin wrote:
>
> > David, do you know real programs that relay on constexpr and dllexport 
> > semantic that doesn't work on MSVC?
>
>
> Yes, Chrome relied on these semantics.


Hm, does it mean that Chrome has some workaround to bypass that MSVC doesn't 
support it?

> > Anyway current implementation is not compatible with MSVC in much more 
> > common case without constexp.

> 

> 

> I don't see how it is not compatible.  The address of the vftable is not 
> observable as far as I know...


You can easily observe the difference if vftable is exported from DLL but some 
virtual functions are not (for example, private). MSVC will uses imported 
vftable and Clang will try to rebuild fvtable that will fail on link time.

> > At the moment my patch works with your example just because it only changes 
> > mangling but don't use imported vftable that seems to be wrong.

> 

> 

> Why is it //wrong//?  It should obey the ABI in all practical matters but it 
> might be less efficient space-wise.


I think it is not ABI compatible use local vftable when MSVC uses imported. The 
easy way to observe the difference I already described but it might be other 
side effect if user start unloading DLL from address space. So user may expect 
that it is safe to unload library #1 that created object from library #2 
because it doesn't have references to library #1 addresses but due to local 
fvtable it might result in crash.


http://reviews.llvm.org/D22034



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


Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-06 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

I found the patch that prevents using imported vftable, 
http://llvm.org/viewvc/llvm-project?view=revision=260548 but the patch 
has no examples of constexpr + dllimport.


http://reviews.llvm.org/D22034



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


Re: [PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-06 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

David, do you know real programs that relay on constexpr and dllexport semantic 
that doesn't work on MSVC? If not, I think we might want to report error 
message instead of miss-compile it as MSVC does. Anyway current implementation 
is not compatible with MSVC in much more common case without constexp. At the 
moment my patch works with your example just because it only changes mangling 
but don't use imported vftable that seems to be wrong. Is it you changes 
somewhere that prevent using imported vftable?


http://reviews.llvm.org/D22034



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


[PATCH] D22034: [MSVC][DLL] use local vftable mangling only exported classes with virtual destructor

2016-07-06 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added a reviewer: rnk.
DmitryPolukhin added a subscriber: cfe-commits.

MSVC uses non-local mangling for vftable if class with dllexport attribute has 
no virtual destructor. I checked all examples that I fixed with MSVC and it 
uses '_7' in all cases. For more info see old thread in 
microsoft.public.vc.language: 
https://groups.google.com/d/msg/microsoft.public.vc.language/atSh_2VSc2w/EgJ3r_7OzVUJ

http://reviews.llvm.org/D22034

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/PR26569.cpp
  test/CodeGenCXX/dllimport-rtti.cpp
  test/CodeGenCXX/dllimport.cpp

Index: test/CodeGenCXX/dllimport.cpp
===
--- test/CodeGenCXX/dllimport.cpp
+++ test/CodeGenCXX/dllimport.cpp
@@ -620,9 +620,18 @@
 struct __declspec(dllimport) W { virtual void foo() {} };
 USECLASS(W)
 // vftable:
-// MO1-DAG: @"\01??_SW@@6B@" = linkonce_odr unnamed_addr constant [1 x i8*] 
[i8* bitcast (void (%struct.W*)* @"\01?foo@W@@UAEXXZ" to i8*)]
+// MO1-DAG: @"\01??_7W@@6B@" = linkonce_odr unnamed_addr constant [1 x i8*] 
[i8* bitcast (void (%struct.W*)* @"\01?foo@W@@UAEXXZ" to i8*)]
 // GO1-DAG: @_ZTV1W = available_externally dllimport unnamed_addr constant [3 
x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.W*)* @_ZN1W3fooEv to 
i8*)]
 
+struct __declspec(dllimport) W2 {
+  virtual ~W2();
+  virtual void foo() {}
+};
+USECLASS(W2)
+// vftable:
+// MO1-DAG: @"\01??_SW2@@6B@" = linkonce_odr unnamed_addr constant [2 x i8*]
+// GO1-DAG: @_ZTV2W2 = external dllimport unnamed_addr constant [5 x i8*]
+
 struct __declspec(dllimport) KeyFuncClass {
   constexpr KeyFuncClass() {}
   virtual void foo();
Index: test/CodeGenCXX/dllimport-rtti.cpp
===
--- test/CodeGenCXX/dllimport-rtti.cpp
+++ test/CodeGenCXX/dllimport-rtti.cpp
@@ -4,8 +4,8 @@
 struct __declspec(dllimport) S {
   virtual void f() {}
 } s;
-// MSVC: [[VF_S:.*]] = private unnamed_addr constant [2 x i8*]
-// MSVC-DAG: @"\01??_SS@@6B@" = unnamed_addr alias i8*, getelementptr inbounds 
([2 x i8*], [2 x i8*]* [[VF_S]], i32 0, i32 1)
+// MSVC: [[VF_7:.*]] = private unnamed_addr constant [2 x i8*]
+// MSVC-DAG: @"\01??_7S@@6B@" = unnamed_addr alias i8*, getelementptr inbounds 
([2 x i8*], [2 x i8*]* [[VF_7]], i32 0, i32 1)
 // MSVC-DAG: @"\01??_R0?AUS@@@8" = linkonce_odr
 // MSVC-DAG: @"\01??_R1A@?0A@EA@S@@8" = linkonce_odr
 // MSVC-DAG: @"\01??_R2S@@8" = linkonce_odr
Index: test/CodeGenCXX/PR26569.cpp
===
--- test/CodeGenCXX/PR26569.cpp
+++ test/CodeGenCXX/PR26569.cpp
@@ -4,17 +4,17 @@
   virtual void m_fn1();
 };
 template 
-class B : virtual A {};
+class B : public virtual A {};
 
 extern template class __declspec(dllimport) B;
 class __declspec(dllexport) C : B {};
 
 // CHECK-DAG: @[[VTABLE_C:.*]] = private unnamed_addr constant [2 x i8*] [i8* 
bitcast (%rtti.CompleteObjectLocator* @"\01??_R4C@@6B@" to i8*), i8* bitcast 
(void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)]
-// CHECK-DAG: @[[VTABLE_B:.*]] = private unnamed_addr constant [2 x i8*] [i8* 
bitcast (%rtti.CompleteObjectLocator* @"\01??_R4?$B@H@@6B@" to i8*), i8* 
bitcast (void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)], 
comdat($"\01??_S?$B@H@@6B@")
+// CHECK-DAG: @[[VTABLE_B:.*]] = private unnamed_addr constant [2 x i8*] [i8* 
bitcast (%rtti.CompleteObjectLocator* @"\01??_R4?$B@H@@6B@" to i8*), i8* 
bitcast (void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)], 
comdat($"\01??_7?$B@H@@6B@")
 // CHECK-DAG: @[[VTABLE_A:.*]] = private unnamed_addr constant [2 x i8*] [i8* 
bitcast (%rtti.CompleteObjectLocator* @"\01??_R4A@@6B@" to i8*), i8* bitcast 
(void (%class.A*)* @"\01?m_fn1@A@@EAEXXZ" to i8*)], comdat($"\01??_7A@@6B@")
 
 // CHECK-DAG: @"\01??_7C@@6B@" = dllexport unnamed_addr alias i8*, 
getelementptr inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_C]], i32 0, i32 1)
-// CHECK-DAG: @"\01??_S?$B@H@@6B@" = unnamed_addr alias i8*, getelementptr 
inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_B]], i32 0, i32 1)
+// CHECK-DAG: @"\01??_7?$B@H@@6B@" = unnamed_addr alias i8*, getelementptr 
inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_B]], i32 0, i32 1)
 // CHECK-DAG: @"\01??_7A@@6B@" = unnamed_addr alias i8*, getelementptr 
inbounds ([2 x i8*], [2 x i8*]* @[[VTABLE_A]], i32 0, i32 1)
 
 // CHECK-DAG: @"\01??_8?$B@H@@7B@" = available_externally dllimport 
unnamed_addr constant [2 x i32] [i32 0, i32 4]
Index: lib/AST/MicrosoftMangle.cpp
===
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -2601,7 +2601,15 @@
   // is always '6' for vftables.
   msvc_hashing_ostream MHO(Out);
   MicrosoftCXXNameMangler Mangler(*this, MHO);
-  if (Derived->hasAttr())
+  bool NeedLocalVFT = false;
+  if (Derived->hasAttr()) {
+// Only dllimported classes with virtual d-tor may need local vtbl
+// for proper memory deallocation 

Re: [PATCH] D18035: [GCC] PR23529 Mangler part of attrbute abi_tag support

2016-06-30 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

Richard, thank you for the review!

I decided to commit this patch without waiting for GCC response to 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71712 (that is last compatibility 
issues in comparison with GCC6) so more people could test Clang implementation 
of ABI tags on real apps and report issues if any. All, please let me know 
(file bug and add me in CC) if you observe any issues with abi_tag 
implementation in Clang.


Repository:
  rL LLVM

http://reviews.llvm.org/D18035



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


r274223 - Fix CodeGenCXX/mangle-abi-tag.cpp on clang-ppc64le-linux bot

2016-06-30 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Thu Jun 30 06:15:52 2016
New Revision: 274223

URL: http://llvm.org/viewvc/llvm-project?rev=274223=rev
Log:
Fix CodeGenCXX/mangle-abi-tag.cpp on clang-ppc64le-linux bot

Modified:
cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp

Modified: cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp?rev=274223=274222=274223=diff
==
--- cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp Thu Jun 30 06:15:52 2016
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 %s -emit-llvm -triple %itanium_abi_triple -std=c++11 -o - | 
FileCheck %s
 // RUN: %clang_cc1 %s -emit-llvm -triple i686-linux-gnu -std=c++11 -o - | 
FileCheck %s
 // RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -std=c++11 -o - | 
FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple powerpc64le-unknown-linux-gnu 
-std=c++11 -o - | FileCheck %s
 
 struct __attribute__((abi_tag("A", "B"))) A { };
 
@@ -159,7 +160,7 @@ A14 A14::f14() {
   return A14();
 }
 // A14[abi:TAG]::f14()
-// CHECK-DAG: define void @_ZN3A14B3TAG3f14Ev(
+// CHECK-DAG: define {{.+}} @_ZN3A14B3TAG3f14Ev(
 
 template
 T f15() {
@@ -169,7 +170,7 @@ void f15_test() {
   f15();
 }
 // A14[abi:TAG] f15()
-// CHECK-DAG: define linkonce_odr void @_Z3f15I3A14B3TAGET_v(
+// CHECK-DAG: define linkonce_odr {{.+}} @_Z3f15I3A14B3TAGET_v(
 
 template
 A14 f16() {
@@ -179,7 +180,7 @@ void f16_test() {
   f16();
 }
 // A14[abi:TAG] f16()
-// CHECK-DAG: define linkonce_odr void @_Z3f16IiE3A14B3TAGv(
+// CHECK-DAG: define linkonce_odr {{.+}} @_Z3f16IiE3A14B3TAGv(
 
 template
 struct __attribute__((abi_tag("TAG"))) A17 {
@@ -192,7 +193,7 @@ void f17_test() {
   a + b;
 }
 // A17[abi:TAG]::operator+(A17[abi:TAG] const&)
-// CHECK-DAG: define linkonce_odr void @_ZN3A17B3TAGIiEplERKS0_(
+// CHECK-DAG: define linkonce_odr {{.+}} @_ZN3A17B3TAGIiEplERKS0_(
 
 struct A18 {
   operator A() { return A(); }
@@ -201,4 +202,4 @@ void f18_test() {
   A a = A18();
 }
 // A18::operator A[abi:A][abi:B]() but GCC adds the same tags twice!
-// CHECK-DAG: define linkonce_odr void @_ZN3A18cv1AB1AB1BEv(
+// CHECK-DAG: define linkonce_odr {{.+}} @_ZN3A18cv1AB1AB1BEv(


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


r274222 - [GCC] PR23529 Mangler part of attrbute abi_tag support

2016-06-30 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Thu Jun 30 04:40:38 2016
New Revision: 274222

URL: http://llvm.org/viewvc/llvm-project?rev=274222=rev
Log:
[GCC] PR23529 Mangler part of attrbute abi_tag support

Original patch by Stefan Bühler http://reviews.llvm.org/D12834

Difference between original and this one:
- fixed all failing tests
- fixed mangling for global variable outside namespace
- emit ABI tags for guards and local names
- clang-format + other stylistic changes
- significantly reworked patch according to Richard's suggestions

Sema part, committed before http://reviews.llvm.org/D17567

Differential revision: http://reviews.llvm.org/D18035

Added:
cfe/trunk/test/CodeGenCXX/mangle-abi-tag.cpp   (with props)
Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/test/PCH/attrs.c
cfe/trunk/test/SemaCXX/attr-abi-tag-syntax.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=274222=274221=274222=diff
==
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Thu Jun 30 04:40:38 2016
@@ -214,6 +214,12 @@ public:
 class CXXNameMangler {
   ItaniumMangleContextImpl 
   raw_ostream 
+  bool NullOut = false;
+  /// In the "DisableDerivedAbiTags" mode derived ABI tags are not calculated.
+  /// This mode is used when mangler creates another mangler recursively to
+  /// calculate ABI tags for the function return value or the variable type.
+  /// Also it is required to avoid infinite recursion in some cases.
+  bool DisableDerivedAbiTags = false;
 
   /// The "structor" is the top-level declaration being mangled, if
   /// that's not a template specialization; otherwise it's the pattern
@@ -263,15 +269,126 @@ class CXXNameMangler {
 
   } FunctionTypeDepth;
 
+  // abi_tag is a gcc attribute, taking one or more strings called "tags".
+  // The goal is to annotate against which version of a library an object was
+  // built and to be able to provide backwards compatibility ("dual abi").
+  // For more information see docs/ItaniumMangleAbiTags.rst.
+  typedef SmallVector AbiTagList;
+
+  // State to gather all implicit and explicit tags used in a mangled name.
+  // Must always have an instance of this while emitting any name to keep
+  // track.
+  class AbiTagState final {
+  public:
+explicit AbiTagState(AbiTagState *) : LinkHead(Head) {
+  Parent = LinkHead;
+  LinkHead = this;
+}
+
+// No copy, no move.
+AbiTagState(const AbiTagState &) = delete;
+AbiTagState =(const AbiTagState &) = delete;
+
+~AbiTagState() { pop(); }
+
+void write(raw_ostream , const NamedDecl *ND,
+   const AbiTagList *AdditionalAbiTags) {
+  ND = cast(ND->getCanonicalDecl());
+  if (!isa(ND) && !isa(ND)) {
+assert(
+!AdditionalAbiTags &&
+"only function and variables need a list of additional abi tags");
+if (const auto *NS = dyn_cast(ND)) {
+  if (const auto *AbiTag = NS->getAttr()) {
+UsedAbiTags.insert(UsedAbiTags.end(), AbiTag->tags().begin(),
+   AbiTag->tags().end());
+  }
+  // Don't emit abi tags for namespaces.
+  return;
+}
+  }
+
+  AbiTagList TagList;
+  if (const auto *AbiTag = ND->getAttr()) {
+UsedAbiTags.insert(UsedAbiTags.end(), AbiTag->tags().begin(),
+   AbiTag->tags().end());
+TagList.insert(TagList.end(), AbiTag->tags().begin(),
+   AbiTag->tags().end());
+  }
+
+  if (AdditionalAbiTags) {
+UsedAbiTags.insert(UsedAbiTags.end(), AdditionalAbiTags->begin(),
+   AdditionalAbiTags->end());
+TagList.insert(TagList.end(), AdditionalAbiTags->begin(),
+   AdditionalAbiTags->end());
+  }
+
+  std::sort(TagList.begin(), TagList.end());
+  TagList.erase(std::unique(TagList.begin(), TagList.end()), 
TagList.end());
+
+  writeSortedUniqueAbiTags(Out, TagList);
+}
+
+const AbiTagList () const { return UsedAbiTags; }
+void setUsedAbiTags(const AbiTagList ) {
+  UsedAbiTags = AbiTags;
+}
+
+const AbiTagList () const {
+  return EmittedAbiTags;
+}
+
+const AbiTagList () {
+  std::sort(UsedAbiTags.begin(), UsedAbiTags.end());
+  UsedAbiTags.erase(std::unique(UsedAbiTags.begin(), UsedAbiTags.end()),
+UsedAbiTags.end());
+  return UsedAbiTags;
+}
+
+  private:
+//! All abi tags used implicitly or explicitly.
+AbiTagList UsedAbiTags;
+//! All explicit abi tags (i.e. not from namespace).
+AbiTagList EmittedAbiTags;
+
+AbiTagState *
+AbiTagState *Parent = nullptr;
+
+void pop() {
+  assert(LinkHead == this &&
+ "abi tag link head must point to us on 

Re: [PATCH] D18035: [GCC] PR23529 Mangler part of attrbute abi_tag support

2016-06-29 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 62213.
DmitryPolukhin marked 2 inline comments as done.
DmitryPolukhin added a comment.

Use SmallVector instead of SmallSetVector and sort the vector when needed.


http://reviews.llvm.org/D18035

Files:
  lib/AST/ItaniumMangle.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/mangle-abi-tag.cpp
  test/PCH/attrs.c
  test/SemaCXX/attr-abi-tag-syntax.cpp

Index: test/SemaCXX/attr-abi-tag-syntax.cpp
===
--- test/SemaCXX/attr-abi-tag-syntax.cpp
+++ test/SemaCXX/attr-abi-tag-syntax.cpp
@@ -16,28 +16,18 @@
 // expected-warning@-1 {{'abi_tag' attribute on anonymous namespace ignored}}
 
 inline namespace N __attribute__((__abi_tag__)) {}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-2 {{'__abi_tag__' attribute ignored}}
 
 } // namespcace N2
 
 __attribute__((abi_tag("B", "A"))) extern int a1;
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-2 {{'abi_tag' attribute ignored}}
 
 __attribute__((abi_tag("A", "B"))) extern int a1;
 // expected-note@-1 {{previous declaration is here}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
 
 __attribute__((abi_tag("A", "C"))) extern int a1;
 // expected-error@-1 {{'abi_tag' C missing in original declaration}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
 
 extern int a2;
 // expected-note@-1 {{previous declaration is here}}
 __attribute__((abi_tag("A")))extern int a2;
 // expected-error@-1 {{cannot add 'abi_tag' attribute in a redeclaration}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
Index: test/PCH/attrs.c
===
--- test/PCH/attrs.c
+++ test/PCH/attrs.c
@@ -9,7 +9,7 @@
 #define HEADER
 
 int f(int) __attribute__((visibility("default"), overloadable));
-int g(int) __attribute__((abi_tag("foo", "bar", "baz"), no_sanitize("address", "memory"))); // expected-warning {{ignored}}
+int g(int) __attribute__((abi_tag("foo", "bar", "baz"), no_sanitize("address", "memory")));
 
 #else
 
Index: test/CodeGenCXX/mangle-abi-tag.cpp
===
--- /dev/null
+++ test/CodeGenCXX/mangle-abi-tag.cpp
@@ -0,0 +1,204 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple %itanium_abi_triple -std=c++11 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-linux-gnu -std=c++11 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -std=c++11 -o - | FileCheck %s
+
+struct __attribute__((abi_tag("A", "B"))) A { };
+
+struct B: A { };
+
+template
+
+struct C {
+};
+
+struct D { A* p; };
+
+template
+struct __attribute__((abi_tag("C", "D"))) E {
+};
+
+struct __attribute__((abi_tag("A", "B"))) F { };
+
+A a1;
+// CHECK-DAG: @_Z2a1B1AB1B =
+
+__attribute__((abi_tag("C", "D")))
+A a2;
+// CHECK-DAG: @_Z2a2B1AB1BB1CB1D =
+
+B a3;
+// CHECK-DAG: @a3 =
+
+C a4;
+// CHECK-DAG: @_Z2a4B1AB1B =
+
+D a5;
+// CHECK-DAG: @a5 =
+
+E a6;
+// CHECK-DAG: @_Z2a6B1CB1D =
+
+E a7;
+// CHECK-DAG: @_Z2a7B1AB1BB1CB1D =
+
+template<>
+struct E {
+  static float a8;
+};
+float E::a8;
+// CHECK-DAG: @_ZN1EB1CB1DIfE2a8E =
+
+template<>
+struct E {
+  static bool a9;
+};
+bool E::a9;
+// CHECK-DAG: @_ZN1EB1CB1DI1FB1AB1BE2a9E =
+
+struct __attribute__((abi_tag("A", "B"))) A10 {
+  virtual ~A10() {}
+} a10;
+// vtable
+// CHECK-DAG: @_ZTV3A10B1AB1B =
+// typeinfo
+// CHECK-DAG: @_ZTI3A10B1AB1B =
+
+struct __attribute__((abi_tag("A"))) B11 {
+  static A10 b;
+};
+A10 B11::b;
+// B11[abi:A]::b[abi:B]
+// CHECK-DAG: @_ZN3B11B1A1bB1BE =
+
+__attribute__ ((abi_tag("C", "D")))
+void* f1() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f1B1CB1Dv(
+
+__attribute__ ((abi_tag("C", "D")))
+A* f2() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f2B1AB1BB1CB1Dv(
+
+B* f3() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f3v(
+
+C* f4() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f4B1AB1Bv(
+
+D* f5() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f5v(
+
+E* f6() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f6B1CB1Dv(
+
+E* f7() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f7B1AB1BB1CB1Dv(
+
+void f8(E*) {
+}
+// CHECK-DAG: define {{.*}} @_Z2f8P1EB1CB1DI1AB1AB1BE(
+
+inline namespace Names1 __attribute__((__abi_tag__)) {
+class C1 {};
+}
+C1 f9() { return C1(); }
+// CHECK-DAG: @_Z2f9B6Names1v(
+
+inline namespace Names2 __attribute__((__abi_tag__("Tag1", "Tag2"))) {
+class C2 {};
+}
+C2 f10() { return C2(); }
+// CHECK-DAG: @_Z3f10B4Tag1B4Tag2v(
+
+void __attribute__((abi_tag("A"))) f11(A) {}
+// f11[abi:A](A[abi:A][abi:B])
+// CHECK-DAG: define {{.*}} @_Z3f11B1A1AB1AB1B(
+
+A f12(A) { return A(); }
+// f12(A[abi:A][abi:B])
+// 

Re: [PATCH] D18035: [GCC] PR23529 Mangler part of attrbute abi_tag support

2016-06-23 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated the summary for this revision.
DmitryPolukhin updated this revision to Diff 61642.
DmitryPolukhin added a comment.

Fixed issue with substitution from function name used in bare type encoding and 
added test. With this patch Clang passes self build with GCC 5.3.1 headers and 
C++ libraries so it gives some level of confidence that it works on real apps.

PTAL!


http://reviews.llvm.org/D18035

Files:
  lib/AST/ItaniumMangle.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/mangle-abi-tag.cpp
  test/PCH/attrs.c
  test/SemaCXX/attr-abi-tag-syntax.cpp

Index: test/SemaCXX/attr-abi-tag-syntax.cpp
===
--- test/SemaCXX/attr-abi-tag-syntax.cpp
+++ test/SemaCXX/attr-abi-tag-syntax.cpp
@@ -16,28 +16,18 @@
 // expected-warning@-1 {{'abi_tag' attribute on anonymous namespace ignored}}
 
 inline namespace N __attribute__((__abi_tag__)) {}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-2 {{'__abi_tag__' attribute ignored}}
 
 } // namespcace N2
 
 __attribute__((abi_tag("B", "A"))) extern int a1;
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-2 {{'abi_tag' attribute ignored}}
 
 __attribute__((abi_tag("A", "B"))) extern int a1;
 // expected-note@-1 {{previous declaration is here}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
 
 __attribute__((abi_tag("A", "C"))) extern int a1;
 // expected-error@-1 {{'abi_tag' C missing in original declaration}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
 
 extern int a2;
 // expected-note@-1 {{previous declaration is here}}
 __attribute__((abi_tag("A")))extern int a2;
 // expected-error@-1 {{cannot add 'abi_tag' attribute in a redeclaration}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
Index: test/PCH/attrs.c
===
--- test/PCH/attrs.c
+++ test/PCH/attrs.c
@@ -9,7 +9,7 @@
 #define HEADER
 
 int f(int) __attribute__((visibility("default"), overloadable));
-int g(int) __attribute__((abi_tag("foo", "bar", "baz"), no_sanitize("address", "memory"))); // expected-warning {{ignored}}
+int g(int) __attribute__((abi_tag("foo", "bar", "baz"), no_sanitize("address", "memory")));
 
 #else
 
Index: test/CodeGenCXX/mangle-abi-tag.cpp
===
--- /dev/null
+++ test/CodeGenCXX/mangle-abi-tag.cpp
@@ -0,0 +1,195 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple %itanium_abi_triple -std=c++11 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-linux-gnu -std=c++11 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -std=c++11 -o - | FileCheck %s
+
+struct __attribute__((abi_tag("A", "B"))) A { };
+
+struct B: A { };
+
+template
+
+struct C {
+};
+
+struct D { A* p; };
+
+template
+struct __attribute__((abi_tag("C", "D"))) E {
+};
+
+struct __attribute__((abi_tag("A", "B"))) F { };
+
+A a1;
+// CHECK-DAG: @_Z2a1B1AB1B =
+
+__attribute__((abi_tag("C", "D")))
+A a2;
+// CHECK-DAG: @_Z2a2B1AB1BB1CB1D =
+
+B a3;
+// CHECK-DAG: @a3 =
+
+C a4;
+// CHECK-DAG: @_Z2a4B1AB1B =
+
+D a5;
+// CHECK-DAG: @a5 =
+
+E a6;
+// CHECK-DAG: @_Z2a6B1CB1D =
+
+E a7;
+// CHECK-DAG: @_Z2a7B1AB1BB1CB1D =
+
+template<>
+struct E {
+  static float a8;
+};
+float E::a8;
+// CHECK-DAG: @_ZN1EB1CB1DIfE2a8E =
+
+template<>
+struct E {
+  static bool a9;
+};
+bool E::a9;
+// CHECK-DAG: @_ZN1EB1CB1DI1FB1AB1BE2a9E =
+
+struct __attribute__((abi_tag("A", "B"))) A10 {
+  virtual ~A10() {}
+} a10;
+// vtable
+// CHECK-DAG: @_ZTV3A10B1AB1B =
+// typeinfo
+// CHECK-DAG: @_ZTI3A10B1AB1B =
+
+struct __attribute__((abi_tag("A"))) B11 {
+  static A10 b;
+};
+A10 B11::b;
+// B11[abi:A]::b[abi:B]
+// CHECK-DAG: @_ZN3B11B1A1bB1BE =
+
+__attribute__ ((abi_tag("C", "D")))
+void* f1() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f1B1CB1Dv(
+
+__attribute__ ((abi_tag("C", "D")))
+A* f2() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f2B1AB1BB1CB1Dv(
+
+B* f3() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f3v(
+
+C* f4() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f4B1AB1Bv(
+
+D* f5() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f5v(
+
+E* f6() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f6B1CB1Dv(
+
+E* f7() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f7B1AB1BB1CB1Dv(
+
+void f8(E*) {
+}
+// CHECK-DAG: define {{.*}} @_Z2f8P1EB1CB1DI1AB1AB1BE(
+
+inline namespace Names1 __attribute__((__abi_tag__)) {
+class C1 {};
+}
+C1 f9() { return C1(); }
+// CHECK-DAG: @_Z2f9B6Names1v(
+
+inline namespace Names2 __attribute__((__abi_tag__("Tag1", "Tag2"))) {
+class C2 {};
+}
+C2 f10() { return C2(); }
+// CHECK-DAG: @_Z3f10B4Tag1B4Tag2v(
+
+void 

Re: [PATCH] D18035: [GCC] PR23529 Mangler part of attrbute abi_tag support

2016-06-21 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 61352.
DmitryPolukhin added a comment.

- removed wrong asserts that I used for an experiment


http://reviews.llvm.org/D18035

Files:
  lib/AST/ItaniumMangle.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/mangle-abi-tag.cpp
  test/PCH/attrs.c
  test/SemaCXX/attr-abi-tag-syntax.cpp

Index: test/SemaCXX/attr-abi-tag-syntax.cpp
===
--- test/SemaCXX/attr-abi-tag-syntax.cpp
+++ test/SemaCXX/attr-abi-tag-syntax.cpp
@@ -16,28 +16,18 @@
 // expected-warning@-1 {{'abi_tag' attribute on anonymous namespace ignored}}
 
 inline namespace N __attribute__((__abi_tag__)) {}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-2 {{'__abi_tag__' attribute ignored}}
 
 } // namespcace N2
 
 __attribute__((abi_tag("B", "A"))) extern int a1;
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-2 {{'abi_tag' attribute ignored}}
 
 __attribute__((abi_tag("A", "B"))) extern int a1;
 // expected-note@-1 {{previous declaration is here}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
 
 __attribute__((abi_tag("A", "C"))) extern int a1;
 // expected-error@-1 {{'abi_tag' C missing in original declaration}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
 
 extern int a2;
 // expected-note@-1 {{previous declaration is here}}
 __attribute__((abi_tag("A")))extern int a2;
 // expected-error@-1 {{cannot add 'abi_tag' attribute in a redeclaration}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
Index: test/PCH/attrs.c
===
--- test/PCH/attrs.c
+++ test/PCH/attrs.c
@@ -9,7 +9,7 @@
 #define HEADER
 
 int f(int) __attribute__((visibility("default"), overloadable));
-int g(int) __attribute__((abi_tag("foo", "bar", "baz"), no_sanitize("address", "memory"))); // expected-warning {{ignored}}
+int g(int) __attribute__((abi_tag("foo", "bar", "baz"), no_sanitize("address", "memory")));
 
 #else
 
Index: test/CodeGenCXX/mangle-abi-tag.cpp
===
--- /dev/null
+++ test/CodeGenCXX/mangle-abi-tag.cpp
@@ -0,0 +1,182 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple %itanium_abi_triple -std=c++11 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-linux-gnu -std=c++11 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -std=c++11 -o - | FileCheck %s
+
+struct __attribute__((abi_tag("A", "B"))) A { };
+
+struct B: A { };
+
+template
+
+struct C {
+};
+
+struct D { A* p; };
+
+template
+struct __attribute__((abi_tag("C", "D"))) E {
+};
+
+struct __attribute__((abi_tag("A", "B"))) F { };
+
+A a1;
+// CHECK-DAG: @_Z2a1B1AB1B =
+
+__attribute__((abi_tag("C", "D")))
+A a2;
+// CHECK-DAG: @_Z2a2B1AB1BB1CB1D =
+
+B a3;
+// CHECK-DAG: @a3 =
+
+C a4;
+// CHECK-DAG: @_Z2a4B1AB1B =
+
+D a5;
+// CHECK-DAG: @a5 =
+
+E a6;
+// CHECK-DAG: @_Z2a6B1CB1D =
+
+E a7;
+// CHECK-DAG: @_Z2a7B1AB1BB1CB1D =
+
+template<>
+struct E {
+  static float a8;
+};
+float E::a8;
+// CHECK-DAG: @_ZN1EB1CB1DIfE2a8E =
+
+template<>
+struct E {
+  static bool a9;
+};
+bool E::a9;
+// CHECK-DAG: @_ZN1EB1CB1DI1FB1AB1BE2a9E =
+
+struct __attribute__((abi_tag("A", "B"))) A10 {
+  virtual ~A10() {}
+} a10;
+// vtable
+// CHECK-DAG: @_ZTV3A10B1AB1B =
+// typeinfo
+// CHECK-DAG: @_ZTI3A10B1AB1B =
+
+struct __attribute__((abi_tag("A"))) B11 {
+  static A10 b;
+};
+A10 B11::b;
+// B11[abi:A]::b[abi:B]
+// CHECK-DAG: @_ZN3B11B1A1bB1BE =
+
+__attribute__ ((abi_tag("C", "D")))
+void* f1() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f1B1CB1Dv(
+
+__attribute__ ((abi_tag("C", "D")))
+A* f2() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f2B1AB1BB1CB1Dv(
+
+B* f3() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f3v(
+
+C* f4() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f4B1AB1Bv(
+
+D* f5() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f5v(
+
+E* f6() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f6B1CB1Dv(
+
+E* f7() {
+  return 0;
+}
+// CHECK-DAG: define {{.*}} @_Z2f7B1AB1BB1CB1Dv(
+
+void f8(E*) {
+}
+// CHECK-DAG: define {{.*}} @_Z2f8P1EB1CB1DI1AB1AB1BE(
+
+inline namespace Names1 __attribute__((__abi_tag__)) {
+class C1 {};
+}
+C1 f9() { return C1(); }
+// CHECK-DAG: @_Z2f9B6Names1v(
+
+inline namespace Names2 __attribute__((__abi_tag__("Tag1", "Tag2"))) {
+class C2 {};
+}
+C2 f10() { return C2(); }
+// CHECK-DAG: @_Z3f10B4Tag1B4Tag2v(
+
+void __attribute__((abi_tag("A"))) f11(A) {}
+// f11[abi:A](A[abi:A][abi:B])
+// CHECK-DAG: define {{.*}} @_Z3f11B1A1AB1AB1B(
+
+A f12(A) { return A(); }
+// f12(A[abi:A][abi:B])
+// CHECK-DAG: define {{.*}} @_Z3f121AB1AB1B(
+
+inline void f13() {
+  

Re: [PATCH] D18035: [GCC] PR23529 Mangler part of attrbute abi_tag support

2016-06-07 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

In http://reviews.llvm.org/D18035#450258, @rsmith wrote:

> Yes, I definitely want us to implement this for GCC compatibility. And now 
> that we have a specification for this feature, we can evaluate whether this 
> is doing the right thing. On that basis:
>
> I still want this refactored so that the normally-mangled part of a function 
> name is only mangled once, rather than being mangled twice (once to find the 
> implicit tag set and once to actually produce the mangled name). As 
> suggested, you can achieve this by first computing the set of tags from the 
> return type, then mangling the encoding to a separate buffer (collecting tags 
> as you go) if the set is non-empty, and finally writing any remaining tags 
> and the buffer contents.
>
> Please factor out a function to mangle the source name and ABI tags for a 
> `NamedDecl` rather than duplicating that pair of calls throughout the patch.
>
> Current discussion on the ABI list suggests that it is not correct to mangle 
> the return type / variable type to get the implicit tag set. The set of 
> available attributes should be determined by a recursive walk of the original 
> type (prior to any substitution), not by mangling it and seeing what it 
> references. It's not yet clear whether that's the actual design intent or 
> just the emergent behavior of the GCC implementation, however.


I'm monitoring the discussion and will try to rewrite this patch according to 
the guidance and avoid double mangling.


http://reviews.llvm.org/D18035



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


Re: [PATCH] D18035: [GCC] PR23529 Mangler part of attrbute abi_tag support

2016-06-03 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

In http://reviews.llvm.org/D18035#447473, @hfinkel wrote:

> FYI: There is now a specification, see: 
> http://sourcerytools.com/pipermail/cxx-abi-dev/2016-June/002919.html


For the records, this patch implements GCC 6 abi_tag semantic and to the best 
of my knowledge mangles everything same as GCC 6. To support GCC 5 semantic 
Clang will need -fabi-version command line flag to support multiple ABI 
versions. But as far as I can see, Richard is not going to approve this patch 
so it seems to be dead end.


http://reviews.llvm.org/D18035



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


r270974 - [MSVC2015] Fix mangling for static variables initialization guards

2016-05-27 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Fri May 27 03:52:34 2016
New Revision: 270974

URL: http://llvm.org/viewvc/llvm-project?rev=270974=rev
Log:
[MSVC2015] Fix mangling for static variables initialization guards

It seems that suffix '@4HA' was omitted for unknown reason. It is
non-cont non-volatile 'int' type of normal variable TSS.

Differential revision: http://reviews.llvm.org/D20683

Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=270974=270973=270974=diff
==
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri May 27 03:52:34 2016
@@ -2837,6 +2837,7 @@ void MicrosoftMangleContextImpl::mangleT
 
   Mangler.getStream() << "\01?$TSS" << GuardNum << '@';
   Mangler.mangleNestedName(VD);
+  Mangler.getStream() << "@4HA";
 }
 
 void MicrosoftMangleContextImpl::mangleStaticGuardVariable(const VarDecl *VD,

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp?rev=270974=270973=270974=diff
==
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-thread-safe-statics.cpp Fri May 27 
03:52:34 2016
@@ -9,12 +9,14 @@ struct S {
 // CHECK-DAG: @"\01?s@?1??f@@YAAAUS@@XZ@4U2@A" = linkonce_odr thread_local 
global %struct.S zeroinitializer
 // CHECK-DAG: @"\01??__J?1??f@@YAAAUS@@XZ@51" = linkonce_odr thread_local 
global i32 0
 // CHECK-DAG: @"\01?s@?1??g@@YAAAUS@@XZ@4U2@A" = linkonce_odr global %struct.S 
zeroinitializer
-// CHECK-DAG: @"\01?$TSS0@?1??g@@YAAAUS@@XZ" = linkonce_odr global i32 0
+// CHECK-DAG: @"\01?$TSS0@?1??g@@YAAAUS@@XZ@4HA" = linkonce_odr global i32 0
 // CHECK-DAG: @_Init_thread_epoch = external thread_local global i32, align 4
 // CHECK-DAG: @"\01?j@?1??h@@YAAAUS@@_N@Z@4U2@A" = linkonce_odr thread_local 
global %struct.S zeroinitializer
 // CHECK-DAG: @"\01??__J?1??h@@YAAAUS@@_N@Z@51" = linkonce_odr thread_local 
global i32 0
 // CHECK-DAG: @"\01?i@?1??h@@YAAAUS@@_N@Z@4U2@A" = linkonce_odr global 
%struct.S zeroinitializer
-// CHECK-DAG: @"\01?$TSS0@?1??h@@YAAAUS@@_N@Z" = linkonce_odr global i32 0
+// CHECK-DAG: @"\01?$TSS0@?1??h@@YAAAUS@@_N@Z@4HA" = linkonce_odr global i32 0
+// CHECK-DAG: @"\01?i@?1??g1@@YAHXZ@4HA" = internal global i32 0, align 4
+// CHECK-DAG: @"\01?$TSS0@?1??g1@@YAHXZ@4HA" = internal global i32 0, align 4
 
 // CHECK-LABEL: define {{.*}} @"\01?f@@YAAAUS@@XZ"()
 // CHECK-SAME:  personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*)
@@ -51,14 +53,14 @@ extern inline S () {
 // CHECK-LABEL: define {{.*}} @"\01?g@@YAAAUS@@XZ"()
 extern inline S () {
   static S s;
-// CHECK:  %[[guard:.*]] = load atomic i32, i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ" unordered, align 4
+// CHECK:  %[[guard:.*]] = load atomic i32, i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ@4HA" unordered, align 4
 // CHECK-NEXT:  %[[epoch:.*]] = load i32, i32* @_Init_thread_epoch
 // CHECK-NEXT:  %[[cmp:.*]] = icmp sgt i32 %[[guard]], %[[epoch]]
 // CHECK-NEXT:  br i1 %[[cmp]], label %[[init_attempt:.*]], label 
%[[init_end:.*]]
 //
 // CHECK: [[init_attempt]]:
-// CHECK-NEXT:  call void @_Init_thread_header(i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ")
-// CHECK-NEXT:  %[[guard2:.*]] = load atomic i32, i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ" unordered, align 4
+// CHECK-NEXT:  call void @_Init_thread_header(i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ@4HA")
+// CHECK-NEXT:  %[[guard2:.*]] = load atomic i32, i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ@4HA" unordered, align 4
 // CHECK-NEXT:  %[[cmp2:.*]] = icmp eq i32 %[[guard2]], -1
 // CHECK-NEXT:  br i1 %[[cmp2]], label %[[init:.*]], label %[[init_end:.*]]
 //
@@ -68,7 +70,7 @@ extern inline S () {
 //
 // CHECK: [[invoke_cont]]:
 // CHECK-NEXT:  call i32 @atexit(void ()* @"\01??__Fs@?1??g@@YAAAUS@@XZ@YAXXZ")
-// CHECK-NEXT:  call void @_Init_thread_footer(i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ")
+// CHECK-NEXT:  call void @_Init_thread_footer(i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ@4HA")
 // CHECK-NEXT:  br label %init.end
 //
 // CHECK: [[init_end]]:
@@ -76,7 +78,7 @@ extern inline S () {
 //
 // CHECK: [[lpad]]:
 // CHECK-NEXT: cleanuppad within none []
-// CHECK:   call void @_Init_thread_abort(i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ")
+// CHECK:   call void @_Init_thread_abort(i32* 
@"\01?$TSS0@?1??g@@YAAAUS@@XZ@4HA")
 // CHECK-NEXT:  cleanupret {{.*}} unwind to caller
   return s;
 }
@@ -86,3 +88,10 @@ extern inline S(bool b) {
   static S i;
   return b ? j : i;
 }
+
+// CHECK-LABEL: define i32 @"\01?g1@@YAHXZ"()
+int f1();
+int g1() {
+  static int i = f1();
+  return i;
+}



Re: [PATCH] D18641: [PP] Handle #include_next after include found relative to current one same as GCC

2016-05-26 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin abandoned this revision.
DmitryPolukhin added a comment.

It seems that there is no interest in this patch, abandon.


http://reviews.llvm.org/D18641



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


Re: [PATCH] D18035: [GCC] PR23529 Mangler part of attrbute abi_tag support

2016-05-26 Thread Dmitry Polukhin via cfe-commits
On Thu, May 26, 2016 at 12:41 AM, David Majnemer 
wrote:

> In http://reviews.llvm.org/D18035#434095, @DmitryPolukhin wrote:
>
> > One more friendly ping.. :(
>
> I think the best way to make progress on this is to refactor this patch
> along the lines @rsmith suggested back on May 3.
>

To be honest I still don't understand what is the key difference between
these two approaches. Both assume that compiler mangles something twice:
one for collecting implicit abi_tags without outputting name to real stream
and once more time mangling name for real with implicit tags collected on
previous stage. I tested my patch on Richard's example and explained why it
works as it should be.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r270535 - [MSVC2015] dllexport for defaulted special class members

2016-05-24 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Tue May 24 01:37:14 2016
New Revision: 270535

URL: http://llvm.org/viewvc/llvm-project?rev=270535=rev
Log:
[MSVC2015] dllexport for defaulted special class members

Clang doesn't dllexport defaulted special member function defaulted
inside class but does it if they defaulted outside class. MSVC doesn't
make any distinction where they were defaulted. Also MSVC 2013 and 2015
export different set of members. MSVC2015 doesn't emit trivial defaulted
x-tors but does emit copy assign operator.

Differential revision: http://reviews.llvm.org/D20422

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/CodeGenCXX/dllexport-members.cpp
cfe/trunk/test/CodeGenCXX/dllexport.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=270535=270534=270535=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue May 24 01:37:14 2016
@@ -4811,11 +4811,17 @@ void Sema::checkClassLevelDLLAttribute(C
 // MSVC versions before 2015 don't export the move assignment operators
 // and move constructor, so don't attempt to import/export them if
 // we have a definition.
-auto *CXXC = dyn_cast(MD);
+auto *Ctor = dyn_cast(MD);
 if ((MD->isMoveAssignmentOperator() ||
- (CXXC && CXXC->isMoveConstructor())) &&
+ (Ctor && Ctor->isMoveConstructor())) &&
 !getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015))
   continue;
+
+// MSVC2015 doesn't export trivial defaulted x-tor but copy assign
+// operator is exported anyway.
+if (getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015) &&
+(Ctor || isa(MD)) && MD->isTrivial())
+  continue;
   }
 }
 
@@ -4889,6 +4895,33 @@ void Sema::propagateDLLAttrToBaseClassTe
   }
 }
 
+static void DefineImplicitSpecialMember(Sema , CXXMethodDecl *MD,
+SourceLocation DefaultLoc) {
+  switch (S.getSpecialMember(MD)) {
+  case Sema::CXXDefaultConstructor:
+S.DefineImplicitDefaultConstructor(DefaultLoc,
+   cast(MD));
+break;
+  case Sema::CXXCopyConstructor:
+S.DefineImplicitCopyConstructor(DefaultLoc, cast(MD));
+break;
+  case Sema::CXXCopyAssignment:
+S.DefineImplicitCopyAssignment(DefaultLoc, MD);
+break;
+  case Sema::CXXDestructor:
+S.DefineImplicitDestructor(DefaultLoc, cast(MD));
+break;
+  case Sema::CXXMoveConstructor:
+S.DefineImplicitMoveConstructor(DefaultLoc, cast(MD));
+break;
+  case Sema::CXXMoveAssignment:
+S.DefineImplicitMoveAssignment(DefaultLoc, MD);
+break;
+  case Sema::CXXInvalid:
+llvm_unreachable("Invalid special member.");
+  }
+}
+
 /// \brief Perform semantic checks on a class definition that has been
 /// completing, introducing implicitly-declared members, checking for
 /// abstract types, etc.
@@ -4984,8 +5017,8 @@ void Sema::CheckCompletedCXXClass(CXXRec
 
   // For an explicitly defaulted or deleted special member, we defer
   // determining triviality until the class is complete. That time is now!
+  CXXSpecialMember CSM = getSpecialMember(M);
   if (!M->isImplicit() && !M->isUserProvided()) {
-CXXSpecialMember CSM = getSpecialMember(M);
 if (CSM != CXXInvalid) {
   M->setTrivial(SpecialMemberIsTrivial(M, CSM));
 
@@ -4993,6 +5026,20 @@ void Sema::CheckCompletedCXXClass(CXXRec
   Record->finishedDefaultedOrDeletedMember(M);
 }
   }
+
+  if (!M->isInvalidDecl() && M->isExplicitlyDefaulted() &&
+  M->hasAttr()) {
+if (getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015) &&
+M->isTrivial() &&
+(CSM == CXXDefaultConstructor || CSM == CXXCopyConstructor ||
+ CSM == CXXDestructor))
+  M->dropAttr();
+
+if (M->hasAttr()) {
+  DefineImplicitSpecialMember(*this, M, M->getLocation());
+  ActOnFinishInlineFunctionDef(M);
+}
+  }
 }
   }
 
@@ -13063,32 +13110,8 @@ void Sema::SetDeclDefaulted(Decl *Dcl, S
 
 CheckExplicitlyDefaultedSpecialMember(MD);
 
-if (MD->isInvalidDecl())
-  return;
-
-switch (Member) {
-case CXXDefaultConstructor:
-  DefineImplicitDefaultConstructor(DefaultLoc,
-   cast(MD));
-  break;
-case CXXCopyConstructor:
-  DefineImplicitCopyConstructor(DefaultLoc, cast(MD));
-  break;
-case CXXCopyAssignment:
-  DefineImplicitCopyAssignment(DefaultLoc, MD);
-  break;
-case CXXDestructor:
-  DefineImplicitDestructor(DefaultLoc, cast(MD));
-  break;
-case CXXMoveConstructor:
-  DefineImplicitMoveConstructor(DefaultLoc, cast(MD));
-  break;
-case CXXMoveAssignment:
-  

Re: [PATCH] D20422: [MSVC2015] dllexport for defaulted special class members

2016-05-23 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

PTAL



Comment at: lib/Sema/SemaDeclCXX.cpp:13113-13114
@@ -13065,28 +13112,4 @@
 
-if (MD->isInvalidDecl())
-  return;
-
-switch (Member) {
-case CXXDefaultConstructor:
-  DefineImplicitDefaultConstructor(DefaultLoc,
-   cast(MD));
-  break;
-case CXXCopyConstructor:
-  DefineImplicitCopyConstructor(DefaultLoc, cast(MD));
-  break;
-case CXXCopyAssignment:
-  DefineImplicitCopyAssignment(DefaultLoc, MD);
-  break;
-case CXXDestructor:
-  DefineImplicitDestructor(DefaultLoc, cast(MD));
-  break;
-case CXXMoveConstructor:
-  DefineImplicitMoveConstructor(DefaultLoc, cast(MD));
-  break;
-case CXXMoveAssignment:
-  DefineImplicitMoveAssignment(DefaultLoc, MD);
-  break;
-case CXXInvalid:
-  llvm_unreachable("Invalid special member.");
-}
+if (!MD->isInvalidDecl())
+  DefineImplicitSpecialMember(*this, MD, DefaultLoc);
   } else {

I added code to drop dllexport attribute but the check for dropping dllexport 
attribute is basically the same. Moreover it cannot be done when the attribute 
is processed because we need full class definition so I moved the check to 
CheckCompletedCXXClass. Alternatively I can move the check to 
checkClassLevelDLLAttribute but it will start working for classes without class 
level dllexport attribute to detect if any class member has member level 
attribute (it is less efficient  because it requires more more loop over all 
class methods even for all classes).


http://reviews.llvm.org/D20422



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


Re: [PATCH] D20422: [MSVC2015] dllexport for defaulted special class members

2016-05-23 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 58088.
DmitryPolukhin added a comment.

- drop dllexport for trivial defaulted x-tors for compatibility with MSVC2015
- move checks to CheckCompletedCXXClass because completed class definition is 
required to detect if x-tor is trivial


http://reviews.llvm.org/D20422

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/CodeGenCXX/dllexport-members.cpp
  test/CodeGenCXX/dllexport.cpp

Index: test/CodeGenCXX/dllexport.cpp
===
--- test/CodeGenCXX/dllexport.cpp
+++ test/CodeGenCXX/dllexport.cpp
@@ -1,8 +1,8 @@
-// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-optzns -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2015 %s
-// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-optzns -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2013 %s
+// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-optzns -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2015 -check-prefix=M32MSVC2015 %s
+// RUN: %clang_cc1 -triple i686-windows-msvc   -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O1 -mconstructor-aliases -disable-llvm-optzns -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M32 -check-prefix=MSVC2013 -check-prefix=M32MSVC2013 %s
 
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2015 %s
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2013 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=19.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2015 -check-prefix=M64MSVC2015 %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w -fms-compatibility-version=18.00 | FileCheck --check-prefix=MSC --check-prefix=M64 -check-prefix=MSVC2013 -check-prefix=M64MSVC2013 %s
 
 // RUN: %clang_cc1 -triple i686-windows-gnu-emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G32 %s
 // RUN: %clang_cc1 -triple x86_64-windows-gnu  -emit-llvm -std=c++1y -fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | FileCheck --check-prefix=GNU --check-prefix=G64 %s
@@ -561,7 +561,7 @@
 
   // Explicitly defaulted copy constructur:
   T(const T&) = default;
-  // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.T* @"\01??0T@@QAE@ABU0@@Z"
+  // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.T* @"\01??0T@@QAE@ABU0@@Z"
 
   void a() {}
   // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01?a@T@@QAEXXZ"
@@ -647,9 +647,34 @@
 
 struct __declspec(dllexport) DefaultedCtorsDtors {
   DefaultedCtorsDtors() = default;
-  // M32-DAG: define weak_odr dllexport x86_thiscallcc %struct.DefaultedCtorsDtors* @"\01??0DefaultedCtorsDtors@@QAE@XZ"
+  // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.DefaultedCtorsDtors* @"\01??0DefaultedCtorsDtors@@QAE@XZ"
   ~DefaultedCtorsDtors() = default;
-  // M32-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??1DefaultedCtorsDtors@@QAE@XZ"
+  // M32MSVC2013-DAG: define weak_odr dllexport x86_thiscallcc void @"\01??1DefaultedCtorsDtors@@QAE@XZ"
+};
+
+// Export defaulted member function definitions declared inside class.
+struct __declspec(dllexport) ExportDefaultedInclassDefs {
+  ExportDefaultedInclassDefs() = default;
+  // M32VS2013-DAG: define weak_odr dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
+  // M64VS2013-DAG: define weak_odr dllexport%struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
+  // M32VS2015-NOT: define weak_odr dllexport x86_thiscallcc %struct.ExportDefaultedInclassDefs* @"\01??0ExportDefaultedInclassDefs@@QAE@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
+  // M64VS2015-NOT: define weak_odr dllexport%struct.ExportDefaultedInclassDefs* 

Re: [PATCH] D18035: [GCC] PR23529 Mangler part of attrbute abi_tag support

2016-05-23 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 58076.
DmitryPolukhin added a comment.

Fix test/PCH/attrs.c failure due to warning about unsupported abi_tag attribute 
(committed in http://reviews.llvm.org/rL269869).
This patch implements abi_tag so the warning is not expected with this patch.


http://reviews.llvm.org/D18035

Files:
  lib/AST/ItaniumMangle.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/mangle-abi-tag.cpp
  test/PCH/attrs.c
  test/SemaCXX/attr-abi-tag-syntax.cpp

Index: test/SemaCXX/attr-abi-tag-syntax.cpp
===
--- test/SemaCXX/attr-abi-tag-syntax.cpp
+++ test/SemaCXX/attr-abi-tag-syntax.cpp
@@ -16,28 +16,18 @@
 // expected-warning@-1 {{'abi_tag' attribute on anonymous namespace ignored}}
 
 inline namespace N __attribute__((__abi_tag__)) {}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-2 {{'__abi_tag__' attribute ignored}}
 
 } // namespcace N2
 
 __attribute__((abi_tag("B", "A"))) extern int a1;
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-2 {{'abi_tag' attribute ignored}}
 
 __attribute__((abi_tag("A", "B"))) extern int a1;
 // expected-note@-1 {{previous declaration is here}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
 
 __attribute__((abi_tag("A", "C"))) extern int a1;
 // expected-error@-1 {{'abi_tag' C missing in original declaration}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
 
 extern int a2;
 // expected-note@-1 {{previous declaration is here}}
 __attribute__((abi_tag("A")))extern int a2;
 // expected-error@-1 {{cannot add 'abi_tag' attribute in a redeclaration}}
-// FIXME: remove this warning as soon as attribute fully supported.
-// expected-warning@-3 {{'abi_tag' attribute ignored}}
Index: test/PCH/attrs.c
===
--- test/PCH/attrs.c
+++ test/PCH/attrs.c
@@ -9,7 +9,7 @@
 #define HEADER
 
 int f(int) __attribute__((visibility("default"), overloadable));
-int g(int) __attribute__((abi_tag("foo", "bar", "baz"), no_sanitize("address", "memory"))); // expected-warning {{ignored}}
+int g(int) __attribute__((abi_tag("foo", "bar", "baz"), no_sanitize("address", "memory")));
 
 #else
 
Index: test/CodeGenCXX/mangle-abi-tag.cpp
===
--- /dev/null
+++ test/CodeGenCXX/mangle-abi-tag.cpp
@@ -0,0 +1,146 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple %itanium_abi_triple -std=c++11 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple i686-linux-gnu -std=c++11 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -triple x86_64-linux-gnu -std=c++11 -o - | FileCheck %s
+
+struct __attribute__((abi_tag("A", "B"))) A { };
+
+struct B: A { };
+
+template
+
+struct C {
+};
+
+struct D { A* p; };
+
+template
+struct __attribute__((abi_tag("C", "D"))) E {
+};
+
+struct __attribute__((abi_tag("A", "B"))) F { };
+
+A a1;
+// CHECK: @_Z2a1B1AB1B =
+
+__attribute__((abi_tag("C", "D")))
+A a2;
+// CHECK: @_Z2a2B1AB1BB1CB1D =
+
+B a3;
+// CHECK: @a3 =
+
+C a4;
+// CHECK: @_Z2a4B1AB1B =
+
+D a5;
+// CHECK: @a5 =
+
+E a6;
+// CHECK: @_Z2a6B1CB1D =
+
+E a7;
+// CHECK: @_Z2a7B1AB1BB1CB1D =
+
+template<>
+struct E {
+  static float a8;
+};
+float E::a8;
+// CHECK: @_ZN1EB1CB1DIfE2a8E =
+
+template<>
+struct E {
+  static bool a9;
+};
+bool E::a9;
+// CHECK: @_ZN1EB1CB1DI1FB1AB1BE2a9E =
+
+struct __attribute__((abi_tag("A", "B"))) A10 {
+  virtual ~A10() {}
+} a10;
+// vtable
+// CHECK: @_ZTV3A10B1AB1B =
+// typeinfo
+// CHECK: @_ZTI3A10B1AB1B =
+
+// Local variables from f13.
+// f13()::L::foo[abi:C][abi:D]()::a[abi:A][abi:B]
+// CHECK-DAG: @_ZZZ3f13vEN1L3fooB1CB1DEvE1aB1AB1B =
+// guard variable for f13()::L::foo[abi:C][abi:D]()::a[abi:A][abi:B]
+// CHECK-DAG: @_ZGVZZ3f13vEN1L3fooB1CB1DEvE1aB1AB1B =
+
+__attribute__ ((abi_tag("C", "D")))
+void* f1() {
+  return 0;
+}
+// CHECK: define {{.*}} @_Z2f1B1CB1Dv(
+
+__attribute__ ((abi_tag("C", "D")))
+A* f2() {
+  return 0;
+}
+// CHECK: define {{.*}} @_Z2f2B1AB1BB1CB1Dv(
+
+B* f3() {
+  return 0;
+}
+// CHECK: define {{.*}} @_Z2f3v(
+
+C* f4() {
+  return 0;
+}
+// CHECK: define {{.*}} @_Z2f4B1AB1Bv(
+
+D* f5() {
+  return 0;
+}
+// CHECK: define {{.*}} @_Z2f5v(
+
+E* f6() {
+  return 0;
+}
+// CHECK: define {{.*}} @_Z2f6B1CB1Dv(
+
+E* f7() {
+  return 0;
+}
+// CHECK: define {{.*}} @_Z2f7B1AB1BB1CB1Dv(
+
+void f8(E*) {
+}
+// CHECK: define {{.*}} @_Z2f8P1EB1CB1DI1AB1AB1BE(
+
+inline namespace Names1 __attribute__((__abi_tag__)) {
+class C1 {};
+}
+C1 f9() { return C1(); }
+// CHECK: @_Z2f9B6Names1v(
+
+inline namespace Names2 __attribute__((__abi_tag__("Tag1", "Tag2"))) {
+class C2 {};
+}
+C2 f10() { return C2(); }
+// CHECK: @_Z3f10B4Tag1B4Tag2v(
+
+void __attribute__((abi_tag("A"))) f11(A) {}
+// 

Re: [PATCH] D20422: [MSVC2015] dllexport for defaulted special class members

2016-05-19 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added inline comments.


Comment at: lib/Sema/SemaDeclCXX.cpp:13111
@@ -13090,3 +13110,3 @@
   llvm_unreachable("Invalid special member.");
 }
   } else {

rnk wrote:
> Can we add `if (InClassDef) ActOnFinishInlineFunctionDef(MD);` here instead? 
> If the decl doesn't have dllexport, we will just defer it until its 
> referenced, which seems OK.
We can move this check here but condition has to be more complicated because 
MSVC2015 doesn't export trivial defaulted c-tors even if they were explicitly 
declared dllexport, see my check on line 4822.


http://reviews.llvm.org/D20422



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


  1   2   >