[PATCH] D44727: [RISCV] Extend getTargetDefines for RISCVTargetInfo

2018-03-28 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 140046.
kito-cheng retitled this revision from "[RISCV] Implement getTargetDefines, 
handleTargetFeatures and hasFeature for RISCVTargetInfo" to "[RISCV] Extend 
getTargetDefines for RISCVTargetInfo".
kito-cheng edited the summary of this revision.
kito-cheng added a comment.

Changes:

- Define __riscv_atomic, __riscv_flen, __riscv_fdiv and __riscv_fsqr, and add 
test for those marco.
- Handle riscv, riscv32 and riscv64 in RISCVTargetInfo::hasFeature.
- Fix several coding style issue.
- Breaking the long lines in test case.
- Add comment for RISCVTargetInfo::hasFeature.


Repository:
  rC Clang

https://reviews.llvm.org/D44727

Files:
  lib/Basic/Targets/RISCV.cpp
  lib/Basic/Targets/RISCV.h
  test/Preprocessor/riscv-target-features.c

Index: test/Preprocessor/riscv-target-features.c
===
--- /dev/null
+++ test/Preprocessor/riscv-target-features.c
@@ -0,0 +1,49 @@
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32i -x c -E -dM %s \
+// RUN: -o - | FileCheck %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64i -x c -E -dM %s \
+// RUN: -o - | FileCheck %s
+
+// CHECK-NOT: __riscv_div
+// CHECK-NOT: __riscv_mul
+// CHECK-NOT: __riscv_muldiv
+// CHECK-NOT: __riscv_compressed
+// CHECK-NOT: __riscv_flen
+// CHECK-NOT: __riscv_fdiv
+// CHECK-NOT: __riscv_fsqrt
+// CHECK-NOT: __riscv_atomic
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32im -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64im -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-M-EXT %s
+// CHECK-M-EXT: __riscv_div 1
+// CHECK-M-EXT: __riscv_mul 1
+// CHECK-M-EXT: __riscv_muldiv 1
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ia -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-A-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ia -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-A-EXT %s
+// CHECK-A-EXT: __riscv_atomic 1
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32if -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-F-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64if -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-F-EXT %s
+// CHECK-F-EXT: __riscv_fdiv 1
+// CHECK-F-EXT: __riscv_flen 32
+// CHECK-F-EXT: __riscv_fsqrt 1
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ifd -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-D-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ifd -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-D-EXT %s
+// CHECK-D-EXT: __riscv_fdiv 1
+// CHECK-D-EXT: __riscv_flen 64
+// CHECK-D-EXT: __riscv_fsqrt 1
+
+// RUN: %clang -target riscv32-unknown-linux-gnu -march=rv32ic -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
+// RUN: %clang -target riscv64-unknown-linux-gnu -march=rv64ic -x c -E -dM %s \
+// RUN: -o - | FileCheck --check-prefix=CHECK-C-EXT %s
+// CHECK-C-EXT: __riscv_compressed 1
Index: lib/Basic/Targets/RISCV.h
===
--- lib/Basic/Targets/RISCV.h
+++ lib/Basic/Targets/RISCV.h
@@ -26,10 +26,16 @@
 class RISCVTargetInfo : public TargetInfo {
 protected:
   std::string ABI;
+  bool HasM;
+  bool HasA;
+  bool HasF;
+  bool HasD;
+  bool HasC;
 
 public:
   RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
-  : TargetInfo(Triple) {
+  : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
+HasD(false), HasC(false) {
 TLSSupported = false;
 LongDoubleWidth = 128;
 LongDoubleAlign = 128;
@@ -59,6 +65,11 @@
  TargetInfo::ConstraintInfo &Info) const override {
 return false;
   }
+
+  bool hasFeature(StringRef Feature) const override;
+
+  bool handleTargetFeatures(std::vector &Features,
+DiagnosticsEngine &Diags) override;
 };
 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
 public:
Index: lib/Basic/Targets/RISCV.cpp
===
--- lib/Basic/Targets/RISCV.cpp
+++ lib/Basic/Targets/RISCV.cpp
@@ -49,4 +49,60 @@
   // TODO: modify when more code models and ABIs are supported.
   Builder.defineMacro("__riscv_cmodel_medlow");
   Builder.defineMacro("__riscv_float_abi_soft");
+
+  if (HasM) {
+Builder.defineMacro("__riscv_mul");
+Builder.defineMacro("__riscv_div");
+Builder.defineMacro("__riscv_muldiv");
+  }
+
+  if (HasC)
+Builder.defineMacro("__riscv_compressed");
+
+  if (HasD)
+Builder.defineMacro("__riscv_flen", "64");
+  else if (HasF)
+Builder.defineMacro("__riscv_flen", "32");
+
+  if (HasF || HasD) {
+Builder.defineMacro("__riscv_fdiv");
+Builder.defineMacro("__riscv_fsqrt");
+  }

[PATCH] D44189: [RISCV] Verify the input value of -march=

2018-03-28 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328690: [PATCH] [RISCV] Verify the input value of -march= 
(authored by shiva, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44189?vs=139256&id=140049#toc

Repository:
  rC Clang

https://reviews.llvm.org/D44189

Files:
  lib/Driver/ToolChains/Arch/RISCV.cpp
  test/Driver/riscv-arch.c

Index: lib/Driver/ToolChains/Arch/RISCV.cpp
===
--- lib/Driver/ToolChains/Arch/RISCV.cpp
+++ lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -24,32 +24,93 @@
std::vector &Features) {
   if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
 StringRef MArch = A->getValue();
-// TODO: handle rv64
-std::pair MArchSplit = StringRef(MArch).split("rv32");
-if (!MArchSplit.second.size())
+if (!(MArch.startswith("rv32") || MArch.startswith("rv64")) ||
+(MArch.size() < 5)) {
+  // ISA string must begin with rv32 or rv64.
+  // TODO: Improve diagnostic message.
+  D.Diag(diag::err_drv_invalid_arch_name) << MArch;
   return;
+}
 
-for (char c : MArchSplit.second) {
+// The canonical order specified in ISA manual.
+// Ref: Table 22.1 in RISC-V User-Level ISA V2.2
+StringRef StdExts = "mafdc";
+
+bool HasF = false, HasD = false;
+char Baseline = MArch[4];
+
+// TODO: Add 'e' once backend supported.
+switch (Baseline) {
+default:
+  // First letter should be 'e', 'i' or 'g'.
+  // TODO: Improve diagnostic message.
+  D.Diag(diag::err_drv_invalid_arch_name) << MArch;
+  return;
+case 'i':
+  break;
+case 'g':
+  // g = imafd
+  StdExts = StdExts.drop_front(4);
+  Features.push_back("+m");
+  Features.push_back("+a");
+  Features.push_back("+f");
+  Features.push_back("+d");
+  HasF = true;
+  HasD = true;
+  break;
+}
+
+auto StdExtsItr = StdExts.begin();
+// Skip rvxxx
+StringRef Exts = MArch.substr(5);
+
+for (char c : Exts) {
+  // Check ISA extensions are specified in the canonical order.
+  while (StdExtsItr != StdExts.end() && *StdExtsItr != c)
+++StdExtsItr;
+
+  if (StdExtsItr == StdExts.end()) {
+// TODO: Improve diagnostic message.
+D.Diag(diag::err_drv_invalid_arch_name) << MArch;
+return;
+  }
+
+  // Move to next char to prevent repeated letter.
+  ++StdExtsItr;
+
+  // The order is OK, then push it into features.
   switch (c) {
-  case 'i':
-break;
+  default:
+// TODO: Improve diagnostic message.
+D.Diag(diag::err_drv_invalid_arch_name) << MArch;
+return;
   case 'm':
 Features.push_back("+m");
 break;
   case 'a':
 Features.push_back("+a");
 break;
   case 'f':
 Features.push_back("+f");
+HasF = true;
 break;
   case 'd':
 Features.push_back("+d");
+HasD = true;
 break;
   case 'c':
 Features.push_back("+c");
 break;
   }
 }
+
+// Dependency check
+// It's illegal to specify the 'd' (double-precision floating point)
+// extension without also specifying the 'f' (single precision
+// floating-point) extension.
+// TODO: Improve diagnostic message.
+if (HasD && !HasF)
+  D.Diag(diag::err_drv_invalid_arch_name) << MArch;
   }
 }
 
Index: test/Driver/riscv-arch.c
===
--- test/Driver/riscv-arch.c
+++ test/Driver/riscv-arch.c
@@ -0,0 +1,89 @@
+// RUN: %clang -target riscv32-unknown-elf -march=rv32i -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32im -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ima -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imaf -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imafd -### %s -fsyntax-only 2>&1 | FileCheck %s
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ic -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imc -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imac -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imafc -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32imafdc -### %s -fsyntax-only 2>&1 | FileCheck %s
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ia -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32iaf -### %s -fsyntax-only 2>&1 | FileCheck %s
+// RUN: %clang -target riscv32-unknown-elf -march=rv32iafd -### %s -fsyntax-only 2>&1 | FileCheck %s

[PATCH] D44609: [Clang-Format] New option BreakBeforeLambdaBody to manage lambda line break inside function parameter call

2018-03-28 Thread Francois JEAN via Phabricator via cfe-commits
Wawha added a comment.

I do not know which reviewer to add for this review. Is it possible to give the 
name of the person that will be able to review this code ?


Repository:
  rC Clang

https://reviews.llvm.org/D44609



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


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

rjmccall wrote:
> I think doing this here can result in double-warning if the overload resolves 
> to a builtin operator.  Now, it might not actually be possible for that to 
> combine with the requirements for self-assignment, but still, I think the 
> right place to diagnose this for C++ is the same place we call 
> DiagnoseSelfMove in CreateOverloadedBinOp.
> 
> Can CheckIdentityFieldAssignment just be integrated with 
> DiagnoseSelfAssignment so that callers don't need to do call both?
> I think the right place to diagnose this for C++ is the same place we call 
> DiagnoseSelfMove in CreateOverloadedBinOp.

```
switch (Opc) {
case BO_Assign:
case BO_DivAssign:
case BO_SubAssign:
case BO_AndAssign:
case BO_OrAssign:
case BO_XorAssign:
  DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
  CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
  break;
default:
  break;
}

// Check for a self move.
if (Op == OO_Equal)
  DiagnoseSelfMove(Args[0], Args[1], OpLoc);
```


^ That does not appear to work. Pretty much all these tests start to fail.



Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44975: Change DEBUG() macro to LLVM_DEBUG()

2018-03-28 Thread Nicola Zaghen via Phabricator via cfe-commits
Nicola created this revision.
Herald added subscribers: cfe-commits, javed.absar, klimek.

The DEBUG() macro is too generic so it might clash with other projects.
This is going to be deprecated and replaced by LLVM_DEBUG() as soon as 
https://reviews.llvm.org/D43624 is submitted.

This is the command I used to do the replacement and formatting:
git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 
-style LLVM

I avoided replacing the clang-format strings that used DEBUG() as a macro.


Repository:
  rC Clang

https://reviews.llvm.org/D44975

Files:
  lib/AST/ExprConstant.cpp
  lib/Analysis/BodyFarm.cpp
  lib/CodeGen/ObjectFilePCHContainerOperations.cpp
  lib/Format/BreakableToken.cpp
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  lib/Format/SortJavaScriptImports.cpp
  lib/Format/TokenAnalyzer.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineFormatter.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UsingDeclarationsSorter.cpp
  lib/StaticAnalyzer/Core/CallEvent.cpp
  lib/StaticAnalyzer/Core/MemRegion.cpp
  lib/Tooling/Tooling.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestComments.cpp
  unittests/Format/FormatTestJS.cpp
  unittests/Format/FormatTestJava.cpp
  unittests/Format/FormatTestObjC.cpp
  unittests/Format/FormatTestProto.cpp
  unittests/Format/FormatTestRawStrings.cpp
  unittests/Format/FormatTestSelective.cpp
  unittests/Format/FormatTestTextProto.cpp
  unittests/Format/NamespaceEndCommentsFixerTest.cpp
  unittests/Format/UsingDeclarationsSorterTest.cpp
  unittests/libclang/LibclangTest.cpp

Index: unittests/libclang/LibclangTest.cpp
===
--- unittests/libclang/LibclangTest.cpp
+++ unittests/libclang/LibclangTest.cpp
@@ -466,15 +466,17 @@
 unsigned NumDiagnostics = clang_getNumDiagnostics(ClangTU);
 for (unsigned i = 0; i < NumDiagnostics; ++i) {
   auto Diag = clang_getDiagnostic(ClangTU, i);
-  DEBUG(llvm::dbgs() << clang_getCString(clang_formatDiagnostic(
-  Diag, clang_defaultDiagnosticDisplayOptions())) << "\n");
+  LLVM_DEBUG(llvm::dbgs()
+ << clang_getCString(clang_formatDiagnostic(
+Diag, clang_defaultDiagnosticDisplayOptions()))
+ << "\n");
   clang_disposeDiagnostic(Diag);
 }
   }
   bool ReparseTU(unsigned num_unsaved_files, CXUnsavedFile* unsaved_files) {
 if (clang_reparseTranslationUnit(ClangTU, num_unsaved_files, unsaved_files,
  clang_defaultReparseOptions(ClangTU))) {
-  DEBUG(llvm::dbgs() << "Reparse failed\n");
+  LLVM_DEBUG(llvm::dbgs() << "Reparse failed\n");
   return false;
 }
 DisplayDiagnostics();
Index: unittests/Format/UsingDeclarationsSorterTest.cpp
===
--- unittests/Format/UsingDeclarationsSorterTest.cpp
+++ unittests/Format/UsingDeclarationsSorterTest.cpp
@@ -23,13 +23,13 @@
   std::string sortUsingDeclarations(llvm::StringRef Code,
 const std::vector &Ranges,
 const FormatStyle &Style = getLLVMStyle()) {
-DEBUG(llvm::errs() << "---\n");
-DEBUG(llvm::errs() << Code << "\n\n");
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
 tooling::Replacements Replaces =
 clang::format::sortUsingDeclarations(Style, Code, Ranges, "");
 auto Result = applyAllReplacements(Code, Replaces);
 EXPECT_TRUE(static_cast(Result));
-DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
 return *Result;
   }
 
Index: unittests/Format/NamespaceEndCommentsFixerTest.cpp
===
--- unittests/Format/NamespaceEndCommentsFixerTest.cpp
+++ unittests/Format/NamespaceEndCommentsFixerTest.cpp
@@ -25,13 +25,13 @@
   fixNamespaceEndComments(llvm::StringRef Code,
   const std::vector &Ranges,
   const FormatStyle &Style = getLLVMStyle()) {
-DEBUG(llvm::errs() << "---\n");
-DEBUG(llvm::errs() << Code << "\n\n");
+LLVM_DEBUG(llvm::errs() << "---\n");
+LLVM_DEBUG(llvm::errs() << Code << "\n\n");
 tooling::Replacements Replaces =
 clang::format::fixNamespaceEndComments(Style, Code, Ranges, "");
 auto Result = applyAllReplacements(Code, Replaces);
 EXPECT_TRUE(static_cast(Result));
-DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
+LLVM_DEBUG(llvm::errs() << "\n" << *Result << "\n\n");
 return *Result;
   }
 
Index: unittests/Format/FormatTestTextProto.cpp
===
--- unittests/Format/FormatTestTextProto.cpp
+++ unittests/Format/FormatTestTextProto.cpp
@@ -21,13 +21,13 @@
 protec

[PATCH] D44976: Change DEBUG() macro to LLVM_DEBUG() in clang-tools-extra

2018-03-28 Thread Nicola Zaghen via Phabricator via cfe-commits
Nicola created this revision.
Herald added subscribers: cfe-commits, ioeric.

The DEBUG() macro is too generic so it might clash with other projects.
This is going to be deprecated and replaced by LLVM_DEBUG() as soon as 
https://reviews.llvm.org/D43624 is submitted.

This is the command I used to do the replacement and formatting:
git grep -l 'DEBUG' | xargs sed -i 's/\bDEBUG\s\?(/LLVM_DEBUG(/g'
git diff -U0 master | ../clang/tools/clang-format/clang-format-diff.py -i -p1 
-style LLVM


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44976

Files:
  clang-move/ClangMove.cpp
  clang-move/HelperDeclRefGraph.cpp
  clang-tidy/ClangTidyOptions.cpp
  clang-tidy/readability/IdentifierNamingCheck.cpp
  include-fixer/IncludeFixer.cpp
  include-fixer/SymbolIndexManager.cpp

Index: include-fixer/SymbolIndexManager.cpp
===
--- include-fixer/SymbolIndexManager.cpp
+++ include-fixer/SymbolIndexManager.cpp
@@ -97,8 +97,8 @@
   Symbols.insert(Symbols.end(), Res.begin(), Res.end());
 }
 
-DEBUG(llvm::dbgs() << "Searching " << Names.back() << "... got "
-   << Symbols.size() << " results...\n");
+LLVM_DEBUG(llvm::dbgs() << "Searching " << Names.back() << "... got "
+<< Symbols.size() << " results...\n");
 
 for (auto &SymAndSig : Symbols) {
   const SymbolInfo &Symbol = SymAndSig.Symbol;
Index: include-fixer/IncludeFixer.cpp
===
--- include-fixer/IncludeFixer.cpp
+++ include-fixer/IncludeFixer.cpp
@@ -156,7 +156,8 @@
   clang::ASTContext &context = CI->getASTContext();
   std::string QueryString = QualType(T->getUnqualifiedDesugaredType(), 0)
 .getAsString(context.getPrintingPolicy());
-  DEBUG(llvm::dbgs() << "Query missing complete type '" << QueryString << "'");
+  LLVM_DEBUG(llvm::dbgs() << "Query missing complete type '" << QueryString
+  << "'");
   // Pass an empty range here since we don't add qualifier in this case.
   std::vector MatchedSymbols =
   query(QueryString, "", tooling::Range());
@@ -276,7 +277,8 @@
 SymbolRange = CreateToolingRange(Typo.getLoc());
   }
 
-  DEBUG(llvm::dbgs() << "TypoScopeQualifiers: " << TypoScopeString << "\n");
+  LLVM_DEBUG(llvm::dbgs() << "TypoScopeQualifiers: " << TypoScopeString
+  << "\n");
   std::vector MatchedSymbols =
   query(QueryString, TypoScopeString, SymbolRange);
 
@@ -357,12 +359,12 @@
 return {};
   }
 
-  DEBUG(llvm::dbgs() << "Looking up '" << Query << "' at ");
-  DEBUG(CI->getSourceManager()
-.getLocForStartOfFile(CI->getSourceManager().getMainFileID())
-.getLocWithOffset(Range.getOffset())
-.print(llvm::dbgs(), CI->getSourceManager()));
-  DEBUG(llvm::dbgs() << " ...");
+  LLVM_DEBUG(llvm::dbgs() << "Looking up '" << Query << "' at ");
+  LLVM_DEBUG(CI->getSourceManager()
+ .getLocForStartOfFile(CI->getSourceManager().getMainFileID())
+ .getLocWithOffset(Range.getOffset())
+ .print(llvm::dbgs(), CI->getSourceManager()));
+  LLVM_DEBUG(llvm::dbgs() << " ...");
   llvm::StringRef FileName = CI->getSourceManager().getFilename(
   CI->getSourceManager().getLocForStartOfFile(
   CI->getSourceManager().getMainFileID()));
@@ -390,8 +392,8 @@
   if (MatchedSymbols.empty())
 MatchedSymbols =
 SymbolIndexMgr.search(Query, /*IsNestedSearch=*/true, FileName);
-  DEBUG(llvm::dbgs() << "Having found " << MatchedSymbols.size()
- << " symbols\n");
+  LLVM_DEBUG(llvm::dbgs() << "Having found " << MatchedSymbols.size()
+  << " symbols\n");
   // We store a copy of MatchedSymbols in a place where it's globally reachable.
   // This is used by the standalone version of the tool.
   this->MatchedSymbols = MatchedSymbols;
Index: clang-tidy/readability/IdentifierNamingCheck.cpp
===
--- clang-tidy/readability/IdentifierNamingCheck.cpp
+++ clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -836,10 +836,10 @@
 std::string Fixup = fixupWithStyle(Name, Style);
 if (StringRef(Fixup).equals(Name)) {
   if (!IgnoreFailedSplit) {
-DEBUG(llvm::dbgs()
-  << Decl->getLocStart().printToString(*Result.SourceManager)
-  << llvm::format(": unable to split words for %s '%s'\n",
-  KindName.c_str(), Name.str().c_str()));
+LLVM_DEBUG(llvm::dbgs()
+   << Decl->getLocStart().printToString(*Result.SourceManager)
+   << llvm::format(": unable to split words for %s '%s'\n",
+   KindName.c_str(), Name.str().c_str()));
   }
 } else {
   NamingCheckFailure &Failure = NamingCheckFailures[NamingCheckId(
@@ -873,10 +873,10 @@
   std::strin

[PATCH] D41938: [Analyzer] SValBuilder Comparison Rearrangement (with Restrictions and Analyzer Option)

2018-03-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 140061.
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added a comment.

Comment fixed.


https://reviews.llvm.org/D41938

Files:
  include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
  lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/conditional-path-notes.c
  test/Analysis/explain-svals.cpp
  test/Analysis/svalbuilder-rearrange-comparisons.c

Index: test/Analysis/svalbuilder-rearrange-comparisons.c
===
--- /dev/null
+++ test/Analysis/svalbuilder-rearrange-comparisons.c
@@ -0,0 +1,931 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=debug.ExprInspection,core.builtin -analyzer-config aggressive-relational-comparison-simplification=true -verify %s
+
+void clang_analyzer_dump(int x);
+void clang_analyzer_eval(int x);
+
+void exit(int);
+
+#define UINT_MAX (~0U)
+#define INT_MAX (UINT_MAX & (UINT_MAX >> 1))
+
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+unsigned int __line, __const char *__function)
+ __attribute__ ((__noreturn__));
+#define assert(expr) \
+  ((expr)  ? (void)(0)  : __assert_fail (#expr, __FILE__, __LINE__, __func__))
+
+int g();
+int f() {
+  int x = g();
+  // Assert that no overflows occur in this test file.
+  // Assuming that concrete integers are also within that range.
+  assert(x <= ((int)INT_MAX / 4));
+  assert(x >= -((int)INT_MAX / 4));
+  return x;
+}
+
+void compare_different_symbol_equal() {
+  int x = f(), y = f();
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$9{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$9{int})) == 0}}
+}
+
+void compare_different_symbol_plus_left_int_equal() {
+  int x = f()+1, y = f();
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$9{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$9{int}) - (conj_$2{int})) == 1}}
+}
+
+void compare_different_symbol_minus_left_int_equal() {
+  int x = f()-1, y = f();
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$9{int}}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$9{int})) == 1}}
+}
+
+void compare_different_symbol_plus_right_int_equal() {
+  int x = f(), y = f()+2;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$9{int}) + 2}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$9{int})) == 2}}
+}
+
+void compare_different_symbol_minus_right_int_equal() {
+  int x = f(), y = f()-2;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$9{int}) - 2}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$9{int}) - (conj_$2{int})) == 2}}
+}
+
+void compare_different_symbol_plus_left_plus_right_int_equal() {
+  int x = f()+2, y = f()+1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$9{int}) + 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$9{int}) - (conj_$2{int})) == 1}}
+}
+
+void compare_different_symbol_plus_left_minus_right_int_equal() {
+  int x = f()+2, y = f()-1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$9{int}) - 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$9{int}) - (conj_$2{int})) == 3}}
+}
+
+void compare_different_symbol_minus_left_plus_right_int_equal() {
+  int x = f()-2, y = f()+1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$9{int}) + 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$9{int})) == 3}}
+}
+
+void compare_different_symbol_minus_left_minus_right_int_equal() {
+  int x = f()-2, y = f()-1;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) - 2}}
+  clang_analyzer_dump(y); // expected-warning{{(conj_$9{int}) - 1}}
+  clang_analyzer_dump(x == y);
+  // expected-warning@-1{{((conj_$2{int}) - (conj_$9{int})) == 1}}
+}
+
+void compare_same_symbol_equal() {
+  int x = f(), y = x;
+  clang_analyzer_dump(x); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_eval(x == y);
+  // expected-warning@-1{{TRUE}}
+}
+
+void compare_same_symbol_plus_left_int_equal() {
+  int x = f(), y = x;
+  ++x;
+  clang_analyzer_dump(x); // expected-warning{{(conj_$2{int}) + 1}}
+  clang_analyzer_dump(y); // expected-warning{{conj_$2{int}}}
+  clang_analyzer_eval(x == y);
+  // expected-warning@-1{{

[PATCH] D44921: [PowerPC] Option for secure plt mode

2018-03-28 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic updated this revision to Diff 140060.

https://reviews.llvm.org/D44921

Files:
  include/clang/Driver/Options.td
  lib/Driver/ToolChains/Arch/PPC.cpp
  lib/Driver/ToolChains/Arch/PPC.h
  test/Driver/ppc-features.cpp


Index: test/Driver/ppc-features.cpp
===
--- test/Driver/ppc-features.cpp
+++ test/Driver/ppc-features.cpp
@@ -22,6 +22,10 @@
 // RUN: %clang -target powerpc-unknown-linux-gnu %s -msoft-float -mhard-float 
-### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTHARD %s
 // CHECK-SOFTHARD-NOT: "-target-feature" "-hard-float"
 
+// check -msecure-plt option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu -msecure-plt %s  -### -o %t.o 
2>&1 | FileCheck --check-prefix=CHECK-SECUREPLT %s
+// CHECK-SECUREPLT: "-target-feature" "+secure-plt"
+
 // check -mfloat-abi=x option
 // RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=x -### -o %t.o 
2>&1 | FileCheck --check-prefix=CHECK-ERRMSG %s
 // CHECK-ERRMSG: error: invalid float ABI '-mfloat-abi=x'
Index: lib/Driver/ToolChains/Arch/PPC.h
===
--- lib/Driver/ToolChains/Arch/PPC.h
+++ lib/Driver/ToolChains/Arch/PPC.h
@@ -29,10 +29,17 @@
   Hard,
 };
 
