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&view=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&r1=305376&r2=305377&view=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


[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 &Opts,
 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 &Iter = 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(LocalN

[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 &IO, clang::tooling::Diagnostic::Level &Value) {
+IO.enumCase(Value, "Warning", clang::tooling::Diagnostic::Warning);
+IO.enumCase(Value, "Error", clang::tooling::Diagnostic::Error);
+  }
+};
+
 } // end namespace yaml
 } // end namespace llvm
 

diff  --git a/clang/unittests/Tooling/Diagnosti

[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 &R)
 : 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] 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() ov

[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 tha

[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;
+/// Off

[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 &Outer, raw_ostream &Out_)
   : 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 &Outer, llvm::raw_null_ostream &Out_)
   : 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, &AdditionalAbiTags);
   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 &Outer, raw_ostream &Out_)
   : 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 &Outer, llvm::raw_null_ostream &Out_)
   : Context(Outer.Context), Out(Out_), NullOut(true),
 Structor(Outer.Structor), StructorType(Outer.StructorType),
-SeqID(Outer.SeqID), AbiTagsRoot(AbiTags) {}
+SeqID(Outer.SeqID), AbiTagsRoot(AbiTags),

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


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-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 &Outer, raw_ostream &Out_)
   : 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 &Outer, llvm::raw_null_ostream &Out_)
   : 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, &AdditionalAbiTags);
   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 +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 &Outer, raw_ostream &Out_)
   : 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 &Outer, llvm::raw_null_ostream &Out_)
   : 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(CXXNameMa

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


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&view=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&r1=282058&r2=282059&view=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 &Outer, raw_ostream &Out_)
   : 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 &Outer, llvm::raw_null_ostream &Out_)
   : 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, &AdditionalAbiTags);
   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 +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&r1=282058&r2=282059&view=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-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


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