+enum class ReadGOTPtrMode {
+  Bss,
+  SecurePlt,
+};
+
 FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
 
 std::string getPPCTargetCPU(const llvm::opt::ArgList &Args);
 const char *getPPCAsmModeForCPU(StringRef Name);
+ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D,
+   const llvm::opt::ArgList &Args);
 
 void getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args,
Index: lib/Driver/ToolChains/Arch/PPC.cpp
===
--- lib/Driver/ToolChains/Arch/PPC.cpp
+++ lib/Driver/ToolChains/Arch/PPC.cpp
@@ -106,6 +106,16 @@
   ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
   if (FloatABI == ppc::FloatABI::Soft)
 Features.push_back("-hard-float");
+
+  ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Args);
+  if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
+Features.push_back("+secure-plt");
+}
+
+ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const ArgList 
&Args) {
+  if (Args.getLastArg(options::OPT_msecure_plt))
+return ppc::ReadGOTPtrMode::SecurePlt;
+  return ppc::ReadGOTPtrMode::Bss;
 }
 
 ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1938,6 +1938,7 @@
 def mno_altivec : Flag<["-"], "mno-altivec">, Group;
 def mvsx : Flag<["-"], "mvsx">, Group;
 def mno_vsx : Flag<["-"], "mno-vsx">, Group;
+def msecure_plt : Flag<["-"], "msecure-plt">, Group;
 def mpower8_vector : Flag<["-"], "mpower8-vector">,
 Group;
 def mno_power8_vector : Flag<["-"], "mno-power8-vector">,


Index: test/Driver/ppc-features.cpp
===
--- test/Driver/ppc-features.cpp
+++ test/Driver/ppc-features.cpp
@@ -22,6 +22,10 @@
 // RUN: %clang -target powerpc-unknown-linux-gnu %s -msoft-float -mhard-float -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SOFTHARD %s
 // CHECK-SOFTHARD-NOT: "-target-feature" "-hard-float"
 
+// check -msecure-plt option for ppc32
+// RUN: %clang -target powerpc-unknown-linux-gnu -msecure-plt %s  -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-SECUREPLT %s
+// CHECK-SECUREPLT: "-target-feature" "+secure-plt"
+
 // check -mfloat-abi=x option
 // RUN: %clang -target powerpc-unknown-linux-gnu %s -mfloat-abi=x -### -o %t.o 2>&1 | FileCheck --check-prefix=CHECK-ERRMSG %s
 // CHECK-ERRMSG: error: invalid float ABI '-mfloat-abi=x'
Index: lib/Driver/ToolChains/Arch/PPC.h
===
--- lib/Driver/ToolChains/Arch/PPC.h
+++ lib/Driver/ToolChains/Arch/PPC.h
@@ -29,10 +29,17 @@
   Hard,
 };
 
+enum class ReadGOTPtrMode {
+  Bss,
+  SecurePlt,
+};
+
 FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args);
 
 std::string getPPCTargetCPU(const llvm::opt::ArgList &Args);
 const char *getPPCAsmModeForCPU(StringRef Name);
+ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D,
+	const llvm::opt::ArgList &Args);
 
 void getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
   const llvm::opt::ArgList &Args,
Index: lib/Driver/ToolChains/Arch/PPC.cpp
===
--- lib/Driver/ToolChains/Arch/PPC.cpp
+++ lib/Driver/ToolChains/Arch/PPC.cpp
@@ -106,6 +106,16 @@
   ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
   if (FloatABI == ppc::FloatABI::Soft)
 Features.push_back

[PATCH] D44921: [PowerPC] Option for secure plt mode

2018-03-28 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic added inline comments.



Comment at: include/clang/Driver/Options.td:1941
 def mno_vsx : Flag<["-"], "mno-vsx">, Group;
+def msecure_plt : Flag<["-"], "msecure-plt">, Group;
 def mpower8_vector : Flag<["-"], "mpower8-vector">,

nemanjai wrote:
> Do we not want the negated option?
Well, I'm not sure if we need negated option. This is just switch from default 
mode (BSS) to SECURE PLT mode, also I didn't see that gcc has negated option 
for SECURE-PLT.



Comment at: lib/Driver/ToolChains/Arch/PPC.cpp:116
+ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const ArgList 
&Args) {
+  ppc::ReadGOTPtrMode ReadGOT = ppc::ReadGOTPtrMode::Bss;
+  if (Args.getLastArg(options::OPT_msecure_plt))

nemanjai wrote:
> Just a style question out of curiosity. Why the temporary? Since there are 
> just two possible values, why not just return the respective enumerator?
You are right, we don't need the temporary.


https://reviews.llvm.org/D44921



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


[PATCH] D41938: [Analyzer] SValBuilder Comparison Rearrangement (with Restrictions and Analyzer Option)

2018-03-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked an inline comment as done.
baloghadamsoftware added inline comments.



Comment at: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h:675-677
+  /// is on the right. This is only done if both concrete integers are greater
+  /// than or equal to the quarter of the minimum value of the type and less
+  /// than or equal to the quarter of the maximum value of that type.

NoQ wrote:
> I believe that we should mention that the integers are signed.
Also the symbols were forgotten. They must be in the range as well and must 
also be signed integers.


https://reviews.llvm.org/D41938



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


[PATCH] D44921: [PowerPC] Option for secure plt mode

2018-03-28 Thread Strahinja Petrovic via Phabricator via cfe-commits
spetrovic added a comment.

Yes, secure PLT is PowerPC specific feature.


https://reviews.llvm.org/D44921



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


[PATCH] D44921: [PowerPC] Option for secure plt mode

2018-03-28 Thread Joerg Sonnenberger via Phabricator via cfe-commits
joerg added a comment.

GCC supports -mbss-plt to get the legacy behavior. Not sure if anyone actually 
uses it though.


https://reviews.llvm.org/D44921



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


[PATCH] D44774: [Driver] Allow use of -fsyntax-only together with -MJ

2018-03-28 Thread David Stenberg via Phabricator via cfe-commits
dstenb added a comment.

Our legacy frontend does not support -MJ, so when using that frontend for code 
generation, we invoke clang with -MJ, and at the same use -fsyntax-only to get 
the improved diagnostics that clang provides. This is idiosyncratic and 
probably hacky, I know, but it works well enough to for example for getting 
access to defines and include flags from the compilation database, and being 
able to run clang-tidy. So (1) does not fit our use case, unfortunately.

Our way of running should of course in itself not  affect what is done 
upstream, but in general I don't see why someone shouldn't be allowed to do, 
for example, the following in their build chain:

  clang -MJ - -DFOO=usual-value foo.c -o foo.out # code generation
  clang -MJ - -DFOO=unusual-value -fsyntax-value foo.c # quick sanity check

and then run a tool like clang-tidy with the resulting compilation database.

Disregarding the above, I agree with the POLA issue with (1), so out of those 
two options the latter seems better to me.


Repository:
  rC Clang

https://reviews.llvm.org/D44774



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


[PATCH] D41537: Optionally add code completion results for arrow instead of dot

2018-03-28 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added inline comments.



Comment at: include/clang/Sema/CodeCompleteConsumer.h:565
+  /// \brief For this completion result correction is required.
+  Optional Corr = None;
+

yvvan wrote:
> ilya-biryukov wrote:
> > Having a string replacement without an actual range to replace still moves 
> > a lot of responsibility onto the clients. We should probably model 
> > corrections after the fix-its for diagnostics:
> > - replacements need to provide a range to be replaced, alongside with a 
> > text for the replacement,
> > - we should provide a list of edits to allow corrections that touch two 
> > separate pieces of code.
> > 
> > For the fix-its in the diagnostics, see 
> > [[https://reviews.llvm.org/source/clang/browse/cfe/trunk/tools/libclang/CXLoadedDiagnostic.h;327861$84
> >  | CXLoadedDiagnostic.h]] for an interface exported via libclang and 
> > [[https://reviews.llvm.org/source/clang/browse/cfe/trunk/include/clang/Basic/Diagnostic.h;327861$947|Diagnostic.h]]
> >  for an interface exported in C++ API.
> > WDYT?
> I thought that fixits always exist separately from diagnostics. I will check 
> this out, thanks.
I've looked  into diagnostics and realized that i already use them here but the 
are just not forwarded to completion results which is of source possible.

I have a draft with Optional instead of Optional
It allows to use further both string and replaced/removed range and also mostly 
uses the same code as already provided in this patch since I already generated 
FixItHint for Diagnostics (line 4117 lib/Sema/SemaCodeComplete.cpp in this 
patch)

Is that fine with you?


https://reviews.llvm.org/D41537



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


[PATCH] D44948: Add diagnostic -Waggregate-ctors, "aggregate type has user-declared constructors"

2018-03-28 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

> If no real code triggers this diagnostic, ...

Boost triggers this diagnostic:

  include/boost/core/noncopyable.hpp:23:9: error: aggregate type has 
user-declared constructors [-Werror,-Waggregate-ctors]
class noncopyable
  ^
  include/boost/iterator/iterator_facade.hpp:496:9: error: aggregate type has 
user-declared constructors [-Werror,-Waggregate-ctors]
class iterator_core_access
  ^
  include/boost/process/detail/posix/environment.hpp:101:7: error: aggregate 
type has user-declared constructors [-Werror,-Waggregate-ctors]
  class native_environment_impl
^
  include/boost/variant/static_visitor.hpp:43:7: error: aggregate type has 
user-declared constructors [-Werror,-Waggregate-ctors]
  class static_visitor
^


Repository:
  rC Clang

https://reviews.llvm.org/D44948



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


r328705 - [OPENMP] Codegen for ctor|dtor of declare target variables.

2018-03-28 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Wed Mar 28 07:28:54 2018
New Revision: 328705

URL: http://llvm.org/viewvc/llvm-project?rev=328705&view=rev
Log:
[OPENMP] Codegen for ctor|dtor of declare target variables.

When the declare target variables are emitted for the device,
constructors|destructors for these variables must emitted and registered
by the runtime in the offloading sections.

Added:
cfe/trunk/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntimeNVPTX.h
cfe/trunk/lib/Parse/ParseOpenMP.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=328705&r1=328704&r2=328705&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Mar 28 07:28:54 2018
@@ -546,7 +546,7 @@ public:
   /// FieldCollector - Collects CXXFieldDecls during parsing of C++ classes.
   std::unique_ptr FieldCollector;
 
-  typedef llvm::SmallSetVector NamedDeclSetType;
+  typedef llvm::SmallSetVector NamedDeclSetType;
 
   /// \brief Set containing all declared private fields that are not used.
   NamedDeclSetType UnusedPrivateFields;

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=328705&r1=328704&r2=328705&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Wed Mar 28 07:28:54 2018
@@ -379,6 +379,10 @@ CodeGenModule::EmitCXXGlobalVarDeclInitF
D->hasAttr()))
 return;
 
+  if (getLangOpts().OpenMP &&
+  getOpenMPRuntime().emitDeclareTargetVarDefinition(D, Addr, PerformInit))
+return;
+
   // Check if we've already initialized this decl.
   auto I = DelayedCXXInitPosition.find(D);
   if (I != DelayedCXXInitPosition.end() && I->second == ~0U)

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=328705&r1=328704&r2=328705&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Mar 28 07:28:54 2018
@@ -2522,6 +2522,139 @@ llvm::Function *CGOpenMPRuntime::emitThr
   return nullptr;
 }
 
+/// \brief Obtain information that uniquely identifies a target entry. This
+/// consists of the file and device IDs as well as line number associated with
+/// the relevant entry source location.
+static void getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc,
+ unsigned &DeviceID, unsigned &FileID,
+ unsigned &LineNum) {
+
+  auto &SM = C.getSourceManager();
+
+  // The loc should be always valid and have a file ID (the user cannot use
+  // #pragma directives in macros)
+
+  assert(Loc.isValid() && "Source location is expected to be always valid.");
+  assert(Loc.isFileID() && "Source location is expected to refer to a file.");
+
+  PresumedLoc PLoc = SM.getPresumedLoc(Loc);
+  assert(PLoc.isValid() && "Source location is expected to be always valid.");
+
+  llvm::sys::fs::UniqueID ID;
+  if (llvm::sys::fs::getUniqueID(PLoc.getFilename(), ID))
+llvm_unreachable("Source file with target region no longer exists!");
+
+  DeviceID = ID.getDevice();
+  FileID = ID.getFile();
+  LineNum = PLoc.getLine();
+}
+
+bool CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
+ llvm::GlobalVariable 
*Addr,
+ bool PerformInit) {
+  Optional Res =
+  isDeclareTargetDeclaration(VD);
+  if (!Res || *Res == OMPDeclareTargetDeclAttr::MT_Link)
+return false;
+  VD = VD->getDefinition(CGM.getContext());
+  if (VD && !DeclareTargetWithDefinition.insert(VD).second)
+return CGM.getLangOpts().OpenMPIsDevice;
+
+  QualType ASTTy = VD->getType();
+
+  SourceLocation Loc = VD->getCanonicalDecl()->getLocStart();
+  // Produce the unique prefix to identify the new target regions. We use
+  // the source location of the variable declaration which we know to not
+  // conflict with any target region.
+  unsigned DeviceID;
+  unsigned FileID;
+  unsigned Line;
+  getTargetEntryUniqueInfo(CGM.getContext(), Loc, DeviceID, FileID, Line);
+  SmallString<128> Buffer, Out;
+  {
+llvm::raw_svector_ostream OS(Buffer);
+OS << "__omp_offloading_" << llvm::format("_%x", DeviceID)
+   << llvm::format("_%x_", FileID) << VD->getName() << "_l" << Line;
+  }
+
+  const Expr *Init = VD->getAnyInitializer();
+  if (CGM

[PATCH] D43764: [clang-apply-replacements] Convert tooling::Replacements to tooling::AtomicChange for conflict resolving of changes, code cleanup, and code formatting.

2018-03-28 Thread Jeremy Demeule via Phabricator via cfe-commits
jdemeule added a comment.

Thanks a lot!
Can I ask you if I need to do something as I do not have commit access?


https://reviews.llvm.org/D43764



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


r328708 - clang-cl: s/Enable/Disable/ in help text for /GX-

2018-03-28 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Wed Mar 28 07:57:49 2018
New Revision: 328708

URL: http://llvm.org/viewvc/llvm-project?rev=328708&view=rev
Log:
clang-cl: s/Enable/Disable/ in help text for /GX-

Modified:
cfe/trunk/include/clang/Driver/CLCompatOptions.td

Modified: cfe/trunk/include/clang/Driver/CLCompatOptions.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CLCompatOptions.td?rev=328708&r1=328707&r2=328708&view=diff
==
--- cfe/trunk/include/clang/Driver/CLCompatOptions.td (original)
+++ cfe/trunk/include/clang/Driver/CLCompatOptions.td Wed Mar 28 07:57:49 2018
@@ -245,7 +245,7 @@ def _SLASH_Guard : CLJoined<"guard:">,
 def _SLASH_GX : CLFlag<"GX">,
   HelpText<"Enable exception handling">;
 def _SLASH_GX_ : CLFlag<"GX-">,
-  HelpText<"Enable exception handling">;
+  HelpText<"Disable exception handling">;
 def _SLASH_imsvc : CLJoinedOrSeparate<"imsvc">,
   HelpText<"Add directory to system include search path, as if part of 
%INCLUDE%">,
   MetaVarName<"">;


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


[PATCH] D44747: Set calling convention for CUDA kernel

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 140076.
yaxunl marked 4 inline comments as done.
yaxunl added a comment.

Revised by John's comments. Drop CUDA kernel calling convention in DRE.


https://reviews.llvm.org/D44747

Files:
  include/clang/Basic/Specifiers.h
  lib/AST/ItaniumMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCUDA/kernel-amdgcn.cu
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -626,6 +626,7 @@
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
+case CC_CUDAKernel: return CXCallingConv_Unexposed;
   break;
 }
 #undef TCALLINGCONV
Index: test/CodeGenCUDA/kernel-amdgcn.cu
===
--- /dev/null
+++ test/CodeGenCUDA/kernel-amdgcn.cu
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -emit-llvm %s -o - | FileCheck %s
+#include "Inputs/cuda.h"
+
+// CHECK: define amdgpu_kernel void @_ZN1A6kernelEv
+class A {
+public:
+  static __global__ void kernel(){}
+};
+
+// CHECK: define void @_Z10non_kernelv
+__device__ void non_kernel(){}
+
+// CHECK: define amdgpu_kernel void @_Z6kerneli
+__global__ void kernel(int x) {
+  non_kernel();
+}
+
+// CHECK: define amdgpu_kernel void @_Z15template_kernelI1AEvT_
+template
+__global__ void template_kernel(T x) {}
+
+void launch(void *f);
+
+int main() {
+  launch((void*)A::kernel);
+  launch((void*)kernel);
+  launch((void*)template_kernel);
+  return 0;
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3316,6 +3316,18 @@
   CallingConv CC = S.Context.getDefaultCallingConvention(FTI.isVariadic,
  IsCXXInstanceMethod);
 
+  // Attribute AT_CUDAGlobal affects the calling convention for AMDGPU targets.
+  // This is the simplest place to infer calling convention for CUDA kernels.
+  if (S.getLangOpts().CUDA && S.getLangOpts().CUDAIsDevice) {
+for (const AttributeList *Attr = D.getDeclSpec().getAttributes().getList();
+ Attr; Attr = Attr->getNext()) {
+  if (Attr->getKind() == AttributeList::AT_CUDAGlobal) {
+CC = CC_CUDAKernel;
+break;
+  }
+}
+  }
+
   // Attribute AT_OpenCLKernel affects the calling convention for SPIR
   // and AMDGPU targets, hence it cannot be treated as a calling
   // convention attribute. This is the simplest place to infer
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -1481,7 +1481,6 @@
  .getTypePtr());
   Changed = true;
 }
-
 // Convert FromFPT's ExtParameterInfo if necessary. The conversion is valid
 // only if the ExtParameterInfo lists of the two function prototypes can be
 // merged and the merged list is identical to ToFPT's ExtParameterInfo list.
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -25,6 +25,7 @@
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
@@ -1657,6 +1658,16 @@
   isa(D) &&
   NeedToCaptureVariable(cast(D), NameInfo.getLoc());
 
+  // Drop CUDA kernel calling convention since it is invisible to the user
+  // in DRE.
+  if (const auto *FT = dyn_cast(Ty.getTypePtr())) {
+if (FT->getCallConv() == CC_CUDAKernel) {
+  FT = Context.adjustFunctionType(FT,
+  FT->getExtInfo().withCallingConv(CC_C));
+  Ty = QualType(FT, Ty.getQualifiers().getAsOpaqueValue());
+}
+  }
+
   DeclRefExpr *E;
   if (isa(D)) {
 VarTemplateSpecializationDecl *VarSpec =
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -223,6 +223,9 @@
   /// Get LLVM calling convention for OpenCL kernel.
   virtual unsigned getOpenCLKernelCallingConv() const;
 
+  /// Get LLVM calling convention for CUDA kernel.
+  virtual unsigned getCUDAKernelCallingConv() const;
+
   /// Get target specific null pointer.
   /// \param T is the LLVM type of the null pointer.
   /// \param QT is the clang QualType of the null pointer.
Index: lib/CodeGen/TargetInfo.cpp
=

[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-03-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 140079.
baloghadamsoftware added a comment.

Updated according to the comments.


https://reviews.llvm.org/D33537

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tidy/bugprone/ExceptionEscapeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-exception-escape.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-exception-escape.cpp

Index: test/clang-tidy/bugprone-exception-escape.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-exception-escape.cpp
@@ -0,0 +1,256 @@
+// RUN: %check_clang_tidy %s bugprone-exception-escape %t -- -extra-arg=-std=c++11 -config="{CheckOptions: [{key: bugprone-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, {key: bugprone-exception-escape.EnabledFunctions, value: 'enabled1,enabled2,enabled3'}]}" --
+
+struct throwing_destructor {
+  ~throwing_destructor() {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function '~throwing_destructor' throws
+throw 1;
+  }
+};
+
+struct throwing_move_constructor {
+  throwing_move_constructor(throwing_move_constructor&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'throwing_move_constructor' throws
+throw 1;
+  }
+};
+
+struct throwing_move_assignment {
+  throwing_move_assignment& operator=(throwing_move_assignment&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: function 'operator=' throws
+throw 1;
+  }
+};
+
+void throwing_noexcept() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throwing_noexcept' throws
+  throw 1;
+}
+
+void throwing_throw_nothing() throw() {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throwing_throw_nothing' throws
+  throw 1;
+}
+
+void throw_and_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch' throws
+  try {
+throw 1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_some(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_and_catch_some' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_each(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch_each' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(double &) {
+  }
+}
+
+void throw_and_catch_all(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch_all' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(...) {
+  }
+}
+
+void throw_and_rethrow() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_and_rethrow' throws
+  try {
+throw 1;
+  } catch(int &) {
+throw;
+  }
+}
+
+void throw_catch_throw() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_catch_throw' throws
+  try {
+throw 1;
+  } catch(int &) {
+throw 2;
+  }
+}
+
+void throw_catch_rethrow_the_rest(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_catch_rethrow_the_rest' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(...) {
+throw;
+  }
+}
+
+class base {};
+class derived: public base {};
+
+void throw_derived_catch_base() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_derived_catch_base' throws
+  try {
+throw derived();
+  } catch(base &) {
+  }
+}
+
+void try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'try_nested_try' throws
+  try {
+try {
+  if (n) throw 1;
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void bad_try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_try_nested_try' throws
+  try {
+if (n) throw 1;
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void try_nested_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'try_nested_catch' throws
+  try {
+try {
+  throw 1;
+} catch(int &) {
+  throw 1.1;
+}
+  } catch(double &) {
+  }
+}
+
+void catch_nested_try() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'catch_nested_try' throws
+  try {
+throw 1;
+  } catch(int &) {
+try {
+  throw 1; 
+} catch(int &) {
+}
+  }
+}
+
+void bad_catch_nested_try() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_catch_nested_try' throws
+  try {
+throw 1;
+  } catch(int &) {
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void implicit_int_thrower() {
+  throw 1;
+}
+
+void explicit_int_thrower() throw(int);
+
+void indirect_implicit() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'indirect_implicit' th

[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-03-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware marked 4 inline comments as done.
baloghadamsoftware added inline comments.



Comment at: clang-tidy/bugprone/ExceptionEscapeCheck.cpp:24-25
+
+const TypeVec _throws(const FunctionDecl *Func);
+const TypeVec _throws(const Stmt *St, const TypeVec &Caught);
+} // namespace

alexfh wrote:
> alexfh wrote:
> > Function names should follow llvm conventions 
> > http://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly
> If there's no need to pass nullptr to these functions, the arguments can be 
> const references.
I agree in general, but I usually get `Stmt*` and `FunctionDecl*` from query 
functions, so it is simpler to pass them as they are instead of dereferencing 
them. The too many asterisks decrease the readability of the code. Furthermore, 
St may be `nullptr` in the second function.


https://reviews.llvm.org/D33537



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


r328712 - [Diag] Avoid emitting a redefinition note if no location is available.

2018-03-28 Thread Matt Davis via cfe-commits
Author: mattd
Date: Wed Mar 28 09:05:05 2018
New Revision: 328712

URL: http://llvm.org/viewvc/llvm-project?rev=328712&view=rev
Log:
[Diag] Avoid emitting a redefinition note if no location is available.

Summary:
The "previous definition is here" note is not helpful if there is no location 
information. The note will reference nothing in such a case. This patch first 
checks to see if there is location data, and if so the note diagnostic is 
emitted.

This fixes PR15409.  The issue in the first comment seems to already be 
resolved. This patch addresses the second example.

Reviewers: bruno, rsmith

Reviewed By: bruno

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/redefine_extname.c

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=328712&r1=328711&r2=328712&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar 28 09:05:05 2018
@@ -4057,7 +4057,8 @@ void Sema::notePreviousDefinition(const
   }
 
   // Redefinition coming from different files or couldn't do better above.
-  Diag(Old->getLocation(), diag::note_previous_definition);
+  if (Old->getLocation().isValid())
+Diag(Old->getLocation(), diag::note_previous_definition);
 }
 
 /// We've just determined that \p Old and \p New both appear to be definitions

Modified: cfe/trunk/test/Sema/redefine_extname.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/redefine_extname.c?rev=328712&r1=328711&r2=328712&view=diff
==
--- cfe/trunk/test/Sema/redefine_extname.c (original)
+++ cfe/trunk/test/Sema/redefine_extname.c Wed Mar 28 09:05:05 2018
@@ -4,3 +4,4 @@
 #pragma redefine_extname foo_static bar_static
 static int foo_static() { return 1; } // expected-warning {{#pragma 
redefine_extname is applicable to external C declarations only; not applied to 
function 'foo_static'}}
 
+unsigned __int128_t; // expected-error {{redefinition of '__int128_t' as 
different kind of symbol}}


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


[PATCH] D44901: [Diag] Avoid emitting a redefinition note if no location is available.