[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


[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 &Error) {
   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-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 &Error) {
   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 
&Command,
   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

[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 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

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 &Error) {
   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 
&Command,
   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

[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-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-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] 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


@@ -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-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-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


[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 &FileChange : 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 0.

[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


[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


[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-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] [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] [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-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 &FileChange : 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
+++ 
b/clang-tools-extra/test/clang-apply-replacements/Inputs/fo

[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] 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-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: Ch

[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 &File;
-  unsigned SI = 1;
-  unsigned BI = 0;
-  FileMaker(FileTy &File) : 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] 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 &getHeader() const;
@@ -79,9 +84,10 @@ class HeaderMap : private HeaderMapImpl {
   /// ".." and a filename "../file.h" this would be "../../file.h".
   Optional LookupFile(StringRef Filename, FileManager &FM) 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 &Hdr = 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 path::convert_to_sl

[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-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] 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) 
/home/ivanmurashko/local/ll

[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 &Arg : 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] 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 [modernize-concat-

[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] 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-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] 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 -no

[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 &JA, 
const ArgList &Args,
 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, SplitSwarfSingleCr

[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


[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 &OverlayFile,
   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 mai

[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 &Dir = 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] 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 
&Command,
   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 &OptTable = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
   llvm::SmallVector OriginalArgs;
@@ -212,7 +229,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
 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 
&Command,
   //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.fron

[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 
&Command,
   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 &OptTable = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
   llvm::SmallVector OriginalArgs;
@@ -212,7 +229,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
 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 
&Command,
   //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) {
 

[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 
&Command,
   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 &OptTable = clang::driver::getDriverOptTable();
   // OriginalArgs needs to outlive ArgList.
   llvm::SmallVector OriginalArgs;
@@ -229,7 +212,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
 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 
&Command,
   //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

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-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


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&view=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&r1=275969&r2=275970&view=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&r1=275969&r2=275970&view=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 &S, 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 &S, 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&view=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] 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


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&view=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&r1=275973&r2=275974&view=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] D16572: PR23057: fix use-after-free due to local token buffer in ParseCXXAmbiguousParenExpression

2016-02-02 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 46644.
DmitryPolukhin added a comment.

Use EOF token instead of copy buffer. This approach looks a bit more fragile 
but definitely more efficient, PTAL.


http://reviews.llvm.org/D16572

Files:
  lib/Parse/ParseExprCXX.cpp
  test/Parser/cxx-ambig-paren-expr-asan.cpp

Index: test/Parser/cxx-ambig-paren-expr-asan.cpp
===
--- /dev/null
+++ test/Parser/cxx-ambig-paren-expr-asan.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+
+// This syntax error used to cause use-after free due to token local buffer
+// in ParseCXXAmbiguousParenExpression.
+int H((int()[)]);
+// expected-error@-1 {{expected expression}}
+// expected-error@-2 {{expected ']'}}
+// expected-note@-3 {{to match this '['}}
+// expected-error@-4 {{expected ';' after top level declarator}}
Index: lib/Parse/ParseExprCXX.cpp
===
--- lib/Parse/ParseExprCXX.cpp
+++ lib/Parse/ParseExprCXX.cpp
@@ -3081,6 +3081,14 @@
 ParseAs = NotCastExpr ? SimpleExpr : CastExpr;
   }
 
+  // Create a fake EOF to mark end of Toks buffer.
+  Token AttrEnd;
+  AttrEnd.startToken();
+  AttrEnd.setKind(tok::eof);
+  AttrEnd.setLocation(Tok.getLocation());
+  AttrEnd.setEofData(Toks.data());
+  Toks.push_back(AttrEnd);
+
   // The current token should go after the cached tokens.
   Toks.push_back(Tok);
   // Re-enter the stored parenthesized tokens into the token stream, so we may
@@ -3105,6 +3113,10 @@
 Tracker.consumeClose();
 ColonProt.restore();
 
+// Consume EOF marker for Toks buffer.
+assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
+ConsumeAnyToken();
+
 if (ParseAs == CompoundLiteral) {
   ExprType = CompoundLiteral;
   if (DeclaratorInfo.isInvalidType())
@@ -3141,10 +3153,16 @@
 
   // Match the ')'.
   if (Result.isInvalid()) {
-SkipUntil(tok::r_paren, StopAtSemi);
+while (Tok.isNot(tok::eof))
+  ConsumeAnyToken();
+assert(Tok.getEofData() == AttrEnd.getEofData());
+ConsumeAnyToken();
 return ExprError();
   }
 
   Tracker.consumeClose();
+  // Consume EOF marker for Toks buffer.
+  assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
+  ConsumeAnyToken();
   return Result;
 }


Index: test/Parser/cxx-ambig-paren-expr-asan.cpp
===
--- /dev/null
+++ test/Parser/cxx-ambig-paren-expr-asan.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
+
+// This syntax error used to cause use-after free due to token local buffer
+// in ParseCXXAmbiguousParenExpression.
+int H((int()[)]);
+// expected-error@-1 {{expected expression}}
+// expected-error@-2 {{expected ']'}}
+// expected-note@-3 {{to match this '['}}
+// expected-error@-4 {{expected ';' after top level declarator}}
Index: lib/Parse/ParseExprCXX.cpp
===
--- lib/Parse/ParseExprCXX.cpp
+++ lib/Parse/ParseExprCXX.cpp
@@ -3081,6 +3081,14 @@
 ParseAs = NotCastExpr ? SimpleExpr : CastExpr;
   }
 
+  // Create a fake EOF to mark end of Toks buffer.
+  Token AttrEnd;
+  AttrEnd.startToken();
+  AttrEnd.setKind(tok::eof);
+  AttrEnd.setLocation(Tok.getLocation());
+  AttrEnd.setEofData(Toks.data());
+  Toks.push_back(AttrEnd);
+
   // The current token should go after the cached tokens.
   Toks.push_back(Tok);
   // Re-enter the stored parenthesized tokens into the token stream, so we may
@@ -3105,6 +3113,10 @@
 Tracker.consumeClose();
 ColonProt.restore();
 
+// Consume EOF marker for Toks buffer.
+assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
+ConsumeAnyToken();
+
 if (ParseAs == CompoundLiteral) {
   ExprType = CompoundLiteral;
   if (DeclaratorInfo.isInvalidType())
@@ -3141,10 +3153,16 @@
 
   // Match the ')'.
   if (Result.isInvalid()) {
-SkipUntil(tok::r_paren, StopAtSemi);
+while (Tok.isNot(tok::eof))
+  ConsumeAnyToken();
+assert(Tok.getEofData() == AttrEnd.getEofData());
+ConsumeAnyToken();
 return ExprError();
   }
 
   Tracker.consumeClose();
+  // Consume EOF marker for Toks buffer.
+  assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
+  ConsumeAnyToken();
   return Result;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D12834: add gcc abi_tag support

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

I think Sema part should be exacted to separate patch and committed first after 
fixing Aaron's comments. Mangling part requires more work and much more tests. 
I'm still looking what actually GCC does and how it can be re-implemented in 
Clang without calling mangler twice.



Comment at: lib/Sema/SemaDeclAttr.cpp:4450
@@ +4449,3 @@
+static void handleAbiTagAttr(Sema &S, Decl *D,
+ const AttributeList &Attr) {
+  const auto *NS = dyn_cast(D);

Nit, all args fits to single line and the whole function needs clang-format.


Repository:
  rL LLVM

http://reviews.llvm.org/D12834



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


Re: [PATCH] D12834: add gcc abi_tag support

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

Hi Stefan,

What are your plans about this patch? The patch has number of comments about 
Sema part from Aaron and me but in general there are no major issues with Sema 
for the attribute.

As for mangling part I think recursive approach looks reasonable because 
alternative implementation will require re-implementation significant part of 
name mangling just to calculate abi_tags for types. So your approach minimizes 
code duplication. I made following changes in your patch F1448674: 
abi_tags.patch :

- rebase on top-of-the-tree
- fixed all failing tests (now check-clang has no unexpected fails)
- fixed issue with mangling for variables in global namespace with abi_tags
- partially fixed style/clang-format issues
- added more tests on abi_tags (used the newest GCC mangling for templates with 
Jason's patches from Jan 31, 2016)

If you are going to keep working on this patch, please integrate my patch in 
your patch. If you are not going to keep working on this patch, please let me 
know.

Thanks,
Dmitry Polukhin

Software Engineer
Intel Compiler Team


Repository:
  rL LLVM

http://reviews.llvm.org/D12834



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


Re: [PATCH] D17023: pr26544: Bitfield layout with pragma pack and attributes "packed" and "aligned

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

John, this patch extends check that I added recently and looks good to me but 
could you please also take a look.


http://reviews.llvm.org/D17023



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


[PATCH] D17197: [OPENMP] NFC rewrite ParseOpenMPDirectiveKind

2016-02-12 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added a reviewer: ABataev.
DmitryPolukhin added a subscriber: cfe-commits.

New implementation is easier to read and extend.

http://reviews.llvm.org/D17197

Files:
  lib/Parse/ParseOpenMP.cpp

Index: lib/Parse/ParseOpenMP.cpp
===
--- lib/Parse/ParseOpenMP.cpp
+++ lib/Parse/ParseOpenMP.cpp
@@ -26,74 +26,80 @@
 // OpenMP declarative directives.
 //===--===//
 
+namespace {
+enum OpenMPDirectiveKindEx {
+  OMPD_cancellation = OMPD_unknown + 1,
+  OMPD_data,
+  OMPD_enter,
+  OMPD_exit,
+  OMPD_point,
+  OMPD_target_enter,
+  OMPD_target_exit
+};
+} // namespace
+
+// Map token string to extended OMP token kind that are
+// OpenMPDirectiveKind + OpenMPDirectiveKindEx.
+static unsigned getOpenMPDirectiveKindEx(StringRef S) {
+  auto DKind = getOpenMPDirectiveKind(S);
+  if (DKind != OMPD_unknown)
+return DKind;
+
+  return llvm::StringSwitch(S)
+  .Case("cancellation", OMPD_cancellation)
+  .Case("data", OMPD_data)
+  .Case("enter", OMPD_enter)
+  .Case("exit", OMPD_exit)
+  .Case("point", OMPD_point)
+  .Default(OMPD_unknown);
+}
+
 static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
   // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
   // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
   // TODO: add other combined directives in topological order.
-  const OpenMPDirectiveKind F[][3] = {
-  {OMPD_unknown /*cancellation*/, OMPD_unknown /*point*/,
-   OMPD_cancellation_point},
-  {OMPD_target, OMPD_unknown /*data*/, OMPD_target_data},
-  {OMPD_target, OMPD_unknown /*enter/exit*/,
-   OMPD_unknown /*target enter/exit*/},
-  {OMPD_unknown /*target enter*/, OMPD_unknown /*data*/,
-   OMPD_target_enter_data},
-  {OMPD_unknown /*target exit*/, OMPD_unknown /*data*/,
-   OMPD_target_exit_data},
-  {OMPD_for, OMPD_simd, OMPD_for_simd},
-  {OMPD_parallel, OMPD_for, OMPD_parallel_for},
-  {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd},
-  {OMPD_parallel, OMPD_sections, OMPD_parallel_sections},
-  {OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd},
-  {OMPD_target, OMPD_parallel, OMPD_target_parallel},
-  {OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for}};
+  static const unsigned F[][3] = {
+{ OMPD_cancellation, OMPD_point, OMPD_cancellation_point },
+{ OMPD_target, OMPD_data, OMPD_target_data },
+{ OMPD_target, OMPD_enter, OMPD_target_enter },
+{ OMPD_target, OMPD_exit, OMPD_target_exit },
+{ OMPD_target_enter, OMPD_data, OMPD_target_enter_data },
+{ OMPD_target_exit, OMPD_data, OMPD_target_exit_data },
+{ OMPD_for, OMPD_simd, OMPD_for_simd },
+{ OMPD_parallel, OMPD_for, OMPD_parallel_for },
+{ OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd },
+{ OMPD_parallel, OMPD_sections, OMPD_parallel_sections },
+{ OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd },
+{ OMPD_target, OMPD_parallel, OMPD_target_parallel },
+{ OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for }
+  };
   auto Tok = P.getCurToken();
-  auto DKind =
+  unsigned DKind =
   Tok.isAnnotation()
-  ? OMPD_unknown
-  : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
+  ? static_cast(OMPD_unknown)
+  : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
+  if (DKind == OMPD_unknown)
+return OMPD_unknown;
 
-  bool TokenMatched = false;
   for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
-if (!Tok.isAnnotation() && DKind == OMPD_unknown) {
-  TokenMatched =
-  ((i == 0) &&
-   !P.getPreprocessor().getSpelling(Tok).compare("cancellation")) ||
-  ((i == 3) &&
-   !P.getPreprocessor().getSpelling(Tok).compare("enter")) ||
-  ((i == 4) && !P.getPreprocessor().getSpelling(Tok).compare("exit"));
-} else {
-  TokenMatched = DKind == F[i][0] && DKind != OMPD_unknown;
-}
-
-if (TokenMatched) {
-  Tok = P.getPreprocessor().LookAhead(0);
-  auto TokenIsAnnotation = Tok.isAnnotation();
-  auto SDKind =
-  TokenIsAnnotation
-  ? OMPD_unknown
-  : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
-
-  if (!TokenIsAnnotation && SDKind == OMPD_unknown) {
-TokenMatched =
-((i == 0) &&
- !P.getPreprocessor().getSpelling(Tok).compare("point")) ||
-((i == 1 || i == 3 || i == 4) &&
- !P.getPreprocessor().getSpelling(Tok).compare("data")) ||
-((i == 2) &&
- (!P.getPreprocessor().getSpelling(Tok).compare("enter") ||
-  !P.getPreprocessor().getSpelling(Tok).compare("exit")));
-  } else {
-TokenMatched = SDKind == F[i][1] && SDKind != OMPD_unknown;
-  }
-
-  if (TokenMatched) {
-P.ConsumeToken();
-DKind = F[

r260811 - [OPENMP] NFC rewrite ParseOpenMPDirectiveKind

2016-02-12 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Sat Feb 13 00:53:38 2016
New Revision: 260811

URL: http://llvm.org/viewvc/llvm-project?rev=260811&view=rev
Log:
[OPENMP] NFC rewrite ParseOpenMPDirectiveKind

New implementation is easier to read and extend.

Differential Revision: http://reviews.llvm.org/D17197

Modified:
cfe/trunk/lib/Parse/ParseOpenMP.cpp

Modified: cfe/trunk/lib/Parse/ParseOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseOpenMP.cpp?rev=260811&r1=260810&r2=260811&view=diff
==
--- cfe/trunk/lib/Parse/ParseOpenMP.cpp (original)
+++ cfe/trunk/lib/Parse/ParseOpenMP.cpp Sat Feb 13 00:53:38 2016
@@ -26,74 +26,80 @@ using namespace clang;
 // OpenMP declarative directives.
 
//===--===//
 
+namespace {
+enum OpenMPDirectiveKindEx {
+  OMPD_cancellation = OMPD_unknown + 1,
+  OMPD_data,
+  OMPD_enter,
+  OMPD_exit,
+  OMPD_point,
+  OMPD_target_enter,
+  OMPD_target_exit
+};
+} // namespace
+
+// Map token string to extended OMP token kind that are
+// OpenMPDirectiveKind + OpenMPDirectiveKindEx.
+static unsigned getOpenMPDirectiveKindEx(StringRef S) {
+  auto DKind = getOpenMPDirectiveKind(S);
+  if (DKind != OMPD_unknown)
+return DKind;
+
+  return llvm::StringSwitch(S)
+  .Case("cancellation", OMPD_cancellation)
+  .Case("data", OMPD_data)
+  .Case("enter", OMPD_enter)
+  .Case("exit", OMPD_exit)
+  .Case("point", OMPD_point)
+  .Default(OMPD_unknown);
+}
+
 static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) {
   // Array of foldings: F[i][0] F[i][1] ===> F[i][2].
   // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd
   // TODO: add other combined directives in topological order.
-  const OpenMPDirectiveKind F[][3] = {
-  {OMPD_unknown /*cancellation*/, OMPD_unknown /*point*/,
-   OMPD_cancellation_point},
-  {OMPD_target, OMPD_unknown /*data*/, OMPD_target_data},
-  {OMPD_target, OMPD_unknown /*enter/exit*/,
-   OMPD_unknown /*target enter/exit*/},
-  {OMPD_unknown /*target enter*/, OMPD_unknown /*data*/,
-   OMPD_target_enter_data},
-  {OMPD_unknown /*target exit*/, OMPD_unknown /*data*/,
-   OMPD_target_exit_data},
-  {OMPD_for, OMPD_simd, OMPD_for_simd},
-  {OMPD_parallel, OMPD_for, OMPD_parallel_for},
-  {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd},
-  {OMPD_parallel, OMPD_sections, OMPD_parallel_sections},
-  {OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd},
-  {OMPD_target, OMPD_parallel, OMPD_target_parallel},
-  {OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for}};
+  static const unsigned F[][3] = {
+{ OMPD_cancellation, OMPD_point, OMPD_cancellation_point },
+{ OMPD_target, OMPD_data, OMPD_target_data },
+{ OMPD_target, OMPD_enter, OMPD_target_enter },
+{ OMPD_target, OMPD_exit, OMPD_target_exit },
+{ OMPD_target_enter, OMPD_data, OMPD_target_enter_data },
+{ OMPD_target_exit, OMPD_data, OMPD_target_exit_data },
+{ OMPD_for, OMPD_simd, OMPD_for_simd },
+{ OMPD_parallel, OMPD_for, OMPD_parallel_for },
+{ OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd },
+{ OMPD_parallel, OMPD_sections, OMPD_parallel_sections },
+{ OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd },
+{ OMPD_target, OMPD_parallel, OMPD_target_parallel },
+{ OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for }
+  };
   auto Tok = P.getCurToken();
-  auto DKind =
+  unsigned DKind =
   Tok.isAnnotation()
-  ? OMPD_unknown
-  : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
+  ? static_cast(OMPD_unknown)
+  : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok));
+  if (DKind == OMPD_unknown)
+return OMPD_unknown;
 
-  bool TokenMatched = false;
   for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) {
-if (!Tok.isAnnotation() && DKind == OMPD_unknown) {
-  TokenMatched =
-  ((i == 0) &&
-   !P.getPreprocessor().getSpelling(Tok).compare("cancellation")) ||
-  ((i == 3) &&
-   !P.getPreprocessor().getSpelling(Tok).compare("enter")) ||
-  ((i == 4) && !P.getPreprocessor().getSpelling(Tok).compare("exit"));
-} else {
-  TokenMatched = DKind == F[i][0] && DKind != OMPD_unknown;
-}
+if (DKind != F[i][0])
+  continue;
 
-if (TokenMatched) {
-  Tok = P.getPreprocessor().LookAhead(0);
-  auto TokenIsAnnotation = Tok.isAnnotation();
-  auto SDKind =
-  TokenIsAnnotation
-  ? OMPD_unknown
-  : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok));
-
-  if (!TokenIsAnnotation && SDKind == OMPD_unknown) {
-TokenMatched =
-((i == 0) &&
- !P.getPreprocessor().getSpelling(Tok).compare("point")) ||
-((i == 1 || i == 3 || i == 4) &&
- !P.getPreprocessor().getSpelling(Tok).

[PATCH] D17567: [GCC] Sema part of attrbute abi_tag support

2016-02-24 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added a reviewer: aaron.ballman.
DmitryPolukhin added subscribers: cfe-commits, stbuehler.

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

Difference between original and this one:
- fixed all comments in original code review
- added more tests, all new diagnostics now covered by tests
- moved abi_tag on re-declaration checks to Sema::mergeDeclAttributes where 
they actually may work as designed
- clang-format + other stylistic changes

Mangle part will be sent for review as a separate patch.

http://reviews.llvm.org/D17567

Files:
  docs/ItaniumMangleAbiTags.rst
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/AttributeList.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/SemaCXX/attr-abi-tag-syntax.cpp

Index: test/SemaCXX/attr-abi-tag-syntax.cpp
===
--- /dev/null
+++ test/SemaCXX/attr-abi-tag-syntax.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
+
+namespace N1 {
+
+namespace __attribute__((__abi_tag__)) {}
+// expected-warning@-1 {{'abi_tag' attribute on non-inline namespace ignored}}
+
+namespace N __attribute__((__abi_tag__)) {}
+// expected-warning@-1 {{'abi_tag' attribute on non-inline namespace ignored}}
+
+} // namespace N1
+
+namespace N2 {
+
+inline namespace __attribute__((__abi_tag__)) {}
+// 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 redeclaration}}
+// FIXME: remove this warning as soon as attribute fully supported.
+// expected-warning@-3 {{'abi_tag' attribute ignored}}
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4493,6 +4493,42 @@
   Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex()));
 }
 
+static void handleAbiTagAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+  SmallVector Tags;
+  for (unsigned I = 0, E = Attr.getNumArgs(); I != E; ++I) {
+StringRef Tag;
+if (!S.checkStringLiteralArgumentAttr(Attr, I, Tag))
+  return;
+Tags.push_back(Tag);
+  }
+
+  if (const auto *NS = dyn_cast(D)) {
+if (!NS->isInline()) {
+  S.Diag(Attr.getLoc(), diag::warn_attr_abi_tag_namespace) << 0;
+  return;
+}
+if (NS->isAnonymousNamespace()) {
+  S.Diag(Attr.getLoc(), diag::warn_attr_abi_tag_namespace) << 1;
+  return;
+}
+if (Attr.getNumArgs() == 0)
+  Tags.push_back(NS->getName());
+  } else if (!checkAttributeAtLeastNumArgs(S, Attr, 1))
+return;
+
+  // Store tags sorted and without duplicates.
+  std::sort(Tags.begin(), Tags.end());
+  Tags.erase(std::unique(Tags.begin(), Tags.end()), Tags.end());
+
+  D->addAttr(::new (S.Context)
+ AbiTagAttr(Attr.getRange(), S.Context, Tags.data(), Tags.size(),
+Attr.getAttributeSpellingListIndex()));
+
+  // FIXME: remove this warning as soon as mangled part is ready.
+  S.Diag(Attr.getRange().getBegin(), diag::warn_attribute_ignored)
+<< Attr.getName();
+}
+
 static void handleARMInterruptAttr(Sema &S, Decl *D,
const AttributeList &Attr) {
   // Check the attribute arguments.
@@ -5466,6 +5502,9 @@
   case AttributeList::AT_Thread:
 handleDeclspecThreadAttr(S, D, Attr);
 break;
+  case AttributeList::AT_AbiTag:
+handleAbiTagAttr(S, D, Attr);
+break;
 
   // Thread safety attributes:
   case AttributeList::AT_AssertExclusiveLock:
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -2398,6 +2398,24 @@
 }
   }
 
+  // Re-declaration cannot add abi_tag's.
+  if (const auto *NewAbiTagAttr = New->getAttr()) {
+if (const auto *OldAbiTagAttr = Old->getAttr()) {
+  for 

Re: r267534 - [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-27 Thread Dmitry Polukhin via cfe-commits
I added example with 'B*' to 'A*' just to make sure that my patch doesn't
break it accidentally in MSVC mode.

As for 'A*' to 'B*" case, indeed it is not very common and it looks like
someone just forgot to specify 'public'. I tried to find more real world
examples in public source codes but without Google Code Search it is hard
to do (GitHub doesn't support regexp search). Please let me know if you
think it doesn't make sense to support this "feature" in Clang and I'll
revert my patch.

On Wed, Apr 27, 2016 at 5:12 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Tue, Apr 26, 2016 at 7:04 PM, David Majnemer via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Visual Studio 2015 (19.00.23720.0) reports:
>>
>> error C2243: 'static_cast': conversion from 'B *' to 'A *' exists, but is
>> inaccessible
>>
>
> Right, it's the other direction ('A *' to 'B *') that this patch is
> permitting.
>
>
>> On Tue, Apr 26, 2016 at 6:33 PM, Richard Smith via cfe-commits <
>> cfe-commits@lists.llvm.org> wrote:
>>
>>> As noted in PR27337, this only occurs in one WTL sample, and we have no
>>> evidence that it actually occurs in real code. Have you seen uses of this
>>> in the wild? We generally don't want to add compatibility for MSVC bugs
>>> unless there's some real-world motivation.
>>>
>>>
>>> On Tue, Apr 26, 2016 at 2:21 AM, Dmitry Polukhin via cfe-commits <
>>> cfe-commits@lists.llvm.org> wrote:
>>>
>>>> Author: dpolukhin
>>>> Date: Tue Apr 26 04:21:17 2016
>>>> New Revision: 267534
>>>>
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=267534&view=rev
>>>> Log:
>>>> [MSVC] PR27337: allow static_cast from private base to derived for WTL
>>>>
>>>> MSVC doesn't report even warning for cast from private base class to
>>>> derived.
>>>>
>>>> Differential Revision: http://reviews.llvm.org/D19477
>>>>
>>>> Added:
>>>> cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp   (with props)
>>>> Modified:
>>>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>>> cfe/trunk/lib/Sema/SemaCast.cpp
>>>>
>>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>>> URL:
>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267534&r1=267533&r2=267534&view=diff
>>>>
>>>> ==
>>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Apr 26
>>>> 04:21:17 2016
>>>> @@ -5764,6 +5764,9 @@ def err_static_downcast_via_virtual : Er
>>>>"cannot cast %0 to %1 via virtual base %2">;
>>>>  def err_downcast_from_inaccessible_base : Error<
>>>>"cannot cast %select{private|protected}2 base class %1 to %0">;
>>>> +def ext_ms_downcast_from_inaccessible_base : ExtWarn<
>>>> +  "casting from %select{private|protected}2 base class %1 to derived
>>>> class %0 is a Microsoft extension">,
>>>> +  InGroup;
>>>>  def err_upcast_to_inaccessible_base : Error<
>>>>"cannot cast %0 to its %select{private|protected}2 base class %1">;
>>>>  def err_bad_dynamic_cast_not_ref_or_ptr : Error<
>>>>
>>>> Modified: cfe/trunk/lib/Sema/SemaCast.cpp
>>>> URL:
>>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=267534&r1=267533&r2=267534&view=diff
>>>>
>>>> ==
>>>> --- cfe/trunk/lib/Sema/SemaCast.cpp (original)
>>>> +++ cfe/trunk/lib/Sema/SemaCast.cpp Tue Apr 26 04:21:17 2016
>>>> @@ -1344,10 +1344,11 @@ TryStaticDowncast(Sema &Self, CanQualTyp
>>>>}
>>>>
>>>>if (!CStyle) {
>>>> -switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
>>>> -  SrcType, DestType,
>>>> -  Paths.front(),
>>>> -
>>>> diag::err_downcast_from_inaccessible_base)) {
>>>> +unsigned Diag = 

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

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

In http://reviews.llvm.org/D18641#413277, @rsmith wrote:

> I'm a little concerned about the possibility of this breaking uses of this 
> feature on platforms where Clang is the system compiler. For instance, this 
> pattern would be broken by your change:
>
>   // stddef.h
>   #include "stddef-helper.h"
>   
>   // stddef-helper.h
>   #include_next 
>   
>
> Conversely, I don't think any important library is likely to be relying on 
> the GCC behavior, because compilations with `gcc -I-` would effectively get 
> the current Clang behavior (because relative-looking paths would be found in 
> the relevant include search path rather than as relative paths).


The same is true for Clang with my patch i.e. use clang -iquote to get almost 
old behavior. So IMHO on the system where Clang is a replacement for GCC it is 
better to be GCC compatible in such basic things as include behavior.

> Is there some way we can gain confidence we're not breaking things here?


I don't know how we can get such confidence without committing code and see if 
any issues arrive. On systems where GCC is default compiler I tested my patch 
on wide range of scenarios and there were no problems.

Please let me know if you would like to proceed with this patch or I should 
abandon it.


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: r267534 - [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-27 Thread Dmitry Polukhin via cfe-commits
So it seems that there is an agreement that Clang don't need this MSVC
"feature" so I'll revert my patch tomorrow when I get to the office.

On Wed, Apr 27, 2016 at 10:09 PM, Stephan T. Lavavej <
s...@exchange.microsoft.com> wrote:

> [Richard Smith]
> > You can find a description of the problem in http://llvm.org/PR27337
> > Brief summary:
> > The WTL bug is the missing 'public' on the second base class on this
> line:
> https://sourceforge.net/p/wtl/code/HEAD/tree/trunk/wtl/Samples/MDIDocVw/mainfrm.h#l636
> > The C1xx bug is that it accepts a (non-C-style) cast from a base class
> to an inaccessible derived class.
>
> Thanks, I've asked my boss if MS devs still maintain WTL and if so, who.
>
> As for C1XX, I've filed VSO#216958 "C1XX shouldn't allow static_cast to
> bypass private inheritance" with a self-contained repro.
>
> STL
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r267865 - Revert "[MSVC] PR27337: allow static_cast from private base to derived for WTL"

2016-04-28 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Thu Apr 28 04:56:22 2016
New Revision: 267865

URL: http://llvm.org/viewvc/llvm-project?rev=267865&view=rev
Log:
Revert "[MSVC] PR27337: allow static_cast from private base to derived for WTL"

This reverts commit r267534.

Removed:
cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaCast.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=267865&r1=267864&r2=267865&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Apr 28 04:56:22 
2016
@@ -5764,9 +5764,6 @@ def err_static_downcast_via_virtual : Er
   "cannot cast %0 to %1 via virtual base %2">;
 def err_downcast_from_inaccessible_base : Error<
   "cannot cast %select{private|protected}2 base class %1 to %0">;
-def ext_ms_downcast_from_inaccessible_base : ExtWarn<
-  "casting from %select{private|protected}2 base class %1 to derived class %0 
is a Microsoft extension">,
-  InGroup;
 def err_upcast_to_inaccessible_base : Error<
   "cannot cast %0 to its %select{private|protected}2 base class %1">;
 def err_bad_dynamic_cast_not_ref_or_ptr : Error<

Modified: cfe/trunk/lib/Sema/SemaCast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCast.cpp?rev=267865&r1=267864&r2=267865&view=diff
==
--- cfe/trunk/lib/Sema/SemaCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCast.cpp Thu Apr 28 04:56:22 2016
@@ -1344,11 +1344,10 @@ TryStaticDowncast(Sema &Self, CanQualTyp
   }
 
   if (!CStyle) {
-unsigned Diag = Self.getLangOpts().MSVCCompat
-? diag::ext_ms_downcast_from_inaccessible_base
-: diag::err_downcast_from_inaccessible_base;
-switch (Self.CheckBaseClassAccess(OpRange.getBegin(), SrcType, DestType,
-  Paths.front(), Diag)) {
+switch (Self.CheckBaseClassAccess(OpRange.getBegin(),
+  SrcType, DestType,
+  Paths.front(),
+diag::err_downcast_from_inaccessible_base)) {
 case Sema::AR_accessible:
 case Sema::AR_delayed: // be optimistic
 case Sema::AR_dependent:   // be optimistic

Removed: cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp?rev=267864&view=auto
==
--- cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp (original)
+++ cfe/trunk/test/SemaCXX/ext_ms_downcast.cpp (removed)
@@ -1,40 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -fms-compatibility -verify %s
-// RUN: %clang_cc1 -fsyntax-only -DNO_MS_COMPATIBILITY -verify %s
-
-// Minimal reproducer.
-class A {};
-class B : A {}; // expected-note 2 {{implicitly declared private here}}
-
-B* foo(A* p) {
-  return static_cast(p);
-#ifdef NO_MS_COMPATIBILITY
-  // expected-error@-2 {{cannot cast private base class 'A' to 'B'}}
-#else
-  // expected-warning@-4 {{casting from private base class 'A' to derived 
class 'B' is a Microsoft extension}}
-#endif
-}
-
-A* bar(B* p) {
-  return static_cast(p); // expected-error {{cannot cast 'B' to its 
private base class 'A'}}
-}
-
-// from atlframe.h
-template 
-class CUpdateUI {
-public:
-  CUpdateUI() {
-T* pT = static_cast(this);
-#ifdef NO_MS_COMPATIBILITY
-// expected-error@-2 {{cannot cast private base class}}
-#else
-// expected-warning@-4 {{casting from private base class 
'CUpdateUI' to derived class 'CMDIFrame' is a Microsoft extension}}
-#endif
-  }
-};
-
-// from sample WTL/MDIDocVw (mainfrm.h
-class CMDIFrame : CUpdateUI {};
-// expected-note@-1 {{implicitly declared private here}}
-// expected-note@-2 {{in instantiation of member function}}
-
-CMDIFrame wndMain;


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


Re: r267534 - [MSVC] PR27337: allow static_cast from private base to derived for WTL

2016-04-28 Thread Dmitry Polukhin via cfe-commits
Reverted in r267865.

On Wed, Apr 27, 2016 at 10:31 PM, Dmitry Polukhin  wrote:

> So it seems that there is an agreement that Clang don't need this MSVC
> "feature" so I'll revert my patch tomorrow when I get to the office.
>
> On Wed, Apr 27, 2016 at 10:09 PM, Stephan T. Lavavej <
> s...@exchange.microsoft.com> wrote:
>
>> [Richard Smith]
>> > You can find a description of the problem in http://llvm.org/PR27337
>> > Brief summary:
>> > The WTL bug is the missing 'public' on the second base class on this
>> line:
>> https://sourceforge.net/p/wtl/code/HEAD/tree/trunk/wtl/Samples/MDIDocVw/mainfrm.h#l636
>> > The C1xx bug is that it accepts a (non-C-style) cast from a base class
>> to an inaccessible derived class.
>>
>> Thanks, I've asked my boss if MS devs still maintain WTL and if so, who.
>>
>> As for C1XX, I've filed VSO#216958 "C1XX shouldn't allow static_cast to
>> bypass private inheritance" with a self-contained repro.
>>
>> STL
>>
>
>
___
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-03 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

Richard, could you please share your counterexample so I could test it on my 
patch and GCC?

As for separate pass, it was my first reaction on the original patch from 
Stefan but soon I realized that I'll have to copy parts of magnler to some 
simplified mangler but with high probability of forgetting something and with 
code duplication. So now I think approach which runs full mangler in special 
mode is better and less error prone.


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-05-04 Thread Dmitry Polukhin via cfe-commits
On Wed, May 4, 2016 at 12:26 AM, Richard Smith 
wrote:

> On Tue, May 3, 2016 at 12:51 PM, Dmitry Polukhin via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> DmitryPolukhin added a comment.
>>
>> Richard, could you please share your counterexample so I could test it on
>> my patch and GCC?
>>
>
> Sure:
>
>   struct __attribute__((abi_tag("X"))) Foo {};
>   void __attribute__((abi_tag("X"))) f(Foo) {}
>
> This should not generate an ABI tag for 'f', because there's one implied
> by the first parameter type. But as far as I can see, this patch doesn't
> look at the parameter types at all until after it's already streamed out
> the mangling for the function name.
>

In this example ABI tag X is explicit tag for function 'f' so it must be
always emitted. Moreover even implicit tag case handled correctly i.e. no
implicit tag for function if the tag is already used in function
parameters. Here is my example and both GCC and Clang with my patch gives
identical mangling:

struct __attribute__((abi_tag("X"))) Foo {};

// _Z1fB1X3FooB1X pretty printed 'f[abi:X](Foo[abi:X])'
void __attribute__((abi_tag("X"))) f(Foo) {}

// _Z2f13FooB1X pretty printed 'f1(Foo[abi:X])'
Foo f1(Foo) {}

As for not looking for function arguments before emitting function name.
Please take a look to makeAdditionalTagsForFunction that handles this case.
It calls getTagsFromPrefixAndTemplateArguments also takes into account
function parameters (it disables implicit tags from return type and mangles
function declaration).

I think a reasonable way to deal with this is:
>
> 1) Collect the ABI tags for the overall entity. Whenever we subsequently
> emit an ABI tag (or emit an inline namespace and suppress emitting its ABI
> tags), remove that tag from our list of ABI tags for the overall entity (if
> it's there).
> 2) Mangle up to and including the name of the entity. If there are any ABI
> tags left for the entity, do subsequent mangling into a temporary buffer
> instead of directly into the output stream.
> 3) Mangle the rest of the declaration.
> 4) If there are any ABI tags left for the overall entity, and we have not
> already mangled the return type, then mangle it to a scratch buffer (which
> we'll throw away).
> 5) If we mangled to a temporary buffer, emit any remaining ABI tags now
> followed by the contents of the temporary buffer.
>
> As for separate pass, it was my first reaction on the original patch from
>> Stefan but soon I realized that I'll have to copy parts of magnler to some
>> simplified mangler but with high probability of forgetting something and
>> with code duplication. So now I think approach which runs full mangler in
>> special mode is better and less error prone.
>>
>>
>> http://reviews.llvm.org/D18035
>>
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
___
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-04 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 56116.
DmitryPolukhin added a comment.

+ rebase
+ added testcase with Richard's example


http://reviews.llvm.org/D18035

Files:
  lib/AST/ItaniumMangle.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/mangle-abi-tag.cpp
  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/CodeGenCXX/mangle-abi-tag.cpp
===
--- /dev/null
+++ test/CodeGenCXX/mangle-abi-tag.cpp
@@ -0,0 +1,144 @@
+// RUN: %clang_cc1 %s -emit-llvm -triple %itanium_abi_triple -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) {}
+// f11[abi:A](A[abi:A][abi:B])
+// CHECK: define {{.*}} @_Z3f11B1A1AB1AB1B(
+
+A f12(A) { return A(); }
+// f12(A[abi:A][abi:B])
+// CHECK: define {{.*}} @_Z3f121AB1AB1B(
+
+inline void f13() {
+  struct L {
+static E* foo() {
+  static A10 a;
+  return 0;
+}
+  };
+  L::foo();
+}
+void f11_test() {
+  f13();
+}
+// f13()::L::foo[abi:C][abi:D]()
+// CHECK: define linkonce_odr %struct.E* @_ZZ3f13vEN1L3fooB1CB1DEv(
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4694,10 +4694,6 @@
   D->addAttr(::new (S.Context)
  AbiTagAttr(Attr.getRange(), S.Context, Tags.data(), Tags.size(),
 Attr.getAttributeSpellingListIndex()));
-
-  // FIXME: remove this warning as soon

[PATCH] D20011: [OpenMP 4.5] Parse+Sema for '#pragma omp declare target' clauses

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

Support OpenMP version 4.5 syntax for #pragma omp declare target.

Syntax:
  #pragma omp declare target (extended-list) new-line
or
  #pragma omp declare target clause[ [,] clause ... ] new-line

Where clause is one of the following:
  to(extended-list)
  link(list)

http://reviews.llvm.org/D20011

Files:
  include/clang/AST/ASTMutationListener.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTWriter.h
  lib/Frontend/MultiplexConsumer.cpp
  lib/Parse/ParseOpenMP.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  test/OpenMP/declare_target_ast_print.cpp
  test/OpenMP/declare_target_messages.cpp

Index: test/OpenMP/declare_target_messages.cpp
===
--- test/OpenMP/declare_target_messages.cpp
+++ test/OpenMP/declare_target_messages.cpp
@@ -4,9 +4,15 @@
 
 int a, b; // expected-warning {{declaration is not declared in any declare target region}}
 __thread int t; // expected-note {{defined as threadprivate or thread local}}
-#pragma omp declare target private(a) // expected-warning {{extra tokens at the end of '#pragma omp declare target' are ignored}}
+
+#pragma omp declare target . // expected-error {{expected '(' after 'declare target'}}
+
+#pragma omp declare target
 void f();
 #pragma omp end declare target shared(a) // expected-warning {{extra tokens at the end of '#pragma omp end declare target' are ignored}}
+
+#pragma omp declare target map(a) // expected-error {{unexpected 'map' clause, only 'to' or 'link' clauses expected}}
+
 void c(); // expected-warning {{declaration is not declared in any declare target region}}
 
 extern int b;
@@ -86,4 +92,10 @@
 } //  expected-error {{expected '#pragma omp end declare target'}}
 #pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
 
+#pragma omp declare target link(S) // expected-error {{'S' used in declare target directive is not a variable or a function name}}
+
+#pragma omp declare target (x, x) // expected-error {{'x' appears multiple times in clauses on the same declare target directive}}
+#pragma omp declare target to(x) to(x) // expected-error {{'x' appears multiple times in clauses on the same declare target directive}}
+#pragma omp declare target link(x) // expected-error {{'x' must not appear in both clauses 'to' and 'link'}}
+
 #pragma omp declare target // expected-error {{expected '#pragma omp end declare target'}} expected-note {{to match this '#pragma omp declare target'}}
Index: test/OpenMP/declare_target_ast_print.cpp
===
--- test/OpenMP/declare_target_ast_print.cpp
+++ test/OpenMP/declare_target_ast_print.cpp
@@ -79,6 +79,51 @@
 #pragma omp end declare target
 // CHECK: #pragma omp end declare target
 
+int a1;
+void f1() {
+}
+#pragma omp declare target (a1, f1)
+// CHECK: #pragma omp declare target
+// CHECK: int a1;
+// CHECK: #pragma omp end declare target
+// CHECK: #pragma omp declare target
+// CHECK: void f1()
+// CHECK: #pragma omp end declare target
+
+int b1, b2, b3;
+void f2() {
+}
+#pragma omp declare target to(b1) to(b2), to(b3, f2)
+// CHECK: #pragma omp declare target
+// CHECK: int b1;
+// CHECK: #pragma omp end declare target
+// CHECK: #pragma omp declare target
+// CHECK: int b2;
+// CHECK: #pragma omp end declare target
+// CHECK: #pragma omp declare target
+// CHECK: int b3;
+// CHECK: #pragma omp end declare target
+// CHECK: #pragma omp declare target
+// CHECK: void f2()
+// CHECK: #pragma omp end declare target
+
+int c1, c2, c3;
+void f3() {
+}
+#pragma omp declare target link(c1) link(c2), link(c3, f3)
+// CHECK: #pragma omp declare target link
+// CHECK: int c1;
+// CHECK: #pragma omp end declare target
+// CHECK: #pragma omp declare target link
+// CHECK: int c2;
+// CHECK: #pragma omp end declare target
+// CHECK: #pragma omp declare target link
+// CHECK: int c3;
+// CHECK: #pragma omp end declare target
+// CHECK: #pragma omp declare target link
+// CHECK: void f3()
+// CHECK: #pragma omp end declare target
+
 int main (int argc, char **argv) {
   foo();
   foo_c();
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -5816,12 +5816,14 @@
   DeclUpdates[D].push_back(DeclUpdate(UPD_DECL_MARKED_OPENMP_THREADPRIVATE));
 }
 
-void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D) {
+void ASTWriter::DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
+ const Attr *Attr) {
   assert(!WritingAST && "Alr

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

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

Thank you for reporting this issue, I'll take a look.
I'm mostly testing on x86_64 so I may not notice the problem.


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-05-09 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 56581.
DmitryPolukhin added a comment.

- fixed tests for i686 when function may have hidden parameter


http://reviews.llvm.org/D18035

Files:
  lib/AST/ItaniumMangle.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGenCXX/mangle-abi-tag.cpp
  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/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) {}
+// f11[abi:A](A[abi:A][abi:B])
+// CHECK: define {{.*}} @_Z3f11B1A1AB1AB1B(
+
+A f12(A) { return A(); }
+// f12(A[abi:A][abi:B])
+// CHECK: define {{.*}} @_Z3f121AB1AB1B(
+
+inline void f13() {
+  struct L {
+static E* foo() {
+  static A10 a;
+  return 0;
+}
+  };
+  L::foo();
+}
+void f11_test() {
+  f13();
+}
+// f13()::L::foo[abi:C][abi:D]()
+// CHECK: define linkonce_odr %struct.E* @_ZZ3f13vEN1L3fooB1CB1DEv(
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -4700,10 +4700,6 @@
   D->addAttr(::new (S.Conte

r268925 - [OpenMP] Parse+Sema for '#pragma omp declare target' syntax version 4.5

2016-05-09 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Mon May  9 09:59:13 2016
New Revision: 268925

URL: http://llvm.org/viewvc/llvm-project?rev=268925&view=rev
Log:
[OpenMP] Parse+Sema for '#pragma omp declare target' syntax version 4.5

Support OpenMP version 4.5 syntax for #pragma omp declare target.

Syntax:
  #pragma omp declare target (extended-list) new-line
or
  #pragma omp declare target clause[ [,] clause ... ] new-line

Where clause is one of the following:
  to(extended-list)
  link(list)

Differential Revision: http://reviews.llvm.org/D20011

Modified:
cfe/trunk/include/clang/AST/ASTMutationListener.h
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/OpenMP/declare_target_ast_print.cpp
cfe/trunk/test/OpenMP/declare_target_messages.cpp

Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=268925&r1=268924&r2=268925&view=diff
==
--- cfe/trunk/include/clang/AST/ASTMutationListener.h (original)
+++ cfe/trunk/include/clang/AST/ASTMutationListener.h Mon May  9 09:59:13 2016
@@ -111,7 +111,9 @@ public:
   /// previously marked as declaretarget.
   ///
   /// \param D the declaration marked OpenMP declaretarget.
-  virtual void DeclarationMarkedOpenMPDeclareTarget(const Decl *D) {}
+  /// \param Attr the added attribute.
+  virtual void DeclarationMarkedOpenMPDeclareTarget(const Decl *D,
+const Attr *Attr) {}
 
   /// \brief A definition has been made visible by being redefined locally.
   ///

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=268925&r1=268924&r2=268925&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon May  9 09:59:13 2016
@@ -2345,8 +2345,17 @@ def OMPDeclareTargetDecl : Attr {
   let Spellings = [Pragma<"omp", "declare target">];
   let SemaHandler = 0;
   let Documentation = [OMPDeclareTargetDocs];
+  let Args = [
+EnumArgument<"MapType", "MapTypeTy",
+ [ "to", "link" ],
+ [ "MT_To", "MT_Link" ]>
+  ];
   let AdditionalMembers = [{
-void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) 
const {}
+void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) 
const {
+  // Use fake syntax because it is for testing and debugging purpose only.
+  if (getMapType() != MT_To)
+OS << ConvertMapTypeTyToStr(getMapType()) << " ";
+}
   }];
 }
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=268925&r1=268924&r2=268925&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Mon May  9 09:59:13 
2016
@@ -967,6 +967,8 @@ def err_omp_declare_simd_inbranch_notinb
   "unexpected '%0' clause, '%1' is specified already">;
 def err_expected_end_declare_target : Error<
   "expected '#pragma omp end declare target'">;
+def err_omp_declare_target_unexpected_clause: Error<
+  "unexpected '%0' clause, only 'to' or 'link' clauses expected">;
 
 // Pragma loop support.
 def err_pragma_loop_missing_argument : Error<

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=268925&r1=268924&r2=268925&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon May  9 09:59:13 
2016
@@ -7984,6 +7984,12 @@ def warn_omp_alignment_not_power_of_two
   InGroup;
 def err_omp_enclosed_declare_target : Error<
   "declare target region may not be enclosed within another declare target 
region">;
+def err_omp_invalid_target_decl : Error<
+  "%0 used in declare target directive is not a variable or a function name">;
+def err_omp_declare_target_multiple : Error<
+  "%0 appears multiple times in clauses on the same declare target directive">;
+def err_omp_declare_target_to_and_link : Error<
+  "%0 must not ap

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

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

Richard, friendly ping. It seems that your counterexample cause no issue with 
this patch. I added tests to prove it. Could you please take another look?


http://reviews.llvm.org/D18035



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


r269400 - [ms][dll] #27212: Generating of implicit special members should take into account MSVC compatibility version

2016-05-13 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Fri May 13 04:03:56 2016
New Revision: 269400

URL: http://llvm.org/viewvc/llvm-project?rev=269400&view=rev
Log:
[ms][dll] #27212: Generating of implicit special members should take into 
account MSVC compatibility version

Clang creates implicit move constructor/assign operator in all cases if
there is std=c++11. But MSVC supports such generation starting from
version 1900 only. As result we have some binary incompatibility.

Differential Revision: http://reviews.llvm.org/D19156

Patch by Andrew V. Tischenko

Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.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=269400&r1=269399&r2=269400&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri May 13 04:03:56 2016
@@ -4774,7 +4774,6 @@ void Sema::checkClassLevelDLLAttribute(C
 
   // The class is either imported or exported.
   const bool ClassExported = ClassAttr->getKind() == attr::DLLExport;
-  const bool ClassImported = !ClassExported;
 
   TemplateSpecializationKind TSK = Class->getTemplateSpecializationKind();
 
@@ -4809,9 +4808,12 @@ void Sema::checkClassLevelDLLAttribute(C
 if (!Context.getTargetInfo().getCXXABI().isMicrosoft())
   continue;
 
-// MSVC versions before 2015 don't export the move assignment 
operators,
-// so don't attempt to import them if we have a definition.
-if (ClassImported && MD->isMoveAssignmentOperator() &&
+// 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);
+if ((MD->isMoveAssignmentOperator() ||
+ (CXXC && CXXC->isMoveConstructor())) &&
 !getLangOpts().isCompatibleWithMSVC(LangOptions::MSVC2015))
   continue;
   }

Modified: cfe/trunk/test/CodeGenCXX/dllexport.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllexport.cpp?rev=269400&r1=269399&r2=269400&view=diff
==
--- cfe/trunk/test/CodeGenCXX/dllexport.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllexport.cpp Fri May 13 04:03:56 2016
@@ -1,5 +1,9 @@
-// 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 | FileCheck --check-prefix=MSC 
--check-prefix=M32 %s
-// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm -std=c++1y 
-fno-threadsafe-statics -fms-extensions -O0 -o - %s -w | FileCheck 
--check-prefix=MSC --check-prefix=M64 %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 %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 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 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
 
@@ -528,6 +532,8 @@ struct SomeTemplate {
   SomeTemplate(T o = T()) : o(o) {}
   T o;
 };
+// MSVC2015-DAG: define weak_odr dllexport {{.+}} 
@"\01??4?$SomeTemplate@H@@Q{{.+}}@$$Q{{.+}}@@Z"
+// MSVC2013-DAG: define weak_odr dllexport {{.+}} 
@"\01??4?$SomeTemplate@H@@Q{{.+}}0@A{{.+}}0@@Z"
 struct __declspec(dllexport) InheritFromTemplate : SomeTemplate {};
 
 // M32-DAG: define weak_odr dllexport x86_thiscallcc void 
@"\01??_F?$SomeTemplate@H@@QAEXXZ"({{.*}}) {{#[0-9]+}} comdat
@@ -616,7 +622,8 @@ struct __declspec(dllexport) X : public
 
 struct __declspec(dllexport) Y {
   // Move assignment operator:
-  // M32-DAG: define weak_odr dllexport x86_thiscallcc 
dereferenceable({{[0-9]+}}) %stru

Re: [PATCH] D19156: [ms][dll] #27212: Generating of implicit special members should take into account MSVC compatibility version

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

Committed as http://reviews.llvm.org/rL269400


http://reviews.llvm.org/D19156



___
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-19 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin added a comment.

One more friendly ping.. :(


http://reviews.llvm.org/D18035



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


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

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

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.


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.Ex

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

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

Comments resolved, PTAL.


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* @"\01??0ExportDefaultedInclassDefs@@QEAA@XZ"(%struct.ExportDefaultedInclassDefs* returned %this)
+
+  ~ExportDefaultedInclassDefs() = default;
+  // M32VS201

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


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

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

Friendly ping, please take a look!


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] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

2016-03-30 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 52070.
DmitryPolukhin added a comment.

- Added test for templates in declare target region


http://reviews.llvm.org/D18542

Files:
  include/clang/AST/ASTMutationListener.h
  include/clang/AST/Attr.h
  include/clang/Basic/Attr.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/OpenMPKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTWriter.h
  lib/AST/ASTContext.cpp
  lib/AST/DeclPrinter.cpp
  lib/Basic/OpenMPKinds.cpp
  lib/Frontend/MultiplexConsumer.cpp
  lib/Parse/ParseOpenMP.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Serialization/ASTCommon.h
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/OpenMP/declare_target_ast_print.cpp
  test/OpenMP/declare_target_messages.cpp
  utils/TableGen/ClangAttrEmitter.cpp

Index: utils/TableGen/ClangAttrEmitter.cpp
===
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -30,28 +30,32 @@
 
 namespace {
 class FlattenedSpelling {
-  std::string V, N, NS;
+  std::string V, N, NS, E;
   bool K;
 
 public:
   FlattenedSpelling(const std::string &Variety, const std::string &Name,
-const std::string &Namespace, bool KnownToGCC) :
-V(Variety), N(Name), NS(Namespace), K(KnownToGCC) {}
+const std::string &Namespace, const std::string &Ending,
+bool KnownToGCC) :
+V(Variety), N(Name), NS(Namespace), E(Ending), K(KnownToGCC) {}
   explicit FlattenedSpelling(const Record &Spelling) :
 V(Spelling.getValueAsString("Variety")),
 N(Spelling.getValueAsString("Name")) {
 
 assert(V != "GCC" && "Given a GCC spelling, which means this hasn't been"
"flattened!");
 if (V == "CXX11" || V == "Pragma")
   NS = Spelling.getValueAsString("Namespace");
+if (V == "Pragma")
+  E = Spelling.getValueAsString("Ending");
 bool Unset;
 K = Spelling.getValueAsBitOrUnset("KnownToGCC", Unset);
   }
 
   const std::string &variety() const { return V; }
   const std::string &name() const { return N; }
   const std::string &nameSpace() const { return NS; }
+  const std::string &ending() const { return E; }
   bool knownToGCC() const { return K; }
 };
 } // end anonymous namespace
@@ -64,8 +68,8 @@
   for (const auto &Spelling : Spellings) {
 if (Spelling->getValueAsString("Variety") == "GCC") {
   // Gin up two new spelling objects to add into the list.
-  Ret.emplace_back("GNU", Spelling->getValueAsString("Name"), "", true);
-  Ret.emplace_back("CXX11", Spelling->getValueAsString("Name"), "gnu",
+  Ret.emplace_back("GNU", Spelling->getValueAsString("Name"), "", "", true);
+  Ret.emplace_back("CXX11", Spelling->getValueAsString("Name"), "gnu", "",
true);
 } else
   Ret.push_back(FlattenedSpelling(*Spelling));
@@ -1259,6 +1263,63 @@
   OS << "}\n\n";
 }
 
+// Determines if an attribute has a Pragma spelling.
+static bool AttrHasPragmaSpelling(const Record *R) {
+  std::vector Spellings = GetFlattenedSpellings(*R);
+  return std::find_if(Spellings.begin(), Spellings.end(),
+  [](const FlattenedSpelling &S) {
+   return S.variety() == "Pragma";
+ }) != Spellings.end();
+}
+
+static void
+writePrettyPrintEndFunction(Record &R,
+const std::vector> &Args,
+raw_ostream &OS) {
+  std::vector Spellings = GetFlattenedSpellings(R);
+
+  OS << "void " << R.getName() << "Attr::printPrettyEnd("
+<< "raw_ostream &OS, const PrintingPolicy &Policy) const {\n";
+
+  if (!AttrHasPragmaSpelling(&R)) {
+OS << "}\n\n";
+return;
+  }
+
+  OS <<
+"  switch (SpellingListIndex) {\n"
+"  default:\n"
+"llvm_unreachable(\"Unknown attribute spelling!\");\n"
+"break;\n";
+
+  for (unsigned I = 0; I < Spellings.size(); ++ I) {
+if (Spellings[I].variety() != "Pragma")
+  continue;
+
+OS << "  case " << I << " : {\n";
+std::string Ending = Spellings[I].ending();
+if (!Ending.empty()) {
+  llvm::SmallString<64> Spelling;
+  std::string Namespace = Spellings[I].nameSpace();
+  if (!Namespace.empty()) {
+Spelling += Namespace;
+Spelling += " ";
+  }
+  Spelling += Ending;
+
+  OS << "OS << \"#pragma "  << Spelling << "\\n\";\n";
+
+}
+OS << "break;\n";
+OS << "  }\n";
+  }
+
+  // End of the switch statement.
+  OS << "}\n";
+  // End of the print function.
+  OS << "}\n\n";
+}
+
 /// \brief Return the index of a spelling in a spelling list.
 static unsigned
 getSpellingListIndex(const std::vector &SpellingList,
@@ -1642,6 +1703,8 @@
 OS << "  " << R.getName() << "Attr *clone(ASTContext &C) const;\n"

Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

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

Aaron,

Could you please take a look to OMPDeclareTargetDecl attribute implementation 
and printPrettyEnd approach in general?
For post print mechanism alternative approach is to use ad hoc solution in 
DeclPrinter.

Thanks,
Dmitry

Software Engineer
Intel Compiler Team


http://reviews.llvm.org/D18542



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


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

2016-03-31 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin created this revision.
DmitryPolukhin added a reviewer: rsmith.
DmitryPolukhin added a subscriber: cfe-commits.

GCC clears current search position in the include directories list used
for #include_next if current header was found using relative paths.
Before this patch Clang kept current position from previous header
included from directories list. Both approaches make sense but I thin it
is better to be GCC compatible in this question. See added test-case for
the example.

Also update warning text to give better understanding what happened.
Previous one about absolute path was incorrect and confusing.

http://reviews.llvm.org/D18641

Files:
  include/clang/Basic/DiagnosticLexKinds.td
  lib/Lex/HeaderSearch.cpp
  lib/Lex/PPDirectives.cpp
  lib/Lex/PPMacroExpansion.cpp
  test/Modules/Inputs/include_next/x/d.h
  test/Modules/Inputs/include_next/y/c.h
  test/Modules/Inputs/include_next/y/d.h
  test/Modules/include_next.c

Index: test/Modules/include_next.c
===
--- test/Modules/include_next.c
+++ test/Modules/include_next.c
@@ -2,10 +2,14 @@
 // RUN: %clang_cc1 -I%S/Inputs/include_next/x -I%S/Inputs/include_next/y -verify %s
 // RUN: %clang_cc1 -I%S/Inputs/include_next/x -I%S/Inputs/include_next/y -verify %s -fmodules -fimplicit-module-maps -fmodules-cache-path=%t
 
-// expected-no-diagnostics
 #include "a.h"
 #include "subdir/b.h"
+#include 
+
 _Static_assert(ax == 1, "");
 _Static_assert(ay == 2, "");
 _Static_assert(bx == 3, "");
 _Static_assert(by == 4, "");
+_Static_assert(cy == 5, "");
+_Static_assert(dy == 6, "");
+_Static_assert(dx == 7, "");
Index: test/Modules/Inputs/include_next/y/d.h
===
--- /dev/null
+++ test/Modules/Inputs/include_next/y/d.h
@@ -0,0 +1,3 @@
+#include_next 
+// expected-warning@-1 {{#include_next without previous state, searching from the beginning of the include directories list}}
+enum { dy = 6 };
Index: test/Modules/Inputs/include_next/y/c.h
===
--- /dev/null
+++ test/Modules/Inputs/include_next/y/c.h
@@ -0,0 +1,2 @@
+#include "d.h"
+enum { cy = 5 };
Index: test/Modules/Inputs/include_next/x/d.h
===
--- /dev/null
+++ test/Modules/Inputs/include_next/x/d.h
@@ -0,0 +1 @@
+enum { dx = 7 };
Index: lib/Lex/PPMacroExpansion.cpp
===
--- lib/Lex/PPMacroExpansion.cpp
+++ lib/Lex/PPMacroExpansion.cpp
@@ -1415,7 +1415,7 @@
 LookupFromFile = PP.getCurrentLexer()->getFileEntry();
 Lookup = nullptr;
   } else if (!Lookup) {
-PP.Diag(Tok, diag::pp_include_next_absolute_path);
+PP.Diag(Tok, diag::pp_include_next_without_state);
   } else {
 // Start looking up in the next directory.
 ++Lookup;
Index: lib/Lex/PPDirectives.cpp
===
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1841,7 +1841,7 @@
 LookupFromFile = CurPPLexer->getFileEntry();
 Lookup = nullptr;
   } else if (!Lookup) {
-Diag(IncludeNextTok, diag::pp_include_next_absolute_path);
+Diag(IncludeNextTok, diag::pp_include_next_without_state);
   } else {
 // Start looking up in the next directory.
 ++Lookup;
Index: lib/Lex/HeaderSearch.cpp
===
--- lib/Lex/HeaderSearch.cpp
+++ lib/Lex/HeaderSearch.cpp
@@ -569,11 +569,13 @@
 bool SkipCache) {
   if (SuggestedModule)
 *SuggestedModule = ModuleMap::KnownHeader();
-
+
+  // Reset CurDir for subsequent include_next searches. It needs to be done in
+  // both cases absolute patch and ""-include, GCC does the same.
+  CurDir = nullptr;
+
   // If 'Filename' is absolute, check to see if it exists and no searching.
   if (llvm::sys::path::is_absolute(Filename)) {
-CurDir = nullptr;
-
 // If this was an #include_next "/absolute/file", fail.
 if (FromDir) return nullptr;
 
@@ -673,8 +675,6 @@
 }
   }
 
-  CurDir = nullptr;
-
   // If this is a system #include, ignore the user #include locs.
   unsigned i = isAngled ? AngledDirIdx : 0;
 
Index: include/clang/Basic/DiagnosticLexKinds.td
===
--- include/clang/Basic/DiagnosticLexKinds.td
+++ include/clang/Basic/DiagnosticLexKinds.td
@@ -265,8 +265,8 @@
   InGroup>;
 def pp_include_macros_out_of_predefines : Error<
   "the #__include_macros directive is only for internal use by -imacros">;
-def pp_include_next_absolute_path : Warning<
-  "#include_next with absolute path">,
+def pp_include_next_without_state : Warning<
+  "#include_next without previous state, searching from the beginning of the include directories list">,
   InGroup>;
 def ext_c99_whitespace_required_after_macro_name : ExtWarn<
   "ISO C99 requires whitespace after the macro name

r265123 - [OPENMP] Avoid useless recursive calls in getDSA if it is called in a loop, NFC

2016-04-01 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Fri Apr  1 04:52:30 2016
New Revision: 265123

URL: http://llvm.org/viewvc/llvm-project?rev=265123&view=rev
Log:
[OPENMP] Avoid useless recursive calls in getDSA if it is called in a loop, NFC

Modified:
cfe/trunk/lib/Sema/SemaOpenMP.cpp

Modified: cfe/trunk/lib/Sema/SemaOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOpenMP.cpp?rev=265123&r1=265122&r2=265123&view=diff
==
--- cfe/trunk/lib/Sema/SemaOpenMP.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOpenMP.cpp Fri Apr  1 04:52:30 2016
@@ -141,7 +141,7 @@ private:
 
   typedef SmallVector::reverse_iterator reverse_iterator;
 
-  DSAVarData getDSA(StackTy::reverse_iterator Iter, ValueDecl *D);
+  DSAVarData getDSA(StackTy::reverse_iterator& Iter, ValueDecl *D);
 
   /// \brief Checks if the variable is a local for OpenMP region.
   bool isOpenMPLocal(VarDecl *D, StackTy::reverse_iterator Iter);
@@ -396,7 +396,7 @@ static ValueDecl *getCanonicalDecl(Value
   return D;
 }
 
-DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter,
+DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator& Iter,
   ValueDecl *D) {
   D = getCanonicalDecl(D);
   auto *VD = dyn_cast(D);
@@ -505,7 +505,7 @@ DSAStackTy::DSAVarData DSAStackTy::getDS
   //  For constructs other than task, if no default clause is present, these
   //  variables inherit their data-sharing attributes from the enclosing
   //  context.
-  return getDSA(std::next(Iter), D);
+  return getDSA(++Iter, D);
 }
 
 Expr *DSAStackTy::addUniqueAligned(ValueDecl *D, Expr *NewDE) {
@@ -722,7 +722,7 @@ DSAStackTy::DSAVarData DSAStackTy::hasDS
   bool FromParent) {
   D = getCanonicalDecl(D);
   auto StartI = std::next(Stack.rbegin());
-  auto EndI = std::prev(Stack.rend());
+  auto EndI = Stack.rend();
   if (FromParent && StartI != EndI) {
 StartI = std::next(StartI);
   }
@@ -742,7 +742,7 @@ DSAStackTy::hasInnermostDSA(ValueDecl *D
 DirectivesPredicate DPred, bool FromParent) {
   D = getCanonicalDecl(D);
   auto StartI = std::next(Stack.rbegin());
-  auto EndI = std::prev(Stack.rend());
+  auto EndI = Stack.rend();
   if (FromParent && StartI != EndI) {
 StartI = std::next(StartI);
   }


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


Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

2016-04-01 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 52349.
DmitryPolukhin marked an inline comment as done.
DmitryPolukhin added a comment.

- implemented ad hoc solution for printing
- added documentation for the attrbute
- reabse

In http://reviews.llvm.org/D18542#388241, @aaron.ballman wrote:

> If you don't feel like doing all that design work (which I'm not attempting 
> to sign you up for!), I think the ad hoc solution may be preferable to the 
> proposed approach. Do you intend to add several more pragmas that need this 
> same sort of behavior, or is this a one-off?


I don't expect more pragmas like declare target and grouping mechanism design 
might be overkill for my case. So I implemented ad hoc solution that is much 
shorter. PTAL!


http://reviews.llvm.org/D18542

Files:
  include/clang/AST/ASTMutationListener.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/OpenMPKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTWriter.h
  lib/AST/ASTContext.cpp
  lib/AST/DeclPrinter.cpp
  lib/Basic/OpenMPKinds.cpp
  lib/Frontend/MultiplexConsumer.cpp
  lib/Parse/ParseOpenMP.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Serialization/ASTCommon.h
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/OpenMP/declare_target_ast_print.cpp
  test/OpenMP/declare_target_messages.cpp

Index: test/OpenMP/declare_target_messages.cpp
===
--- /dev/null
+++ test/OpenMP/declare_target_messages.cpp
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - %s
+
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+
+int a, b; // expected-warning {{declaration is not declared in any declare target region}}
+__thread int t; // expected-note {{defined as threadprivate or thread local}}
+#pragma omp declare target private(a) // expected-warning {{extra tokens at the end of '#pragma omp declare target' are ignored}}
+void f();
+#pragma omp end declare target shared(a) // expected-warning {{extra tokens at the end of '#pragma omp end declare target' are ignored}}
+void c(); // expected-warning {{declaration is not declared in any declare target region}}
+
+extern int b;
+
+struct NonT {
+  int a;
+};
+
+typedef int sint;
+
+#pragma omp declare target // expected-note {{to match this '#pragma omp declare target'}}
+#pragma omp threadprivate(a) // expected-note {{defined as threadprivate or thread local}}
+extern int b;
+int g;
+
+struct T { // expected-note {{mappable type cannot be polymorphic}}
+  int a;
+  virtual int method();
+};
+
+class VC { // expected-note {{mappable type cannot be polymorphic}}
+  T member;
+  NonT member1;
+  public:
+virtual int method() { T a; return 0; } // expected-error {{type 'T' is not mappable to target}}
+};
+
+struct C {
+  NonT a;
+  sint b;
+  int method();
+  int method1();
+};
+
+int C::method1() {
+  return 0;
+}
+
+void foo() {
+  a = 0; // expected-error {{threadprivate variables cannot be used in target constructs}}
+  b = 0; // expected-note {{used here}}
+  t = 1; // expected-error {{threadprivate variables cannot be used in target constructs}}
+  C object;
+  VC object1; // expected-error {{type 'VC' is not mappable to target}}
+  g = object.method();
+  g += object.method1();
+  g += object1.method();
+  f();
+  c(); // expected-note {{used here}}
+}
+#pragma omp declare target // expected-error {{expected '#pragma omp end declare target'}}
+void foo1() {}
+#pragma omp end declare target
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+
+int C::method() {
+  return 0;
+}
+
+struct S {
+#pragma omp declare target // expected-error {{directive must be at file or namespace scope}}
+  int v;
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+};
+
+int main (int argc, char **argv) {
+#pragma omp declare target // expected-error {{unexpected OpenMP directive '#pragma omp declare target'}}
+  int v;
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+  foo();
+  return (0);
+}
+
+namespace {
+#pragma omp declare target // expected-note {{to match this '#pragma omp declare target'}}
+  int x;
+} //  expected-error {{expected '#pragma omp end declare target'}}
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+
+#pragma omp declare target // expected-error {{expected '#pragma omp end declare target'}} expected-note {{to match this '#pragma omp declare targe

Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

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

Alexey, please review OpenMP specific things.

Aaron, are you OK with the attribute implementation and printing approach?


http://reviews.llvm.org/D18542



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


Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

2016-04-05 Thread Dmitry Polukhin via cfe-commits
DmitryPolukhin updated this revision to Diff 52690.
DmitryPolukhin marked 8 inline comments as done.
DmitryPolukhin added a comment.

- fixed all comments
- rebase

Aaron and Alexey, thank you for the review!


http://reviews.llvm.org/D18542

Files:
  include/clang/AST/ASTMutationListener.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/OpenMPKinds.def
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTWriter.h
  lib/AST/ASTContext.cpp
  lib/AST/DeclPrinter.cpp
  lib/Basic/OpenMPKinds.cpp
  lib/Frontend/MultiplexConsumer.cpp
  lib/Parse/ParseOpenMP.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOpenMP.cpp
  lib/Serialization/ASTCommon.h
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/OpenMP/declare_target_ast_print.cpp
  test/OpenMP/declare_target_messages.cpp

Index: test/OpenMP/declare_target_messages.cpp
===
--- /dev/null
+++ test/OpenMP/declare_target_messages.cpp
@@ -0,0 +1,89 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macos10.7.0 -verify -fopenmp -fnoopenmp-use-tls -ferror-limit 100 -o - %s
+
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+
+int a, b; // expected-warning {{declaration is not declared in any declare target region}}
+__thread int t; // expected-note {{defined as threadprivate or thread local}}
+#pragma omp declare target private(a) // expected-warning {{extra tokens at the end of '#pragma omp declare target' are ignored}}
+void f();
+#pragma omp end declare target shared(a) // expected-warning {{extra tokens at the end of '#pragma omp end declare target' are ignored}}
+void c(); // expected-warning {{declaration is not declared in any declare target region}}
+
+extern int b;
+
+struct NonT {
+  int a;
+};
+
+typedef int sint;
+
+#pragma omp declare target // expected-note {{to match this '#pragma omp declare target'}}
+#pragma omp threadprivate(a) // expected-note {{defined as threadprivate or thread local}}
+extern int b;
+int g;
+
+struct T { // expected-note {{mappable type cannot be polymorphic}}
+  int a;
+  virtual int method();
+};
+
+class VC { // expected-note {{mappable type cannot be polymorphic}}
+  T member;
+  NonT member1;
+  public:
+virtual int method() { T a; return 0; } // expected-error {{type 'T' is not mappable to target}}
+};
+
+struct C {
+  NonT a;
+  sint b;
+  int method();
+  int method1();
+};
+
+int C::method1() {
+  return 0;
+}
+
+void foo() {
+  a = 0; // expected-error {{threadprivate variables cannot be used in target constructs}}
+  b = 0; // expected-note {{used here}}
+  t = 1; // expected-error {{threadprivate variables cannot be used in target constructs}}
+  C object;
+  VC object1; // expected-error {{type 'VC' is not mappable to target}}
+  g = object.method();
+  g += object.method1();
+  g += object1.method();
+  f();
+  c(); // expected-note {{used here}}
+}
+#pragma omp declare target // expected-error {{expected '#pragma omp end declare target'}}
+void foo1() {}
+#pragma omp end declare target
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+
+int C::method() {
+  return 0;
+}
+
+struct S {
+#pragma omp declare target // expected-error {{directive must be at file or namespace scope}}
+  int v;
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+};
+
+int main (int argc, char **argv) {
+#pragma omp declare target // expected-error {{unexpected OpenMP directive '#pragma omp declare target'}}
+  int v;
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+  foo();
+  return (0);
+}
+
+namespace {
+#pragma omp declare target // expected-note {{to match this '#pragma omp declare target'}}
+  int x;
+} //  expected-error {{expected '#pragma omp end declare target'}}
+#pragma omp end declare target // expected-error {{unexpected OpenMP directive '#pragma omp end declare target'}}
+
+#pragma omp declare target // expected-error {{expected '#pragma omp end declare target'}} expected-note {{to match this '#pragma omp declare target'}}
Index: test/OpenMP/declare_target_ast_print.cpp
===
--- /dev/null
+++ test/OpenMP/declare_target_ast_print.cpp
@@ -0,0 +1,93 @@
+// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
+// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -fsyntax-only -verify %s -ast-print | FileCheck %s
+// expected-no-diagnostics
+
+#ifndef HEADER
+#define HEADER
+
+#pragma omp declare target
+// CHECK: 

r265530 - [OPENMP] Parsing and Sema support for 'omp declare target' directive

2016-04-06 Thread Dmitry Polukhin via cfe-commits
Author: dpolukhin
Date: Wed Apr  6 06:38:59 2016
New Revision: 265530

URL: http://llvm.org/viewvc/llvm-project?rev=265530&view=rev
Log:
[OPENMP] Parsing and Sema support for 'omp declare target' directive

Add parsing, sema analysis for 'declare target' construct for OpenMP 4.0
(4.5 support will be added in separate patch).

The declare target directive specifies that variables, functions (C, C++
and Fortran), and subroutines (Fortran) are mapped to a device. The declare
target directive is a declarative directive. In Clang declare target is
implemented as implicit attribute for the declaration.

The syntax of the declare target directive is as follows:

 #pragma omp declare target
 declarations-definition-seq
 #pragma omp end declare target

Based on patch from Michael Wong http://reviews.llvm.org/D15321

Added:
cfe/trunk/test/OpenMP/declare_target_ast_print.cpp   (with props)
cfe/trunk/test/OpenMP/declare_target_messages.cpp   (with props)
Modified:
cfe/trunk/include/clang/AST/ASTMutationListener.h
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Basic/OpenMPKinds.def
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTWriter.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/DeclPrinter.cpp
cfe/trunk/lib/Basic/OpenMPKinds.cpp
cfe/trunk/lib/Frontend/MultiplexConsumer.cpp
cfe/trunk/lib/Parse/ParseOpenMP.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Serialization/ASTCommon.h
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/ASTMutationListener.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTMutationListener.h?rev=265530&r1=265529&r2=265530&view=diff
==
--- cfe/trunk/include/clang/AST/ASTMutationListener.h (original)
+++ cfe/trunk/include/clang/AST/ASTMutationListener.h Wed Apr  6 06:38:59 2016
@@ -107,6 +107,12 @@ public:
   /// \param D the declaration marked OpenMP threadprivate.
   virtual void DeclarationMarkedOpenMPThreadPrivate(const Decl *D) {}
 
+  /// \brief A declaration is marked as OpenMP declaretarget which was not
+  /// previously marked as declaretarget.
+  ///
+  /// \param D the declaration marked OpenMP declaretarget.
+  virtual void DeclarationMarkedOpenMPDeclareTarget(const Decl *D) {}
+
   /// \brief A definition has been made visible by being redefined locally.
   ///
   /// \param D The definition that was previously not visible.

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=265530&r1=265529&r2=265530&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Apr  6 06:38:59 2016
@@ -2276,6 +2276,15 @@ def OMPDeclareSimdDecl : Attr {
   }];
 }
 
+def OMPDeclareTargetDecl : Attr {
+  let Spellings = [Pragma<"omp", "declare target">];
+  let SemaHandler = 0;
+  let Documentation = [OMPDeclareTargetDocs];
+  let AdditionalMembers = [{
+void printPrettyPragma(raw_ostream &OS, const PrintingPolicy &Policy) 
const {}
+  }];
+}
+
 def InternalLinkage : InheritableAttr {
   let Spellings = [GNU<"internal_linkage">, CXX11<"clang", 
"internal_linkage">];
   let Subjects = SubjectList<[Var, Function, CXXRecord]>;

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=265530&r1=265529&r2=265530&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Wed Apr  6 06:38:59 2016
@@ -1941,6 +1941,23 @@ where clause is one of the following:
   }];
 }
 
+def OMPDeclareTargetDocs : Documentation {
+  let Category = DocCatFunction;
+  let Heading = "#pragma omp declare target";
+  let Content = [{
+The `declare target` directive specifies that variables and functions are 
mapped
+to a device for OpenMP offload mechanism.
+
+The syntax of the declare target directive is as follows:
+
+  .. code-block:: c
+
+  #pragma omp declare target new-line
+  declarations-definition-seq
+  #pragma omp end declare target new-line
+  }];
+}
+
 def NotTailCalledDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Dia

Re: [PATCH] D18542: [OPENMP] Parsing and Sema support for 'omp declare target' directive

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

Committed as http://reviews.llvm.org/rL265530


http://reviews.llvm.org/D18542



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


Re: [PATCH] D15524: [GCC] Attribute ifunc support in clang

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

- rebase after committing llvm patch


http://reviews.llvm.org/D15524

Files:
  include/clang/AST/DeclBase.h
  include/clang/Basic/Attr.td
  include/clang/Basic/AttrDocs.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/AST/Decl.cpp
  lib/AST/DeclBase.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenModule.h
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclAttr.cpp
  test/CodeGen/ifunc.c
  test/Sema/attr-alias-elf.c
  test/Sema/attr-ifunc.c

Index: test/Sema/attr-ifunc.c
===
--- /dev/null
+++ test/Sema/attr-ifunc.c
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple x86_64-windows -fsyntax-only -verify %s
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm -DCHECK_ALIASES %s
+// RUN: %clang_cc1 -triple x86_64-linux -fsyntax-only -verify -emit-llvm %s
+
+#if defined(_WIN32)
+void foo() {}
+void bar() __attribute__((ifunc("foo")));
+//expected-warning@-1 {{'ifunc' attribute ignored}}
+
+#else
+#if defined(CHECK_ALIASES)
+void* f1_ifunc();
+void f1() __attribute__((ifunc("f1_ifunc")));
+//expected-error@-1 {{ifunc must point to a defined function}}
+
+void* f2_a() __attribute__((ifunc("f2_b")));
+//expected-error@-1 {{ifunc definition is part of a cycle}}
+void* f2_b() __attribute__((ifunc("f2_a")));
+//expected-error@-1 {{ifunc definition is part of a cycle}}
+
+void* f3_a() __attribute__((ifunc("f3_b")));
+//expected-warning@-1 {{ifunc will always resolve to f3_c even if weak definition of f3_b is overridden}}
+void* f3_b() __attribute__((weak, alias("f3_c")));
+void* f3_c() { return 0; }
+
+void f4_ifunc() {}
+void f4() __attribute__((ifunc("f4_ifunc")));
+//expected-error@-1 {{ifunc resolver function must return a pointer}}
+
+void* f5_ifunc(int i) { return 0; }
+void f5() __attribute__((ifunc("f5_ifunc")));
+//expected-error@-1 {{ifunc resolver function must have no parameters}}
+
+#else
+void f1a() __asm("f1");
+void f1a() {}
+//expected-note@-1 {{previous definition is here}}
+void f1() __attribute__((ifunc("f1_ifunc")));
+//expected-error@-1 {{definition with same mangled name as another definition}}
+void* f1_ifunc() { return 0; }
+
+#endif
+#endif
Index: test/Sema/attr-alias-elf.c
===
--- test/Sema/attr-alias-elf.c
+++ test/Sema/attr-alias-elf.c
@@ -55,7 +55,7 @@
 
 void test2_bar() {}
 void test2_foo() __attribute__((weak, alias("test2_bar")));
-void test2_zed() __attribute__((alias("test2_foo"))); // expected-warning {{alias will always resolve to test2_bar even if weak definition of alias test2_foo is overridden}}
+void test2_zed() __attribute__((alias("test2_foo"))); // expected-warning {{alias will always resolve to test2_bar even if weak definition of test2_foo is overridden}}
 
 void test3_bar() { }
 void test3_foo() __attribute__((section("test"))); // expected-warning {{alias will not be in section 'test' but in the same section as the aliasee}}
Index: test/CodeGen/ifunc.c
===
--- /dev/null
+++ test/CodeGen/ifunc.c
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -O2 -emit-llvm -o - %s | FileCheck %s
+
+int foo(int) __attribute__ ((ifunc("foo_ifunc")));
+
+static int f1(int i) {
+  return i + 1;
+}
+
+static int f2(int i) {
+  return i + 2;
+}
+
+typedef int (*foo_t)(int);
+
+int global;
+
+static foo_t foo_ifunc() {
+  return global ? f1 : f2;
+}
+
+int bar() {
+  return foo(1);
+}
+
+extern void goo(void);
+
+void bar2(void) {
+  goo();
+}
+
+extern void goo(void) __attribute__ ((ifunc("goo_ifunc")));
+
+void* goo_ifunc(void) {
+  return 0;
+}
+// CHECK: @foo = ifunc i32 (i32), bitcast (i32 (i32)* ()* @foo_ifunc to i32 (i32)*)
+// CHECK: @goo = ifunc void (), bitcast (i8* ()* @goo_ifunc to void ()*)
+
+// CHECK: call i32 @foo(i32
+// CHECK: call void @goo()
Index: lib/Sema/SemaDeclAttr.cpp
===
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -1548,6 +1548,28 @@
  Attr.getAttributeSpellingListIndex()));
 }
 
+static void handleIFuncAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+  StringRef Str;
+  if (!S.checkStringLiteralArgumentAttr(Attr, 0, Str))
+return;
+
+  // Aliases should be on declarations, not definitions.
+  const auto *FD = cast(D);
+  if (FD->isThisDeclarationADefinition()) {
+S.Diag(Attr.getLoc(), diag::err_alias_is_definition) << FD << 1;
+return;
+  }
+  // FIXME: it should be handled as a target specific attribute.
+  if (S.Context.getTargetInfo().getTriple().getObjectFormat() !=
+  llvm::Triple::ELF) {
+S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
+return;
+  }
+
+  D->addAttr(::new (S.Context) IFuncAttr(Attr.getRange

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

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

Richard, Reid and David,

Friendly ping, please take a look to this patch. If there are no more 
comments/suggestion, I think it is better to commit this patch iterate on GCC 
abi_tag support based on users' feedback.


http://reviews.llvm.org/D18035



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


  1   2   3   4   >