2018-03-28 Thread Matt Davis via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328712: [Diag] Avoid emitting a redefinition note if no 
location is available. (authored by mattd, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D44901

Files:
  lib/Sema/SemaDecl.cpp
  test/Sema/redefine_extname.c


Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -4057,7 +4057,8 @@
   }
 
   // Redefinition coming from different files or couldn't do better above.
-  Diag(Old->getLocation(), diag::note_previous_definition);
+  if (Old->getLocation().isValid())
+Diag(Old->getLocation(), diag::note_previous_definition);
 }
 
 /// We've just determined that \p Old and \p New both appear to be definitions
Index: test/Sema/redefine_extname.c
===
--- test/Sema/redefine_extname.c
+++ test/Sema/redefine_extname.c
@@ -4,3 +4,4 @@
 #pragma redefine_extname foo_static bar_static
 static int foo_static() { return 1; } // expected-warning {{#pragma 
redefine_extname is applicable to external C declarations only; not applied to 
function 'foo_static'}}
 
+unsigned __int128_t; // expected-error {{redefinition of '__int128_t' as 
different kind of symbol}}


Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -4057,7 +4057,8 @@
   }
 
   // Redefinition coming from different files or couldn't do better above.
-  Diag(Old->getLocation(), diag::note_previous_definition);
+  if (Old->getLocation().isValid())
+Diag(Old->getLocation(), diag::note_previous_definition);
 }
 
 /// We've just determined that \p Old and \p New both appear to be definitions
Index: test/Sema/redefine_extname.c
===
--- test/Sema/redefine_extname.c
+++ test/Sema/redefine_extname.c
@@ -4,3 +4,4 @@
 #pragma redefine_extname foo_static bar_static
 static int foo_static() { return 1; } // expected-warning {{#pragma redefine_extname is applicable to external C declarations only; not applied to function 'foo_static'}}
 
+unsigned __int128_t; // expected-error {{redefinition of '__int128_t' as different kind of symbol}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44984: [HIP] Add hip file type and codegen for kernel launching

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: rjmccall.
Herald added a subscriber: tpr.

HIP is a language similar to CUDA 
(https://github.com/ROCm-Developer-Tools/HIP/blob/master/docs/markdown/hip_kernel_language.md
 ).
The language syntax is very similar, which allows a hip program to be compiled 
as a CUDA program by Clang. The main difference
is the host API. HIP has a set of vendor neutral host API which can be 
implemented on different platforms. Currently there is open source
implementation of HIP runtime on amdgpu target 
(https://github.com/ROCm-Developer-Tools/HIP).

This patch adds support of file type hip and language option HIP.

When hip file is compiled, both LangOpts.CUDA and LangOpts.HIP is turned on. 
This allows compilation of hip program as CUDA
in most cases and only special handling of hip program is needed LangOpts.HIP 
is checked.

This patch also adds support of kernel launching of HIP program using HIP host 
API.

When -x hip is not specified, there is no behaviour change for CUDA.

Patch by Greg Rodgers.
Lit test added by Yaxun Liu.


https://reviews.llvm.org/D44984

Files:
  include/clang/Basic/LangOptions.def
  lib/CodeGen/CGCUDANV.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Frontend/InitPreprocessor.cpp
  lib/Sema/SemaCUDA.cpp
  lib/Sema/SemaDecl.cpp
  test/CodeGenCUDA/Inputs/cuda.h
  test/CodeGenCUDA/device-stub.cu
  test/CodeGenCUDA/kernel-call.cu

Index: test/CodeGenCUDA/kernel-call.cu
===
--- test/CodeGenCUDA/kernel-call.cu
+++ test/CodeGenCUDA/kernel-call.cu
@@ -1,11 +1,20 @@
-// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -o - | FileCheck %s --check-prefixes=CUDA,CHECK
+// RUN: %clang_cc1 -x hip -emit-llvm %s -o - | FileCheck %s --check-prefixes=HIP,CHECk
+
 
 #include "Inputs/cuda.h"
 
+// CHECK-LABEL: define void @_Z2g1i(i32 %x)
+// HIP: call{{.*}}hipSetupArgument
+// HIP: call{{.*}}hipLaunchByPtr
+// CUDA: call{{.*}}cudaSetupArgument
+// CUDA: call{{.*}}cudaLaunch
 __global__ void g1(int x) {}
 
+// CHECK-LABEL: define i32 @main
 int main(void) {
-  // CHECK: call{{.*}}cudaConfigureCall
+  // HIP: call{{.*}}hipConfigureCall
+  // CUDA: call{{.*}}cudaConfigureCall
   // CHECK: icmp
   // CHECK: br
   // CHECK: call{{.*}}g1
Index: test/CodeGenCUDA/device-stub.cu
===
--- test/CodeGenCUDA/device-stub.cu
+++ test/CodeGenCUDA/device-stub.cu
@@ -1,8 +1,12 @@
 // RUN: echo "GPU binary would be here" > %t
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -fcuda-include-gpubinary %t -o - | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -fcuda-include-gpubinary %t -o - | FileCheck -check-prefixes=CHECK,CUDA %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -fcuda-include-gpubinary %t -o -  -DNOGLOBALS \
 // RUN:   | FileCheck %s -check-prefix=NOGLOBALS
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s -check-prefix=NOGPUBIN
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x hip -emit-llvm %s -o - | FileCheck %s -check-prefix=NOGPUBIN
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x hip -emit-llvm %s -fcuda-include-gpubinary %t -o - | FileCheck -check-prefixes=CHECK,HIP %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x hip -emit-llvm %s -fcuda-include-gpubinary %t -o -  -DNOGLOBALS \
+// RUN:   | FileCheck %s -check-prefix=NOGLOBALS
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x hip -emit-llvm %s -o - | FileCheck %s -check-prefix=NOGPUBIN
 
 #include "Inputs/cuda.h"
 
@@ -48,67 +52,68 @@
 // CHECK: private unnamed_addr constant{{.*GPU binary would be here.*}}\00"
 // CHECK-SAME: section ".nv_fatbin", align 8
 // * constant struct that wraps GPU binary
-// CHECK: @__cuda_fatbin_wrapper = internal constant { i32, i32, i8*, i8* } 
+// CUDA: @__[[PREFIX:cuda]]_fatbin_wrapper = internal constant { i32, i32, i8*, i8* }
+// HIP: @__[[PREFIX:hip]]_fatbin_wrapper = internal constant { i32, i32, i8*, i8* }
 // CHECK-SAME: { i32 1180844977, i32 1, {{.*}}, i8* null }
 // CHECK-SAME: section ".nvFatBinSegment"
 // * variable to save GPU binary handle after initialization
-// CHECK: @__cuda_gpubin_handle = internal global i8** null
+// CHECK: @__[[PREFIX]]_gpubin_handle = internal global i8** null
 // * Make sure our constructor/destructor was added to global ctor/dtor list.
-// CHECK: @llvm.global_ctors = appending global {{.*}}@__cuda_module_ctor
-// CHECK: @llvm.global_dtors = appending global {{.*}}@__cuda_module_dtor
+// CHECK: @llvm.global_ctors = appending global {{.*}}@__[[PREFIX]]_module_ctor
+// CHECK: @llvm.global_dtors = appending global {{.*}}@__[[PREFIX]]_module_dtor
 
 // Test that we build the correct number of calls to cudaSetupArgument followed
 // by a call to cudaLaunch.
 
 // CHECK: define{{.*}}kernelfunc
-// CHECK: call{{.*}}cudaSetupArgument
-// CHECK: call{{.*}}cudaSetupArgument
-// CHECK: call{{.*}}cudaSetupArgument
-/

[PATCH] D44970: [XRay][clang] Add flag to choose instrumentation bundles

2018-03-28 Thread Eric Christopher via Phabricator via cfe-commits
echristo added inline comments.



Comment at: clang/include/clang/Frontend/CodeGenOptions.h:113
+XRay_None,// Emit none of the instrumentation points.
+XRay_FunctionExtents, // Only emit function entry/exit instrumentation
+  // points.

"function" might spell easier? :)



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:3248
+// custom events.
+{
+  auto XRayBundle = CGM.getCodeGenOpts().getXRayInstrumentationBundle();

I'd probably spell this code like the block above it rather than this.



Comment at: clang/lib/Driver/XRayArgs.cpp:61
   D.Diag(diag::err_drv_clang_unsupported)
-  << (std::string(XRayInstrumentOption) + " on non-supported target 
OS");
+  << (std::string(XRayInstrumentOption) +
+  " on non-supported target OS");

Extraneous reformat.



Comment at: clang/lib/Driver/XRayArgs.cpp:86
+Args.getLastArg(options::OPT_fxray_instrumentation_bundle)) {
+  StringRef B = A->getValue();
+  if (B != "all" && B != "none" && B != "function-extents" &&

How about a more descriptive name here and a string switch below?



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:452
+  StringRef V = A->getValue();
+  if (V == "all")
+return CodeGenOptions::XRayInstrumentationPointBundle::XRay_All;

StringSwitch maybe?


https://reviews.llvm.org/D44970



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


[PATCH] D44985: Disable zeroinitializer for CUDA shared varirable for amdgcn target

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: rjmccall.

amdgcn does not support zeroinitializer for CUDS shared variable.

Patch by Greg Rodgers.
Lit test added by Yaxun Liu.


https://reviews.llvm.org/D44985

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenCUDA/device-var-init.cu

Index: test/CodeGenCUDA/device-var-init.cu
===
--- test/CodeGenCUDA/device-var-init.cu
+++ test/CodeGenCUDA/device-var-init.cu
@@ -1,10 +1,14 @@
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // Make sure we don't allow dynamic initialization for device
 // variables, but accept empty constructors allowed by CUDA.
 
 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -std=c++11 \
-// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck %s
+// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,NVPTX %s
+
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 \
+// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,AMDGCN %s
 
 #ifdef __clang__
 #include "Inputs/cuda.h"
@@ -105,68 +109,116 @@
 __constant__ EC_I_EC c_ec_i_ec;
 // CHECK: @c_ec_i_ec = addrspace(4) externally_initialized global %struct.EC_I_EC zeroinitializer,
 
+// NVPTX:  @_ZZ2dfvE4s_ec = internal addrspace(3) global %struct.EC zeroinitializer
+// AMDGCN: @_ZZ2dfvE4s_ec = internal addrspace(3) global %struct.EC undef
+// NVPTX:  @_ZZ2dfvE5s_etc = internal addrspace(3) global %struct.ETC zeroinitializer
+// AMDGCN: @_ZZ2dfvE5s_etc = internal addrspace(3) global %struct.ETC undef
+
 // We should not emit global initializers for device-side variables.
 // CHECK-NOT: @__cxx_global_var_init
 
 // Make sure that initialization restrictions do not apply to local
 // variables.
 __device__ void df() {
+  // AMDGCN:  %[[ec:.*]] = addrspacecast %struct.EC addrspace(5)* %ec to %struct.EC*
+  // AMDGCN:  %[[ed:.*]] = addrspacecast %struct.ED addrspace(5)* %ed to %struct.ED*
+  // AMDGCN:  %[[ecd:.*]] = addrspacecast %struct.ECD addrspace(5)* %ecd to %struct.ECD*
+  // AMDGCN:  %[[etc:.*]] = addrspacecast %struct.ETC addrspace(5)* %etc to %struct.ETC*
+  // AMDGCN:  %[[uc:.*]] = addrspacecast %struct.UC addrspace(5)* %uc to %struct.UC*
+  // AMDGCN:  %[[ud:.*]] = addrspacecast %struct.UD addrspace(5)* %ud to %struct.UD*
+  // AMDGCN:  %[[eci:.*]] = addrspacecast %struct.ECI addrspace(5)* %eci to %struct.ECI*
+  // AMDGCN:  %[[nec:.*]] = addrspacecast %struct.NEC addrspace(5)* %nec to %struct.NEC*
+  // AMDGCN:  %[[ned:.*]] = addrspacecast %struct.NED addrspace(5)* %ned to %struct.NED*
+  // AMDGCN:  %[[ncv:.*]] = addrspacecast %struct.NCV addrspace(5)* %ncv to %struct.NCV*
+  // AMDGCN:  %[[vd:.*]] = addrspacecast %struct.VD addrspace(5)* %vd to %struct.VD*
+  // AMDGCN:  %[[ncf:.*]] = addrspacecast %struct.NCF addrspace(5)* %ncf to %struct.NCF*
+  // AMDGCN:  %[[ncfs:.*]] = addrspacecast %struct.NCFS addrspace(5)* %ncfs to %struct.NCFS*
+  // AMDGCN:  %[[utc:.*]] = addrspacecast %struct.UTC addrspace(5)* %utc to %struct.UTC*
+  // AMDGCN:  %[[netc:.*]] = addrspacecast %struct.NETC addrspace(5)* %netc to %struct.NETC*
+  // AMDGCN:  %[[ec_i_ec:.*]] = addrspacecast %struct.EC_I_EC addrspace(5)* %ec_i_ec to %struct.EC_I_EC*
+  // AMDGCN:  %[[ec_i_ec1:.*]] = addrspacecast %struct.EC_I_EC1 addrspace(5)* %ec_i_ec1 to %struct.EC_I_EC1*
+  // AMDGCN:  %[[t_v_t:.*]] = addrspacecast %struct.T_V_T addrspace(5)* %t_v_t to %struct.T_V_T*
+  // AMDGCN:  %[[t_b_nec:.*]] = addrspacecast %struct.T_B_NEC addrspace(5)* %t_b_nec to %struct.T_B_NEC*
+  // AMDGCN:  %[[t_f_nec:.*]] = addrspacecast %struct.T_F_NEC addrspace(5)* %t_f_nec to %struct.T_F_NEC*
+  // AMDGCN:  %[[t_fa_nec:.*]] = addrspacecast %struct.T_FA_NEC addrspace(5)* %t_fa_nec to %struct.T_FA_NEC*
+  // AMDGCN:  %[[t_b_ned:.*]] = addrspacecast %struct.T_B_NED addrspace(5)* %t_b_ned to %struct.T_B_NED*
+  // AMDGCN:  %[[t_f_ned:.*]] = addrspacecast %struct.T_F_NED addrspace(5)* %t_f_ned to %struct.T_F_NED*
+  // AMDGCN:  %[[t_fa_ned:.*]] = addrspacecast %struct.T_FA_NED addrspace(5)* %t_fa_ned to %struct.T_FA_NED*
+
   T t;
   // CHECK-NOT: call
   EC ec;
-  // CHECK:   call void @_ZN2ECC1Ev(%struct.EC* %ec)
+  // NVPTX:   call void @_ZN2ECC1Ev(%struct.EC* %ec)
+  // AMDGCN:  call void @_ZN2ECC1Ev(%struct.EC* %[[ec]])
   ED ed;
   // CHECK-NOT: call
   ECD ecd;
-  // CHECK:   call void @_ZN3ECDC1Ev(%struct.ECD* %ecd)
+  // NVPTX:   call void @_ZN3ECDC1Ev(%struct.ECD* %ecd)
+  // AMDGCN:  call void @_ZN3ECDC1Ev(%struct.ECD* %[[ecd]])
   ETC etc;
-  // CHECK:   call void @_ZN3ETCC1IJEEEDpT_(%struct.ETC* %etc)
+  // NVPTX:   call void @_ZN3ETCC1IJEEEDpT_(%struct.ETC* %etc)
+  // AMDGCN:  call void @_ZN3ETCC1IJEEEDpT_(%struct.ETC* %[[etc]])
   UC uc;
   // undefined constructor -- not allowed
-  // CHECK:   call void @_ZN2UCC1Ev(%struct.UC* %uc)
+  // NVPTX:   call void @_ZN2UCC1Ev(%struct.UC* %uc)
+  // AMDGCN:  call void @_ZN2UCC1Ev(%

[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-03-28 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/ReleaseNotes.rst:68
+- New :doc:`bugprone-exception-escape
+  ` check
+

.html is not necessary.


https://reviews.llvm.org/D33537



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


[PATCH] D44984: [HIP] Add hip file type and codegen for kernel launching

2018-03-28 Thread Artem Belevich via Phabricator via cfe-commits
tra added a subscriber: gregrodgers.
tra added a comment.

The changes appear to cover only some of the functionality needed to enable HIP 
support. Do you have more patches in queue? Having complete picture would help 
to make sense of the overall plan.
I did ask for it in https://reviews.llvm.org/D42800, but I don't think I've got 
the answers. It would help a lot if you or @gregrodgers could write a doc 
somewhere outlining overall plan for HIP support in clang, what are the main 
issues that need to be dealt with, and at least a general idea on how to handle 
them.

As far as "add -x hip, and tweak runtime glue codegen" goes, the change looks 
OK, but it's not very useful all by itself. It leaves a lot of other issues 
unsolved and no clear plan on whether/when/how you are planning to deal with 
them.

As things stand right now, with this patch clang will still attempt to include 
CUDA headers, which, among other things will provide threadIdx/blockIdx and 
other CUDA-specific features.
Perhaps it would make sense to disable pre-inclusion of CUDA headers and, 
probably, disable use of CUDA's libdevice bitcode library if we're compiling 
with -x hip (i.e. -nocudainc -nocudalib).
If you do depend on CUDA headers, then, I suspect, you may need to adjust some 
wrapper headers we use for CUDA and that change should probably come before 
this one.




Comment at: test/CodeGenCUDA/device-stub.cu:2-9
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s 
-fcuda-include-gpubinary %t -o - | FileCheck -check-prefixes=CHECK,CUDA %s
 // RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s 
-fcuda-include-gpubinary %t -o -  -DNOGLOBALS \
 // RUN:   | FileCheck %s -check-prefix=NOGLOBALS
-// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s -o - | FileCheck %s 
-check-prefix=NOGPUBIN
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x hip -emit-llvm %s -o - | 
FileCheck %s -check-prefix=NOGPUBIN
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x hip -emit-llvm %s 
-fcuda-include-gpubinary %t -o - | FileCheck -check-prefixes=CHECK,HIP %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -x hip -emit-llvm %s 
-fcuda-include-gpubinary %t -o -  -DNOGLOBALS \
+// RUN:   | FileCheck %s -check-prefix=NOGLOBALS

Please wrap the long lines.


https://reviews.llvm.org/D44984



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


[PATCH] D44987: Disable emitting static extern C aliases for amdgcn target for CUDA

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl created this revision.
yaxunl added a reviewer: rjmccall.

Patch by Greg Rodgers.
Lit test added by Yaxun Liu.


https://reviews.llvm.org/D44987

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCUDA/alias.cu


Index: test/CodeGenCUDA/alias.cu
===
--- test/CodeGenCUDA/alias.cu
+++ test/CodeGenCUDA/alias.cu
@@ -1,8 +1,11 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \
 // RUN:   -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn -emit-llvm \
+// RUN:   -o - %s | FileCheck %s
 
 #include "Inputs/cuda.h"
 
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4678,8 +4678,9 @@
 /// same translation unit.
 void CodeGenModule::EmitStaticExternCAliases() {
   // Don't do anything if we're generating CUDA device code -- the NVPTX
-  // assembly target doesn't support aliases.
-  if (Context.getTargetInfo().getTriple().isNVPTX())
+  // and AMDGCN assembly target doesn't support aliases.
+  if (Context.getTargetInfo().getTriple().isNVPTX() ||
+  (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::amdgcn))
 return;
   for (auto &I : StaticExternCValues) {
 IdentifierInfo *Name = I.first;


Index: test/CodeGenCUDA/alias.cu
===
--- test/CodeGenCUDA/alias.cu
+++ test/CodeGenCUDA/alias.cu
@@ -1,8 +1,11 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \
 // RUN:   -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn -emit-llvm \
+// RUN:   -o - %s | FileCheck %s
 
 #include "Inputs/cuda.h"
 
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4678,8 +4678,9 @@
 /// same translation unit.
 void CodeGenModule::EmitStaticExternCAliases() {
   // Don't do anything if we're generating CUDA device code -- the NVPTX
-  // assembly target doesn't support aliases.
-  if (Context.getTargetInfo().getTriple().isNVPTX())
+  // and AMDGCN assembly target doesn't support aliases.
+  if (Context.getTargetInfo().getTriple().isNVPTX() ||
+  (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::amdgcn))
 return;
   for (auto &I : StaticExternCValues) {
 IdentifierInfo *Name = I.first;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r328718 - Fix for LLVM header changes

2018-03-28 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Wed Mar 28 10:45:10 2018
New Revision: 328718

URL: http://llvm.org/viewvc/llvm-project?rev=328718&view=rev
Log:
Fix for LLVM header changes

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=328718&r1=328717&r2=328718&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Wed Mar 28 10:45:10 2018
@@ -56,6 +56,7 @@
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/GVN.h"
+#include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
 #include 


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


[PATCH] D44985: Disable zeroinitializer for CUDA shared varirable for amdgcn target

2018-03-28 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: test/CodeGenCUDA/device-var-init.cu:112
 
+// NVPTX:  @_ZZ2dfvE4s_ec = internal addrspace(3) global %struct.EC 
zeroinitializer
+// AMDGCN: @_ZZ2dfvE4s_ec = internal addrspace(3) global %struct.EC undef

Hmm. __shared__ should not be initialized in NVPTX either. This looks like a 
bug in NVPTX. 

For now you should make shared uninitialized regardless of whether we're 
compiling for AMDGCN or NVPTX.


https://reviews.llvm.org/D44985



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


[PATCH] D43322: Diagnose cases of "return x" that should be "return std::move(x)" for efficiency

2018-03-28 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone updated this revision to Diff 140103.
Quuxplusone added a comment.

Addressed review comments from @rsmith and rebased on master.
I still need someone else to land this for me, though.


Repository:
  rC Clang

https://reviews.llvm.org/D43322

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/SemaStmt.cpp
  test/SemaCXX/warn-return-std-move.cpp

Index: test/SemaCXX/warn-return-std-move.cpp
===
--- /dev/null
+++ test/SemaCXX/warn-return-std-move.cpp
@@ -0,0 +1,334 @@
+// RUN: %clang_cc1 -fsyntax-only -Wreturn-std-move -Wreturn-std-move-in-cxx11 -std=c++11 -verify %s
+// RUN: %clang_cc1 -fsyntax-only -Wreturn-std-move -Wreturn-std-move-in-cxx11 -std=c++11 -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+// definitions for std::move
+namespace std {
+inline namespace foo {
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+template  struct remove_reference { typedef T type; };
+
+template  typename remove_reference::type &&move(T &&t);
+} // namespace foo
+} // namespace std
+
+struct Instrument {
+Instrument() {}
+Instrument(Instrument&&) { /* MOVE */ }
+Instrument(const Instrument&) { /* COPY */ }
+};
+struct ConvertFromBase { Instrument i; };
+struct ConvertFromDerived { Instrument i; };
+struct Base {
+Instrument i;
+operator ConvertFromBase() const& { return ConvertFromBase{i}; }
+operator ConvertFromBase() && { return ConvertFromBase{std::move(i)}; }
+};
+struct Derived : public Base {
+operator ConvertFromDerived() const& { return ConvertFromDerived{i}; }
+operator ConvertFromDerived() && { return ConvertFromDerived{std::move(i)}; }
+};
+struct ConstructFromBase {
+Instrument i;
+ConstructFromBase(const Base& b): i(b.i) {}
+ConstructFromBase(Base&& b): i(std::move(b.i)) {}
+};
+struct ConstructFromDerived {
+Instrument i;
+ConstructFromDerived(const Derived& d): i(d.i) {}
+ConstructFromDerived(Derived&& d): i(std::move(d.i)) {}
+};
+
+struct TrivialInstrument {
+int i = 42;
+};
+struct ConvertFromTrivialBase { TrivialInstrument i; };
+struct ConvertFromTrivialDerived { TrivialInstrument i; };
+struct TrivialBase {
+TrivialInstrument i;
+operator ConvertFromTrivialBase() const& { return ConvertFromTrivialBase{i}; }
+operator ConvertFromTrivialBase() && { return ConvertFromTrivialBase{std::move(i)}; }
+};
+struct TrivialDerived : public TrivialBase {
+operator ConvertFromTrivialDerived() const& { return ConvertFromTrivialDerived{i}; }
+operator ConvertFromTrivialDerived() && { return ConvertFromTrivialDerived{std::move(i)}; }
+};
+struct ConstructFromTrivialBase {
+TrivialInstrument i;
+ConstructFromTrivialBase(const TrivialBase& b): i(b.i) {}
+ConstructFromTrivialBase(TrivialBase&& b): i(std::move(b.i)) {}
+};
+struct ConstructFromTrivialDerived {
+TrivialInstrument i;
+ConstructFromTrivialDerived(const TrivialDerived& d): i(d.i) {}
+ConstructFromTrivialDerived(TrivialDerived&& d): i(std::move(d.i)) {}
+};
+
+Derived test1() {
+Derived d1;
+return d1;  // ok
+}
+Base test2() {
+Derived d2;
+return d2;  // e1
+// expected-warning@-1{{will be copied despite being returned by name}}
+// expected-note@-2{{to avoid copying}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d2)"
+}
+ConstructFromDerived test3() {
+Derived d3;
+return d3;  // e2-cxx11
+// expected-warning@-1{{would have been copied despite being returned by name}}
+// expected-note@-2{{to avoid copying on older compilers}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d3)"
+}
+ConstructFromBase test4() {
+Derived d4;
+return d4;  // e3
+// expected-warning@-1{{will be copied despite being returned by name}}
+// expected-note@-2{{to avoid copying}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d4)"
+}
+ConvertFromDerived test5() {
+Derived d5;
+return d5;  // e4
+// expected-warning@-1{{will be copied despite being returned by name}}
+// expected-note@-2{{to avoid copying}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d5)"
+}
+ConvertFromBase test6() {
+Derived d6;
+return d6;  // e5
+// expected-warning@-1{{will be copied despite being returned by name}}
+// expected-note@-2{{to avoid copying}}
+// CHECK: fix-it:"{{.*}}":{[[@LINE-3]]:12-[[@LINE-3]]:14}:"std::move(d6)"
+}
+
+// These test cases should not produce the warning.
+Derived ok1() { Derived d; return d; }
+Base ok2() { Derived d; return static_cast(d); }
+ConstructFromDerived ok3() { Derived d; return static_cast(d); }
+ConstructFromBase ok4() { Derived d; return static_cast(d); }
+ConvertFromDerived ok5() { Derived d; return static_cast(d); }
+ConvertFromBase

[PATCH] D44984: [HIP] Add hip file type and codegen for kernel launching

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D44984#1050526, @tra wrote:

> The changes appear to cover only some of the functionality needed to enable 
> HIP support. Do you have more patches in queue? Having complete picture would 
> help to make sense of the overall plan.
>  I did ask for it in https://reviews.llvm.org/D42800, but I don't think I've 
> got the answers. It would help a lot if you or @gregrodgers could write a doc 
> somewhere outlining overall plan for HIP support in clang, what are the main 
> issues that need to be dealt with, and at least a general idea on how to 
> handle them.
>
> As far as "add -x hip, and tweak runtime glue codegen" goes, the change looks 
> OK, but it's not very useful all by itself. It leaves a lot of other issues 
> unsolved and no clear plan on whether/when/how you are planning to deal with 
> them.
>
> As things stand right now, with this patch clang will still attempt to 
> include CUDA headers, which, among other things will provide 
> threadIdx/blockIdx and other CUDA-specific features.
>  Perhaps it would make sense to disable pre-inclusion of CUDA headers and, 
> probably, disable use of CUDA's libdevice bitcode library if we're compiling 
> with -x hip (i.e. -nocudainc -nocudalib).
>  If you do depend on CUDA headers, then, I suspect, you may need to adjust 
> some wrapper headers we use for CUDA and that change should probably come 
> before this one.


Hi Artem, I am responsible for upstreaming Greg's work and addressing 
reviewers' comments.

Yes we already have a basic working implementation of HIP compiler due to 
Greg's work. I will either update https://reviews.llvm.org/D42800 or create a 
new review about the toolchain changes for compiling and linking HIP programs. 
Essentially HIP has its own header files and device libraries which are taken 
care of by the toolchain patch.

Since the header file and library seem not to affect this patch, is it OK to 
defer their changes to be part of the toolchain patch?

Thanks.


https://reviews.llvm.org/D44984



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


[PATCH] D44906: [clang-tidy] Define __clang_analyzer__ macro for clang-tidy for compatibility with clang static analyzer

2018-03-28 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG




Comment at: clang-tidy/ClangTidy.cpp:490
+CommandLineArguments AdjustedArgs = Args;
+AdjustedArgs.emplace_back("-D__clang_analyzer__");
+return AdjustedArgs;

zinovy.nis wrote:
> alexfh wrote:
> > I wonder whether we should instead reuse the logic in the frontend 
> > (tools/clang/lib/Frontend/InitPreprocessor.cpp:970). This could be done by 
> > overriding ActionFactory::runInvocation and setting 
> > FrontendOptions::ProgramAction to frontend::RunAnalysis there. WDYT?
> Thanks. I know about this code. But I'm not sure that we can reuse 
> RunAnalysys action hre - we need to parse AST only, but RunAnalysys does a 
> lot of other things we dont' need. Is it correct?
Clang tooling accepts the action from the client (in this case clang-tidy) and 
doesn't rely on frontend code that creates an action depending on the value of 
FrontendOptions::ProgramAction (clang::ExecuteCompilerInvocation). Thus, 
setting this frontend option will only trigger the logic in 
Frontend/InitPreprocessor.cpp that defines the macro.

On one hand, doing so will help clang-tidy to keep distance from whatever is 
done in the frontend to support static analyzer. On the other side, as your 
answer shows, this may not be a clear way to interact with that logic.

So I'm fine with either implementation.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44906



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


[PATCH] D44988: [Sema] Fix decrement availability for built-in types

2018-03-28 Thread Jan Korous via Phabricator via cfe-commits
jkorous-apple created this revision.
jkorous-apple added reviewers: speziale.ettore, arphaman.
Herald added a subscriber: cfe-commits.

C++ [over.built]p4:

  For every pair (T, VQ), where T is an arithmetic type other than bool, and VQ 
is either volatile or empty, there exist candidate operator functions of the 
form
  
VQ T&  operator--(VQ T&);
T  operator--(VQ T&, int);

The bool type is in position LastPromotedIntegralType in 
BuiltinOperatorOverloadBuilder::getArithmeticType::ArithmeticTypes, but 
addPlusPlusMinusMinusArithmeticOverloads() is expecting it at position 0.

Original patch by Ettore Speziale.

rdar://problem/34255516


Repository:
  rC Clang

https://reviews.llvm.org/D44988

Files:
  lib/Sema/SemaOverload.cpp
  test/SemaCXX/overloaded-builtin-operators.cpp


Index: test/SemaCXX/overloaded-builtin-operators.cpp
===
--- test/SemaCXX/overloaded-builtin-operators.cpp
+++ test/SemaCXX/overloaded-builtin-operators.cpp
@@ -73,6 +73,10 @@
   operator volatile long&();
 };
 
+struct FloatRef {
+  operator float&();
+};
+
 struct XpmfRef { // expected-note{{candidate function (the implicit copy 
assignment operator) not viable}}
 #if __cplusplus >= 201103L // C++11 or later
 // expected-note@-2 {{candidate function (the implicit move assignment 
operator) not viable}}
@@ -84,13 +88,16 @@
   operator E2&();
 };
 
-void g(ShortRef sr, LongRef lr, E2Ref e2_ref, XpmfRef pmf_ref) {
+void g(ShortRef sr, LongRef lr, FloatRef fr, E2Ref e2_ref, XpmfRef pmf_ref) {
   // C++ [over.built]p3
   short s1 = sr++;
 
   // C++ [over.built]p3
   long l1 = lr--;
 
+  // C++ [over.built]p4
+  float f1 = fr--;
+
   // C++ [over.built]p18
   short& sr1 = (sr *= lr);
   volatile long& lr1 = (lr *= sr);
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -7796,10 +7796,12 @@
 if (!HasArithmeticOrEnumeralCandidateType)
   return;
 
-for (unsigned Arith = (Op == OO_PlusPlus? 0 : 1);
- Arith < NumArithmeticTypes; ++Arith) {
+for (unsigned Arith = 0; Arith < NumArithmeticTypes; ++Arith) {
+  const auto TypeOfT = ArithmeticTypes[Arith];
+  if (Op == OO_MinusMinus && TypeOfT == S.Context.BoolTy)
+continue;
   addPlusPlusMinusMinusStyleOverloads(
-ArithmeticTypes[Arith],
+TypeOfT,
 VisibleTypeConversionsQuals.hasVolatile(),
 VisibleTypeConversionsQuals.hasRestrict());
 }


Index: test/SemaCXX/overloaded-builtin-operators.cpp
===
--- test/SemaCXX/overloaded-builtin-operators.cpp
+++ test/SemaCXX/overloaded-builtin-operators.cpp
@@ -73,6 +73,10 @@
   operator volatile long&();
 };
 
+struct FloatRef {
+  operator float&();
+};
+
 struct XpmfRef { // expected-note{{candidate function (the implicit copy assignment operator) not viable}}
 #if __cplusplus >= 201103L // C++11 or later
 // expected-note@-2 {{candidate function (the implicit move assignment operator) not viable}}
@@ -84,13 +88,16 @@
   operator E2&();
 };
 
-void g(ShortRef sr, LongRef lr, E2Ref e2_ref, XpmfRef pmf_ref) {
+void g(ShortRef sr, LongRef lr, FloatRef fr, E2Ref e2_ref, XpmfRef pmf_ref) {
   // C++ [over.built]p3
   short s1 = sr++;
 
   // C++ [over.built]p3
   long l1 = lr--;
 
+  // C++ [over.built]p4
+  float f1 = fr--;
+
   // C++ [over.built]p18
   short& sr1 = (sr *= lr);
   volatile long& lr1 = (lr *= sr);
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -7796,10 +7796,12 @@
 if (!HasArithmeticOrEnumeralCandidateType)
   return;
 
-for (unsigned Arith = (Op == OO_PlusPlus? 0 : 1);
- Arith < NumArithmeticTypes; ++Arith) {
+for (unsigned Arith = 0; Arith < NumArithmeticTypes; ++Arith) {
+  const auto TypeOfT = ArithmeticTypes[Arith];
+  if (Op == OO_MinusMinus && TypeOfT == S.Context.BoolTy)
+continue;
   addPlusPlusMinusMinusStyleOverloads(
-ArithmeticTypes[Arith],
+TypeOfT,
 VisibleTypeConversionsQuals.hasVolatile(),
 VisibleTypeConversionsQuals.hasRestrict());
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44984: [HIP] Add hip file type and codegen for kernel launching

2018-03-28 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D44984#1050557, @yaxunl wrote:

> Yes we already have a basic working implementation of HIP compiler due to 
> Greg's work.


That is great, but it's not necessarily true that all these changes will make 
it into clang/llvm as is. LLVM/Clang is a community effort and it helps a lot 
to get the changes in when the community understands what is it you're planning 
to do. I personally am very glad to see AMD moving towards making clang a 
viable compiler for AMD GPUs, but there's only so much I'll be able to do to 
help you with reviews if all I have is either piecemeal patches with little 
idea how they all fit together or one humongous patch I would have no time to 
dive in and really understand. Considering that compilation for GPU is a fairly 
niche market my bet is that your progress will be bottlenecked by the code 
reviews. Whatever you can do to make reviewers jobs easier by giving more 
context will help a lot with upstreaming the patches.

> I will either update https://reviews.llvm.org/D42800 or create a new review 
> about the toolchain changes for compiling and linking HIP programs. 
> Essentially HIP has its own header files and device libraries which are taken 
> care of by the toolchain patch.

Fair enough. I'll wait for the rest of the patches. If you have multiple 
pending patches, it helps if you could arrange them as dependent patches in 
phabricator. It makes it easier to see the big picture.

> Since the header file and library seem not to affect this patch, is it OK to 
> defer their changes to be part of the toolchain patch?

I'm not sure I understand. Could you elaborate?


https://reviews.llvm.org/D44984



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 140110.
yaxunl retitled this revision from "Disable zeroinitializer for CUDA shared 
varirable for amdgcn target" to "Remove initializer for CUDA shared varirable".
yaxunl edited the summary of this revision.
yaxunl added a reviewer: tra.
yaxunl added a comment.

Revised by Artem's comments.


https://reviews.llvm.org/D44985

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenCUDA/address-spaces.cu
  test/CodeGenCUDA/device-var-init.cu

Index: test/CodeGenCUDA/device-var-init.cu
===
--- test/CodeGenCUDA/device-var-init.cu
+++ test/CodeGenCUDA/device-var-init.cu
@@ -1,10 +1,14 @@
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // Make sure we don't allow dynamic initialization for device
 // variables, but accept empty constructors allowed by CUDA.
 
 // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fcuda-is-device -std=c++11 \
-// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck %s
+// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,NVPTX %s
+
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -std=c++11 \
+// RUN: -fno-threadsafe-statics -emit-llvm -o - %s | FileCheck -check-prefixes=CHECK,AMDGCN %s
 
 #ifdef __clang__
 #include "Inputs/cuda.h"
@@ -105,68 +109,114 @@
 __constant__ EC_I_EC c_ec_i_ec;
 // CHECK: @c_ec_i_ec = addrspace(4) externally_initialized global %struct.EC_I_EC zeroinitializer,
 
+// CHECK: @_ZZ2dfvE4s_ec = internal addrspace(3) global %struct.EC undef
+// CHECK: @_ZZ2dfvE5s_etc = internal addrspace(3) global %struct.ETC undef
+
 // We should not emit global initializers for device-side variables.
 // CHECK-NOT: @__cxx_global_var_init
 
 // Make sure that initialization restrictions do not apply to local
 // variables.
 __device__ void df() {
+  // AMDGCN:  %[[ec:.*]] = addrspacecast %struct.EC addrspace(5)* %ec to %struct.EC*
+  // AMDGCN:  %[[ed:.*]] = addrspacecast %struct.ED addrspace(5)* %ed to %struct.ED*
+  // AMDGCN:  %[[ecd:.*]] = addrspacecast %struct.ECD addrspace(5)* %ecd to %struct.ECD*
+  // AMDGCN:  %[[etc:.*]] = addrspacecast %struct.ETC addrspace(5)* %etc to %struct.ETC*
+  // AMDGCN:  %[[uc:.*]] = addrspacecast %struct.UC addrspace(5)* %uc to %struct.UC*
+  // AMDGCN:  %[[ud:.*]] = addrspacecast %struct.UD addrspace(5)* %ud to %struct.UD*
+  // AMDGCN:  %[[eci:.*]] = addrspacecast %struct.ECI addrspace(5)* %eci to %struct.ECI*
+  // AMDGCN:  %[[nec:.*]] = addrspacecast %struct.NEC addrspace(5)* %nec to %struct.NEC*
+  // AMDGCN:  %[[ned:.*]] = addrspacecast %struct.NED addrspace(5)* %ned to %struct.NED*
+  // AMDGCN:  %[[ncv:.*]] = addrspacecast %struct.NCV addrspace(5)* %ncv to %struct.NCV*
+  // AMDGCN:  %[[vd:.*]] = addrspacecast %struct.VD addrspace(5)* %vd to %struct.VD*
+  // AMDGCN:  %[[ncf:.*]] = addrspacecast %struct.NCF addrspace(5)* %ncf to %struct.NCF*
+  // AMDGCN:  %[[ncfs:.*]] = addrspacecast %struct.NCFS addrspace(5)* %ncfs to %struct.NCFS*
+  // AMDGCN:  %[[utc:.*]] = addrspacecast %struct.UTC addrspace(5)* %utc to %struct.UTC*
+  // AMDGCN:  %[[netc:.*]] = addrspacecast %struct.NETC addrspace(5)* %netc to %struct.NETC*
+  // AMDGCN:  %[[ec_i_ec:.*]] = addrspacecast %struct.EC_I_EC addrspace(5)* %ec_i_ec to %struct.EC_I_EC*
+  // AMDGCN:  %[[ec_i_ec1:.*]] = addrspacecast %struct.EC_I_EC1 addrspace(5)* %ec_i_ec1 to %struct.EC_I_EC1*
+  // AMDGCN:  %[[t_v_t:.*]] = addrspacecast %struct.T_V_T addrspace(5)* %t_v_t to %struct.T_V_T*
+  // AMDGCN:  %[[t_b_nec:.*]] = addrspacecast %struct.T_B_NEC addrspace(5)* %t_b_nec to %struct.T_B_NEC*
+  // AMDGCN:  %[[t_f_nec:.*]] = addrspacecast %struct.T_F_NEC addrspace(5)* %t_f_nec to %struct.T_F_NEC*
+  // AMDGCN:  %[[t_fa_nec:.*]] = addrspacecast %struct.T_FA_NEC addrspace(5)* %t_fa_nec to %struct.T_FA_NEC*
+  // AMDGCN:  %[[t_b_ned:.*]] = addrspacecast %struct.T_B_NED addrspace(5)* %t_b_ned to %struct.T_B_NED*
+  // AMDGCN:  %[[t_f_ned:.*]] = addrspacecast %struct.T_F_NED addrspace(5)* %t_f_ned to %struct.T_F_NED*
+  // AMDGCN:  %[[t_fa_ned:.*]] = addrspacecast %struct.T_FA_NED addrspace(5)* %t_fa_ned to %struct.T_FA_NED*
+
   T t;
   // CHECK-NOT: call
   EC ec;
-  // CHECK:   call void @_ZN2ECC1Ev(%struct.EC* %ec)
+  // NVPTX:   call void @_ZN2ECC1Ev(%struct.EC* %ec)
+  // AMDGCN:  call void @_ZN2ECC1Ev(%struct.EC* %[[ec]])
   ED ed;
   // CHECK-NOT: call
   ECD ecd;
-  // CHECK:   call void @_ZN3ECDC1Ev(%struct.ECD* %ecd)
+  // NVPTX:   call void @_ZN3ECDC1Ev(%struct.ECD* %ecd)
+  // AMDGCN:  call void @_ZN3ECDC1Ev(%struct.ECD* %[[ecd]])
   ETC etc;
-  // CHECK:   call void @_ZN3ETCC1IJEEEDpT_(%struct.ETC* %etc)
+  // NVPTX:   call void @_ZN3ETCC1IJEEEDpT_(%struct.ETC* %etc)
+  // AMDGCN:  call void @_ZN3ETCC1IJEEEDpT_(%struct.ETC* %[[etc]])
   UC uc;
   // undefined constructor -- not allowed
-  // CHECK:   call void @_ZN2UCC1Ev(%struct.UC* %uc)
+  // NVPTX:   call void @_ZN2UCC1Ev(%struct.UC* %uc)
+  // AMDGCN:  call void @_ZN2

r328723 - [MS] Fix bug in method vfptr location code

2018-03-28 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Wed Mar 28 11:23:35 2018
New Revision: 328723

URL: http://llvm.org/viewvc/llvm-project?rev=328723&view=rev
Log:
[MS] Fix bug in method vfptr location code

We were assuming that vbtable indices were assigned in layout order in
our comparison, which is not the case. When a virtual method, such as
the destructor, appears in multiple vftables, the vftable that appears
first in object layout order is the one that points to the main
implementation of that method. The later vftables use thunks.

In this layout, we adjusted "this" in the main implementation by the
amount that is appropriate for 'B' instead of 'A', even though the main
implementation is found in D's vftable for A:

  struct A {
virtual ~A() {}
  };
  struct B {
virtual ~B() {}
  };
  struct C : virtual B {};
  struct D : virtual A, C {};

D's layout looks like:
   0 D subobject (empty)
   0 C base suboject
   8 A base subobject
  16 B base subobject

With this fix, we correctly adjust by -8 in D's deleting destructor
instead of -16.

Fixes PR36921.

Modified:
cfe/trunk/lib/AST/VTableBuilder.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp

Modified: cfe/trunk/lib/AST/VTableBuilder.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/VTableBuilder.cpp?rev=328723&r1=328722&r2=328723&view=diff
==
--- cfe/trunk/lib/AST/VTableBuilder.cpp (original)
+++ cfe/trunk/lib/AST/VTableBuilder.cpp Wed Mar 28 11:23:35 2018
@@ -3544,6 +3544,19 @@ static void computeFullPathsForVFTables(
   }
 }
 
+static bool
+vfptrIsEarlierInMDC(const ASTRecordLayout &Layout,
+const MicrosoftVTableContext::MethodVFTableLocation &LHS,
+const MicrosoftVTableContext::MethodVFTableLocation &RHS) {
+  CharUnits L = LHS.VFPtrOffset;
+  CharUnits R = RHS.VFPtrOffset;
+  if (LHS.VBase)
+L += Layout.getVBaseClassOffset(LHS.VBase);
+  if (RHS.VBase)
+R += Layout.getVBaseClassOffset(RHS.VBase);
+  return L < R;
+}
+
 void MicrosoftVTableContext::computeVTableRelatedInformation(
 const CXXRecordDecl *RD) {
   assert(RD->isDynamicClass());
@@ -3574,12 +3587,15 @@ void MicrosoftVTableContext::computeVTab
 EmptyAddressPointsMap);
 Thunks.insert(Builder.thunks_begin(), Builder.thunks_end());
 
+const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
 for (const auto &Loc : Builder.vtable_locations()) {
-  GlobalDecl GD = Loc.first;
-  MethodVFTableLocation NewLoc = Loc.second;
-  auto M = NewMethodLocations.find(GD);
-  if (M == NewMethodLocations.end() || NewLoc < M->second)
-NewMethodLocations[GD] = NewLoc;
+  auto Insert = NewMethodLocations.insert(Loc);
+  if (!Insert.second) {
+const MethodVFTableLocation &NewLoc = Loc.second;
+MethodVFTableLocation &OldLoc = Insert.first->second;
+if (vfptrIsEarlierInMDC(Layout, NewLoc, OldLoc))
+  OldLoc = NewLoc;
+  }
 }
   }
 

Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp?rev=328723&r1=328722&r2=328723&view=diff
==
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-virtual-inheritance.cpp Wed Mar 28 
11:23:35 2018
@@ -538,3 +538,20 @@ D::D() : C() {}
 // CHECK:   %[[FIELD:.*]] = getelementptr inbounds i8, i8* %[[C_i8]], i32 8
 // CHECK:   call void @llvm.memset.p0i8.i32(i8* align 4 %[[FIELD]], i8 0, i32 
4, i1 false)
 }
+
+namespace pr36921 {
+struct A {
+  virtual ~A() {}
+};
+struct B {
+  virtual ~B() {}
+};
+struct C : virtual B {};
+struct D : virtual A, C {};
+D d;
+// CHECK-LABEL: define linkonce_odr dso_local x86_thiscallcc i8* 
@"??_GD@pr36921@@UAEPAXI@Z"(
+// CHECK:   %[[THIS:.*]] = load %"struct.pr36921::D"*, %"struct.pr36921::D"**
+// CHECK:   %[[THIS_UNADJ_i8:.*]] = bitcast %"struct.pr36921::D"* 
%[[THIS_RELOAD]] to i8*
+// CHECK:   %[[THIS_ADJ_i8:.*]] = getelementptr inbounds i8, i8* 
%[[THIS_UNADJ_i8]], i32 -4
+// CHECK:   %[[THIS:.*]] = bitcast i8* %[[THIS_ADJ_i8]] to 
%"struct.pr36921::D"*
+}


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


[PATCH] D44727: [RISCV] Extend getTargetDefines for RISCVTargetInfo

2018-03-28 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Do the macros you're defining here match gcc?




Comment at: lib/Basic/Targets/RISCV.cpp:68
+
+bool RISCVTargetInfo::hasFeature(StringRef Feature) const {
+  return llvm::StringSwitch(Feature)

asb wrote:
> It seems a number of other targets also return true for the archname, e.g. 
> "riscv".
> 
> Is it the case that hasFeature should always support at least everything 
> detected by handleTargetFeatures? If so, a comment to document this would be 
> helpful.
> 
> I can see this method was introduced in rC149227 and is primarily motivated 
> by module requirements.
> 
> @doug.gregor / @rsmith : could you please advise on the implementation and 
> testing of this function? Which features should be hasFeature check for? I 
> note that e.g. lib/Basic/Targets/ARM.cpp only supports a subset of the 
> features in hasFeature compared to handleTargetFeatures.
I think your assessment is right... and also, it looks like we have poor test 
coverage for the set of features which are actually supported.  So probably 
some targets are missing relevant features.

Should be straightforward to test, I think; you just need to write a module.map 
with appropriate "requires" lines, and a test file which tries to include those 
modules.  See test/Modules/Inputs/module.map.


Repository:
  rC Clang

https://reviews.llvm.org/D44727



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


[PATCH] D44801: Add the -fsanitize=shadow-call-stack flag

2018-03-28 Thread Vlad Tsyrklevich via Phabricator via cfe-commits
vlad.tsyrklevich added inline comments.



Comment at: docs/ShadowCallStack.rst:14
+buffer overflows. It works by saving a function's return address to a
+separately allocated 'shadow call stack' in the function prolog and checking 
the
+return address on the stack against the shadow call stack in the function

kcc wrote:
> kcc wrote:
> > prologue/epilogue? 
> > (it's your native tongue, not mine, though)
> PTAL
Forgot to submit this comment: It's used both ways across LLVM but I chose to 
go with this one just because that's how the PrologEpilogInserter pass wrote it.


Repository:
  rC Clang

https://reviews.llvm.org/D44801



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: test/CodeGenCUDA/device-var-init.cu:121
 __device__ void df() {
+  // AMDGCN:  %[[ec:.*]] = addrspacecast %struct.EC addrspace(5)* %ec to 
%struct.EC*
+  // AMDGCN:  %[[ed:.*]] = addrspacecast %struct.ED addrspace(5)* %ed to 
%struct.ED*

Perhaps it would make sense to capture there names for NVPTX as well and avoid 
duplicating all the checks below.


https://reviews.llvm.org/D44985



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: test/CodeGenCUDA/device-var-init.cu:121
 __device__ void df() {
+  // AMDGCN:  %[[ec:.*]] = addrspacecast %struct.EC addrspace(5)* %ec to 
%struct.EC*
+  // AMDGCN:  %[[ed:.*]] = addrspacecast %struct.ED addrspace(5)* %ed to 
%struct.ED*

tra wrote:
> Perhaps it would make sense to capture there names for NVPTX as well and 
> avoid duplicating all the checks below.
will do when committing.


https://reviews.llvm.org/D44985



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


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

lebedev.ri wrote:
> rjmccall wrote:
> > I think doing this here can result in double-warning if the overload 
> > resolves to a builtin operator.  Now, it might not actually be possible for 
> > that to combine with the requirements for self-assignment, but still, I 
> > think the right place to diagnose this for C++ is the same place we call 
> > DiagnoseSelfMove in CreateOverloadedBinOp.
> > 
> > Can CheckIdentityFieldAssignment just be integrated with 
> > DiagnoseSelfAssignment so that callers don't need to do call both?
> > I think the right place to diagnose this for C++ is the same place we call 
> > DiagnoseSelfMove in CreateOverloadedBinOp.
> 
> ```
> switch (Opc) {
> case BO_Assign:
> case BO_DivAssign:
> case BO_SubAssign:
> case BO_AndAssign:
> case BO_OrAssign:
> case BO_XorAssign:
>   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
>   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
>   break;
> default:
>   break;
> }
> 
> // Check for a self move.
> if (Op == OO_Equal)
>   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> ```
> 
> 
> ^ That does not appear to work. Pretty much all these tests start to fail.
> 
Okay.  It's possible that my suggestion is wrong.  Can you explain more how 
they fail?


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44747: Set calling convention for CUDA kernel

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

LGTM.

If `__global__` is supported in C++ structures, you might also need to make 
sure that member function constants (`&A::kernel_function`) drop the CC.  And 
it might be a good idea to make sure that `decltype(kernel_function)` doesn't 
have a problem with it, either, since that does do some special-case work.




Comment at: lib/Sema/SemaExpr.cpp:1669
+}
+  }
+

You should use `getAs` here (no `const` necessary).  It's 
possible to declare a function with a typedef of function type, you just can't 
define it that way.


https://reviews.llvm.org/D44747



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


[PATCH] D44747: Set calling convention for CUDA kernel

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

Matt, are you OK with the change from amdgcn backend point of view? Thanks.




Comment at: lib/Sema/SemaExpr.cpp:1669
+}
+  }
+

rjmccall wrote:
> You should use `getAs` here (no `const` necessary).  It's 
> possible to declare a function with a typedef of function type, you just 
> can't define it that way.
will do.


https://reviews.llvm.org/D44747



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

What exactly are you trying to express here?  Are you just trying to make these 
external declarations when compiling for the device because `__shared__` 
variables are actually defined on the host?  That should be handled by the 
frontend by setting up the AST so that these declarations are not definitions.


https://reviews.llvm.org/D44985



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


[PATCH] D44987: Disable emitting static extern C aliases for amdgcn target for CUDA

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/CodeGen/CodeGenModule.cpp:4684
+  (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::amdgcn))
 return;
   for (auto &I : StaticExternCValues) {

Please add a target hook for this instead of building a list of targets that 
don't support it.


https://reviews.llvm.org/D44987



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In https://reviews.llvm.org/D44985#1050670, @rjmccall wrote:

> What exactly are you trying to express here?  Are you just trying to make 
> these external declarations when compiling for the device because 
> `__shared__` variables are actually defined on the host?  That should be 
> handled by the frontend by setting up the AST so that these declarations are 
> not definitions.


__shared__ vars (at least in CUDA) are weird. Local-scoped ones are implicitly 
static (which compiler will attempt to zero-init) but in CUDA __shared__ 
variables can't have static initializers and we don't know the value of such 
vars when we launch the kernel.


https://reviews.llvm.org/D44985



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


[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D44985#1050670, @rjmccall wrote:

> What exactly are you trying to express here?  Are you just trying to make 
> these external declarations when compiling for the device because 
> `__shared__` variables are actually defined on the host?  That should be 
> handled by the frontend by setting up the AST so that these declarations are 
> not definitions.


No. These variables are not like external symbols defined on the host. They 
behave like global variables in the kernel code but never initialized. 
Currently no targets are able to initialize them and it is users' 
responsibility to initialize them explicitly.

Giving them an initial value will cause error in some backends since they 
cannot handle them, therefore put undef as initializer.


https://reviews.llvm.org/D44985



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


[PATCH] D44984: [HIP] Add hip file type and codegen for kernel launching

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

You should send an RFC to cfe-dev about adding this new language mode.  I 
understand that it's very similar to an existing language mode that we already 
support, and that's definitely we'll consider, but we shouldn't just agree to 
add new language modes in patch review.


https://reviews.llvm.org/D44984



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


[PATCH] D33537: [clang-tidy] Exception Escape Checker

2018-03-28 Thread Balogh , Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 140117.
baloghadamsoftware added a comment.

,html removed from release notes.


https://reviews.llvm.org/D33537

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/ExceptionEscapeCheck.cpp
  clang-tidy/bugprone/ExceptionEscapeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-exception-escape.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-exception-escape.cpp

Index: test/clang-tidy/bugprone-exception-escape.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-exception-escape.cpp
@@ -0,0 +1,256 @@
+// RUN: %check_clang_tidy %s bugprone-exception-escape %t -- -extra-arg=-std=c++11 -config="{CheckOptions: [{key: bugprone-exception-escape.IgnoredExceptions, value: 'ignored1,ignored2'}, {key: bugprone-exception-escape.EnabledFunctions, value: 'enabled1,enabled2,enabled3'}]}" --
+
+struct throwing_destructor {
+  ~throwing_destructor() {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function '~throwing_destructor' throws
+throw 1;
+  }
+};
+
+struct throwing_move_constructor {
+  throwing_move_constructor(throwing_move_constructor&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: function 'throwing_move_constructor' throws
+throw 1;
+  }
+};
+
+struct throwing_move_assignment {
+  throwing_move_assignment& operator=(throwing_move_assignment&&) {
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: function 'operator=' throws
+throw 1;
+  }
+};
+
+void throwing_noexcept() noexcept {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throwing_noexcept' throws
+  throw 1;
+}
+
+void throwing_throw_nothing() throw() {
+// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throwing_throw_nothing' throws
+  throw 1;
+}
+
+void throw_and_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch' throws
+  try {
+throw 1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_some(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_and_catch_some' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  }
+}
+
+void throw_and_catch_each(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch_each' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(double &) {
+  }
+}
+
+void throw_and_catch_all(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_and_catch_all' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(...) {
+  }
+}
+
+void throw_and_rethrow() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_and_rethrow' throws
+  try {
+throw 1;
+  } catch(int &) {
+throw;
+  }
+}
+
+void throw_catch_throw() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_catch_throw' throws
+  try {
+throw 1;
+  } catch(int &) {
+throw 2;
+  }
+}
+
+void throw_catch_rethrow_the_rest(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'throw_catch_rethrow_the_rest' throws
+  try {
+if (n) throw 1;
+throw 1.1;
+  } catch(int &) {
+  } catch(...) {
+throw;
+  }
+}
+
+class base {};
+class derived: public base {};
+
+void throw_derived_catch_base() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'throw_derived_catch_base' throws
+  try {
+throw derived();
+  } catch(base &) {
+  }
+}
+
+void try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'try_nested_try' throws
+  try {
+try {
+  if (n) throw 1;
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void bad_try_nested_try(int n) noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_try_nested_try' throws
+  try {
+if (n) throw 1;
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void try_nested_catch() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'try_nested_catch' throws
+  try {
+try {
+  throw 1;
+} catch(int &) {
+  throw 1.1;
+}
+  } catch(double &) {
+  }
+}
+
+void catch_nested_try() noexcept {
+  // CHECK-MESSAGES-NOT: :[[@LINE-1]]:6: warning: function 'catch_nested_try' throws
+  try {
+throw 1;
+  } catch(int &) {
+try {
+  throw 1; 
+} catch(int &) {
+}
+  }
+}
+
+void bad_catch_nested_try() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'bad_catch_nested_try' throws
+  try {
+throw 1;
+  } catch(int &) {
+try {
+  throw 1.1;
+} catch(int &) {
+}
+  } catch(double &) {
+  }
+}
+
+void implicit_int_thrower() {
+  throw 1;
+}
+
+void explicit_int_thrower() throw(int);
+
+void indirect_implicit() noexcept {
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'indirect_implicit' thr

[PATCH] D44994: [clang-format] Ensure wrapped ObjC selectors with 1 arg obey IndentWrappedFunctionNames

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, klimek, Typz.
Herald added a subscriber: cfe-commits.
benhamilton added a reviewer: jolesiak.

In https://reviews.llvm.org/D43121, @Typz introduced logic to avoid indenting 
2-or-more
argument ObjC selectors too far to the right if the first component
of the selector was longer than the others.

This had a small side effect of causing wrapped ObjC selectors with
exactly 1 argument to not obey IndentWrappedFunctionNames:

  - (aa)
  aa;

This diff fixes the issue by ensuring we align wrapped 1-argument
ObjC selectors correctly:

  - (aa)
  aa;

Test Plan: New tests added. Test failed before change, passed

  after change. Ran tests with:
  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D44994

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -537,6 +537,22 @@
"   aShortf:(NSRect)theRect {\n"
"}");
 
+  // Make sure selectors with 0, 1, or more arguments are indented
+  // when IndentWrappedFunctionNames is true.
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
   // Format pairs correctly.
   Style.ColumnLimit = 80;
   verifyFormat("- (void)drawRectOn:(id)surface\n"
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -896,12 +896,14 @@
 return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent);
   if (NextNonComment->is(TT_SelectorName)) {
 if (!State.Stack.back().ObjCSelectorNameFound) {
+  unsigned MinIndent =
+  (Style.IndentWrappedFunctionNames
+   ? std::max(State.Stack.back().Indent,
+  State.FirstIndent + Style.ContinuationIndentWidth)
+   : State.Stack.back().Indent);
   if (NextNonComment->LongestObjCSelectorName == 0)
-return State.Stack.back().Indent;
-  return (Style.IndentWrappedFunctionNames
-  ? std::max(State.Stack.back().Indent,
- State.FirstIndent + Style.ContinuationIndentWidth)
-  : State.Stack.back().Indent) +
+return MinIndent;
+  return MinIndent +
  std::max(NextNonComment->LongestObjCSelectorName,
   NextNonComment->ColumnWidth) -
  NextNonComment->ColumnWidth;


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -537,6 +537,22 @@
"   aShortf:(NSRect)theRect {\n"
"}");
 
+  // Make sure selectors with 0, 1, or more arguments are indented
+  // when IndentWrappedFunctionNames is true.
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
   // Format pairs correctly.
   Style.ColumnLimit = 80;
   verifyFormat("- (void)drawRectOn:(id)surface\n"
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -896,12 +896,14 @@
 return std::max(State.Stack.back().LastSpace, State.Stack.back().Indent)

[PATCH] D44995: [Driver] Include the Android multiarch includes.

2018-03-28 Thread Dan Albert via Phabricator via cfe-commits
danalbert created this revision.
danalbert added a reviewer: srhines.
Herald added a subscriber: javed.absar.

Most Android headers live in a single directory, but a small handful
live in multiarch directories.


Repository:
  rC Clang

https://reviews.llvm.org/D44995

Files:
  lib/Driver/ToolChains/Linux.cpp
  
test/Driver/Inputs/basic_android_ndk_tree/include/c++/4.9/x86_64-linux-android/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtbegin.o
  
test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/crtend.o
  
test/Driver/Inputs/basic_android_ndk_tree/lib/gcc/x86_64-linux-android/4.9/include/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/aarch64-linux-android/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/arm-linux-androideabi/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/i686-linux-android/.keep
  
test/Driver/Inputs/basic_android_ndk_tree/sysroot/usr/include/x86_64-linux-android/.keep
  test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld
  test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.bfd
  test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/bin/ld.gold
  test/Driver/Inputs/basic_android_ndk_tree/x86_64-linux-android/lib/.keep
  test/Driver/android-ndk-standalone.cpp

Index: test/Driver/android-ndk-standalone.cpp
===
--- test/Driver/android-ndk-standalone.cpp
+++ test/Driver/android-ndk-standalone.cpp
@@ -19,6 +19,7 @@
 // CHECK: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -56,6 +57,7 @@
 // CHECK-ARMV7: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK-ARMV7: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK-ARMV7: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-ARMV7: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-ARMV7: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -115,6 +117,7 @@
 // CHECK-THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK-THUMB: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK-THUMB: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-THUMB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -154,6 +157,7 @@
 // CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
 // CHECK-ARMV7THUMB: "-internal-isystem" "{{.*}}/sysroot/usr/local/include"
 // CHECK-ARMV7THUMB: "-internal-isystem" "[[RESOURCE_DIR]]{{(/|)}}include"
+// CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/arm-linux-androideabi"
 // CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-ARMV7THUMB: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-ARMV7THUMB: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -203,6 +207,7 @@
 // CHECK-AARCH64: "-internal-isystem" "{{.*}}/include/c++/4.9"
 // CHECK-AARCH64: "-internal-isystem" "{{.*}}/include/c++/4.9/aarch64-linux-android"
 // CHECK-AARCH64: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/aarch64-linux-android"
 // CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-AARCH64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-AARCH64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -219,6 +224,7 @@
 // CHECK-ARM64: "-internal-isystem" "{{.*}}/include/c++/4.9"
 // CHECK-ARM64: "-internal-isystem" "{{.*}}/include/c++/4.9/aarch64-linux-android"
 // CHECK-ARM64: "-internal-isystem" "{{.*}}/include/c++/4.9/backward"
+// CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include/aarch64-linux-android"
 // CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/include"
 // CHECK-ARM64: "-internal-externc-isystem" "{{.*}}/sysroot/usr/include"
 // CHECK-ARM64: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]"
@@ -321,9 +327,28 @@
 // CHECK-I686: "-internal-isystem" "{{.*}}/include/c++/4.9"
 // CHECK-I686: "-internal-isystem" "{{.*}}/include/c++/4

[PATCH] D44984: [HIP] Add hip file type and codegen for kernel launching

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D44984#1050672, @rjmccall wrote:

> You should send an RFC to cfe-dev about adding this new language mode.  I 
> understand that it's very similar to an existing language mode that we 
> already support, and that's definitely we'll consider, but we shouldn't just 
> agree to add new language modes in patch review.


RFC sent http://lists.llvm.org/pipermail/cfe-dev/2018-March/057426.html

Thanks.


https://reviews.llvm.org/D44984



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


r328725 - [Hexagon] Add support for "new" circular buffer intrinsics

2018-03-28 Thread Krzysztof Parzyszek via cfe-commits
Author: kparzysz
Date: Wed Mar 28 12:40:57 2018
New Revision: 328725

URL: http://llvm.org/viewvc/llvm-project?rev=328725&view=rev
Log:
[Hexagon] Add support for "new" circular buffer intrinsics

These instructions have been around for a long time, but we
haven't supported intrinsics for them. The "new" vesrions use
the CSx register for the start of the buffer instead of the K
field in the Mx register.

There is a related llvm patch.

Patch by Brendon Cahoon.

Added:
cfe/trunk/test/CodeGen/builtins-hexagon-circ.c
Modified:
cfe/trunk/include/clang/Basic/BuiltinsHexagon.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp

Modified: cfe/trunk/include/clang/Basic/BuiltinsHexagon.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsHexagon.def?rev=328725&r1=328724&r2=328725&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsHexagon.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsHexagon.def Wed Mar 28 12:40:57 2018
@@ -39,6 +39,29 @@ BUILTIN(__builtin_circ_stw,   "i*i*iiIi"
 BUILTIN(__builtin_circ_sth,   "s*s*iiIi", "")
 BUILTIN(__builtin_circ_sthhi, "s*s*iiIi", "")
 BUILTIN(__builtin_circ_stb,   "c*c*iiIi", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrub_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrb_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadruh_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrh_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadri_pci, "iv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrd_pci, "LLiv*IiivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrub_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrb_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadruh_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrh_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadri_pcr, "iv*ivC*", "")
+BUILTIN(__builtin_HEXAGON_L2_loadrd_pcr, "LLiv*ivC*", "")
+
+BUILTIN(__builtin_HEXAGON_S2_storerb_pci, "vv*IiiivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerh_pci, "vv*IiiivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerf_pci, "vv*IiiivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storeri_pci, "vv*IiiivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerd_pci, "vv*IiiLLivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerb_pcr, "vv*iivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerh_pcr, "vv*iivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerf_pcr, "vv*iivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storeri_pcr, "vv*iivC*", "")
+BUILTIN(__builtin_HEXAGON_S2_storerd_pcr, "vv*iLLivC*", "")
 
 // The builtins above are not autogenerated from iset.py.
 // Make sure you do not overwrite these.

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=328725&r1=328724&r2=328725&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Mar 28 12:40:57 2018
@@ -10772,6 +10772,54 @@ Value *CodeGenFunction::EmitHexagonBuilt
   SmallVector Ops;
   Intrinsic::ID ID = Intrinsic::not_intrinsic;
 
+  auto MakeCircLd = [&](unsigned IntID, bool HasImm = true) {
+// The base pointer is passed by address, so it needs to be loaded.
+Address BP = EmitPointerWithAlignment(E->getArg(0));
+BP = Address(Builder.CreateBitCast(BP.getPointer(), Int8PtrPtrTy),
+ BP.getAlignment());
+llvm::Value *Base = Builder.CreateLoad(BP);
+// Operands are Base, Increment, Modifier, Start.
+if (HasImm)
+  Ops = { Base, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2)),
+  EmitScalarExpr(E->getArg(3)) };
+else
+  Ops = { Base, EmitScalarExpr(E->getArg(1)),
+  EmitScalarExpr(E->getArg(2)) };
+
+llvm::Value *Result = Builder.CreateCall(CGM.getIntrinsic(IntID), Ops);
+llvm::Value *NewBase = Builder.CreateExtractValue(Result, 1);
+llvm::Value *LV = Builder.CreateBitCast(EmitScalarExpr(E->getArg(0)),
+
NewBase->getType()->getPointerTo());
+Address Dest = EmitPointerWithAlignment(E->getArg(0));
+// The intrinsic generates two results. The new value for the base pointer
+// needs to be stored.
+Builder.CreateAlignedStore(NewBase, LV, Dest.getAlignment());
+return Builder.CreateExtractValue(Result, 0);
+  };
+
+  auto MakeCircSt = [&](unsigned IntID, bool HasImm = true) {
+// The base pointer is passed by address, so it needs to be loaded.
+Address BP = EmitPointerWithAlignment(E->getArg(0));
+BP = Address(Builder.CreateBitCast(BP.getPointer(), Int8PtrPtrTy),
+ BP.getAlignment());
+llvm::Value *Base = Builder.CreateLoad(BP);
+// Operands are Base, Increment, Modifier, Value, Start.
+if (HasImm)
+  Ops = { Base, EmitScalarExpr(E->getArg(1)), EmitScalarExpr(E->getArg(2)),
+  EmitScalarExpr(E->getArg(3)), EmitScalarExpr(E->getArg(4)

[PATCH] D42893: [libclang] Add clang_File_tryGetRealPathName

2018-03-28 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Ping


Repository:
  rC Clang

https://reviews.llvm.org/D42893



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


[PATCH] D44720: [clangd] Simplify fuzzy matcher (sequence alignment) by removing some condition checks.

2018-03-28 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Friendly ping..


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44720



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


[PATCH] D44996: [clang-format] Ensure ObjC selectors with 0 args are annotated correctly

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak.
Herald added subscribers: cfe-commits, klimek.

Previously, clang-format would incorrectly annotate 0-argument
Objective-C selector names as TT_TrailingAnnotation:

  % echo "-(void)foo;" > /tmp/test.m
  % ./bin/clang-format -debug /tmp/test.m
  Language: Objective-C
  
  Line(0, FSC=0): minus[T=68, OC=0] l_paren[T=68, OC=1] void[T=68, OC=2]
  r_paren[T=68, OC=6] identifier[T=68, OC=7] semi[T=68, OC=10]
  Line(0, FSC=0): eof[T=68, OC=0]
  Run 0...
  AnnotatedTokens(L=0):
   M=0 C=0 T=ObjCMethodSpecifier S=1 B=0 BK=0 P=0 Name=minus L=1 PPK=2
   FakeLParens= FakeRParens=0 Text='-'
   M=0 C=1 T=Unknown S=1 B=0 BK=0 P=33 Name=l_paren L=3 PPK=2
   FakeLParens= FakeRParens=0 Text='('
   M=0 C=1 T=Unknown S=0 B=0 BK=0 P=140 Name=void L=7 PPK=2 FakeLParens=
   FakeRParens=0 Text='void'
   M=0 C=0 T=CastRParen S=0 B=0 BK=0 P=43 Name=r_paren L=8 PPK=2
   FakeLParens= FakeRParens=0 Text=')'
   M=0 C=1 T=TrailingAnnotation S=0 B=0 BK=0 P=120 Name=identifier L=11
   PPK=2 FakeLParens= FakeRParens=0 Text='foo'
   M=0 C=0 T=Unknown S=0 B=0 BK=0 P=23 Name=semi L=12 PPK=2 FakeLParens=
   FakeRParens=0 Text=';'

This caused us to incorrectly indent 0-argument wrapped selectors
when Style.IndentWrappedFunctionNames was false, as we thought
the 0-argument ObjC selector name was actually a trailing
annotation (which is always indented).

This diff fixes the issue and adds tests.

Test Plan: New tests added. Confirmed tests failed before diff.

  After diff, tests passed. Ran tests with:
  % make -j12 FormatTests &&
  ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D44996

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -522,6 +522,22 @@
   verifyFormat("- (void)drawRectOn:(id)surface\n"
"ofSize:(size_t)height\n"
"  :(size_t)width;");
+  Style.ColumnLimit = 40;
+  // Make sure selectors with 0, 1, or more arguments are not indented
+  // when IndentWrappedFunctionNames is false.
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
 
   // Continuation indent width should win over aligning colons if the function
   // name is long.
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -1343,6 +1343,16 @@
  TT_LeadingJavaAnnotation)) {
 Current.Type = Current.Previous->Type;
   }
+} else if (Current.isOneOf(tok::identifier, tok::kw_new) &&
+   Current.Previous && Current.Previous->is(TT_CastRParen) &&
+   Current.Previous->MatchingParen &&
+   Current.Previous->MatchingParen->Previous &&
+   Current.Previous->MatchingParen->Previous->is(
+   TT_ObjCMethodSpecifier)) {
+  // This is the first part of an Objective-C selector name. (If there's no
+  // colon after this, this is the only place which annotates the 
identifier
+  // as a selector.)
+  Current.Type = TT_SelectorName;
 } else if (Current.isOneOf(tok::identifier, tok::kw_const) &&
Current.Previous &&
!Current.Previous->isOneOf(tok::equal, tok::at) &&


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -522,6 +522,22 @@
   verifyFormat("- (void)drawRectOn:(id)surface\n"
"ofSize:(size_t)height\n"
"  :(size_t)width;");
+  Style.ColumnLimit = 40;
+  // Make sure selectors with 0, 1, or more arguments are not indented
+  // when IndentWrappedFunctionNames is false.
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (aaa

[PATCH] D44964: Change order of libclang_rt.profile link for freebsd

2018-03-28 Thread Vedant Kumar via Phabricator via cfe-commits
vsk added a comment.

Could you add a test in test/Driver/instrprof-ld.c?


Repository:
  rC Clang

https://reviews.llvm.org/D44964



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


[PATCH] D44987: Disable emitting static extern C aliases for amdgcn target for CUDA

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 140129.
yaxunl edited the summary of this revision.
yaxunl added a comment.

Add a target hook as suggested by John.


https://reviews.llvm.org/D44987

Files:
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  test/CodeGenCUDA/alias.cu


Index: test/CodeGenCUDA/alias.cu
===
--- test/CodeGenCUDA/alias.cu
+++ test/CodeGenCUDA/alias.cu
@@ -1,8 +1,11 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \
 // RUN:   -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn -emit-llvm \
+// RUN:   -o - %s | FileCheck %s
 
 #include "Inputs/cuda.h"
 
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -296,6 +296,11 @@
   createEnqueuedBlockKernel(CodeGenFunction &CGF,
 llvm::Function *BlockInvokeFunc,
 llvm::Value *BlockLiteral) const;
+
+  /// \return true if the target supports alias from the unmangled name to the
+  /// mangled name of functions declared within an extern "C" region and marked
+  /// as 'used', and having internal linkage.
+  virtual bool shouldEmitStaticExternCAliases() const { return true; }
 };
 
 } // namespace CodeGen
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -6154,6 +6154,7 @@
 
   void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
CodeGen::CodeGenModule &M) const override;
+  bool shouldEmitStaticExternCAliases() const override;
 
 private:
   // Adds a NamedMDNode with F, Name, and Operand as operands, and adds the
@@ -6275,6 +6276,10 @@
   // Append metadata to nvvm.annotations
   MD->addOperand(llvm::MDNode::get(Ctx, MDVals));
 }
+
+bool NVPTXTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
+  return false;
+}
 }
 
 
//===--===//
@@ -7646,6 +7651,7 @@
   createEnqueuedBlockKernel(CodeGenFunction &CGF,
 llvm::Function *BlockInvokeFunc,
 llvm::Value *BlockLiteral) const override;
+  bool shouldEmitStaticExternCAliases() const override;
 };
 }
 
@@ -,6 +7783,10 @@
   return C.getOrInsertSyncScopeID(Name);
 }
 
+bool AMDGPUTargetCodeGenInfo::shouldEmitStaticExternCAliases() const {
+  return false;
+}
+
 
//===--===//
 // SPARC v8 ABI Implementation.
 // Based on the SPARC Compliance Definition version 2.4.1.
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -4677,9 +4677,7 @@
 /// to such functions with an unmangled name from inline assembly within the
 /// same translation unit.
 void CodeGenModule::EmitStaticExternCAliases() {
-  // Don't do anything if we're generating CUDA device code -- the NVPTX
-  // assembly target doesn't support aliases.
-  if (Context.getTargetInfo().getTriple().isNVPTX())
+  if (!getTargetCodeGenInfo().shouldEmitStaticExternCAliases())
 return;
   for (auto &I : StaticExternCValues) {
 IdentifierInfo *Name = I.first;


Index: test/CodeGenCUDA/alias.cu
===
--- test/CodeGenCUDA/alias.cu
+++ test/CodeGenCUDA/alias.cu
@@ -1,8 +1,11 @@
 // REQUIRES: x86-registered-target
 // REQUIRES: nvptx-registered-target
+// REQUIRES: amdgpu-registered-target
 
 // RUN: %clang_cc1 -fcuda-is-device -triple nvptx-nvidia-cuda -emit-llvm \
 // RUN:   -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fcuda-is-device -triple amdgcn -emit-llvm \
+// RUN:   -o - %s | FileCheck %s
 
 #include "Inputs/cuda.h"
 
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -296,6 +296,11 @@
   createEnqueuedBlockKernel(CodeGenFunction &CGF,
 llvm::Function *BlockInvokeFunc,
 llvm::Value *BlockLiteral) const;
+
+  /// \return true if the target supports alias from the unmangled name to the
+  /// mangled name of functions declared within an extern "C" region and marked
+  /// as 'used', and having internal linkage.
+  virtual bool shouldEmitStaticExternCAliases() const { return true; }
 };
 
 } // namespace CodeGen
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/TargetInfo.cpp
+++ lib/CodeGen/TargetInfo.cpp
@@ -6154,6 +6154,7 @@
 
   void setTargetAttributes(con

[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd requested changes to this revision.
compnerd added a comment.
This revision now requires changes to proceed.

I really don't like this approach.  I think that we should introduce a 
different entry point for this behavior rather than saying that we go through 
the existing interface.  Having a reference to the `.eh_frame_hdr` seems 
better, as it would be better to make use of that optimization and we already 
have handling for that in libunwind.


https://reviews.llvm.org/D44494



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


[PATCH] D44536: Avoid segfault when destructor is not yet known

2018-03-28 Thread Dimitry Andric via Phabricator via cfe-commits
dim added a comment.

Ping. Open to sugggestions here :)


Repository:
  rC Clang

https://reviews.llvm.org/D44536



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


[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D44494#1050783, @compnerd wrote:

> I really don't like this approach.  I think that we should introduce a 
> different entry point for this behavior rather than saying that we go through 
> the existing interface.  Having a reference to the `.eh_frame_hdr` seems 
> better, as it would be better to make use of that optimization and we already 
> have handling for that in libunwind.


Well, this is just a plain `.eh_frame`, not an `.eh_frame_hdr`, since nothing 
for MinGW actually produces such a section for COFF (yet), GNU binutils doesn't 
either. Adding support for an indexed `.eh_frame_hdr`, while good from a 
performance PoV, feels like an orthogonal issue from this.

This else clause isn't about `.eh_frame` vs `.eh_frame_hdr`, but about 
registering a single FDE (which libunwind's `__register_frame` currently does) 
vs registering a full `.eh_frame` section (which libgcc's `__register_frame` 
does).


https://reviews.llvm.org/D44494



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


[PATCH] D44747: Set calling convention for CUDA kernel

2018-03-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 140131.
yaxunl marked 2 inline comments as done.
yaxunl added a comment.

Use getAs instead of dyn_cast as John suggested.


https://reviews.llvm.org/D44747

Files:
  include/clang/Basic/Specifiers.h
  lib/AST/ItaniumMangle.cpp
  lib/AST/Type.cpp
  lib/AST/TypePrinter.cpp
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/CodeGen/TargetInfo.h
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaType.cpp
  test/CodeGenCUDA/kernel-amdgcn.cu
  tools/libclang/CXType.cpp

Index: tools/libclang/CXType.cpp
===
--- tools/libclang/CXType.cpp
+++ tools/libclang/CXType.cpp
@@ -626,6 +626,7 @@
   TCALLINGCONV(PreserveAll);
 case CC_SpirFunction: return CXCallingConv_Unexposed;
 case CC_OpenCLKernel: return CXCallingConv_Unexposed;
+case CC_CUDAKernel: return CXCallingConv_Unexposed;
   break;
 }
 #undef TCALLINGCONV
Index: test/CodeGenCUDA/kernel-amdgcn.cu
===
--- /dev/null
+++ test/CodeGenCUDA/kernel-amdgcn.cu
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple amdgcn -fcuda-is-device -emit-llvm %s -o - | FileCheck %s
+#include "Inputs/cuda.h"
+
+// CHECK: define amdgpu_kernel void @_ZN1A6kernelEv
+class A {
+public:
+  static __global__ void kernel(){}
+};
+
+// CHECK: define void @_Z10non_kernelv
+__device__ void non_kernel(){}
+
+// CHECK: define amdgpu_kernel void @_Z6kerneli
+__global__ void kernel(int x) {
+  non_kernel();
+}
+
+// CHECK: define amdgpu_kernel void @_Z15template_kernelI1AEvT_
+template
+__global__ void template_kernel(T x) {}
+
+void launch(void *f);
+
+int main() {
+  launch((void*)A::kernel);
+  launch((void*)kernel);
+  launch((void*)template_kernel);
+  return 0;
+}
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -3316,6 +3316,18 @@
   CallingConv CC = S.Context.getDefaultCallingConvention(FTI.isVariadic,
  IsCXXInstanceMethod);
 
+  // Attribute AT_CUDAGlobal affects the calling convention for AMDGPU targets.
+  // This is the simplest place to infer calling convention for CUDA kernels.
+  if (S.getLangOpts().CUDA && S.getLangOpts().CUDAIsDevice) {
+for (const AttributeList *Attr = D.getDeclSpec().getAttributes().getList();
+ Attr; Attr = Attr->getNext()) {
+  if (Attr->getKind() == AttributeList::AT_CUDAGlobal) {
+CC = CC_CUDAKernel;
+break;
+  }
+}
+  }
+
   // Attribute AT_OpenCLKernel affects the calling convention for SPIR
   // and AMDGPU targets, hence it cannot be treated as a calling
   // convention attribute. This is the simplest place to infer
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -1481,7 +1481,6 @@
  .getTypePtr());
   Changed = true;
 }
-
 // Convert FromFPT's ExtParameterInfo if necessary. The conversion is valid
 // only if the ExtParameterInfo lists of the two function prototypes can be
 // merged and the merged list is identical to ToFPT's ExtParameterInfo list.
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -25,6 +25,7 @@
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/ExprOpenMP.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
@@ -1657,6 +1658,16 @@
   isa(D) &&
   NeedToCaptureVariable(cast(D), NameInfo.getLoc());
 
+  // Drop CUDA kernel calling convention since it is invisible to the user
+  // in DRE.
+  if (const auto *FT = Ty->getAs()) {
+if (FT->getCallConv() == CC_CUDAKernel) {
+  FT = Context.adjustFunctionType(FT,
+  FT->getExtInfo().withCallingConv(CC_C));
+  Ty = QualType(FT, Ty.getQualifiers().getAsOpaqueValue());
+}
+  }
+
   DeclRefExpr *E;
   if (isa(D)) {
 VarTemplateSpecializationDecl *VarSpec =
Index: lib/CodeGen/TargetInfo.h
===
--- lib/CodeGen/TargetInfo.h
+++ lib/CodeGen/TargetInfo.h
@@ -223,6 +223,9 @@
   /// Get LLVM calling convention for OpenCL kernel.
   virtual unsigned getOpenCLKernelCallingConv() const;
 
+  /// Get LLVM calling convention for CUDA kernel.
+  virtual unsigned getCUDAKernelCallingConv() const;
+
   /// Get target specific null pointer.
   /// \param T is the LLVM type of the null pointer.
   /// \param QT is the clang QualType of the null pointer.
Index: lib/CodeGen/TargetInfo.cpp
===
--- lib/CodeGen/Ta

[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

rjmccall wrote:
> lebedev.ri wrote:
> > rjmccall wrote:
> > > I think doing this here can result in double-warning if the overload 
> > > resolves to a builtin operator.  Now, it might not actually be possible 
> > > for that to combine with the requirements for self-assignment, but still, 
> > > I think the right place to diagnose this for C++ is the same place we 
> > > call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > 
> > > Can CheckIdentityFieldAssignment just be integrated with 
> > > DiagnoseSelfAssignment so that callers don't need to do call both?
> > > I think the right place to diagnose this for C++ is the same place we 
> > > call DiagnoseSelfMove in CreateOverloadedBinOp.
> > 
> > ```
> > switch (Opc) {
> > case BO_Assign:
> > case BO_DivAssign:
> > case BO_SubAssign:
> > case BO_AndAssign:
> > case BO_OrAssign:
> > case BO_XorAssign:
> >   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
> >   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
> >   break;
> > default:
> >   break;
> > }
> > 
> > // Check for a self move.
> > if (Op == OO_Equal)
> >   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> > ```
> > 
> > 
> > ^ That does not appear to work. Pretty much all these tests start to fail.
> > 
> Okay.  It's possible that my suggestion is wrong.  Can you explain more how 
> they fail?
Right, i should have been verbose :)
There are no test changes as compared to the current diff.
Here is the output of `$ ninja check-clang-sema check-clang-semacxx`
{F5920055}
It is also totally possible that i'm missing something obvious on my end...


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D44494#1050797, @mstorsjo wrote:

> This else clause isn't about `.eh_frame` vs `.eh_frame_hdr`, but about 
> registering a single FDE (which libunwind's `__register_frame` currently 
> does) vs registering a full `.eh_frame` section (which libgcc's 
> `__register_frame` does).


However, this function actually just is `_unw_add_dynamic_fde`, while 
`__register_frame` in `UnwindLevel1-gcc-ext.c` just calls this function. So we 
should probably check there instead, whether it's an FDE (which libgcc doesn't 
support via that entry point) or a full `.eh_frame` section.


https://reviews.llvm.org/D44494



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


[PATCH] D44882: [clangd] Implementation of workspace/symbol request

2018-03-28 Thread Marc-Andre Laperle via Phabricator via cfe-commits
malaperle added inline comments.



Comment at: clangd/SourceCode.cpp:110
+
+llvm::Optional offsetRangeToLocation(SourceManager &SourceMgr,
+   StringRef File,

MaskRay wrote:
> May I ask a question about the conversion between SourceLocation and LSP 
> location? When the document is slightly out of sync with the indexed version, 
> what will be returned?
I forgot to cover the case of the unsaved files, which are indexed in memory. 
It that what you mean? I'll update the patch to address by using the DraftStore 
when available. There is also the case where the file is not opened but 
outdated on disk. I don't think we can do much about it but make sure it 
doesn't crash :) At worst, the location might be off, and navigation will be 
momentarily affected, until the index can be updated with the file change. This 
is what I've noticed in other IDEs as well.



Comment at: clangd/tool/ClangdMain.cpp:105
 
+static llvm::cl::opt LimitWorkspaceSymbolResult(
+"workspace-symbol-limit",

MaskRay wrote:
> malaperle wrote:
> > sammccall wrote:
> > > the -completion-limit was mostly to control rollout, I'm not sure this 
> > > needs to be a flag. If it does, can we make it the same flag as 
> > > completions (and call it -limit or so?)
> > I think it's quite similar to "completions", when you type just one letter 
> > for example, you can get a lot of results and a lot of JSON output. So it 
> > feels like the flag could apply to both completions and workspace symbols. 
> > How about -limit-resuts? I think just -limit might be a bit too general as 
> > we might want to limit other things.
> Can these options be set by LSP initialization options?
They could. Are you say they *should*? We could add it in 
DidChangeConfigurationParams/ClangdConfigurationParamsChange 
(workspace/didChangeConfiguration) if we need to. I haven't tried or needed to 
add it on the client side though. It's not 100% clear what should go in 
workspace/didChangeConfiguration but I think it should probably things that the 
user would change more often at run-time. I'm not sure how frequent this 
"limit" will be changed by the user.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D44882



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


r328731 - [ObjC++] Make parameter passing and function return compatible with ObjC

2018-03-28 Thread Akira Hatanaka via cfe-commits
Author: ahatanak
Date: Wed Mar 28 14:13:14 2018
New Revision: 328731

URL: http://llvm.org/viewvc/llvm-project?rev=328731&view=rev
Log:
[ObjC++] Make parameter passing and function return compatible with ObjC

ObjC and ObjC++ pass non-trivial structs in a way that is incompatible
with each other. For example:

typedef struct {
  id f0;
  __weak id f1;
} S;

// this code is compiled in c++.
extern "C" {
  void foo(S s);
}

void caller() {
  // the caller passes the parameter indirectly and destructs it.
  foo(S());
}

// this function is compiled in c.
// 'a' is passed directly and is destructed in the callee.
void foo(S a) {
}

This patch fixes the incompatibility by passing and returning structs
with __strong or weak fields using the C ABI in C++ mode. __strong and
__weak fields in a struct do not cause the struct to be destructed in
the caller and __strong fields do not cause the struct to be passed
indirectly.

Also, this patch fixes the microsoft ABI bug mentioned here:

https://reviews.llvm.org/D41039?id=128767#inline-364710

rdar://problem/38887866

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

Added:
cfe/trunk/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
  - copied, changed from r328730, 
cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm
Removed:
cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm
Modified:
cfe/trunk/include/clang/AST/Decl.h
cfe/trunk/include/clang/AST/DeclCXX.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Basic/LangOptions.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/lib/AST/DeclCXX.cpp
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets/X86.h
cfe/trunk/lib/CodeGen/CGCall.cpp
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
cfe/trunk/test/CodeGenObjCXX/arc-special-member-functions.mm
cfe/trunk/test/CodeGenObjCXX/property-dot-copy-elision.mm

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=328731&r1=328730&r2=328731&view=diff
==
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Mar 28 14:13:14 2018
@@ -3559,6 +3559,11 @@ class RecordDecl : public TagDecl {
   /// pass an object of this class.
   bool CanPassInRegisters : 1;
 
+  /// Indicates whether this struct is destroyed in the callee. This flag is
+  /// meaningless when Microsoft ABI is used since parameters are always
+  /// destroyed in the callee.
+  bool ParamDestroyedInCallee : 1;
+
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
@@ -3654,6 +3659,14 @@ public:
 CanPassInRegisters = CanPass;
   }
 
+  bool isParamDestroyedInCallee() const {
+return ParamDestroyedInCallee;
+  }
+
+  void setParamDestroyedInCallee(bool V) {
+ParamDestroyedInCallee = V;
+  }
+
   /// \brief Determines whether this declaration represents the
   /// injected class name.
   ///

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=328731&r1=328730&r2=328731&view=diff
==
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Wed Mar 28 14:13:14 2018
@@ -1468,13 +1468,6 @@ public:
 return data().HasIrrelevantDestructor;
   }
 
-  /// Determine whether the triviality for the purpose of calls for this class
-  /// is overridden to be trivial because this class or the type of one of its
-  /// subobjects has attribute "trivial_abi".
-  bool hasTrivialABIOverride() const {
-return canPassInRegisters() && hasNonTrivialDestructor();
-  }
-
   /// \brief Determine whether this class has a non-literal or/ volatile type
   /// non-static data member or base class.
   bool hasNonLiteralTypeFieldsOrBases() const {

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=328731&r1=328730&r2=328731&view=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clan

[PATCH] D44908: [ObjC++] Make parameter passing and function return compatible with ObjC

2018-03-28 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC328731: [ObjC++] Make parameter passing and function return 
compatible with ObjC (authored by ahatanak, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44908?vs=139935&id=140137#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44908

Files:
  include/clang/AST/Decl.h
  include/clang/AST/DeclCXX.h
  include/clang/AST/Type.h
  include/clang/Basic/LangOptions.def
  include/clang/Basic/LangOptions.h
  include/clang/Basic/TargetInfo.h
  include/clang/Frontend/CodeGenOptions.def
  lib/AST/ASTContext.cpp
  lib/AST/Decl.cpp
  lib/AST/DeclCXX.cpp
  lib/AST/Type.cpp
  lib/Basic/TargetInfo.cpp
  lib/Basic/Targets/X86.h
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  lib/CodeGen/TargetInfo.cpp
  lib/Frontend/CompilerInvocation.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
  test/CodeGenObjCXX/arc-special-member-functions.mm
  test/CodeGenObjCXX/objc-struct-cxx-abi.mm
  test/CodeGenObjCXX/property-dot-copy-elision.mm
  test/CodeGenObjCXX/trivial_abi.mm

Index: include/clang/AST/DeclCXX.h
===
--- include/clang/AST/DeclCXX.h
+++ include/clang/AST/DeclCXX.h
@@ -1468,13 +1468,6 @@
 return data().HasIrrelevantDestructor;
   }
 
-  /// Determine whether the triviality for the purpose of calls for this class
-  /// is overridden to be trivial because this class or the type of one of its
-  /// subobjects has attribute "trivial_abi".
-  bool hasTrivialABIOverride() const {
-return canPassInRegisters() && hasNonTrivialDestructor();
-  }
-
   /// \brief Determine whether this class has a non-literal or/ volatile type
   /// non-static data member or base class.
   bool hasNonLiteralTypeFieldsOrBases() const {
Index: include/clang/AST/Decl.h
===
--- include/clang/AST/Decl.h
+++ include/clang/AST/Decl.h
@@ -3559,6 +3559,11 @@
   /// pass an object of this class.
   bool CanPassInRegisters : 1;
 
+  /// Indicates whether this struct is destroyed in the callee. This flag is
+  /// meaningless when Microsoft ABI is used since parameters are always
+  /// destroyed in the callee.
+  bool ParamDestroyedInCallee : 1;
+
 protected:
   RecordDecl(Kind DK, TagKind TK, const ASTContext &C, DeclContext *DC,
  SourceLocation StartLoc, SourceLocation IdLoc,
@@ -3654,6 +3659,14 @@
 CanPassInRegisters = CanPass;
   }
 
+  bool isParamDestroyedInCallee() const {
+return ParamDestroyedInCallee;
+  }
+
+  void setParamDestroyedInCallee(bool V) {
+ParamDestroyedInCallee = V;
+  }
+
   /// \brief Determines whether this declaration represents the
   /// injected class name.
   ///
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -808,11 +808,6 @@
   /// Return true if this is a trivially copyable type (C++0x [basic.types]p9)
   bool isTriviallyCopyableType(const ASTContext &Context) const;
 
-  /// Determine whether this is a class whose triviality for the purpose of
-  /// calls is overridden to be trivial because the class or the type of one of
-  /// its subobjects has attribute "trivial_abi".
-  bool hasTrivialABIOverride() const;
-
   // Don't promise in the API that anything besides 'const' can be
   // easily added.
 
Index: include/clang/Basic/TargetInfo.h
===
--- include/clang/Basic/TargetInfo.h
+++ include/clang/Basic/TargetInfo.h
@@ -1053,6 +1053,14 @@
 }
   }
 
+  enum CallingConvKind {
+CCK_Default,
+CCK_ClangABI4OrPS4,
+CCK_MicrosoftX86_64
+  };
+
+  virtual CallingConvKind getCallingConvKind(bool ClangABICompat4) const;
+
   /// Controls if __builtin_longjmp / __builtin_setjmp can be lowered to
   /// llvm.eh.sjlj.longjmp / llvm.eh.sjlj.setjmp.
   virtual bool hasSjLjLowering() const {
Index: include/clang/Basic/LangOptions.h
===
--- include/clang/Basic/LangOptions.h
+++ include/clang/Basic/LangOptions.h
@@ -102,6 +102,23 @@
 MSVC2015 = 19
   };
 
+  /// Clang versions with different platform ABI conformance.
+  enum class ClangABI {
+/// Attempt to be ABI-compatible with code generated by Clang 3.8.x
+/// (SVN r257626). This causes <1 x long long> to be passed in an
+/// integer register instead of an SSE register on x64_64.
+Ver3_8,
+
+/// Attempt to be ABI-compatible with code generated by Clang 4.0.x
+/// (SVN r291814). This causes move operations to be ignored when
+/// determining whether a class type can be passed or returned directly.
+Ver4,
+
+/// Co

[PATCH] D44908: [ObjC++] Make parameter passing and function return compatible with ObjC

2018-03-28 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328731: [ObjC++] Make parameter passing and function return 
compatible with ObjC (authored by ahatanak, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44908?vs=139935&id=140138#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44908

Files:
  cfe/trunk/include/clang/AST/Decl.h
  cfe/trunk/include/clang/AST/DeclCXX.h
  cfe/trunk/include/clang/AST/Type.h
  cfe/trunk/include/clang/Basic/LangOptions.def
  cfe/trunk/include/clang/Basic/LangOptions.h
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/AST/ASTContext.cpp
  cfe/trunk/lib/AST/Decl.cpp
  cfe/trunk/lib/AST/DeclCXX.cpp
  cfe/trunk/lib/AST/Type.cpp
  cfe/trunk/lib/Basic/TargetInfo.cpp
  cfe/trunk/lib/Basic/Targets/X86.h
  cfe/trunk/lib/CodeGen/CGCall.cpp
  cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
  cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
  cfe/trunk/lib/CodeGen/TargetInfo.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
  cfe/trunk/lib/Serialization/ASTWriter.cpp
  cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
  cfe/trunk/test/CodeGenCXX/microsoft-abi-sret-and-byval.cpp
  cfe/trunk/test/CodeGenObjCXX/arc-special-member-functions.mm
  cfe/trunk/test/CodeGenObjCXX/objc-struct-cxx-abi.mm
  cfe/trunk/test/CodeGenObjCXX/property-dot-copy-elision.mm
  cfe/trunk/test/CodeGenObjCXX/trivial_abi.mm

Index: cfe/trunk/lib/AST/DeclCXX.cpp
===
--- cfe/trunk/lib/AST/DeclCXX.cpp
+++ cfe/trunk/lib/AST/DeclCXX.cpp
@@ -801,7 +801,17 @@
 struct DefinitionData &Data = data();
 Data.PlainOldData = false;
 Data.HasTrivialSpecialMembers = 0;
-Data.HasTrivialSpecialMembersForCall = 0;
+
+// __strong or __weak fields do not make special functions non-trivial
+// for the purpose of calls.
+Qualifiers::ObjCLifetime LT = T.getQualifiers().getObjCLifetime();
+if (LT != Qualifiers::OCL_Strong && LT != Qualifiers::OCL_Weak)
+  data().HasTrivialSpecialMembersForCall = 0;
+
+// Structs with __weak fields should never be passed directly.
+if (LT == Qualifiers::OCL_Weak)
+  setCanPassInRegisters(false);
+
 Data.HasIrrelevantDestructor = false;
   } else if (!Context.getLangOpts().ObjCAutoRefCount) {
 setHasObjectMember(true);
Index: cfe/trunk/lib/AST/Decl.cpp
===
--- cfe/trunk/lib/AST/Decl.cpp
+++ cfe/trunk/lib/AST/Decl.cpp
@@ -3951,7 +3951,7 @@
   LoadedFieldsFromExternalStorage(false),
   NonTrivialToPrimitiveDefaultInitialize(false),
   NonTrivialToPrimitiveCopy(false), NonTrivialToPrimitiveDestroy(false),
-  CanPassInRegisters(true) {
+  CanPassInRegisters(true), ParamDestroyedInCallee(false) {
   assert(classof(static_cast(this)) && "Invalid Kind!");
 }
 
Index: cfe/trunk/lib/AST/ASTContext.cpp
===
--- cfe/trunk/lib/AST/ASTContext.cpp
+++ cfe/trunk/lib/AST/ASTContext.cpp
@@ -2643,9 +2643,11 @@
 }
 
 bool ASTContext::isParamDestroyedInCallee(QualType T) const {
-  return getTargetInfo().getCXXABI().areArgsDestroyedLeftToRightInCallee() ||
- T.hasTrivialABIOverride() ||
- T.isDestructedType() == QualType::DK_nontrivial_c_struct;
+  if (getTargetInfo().getCXXABI().areArgsDestroyedLeftToRightInCallee())
+return true;
+  if (const auto *RT = T->getBaseElementTypeUnsafe()->getAs())
+return RT->getDecl()->isParamDestroyedInCallee();
+  return false;
 }
 
 /// getComplexType - Return the uniqued reference to the type for a complex
Index: cfe/trunk/lib/AST/Type.cpp
===
--- cfe/trunk/lib/AST/Type.cpp
+++ cfe/trunk/lib/AST/Type.cpp
@@ -2195,12 +2195,6 @@
   return false;
 }
 
-bool QualType::hasTrivialABIOverride() const {
-  if (const auto *RD = getTypePtr()->getAsCXXRecordDecl())
-return RD->hasTrivialABIOverride();
-  return false;
-}
-
 bool QualType::isNonWeakInMRRWithObjCWeak(const ASTContext &Context) const {
   return !Context.getLangOpts().ObjCAutoRefCount &&
  Context.getLangOpts().ObjCWeak &&
Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -15461,8 +15461,10 @@
   QualType::PrimitiveCopyKind PCK = FT.isNonTrivialToPrimitiveCopy();
   if (PCK != QualType::PCK_Trivial && PCK != QualType::PCK_VolatileTrivial)
 Record->setNonTrivialToPrimitiveCopy(true);
-  if (FT.isDestructedType())
+  if (FT.isDestructedType()) {
 Record->setNonTrivialToPrimitiveDestroy(true);

[PATCH] D44985: Remove initializer for CUDA shared varirable

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In https://reviews.llvm.org/D44985#1050674, @yaxunl wrote:

> In https://reviews.llvm.org/D44985#1050670, @rjmccall wrote:
>
> > What exactly are you trying to express here?  Are you just trying to make 
> > these external declarations when compiling for the device because 
> > `__shared__` variables are actually defined on the host?  That should be 
> > handled by the frontend by setting up the AST so that these declarations 
> > are not definitions.
>
>
> No. These variables are not like external symbols defined on the host. They 
> behave like global variables in the kernel code but never initialized. 
> Currently no targets are able to initialize them and it is users' 
> responsibility to initialize them explicitly.
>
> Giving them an initial value will cause error in some backends since they 
> cannot handle them, therefore put undef as initializer.


So undef is being used as a special marker to the backends that it's okay not 
to try to initialize these variables?


https://reviews.llvm.org/D44985



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


[PATCH] D44987: Disable emitting static extern C aliases for amdgcn target for CUDA

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.

LGTM.


https://reviews.llvm.org/D44987



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


[PATCH] D44747: Set calling convention for CUDA kernel

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D44747



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


[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In https://reviews.llvm.org/D44494#1050803, @mstorsjo wrote:

> In https://reviews.llvm.org/D44494#1050797, @mstorsjo wrote:
>
> > This else clause isn't about `.eh_frame` vs `.eh_frame_hdr`, but about 
> > registering a single FDE (which libunwind's `__register_frame` currently 
> > does) vs registering a full `.eh_frame` section (which libgcc's 
> > `__register_frame` does).
>
>
> However, this function actually just is `_unw_add_dynamic_fde`, while 
> `__register_frame` in `UnwindLevel1-gcc-ext.c` just calls this function. So 
> we should probably check there instead, whether it's an FDE (which libgcc 
> doesn't support via that entry point) or a full `.eh_frame` section.


In this case, it triggers the "FDE is really a CIE" case in decodeFDE, so we 
could do a quick check in `__register_frame` and see if it is a CIE or an FDE, 
and then call the right underlying functions based on that, instead of adding 
it in the error handling else statement like this.


https://reviews.llvm.org/D44494



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


[PATCH] D44968: [ObjC] Generalize NRVO to cover C structs

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Wow, the IR improvements here are amazing.




Comment at: lib/CodeGen/CGDecl.cpp:1119
+if ((CXXRD && !CXXRD->hasTrivialDestructor()) ||
+RD->isNonTrivialToPrimitiveCopy()) {
   // Create a flag that is used to indicate when the NRVO was applied

This should be isNonTrivialToPrimitiveDestroy(), I think.  The dynamic NRVO 
flag is specifically tied to whether we should destroy the local variable in 
its normal cleanup.


Repository:
  rC Clang

https://reviews.llvm.org/D44968



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


[PATCH] D44494: [libunwind] Support __register_frame with a full .eh_frame section

2018-03-28 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a subscriber: joerg.
mstorsjo added a comment.

Also, relating to this, @joerg mentioned on irc that one should rather use 
`__register_frame_info_bases` instead of `__register_frame`. That function is a 
bit tricky to call though, since it uses a libgcc internal struct `struct 
object`, only available in libgcc headers and in Unwind_AppleExtras.cpp (as 
struct libgcc_object, with the comment "undocumented libgcc struct object").


https://reviews.llvm.org/D44494



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


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

lebedev.ri wrote:
> rjmccall wrote:
> > lebedev.ri wrote:
> > > rjmccall wrote:
> > > > I think doing this here can result in double-warning if the overload 
> > > > resolves to a builtin operator.  Now, it might not actually be possible 
> > > > for that to combine with the requirements for self-assignment, but 
> > > > still, I think the right place to diagnose this for C++ is the same 
> > > > place we call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > > 
> > > > Can CheckIdentityFieldAssignment just be integrated with 
> > > > DiagnoseSelfAssignment so that callers don't need to do call both?
> > > > I think the right place to diagnose this for C++ is the same place we 
> > > > call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > 
> > > ```
> > > switch (Opc) {
> > > case BO_Assign:
> > > case BO_DivAssign:
> > > case BO_SubAssign:
> > > case BO_AndAssign:
> > > case BO_OrAssign:
> > > case BO_XorAssign:
> > >   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
> > >   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
> > >   break;
> > > default:
> > >   break;
> > > }
> > > 
> > > // Check for a self move.
> > > if (Op == OO_Equal)
> > >   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> > > ```
> > > 
> > > 
> > > ^ That does not appear to work. Pretty much all these tests start to fail.
> > > 
> > Okay.  It's possible that my suggestion is wrong.  Can you explain more how 
> > they fail?
> Right, i should have been verbose :)
> There are no test changes as compared to the current diff.
> Here is the output of `$ ninja check-clang-sema check-clang-semacxx`
> {F5920055}
> It is also totally possible that i'm missing something obvious on my end...
Oh, DiagnoseSelfAssignment disables itself during template instantiation, 
presumably because it's an easy syntactic check that will always warn on the 
parsed code and so doesn't need to warn again during instantiation.

In that case, I think the place you had the check is fine.


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


r328735 - [Basic] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

2018-03-28 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Wed Mar 28 15:09:09 2018
New Revision: 328735

URL: http://llvm.org/viewvc/llvm-project?rev=328735&view=rev
Log:
[Basic] Fix some Clang-tidy modernize and Include What You Use warnings; other 
minor fixes (NFC).

Modified:
cfe/trunk/include/clang/Basic/AddressSpaces.h
cfe/trunk/include/clang/Basic/CommentOptions.h
cfe/trunk/include/clang/Basic/FileSystemStatCache.h
cfe/trunk/include/clang/Basic/Linkage.h
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/include/clang/Basic/Sanitizers.h
cfe/trunk/include/clang/Basic/VirtualFileSystem.h
cfe/trunk/lib/Basic/FileSystemStatCache.cpp
cfe/trunk/lib/Basic/ObjCRuntime.cpp
cfe/trunk/lib/Basic/Sanitizers.cpp
cfe/trunk/lib/Basic/VirtualFileSystem.cpp

Modified: cfe/trunk/include/clang/Basic/AddressSpaces.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AddressSpaces.h?rev=328735&r1=328734&r2=328735&view=diff
==
--- cfe/trunk/include/clang/Basic/AddressSpaces.h (original)
+++ cfe/trunk/include/clang/Basic/AddressSpaces.h Wed Mar 28 15:09:09 2018
@@ -1,4 +1,4 @@
-//===--- AddressSpaces.h - Language-specific address spaces -*- C++ 
-*-===//
+//===- AddressSpaces.h - Language-specific address spaces ---*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -6,17 +6,17 @@
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
-///
+//
 /// \file
 /// \brief Provides definitions for the various language-specific address
 /// spaces.
-///
+//
 
//===--===//
 
 #ifndef LLVM_CLANG_BASIC_ADDRESSSPACES_H
 #define LLVM_CLANG_BASIC_ADDRESSSPACES_H
 
-#include 
+#include 
 
 namespace clang {
 
@@ -51,7 +51,7 @@ enum class LangAS : unsigned {
 
 /// The type of a lookup table which maps from language-specific address spaces
 /// to target-specific ones.
-typedef unsigned LangASMap[(unsigned)LangAS::FirstTargetAddressSpace];
+using LangASMap = unsigned[(unsigned)LangAS::FirstTargetAddressSpace];
 
 /// \return whether \p AS is a target-specific address space rather than a
 /// clang AST address space
@@ -71,4 +71,4 @@ inline LangAS getLangASFromTargetAS(unsi
 
 } // namespace clang
 
-#endif
+#endif // LLVM_CLANG_BASIC_ADDRESSSPACES_H

Modified: cfe/trunk/include/clang/Basic/CommentOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CommentOptions.h?rev=328735&r1=328734&r2=328735&view=diff
==
--- cfe/trunk/include/clang/Basic/CommentOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CommentOptions.h Wed Mar 28 15:09:09 2018
@@ -1,4 +1,4 @@
-//===--- CommentOptions.h - Options for parsing comments -*- C++ -*-===//
+//===- CommentOptions.h - Options for parsing comments --*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -6,10 +6,10 @@
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
-///
+//
 /// \file
 /// \brief Defines the clang::CommentOptions interface.
-///
+//
 
//===--===//
 
 #ifndef LLVM_CLANG_BASIC_COMMENTOPTIONS_H
@@ -22,18 +22,18 @@ namespace clang {
 
 /// \brief Options for controlling comment parsing.
 struct CommentOptions {
-  typedef std::vector BlockCommandNamesTy;
+  using BlockCommandNamesTy = std::vector;
 
   /// \brief Command names to treat as block commands in comments.
   /// Should not include the leading backslash.
   BlockCommandNamesTy BlockCommandNames;
 
   /// \brief Treat ordinary comments as documentation comments.
-  bool ParseAllComments;
+  bool ParseAllComments = false;
 
-  CommentOptions() : ParseAllComments(false) { }
+  CommentOptions() = default;
 };
 
-}  // end namespace clang
+} // namespace clang
 
-#endif
+#endif // LLVM_CLANG_BASIC_COMMENTOPTIONS_H

Modified: cfe/trunk/include/clang/Basic/FileSystemStatCache.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/FileSystemStatCache.h?rev=328735&r1=328734&r2=328735&view=diff
==
--- cfe/trunk/include/clang/Basic/FileSystemStatCache.h (original)
+++ cfe/trunk/include/clang/Basic/FileSystemStatCache.h Wed Mar 28 15:09:09 2018
@@ -1,4 +1,4 @@
-//===--- FileSystemStatCache.h - Caching for 'stat' calls ---*- C++ 
-*-===//
+//===- FileSystemStatCache.h - Caching for 'stat' calls -*- C++ 
-*-===//
 //
 // The LLVM Compiler Infrastructure
 //
@@ -6,10 +6,10 @@
 // License. See LICENSE.TXT for details.
 //
 
//===--===//
-///
+//
 /// \file
 /// \brief 

[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Will do stage2 testing next..




Comment at: lib/Sema/SemaExpr.cpp:12087
+  case BO_AndAssign:
+  case BO_OrAssign:
+DiagnoseSelfAssignment(S, LHS, RHS, OpLoc, /*IsBuiltin=*/false);

lebedev.ri wrote:
> rjmccall wrote:
> > Quuxplusone wrote:
> > > I understand why `x &= x` and `x |= x` are mathematically special for the 
> > > built-in types, but surely `x -= x` and `x ^= x` and `x /= x` are just as 
> > > likely to indicate programmer error. I would be happy if Clang either 
> > > took the philosophical stance "We will diagnose `x = x` but uniformly 
> > > //never// `x op= x`," or else took the pragmatic stance "We will diagnose 
> > > any `x op= x` or `x op x` that seems likely to be a programming bug." 
> > > This "middle way" of warning only for `&=` and `|=` is bothersome to me.
> > I think "we want to diagnose anything that seems likely to be a programming 
> > bug" is already our policy here.  It's inevitable that we'll overlook 
> > examples of that.  I agree that we should apply this warning to at least 
> > -=, ^=, and /=.
> Ok, will extend.
Would it make sense to also check `%=`?
It's a direct counterpart to `/=`, so i guess it would?



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

rjmccall wrote:
> lebedev.ri wrote:
> > rjmccall wrote:
> > > lebedev.ri wrote:
> > > > rjmccall wrote:
> > > > > I think doing this here can result in double-warning if the overload 
> > > > > resolves to a builtin operator.  Now, it might not actually be 
> > > > > possible for that to combine with the requirements for 
> > > > > self-assignment, but still, I think the right place to diagnose this 
> > > > > for C++ is the same place we call DiagnoseSelfMove in 
> > > > > CreateOverloadedBinOp.
> > > > > 
> > > > > Can CheckIdentityFieldAssignment just be integrated with 
> > > > > DiagnoseSelfAssignment so that callers don't need to do call both?
> > > > > I think the right place to diagnose this for C++ is the same place we 
> > > > > call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > > 
> > > > ```
> > > > switch (Opc) {
> > > > case BO_Assign:
> > > > case BO_DivAssign:
> > > > case BO_SubAssign:
> > > > case BO_AndAssign:
> > > > case BO_OrAssign:
> > > > case BO_XorAssign:
> > > >   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
> > > >   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
> > > >   break;
> > > > default:
> > > >   break;
> > > > }
> > > > 
> > > > // Check for a self move.
> > > > if (Op == OO_Equal)
> > > >   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> > > > ```
> > > > 
> > > > 
> > > > ^ That does not appear to work. Pretty much all these tests start to 
> > > > fail.
> > > > 
> > > Okay.  It's possible that my suggestion is wrong.  Can you explain more 
> > > how they fail?
> > Right, i should have been verbose :)
> > There are no test changes as compared to the current diff.
> > Here is the output of `$ ninja check-clang-sema check-clang-semacxx`
> > {F5920055}
> > It is also totally possible that i'm missing something obvious on my end...
> Oh, DiagnoseSelfAssignment disables itself during template instantiation, 
> presumably because it's an easy syntactic check that will always warn on the 
> parsed code and so doesn't need to warn again during instantiation.
> 
> In that case, I think the place you had the check is fine.
Am i correctly reading that as "ok, keep it as it is, in 
`BuildOverloadedBinOp()`" ?


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added inline comments.



Comment at: lib/CodeGen/CGCXXABI.h:610
 
+struct CatchRetScope final : EHScopeStack::Cleanup {
+  llvm::CatchPadInst *CPI;

dschuff wrote:
> Should be `public`?
This code was moved from [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/MicrosoftCXXABI.cpp#L865
 | here ]] in `lib/CodeGen/MicrosoftCXXABI.cpp`. There are dozens of classes 
inheriting from `EHScopeStack::Cleanup` and they all use private inheritance. 
Examples [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/CGDecl.cpp#L449
 | 1 ]] [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/CGDecl.cpp#L504
 | 2 ]] [[ 
https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/CGException.cpp#L347
 | 3 ]] [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/ItaniumCXXABI.cpp#L3728
 | 4 ]] 

The [[ 
https://github.com/llvm-mirror/clang/blob/c4bfd75d786a2a77c779cee6976534f37202ac21/lib/CodeGen/EHScopeStack.h#L140-L147
 | comment ]] from `EHScopeStack::Cleanup` says all subclasses must be 
POD-like, which I guess is the reason, but I'm not very sure.



Comment at: lib/CodeGen/CGCleanup.h:630
   static const EHPersonality MSVC_CxxFrameHandler3;
+  static const EHPersonality GNU_Wasm_CPlusCPlus;
 

dschuff wrote:
> We might consider having 2 personalities: one for use with builtin 
> exceptions, and other for emulated exceptions? I'm imagining that with this 
> style of IR we might be able to do emulated exceptions better than we have 
> for emscripten today. We don't have to think about that now, but maybe the 
> name of the personality might reflect it: e.g. `GNU_Wasm_CPlusPlus_Native` 
> (or builtin) vs `GNU_Wasm_CPlusPlus_Emulated` (or external).
(We talked in person :) ) I'll think about it. But I guess we can change the 
name once we start implementing that feature?



Comment at: lib/CodeGen/CGException.cpp:1236
+  // them, we should unwind to the next EH enclosing scope. We generate a call
+  // to rethrow function here to do that.
+  if (EHPersonality::get(*this).isWasmPersonality() && !HasCatchAll) {

dschuff wrote:
> Why do we need to call `__cxa_rethrow` instead of just emitting a rethrow 
> instruction intrinsic to unwind?
Because we have to run the library code as well. As well as in other functions 
in libcxxabi, [[ 
https://github.com/llvm-mirror/libcxxabi/blob/565ba0415b6b17bbca46820a0fcfe4b6ab5abce2/src/cxa_exception.cpp#L571-L607
 | `__cxa_rethrow` ]] has some bookeeping code like incrementing the handler 
count or something. After it is re-caught by an enclosing scope, it is 
considered as a newly thrown exception and the enclosing scope is run functions 
like `__cxa_begin_catch` and `__cxa_end_catch`. So we also have to run 
`__cxa_rethrow` when rethrowing something to make sure everything is matched. 

The actual `rethrow` instruction will be added next to `__cxa_rethrow` in the 
backend, or can be embedded within `__cxa_rethrow` function later if we decide 
how to pass an exception value to a function. (which might be one reason why we 
want to keep the first-class exception thing)



Comment at: lib/CodeGen/CGException.cpp:1534
+  // In case of wasm personality, we need to pass the exception value to
+  // __clang_call_terminate function.
+  if (getLangOpts().CPlusPlus &&

dschuff wrote:
> Why?
Not strictly necessarily, because we can modify libcxxabi to our liking. I was 
trying to keep the same behavior as Itanium-style libcxxabi. The 
`__clang_call_terminate` function that's called when an EH cleanup throws is as 
follows:
```
; Function Attrs: noinline noreturn nounwind
 
define linkonce_odr hidden void @__clang_call_terminate(i8*) #6 comdat {
 
  %2 = call i8* @__cxa_begin_catch(i8* %0) #2   
 
  call void @_ZSt9terminatev() #8   
 
  unreachable   
 
}   
```

So it calls `__cxa_begin_catch` on the exception value before calling 
`std::terminate`. We can change this behavior for wasm if we want, and I guess 
we need some proxy object in case of a foreign exception, but anyway I was 
trying to keep the behavior the same unless there's any reason not to.



Comment at: test/CodeGenCXX/wasm-eh.cpp:33
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* 
bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)]
+// CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.get.exception()
+// CHECK-NEXT:   store i8* %[[EXN]], i8** %exn.slot

majnemer wrote:
> I'd expect a funclet bundle operand here..
Even if it cannot throw? Looks like even 
`CodeGenFu

[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 140144.
aheejin marked an inline comment as done.
aheejin added a comment.

- Rebase & Simplified the if condition


Repository:
  rC Clang

https://reviews.llvm.org/D44931

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGCleanup.cpp
  lib/CodeGen/CGCleanup.h
  lib/CodeGen/CGException.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/wasm-eh.cpp

Index: test/CodeGenCXX/wasm-eh.cpp
===
--- /dev/null
+++ test/CodeGenCXX/wasm-eh.cpp
@@ -0,0 +1,346 @@
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+
+void may_throw();
+void dont_throw() noexcept;
+
+struct Cleanup {
+  ~Cleanup() { dont_throw(); }
+};
+
+// Multiple catch clauses w/o catch-all
+void test0() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (double) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: define void @_Z5test0v() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+
+// CHECK:   %[[INT_ALLOCA:.*]] = alloca i32
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label %[[NORMAL_BB:.*]] unwind label %[[CATCHDISPATCH_BB:.*]]
+
+// CHECK: [[CATCHDISPATCH_BB]]:
+// CHECK-NEXT:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)]
+// CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.get.exception()
+// CHECK-NEXT:   store i8* %[[EXN]], i8** %exn.slot
+// CHECK-NEXT:   %[[SELECTOR:.*]] = call i32 @llvm.wasm.get.ehselector()
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_INT_BB:.*]], label %[[CATCH_FALLTHROUGH_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK-NEXT:   %[[EXN:.*]] = load i8*, i8** %exn.slot
+// CHECK-NEXT:   %[[ADDR:.*]] = call i8* @__cxa_begin_catch(i8* %[[EXN]]) {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   %[[ADDR_CAST:.*]] = bitcast i8* %[[ADDR]] to i32*
+// CHECK-NEXT:   %[[INT_VAL:.*]] = load i32, i32* %[[ADDR_CAST]]
+// CHECK-NEXT:   store i32 %[[INT_VAL]], i32* %[[INT_ALLOCA]]
+// CHECK-NEXT:   call void @_Z10dont_throwv() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   call void @__cxa_end_catch() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB0:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB0]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB:.*]]
+
+// CHECK: [[CATCH_FALLTHROUGH_BB]]
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTId to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_FLOAT_BB:.*]], label %[[RETHROW_BB:.*]]
+
+// CHECK: [[CATCH_FLOAT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB1:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB1]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB]]
+
+// CHECK: [[RETHROW_BB]]:
+// CHECK-NEXT:   call void @__cxa_rethrow() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   unreachable
+
+
+// Single catch-all
+void test1() {
+  try {
+may_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CATCH-LABEL: @_Z5test1v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* null]
+// CHECK:   br label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Multiple catch clauses w/ catch-all
+void test2() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: @_Z5test2v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* null]
+// CHECK:   br i1 %{{.*}}, label %[[CATCH_INT_BB:.*]], label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Cleanup
+void test3() {
+  Cleanup c;
+  may_throw();
+}
+
+// CHECK-LABEL: @_Z5test3v()
+
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label {{

[PATCH] D45002: [test] Conservatively re-enable a FreeBSD/XRay test

2018-03-28 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray created this revision.
lichray added reviewers: devnexen, krytarowski.
Herald added subscribers: dberris, emaste.

Fixing clang-test on FreeBSD as a follow-up of https://reviews.llvm.org/D43378 
to handle the revert happened in r325749.


Repository:
  rC Clang

https://reviews.llvm.org/D45002

Files:
  test/Driver/XRay/xray-instrument-os.c


Index: test/Driver/XRay/xray-instrument-os.c
===
--- test/Driver/XRay/xray-instrument-os.c
+++ test/Driver/XRay/xray-instrument-os.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-
+// XFAIL: -linux-, -freebsd
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64
 typedef int a;


Index: test/Driver/XRay/xray-instrument-os.c
===
--- test/Driver/XRay/xray-instrument-os.c
+++ test/Driver/XRay/xray-instrument-os.c
@@ -1,4 +1,4 @@
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-
+// XFAIL: -linux-, -freebsd
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64
 typedef int a;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44968: Generalize NRVO to cover C structs

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rC Clang

https://reviews.llvm.org/D44968



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


[PATCH] D44883: [Sema] Extend -Wself-assign and -Wself-assign-field to warn on overloaded self-assignment (classes)

2018-03-28 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: lib/Sema/SemaExpr.cpp:12093
+break;
+  }
+

lebedev.ri wrote:
> rjmccall wrote:
> > lebedev.ri wrote:
> > > rjmccall wrote:
> > > > lebedev.ri wrote:
> > > > > rjmccall wrote:
> > > > > > I think doing this here can result in double-warning if the 
> > > > > > overload resolves to a builtin operator.  Now, it might not 
> > > > > > actually be possible for that to combine with the requirements for 
> > > > > > self-assignment, but still, I think the right place to diagnose 
> > > > > > this for C++ is the same place we call DiagnoseSelfMove in 
> > > > > > CreateOverloadedBinOp.
> > > > > > 
> > > > > > Can CheckIdentityFieldAssignment just be integrated with 
> > > > > > DiagnoseSelfAssignment so that callers don't need to do call both?
> > > > > > I think the right place to diagnose this for C++ is the same place 
> > > > > > we call DiagnoseSelfMove in CreateOverloadedBinOp.
> > > > > 
> > > > > ```
> > > > > switch (Opc) {
> > > > > case BO_Assign:
> > > > > case BO_DivAssign:
> > > > > case BO_SubAssign:
> > > > > case BO_AndAssign:
> > > > > case BO_OrAssign:
> > > > > case BO_XorAssign:
> > > > >   DiagnoseSelfAssignment(Args[0], Args[1], OpLoc);
> > > > >   CheckIdentityFieldAssignment(Args[0], Args[1], OpLoc);
> > > > >   break;
> > > > > default:
> > > > >   break;
> > > > > }
> > > > > 
> > > > > // Check for a self move.
> > > > > if (Op == OO_Equal)
> > > > >   DiagnoseSelfMove(Args[0], Args[1], OpLoc);
> > > > > ```
> > > > > 
> > > > > 
> > > > > ^ That does not appear to work. Pretty much all these tests start to 
> > > > > fail.
> > > > > 
> > > > Okay.  It's possible that my suggestion is wrong.  Can you explain more 
> > > > how they fail?
> > > Right, i should have been verbose :)
> > > There are no test changes as compared to the current diff.
> > > Here is the output of `$ ninja check-clang-sema check-clang-semacxx`
> > > {F5920055}
> > > It is also totally possible that i'm missing something obvious on my 
> > > end...
> > Oh, DiagnoseSelfAssignment disables itself during template instantiation, 
> > presumably because it's an easy syntactic check that will always warn on 
> > the parsed code and so doesn't need to warn again during instantiation.
> > 
> > In that case, I think the place you had the check is fine.
> Am i correctly reading that as "ok, keep it as it is, in 
> `BuildOverloadedBinOp()`" ?
Yes, I think that's the right place for it, given that it's basically designed 
to only fire during parsing.

We could also just move the check (in all cases) to ActOnBinOp, which is not 
called by template instantiation.


Repository:
  rC Clang

https://reviews.llvm.org/D44883



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


[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, jolesiak.
Herald added subscribers: cfe-commits, klimek.

Currently, indentation of Objective-C method names which are wrapped
onto the next line due to a long return type is controlled by the
style option `IndentWrappedFunctionNames`.

For the Google style, we'd like to indent Objective-C method names
when wrapped onto the next line, but *not* indent non-Objective-C
functions when wrapped onto the next line.

This diff adds a new style option, `IndentWrappedObjCMethodNames`,
with three options:

1. Auto: Keep current behavior (indent ObjC methods according to

`IndentWrappedFunctionNames`)

2. Always: Always indent wrapped ObjC methods

3. Never: Never indent wrapped ObjC methods

In a separate diff, I'll update the Google style to set
`IndentWrappedFunctionNames` to `Always`.

Test Plan: Tests updated. Ran tests with:

  % make -j12 FormatTests && ./tools/clang/unittests/Format/FormatTests


Repository:
  rC Clang

https://reviews.llvm.org/D45004

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -539,6 +539,36 @@
":(int)a\n"
" aaa:(int)a;\n");
 
+  Style.IndentWrappedObjCMethodNames = FormatStyle::IWM_Always;
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
+  Style.IndentWrappedObjCMethodNames = FormatStyle::IWM_Never;
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
   // Continuation indent width should win over aligning colons if the function
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -243,6 +243,16 @@
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO,
+  FormatStyle::IndentWrappedMethodStyle &Value) {
+IO.enumCase(Value, "Auto", FormatStyle::IWM_Auto);
+IO.enumCase(Value, "Always", FormatStyle::IWM_Always);
+IO.enumCase(Value, "Never", FormatStyle::IWM_Never);
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, FormatStyle &Style) {
 // When reading, read the language first, we need it for getPredefinedStyle.
@@ -378,6 +388,8 @@
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
+IO.mapOptional("IndentWrappedObjCMethodNames",
+   Style.IndentWrappedObjCMethodNames);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
@@ -645,6 +657,7 @@
   LLVMStyle.IndentCaseLabels = false;
   LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
   LLVMStyle.IndentWrappedFunctionNames = false;
+  LLVMStyle.IndentWrappedObjCMethodNames = FormatStyle::IWM_Auto;
   LLVMStyle.IndentWidth = 2;
   LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
   LLVMStyle.JavaScriptWrapImports = true;
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndent

[PATCH] D45005: [clang-format] Set IndentWrappedObjCMethodNames to Always in google style

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton created this revision.
benhamilton added reviewers: djasper, klimek, jolesiak.
Herald added a subscriber: cfe-commits.

Now that we can separately control ObjC method name wrapping
and non-ObjC function name wrapping, this diff sets
`IndentWrappedObjCMethodNames` to `Always` for the Google style.

Depends On https://reviews.llvm.org/D45004

Test Plan: Updated test which manually set
`IndentWrappedFunctionNames` to no longer set that, confirmed
tests which depended on indenting wrapped ObjC method names
still passed.


Repository:
  rC Clang

https://reviews.llvm.org/D45005

Files:
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -573,7 +573,6 @@
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   Style.ColumnLimit = 40;
-  Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
"dontAlignNamef:(NSRect)theRect {\n"
"}");
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -726,6 +726,7 @@
   {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
+  GoogleStyle.IndentWrappedObjCMethodNames = FormatStyle::IWM_Always;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
   GoogleStyle.ObjCSpaceAfterProperty = false;


Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -573,7 +573,6 @@
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
   Style.ColumnLimit = 40;
-  Style.IndentWrappedFunctionNames = true;
   verifyFormat("- (void)shortf:(GTMFoo *)theFoo\n"
"dontAlignNamef:(NSRect)theRect {\n"
"}");
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -726,6 +726,7 @@
   {"^", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
   GoogleStyle.IndentCaseLabels = true;
+  GoogleStyle.IndentWrappedObjCMethodNames = FormatStyle::IWM_Always;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
   GoogleStyle.ObjCSpaceAfterProperty = false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added a comment.

Otherwise it looks good to me, although @majnemer would know more about the 
subtleties of what IR actually gets generated.




Comment at: lib/CodeGen/CGCleanup.h:630
   static const EHPersonality MSVC_CxxFrameHandler3;
+  static const EHPersonality GNU_Wasm_CPlusCPlus;
 

aheejin wrote:
> dschuff wrote:
> > We might consider having 2 personalities: one for use with builtin 
> > exceptions, and other for emulated exceptions? I'm imagining that with this 
> > style of IR we might be able to do emulated exceptions better than we have 
> > for emscripten today. We don't have to think about that now, but maybe the 
> > name of the personality might reflect it: e.g. `GNU_Wasm_CPlusPlus_Native` 
> > (or builtin) vs `GNU_Wasm_CPlusPlus_Emulated` (or external).
> (We talked in person :) ) I'll think about it. But I guess we can change the 
> name once we start implementing that feature?
Sounds good. BTW this should actually be `GNU_Wasm_CPlusPlus` instead of 
`GNU_Wasm_CPlusCPlus`



Comment at: lib/CodeGen/CGException.cpp:1534
+  // In case of wasm personality, we need to pass the exception value to
+  // __clang_call_terminate function.
+  if (getLangOpts().CPlusPlus &&

aheejin wrote:
> dschuff wrote:
> > Why?
> Not strictly necessarily, because we can modify libcxxabi to our liking. I 
> was trying to keep the same behavior as Itanium-style libcxxabi. The 
> `__clang_call_terminate` function that's called when an EH cleanup throws is 
> as follows:
> ```
> ; Function Attrs: noinline noreturn nounwind  
>
> define linkonce_odr hidden void @__clang_call_terminate(i8*) #6 comdat {  
>
>   %2 = call i8* @__cxa_begin_catch(i8* %0) #2 
>
>   call void @_ZSt9terminatev() #8 
>
>   unreachable 
>
> }   
> ```
> 
> So it calls `__cxa_begin_catch` on the exception value before calling 
> `std::terminate`. We can change this behavior for wasm if we want, and I 
> guess we need some proxy object in case of a foreign exception, but anyway I 
> was trying to keep the behavior the same unless there's any reason not to.
Oh I see, we are deviating from MSVC behavior to be more like itanium here. 
Makes sense.



Comment at: lib/CodeGen/CGException.cpp:1541
+  }
   llvm::CallInst *terminateCall =
+  CGM.getCXXABI().emitTerminateForUnexpectedException(*this, Exn);

Should this be in an else block? No need to emit it after we emit the call to 
`__clang_call_terminate`


Repository:
  rC Clang

https://reviews.llvm.org/D44931



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


[PATCH] D45002: [test] Conservatively re-enable a FreeBSD/XRay test

2018-03-28 Thread David CARLIER via Phabricator via cfe-commits
devnexen added inline comments.



Comment at: test/Driver/XRay/xray-instrument-os.c:2
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-
+// XFAIL: -linux-, -freebsd
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64

What output do you get when you use directly llvm-lit on this ?


Repository:
  rC Clang

https://reviews.llvm.org/D45002



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


[PATCH] D44934: [analyzer] Improve the modeling of `memset()`.

2018-03-28 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Why do you need separate code for null and non-null character? The function's 
semantics doesn't seem to care.

I'd rather consider the case of non-concrete character separately. Because 
wiping a region with a symbol is not something we currently support; a symbolic 
default binding over a region means a different thing and it'd be equivalent to 
invalidation, so for non-concrete character we don't have a better choice than 
to invalidate. For concrete non-zero character, on the contrary, a default 
binding would work just fine.

Could you explain why didn't a straightforward `bindLoc` over a base region 
wasn't doing the thing you wanted? I.e., why is new Store API function 
necessary?


Repository:
  rC Clang

https://reviews.llvm.org/D44934



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


[PATCH] D44934: [analyzer] Improve the modeling of `memset()`.

2018-03-28 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

> In addition, `memset` can bind anything to the region, so 
> `getBindingForDerivedDefaultValue()`'s logic needs some adjustment. **The 
> solution in this patch is certainly not correct.**

Yeah, i guess you meant here the thing that i was saying about concrete 
bindings. If we only limit ourselves to concrete bindings, it should work well.


Repository:
  rC Clang

https://reviews.llvm.org/D44934



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


[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton updated this revision to Diff 140155.
benhamilton added a comment.

Fix typo


Repository:
  rC Clang

https://reviews.llvm.org/D45004

Files:
  include/clang/Format/Format.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/Format.cpp
  unittests/Format/FormatTestObjC.cpp

Index: unittests/Format/FormatTestObjC.cpp
===
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -539,6 +539,36 @@
":(int)a\n"
" aaa:(int)a;\n");
 
+  Style.IndentWrappedObjCMethodNames = FormatStyle::IWM_Always;
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
+  Style.IndentWrappedObjCMethodNames = FormatStyle::IWM_Never;
+  verifyFormat("- (a)\n"
+   ";\n");
+  verifyFormat("- (a)\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   " aaa:(int)a\n"
+   ":(int)a;\n");
+  verifyFormat("- (a)\n"
+   ":(int)a\n"
+   " aaa:(int)a;\n");
+
   // Continuation indent width should win over aligning colons if the function
   // name is long.
   Style = getGoogleStyle(FormatStyle::LK_ObjC);
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -243,6 +243,16 @@
   }
 };
 
+template <>
+struct ScalarEnumerationTraits {
+  static void enumeration(IO &IO,
+  FormatStyle::IndentWrappedMethodStyle &Value) {
+IO.enumCase(Value, "Auto", FormatStyle::IWM_Auto);
+IO.enumCase(Value, "Always", FormatStyle::IWM_Always);
+IO.enumCase(Value, "Never", FormatStyle::IWM_Never);
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, FormatStyle &Style) {
 // When reading, read the language first, we need it for getPredefinedStyle.
@@ -378,6 +388,8 @@
 IO.mapOptional("IndentWidth", Style.IndentWidth);
 IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
+IO.mapOptional("IndentWrappedObjCMethodNames",
+   Style.IndentWrappedObjCMethodNames);
 IO.mapOptional("JavaScriptQuotes", Style.JavaScriptQuotes);
 IO.mapOptional("JavaScriptWrapImports", Style.JavaScriptWrapImports);
 IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
@@ -645,6 +657,7 @@
   LLVMStyle.IndentCaseLabels = false;
   LLVMStyle.IndentPPDirectives = FormatStyle::PPDIS_None;
   LLVMStyle.IndentWrappedFunctionNames = false;
+  LLVMStyle.IndentWrappedObjCMethodNames = FormatStyle::IWM_Auto;
   LLVMStyle.IndentWidth = 2;
   LLVMStyle.JavaScriptQuotes = FormatStyle::JSQS_Leave;
   LLVMStyle.JavaScriptWrapImports = true;
Index: lib/Format/ContinuationIndenter.cpp
===
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -26,6 +26,19 @@
 namespace clang {
 namespace format {
 
+// Returns true if a TT_SelectorName should be indented when wrapped,
+// false otherwise.
+static bool shouldIndentWrappedSelectorName(const FormatStyle &Style) {
+  // TT_SelectorName is used across multiple languages; we only want
+  // Style.IndentWrappedObjCMethodNames to apply to ObjC.
+  if (Style.Language == FormatStyle::LK_ObjC)
+return Style.IndentWrappedObjCMethodNames == FormatStyle::IWM_Always ||
+   (Style.IndentWrappedObjCMethodNames == FormatStyle::IWM_Auto &&
+Style.IndentWrappedFunctionNames);
+  else
+return Style.IndentWrappedFunctionNames;
+}
+
 // Returns the length of everything up to the first possible line break after
 // the ), ], } or > matching \c Tok.
 static unsigned getLengthToMatchingParen(const FormatToken &Tok) {
@@ -698,7 +711,7 @@
 State.S

[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added a comment.

What do you think of the name `IndentWrappedObjCMethodSignatures` as an 
alternative to `IndentWrappedObjCMethodNames`? In Objective-C the method name 
might be considered the selector whereas I believe that this option pertains to 
formatting of the method signature?


Repository:
  rC Clang

https://reviews.llvm.org/D45004



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


[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Ben Hamilton via Phabricator via cfe-commits
benhamilton added a comment.

> What do you think of the name IndentWrappedObjCMethodSignatures as an 
> alternative to IndentWrappedObjCMethodNames? In Objective-C the method name 
> might be considered the selector whereas I believe that this option pertains 
> to formatting of the method signature?

This is a good suggestion, but since this is a specialization of 
`IndentWrappedFunctionNames`, I figured keeping the name of the new option 
similar to that would be best.


Repository:
  rC Clang

https://reviews.llvm.org/D45004



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


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin added inline comments.



Comment at: lib/CodeGen/CGException.cpp:1541
+  }
   llvm::CallInst *terminateCall =
+  CGM.getCXXABI().emitTerminateForUnexpectedException(*this, Exn);

dschuff wrote:
> Should this be in an else block? No need to emit it after we emit the call to 
> `__clang_call_terminate`
I don't understand? The call emitted within the `if` block is not a call to 
`__clang_call_terminate` but to `wasm.get.exception` intrinsic.


Repository:
  rC Clang

https://reviews.llvm.org/D44931



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


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Heejin Ahn via Phabricator via cfe-commits
aheejin updated this revision to Diff 140156.
aheejin marked an inline comment as done.
aheejin added a comment.

- GNU_CPlusCPlus -> GNU_CPlusPlus


Repository:
  rC Clang

https://reviews.llvm.org/D44931

Files:
  lib/CodeGen/CGCXXABI.h
  lib/CodeGen/CGCleanup.cpp
  lib/CodeGen/CGCleanup.h
  lib/CodeGen/CGException.cpp
  lib/CodeGen/ItaniumCXXABI.cpp
  lib/CodeGen/MicrosoftCXXABI.cpp
  test/CodeGenCXX/wasm-eh.cpp

Index: test/CodeGenCXX/wasm-eh.cpp
===
--- /dev/null
+++ test/CodeGenCXX/wasm-eh.cpp
@@ -0,0 +1,346 @@
+// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+// RUN: %clang_cc1 %s -triple wasm64-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 | FileCheck %s
+
+void may_throw();
+void dont_throw() noexcept;
+
+struct Cleanup {
+  ~Cleanup() { dont_throw(); }
+};
+
+// Multiple catch clauses w/o catch-all
+void test0() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (double) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: define void @_Z5test0v() {{.*}} personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
+
+// CHECK:   %[[INT_ALLOCA:.*]] = alloca i32
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label %[[NORMAL_BB:.*]] unwind label %[[CATCHDISPATCH_BB:.*]]
+
+// CHECK: [[CATCHDISPATCH_BB]]:
+// CHECK-NEXT:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* bitcast (i8** @_ZTId to i8*)]
+// CHECK-NEXT:   %[[EXN:.*]] = call i8* @llvm.wasm.get.exception()
+// CHECK-NEXT:   store i8* %[[EXN]], i8** %exn.slot
+// CHECK-NEXT:   %[[SELECTOR:.*]] = call i32 @llvm.wasm.get.ehselector()
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_INT_BB:.*]], label %[[CATCH_FALLTHROUGH_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK-NEXT:   %[[EXN:.*]] = load i8*, i8** %exn.slot
+// CHECK-NEXT:   %[[ADDR:.*]] = call i8* @__cxa_begin_catch(i8* %[[EXN]]) {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   %[[ADDR_CAST:.*]] = bitcast i8* %[[ADDR]] to i32*
+// CHECK-NEXT:   %[[INT_VAL:.*]] = load i32, i32* %[[ADDR_CAST]]
+// CHECK-NEXT:   store i32 %[[INT_VAL]], i32* %[[INT_ALLOCA]]
+// CHECK-NEXT:   call void @_Z10dont_throwv() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   call void @__cxa_end_catch() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB0:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB0]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB:.*]]
+
+// CHECK: [[CATCH_FALLTHROUGH_BB]]
+// CHECK-NEXT:   %[[TYPEID:.*]] = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTId to i8*)) #2
+// CHECK-NEXT:   %[[MATCHES:.*]] = icmp eq i32 %[[SELECTOR]], %[[TYPEID]]
+// CHECK-NEXT:   br i1 %[[MATCHES]], label %[[CATCH_FLOAT_BB:.*]], label %[[RETHROW_BB:.*]]
+
+// CHECK: [[CATCH_FLOAT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label %[[CATCHRET_DEST_BB1:.*]]
+
+// CHECK: [[CATCHRET_DEST_BB1]]:
+// CHECK-NEXT:   br label %[[TRY_CONT_BB]]
+
+// CHECK: [[RETHROW_BB]]:
+// CHECK-NEXT:   call void @__cxa_rethrow() {{.*}} [ "funclet"(token %[[CATCHPAD]]) ]
+// CHECK-NEXT:   unreachable
+
+
+// Single catch-all
+void test1() {
+  try {
+may_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CATCH-LABEL: @_Z5test1v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* null]
+// CHECK:   br label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Multiple catch clauses w/ catch-all
+void test2() {
+  try {
+may_throw();
+  } catch (int) {
+dont_throw();
+  } catch (...) {
+dont_throw();
+  }
+}
+
+// CHECK-LABEL: @_Z5test2v()
+
+// CHECK:   %[[CATCHSWITCH:.*]] = catchswitch within none [label %[[CATCHSTART_BB:.*]]] unwind to caller
+
+// CHECK: [[CATCHSTART_BB]]:
+// CHECK-NEXT:   %[[CATCHPAD:.*]] = catchpad within %[[CATCHSWITCH]] [i8* bitcast (i8** @_ZTIi to i8*), i8* null]
+// CHECK:   br i1 %{{.*}}, label %[[CATCH_INT_BB:.*]], label %[[CATCH_ALL_BB:.*]]
+
+// CHECK: [[CATCH_INT_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+// CHECK: [[CATCH_ALL_BB]]:
+// CHECK:   catchret from %[[CATCHPAD]] to label
+
+
+// Cleanup
+void test3() {
+  Cleanup c;
+  may_throw();
+}
+
+// CHECK-LABEL: @_Z5test3v()
+
+// CHECK:   invoke void @_Z9may_throwv()
+// CHECK-NEXT:   to label {{.*}} 

[PATCH] D45006: [Tooling] A CompilationDatabase wrapper that infers header commands.

2018-03-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: cfe-commits, mgorny, klimek.

The wrapper finds the closest matching compile command using filename heuristics
and makes minimal tweaks so it can be used with the header.

(This is WIP and needs tests)


Repository:
  rC Clang

https://reviews.llvm.org/D45006

Files:
  include/clang/Tooling/CompilationDatabase.h
  lib/Tooling/CMakeLists.txt
  lib/Tooling/InterpolatingCompilationDatabase.cpp

Index: lib/Tooling/InterpolatingCompilationDatabase.cpp
===
--- /dev/null
+++ lib/Tooling/InterpolatingCompilationDatabase.cpp
@@ -0,0 +1,271 @@
+//===- InterpolatingCompilationDatabase.cpp -*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// InterpolatingCompilationDatabase wraps another CompilationDatabase and
+// attempts to heuristically determine appropriate compile commands for files
+// that are not included, such as headers or newly created files.
+//
+// We "borrow" the compile command for the closest available file:
+//   - points are awarded if the filename matches (ignoring extension)
+//   - points are awarded if the directory structure matches
+//   - ties are broken by length of path prefix match
+//
+// The compile command is adjusted:
+//   - the input filename is replaced
+//   - if the extension differs, an "-x" flag is added to preserve the language
+//   - output file arguments are removed
+//
+// This class is only useful when wrapping databases that can enumerate all
+// their compile commands. If getAllFilenames() is empty, no inference occurs.
+//
+//===--===//
+
+#include "clang/Driver/Options.h"
+#include "clang/Driver/Types.h"
+#include "clang/Tooling/CompilationDatabase.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/Option/ArgList.h"
+#include "llvm/Option/OptTable.h"
+#include "llvm/Support/StringSaver.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+namespace tooling {
+namespace {
+using namespace llvm;
+
+size_t matchingPrefix(StringRef L, StringRef R) {
+  size_t Limit = std::min(L.size(), R.size());
+  for (size_t I = 0; I < Limit; ++I)
+if (L[I] != R[I])
+  return I;
+  return Limit;
+}
+
+// Like memcmp(), but traverses in reverse order. L and R are one-past-end.
+int rMemCompare(const char *L, const char *R, size_t N) {
+  for (const char *LStop = L - N; L > LStop;)
+if (*--L != *--R)
+  return *L < *R ? -1 : 1;
+  return 0;
+}
+
+// This is like L.compare(R), but maybe with the order of characters reversed.
+template 
+int compare(StringRef L, StringRef R) {
+  if (!Reverse)
+return L.compare(R);
+  // Traverse the common region backwards, first differing byte is decisive.
+  if (int Cmp = rMemCompare(L.end(), R.end(), std::min(L.size(), R.size(
+return Cmp;
+  // No byte differed, so the shorter string is smaller.
+  return L.size() == R.size() ? 0 : L.size() < R.size() ? -1 : 1;
+}
+
+// Returns 0 if S starts with prefix, else -1 for S < Prefix, 1 for S > Prefix.
+template  int prefixCompare(StringRef S, StringRef Prefix) {
+  if (S.size() >= Prefix.size())
+return Reverse ? rMemCompare(S.end(), Prefix.end(), Prefix.size())
+   : memcmp(S.begin(), Prefix.begin(), Prefix.size());
+  return compare(S, Prefix);
+}
+
+template  struct Less {
+  bool operator()(StringRef Key, std::pair Value) const {
+return Prefix ? prefixCompare(Value.first, Key) > 0
+  : compare(Key, Value.first) < 0;
+  }
+  bool operator()(std::pair Value, StringRef Key) const {
+return Prefix ? prefixCompare(Value.first, Key) < 0
+  : compare(Value.first, Key) < 0;
+  }
+};
+
+class InterpolatingCompilationDatabase : public CompilationDatabase {
+public:
+  InterpolatingCompilationDatabase(std::unique_ptr Inner)
+  : Inner(std::move(Inner)), Strings(Arena) {
+for (auto F : getAllFiles())
+  Paths.emplace_back(Strings.save(F), 0);
+finalizeIndex();
+  }
+
+  std::vector
+  getCompileCommands(StringRef FilePath) const override {
+auto Known = Inner->getCompileCommands(FilePath);
+if (Paths.empty() || !Known.empty())
+  return Known;
+return {inferCommand(FilePath)};
+  }
+
+  std::vector getAllFiles() const override {
+return Inner->getAllFiles();
+  }
+
+  std::vector getAllCompileCommands() const override {
+return Inner->getAllCompileCommands();
+  }
+
+private:
+  using SubstringAndIndex = std::pair;
+
+  // Sort the paths list, and populate other index fields from it.
+  // We identify files by the index into (sorted) Paths.
+  void finalizeIndex() {
+llvm::sort(Paths.begin(),

[PATCH] D45004: [clang-format] New style option IndentWrappedObjCMethodNames

2018-03-28 Thread Stephane Moore via Phabricator via cfe-commits
stephanemoore added inline comments.



Comment at: include/clang/Format/Format.h:1154-1163
+  /// \brief The style of indenting long function or method names wrapped
+  /// onto the next line.
+  enum IndentWrappedMethodStyle {
+/// Automatically determine indenting style.
+IWM_Auto,
+/// Always indent wrapped method names.
+IWM_Always,

Do we explicitly want these to be generic with the intent to later reuse the 
enum for C++ method wrapping style?


Repository:
  rC Clang

https://reviews.llvm.org/D45004



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


[PATCH] D45007: [clang] Use compile-command interpolation to provide commands for header files.

2018-03-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
Herald added subscribers: cfe-commits, ioeric, jkorous-apple, ilya-biryukov, 
klimek.

This uses the inferring wrapper introduced in https://reviews.llvm.org/D45006.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D45007

Files:
  clangd/GlobalCompilationDatabase.cpp


Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -86,6 +86,8 @@
 return CachedIt->second.get();
   std::string Error = "";
   auto CDB = tooling::CompilationDatabase::loadFromDirectory(Dir, Error);
+  if (CDB)
+CDB = tooling::inferMissingCompileCommands(std::move(CDB));
   auto Result = CDB.get();
   CompilationDatabases.insert(std::make_pair(Dir, std::move(CDB)));
   return Result;


Index: clangd/GlobalCompilationDatabase.cpp
===
--- clangd/GlobalCompilationDatabase.cpp
+++ clangd/GlobalCompilationDatabase.cpp
@@ -86,6 +86,8 @@
 return CachedIt->second.get();
   std::string Error = "";
   auto CDB = tooling::CompilationDatabase::loadFromDirectory(Dir, Error);
+  if (CDB)
+CDB = tooling::inferMissingCompileCommands(std::move(CDB));
   auto Result = CDB.get();
   CompilationDatabases.insert(std::make_pair(Dir, std::move(CDB)));
   return Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44931: [WebAssembly] Use Windows EH instructions for Wasm EH

2018-03-28 Thread Derek Schuff via Phabricator via cfe-commits
dschuff added inline comments.



Comment at: lib/CodeGen/CGException.cpp:1541
+  }
   llvm::CallInst *terminateCall =
+  CGM.getCXXABI().emitTerminateForUnexpectedException(*this, Exn);

aheejin wrote:
> dschuff wrote:
> > Should this be in an else block? No need to emit it after we emit the call 
> > to `__clang_call_terminate`
> I don't understand? The call emitted within the `if` block is not a call to 
> `__clang_call_terminate` but to `wasm.get.exception` intrinsic.
Oh you're right, I misread that, nevermind.


Repository:
  rC Clang

https://reviews.llvm.org/D44931



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


[PATCH] D45002: [test] Conservatively re-enable a FreeBSD/XRay test

2018-03-28 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray added inline comments.



Comment at: test/Driver/XRay/xray-instrument-os.c:2
 // RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: -linux-
+// XFAIL: -linux-, -freebsd
 // REQUIRES-ANY: amd64, x86_64, x86_64h, arm, aarch64, arm64

devnexen wrote:
> What output do you get when you use directly llvm-lit on this ?
Before:

```
clang -cc1 version 7.0.0 based upon LLVM 7.0.0svn default target 
x86_64-unknown-freebsd11.1
#include "..." search starts here:
#include <...> search starts here:
 [...]/llvm/build/lib/clang/7.0.0/include
 /usr/include
End of search list.

--


Testing Time: 0.12s

Failing Tests (1):
Clang :: Driver/XRay/xray-instrument-os.c

  Unexpected Failures: 1

```
After:
```
lit: [...]llvm/utils/lit/lit/llvm/config.py:334: note: using clang: 
[...]/llvm/build/bin/clang
Testing Time: 0.11s
  Expected Failures  : 1
```



Repository:
  rC Clang

https://reviews.llvm.org/D45002



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


  1   2   >