[PATCH] D68627: [Sema][X86] Consider target attribute into the checks in validateOutputSize and validateInputSize.

2019-10-07 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: rnk, echristo, erichkeane, RKSimon, spatel.
Herald added a project: clang.

The validateOutputSize and validateInputSize need to check whether
AVX or AVX512 are enabled. But this can be affected by the
target attribute so we need to factor that in.

This patch copies some of the code from CodeGen to create an
appropriate feature map that we can pass to the function. Probably
need some refactoring here to share more code with Codegen. Is
there a good place to do that? Also need to support the cpu_specific
attribute as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68627

Files:
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/Sema/SemaStmtAsm.cpp
  clang/test/CodeGen/x86_32-inline-asm.c

Index: clang/test/CodeGen/x86_32-inline-asm.c
===
--- clang/test/CodeGen/x86_32-inline-asm.c
+++ clang/test/CodeGen/x86_32-inline-asm.c
@@ -70,3 +70,35 @@
   __asm__ volatile("foo1 %0" : "=x" (val256)); // expected-error {{invalid output size for constraint '=x'}}
 #endif
 }
+
+int __attribute__((__target__("sse"))) _func2() {
+  __asm__ volatile("foo1 %0" : : "x" (val128)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val128));  // No error.
+#ifdef __AVX__
+  __asm__ volatile("foo1 %0" : : "x" (val256)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val256));  // No error.
+#else
+  __asm__ volatile("foo1 %0" : : "x" (val256)); // expected-error {{invalid input size for constraint 'x'}}
+  __asm__ volatile("foo1 %0" : "=x" (val256)); // expected-error {{invalid output size for constraint '=x'}}
+#endif
+  __asm__ volatile("foo1 %0" : : "x" (val512)); // expected-error {{invalid input size for constraint 'x'}}
+  __asm__ volatile("foo1 %0" : "=x" (val512)); // expected-error {{invalid output size for constraint '=x'}}
+}
+
+int __attribute__((__target__("avx"))) _func3() {
+  __asm__ volatile("foo1 %0" : : "x" (val128)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val128));  // No error.
+  __asm__ volatile("foo1 %0" : : "x" (val256)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val256));  // No error.
+  __asm__ volatile("foo1 %0" : : "x" (val512)); // expected-error {{invalid input size for constraint 'x'}}
+  __asm__ volatile("foo1 %0" : "=x" (val512)); // expected-error {{invalid output size for constraint '=x'}}
+}
+
+int __attribute__((__target__("avx512f"))) _func4() {
+  __asm__ volatile("foo1 %0" : : "x" (val128)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val128));  // No error.
+  __asm__ volatile("foo1 %0" : : "x" (val256)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val256));  // No error.
+  __asm__ volatile("foo1 %0" : : "x" (val512)); // No error.
+  __asm__ volatile("foo1 %0" : "=x" (val512)); // No error.
+}
Index: clang/lib/Sema/SemaStmtAsm.cpp
===
--- clang/lib/Sema/SemaStmtAsm.cpp
+++ clang/lib/Sema/SemaStmtAsm.cpp
@@ -237,6 +237,44 @@
   return SourceLocation();
 }
 
+void getFunctionFeatureMap(llvm::StringMap ,
+   DiagnosticsEngine ,
+   const TargetInfo , FunctionDecl *FD) {
+  StringRef TargetCPU = Target.getTargetOpts().CPU;
+  if (FD) {
+if (const auto *TD = FD->getAttr()) {
+  TargetAttr::ParsedTargetAttr ParsedAttr = TD->parse();
+
+  ParsedAttr.Features.erase(
+  llvm::remove_if(ParsedAttr.Features,
+  [&](const std::string ) {
+return !Target.isValidFeatureName(
+StringRef{Feat}.substr(1));
+  }),
+  ParsedAttr.Features.end());
+
+  ParsedAttr.Features.insert(ParsedAttr.Features.begin(),
+Target.getTargetOpts().FeaturesAsWritten.begin(),
+Target.getTargetOpts().FeaturesAsWritten.end());
+
+  if (ParsedAttr.Architecture != "" &&
+  Target.isValidCPUName(ParsedAttr.Architecture))
+TargetCPU = ParsedAttr.Architecture;
+
+  // Now populate the feature map, first with the TargetCPU which is either
+  // the default or a new one from the target attribute string. Then we'll
+  // use the passed in features (FeaturesAsWritten) along with the new ones
+  // from the attribute.
+  Target.initFeatureMap(FeatureMap, Diags, TargetCPU,
+ParsedAttr.Features);
+  return;
+}
+  }
+
+  Target.initFeatureMap(FeatureMap, Diags, TargetCPU,
+Target.getTargetOpts().Features);
+}
+
 StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
  bool IsVolatile, unsigned NumOutputs,
  unsigned NumInputs, IdentifierInfo **Names,
@@ -255,6 +293,10 @@
   // The parser verifies that 

[PATCH] D68368: [ItaniumMangle] Fix mangling of GNU __null in an expression to match GCC

2019-10-07 Thread James Clarke via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL374013: [ItaniumMangle] Fix mangling of GNU __null in an 
expression to match GCC (authored by jrtc27, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68368?vs=222949=223783#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68368

Files:
  cfe/trunk/lib/AST/ItaniumMangle.cpp
  cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp


Index: cfe/trunk/lib/AST/ItaniumMangle.cpp
===
--- cfe/trunk/lib/AST/ItaniumMangle.cpp
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp
@@ -4273,8 +4273,11 @@
   }
 
   case Expr::GNUNullExprClass:
-// FIXME: should this really be mangled the same as nullptr?
-// fallthrough
+// Mangle as if an integer literal 0.
+Out << 'L';
+mangleType(E->getType());
+Out << "0E";
+break;
 
   case Expr::CXXNullPtrLiteralExprClass: {
 Out << "LDnE";
Index: cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
===
--- cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
+++ cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
@@ -373,3 +373,19 @@
   template void f(decltype(T{.a.b[3][1 ... 4] = 9}) x) {}
   void use_f(A a) { f(a); }
 }
+
+namespace null {
+  template 
+  void cpp_nullptr(typename enable_if::type* = 0) {
+  }
+
+  template 
+  void gnu_null(typename enable_if::type* = 0) {
+  }
+
+  // CHECK-LABEL: define {{.*}} 
@_ZN4null11cpp_nullptrILDn0EEEvPN9enable_ifIXeqT_LDnEEvE4typeE
+  template void cpp_nullptr(void *);
+
+  // CHECK-LABEL: define {{.*}} 
@_ZN4null8gnu_nullILPv0EEEvPN9enable_ifIXeqT_Ll0EEvE4typeE
+  template void gnu_null(void *);
+}


Index: cfe/trunk/lib/AST/ItaniumMangle.cpp
===
--- cfe/trunk/lib/AST/ItaniumMangle.cpp
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp
@@ -4273,8 +4273,11 @@
   }
 
   case Expr::GNUNullExprClass:
-// FIXME: should this really be mangled the same as nullptr?
-// fallthrough
+// Mangle as if an integer literal 0.
+Out << 'L';
+mangleType(E->getType());
+Out << "0E";
+break;
 
   case Expr::CXXNullPtrLiteralExprClass: {
 Out << "LDnE";
Index: cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
===
--- cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
+++ cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
@@ -373,3 +373,19 @@
   template void f(decltype(T{.a.b[3][1 ... 4] = 9}) x) {}
   void use_f(A a) { f(a); }
 }
+
+namespace null {
+  template 
+  void cpp_nullptr(typename enable_if::type* = 0) {
+  }
+
+  template 
+  void gnu_null(typename enable_if::type* = 0) {
+  }
+
+  // CHECK-LABEL: define {{.*}} @_ZN4null11cpp_nullptrILDn0EEEvPN9enable_ifIXeqT_LDnEEvE4typeE
+  template void cpp_nullptr(void *);
+
+  // CHECK-LABEL: define {{.*}} @_ZN4null8gnu_nullILPv0EEEvPN9enable_ifIXeqT_Ll0EEvE4typeE
+  template void gnu_null(void *);
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68608: [clang] Accept -ftrivial-auto-var-init in clang-cl

2019-10-07 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373992: [clang] Accept -ftrivial-auto-var-init in clang-cl 
(authored by vitalybuka, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68608?vs=223694=223773#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68608

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/test/Driver/cl-options.c


Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -1715,10 +1715,10 @@
"alloca, which are of greater size than ssp-buffer-size (default: 8 
bytes). "
"All variable sized calls to alloca are considered vulnerable">;
 def ftrivial_auto_var_init : Joined<["-"], "ftrivial-auto-var-init=">, 
Group,
-  Flags<[CC1Option]>, HelpText<"Initialize trivial automatic stack variables: 
uninitialized (default)"
+  Flags<[CC1Option, CoreOption]>, HelpText<"Initialize trivial automatic stack 
variables: uninitialized (default)"
   " | pattern">, Values<"uninitialized,pattern">;
 def enable_trivial_var_init_zero : Joined<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
-  Flags<[CC1Option]>,
+  Flags<[CC1Option, CoreOption]>,
   HelpText<"Trivial automatic variable initialization to zero is only here for 
benchmarks, it'll eventually be removed, and I'm OK with that because I'm only 
using it to benchmark">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, 
Flags<[CoreOption]>,
   HelpText<"Emit full debug info for all types used by the program">;
Index: cfe/trunk/test/Driver/cl-options.c
===
--- cfe/trunk/test/Driver/cl-options.c
+++ cfe/trunk/test/Driver/cl-options.c
@@ -653,6 +653,8 @@
 // RUN: -fcs-profile-generate \
 // RUN: -fcs-profile-generate=dir \
 // RUN: -ftime-trace \
+// RUN: -ftrivial-auto-var-init=zero \
+// RUN: 
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang \
 // RUN: --version \
 // RUN: -Werror /Zs -- %s 2>&1
 


Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -1715,10 +1715,10 @@
"alloca, which are of greater size than ssp-buffer-size (default: 8 bytes). "
"All variable sized calls to alloca are considered vulnerable">;
 def ftrivial_auto_var_init : Joined<["-"], "ftrivial-auto-var-init=">, Group,
-  Flags<[CC1Option]>, HelpText<"Initialize trivial automatic stack variables: uninitialized (default)"
+  Flags<[CC1Option, CoreOption]>, HelpText<"Initialize trivial automatic stack variables: uninitialized (default)"
   " | pattern">, Values<"uninitialized,pattern">;
 def enable_trivial_var_init_zero : Joined<["-"], "enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
-  Flags<[CC1Option]>,
+  Flags<[CC1Option, CoreOption]>,
   HelpText<"Trivial automatic variable initialization to zero is only here for benchmarks, it'll eventually be removed, and I'm OK with that because I'm only using it to benchmark">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, Flags<[CoreOption]>,
   HelpText<"Emit full debug info for all types used by the program">;
Index: cfe/trunk/test/Driver/cl-options.c
===
--- cfe/trunk/test/Driver/cl-options.c
+++ cfe/trunk/test/Driver/cl-options.c
@@ -653,6 +653,8 @@
 // RUN: -fcs-profile-generate \
 // RUN: -fcs-profile-generate=dir \
 // RUN: -ftime-trace \
+// RUN: -ftrivial-auto-var-init=zero \
+// RUN: -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang \
 // RUN: --version \
 // RUN: -Werror /Zs -- %s 2>&1
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68114: Fix for expanding __pragmas in macro arguments

2019-10-07 Thread Amy Huang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373950: Fix for expanding __pragmas in macro arguments 
(authored by akhuang, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68114?vs=223255=223754#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68114

Files:
  cfe/trunk/lib/Lex/Pragma.cpp
  cfe/trunk/test/Preprocessor/pragma_microsoft.c

Index: cfe/trunk/test/Preprocessor/pragma_microsoft.c
===
--- cfe/trunk/test/Preprocessor/pragma_microsoft.c
+++ cfe/trunk/test/Preprocessor/pragma_microsoft.c
@@ -51,6 +51,8 @@
   __pragma(warning(pop)); \
 }
 
+#define PRAGMA_IN_ARGS(p) p
+
 void f()
 {
   __pragma() // expected-warning{{unknown pragma ignored}}
@@ -64,8 +66,16 @@
 // CHECK: #pragma warning(disable: 1)
 // CHECK: ; 1 + (2 > 3) ? 4 : 5;
 // CHECK: #pragma warning(pop)
-}
 
+  // Check that macro arguments can contain __pragma.
+  PRAGMA_IN_ARGS(MACRO_WITH__PRAGMA) // expected-warning {{lower precedence}} \
+ // expected-note 2 {{place parentheses}} \
+ // expected-warning {{expression result unused}}
+// CHECK: #pragma warning(push)
+// CHECK: #pragma warning(disable: 1)
+// CHECK: ; 1 + (2 > 3) ? 4 : 5;
+// CHECK: #pragma warning(pop)
+}
 
 // This should include macro_arg_directive even though the include
 // is looking for test.h  This allows us to assign to "n"
Index: cfe/trunk/lib/Lex/Pragma.cpp
===
--- cfe/trunk/lib/Lex/Pragma.cpp
+++ cfe/trunk/lib/Lex/Pragma.cpp
@@ -121,6 +121,40 @@
 // Preprocessor Pragma Directive Handling.
 //===--===//
 
+namespace {
+// TokenCollector provides the option to collect tokens that were "read"
+// and return them to the stream to be read later.
+// Currently used when reading _Pragma/__pragma directives.
+struct TokenCollector {
+  Preprocessor 
+  bool Collect;
+  SmallVector Tokens;
+  Token 
+
+  void lex() {
+if (Collect)
+  Tokens.push_back(Tok);
+Self.Lex(Tok);
+  }
+
+  void revert() {
+assert(Collect && "did not collect tokens");
+assert(!Tokens.empty() && "collected unexpected number of tokens");
+
+// Push the ( "string" ) tokens into the token stream.
+auto Toks = std::make_unique(Tokens.size());
+std::copy(Tokens.begin() + 1, Tokens.end(), Toks.get());
+Toks[Tokens.size() - 1] = Tok;
+Self.EnterTokenStream(std::move(Toks), Tokens.size(),
+  /*DisableMacroExpansion*/ true,
+  /*IsReinject*/ true);
+
+// ... and return the pragma token unchanged.
+Tok = *Tokens.begin();
+  }
+};
+} // namespace
+
 /// HandlePragmaDirective - The "\#pragma" directive has been parsed.  Lex the
 /// rest of the pragma, passing it to the registered pragma handlers.
 void Preprocessor::HandlePragmaDirective(PragmaIntroducer Introducer) {
@@ -166,35 +200,6 @@
   // In Case #2, we check the syntax now, but then put the tokens back into the
   // token stream for later consumption.
 
-  struct TokenCollector {
-Preprocessor 
-bool Collect;
-SmallVector Tokens;
-Token 
-
-void lex() {
-  if (Collect)
-Tokens.push_back(Tok);
-  Self.Lex(Tok);
-}
-
-void revert() {
-  assert(Collect && "did not collect tokens");
-  assert(!Tokens.empty() && "collected unexpected number of tokens");
-
-  // Push the ( "string" ) tokens into the token stream.
-  auto Toks = std::make_unique(Tokens.size());
-  std::copy(Tokens.begin() + 1, Tokens.end(), Toks.get());
-  Toks[Tokens.size() - 1] = Tok;
-  Self.EnterTokenStream(std::move(Toks), Tokens.size(),
-/*DisableMacroExpansion*/ true,
-/*IsReinject*/ true);
-
-  // ... and return the _Pragma token unchanged.
-  Tok = *Tokens.begin();
-}
-  };
-
   TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
 
   // Remember the pragma token location.
@@ -328,11 +333,15 @@
 /// HandleMicrosoft__pragma - Like Handle_Pragma except the pragma text
 /// is not enclosed within a string literal.
 void Preprocessor::HandleMicrosoft__pragma(Token ) {
+  // During macro pre-expansion, check the syntax now but put the tokens back
+  // into the token stream for later consumption. Same as Handle_Pragma.
+  TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
+
   // Remember the pragma token location.
   SourceLocation PragmaLoc = Tok.getLocation();
 
   // Read the '('.
-  Lex(Tok);
+  Toks.lex();
   if (Tok.isNot(tok::l_paren)) {
 Diag(PragmaLoc, diag::err__Pragma_malformed);
 return;
@@ -341,14 +350,14 @@
   // Get the tokens 

[PATCH] D68412: [clang] [cmake] Support LLVM_DISTRIBUTION_COMPONENTS in stand-alone build

2019-10-07 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373936: [clang] [cmake] Support LLVM_DISTRIBUTION_COMPONENTS 
in stand-alone build (authored by mgorny, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68412?vs=223064=223753#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68412

Files:
  cfe/trunk/CMakeLists.txt


Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -114,6 +114,7 @@
   include(TableGen)
   include(HandleLLVMOptions)
   include(VersionFromVCS)
+  include(LLVMDistributionSupport)
 
   set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
 
@@ -858,6 +859,10 @@
 endif()
 add_subdirectory(utils/hmaptool)
 
+if(CLANG_BUILT_STANDALONE)
+  llvm_distribution_add_targets()
+endif()
+
 configure_file(
   ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
   ${CLANG_BINARY_DIR}/include/clang/Config/config.h)


Index: cfe/trunk/CMakeLists.txt
===
--- cfe/trunk/CMakeLists.txt
+++ cfe/trunk/CMakeLists.txt
@@ -114,6 +114,7 @@
   include(TableGen)
   include(HandleLLVMOptions)
   include(VersionFromVCS)
+  include(LLVMDistributionSupport)
 
   set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
 
@@ -858,6 +859,10 @@
 endif()
 add_subdirectory(utils/hmaptool)
 
+if(CLANG_BUILT_STANDALONE)
+  llvm_distribution_add_targets()
+endif()
+
 configure_file(
   ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
   ${CLANG_BINARY_DIR}/include/clang/Config/config.h)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68584: Fix Calling Convention through aliases

2019-10-07 Thread Erich Keane via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373929: Fix Calling Convention through aliases (authored by 
erichkeane, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D68584?vs=223617=223750#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68584

Files:
  cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
  cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
  llvm/trunk/include/llvm/IR/Value.h
  llvm/trunk/lib/IR/Value.cpp

Index: llvm/trunk/lib/IR/Value.cpp
===
--- llvm/trunk/lib/IR/Value.cpp
+++ llvm/trunk/lib/IR/Value.cpp
@@ -455,6 +455,7 @@
 // Various metrics for how much to strip off of pointers.
 enum PointerStripKind {
   PSK_ZeroIndices,
+  PSK_ZeroIndicesAndAliases,
   PSK_ZeroIndicesSameRepresentation,
   PSK_ZeroIndicesAndInvariantGroups,
   PSK_InBoundsConstantIndices,
@@ -475,6 +476,7 @@
 if (auto *GEP = dyn_cast(V)) {
   switch (StripKind) {
   case PSK_ZeroIndices:
+  case PSK_ZeroIndicesAndAliases:
   case PSK_ZeroIndicesSameRepresentation:
   case PSK_ZeroIndicesAndInvariantGroups:
 if (!GEP->hasAllZeroIndices())
@@ -497,6 +499,8 @@
   // TODO: If we know an address space cast will not change the
   //   representation we could look through it here as well.
   V = cast(V)->getOperand(0);
+} else if (StripKind == PSK_ZeroIndicesAndAliases && isa(V)) {
+  V = cast(V)->getAliasee();
 } else {
   if (const auto *Call = dyn_cast(V)) {
 if (const Value *RV = Call->getReturnedArgOperand()) {
@@ -526,6 +530,10 @@
   return stripPointerCastsAndOffsets(this);
 }
 
+const Value *Value::stripPointerCastsAndAliases() const {
+  return stripPointerCastsAndOffsets(this);
+}
+
 const Value *Value::stripPointerCastsSameRepresentation() const {
   return stripPointerCastsAndOffsets(this);
 }
Index: llvm/trunk/include/llvm/IR/Value.h
===
--- llvm/trunk/include/llvm/IR/Value.h
+++ llvm/trunk/include/llvm/IR/Value.h
@@ -523,6 +523,16 @@
 static_cast(this)->stripPointerCasts());
   }
 
+  /// Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
+  ///
+  /// Returns the original uncasted value.  If this is called on a non-pointer
+  /// value, it returns 'this'.
+  const Value *stripPointerCastsAndAliases() const;
+  Value *stripPointerCastsAndAliases() {
+return const_cast(
+static_cast(this)->stripPointerCastsAndAliases());
+  }
+
   /// Strip off pointer casts, all-zero GEPs and address space casts
   /// but ensures the representation of the result stays the same.
   ///
Index: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
===
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
@@ -248,8 +248,8 @@
   llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr);
 
  // Make sure the call and the callee agree on calling convention.
-  if (llvm::Function *dtorFn =
-  dyn_cast(dtor.getCallee()->stripPointerCasts()))
+  if (auto *dtorFn = dyn_cast(
+  dtor.getCallee()->stripPointerCastsAndAliases()))
 call->setCallingConv(dtorFn->getCallingConv());
 
   CGF.FinishFunction();
Index: cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
===
--- cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
+++ cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple i686-windows-pc -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-passes %s | FileCheck %s
+
+struct Base { virtual ~Base(); };
+struct Derived : Base {
+  virtual ~Derived();
+  static Derived inst;
+};
+
+Base::~Base(){}
+Derived::~Derived(){}
+Derived Derived::inst;
+
+// CHECK: @"??1Derived@@UAE@XZ" = dso_local unnamed_addr alias void (%struct.Derived*), bitcast (void (%struct.Base*)* @"??1Base@@UAE@XZ" to void (%struct.Derived*)*)
+
+// CHECK: define dso_local x86_thiscallcc void @"??1Base@@UAE@XZ"
+// CHECK: define internal void @"??__E?inst@Derived@@2U1@A@@YAXXZ"
+// CHECK: call i32 @atexit(void ()* @"??__F?inst@Derived@@2U1@A@@YAXXZ"
+//
+// CHECK: define internal void @"??__F?inst@Derived@@2U1@A@@YAXXZ"
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call x86_thiscallcc void @"??1Derived@@UAE@XZ"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68273: [clangd] Fix raciness in code completion tests

2019-10-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373924: [clangd] Fix raciness in code completion tests 
(authored by kadircet, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68273?vs=222890=223748#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68273

Files:
  clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp


Index: clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
@@ -18,6 +18,7 @@
 #include "TestFS.h"
 #include "TestIndex.h"
 #include "TestTU.h"
+#include "Threading.h"
 #include "index/Index.h"
 #include "index/MemIndex.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -27,6 +28,8 @@
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1112,8 +1115,9 @@
   bool
   fuzzyFind(const FuzzyFindRequest ,
 llvm::function_ref Callback) const override {
-std::lock_guard Lock(Mut);
+std::unique_lock Lock(Mut);
 Requests.push_back(Req);
+ReceivedRequestCV.notify_one();
 return true;
   }
 
@@ -1131,8 +1135,10 @@
   // isn't used in production code.
   size_t estimateMemoryUsage() const override { return 0; }
 
-  const std::vector consumeRequests() const {
-std::lock_guard Lock(Mut);
+  const std::vector consumeRequests(size_t Num) const {
+std::unique_lock Lock(Mut);
+EXPECT_TRUE(wait(Lock, ReceivedRequestCV, timeoutSeconds(10),
+ [this, Num] { return Requests.size() == Num; }));
 auto Reqs = std::move(Requests);
 Requests = {};
 return Reqs;
@@ -1140,16 +1146,21 @@
 
 private:
   // We need a mutex to handle async fuzzy find requests.
+  mutable std::condition_variable ReceivedRequestCV;
   mutable std::mutex Mut;
   mutable std::vector Requests;
 };
 
-std::vector captureIndexRequests(llvm::StringRef Code) {
+// Clients have to consume exactly Num requests.
+std::vector captureIndexRequests(llvm::StringRef Code,
+   size_t Num = 1) {
   clangd::CodeCompleteOptions Opts;
   IndexRequestCollector Requests;
   Opts.Index = 
   completions(Code, {}, Opts);
-  return Requests.consumeRequests();
+  const auto Reqs = Requests.consumeRequests(Num);
+  EXPECT_EQ(Reqs.size(), Num);
+  return Reqs;
 }
 
 TEST(CompletionTest, UnqualifiedIdQuery) {
@@ -2098,18 +2109,15 @@
 
   auto CompleteAtPoint = [&](StringRef P) {
 cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
-// Sleep for a while to make sure asynchronous call (if applicable) is also
-// triggered before callback is invoked.
-std::this_thread::sleep_for(std::chrono::milliseconds(100));
   };
 
   CompleteAtPoint("1");
-  auto Reqs1 = Requests.consumeRequests();
+  auto Reqs1 = Requests.consumeRequests(1);
   ASSERT_EQ(Reqs1.size(), 1u);
   EXPECT_THAT(Reqs1[0].Scopes, UnorderedElementsAre("ns1::"));
 
   CompleteAtPoint("2");
-  auto Reqs2 = Requests.consumeRequests();
+  auto Reqs2 = Requests.consumeRequests(1);
   // Speculation succeeded. Used speculative index result.
   ASSERT_EQ(Reqs2.size(), 1u);
   EXPECT_EQ(Reqs2[0], Reqs1[0]);
@@ -2117,7 +2125,7 @@
   CompleteAtPoint("3");
   // Speculation failed. Sent speculative index request and the new index
   // request after sema.
-  auto Reqs3 = Requests.consumeRequests();
+  auto Reqs3 = Requests.consumeRequests(2);
   ASSERT_EQ(Reqs3.size(), 2u);
 }
 


Index: clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
@@ -18,6 +18,7 @@
 #include "TestFS.h"
 #include "TestIndex.h"
 #include "TestTU.h"
+#include "Threading.h"
 #include "index/Index.h"
 #include "index/MemIndex.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -27,6 +28,8 @@
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1112,8 +1115,9 @@
   bool
   fuzzyFind(const FuzzyFindRequest ,
 llvm::function_ref Callback) const override {
-std::lock_guard Lock(Mut);
+std::unique_lock Lock(Mut);
 Requests.push_back(Req);
+ReceivedRequestCV.notify_one();
 return true;
   }
 
@@ -1131,8 +1135,10 @@
   // isn't used in production code.
   size_t estimateMemoryUsage() const override { return 0; }
 
-  const std::vector consumeRequests() const {
-std::lock_guard Lock(Mut);
+  const std::vector consumeRequests(size_t Num) 

[PATCH] D68481: [clang-format] [PR27004] omits leading space for noexcept when formatting operator delete()

2019-10-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373922: [clang-format] [PR27004] omits leading space for 
noexcept when formatting… (authored by paulhoad, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68481?vs=223369=223745#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68481

Files:
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -1611,6 +1611,13 @@
 if (Tok.Next->is(tok::question))
   return false;
 
+// Functions which end with decorations like volatile, noexcept are 
unlikely
+// to be casts.
+if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
+  tok::kw_throw, tok::l_square, tok::arrow,
+  Keywords.kw_override, Keywords.kw_final))
+  return false;
+
 // As Java has no function types, a "(" after the ")" likely means that 
this
 // is a cast.
 if (Style.Language == FormatStyle::LK_Java && Tok.Next->is(tok::l_paren))
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -14678,6 +14678,33 @@
   */
 }
 
+TEST_F(FormatTest, NotCastRPaen) {
+
+  verifyFormat("void operator++(int) noexcept;");
+  verifyFormat("void operator++(int &) noexcept;");
+  verifyFormat("void operator delete(void *, std::size_t, const std::nothrow_t 
"
+   "&) noexcept;");
+  verifyFormat(
+  "void operator delete(std::size_t, const std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(const std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(foo &) noexcept;");
+  verifyFormat("void operator delete(foo) noexcept;");
+  verifyFormat("void operator delete(int) noexcept;");
+  verifyFormat("void operator delete(int &) noexcept;");
+  verifyFormat("void operator delete(int &) volatile noexcept;");
+  verifyFormat("void operator delete(int &) const");
+  verifyFormat("void operator delete(int &) = default");
+  verifyFormat("void operator delete(int &) = delete");
+  verifyFormat("void operator delete(int &) [[noreturn]]");
+  verifyFormat("void operator delete(int &) throw();");
+  verifyFormat("void operator delete(int &) throw(int);");
+  verifyFormat("auto operator delete(int &) -> int;");
+  verifyFormat("auto operator delete(int &) override");
+  verifyFormat("auto operator delete(int &) final");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -1611,6 +1611,13 @@
 if (Tok.Next->is(tok::question))
   return false;
 
+// Functions which end with decorations like volatile, noexcept are unlikely
+// to be casts.
+if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
+  tok::kw_throw, tok::l_square, tok::arrow,
+  Keywords.kw_override, Keywords.kw_final))
+  return false;
+
 // As Java has no function types, a "(" after the ")" likely means that this
 // is a cast.
 if (Style.Language == FormatStyle::LK_Java && Tok.Next->is(tok::l_paren))
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -14678,6 +14678,33 @@
   */
 }
 
+TEST_F(FormatTest, NotCastRPaen) {
+
+  verifyFormat("void operator++(int) noexcept;");
+  verifyFormat("void operator++(int &) noexcept;");
+  verifyFormat("void operator delete(void *, std::size_t, const std::nothrow_t "
+   "&) noexcept;");
+  verifyFormat(
+  "void operator delete(std::size_t, const std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(const std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(foo &) noexcept;");
+  verifyFormat("void operator delete(foo) noexcept;");
+  verifyFormat("void operator delete(int) noexcept;");
+  verifyFormat("void operator delete(int &) noexcept;");
+  verifyFormat("void operator delete(int &) volatile 

[PATCH] D68551: [clang-format] [NFC] Ensure clang-format is itself clang-formatted.

2019-10-07 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373921: [clang-format] [NFC] Ensure clang-format is itself 
clang-formatted. (authored by paulhoad, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68551?vs=223408=223744#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68551

Files:
  cfe/trunk/tools/clang-format/ClangFormat.cpp

Index: cfe/trunk/tools/clang-format/ClangFormat.cpp
===
--- cfe/trunk/tools/clang-format/ClangFormat.cpp
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp
@@ -51,13 +51,14 @@
  "Can only be used with one input file."),
 cl::cat(ClangFormatCategory));
 static cl::list
-LineRanges("lines", cl::desc(": - format a range of\n"
- "lines (both 1-based).\n"
- "Multiple ranges can be formatted by specifying\n"
- "several -lines arguments.\n"
- "Can't be used with -offset and -length.\n"
- "Can only be used with one input file."),
-   cl::cat(ClangFormatCategory));
+LineRanges("lines",
+   cl::desc(": - format a range of\n"
+"lines (both 1-based).\n"
+"Multiple ranges can be formatted by specifying\n"
+"several -lines arguments.\n"
+"Can't be used with -offset and -length.\n"
+"Can only be used with one input file."),
+   cl::cat(ClangFormatCategory));
 static cl::opt
 Style("style", cl::desc(clang::format::StyleOptionHelpDescription),
   cl::init(clang::format::DefaultFormatStyle),
@@ -72,12 +73,12 @@
   cl::init(clang::format::DefaultFallbackStyle),
   cl::cat(ClangFormatCategory));
 
-static cl::opt
-AssumeFileName("assume-filename",
-   cl::desc("When reading from stdin, clang-format assumes this\n"
-"filename to look for a style config file (with\n"
-"-style=file) and to determine the language."),
-   cl::init(""), cl::cat(ClangFormatCategory));
+static cl::opt AssumeFileName(
+"assume-filename",
+cl::desc("When reading from stdin, clang-format assumes this\n"
+ "filename to look for a style config file (with\n"
+ "-style=file) and to determine the language."),
+cl::init(""), cl::cat(ClangFormatCategory));
 
 static cl::opt Inplace("i",
  cl::desc("Inplace edit s, if specified."),
@@ -249,8 +250,8 @@
   // On Windows, overwriting a file with an open file mapping doesn't work,
   // so read the whole file into memory when formatting in-place.
   ErrorOr> CodeOrErr =
-  !OutputXML && Inplace ? MemoryBuffer::getFileAsStream(FileName) :
-  MemoryBuffer::getFileOrSTDIN(FileName);
+  !OutputXML && Inplace ? MemoryBuffer::getFileAsStream(FileName)
+: MemoryBuffer::getFileOrSTDIN(FileName);
   if (std::error_code EC = CodeOrErr.getError()) {
 errs() << EC.message() << "\n";
 return true;
@@ -264,20 +265,21 @@
   // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
   // for more information.
   StringRef BufStr = Code->getBuffer();
-  const char *InvalidBOM = llvm::StringSwitch(BufStr)
-.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
-  "UTF-32 (BE)")
-.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
-  "UTF-32 (LE)")
-.StartsWith("\xFE\xFF", "UTF-16 (BE)")
-.StartsWith("\xFF\xFE", "UTF-16 (LE)")
-.StartsWith("\x2B\x2F\x76", "UTF-7")
-.StartsWith("\xF7\x64\x4C", "UTF-1")
-.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
-.StartsWith("\x0E\xFE\xFF", "SCSU")
-.StartsWith("\xFB\xEE\x28", "BOCU-1")
-.StartsWith("\x84\x31\x95\x33", "GB-18030")
-.Default(nullptr);
+  const char *InvalidBOM =
+  llvm::StringSwitch(BufStr)
+  .StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+  .StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+  .StartsWith("\xFE\xFF", "UTF-16 (BE)")
+  .StartsWith("\xFF\xFE", "UTF-16 (LE)")
+  .StartsWith("\x2B\x2F\x76", "UTF-7")
+  .StartsWith("\xF7\x64\x4C", "UTF-1")
+  .StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
+  .StartsWith("\x0E\xFE\xFF", "SCSU")
+  .StartsWith("\xFB\xEE\x28", "BOCU-1")
+  .StartsWith("\x84\x31\x95\x33", "GB-18030")
+  

[PATCH] D68574: [libTooling] Add `toString` method to the Stencil class

2019-10-07 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373916: [libTooling] Add `toString` method to the Stencil 
class (authored by ymandel, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68574?vs=223619=223741#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68574

Files:
  cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h
  cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp
  cfe/trunk/unittests/Tooling/StencilTest.cpp

Index: cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h
===
--- cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h
+++ cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h
@@ -50,6 +50,11 @@
 
   virtual bool isEqual(const StencilPartInterface ) const = 0;
 
+  /// Constructs a string representation of the StencilPart. StencilParts
+  /// generated by the `selection` and `run` functions do not have a unique
+  /// string representation.
+  virtual std::string toString() const = 0;
+
   const void *typeId() const { return TypeId; }
 
 protected:
@@ -86,6 +91,12 @@
 return Impl->isEqual(*Other.Impl);
   }
 
+  std::string toString() const {
+if (Impl == nullptr)
+  return "";
+return Impl->toString();
+  }
+
 private:
   std::shared_ptr Impl;
 };
@@ -120,6 +131,16 @@
 return eval(Result);
   }
 
+  /// Constructs a string representation of the Stencil. The string is not
+  /// guaranteed to be unique.
+  std::string toString() const {
+std::vector PartStrings;
+PartStrings.reserve(Parts.size());
+for (const auto  : Parts)
+  PartStrings.push_back(Part.toString());
+return llvm::join(PartStrings, ", ");
+  }
+
 private:
   friend bool operator==(const Stencil , const Stencil );
   static StencilPart wrap(llvm::StringRef Text);
Index: cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp
===
--- cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp
+++ cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp
@@ -15,6 +15,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Refactoring/SourceCode.h"
 #include "clang/Tooling/Refactoring/SourceCodeBuilders.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/Errc.h"
 #include 
 #include 
@@ -128,6 +129,54 @@
   return false;
 }
 
+std::string toStringData(const RawTextData ) {
+  std::string Result;
+  llvm::raw_string_ostream OS(Result);
+  OS << "\"";
+  OS.write_escaped(Data.Text);
+  OS << "\"";
+  OS.flush();
+  return Result;
+}
+
+std::string toStringData(const DebugPrintNodeData ) {
+  return (llvm::Twine("dPrint(\"") + Data.Id + "\")").str();
+}
+
+std::string toStringData(const UnaryOperationData ) {
+  StringRef OpName;
+  switch (Data.Op) {
+  case UnaryNodeOperator::Parens:
+OpName = "expression";
+break;
+  case UnaryNodeOperator::Deref:
+OpName = "deref";
+break;
+  case UnaryNodeOperator::Address:
+OpName = "addressOf";
+break;
+  }
+  return (OpName + "(\"" + Data.Id + "\")").str();
+}
+
+std::string toStringData(const SelectorData &) { return "SelectorData()"; }
+
+std::string toStringData(const AccessData ) {
+  return (llvm::Twine("access(\"") + Data.BaseId + "\", " +
+  Data.Member.toString() + ")")
+  .str();
+}
+
+std::string toStringData(const IfBoundData ) {
+  return (llvm::Twine("ifBound(\"") + Data.Id + "\", " +
+  Data.TruePart.toString() + ", " + Data.FalsePart.toString() + ")")
+  .str();
+}
+
+std::string toStringData(const MatchConsumer &) {
+  return "MatchConsumer()";
+}
+
 // The `evalData()` overloads evaluate the given stencil data to a string, given
 // the match result, and append it to `Result`. We define an overload for each
 // type of stencil data.
@@ -247,6 +296,8 @@
   return isEqualData(Data, OtherPtr->Data);
 return false;
   }
+
+  std::string toString() const override { return toStringData(Data); }
 };
 } // namespace
 
Index: cfe/trunk/unittests/Tooling/StencilTest.cpp
===
--- cfe/trunk/unittests/Tooling/StencilTest.cpp
+++ cfe/trunk/unittests/Tooling/StencilTest.cpp
@@ -389,4 +389,59 @@
   auto S2 = cat(run(F));
   EXPECT_NE(S1, S2);
 }
+
+TEST(StencilToStringTest, RawTextOp) {
+  auto S = cat("foo bar baz");
+  EXPECT_EQ(S.toString(), R"("foo bar baz")");
+}
+
+TEST(StencilToStringTest, RawTextOpEscaping) {
+  auto S = cat("foo \"bar\" baz\\n");
+  EXPECT_EQ(S.toString(), R"("foo \"bar\" baz\\n")");
+}
+
+TEST(StencilToStringTest, DebugPrintNodeOp) {
+  auto S = cat(dPrint("Id"));
+  EXPECT_EQ(S.toString(), R"repr(dPrint("Id"))repr");
+}
+
+TEST(StencilToStringTest, ExpressionOp) {
+  auto S = cat(expression("Id"));
+  EXPECT_EQ(S.toString(), R"repr(expression("Id"))repr");
+}
+
+TEST(StencilToStringTest, DerefOp) {
+  

[PATCH] D68565: [clang] Add test for FindNextToken in Lexer.

2019-10-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGedf5027689c5: [clang] Add test for FindNextToken in Lexer. 
(authored by usaxena95).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68565

Files:
  clang/unittests/Lex/LexerTest.cpp


Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -11,9 +11,11 @@
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Lex/MacroArgs.h"
@@ -21,11 +23,13 @@
 #include "clang/Lex/ModuleLoader.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
-
-using namespace clang;
+#include 
 
 namespace {
+using namespace clang;
+using testing::ElementsAre;
 
 // The test fixture.
 class LexerTest : public ::testing::Test {
@@ -535,4 +539,21 @@
   EXPECT_EQ(Lexer::getSourceText(CR, SourceMgr, LangOpts), "MOO"); // Was "MO".
 }
 
+TEST_F(LexerTest, FindNextToken) {
+  Lex("int abcd = 0;\n"
+  "int xyz = abcd;\n");
+  std::vector GeneratedByNextToken;
+  SourceLocation Loc =
+  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+  while (true) {
+auto T = Lexer::findNextToken(Loc, SourceMgr, LangOpts);
+ASSERT_TRUE(T.hasValue());
+if (T->is(tok::eof))
+  break;
+GeneratedByNextToken.push_back(getSourceText(*T, *T));
+Loc = T->getLocation();
+  }
+  EXPECT_THAT(GeneratedByNextToken, ElementsAre("abcd", "=", "0", ";", "int",
+"xyz", "=", "abcd", ";"));
+}
 } // anonymous namespace


Index: clang/unittests/Lex/LexerTest.cpp
===
--- clang/unittests/Lex/LexerTest.cpp
+++ clang/unittests/Lex/LexerTest.cpp
@@ -11,9 +11,11 @@
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Lex/MacroArgs.h"
@@ -21,11 +23,13 @@
 #include "clang/Lex/ModuleLoader.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
-
-using namespace clang;
+#include 
 
 namespace {
+using namespace clang;
+using testing::ElementsAre;
 
 // The test fixture.
 class LexerTest : public ::testing::Test {
@@ -535,4 +539,21 @@
   EXPECT_EQ(Lexer::getSourceText(CR, SourceMgr, LangOpts), "MOO"); // Was "MO".
 }
 
+TEST_F(LexerTest, FindNextToken) {
+  Lex("int abcd = 0;\n"
+  "int xyz = abcd;\n");
+  std::vector GeneratedByNextToken;
+  SourceLocation Loc =
+  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+  while (true) {
+auto T = Lexer::findNextToken(Loc, SourceMgr, LangOpts);
+ASSERT_TRUE(T.hasValue());
+if (T->is(tok::eof))
+  break;
+GeneratedByNextToken.push_back(getSourceText(*T, *T));
+Loc = T->getLocation();
+  }
+  EXPECT_THAT(GeneratedByNextToken, ElementsAre("abcd", "=", "0", ";", "int",
+"xyz", "=", "abcd", ";"));
+}
 } // anonymous namespace
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68564: [clangd] Catch an unchecked "Expected" in HeaderSourceSwitch.

2019-10-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373897: [clangd] Catch an unchecked 
ExpectedT in HeaderSourceSwitch. (authored by hokein, 
committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68564?vs=223464=223733#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68564

Files:
  clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
  clang-tools-extra/trunk/clangd/ClangdServer.cpp
  clang-tools-extra/trunk/clangd/HeaderSourceSwitch.cpp
  clang-tools-extra/trunk/clangd/unittests/HeaderSourceSwitchTests.cpp


Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -460,7 +460,7 @@
   if (auto CorrespondingFile =
   getCorrespondingHeaderOrSource(Path, FSProvider.getFileSystem()))
 return CB(std::move(CorrespondingFile));
-  auto Action = [Path, CB = std::move(CB),
+  auto Action = [Path = Path.str(), CB = std::move(CB),
  this](llvm::Expected InpAST) mutable {
 if (!InpAST)
   return CB(InpAST.takeError());
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -1045,7 +1045,7 @@
 if (!Path)
   return Reply(Path.takeError());
 if (*Path)
-  Reply(URIForFile::canonicalize(**Path, Params.uri.file()));
+  return Reply(URIForFile::canonicalize(**Path, Params.uri.file()));
 return Reply(llvm::None);
   });
 }
Index: clang-tools-extra/trunk/clangd/HeaderSourceSwitch.cpp
===
--- clang-tools-extra/trunk/clangd/HeaderSourceSwitch.cpp
+++ clang-tools-extra/trunk/clangd/HeaderSourceSwitch.cpp
@@ -86,7 +86,9 @@
 if (auto TargetPath = URI::resolve(TargetURI, OriginalFile)) {
   if (*TargetPath != OriginalFile) // exclude the original file.
 ++Candidates[*TargetPath];
-};
+} else {
+  elog("Failed to resolve URI {0}: {1}", TargetURI, 
TargetPath.takeError());
+}
   };
   // If we switch from a header, we are looking for the implementation
   // file, so we use the definition loc; otherwise we look for the header file,
Index: clang-tools-extra/trunk/clangd/unittests/HeaderSourceSwitchTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/HeaderSourceSwitchTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/HeaderSourceSwitchTests.cpp
@@ -125,6 +125,7 @@
   Testing.HeaderCode = R"cpp(
   void B_Sym1();
   void B_Sym2();
+  void B_Sym3_NoDef();
   )cpp";
   Testing.Filename = "b.cpp";
   Testing.Code = R"cpp(
@@ -163,6 +164,12 @@
  void B_Sym1();
)cpp",
testPath("a.cpp")},
+
+   {R"cpp(
+  // We don't have definition in the index, so stay in the header.
+  void B_Sym3_NoDef();
+   )cpp",
+   None},
   };
   for (const auto  : TestCases) {
 TestTU TU = TestTU::withCode(Case.HeaderCode);


Index: clang-tools-extra/trunk/clangd/ClangdServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdServer.cpp
@@ -460,7 +460,7 @@
   if (auto CorrespondingFile =
   getCorrespondingHeaderOrSource(Path, FSProvider.getFileSystem()))
 return CB(std::move(CorrespondingFile));
-  auto Action = [Path, CB = std::move(CB),
+  auto Action = [Path = Path.str(), CB = std::move(CB),
  this](llvm::Expected InpAST) mutable {
 if (!InpAST)
   return CB(InpAST.takeError());
Index: clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/trunk/clangd/ClangdLSPServer.cpp
@@ -1045,7 +1045,7 @@
 if (!Path)
   return Reply(Path.takeError());
 if (*Path)
-  Reply(URIForFile::canonicalize(**Path, Params.uri.file()));
+  return Reply(URIForFile::canonicalize(**Path, Params.uri.file()));
 return Reply(llvm::None);
   });
 }
Index: clang-tools-extra/trunk/clangd/HeaderSourceSwitch.cpp
===
--- clang-tools-extra/trunk/clangd/HeaderSourceSwitch.cpp
+++ clang-tools-extra/trunk/clangd/HeaderSourceSwitch.cpp
@@ -86,7 +86,9 @@
 if (auto TargetPath = URI::resolve(TargetURI, OriginalFile)) {
   if (*TargetPath != OriginalFile) // exclude the original file.
 ++Candidates[*TargetPath];
-};
+} else {

[PATCH] D68467: [clangd] If an undocumented definition exists, don't accept documentation from other forward decls.

2019-10-07 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373892: [clangd] If an undocumented definition exists, 
dont accept documentation from… (authored by sammccall, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68467?vs=223224=223732#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68467

Files:
  clang-tools-extra/trunk/clangd/index/Merge.cpp
  clang-tools-extra/trunk/clangd/unittests/IndexTests.cpp


Index: clang-tools-extra/trunk/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/IndexTests.cpp
@@ -413,6 +413,16 @@
FileURI("unittest:///test2.cc"));
 }
 
+TEST(MergeIndexTest, NonDocumentation) {
+  Symbol L, R;
+  L.ID = R.ID = SymbolID("x");
+  L.Definition.FileURI = "file:/x.h";
+  R.Documentation = "Forward declarations because x.h is too big to include";
+
+  Symbol M = mergeSymbol(L, R);
+  EXPECT_EQ(M.Documentation, "");
+}
+
 MATCHER_P2(IncludeHeaderWithRef, IncludeHeader, References, "") {
   return (arg.IncludeHeader == IncludeHeader) && (arg.References == 
References);
 }
Index: clang-tools-extra/trunk/clangd/index/Merge.cpp
===
--- clang-tools-extra/trunk/clangd/index/Merge.cpp
+++ clang-tools-extra/trunk/clangd/index/Merge.cpp
@@ -186,7 +186,10 @@
 S.Signature = O.Signature;
   if (S.CompletionSnippetSuffix == "")
 S.CompletionSnippetSuffix = O.CompletionSnippetSuffix;
-  if (S.Documentation == "")
+  // Don't accept documentation from bare forward declarations, if there is a
+  // definition and it didn't provide one. S is often an undocumented class,
+  // and O is a non-canonical forward decl preceded by an irrelevant comment.
+  if (S.Documentation == "" && !S.Definition)
 S.Documentation = O.Documentation;
   if (S.ReturnType == "")
 S.ReturnType = O.ReturnType;


Index: clang-tools-extra/trunk/clangd/unittests/IndexTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/IndexTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/IndexTests.cpp
@@ -413,6 +413,16 @@
FileURI("unittest:///test2.cc"));
 }
 
+TEST(MergeIndexTest, NonDocumentation) {
+  Symbol L, R;
+  L.ID = R.ID = SymbolID("x");
+  L.Definition.FileURI = "file:/x.h";
+  R.Documentation = "Forward declarations because x.h is too big to include";
+
+  Symbol M = mergeSymbol(L, R);
+  EXPECT_EQ(M.Documentation, "");
+}
+
 MATCHER_P2(IncludeHeaderWithRef, IncludeHeader, References, "") {
   return (arg.IncludeHeader == IncludeHeader) && (arg.References == References);
 }
Index: clang-tools-extra/trunk/clangd/index/Merge.cpp
===
--- clang-tools-extra/trunk/clangd/index/Merge.cpp
+++ clang-tools-extra/trunk/clangd/index/Merge.cpp
@@ -186,7 +186,10 @@
 S.Signature = O.Signature;
   if (S.CompletionSnippetSuffix == "")
 S.CompletionSnippetSuffix = O.CompletionSnippetSuffix;
-  if (S.Documentation == "")
+  // Don't accept documentation from bare forward declarations, if there is a
+  // definition and it didn't provide one. S is often an undocumented class,
+  // and O is a non-canonical forward decl preceded by an irrelevant comment.
+  if (S.Documentation == "" && !S.Definition)
 S.Documentation = O.Documentation;
   if (S.ReturnType == "")
 S.ReturnType = O.ReturnType;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68458: [clangd] Collect missing macro references.

2019-10-07 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL373889: [clangd] Collect missing macro references. (authored 
by hokein, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D68458?vs=223191=223730#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D68458

Files:
  clang-tools-extra/trunk/clangd/CollectMacros.h
  clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/trunk/clangd/CollectMacros.h
===
--- clang-tools-extra/trunk/clangd/CollectMacros.h
+++ clang-tools-extra/trunk/clangd/CollectMacros.h
@@ -25,7 +25,8 @@
   std::vector Ranges;
 };
 
-/// Collects macro definitions and expansions in the main file. It is used to:
+/// Collects macro references (e.g. definitions, expansions) in the main file.
+/// It is used to:
 ///  - collect macros in the preamble section of the main file (in 
Preamble.cpp)
 ///  - collect macros after the preamble of the main file (in ParsedAST.cpp)
 class CollectMainFileMacros : public PPCallbacks {
@@ -49,6 +50,27 @@
 add(MacroName, MD.getMacroInfo());
   }
 
+  void MacroUndefined(const clang::Token ,
+  const clang::MacroDefinition ,
+  const clang::MacroDirective *Undef) override {
+add(MacroName, MD.getMacroInfo());
+  }
+
+  void Ifdef(SourceLocation Loc, const Token ,
+ const MacroDefinition ) override {
+add(MacroName, MD.getMacroInfo());
+  }
+
+  void Ifndef(SourceLocation Loc, const Token ,
+  const MacroDefinition ) override {
+add(MacroName, MD.getMacroInfo());
+  }
+
+  void Defined(const Token , const MacroDefinition ,
+   SourceRange Range) override {
+add(MacroName, MD.getMacroInfo());
+  }
+
 private:
   void add(const Token , const MacroInfo *MI) {
 if (!InMainFile)
@@ -57,7 +79,7 @@
 if (Loc.isMacroID())
   return;
 
-if (auto Range = getTokenRange(SM, LangOpts, MacroNameTok.getLocation())) {
+if (auto Range = getTokenRange(SM, LangOpts, Loc)) {
   Out.Names.insert(MacroNameTok.getIdentifierInfo()->getName());
   Out.Ranges.push_back(*Range);
 }
Index: clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/trunk/clangd/unittests/SemanticHighlightingTests.cpp
@@ -476,6 +476,20 @@
 $Macro[[assert]]($Variable[[x]] != $Function[[f]]());
   }
 )cpp",
+  // highlighting all macro references
+  R"cpp(
+  #ifndef $Macro[[name]]
+  #define $Macro[[name]]
+  #endif
+
+  #define $Macro[[test]]
+  #undef $Macro[[test]]
+  #ifdef $Macro[[test]]
+  #endif
+
+  #if defined($Macro[[test]])
+  #endif
+)cpp",
   R"cpp(
   struct $Class[[S]] {
 $Primitive[[float]] $Field[[Value]];


Index: clang-tools-extra/trunk/clangd/CollectMacros.h
===
--- clang-tools-extra/trunk/clangd/CollectMacros.h
+++ clang-tools-extra/trunk/clangd/CollectMacros.h
@@ -25,7 +25,8 @@
   std::vector Ranges;
 };
 
-/// Collects macro definitions and expansions in the main file. It is used to:
+/// Collects macro references (e.g. definitions, expansions) in the main file.
+/// It is used to:
 ///  - collect macros in the preamble section of the main file (in Preamble.cpp)
 ///  - collect macros after the preamble of the main file (in ParsedAST.cpp)
 class CollectMainFileMacros : public PPCallbacks {
@@ -49,6 +50,27 @@
 add(MacroName, MD.getMacroInfo());
   }
 
+  void MacroUndefined(const clang::Token ,
+  const clang::MacroDefinition ,
+  const clang::MacroDirective *Undef) override {
+add(MacroName, MD.getMacroInfo());
+  }
+
+  void Ifdef(SourceLocation Loc, const Token ,
+ const MacroDefinition ) override {
+add(MacroName, MD.getMacroInfo());
+  }
+
+  void Ifndef(SourceLocation Loc, const Token ,
+  const MacroDefinition ) override {
+add(MacroName, MD.getMacroInfo());
+  }
+
+  void Defined(const Token , const MacroDefinition ,
+   SourceRange Range) override {
+add(MacroName, MD.getMacroInfo());
+  }
+
 private:
   void add(const Token , const MacroInfo *MI) {
 if (!InMainFile)
@@ -57,7 +79,7 @@
 if (Loc.isMacroID())
   return;
 
-if (auto Range = getTokenRange(SM, LangOpts, MacroNameTok.getLocation())) {
+if (auto Range = getTokenRange(SM, LangOpts, Loc)) {
   Out.Names.insert(MacroNameTok.getIdentifierInfo()->getName());
   Out.Ranges.push_back(*Range);
 }
Index: 

[PATCH] D68578: [HIP] Fix device stub name

2019-10-07 Thread Tony Tye via Phabricator via cfe-commits
t-tye added a comment.

In D68578#1697898 , @tra wrote:

> In D68578#1697851 , @yaxunl wrote:
>
> > In D68578#1697822 , @tra wrote:
> >
> > > Could you elaborate on how exactly current implementation does not work?
> > >
> > > I would expect the kernel and the stub to be two distinct entities, as 
> > > far as debugger is concerned. It does have enough information to track 
> > > each independently (different address, .stub suffix, perhaps knowledge 
> > > whether it's device or host code). Without the details, it looks to me 
> > > that this is something that can and should be dealt with in the debugger. 
> > > I've asked the same question in D63335  
> > > but I don't think I've got a good answer.
> >
> >
> > HIP debugger is a branch of gdb and the changes to support HIP will be 
> > upstreamed. When users set break point on a kernel, they intend to set a 
> > break point on the real kernel, not the device stub function. The device 
> > stub function is only a compiler generated helper function to help launch 
> > the kernel. Therefore it should have a different name so that it does not 
> > interfere with the symbol resolution of the real kernel.
>
>
> I would agree that having distinct names for the device-side kernel and it's 
> host-side stub would probably make things easier for debugger. 
>  However, debugger does have access to mangled names and does see the '.stub' 
> suffix in the mangled name. I don't understand why it can't be considered to 
> disambiguate between the kernel and the stub? 
>  I'm clearly missing something here. Is there a chance to get someone from 
> the debugger team to chime in on this review directly?
>
> Also, I would not agree that `they intend to set a break point on the real 
> kernel` is the only scenario. E.g. quite often when I debug CUDA stuff, I do 
> only care about host-side things and I do want to set breakpoint on the stub, 
> so I can check kernel call parameters as they are passed to the kernel. It 
> would be great if there were a way to explicitly tell debugger whether we 
> want host-side stub or the kernel without having user to know how particular 
> compiler transforms the name. For the user both entities have the same name, 
> but distinct location and there should be a way to express that in the 
> debugger.


From a source language point of view, the device function comprises the code 
that is launched as a grid. We need this fact to be present in the symbols 
used. Only the device function should have a symbol name matching the mangled 
name of the device function. It the device function has both a host and device 
implementation then both can have the source language function name for the 
symbol since both actually implement the device function. If the user asks to 
set a breakpoint in the device function then the debugger would set in both 
implementations so the user is notified when the source program executes the 
device function, regardless of which implementation is invoked. This is similar 
to the debugger setting a breakpoint in a function that is inlined into 
multiple places: the debugger sets breeakpoints in all the inlined places so 
the user can tstill think of the program debugging in terms of the source 
language semantics.

In contrast, the stub is effectively part of the implementation of actually 
launching the device function. It should have a distinct name. The debugger can 
still be used to set a breakpoint in it, or to step into it. But that should be 
done in terms of the stub name. If the debugger wants to support source 
language specific intelligence it can provide a helper library that understands 
the stub names. This helper library (similar to the thread helper library) can 
be used by the debugger to present a cleaner language view to the user. In fact 
OpenMP has also done this and provides a helper library called OMPD that can be 
used by tools such as a debugger to hide OpenMP trampoline functions etc.

I am a little unclear what this patch is doing as it is mentioned that the 
mangled name has a _stub in it. My understanding is that the intention was to 
create a distinct unmangled name for the stub, and then mangle it so that the 
resulting symbol was a legal mangled name. It sounded like this was the 
preferred approach, and makes sense to me based on my current understanding. Am 
I understanding this correctly?


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

https://reviews.llvm.org/D68578



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


r374011 - [NFC] Fix ubsan-blacklist test

2019-10-07 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Oct  7 19:26:17 2019
New Revision: 374011

URL: http://llvm.org/viewvc/llvm-project?rev=374011=rev
Log:
[NFC] Fix ubsan-blacklist test

Restored original test and marked tests for VFS as unsupported on Windows.

Added:
cfe/trunk/test/CodeGen/ubsan-blacklist-vfs.c
Modified:
cfe/trunk/test/CodeGen/ubsan-blacklist.c

Added: cfe/trunk/test/CodeGen/ubsan-blacklist-vfs.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-blacklist-vfs.c?rev=374011=auto
==
--- cfe/trunk/test/CodeGen/ubsan-blacklist-vfs.c (added)
+++ cfe/trunk/test/CodeGen/ubsan-blacklist-vfs.c Mon Oct  7 19:26:17 2019
@@ -0,0 +1,38 @@
+// UNSUPPORTED: system-windows
+
+// Verify ubsan doesn't emit checks for blacklisted functions and files
+// RUN: echo "fun:hash" > %t-func.blacklist
+// RUN: echo "src:%s" | sed -e 's/\\//g' > %t-file.blacklist
+
+// RUN: rm -f %t-vfsoverlay.yaml
+// RUN: rm -f %t-nonexistent.blacklist
+// RUN: sed -e "s|@DIR@|%/T|g" %S/Inputs/sanitizer-blacklist-vfsoverlay.yaml | 
sed -e "s|@REAL_FILE@|%/t-func.blacklist|g" | sed -e 
"s|@NONEXISTENT_FILE@|%/t-nonexistent.blacklist|g" > %t-vfsoverlay.yaml
+// RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/only-virtual-file.blacklist 
-emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
+
+// RUN: not %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/invalid-virtual-file.blacklist 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=INVALID-MAPPED-FILE
+// INVALID-MAPPED-FILE: invalid-virtual-file.blacklist': No such file or 
directory
+
+// RUN: not %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%t-nonexistent.blacklist -emit-llvm %s 
-o - 2>&1 | FileCheck %s --check-prefix=INVALID
+// INVALID: nonexistent.blacklist': No such file or directory
+
+unsigned i;
+
+// DEFAULT: @hash
+// FUNC: @hash
+// FILE: @hash
+unsigned hash() {
+// DEFAULT: call {{.*}}void @__ubsan
+// FUNC-NOT: call {{.*}}void @__ubsan
+// FILE-NOT: call {{.*}}void @__ubsan
+  return i * 37;
+}
+
+// DEFAULT: @add
+// FUNC: @add
+// FILE: @add
+unsigned add() {
+// DEFAULT: call {{.*}}void @__ubsan
+// FUNC: call {{.*}}void @__ubsan
+// FILE-NOT: call {{.*}}void @__ubsan
+  return i + 1;
+}

Modified: cfe/trunk/test/CodeGen/ubsan-blacklist.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-blacklist.c?rev=374011=374010=374011=diff
==
--- cfe/trunk/test/CodeGen/ubsan-blacklist.c (original)
+++ cfe/trunk/test/CodeGen/ubsan-blacklist.c Mon Oct  7 19:26:17 2019
@@ -5,17 +5,6 @@
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow 
-fsanitize-blacklist=%t-func.blacklist -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FUNC
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow 
-fsanitize-blacklist=%t-file.blacklist -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FILE
 
-// RUN: rm -f %t-vfsoverlay.yaml
-// RUN: rm -f %t-nonexistent.blacklist
-// RUN: sed -e "s|@DIR@|%/T|g" %S/Inputs/sanitizer-blacklist-vfsoverlay.yaml | 
sed -e "s|@REAL_FILE@|%/t-func.blacklist|g" | sed -e 
"s|@NONEXISTENT_FILE@|%/t-nonexistent.blacklist|g" > %t-vfsoverlay.yaml
-// RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/only-virtual-file.blacklist 
-emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
-
-// RUN: not %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/invalid-virtual-file.blacklist 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=INVALID-MAPPED-FILE
-// INVALID-MAPPED-FILE: invalid-virtual-file.blacklist': No such file or 
directory
-
-// RUN: not %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%t-nonexistent.blacklist -emit-llvm %s 
-o - 2>&1 | FileCheck %s --check-prefix=INVALID
-// INVALID: nonexistent.blacklist': No such file or directory
-
 unsigned i;
 
 // DEFAULT: @hash


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


[PATCH] D68587: [hip] Assume host-only compilation if the final phase is ahead of `backend`.

2019-10-07 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D68587#1698247 , @tra wrote:

> In D68587#1698102 , @hliao wrote:
>
> > for most compilation tools, single input and single output are expected. 
> > Without assuming `-fsyntax-only` alone is host-compilation only, that at 
> > least run syntax checking twice.
>
>
> I believe the driver will not run subsequent jobs if one of the device 
> compilations fails. You may see duplicate warnings from multiple stages, but 
> overall the error handling works in a fairly predictable way now.


It still runs and gives the same error (if that error is applicable to both 
sides) at least twice if you just specify `-fsyntax-only` or `-E`. That won't 
happen for regular compilation option (`-c`) due to the additional device 
dependencies added.
The error itself is, in fact, should be clear enough, the most confusing part 
is the diagnostic message and suggestions from clang as host- and device-side 
compilations are quite different, especially the error message may be mixed 
with other-side the normal output.

> 
> 
>> The result may be misleading
> 
> Potentially repeated warning are still *correct*, while omitting an error is 
> not, IMO.  I believe that did come up before and we had to make some changes 
> to the driver to keep host compilation working even when device-side 
> compilations produce no output.
> 
> To think of it, I'm starting to doubt that this patch is an improvement for 
> `-M` either. You will get the dependencies for the host, but they are not 
> necessarily the same as the dependencies for the device-side compilation. 
> Producing a partial list of dependencies will be potentially incorrect. IMO 
> we do need dependencies info from all sub-compilations.

Even without this patch, `-M` or more specifically `-MD` already breaks now as 
we just run the dependency generation action twice for each side. The later 
will overwrite the former *.d file. We need special handling of `-M` to match 
nvcc.

> Perhaps we should limit the scope of this patch to -E only for now?

Just found nvcc's `-E` returns the output of the device-side compilation for 
the first GPU arch specified. Anyway, whether to match that behavior is just 
another question.

> 
> 
>> and there are clang-based tools (like clang-tidy) may have no legacy way to 
>> be runnable.
> 
> Tooling does get surprised by the multiple jobs created by CUDA compilation. 
>  The work around is to pass `--cuda-host-only`. Passing an extra flag is 
> usually not a showstopper (at least it was not in cases I had to deal with at 
> work and we have fair number of clang-derived tools). Usually in order to get 
> correct CUDA compilation in this scenario you will also need to tell the tool 
> where to find CUDA's headers, so the mechanism for passing additional options 
> already exists.

but some tools, like clang-tidy, may be found difficult to insert that option 
properly, says `clang-tidy -p` supposes to read the compilation command 
databased generated by cmake or meta-build systems and performs additional 
checks for sources. Adding that option may inevitably make them CUDA/HIP aware.

> If that's still a problem, then we should change the tooling infrastructure 
> to use host-only compilation for HIP and CUDA by default.

That's an option I was looking into as well. But, generally speaking, we need a 
clear definition on expected output for options like `-M`, `-MD`, `-E`, 
`-fsyntax-only`, `-S -emit-llvm`, even `-S` (for HIP only.)

>> To check device-side compilation syntax, we are still able to explicitly ask 
>> that by specifying `--cuda-device-only`.
> 
> Yes, that could be done. However, as I've mentioned above the same argument 
> applies to tooling & `--cuda-host-only`, so there's no advantage here. IMO 
> the most common use case should be the default, so it's the clang itself 
> which should remain working correctly without having to add extra flags.
> 
> Also, this patch makes it impossible to run -fsyntax-only on *all* 
> sub-compilations at once. I will have to run `clang -fsyntax-only` multiple 
> times -- once per host and once per each device.

We do have another option `-cuda-compile-host-device` to explicit ask for host- 
and device-side compilations.

> I do want to check all sub-compilations with `-fsyntax-only` on a regular 
> basis (e.g. when running creduce on a cuda source), so having to do that for 
> each sub-compilation separately does not look like an improvement to me.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68587



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


[PATCH] D67837: [CUDA][HIP] Fix host/device check with -fopenmp

2019-10-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 223712.
yaxunl marked 14 inline comments as done.
yaxunl added a comment.

revised by Alexey's comments.


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

https://reviews.llvm.org/D67837

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaCUDA.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaOpenMP.cpp
  test/CodeGenCUDA/openmp-target.cu
  test/OpenMP/declare_target_messages.cpp
  test/SemaCUDA/call-device-fn-from-host.cu
  test/SemaCUDA/host-device-constexpr.cu
  test/SemaCUDA/openmp-static-func.cu
  test/SemaCUDA/openmp-target.cu

Index: test/SemaCUDA/openmp-target.cu
===
--- /dev/null
+++ test/SemaCUDA/openmp-target.cu
@@ -0,0 +1,43 @@
+// RUN: %clang_cc1 -triple x86_64 -verify=expected,dev \
+// RUN:-verify-ignore-unexpected=note \
+// RUN:-fopenmp -fopenmp-version=50 -o - %s
+// RUN: %clang_cc1 -triple x86_64 -verify -verify-ignore-unexpected=note\
+// RUN:-fopenmp -fopenmp-version=50 -o - -x c++ %s
+// RUN: %clang_cc1 -triple x86_64 -verify=dev -verify-ignore-unexpected=note\
+// RUN:-fcuda-is-device -o - %s
+
+#if __CUDA__
+#include "Inputs/cuda.h"
+__device__ void cu_devf();
+#endif
+
+void bazz() {}
+#pragma omp declare target to(bazz) device_type(nohost)
+void bazzz() {bazz();}
+#pragma omp declare target to(bazzz) device_type(nohost)
+void any() {bazz();} // expected-error {{function with 'device_type(nohost)' is not available on host}}
+void host1() {bazz();}
+#pragma omp declare target to(host1) device_type(host)
+void host2() {bazz();}
+#pragma omp declare target to(host2)
+void device() {host1();}
+#pragma omp declare target to(device) device_type(nohost)
+void host3() {host1();}
+#pragma omp declare target to(host3)
+
+#pragma omp declare target
+void any1() {any();}
+void any2() {host1();}
+void any3() {device();} // expected-error {{function with 'device_type(nohost)' is not available on host}}
+void any4() {any2();}
+#pragma omp end declare target
+
+void any5() {any();}
+void any6() {host1();}
+void any7() {device();} // expected-error {{function with 'device_type(nohost)' is not available on host}}
+void any8() {any2();}
+
+#if __CUDA__
+void cu_hostf() { cu_devf(); } // dev-error {{no matching function for call to 'cu_devf'}}
+__device__ void cu_devf2() { cu_hostf(); } // dev-error{{no matching function for call to 'cu_hostf'}}
+#endif
Index: test/SemaCUDA/openmp-static-func.cu
===
--- /dev/null
+++ test/SemaCUDA/openmp-static-func.cu
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:-verify -fopenmp %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:-verify -fopenmp -x hip %s
+// expected-no-diagnostics
+
+// Tests there is no assertion in Sema::markKnownEmitted when fopenmp is used
+// with CUDA/HIP host compilation.
+
+static void f() {}
+
+static void g() { f(); }
+
+static void h() { g(); }
Index: test/SemaCUDA/host-device-constexpr.cu
===
--- test/SemaCUDA/host-device-constexpr.cu
+++ test/SemaCUDA/host-device-constexpr.cu
@@ -1,5 +1,10 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -isystem %S/Inputs %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -isystem %S/Inputs %s -fcuda-is-device
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -isystem %S/Inputs %s \
+// RUN:-fcuda-is-device
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -isystem %S/Inputs \
+// RUN:-fopenmp %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -isystem %S/Inputs \
+// RUN:-fopenmp %s -fcuda-is-device
 
 #include "Inputs/cuda.h"
 
Index: test/SemaCUDA/call-device-fn-from-host.cu
===
--- test/SemaCUDA/call-device-fn-from-host.cu
+++ test/SemaCUDA/call-device-fn-from-host.cu
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 %s --std=c++11 -triple x86_64-unknown-linux -emit-llvm -o - \
 // RUN:   -verify -verify-ignore-unexpected=note
+// RUN: %clang_cc1 %s --std=c++11 -triple x86_64-unknown-linux -emit-llvm -o - \
+// RUN:   -verify -verify-ignore-unexpected=note -fopenmp
 
 // Note: This test won't work with -fsyntax-only, because some of these errors
 // are emitted during codegen.
Index: test/OpenMP/declare_target_messages.cpp
===
--- test/OpenMP/declare_target_messages.cpp
+++ test/OpenMP/declare_target_messages.cpp
@@ -162,10 +162,10 @@
 #pragma omp declare target link(x) // expected-error {{'x' must not appear in both clauses 'to' and 'link'}}
 
 void bazz() {}
-#pragma omp declare target to(bazz) device_type(nohost) // omp45-error {{unexpected 'device_type' clause, only 'to' or 'link' clauses expected}}
+#pragma omp declare target to(bazz) 

r374006 - Reland 'Add VFS support for sanitizers' blacklist'

2019-10-07 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Oct  7 18:13:17 2019
New Revision: 374006

URL: http://llvm.org/viewvc/llvm-project?rev=374006=rev
Log:
Reland 'Add VFS support for sanitizers' blacklist'

The original patch broke the test for Windows.
Trying to fix as per Reid's suggestions outlined here:
https://reviews.llvm.org/rC371663

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

Added:
cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/CodeGen/ubsan-blacklist.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=374006=374005=374006=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Oct  7 18:13:17 2019
@@ -72,6 +72,7 @@
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -81,6 +82,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -826,6 +828,18 @@ static bool isAddrSpaceMapManglingEnable
   llvm_unreachable("getAddressSpaceMapMangling() doesn't cover anything.");
 }
 
+static std::vector
+getRealPaths(llvm::vfs::FileSystem , llvm::ArrayRef Paths) {
+  std::vector Result;
+  llvm::SmallString<128> Buffer;
+  for (const auto  : Paths) {
+if (std::error_code EC = VFS.getRealPath(File, Buffer))
+  llvm::report_fatal_error("can't open file '" + File + "': " + 
EC.message());
+Result.push_back(Buffer.str());
+  }
+  return Result;
+}
+
 ASTContext::ASTContext(LangOptions , SourceManager ,
IdentifierTable , SelectorTable ,
Builtin::Context )
@@ -833,7 +847,10 @@ ASTContext::ASTContext(LangOptions 
   TemplateSpecializationTypes(this_()),
   DependentTemplateSpecializationTypes(this_()),
   SubstTemplateTemplateParmPacks(this_()), SourceMgr(SM), LangOpts(LOpts),
-  SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, 
SM)),
+  SanitizerBL(new SanitizerBlacklist(
+  getRealPaths(SM.getFileManager().getVirtualFileSystem(),
+   LangOpts.SanitizerBlacklistFiles),
+  SM)),
   XRayFilter(new XRayFunctionFilter(LangOpts.XRayAlwaysInstrumentFiles,
 LangOpts.XRayNeverInstrumentFiles,
 LangOpts.XRayAttrListFiles, SM)),

Added: cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml?rev=374006=auto
==
--- cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml (added)
+++ cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml Mon Oct  
7 18:13:17 2019
@@ -0,0 +1,15 @@
+{
+  'version': 0,
+  'roots': [
+{ 'name': '@DIR@', 'type': 'directory',
+  'contents': [
+{ 'name': 'only-virtual-file.blacklist', 'type': 'file',
+  'external-contents': '@REAL_FILE@'
+},
+{ 'name': 'invalid-virtual-file.blacklist', 'type': 'file',
+  'external-contents': '@NONEXISTENT_FILE@'
+}
+  ]
+}
+  ]
+}

Modified: cfe/trunk/test/CodeGen/ubsan-blacklist.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-blacklist.c?rev=374006=374005=374006=diff
==
--- cfe/trunk/test/CodeGen/ubsan-blacklist.c (original)
+++ cfe/trunk/test/CodeGen/ubsan-blacklist.c Mon Oct  7 18:13:17 2019
@@ -5,6 +5,17 @@
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow 
-fsanitize-blacklist=%t-func.blacklist -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FUNC
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow 
-fsanitize-blacklist=%t-file.blacklist -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FILE
 
+// RUN: rm -f %t-vfsoverlay.yaml
+// RUN: rm -f %t-nonexistent.blacklist
+// RUN: sed -e "s|@DIR@|%/T|g" %S/Inputs/sanitizer-blacklist-vfsoverlay.yaml | 
sed -e "s|@REAL_FILE@|%/t-func.blacklist|g" | sed -e 
"s|@NONEXISTENT_FILE@|%/t-nonexistent.blacklist|g" > %t-vfsoverlay.yaml
+// RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/only-virtual-file.blacklist 
-emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
+
+// RUN: not %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/invalid-virtual-file.blacklist 
-emit-llvm %s -o - 2>&1 | 

[PATCH] D68591: [analyzer] PR43551: Do not dereferce void* in UndefOrNullArgVisitor

2019-10-07 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Thanks!!




Comment at: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp:2030-2033
 // FIXME: this is a hack for fixing a later crash when attempting to
 // dereference a void* pointer.
 // We should not try to dereference pointers at all when we don't care
 // what is written inside the pointer.

Aha, so you're basically propagating this FIXME instead of addressing it. When 
it was originally added, i vaguely recall that the pointer that we were trying 
to dereference did not really need to be tracked to begin with. I'm really 
curious if that's still the case in this example.



Comment at: clang/test/Analysis/novoidtypecrash.c:1
 // RUN: %clang_analyze_cc1 -analyzer-checker=core %s
+x;

So does the warning get actually emitted, or is it marked as invalid? Maybe 
it's worth it to add `-verify` (and maybe even `-analyzer-output=text`) and 
assess how good the report actually is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68591



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


r373999 - Revert "Add VFS support for sanitizers' blacklist"

2019-10-07 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Oct  7 17:36:19 2019
New Revision: 373999

URL: http://llvm.org/viewvc/llvm-project?rev=373999=rev
Log:
Revert "Add VFS support for sanitizers' blacklist"

Fix tests on Windows for now.

This reverts commit 96ac97a4213287003f08636d0c372b3f71e9cfca.

Removed:
cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/CodeGen/ubsan-blacklist.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=373999=373998=373999=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Oct  7 17:36:19 2019
@@ -72,7 +72,6 @@
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
-#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -82,7 +81,6 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
-#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -828,18 +826,6 @@ static bool isAddrSpaceMapManglingEnable
   llvm_unreachable("getAddressSpaceMapMangling() doesn't cover anything.");
 }
 
-static std::vector
-getRealPaths(llvm::vfs::FileSystem , llvm::ArrayRef Paths) {
-  std::vector Result;
-  llvm::SmallString<128> Buffer;
-  for (const auto  : Paths) {
-if (std::error_code EC = VFS.getRealPath(File, Buffer))
-  llvm::report_fatal_error("can't open file '" + File + "': " + 
EC.message());
-Result.push_back(Buffer.str());
-  }
-  return Result;
-}
-
 ASTContext::ASTContext(LangOptions , SourceManager ,
IdentifierTable , SelectorTable ,
Builtin::Context )
@@ -847,10 +833,7 @@ ASTContext::ASTContext(LangOptions 
   TemplateSpecializationTypes(this_()),
   DependentTemplateSpecializationTypes(this_()),
   SubstTemplateTemplateParmPacks(this_()), SourceMgr(SM), LangOpts(LOpts),
-  SanitizerBL(new SanitizerBlacklist(
-  getRealPaths(SM.getFileManager().getVirtualFileSystem(),
-   LangOpts.SanitizerBlacklistFiles),
-  SM)),
+  SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, 
SM)),
   XRayFilter(new XRayFunctionFilter(LangOpts.XRayAlwaysInstrumentFiles,
 LangOpts.XRayNeverInstrumentFiles,
 LangOpts.XRayAttrListFiles, SM)),

Removed: cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml?rev=373998=auto
==
--- cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml (original)
+++ cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml (removed)
@@ -1,15 +0,0 @@
-{
-  'version': 0,
-  'roots': [
-{ 'name': '@DIR@', 'type': 'directory',
-  'contents': [
-{ 'name': 'only-virtual-file.blacklist', 'type': 'file',
-  'external-contents': '@REAL_FILE@'
-},
-{ 'name': 'invalid-virtual-file.blacklist', 'type': 'file',
-  'external-contents': '@NONEXISTENT_FILE@'
-}
-  ]
-}
-  ]
-}

Modified: cfe/trunk/test/CodeGen/ubsan-blacklist.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-blacklist.c?rev=373999=373998=373999=diff
==
--- cfe/trunk/test/CodeGen/ubsan-blacklist.c (original)
+++ cfe/trunk/test/CodeGen/ubsan-blacklist.c Mon Oct  7 17:36:19 2019
@@ -5,17 +5,6 @@
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow 
-fsanitize-blacklist=%t-func.blacklist -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FUNC
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow 
-fsanitize-blacklist=%t-file.blacklist -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FILE
 
-// RUN: rm -f %t-vfsoverlay.yaml
-// RUN: rm -f %t-nonexistent.blacklist
-// RUN: sed -e "s|@DIR@|%T|g" %S/Inputs/sanitizer-blacklist-vfsoverlay.yaml | 
sed -e "s|@REAL_FILE@|%t-func.blacklist|g" | sed -e 
"s|@NONEXISTENT_FILE@|%t-nonexistent.blacklist|g" > %t-vfsoverlay.yaml
-// RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/only-virtual-file.blacklist 
-emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
-
-// RUN: not %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/invalid-virtual-file.blacklist 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=INVALID-MAPPED-FILE
-// INVALID-MAPPED-FILE: invalid-virtual-file.blacklist': No such 

[PATCH] D68055: Add -fgnuc-version= to control __GNUC__ and other GCC macros

2019-10-07 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

From a big-picture perspective, I would like us to move to treating MS and GNU 
extensions in the same way (at the cc1 level) to the extent that we can. I 
think this moves us in that direction.

One comment, though: I'm not convinced that the `__EXCEPTIONS` macro should be 
controlled by this flag. Many compilers define this when exceptions are 
available (ARM, IBM, HP, EDG in all modes -- including MSVC-compatible mode, 
...) and it's not obvious to me whether it is in fact a GNU extension or has 
more history than that. (It's also a somewhat-documented 

 Clang feature independent of GCC compatibility.)

Do you know why we turn that macro off under `MSVCCompat`? If EDG can get away 
with defining it in MSVC-compatible mode, I would expect that we can too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68055



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


r373992 - [clang] Accept -ftrivial-auto-var-init in clang-cl

2019-10-07 Thread Vitaly Buka via cfe-commits
Author: vitalybuka
Date: Mon Oct  7 16:57:11 2019
New Revision: 373992

URL: http://llvm.org/viewvc/llvm-project?rev=373992=rev
Log:
[clang] Accept -ftrivial-auto-var-init in clang-cl

Reviewers: eugenis, rnk

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/test/Driver/cl-options.c

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=373992=373991=373992=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Oct  7 16:57:11 2019
@@ -1715,10 +1715,10 @@ def fstack_protector : Flag<["-"], "fsta
"alloca, which are of greater size than ssp-buffer-size (default: 8 
bytes). "
"All variable sized calls to alloca are considered vulnerable">;
 def ftrivial_auto_var_init : Joined<["-"], "ftrivial-auto-var-init=">, 
Group,
-  Flags<[CC1Option]>, HelpText<"Initialize trivial automatic stack variables: 
uninitialized (default)"
+  Flags<[CC1Option, CoreOption]>, HelpText<"Initialize trivial automatic stack 
variables: uninitialized (default)"
   " | pattern">, Values<"uninitialized,pattern">;
 def enable_trivial_var_init_zero : Joined<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
-  Flags<[CC1Option]>,
+  Flags<[CC1Option, CoreOption]>,
   HelpText<"Trivial automatic variable initialization to zero is only here for 
benchmarks, it'll eventually be removed, and I'm OK with that because I'm only 
using it to benchmark">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, 
Flags<[CoreOption]>,
   HelpText<"Emit full debug info for all types used by the program">;

Modified: cfe/trunk/test/Driver/cl-options.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cl-options.c?rev=373992=373991=373992=diff
==
--- cfe/trunk/test/Driver/cl-options.c (original)
+++ cfe/trunk/test/Driver/cl-options.c Mon Oct  7 16:57:11 2019
@@ -653,6 +653,8 @@
 // RUN: -fcs-profile-generate \
 // RUN: -fcs-profile-generate=dir \
 // RUN: -ftime-trace \
+// RUN: -ftrivial-auto-var-init=zero \
+// RUN: 
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang \
 // RUN: --version \
 // RUN: -Werror /Zs -- %s 2>&1
 


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


[PATCH] D68608: [clang] Accept -ftrivial-auto-var-init in clang-cl

2019-10-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked an inline comment as done.
vitalybuka added inline comments.



Comment at: clang/include/clang/Driver/Options.td:1720
   " | pattern">, Values<"uninitialized,pattern">;
 def enable_trivial_var_init_zero : Joined<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
+  Flags<[CC1Option, CoreOption]>,

rnk wrote:
> Should this really be Joined? Does it take an argument? Should it use Flag?
D68610


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68608



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


[PATCH] D68610: [clang] enable_trivial_var_init_zero should not be Joined<>

2019-10-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added a reviewer: rnk.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68610

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1717,7 +1717,7 @@
 def ftrivial_auto_var_init : Joined<["-"], "ftrivial-auto-var-init=">, 
Group,
   Flags<[CC1Option, CoreOption]>, HelpText<"Initialize trivial automatic stack 
variables: uninitialized (default)"
   " | pattern">, Values<"uninitialized,pattern">;
-def enable_trivial_var_init_zero : Joined<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
+def enable_trivial_var_init_zero : Flag<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
   Flags<[CC1Option, CoreOption]>,
   HelpText<"Trivial automatic variable initialization to zero is only here for 
benchmarks, it'll eventually be removed, and I'm OK with that because I'm only 
using it to benchmark">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, 
Flags<[CoreOption]>,


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1717,7 +1717,7 @@
 def ftrivial_auto_var_init : Joined<["-"], "ftrivial-auto-var-init=">, Group,
   Flags<[CC1Option, CoreOption]>, HelpText<"Initialize trivial automatic stack variables: uninitialized (default)"
   " | pattern">, Values<"uninitialized,pattern">;
-def enable_trivial_var_init_zero : Joined<["-"], "enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
+def enable_trivial_var_init_zero : Flag<["-"], "enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
   Flags<[CC1Option, CoreOption]>,
   HelpText<"Trivial automatic variable initialization to zero is only here for benchmarks, it'll eventually be removed, and I'm OK with that because I'm only using it to benchmark">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, Flags<[CoreOption]>,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68608: [clang] Accept -ftrivial-auto-var-init in clang-cl

2019-10-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm




Comment at: clang/include/clang/Driver/Options.td:1720
   " | pattern">, Values<"uninitialized,pattern">;
 def enable_trivial_var_init_zero : Joined<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
+  Flags<[CC1Option, CoreOption]>,

Should this really be Joined? Does it take an argument? Should it use Flag?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68608



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


[PATCH] D68608: [clang] Accept -ftrivial-auto-var-init in clang-cl

2019-10-07 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka created this revision.
vitalybuka added reviewers: eugenis, rnk.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68608

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/cl-options.c


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -653,6 +653,8 @@
 // RUN: -fcs-profile-generate \
 // RUN: -fcs-profile-generate=dir \
 // RUN: -ftime-trace \
+// RUN: -ftrivial-auto-var-init=zero \
+// RUN: 
-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang \
 // RUN: --version \
 // RUN: -Werror /Zs -- %s 2>&1
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1715,10 +1715,10 @@
"alloca, which are of greater size than ssp-buffer-size (default: 8 
bytes). "
"All variable sized calls to alloca are considered vulnerable">;
 def ftrivial_auto_var_init : Joined<["-"], "ftrivial-auto-var-init=">, 
Group,
-  Flags<[CC1Option]>, HelpText<"Initialize trivial automatic stack variables: 
uninitialized (default)"
+  Flags<[CC1Option, CoreOption]>, HelpText<"Initialize trivial automatic stack 
variables: uninitialized (default)"
   " | pattern">, Values<"uninitialized,pattern">;
 def enable_trivial_var_init_zero : Joined<["-"], 
"enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
-  Flags<[CC1Option]>,
+  Flags<[CC1Option, CoreOption]>,
   HelpText<"Trivial automatic variable initialization to zero is only here for 
benchmarks, it'll eventually be removed, and I'm OK with that because I'm only 
using it to benchmark">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, 
Flags<[CoreOption]>,
   HelpText<"Emit full debug info for all types used by the program">;


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -653,6 +653,8 @@
 // RUN: -fcs-profile-generate \
 // RUN: -fcs-profile-generate=dir \
 // RUN: -ftime-trace \
+// RUN: -ftrivial-auto-var-init=zero \
+// RUN: -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang \
 // RUN: --version \
 // RUN: -Werror /Zs -- %s 2>&1
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1715,10 +1715,10 @@
"alloca, which are of greater size than ssp-buffer-size (default: 8 bytes). "
"All variable sized calls to alloca are considered vulnerable">;
 def ftrivial_auto_var_init : Joined<["-"], "ftrivial-auto-var-init=">, Group,
-  Flags<[CC1Option]>, HelpText<"Initialize trivial automatic stack variables: uninitialized (default)"
+  Flags<[CC1Option, CoreOption]>, HelpText<"Initialize trivial automatic stack variables: uninitialized (default)"
   " | pattern">, Values<"uninitialized,pattern">;
 def enable_trivial_var_init_zero : Joined<["-"], "enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang">,
-  Flags<[CC1Option]>,
+  Flags<[CC1Option, CoreOption]>,
   HelpText<"Trivial automatic variable initialization to zero is only here for benchmarks, it'll eventually be removed, and I'm OK with that because I'm only using it to benchmark">;
 def fstandalone_debug : Flag<["-"], "fstandalone-debug">, Group, Flags<[CoreOption]>,
   HelpText<"Emit full debug info for all types used by the program">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68410: [AttrDocs] document always_inline

2019-10-07 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

> In D68410#1696411 , @joerg wrote:
> 
>> I wonder if we should actually enumerate evil here, i.e. give the situations 
>> in which inlining actually fails.
> 
> 
> Which is likely to change over time.  I worry that enumerating such cases is 
> compiler version specific, and might lead to developers depending/[ab]using 
> that behavior?

I'm jumping in part-way here, but FWIW I'd be concerned that the lack of 
explicit rules is actually going to make people depend on the whims of the 
optimizer/inliner - if we have a backend warning that only fires when inlining 
doesn't occur. So narrowing the set of cases we accept in the frontend seems 
like it reduces the risk of abuse by compiler users - leaving more freedom for 
the compiler optimizations to change without breaking existing code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68410



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


Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-07 Thread Dávid Bolvanský via cfe-commits
Hm, there is no "bitwise negation of a boolean expression always
evaluates to 'true'; did you mean logical negation?" for chromium
case. I will try to fix it.

ut 8. 10. 2019 o 0:03 Dávid Bolvanský  napísal(a):
>
> "FWIW I found the "always evaluates to 'true'" bit important to
> understand the warning."
>
> Yeah. I moved this check somewhere else, so we can print precise message:
> r373973 should emit "bitwise negation of a boolean expression always
> evaluates to 'true'; did you mean logical negation?" where possible.
> In the suspicious case like int i = ~b there is a general message
> "bitwise negation of a boolean expression; did you mean logical
> negation?".
>
> I like it now. What do you think? fine for you?
>
> po 7. 10. 2019 o 17:29 Dávid Bolvanský  napísal(a):
> >
> > Typo was fixed some days ago :)
> >
> > Odoslané z iPhonu
> >
> > Dňa 7. 10. 2019 o 17:22 užívateľ Arthur O'Dwyer  
> > napísal:
> >
> > 
> > On Mon, Oct 7, 2019 at 10:59 AM Dávid Bolvanský via cfe-commits 
> >  wrote:
> >>
> >> Okey, I will see what I can do (I know I need to move checking code 
> >> somewhere else).
> >>
> >> > Dňa 7. 10. 2019 o 16:54 užívateľ Nico Weber  
> >> > napísal:
> >> > FWIW I found the "always evaluates to 'true'" bit important to 
> >> > understand the warning.
> >
> >
> > +1, I think "always evaluates to true" is useful, especially for people who 
> > don't immediately intuit the difference between "bitwise negation" and 
> > "logical negation." (Although the fixit will help clear up the difference.)
> >
> > Also, Dávid, you misspelled "logical" as "logicial" in the patch I saw. So 
> > you might need to push a fix for that typo, unless you already caught it.
> > My suggested message follows—
> >
> > -  "bitwise negation of a boolean expression; did you mean a logicial 
> > negation?">,
> > +  "bitwise negation of a boolean expression is always true; did you mean 
> > logical negation?">,
> >
> > my $.02,
> > –Arthur
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373977 - Add VFS support for sanitizers' blacklist

2019-10-07 Thread Jan Korous via cfe-commits
Author: jkorous
Date: Mon Oct  7 15:36:19 2019
New Revision: 373977

URL: http://llvm.org/viewvc/llvm-project?rev=373977=rev
Log:
Add VFS support for sanitizers' blacklist

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

Added:
cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/test/CodeGen/ubsan-blacklist.c

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=373977=373976=373977=diff
==
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Mon Oct  7 15:36:19 2019
@@ -72,6 +72,7 @@
 #include "llvm/ADT/PointerUnion.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
@@ -81,6 +82,7 @@
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 #include 
@@ -826,6 +828,18 @@ static bool isAddrSpaceMapManglingEnable
   llvm_unreachable("getAddressSpaceMapMangling() doesn't cover anything.");
 }
 
+static std::vector
+getRealPaths(llvm::vfs::FileSystem , llvm::ArrayRef Paths) {
+  std::vector Result;
+  llvm::SmallString<128> Buffer;
+  for (const auto  : Paths) {
+if (std::error_code EC = VFS.getRealPath(File, Buffer))
+  llvm::report_fatal_error("can't open file '" + File + "': " + 
EC.message());
+Result.push_back(Buffer.str());
+  }
+  return Result;
+}
+
 ASTContext::ASTContext(LangOptions , SourceManager ,
IdentifierTable , SelectorTable ,
Builtin::Context )
@@ -833,7 +847,10 @@ ASTContext::ASTContext(LangOptions 
   TemplateSpecializationTypes(this_()),
   DependentTemplateSpecializationTypes(this_()),
   SubstTemplateTemplateParmPacks(this_()), SourceMgr(SM), LangOpts(LOpts),
-  SanitizerBL(new SanitizerBlacklist(LangOpts.SanitizerBlacklistFiles, 
SM)),
+  SanitizerBL(new SanitizerBlacklist(
+  getRealPaths(SM.getFileManager().getVirtualFileSystem(),
+   LangOpts.SanitizerBlacklistFiles),
+  SM)),
   XRayFilter(new XRayFunctionFilter(LangOpts.XRayAlwaysInstrumentFiles,
 LangOpts.XRayNeverInstrumentFiles,
 LangOpts.XRayAttrListFiles, SM)),

Added: cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml?rev=373977=auto
==
--- cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml (added)
+++ cfe/trunk/test/CodeGen/Inputs/sanitizer-blacklist-vfsoverlay.yaml Mon Oct  
7 15:36:19 2019
@@ -0,0 +1,15 @@
+{
+  'version': 0,
+  'roots': [
+{ 'name': '@DIR@', 'type': 'directory',
+  'contents': [
+{ 'name': 'only-virtual-file.blacklist', 'type': 'file',
+  'external-contents': '@REAL_FILE@'
+},
+{ 'name': 'invalid-virtual-file.blacklist', 'type': 'file',
+  'external-contents': '@NONEXISTENT_FILE@'
+}
+  ]
+}
+  ]
+}

Modified: cfe/trunk/test/CodeGen/ubsan-blacklist.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-blacklist.c?rev=373977=373976=373977=diff
==
--- cfe/trunk/test/CodeGen/ubsan-blacklist.c (original)
+++ cfe/trunk/test/CodeGen/ubsan-blacklist.c Mon Oct  7 15:36:19 2019
@@ -5,6 +5,17 @@
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow 
-fsanitize-blacklist=%t-func.blacklist -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FUNC
 // RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow 
-fsanitize-blacklist=%t-file.blacklist -emit-llvm %s -o - | FileCheck %s 
--check-prefix=FILE
 
+// RUN: rm -f %t-vfsoverlay.yaml
+// RUN: rm -f %t-nonexistent.blacklist
+// RUN: sed -e "s|@DIR@|%T|g" %S/Inputs/sanitizer-blacklist-vfsoverlay.yaml | 
sed -e "s|@REAL_FILE@|%t-func.blacklist|g" | sed -e 
"s|@NONEXISTENT_FILE@|%t-nonexistent.blacklist|g" > %t-vfsoverlay.yaml
+// RUN: %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/only-virtual-file.blacklist 
-emit-llvm %s -o - | FileCheck %s --check-prefix=FUNC
+
+// RUN: not %clang_cc1 -fsanitize=unsigned-integer-overflow -ivfsoverlay 
%t-vfsoverlay.yaml -fsanitize-blacklist=%T/invalid-virtual-file.blacklist 
-emit-llvm %s -o - 2>&1 | FileCheck %s --check-prefix=INVALID-MAPPED-FILE
+// INVALID-MAPPED-FILE: invalid-virtual-file.blacklist': No such file or 
directory
+
+// RUN: not 

[PATCH] D68377: [Builtins] Teach Clang about memccpy

2019-10-07 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

Current solution does not work
/home/xbolva00/LLVM/llvm/tools/clang/include/clang/Basic/Builtins.h:50:34: 
error: redefinition of ‘BImemccpy’
 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,

  ^

/home/xbolva00/LLVM/llvm/tools/clang/include/clang/Basic/Builtins.h:50:34: 
note: in definition of macro ‘BUILTIN’
 #define BUILTIN(ID, TYPE, ATTRS) BI##ID,

@aaron.ballman, maybe you can help me how to represent that memccpy exists for 
GNU and MS?


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

https://reviews.llvm.org/D68377



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


Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-07 Thread Dávid Bolvanský via cfe-commits
"FWIW I found the "always evaluates to 'true'" bit important to
understand the warning."

Yeah. I moved this check somewhere else, so we can print precise message:
r373973 should emit "bitwise negation of a boolean expression always
evaluates to 'true'; did you mean logical negation?" where possible.
In the suspicious case like int i = ~b there is a general message
"bitwise negation of a boolean expression; did you mean logical
negation?".

I like it now. What do you think? fine for you?

po 7. 10. 2019 o 17:29 Dávid Bolvanský  napísal(a):
>
> Typo was fixed some days ago :)
>
> Odoslané z iPhonu
>
> Dňa 7. 10. 2019 o 17:22 užívateľ Arthur O'Dwyer  
> napísal:
>
> 
> On Mon, Oct 7, 2019 at 10:59 AM Dávid Bolvanský via cfe-commits 
>  wrote:
>>
>> Okey, I will see what I can do (I know I need to move checking code 
>> somewhere else).
>>
>> > Dňa 7. 10. 2019 o 16:54 užívateľ Nico Weber  napísal:
>> > FWIW I found the "always evaluates to 'true'" bit important to understand 
>> > the warning.
>
>
> +1, I think "always evaluates to true" is useful, especially for people who 
> don't immediately intuit the difference between "bitwise negation" and 
> "logical negation." (Although the fixit will help clear up the difference.)
>
> Also, Dávid, you misspelled "logical" as "logicial" in the patch I saw. So 
> you might need to push a fix for that typo, unless you already caught it.
> My suggested message follows—
>
> -  "bitwise negation of a boolean expression; did you mean a logicial 
> negation?">,
> +  "bitwise negation of a boolean expression is always true; did you mean 
> logical negation?">,
>
> my $.02,
> –Arthur
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r373973 - [Diagnostics] Emit better -Wbool-operation's warning message if we known that the result is always true

2019-10-07 Thread David Bolvansky via cfe-commits
Author: xbolva00
Date: Mon Oct  7 14:57:03 2019
New Revision: 373973

URL: http://llvm.org/viewvc/llvm-project?rev=373973=rev
Log:
[Diagnostics] Emit better -Wbool-operation's warning message if we known that 
the result is always true


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/warn-bitwise-negation-bool.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373973=373972=373973=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Oct  7 14:57:03 
2019
@@ -6638,7 +6638,8 @@ def note_member_declared_here : Note<
 def note_member_first_declared_here : Note<
   "member %0 first declared here">;
 def warn_bitwise_negation_bool : Warning<
-  "bitwise negation of a boolean expression; did you mean logical negation?">,
+  "bitwise negation of a boolean expression%select{;| always evaluates to 
'true';}0 "
+  "did you mean logical negation?">,
   InGroup>;
 def err_decrement_bool : Error<"cannot decrement expression of type bool">;
 def warn_increment_bool : Warning<

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373973=373972=373973=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Oct  7 14:57:03 2019
@@ -11896,6 +11896,13 @@ static void AnalyzeImplicitConversions(S
   if (E->isTypeDependent() || E->isValueDependent())
 return;
 
+  if (const auto *UO = dyn_cast(E))
+if (UO->getOpcode() == UO_Not &&
+UO->getSubExpr()->isKnownToHaveBooleanValue())
+  S.Diag(UO->getBeginLoc(), diag::warn_bitwise_negation_bool)
+  << OrigE->getSourceRange() << T->isBooleanType()
+  << FixItHint::CreateReplacement(UO->getBeginLoc(), "!");
+
   // For conditional operators, we analyze the arguments as if they
   // were being fed directly into the output.
   if (isa(E)) {

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=373973=373972=373973=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Oct  7 14:57:03 2019
@@ -13479,10 +13479,6 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
   // C99 does not support '~' for complex conjugation.
   Diag(OpLoc, diag::ext_integer_complement_complex)
   << resultType << Input.get()->getSourceRange();
-else if (Input.get()->isKnownToHaveBooleanValue())
-  Diag(OpLoc, diag::warn_bitwise_negation_bool)
-  << Input.get()->getSourceRange()
-  << FixItHint::CreateReplacement(OpLoc, "!");
 else if (resultType->hasIntegerRepresentation())
   break;
 else if (resultType->isExtVectorType() && Context.getLangOpts().OpenCL) {

Modified: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373973=373972=373973=diff
==
--- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (original)
+++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Mon Oct  7 14:57:03 2019
@@ -12,13 +12,13 @@ typedef _Bool boolean;
 #endif
 
 void test(boolean b, int i) {
-  b = ~b; // expected-warning {{bitwise negation of a boolean expression; did 
you mean logical negation?}}
+  b = ~b; // expected-warning {{bitwise negation of a boolean expression 
always evaluates to 'true'; did you mean logical negation?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
-  b = ~(b); // expected-warning {{bitwise negation of a boolean expression; 
did you mean logical negation?}}
+  b = ~(b); // expected-warning {{bitwise negation of a boolean expression 
always evaluates to 'true'; did you mean logical negation?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
   b = ~i;
   i = ~b; // expected-warning {{bitwise negation of a boolean expression; did 
you mean logical negation?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
-  b = ~(i > 4); // expected-warning {{bitwise negation of a boolean 
expression; did you mean logical negation?}}
+  b = ~(i > 4); // expected-warning {{bitwise negation of a boolean expression 
always evaluates to 'true'; did you mean logical negation?}}
   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
 }


___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D68587: [hip] Assume host-only compilation if the final phase is ahead of `backend`.

2019-10-07 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D68587#1698102 , @hliao wrote:

> for most compilation tools, single input and single output are expected. 
> Without assuming `-fsyntax-only` alone is host-compilation only, that at 
> least run syntax checking twice.


I believe the driver will not run subsequent jobs if one of the device 
compilations fails. You may see duplicate warnings from multiple stages, but 
overall the error handling works in a fairly predictable way now.

> The result may be misleading

Potentially repeated warning are still *correct*, while omitting an error is 
not, IMO.  I believe that did come up before and we had to make some changes to 
the driver to keep host compilation working even when device-side compilations 
produce no output.

To think of it, I'm starting to doubt that this patch is an improvement for 
`-M` either. You will get the dependencies for host, but they are not 
necessarily the same as the dependencies for the device-side compilation. 
Producing partial list of dependencies will be potentially incorrect. IMO we do 
need dependencies info from all sub-compilations.

Perhaps we should limit the scope of this patch to -E only for now?

> and there are clang-based tools (like clang-tidy) may have no legacy way to 
> be runnable.

Tooling does get surprised by the multiple jobs created by CUDA compilation. 
The work around is to pass `--cuda-host-only`. Passing an extra flag is usually 
not a showstopper (at least it was not in cases I had to deal with at work and 
we have fair number of clang-derived tools). Usually in order to get correct 
CUDA compilation in this scenario you will also need to tell the tool where to 
find CUDA's headers, so the mechanism for passing additional options already 
exists.

If that's still a problem, then we should change the tooling infrastructure to 
use host-only compilation for HIP and CUDA by default.

> To check device-side compilation syntax, we are still able to explicitly ask 
> that by specifying `--cuda-device-only`.

Yes, that could be done. However, as I've mentioned above the same argument 
applies to tooling & `--cuda-host-only`, so there's no advantage here. IMO the 
most common use case should be the default, so it's the clang itself which 
should remain working correctly without having to add extra flags.

Also, this patch makes it impossible to run -fsyntax-only on *all* 
sub-compilations at once. I will have to run `clang -fsyntax-only` multiple 
times -- once per host and once per each device. 
I do want to check all sub-compilations with `-fsyntax-only` on a regular basis 
(e.g. when running creduce on a cuda source), so having to do that for each 
sub-compilation separately does not look like an improvement to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68587



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


[PATCH] D68591: [analyzer] PR43551: Do not dereferce void* in UndefOrNullArgVisitor

2019-10-07 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus created this revision.
Szelethus added reviewers: NoQ, xazax.hun, baloghadamsoftware, Charusso, 
dcoughlin, rnkovacs.
Szelethus added a project: clang.
Herald added subscribers: cfe-commits, gamesh411, dkrupp, donat.nagy, 
mikhail.ramalho, a.sidorin, szepet, whisperity.

Exactly what it says on the tin!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68591

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/novoidtypecrash.c


Index: clang/test/Analysis/novoidtypecrash.c
===
--- clang/test/Analysis/novoidtypecrash.c
+++ clang/test/Analysis/novoidtypecrash.c
@@ -1,8 +1,27 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core %s
+x;
+y(void **z) { // no-crash
+  *z = x;
+  int *w;
+  y();
+  *w;
+}
+
 a;
-b(void **c) { // no-crash
-  *c = a;
-  int *d;
-  b();
-  *d;
+b(*c) {}
+e(*c) {
+  void *d = f();
+  b(d);
+  *c = d;
+}
+void *g() {
+  e();
+  return a;
+}
+j() {
+  int h;
+  char i = g();
+  if (i)
+for (; h;)
+  ;
 }
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2027,8 +2027,6 @@
 
   // Is it a symbolic value?
   if (auto L = V.getAs()) {
-report.addVisitor(std::make_unique(L->getRegion()));
-
 // FIXME: this is a hack for fixing a later crash when attempting to
 // dereference a void* pointer.
 // We should not try to dereference pointers at all when we don't care
@@ -2049,10 +2047,14 @@
 else if (CanDereference)
   RVal = LVState->getSVal(L->getRegion());
 
-if (CanDereference)
+if (CanDereference) {
+  report.addVisitor(
+  std::make_unique(L->getRegion()));
+
   if (auto KV = RVal.getAs())
 report.addVisitor(std::make_unique(
 *KV, L->getRegion(), EnableNullFPSuppression, TKind, SFC));
+}
 
 const MemRegion *RegionRVal = RVal.getAsRegion();
 if (RegionRVal && isa(RegionRVal)) {


Index: clang/test/Analysis/novoidtypecrash.c
===
--- clang/test/Analysis/novoidtypecrash.c
+++ clang/test/Analysis/novoidtypecrash.c
@@ -1,8 +1,27 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=core %s
+x;
+y(void **z) { // no-crash
+  *z = x;
+  int *w;
+  y();
+  *w;
+}
+
 a;
-b(void **c) { // no-crash
-  *c = a;
-  int *d;
-  b();
-  *d;
+b(*c) {}
+e(*c) {
+  void *d = f();
+  b(d);
+  *c = d;
+}
+void *g() {
+  e();
+  return a;
+}
+j() {
+  int h;
+  char i = g();
+  if (i)
+for (; h;)
+  ;
 }
Index: clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
===
--- clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -2027,8 +2027,6 @@
 
   // Is it a symbolic value?
   if (auto L = V.getAs()) {
-report.addVisitor(std::make_unique(L->getRegion()));
-
 // FIXME: this is a hack for fixing a later crash when attempting to
 // dereference a void* pointer.
 // We should not try to dereference pointers at all when we don't care
@@ -2049,10 +2047,14 @@
 else if (CanDereference)
   RVal = LVState->getSVal(L->getRegion());
 
-if (CanDereference)
+if (CanDereference) {
+  report.addVisitor(
+  std::make_unique(L->getRegion()));
+
   if (auto KV = RVal.getAs())
 report.addVisitor(std::make_unique(
 *KV, L->getRegion(), EnableNullFPSuppression, TKind, SFC));
+}
 
 const MemRegion *RegionRVal = RVal.getAsRegion();
 if (RegionRVal && isa(RegionRVal)) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68590: [clangd] Improve hover support for Objective-C

2019-10-07 Thread David Goldman via Phabricator via cfe-commits
dgoldman created this revision.
dgoldman added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, jfb, arphaman, 
jkorous, MaskRay, ilya-biryukov.
Herald added a project: clang.

- Instead of `AppDelegate::application:didFinishLaunchingWithOptions:` you will 
now see `-[AppDelegate application:didFinishLaunchingWithOptions:]`

- Also include support for Objective-C categories so you will see 
`Class(Category)` or `-[Class(Category) method]`


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D68590

Files:
  clangd/XRefs.cpp
  clangd/unittests/XRefsTests.cpp

Index: clangd/unittests/XRefsTests.cpp
===
--- clangd/unittests/XRefsTests.cpp
+++ clangd/unittests/XRefsTests.cpp
@@ -1026,6 +1026,186 @@
   }
 } // namespace clang
 
+TEST(Hover, ObjectiveC) {
+  struct {
+const char *const Code;
+const std::function ExpectedBuilder;
+  } Cases[] = {
+  // Property reference: LocalScope resolution to interface.
+  {R"objc(
+@interface Foo
+@property(nonatomic, assign) int field;
+
++ (instancetype)sharedInstance;
+@end
+
+int someFunction() {
+  Foo *foo = [Foo sharedInstance];
+  return foo.[[fie^ld]];
+}
+)objc",
+   [](HoverInfo ) {
+ HI.Name = "field";
+ HI.Definition = "@property(nonatomic, assign, unsafe_unretained, readwrite) int field;";
+ HI.Kind = SymbolKind::Property;
+ HI.LocalScope = "Foo::";
+ HI.NamespaceScope = "";
+   }},
+  // Property reference: LocalScope resolution to interface category.
+  {R"objc(
+@interface Foo
++ (instancetype)sharedInstance;
+@end
+
+@interface Foo (Private)
+@property(nonatomic, assign) int privateField;
+@end
+
+int someFunction() {
+  Foo *foo = [Foo sharedInstance];
+  return foo.[[private^Field]];
+}
+)objc",
+   [](HoverInfo ) {
+ HI.Name = "privateField";
+ HI.Definition = "@property(nonatomic, assign, unsafe_unretained, readwrite) int privateField;";
+ HI.Kind = SymbolKind::Property;
+ HI.LocalScope = "Foo(Private)::";
+ HI.NamespaceScope = "";
+   }},
+  // Variable declaration in method: LocalScope resolution to implementation.
+  {R"objc(
+@interface Foo
+@property(nonatomic, assign) float someNumber;
+@end
+
+@implementation Foo
+- (float)someMethod {
+  float [[res^ult]] = self.someNumber;
+  return result;
+}
+@end
+)objc",
+   [](HoverInfo ) {
+ HI.Name = "result";
+ HI.Definition = "float result = self.someNumber";
+ HI.Kind = SymbolKind::Variable;
+ HI.Type = "float";
+ HI.LocalScope = "-[Foo someMethod]::";
+ HI.NamespaceScope = "";
+   }},
+  // Variable declaration in method: LocalScope resolution to category implementation.
+  {R"objc(
+@interface Foo
+@property(nonatomic, assign) int someNumber;
+@end
+
+@implementation Foo(Private)
++ (int)somePrivateMethod {
+  int [[res^ult]] = 2;
+  return result;
+}
+@end
+)objc",
+   [](HoverInfo ) {
+ HI.Name = "result";
+ HI.Definition = "int result = 2";
+ HI.Kind = SymbolKind::Variable;
+ HI.Type = "int";
+ HI.LocalScope = "+[Foo(Private) somePrivateMethod]::";
+ HI.NamespaceScope = "";
+ HI.Value = "2";
+   }},
+  };
+  for (const auto  : Cases) {
+SCOPED_TRACE(Case.Code);
+
+Annotations T(Case.Code);
+TestTU TU = TestTU::withCode(T.code());
+TU.Filename = "TestTU.m";
+TU.ExtraArgs.push_back("-Wno-objc-root-class");
+auto AST = TU.build();
+
+ASSERT_TRUE(AST.getDiagnostics().empty())
+<< AST.getDiagnostics().begin()->Message;
+
+auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+ASSERT_TRUE(H);
+HoverInfo Expected;
+Expected.SymRange = T.range();
+Case.ExpectedBuilder(Expected);
+
+EXPECT_EQ(H->NamespaceScope, Expected.NamespaceScope);
+EXPECT_EQ(H->LocalScope, Expected.LocalScope);
+EXPECT_EQ(H->Name, Expected.Name);
+EXPECT_EQ(H->Kind, Expected.Kind);
+EXPECT_EQ(H->Documentation, Expected.Documentation);
+EXPECT_EQ(H->Definition, Expected.Definition);
+EXPECT_EQ(H->Type, Expected.Type);
+EXPECT_EQ(H->ReturnType, Expected.ReturnType);
+EXPECT_EQ(H->Parameters, Expected.Parameters);
+EXPECT_EQ(H->TemplateParameters, Expected.TemplateParameters);
+EXPECT_EQ(H->SymRange, Expected.SymRange);
+EXPECT_EQ(H->Value, Expected.Value);
+  }
+}
+
+TEST(Hover, ObjectiveCInterfaceInferred) {
+  struct {
+const char *const Code;
+const std::function ExpectedBuilder;
+  } Cases[] = {
+  // No interface, variable 

[PATCH] D68587: [hip] Assume host-only compilation if the final phase is ahead of `backend`.

2019-10-07 Thread Michael Liao via Phabricator via cfe-commits
hliao added a comment.

In D68587#1698055 , @tra wrote:

> I'm fine with this for -E/-M,
>
> I would argue that with `-fsyntax-only` we want to know whether our source 
> code, which is common for all sub-compilations, has syntactic errors. 
>  The way we compile HIP & CUDA sources, some of the errors will only be 
> reported on one side of the compilation. 
>  So, in order to make sure there are no syntax errors, we need to perform 
> *all* sub-compilations with `-fsyntax-only`.
>
> E.g. it would be rather surprising to see the compilation succeeding with 
> `-fsyntax-only`, but then fail with a syntax error somewhere on the device 
> side during a real compilation.


for most compilation tools, single input and single output are expected. 
Without assuming `-fsyntax-only` alone is host-compilation only, that at least 
run syntax checking twice. The result may be misleading and there are 
clang-based tools (like clang-tidy) may have no legacy way to be runnable. To 
check device-side compilation syntax, we are still able to explicitly ask that 
by specifying `--cuda-device-only`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68587



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


[PATCH] D66035: [WebAssembly] WIP: Add support for reference types

2019-10-07 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

Another approach to reference types we should look at is clang's upcoming 
sizeless types support (https://reviews.llvm.org/D62962, RFC: 
http://lists.llvm.org/pipermail/cfe-dev/2019-June/062523.html). This would 
allow reference types to be constructed at the source level but most operations 
such as `sizeof`, loading, and storing would be disallowed because they would 
be treated as incomplete types.

I don't think that approach is inconsistent with this one, though. This patch 
deals mostly with the backend while sizeless types are a frontend concept. I'm 
not sure what the codegen and lowering would look like, though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66035



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


r373952 - [OPENMP]Fix caonical->canonical, NFC.

2019-10-07 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Oct  7 12:57:40 2019
New Revision: 373952

URL: http://llvm.org/viewvc/llvm-project?rev=373952=rev
Log:
[OPENMP]Fix caonical->canonical, NFC.

Fixed typo.

Modified:
cfe/trunk/include/clang/AST/StmtOpenMP.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp

Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=373952=373951=373952=diff
==
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Mon Oct  7 12:57:40 2019
@@ -1092,7 +1092,7 @@ public:
   Body = For->getBody();
 } else {
   assert(isa(Body) &&
- "Expected caonical for loop or range-based for loop.");
+ "Expected canonical for loop or range-based for loop.");
   Body = cast(Body)->getBody();
 }
 for (unsigned Cnt = 1; Cnt < CollapsedNum; ++Cnt) {
@@ -1101,7 +1101,7 @@ public:
 Body = For->getBody();
   } else {
 assert(isa(Body) &&
-   "Expected caonical for loop or range-based for loop.");
+   "Expected canonical for loop or range-based for loop.");
 Body = cast(Body)->getBody();
   }
 }

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=373952=373951=373952=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Mon Oct  7 12:57:40 2019
@@ -151,7 +151,7 @@ class OMPLoopScope : public CodeGenFunct
 Body = For->getBody();
   } else {
 assert(isa(Body) &&
-   "Expected caonical for loop or range-based for loop.");
+   "Expected canonical for loop or range-based for loop.");
 auto *CXXFor = cast(Body);
 if (const Stmt *Init = CXXFor->getInit())
   CGF.EmitStmt(Init);
@@ -1377,7 +1377,7 @@ void CodeGenFunction::EmitOMPLoopBody(co
   Body = For->getBody();
 } else {
   assert(isa(Body) &&
- "Expected caonical for loop or range-based for loop.");
+ "Expected canonical for loop or range-based for loop.");
   auto *CXXFor = cast(Body);
   EmitStmt(CXXFor->getLoopVarStmt());
   Body = CXXFor->getBody();


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


[PATCH] D68587: [hip] Assume host-only compilation if the final phase is ahead of `backend`.

2019-10-07 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

I'm fine with this for -E/-M,

I would argue that with `-fsyntax-only` we want to know whether our source 
code, which is common for all sub-compilations, has syntactic errors. 
The way we compile HIP & CUDA sources, some of the errors will only be reported 
on one side of the compilation. 
So, in order to make sure there are no syntax errors, we need to perform *all* 
sub-compilations with `-fsyntax-only`.

E.g. it would be rather surprising to see the compilation succeeding with 
`-fsyntax-only`, but then fail with a syntax error somewhere on device side 
during a real compilation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68587



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


[clang-tools-extra] r373951 - Attempt to fix a few clang-tidy tests on Windows, see PR43593.

2019-10-07 Thread Nico Weber via cfe-commits
Author: nico
Date: Mon Oct  7 12:54:19 2019
New Revision: 373951

URL: http://llvm.org/viewvc/llvm-project?rev=373951=rev
Log:
Attempt to fix a few clang-tidy tests on Windows, see PR43593.

Modified:
clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone.cpp

clang-tools-extra/trunk/test/clang-tidy/bugprone-unhandled-self-assignment.cpp
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-init-variables.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone.cpp?rev=373951=373950=373951=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-branch-clone.cpp Mon Oct  
7 12:54:19 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-branch-clone %t
+// RUN: %check_clang_tidy %s bugprone-branch-clone %t -- -- 
-fno-delayed-template-parsing
 
 void test_basic1(int in, int ) {
   if (in > 77)

Modified: 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unhandled-self-assignment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-unhandled-self-assignment.cpp?rev=373951=373950=373951=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unhandled-self-assignment.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/bugprone-unhandled-self-assignment.cpp 
Mon Oct  7 12:54:19 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t
+// RUN: %check_clang_tidy %s bugprone-unhandled-self-assignment %t -- -- 
-fno-delayed-template-parsing
 
 namespace std {
 

Modified: 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-init-variables.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-init-variables.cpp?rev=373951=373950=373951=diff
==
--- 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-init-variables.cpp 
(original)
+++ 
clang-tools-extra/trunk/test/clang-tidy/cppcoreguidelines-init-variables.cpp 
Mon Oct  7 12:54:19 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t
+// RUN: %check_clang_tidy %s cppcoreguidelines-init-variables %t -- -- 
-fno-delayed-template-parsing
 
 // Ensure that function declarations are not changed.
 void some_func(int x, double d, bool b, const char *p);

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp?rev=373951=373950=373951=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-redundant-expression.cpp Mon 
Oct  7 12:54:19 2019
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-redundant-expression %t
+// RUN: %check_clang_tidy %s misc-redundant-expression %t -- -- 
-fno-delayed-template-parsing
 
 typedef __INT64_TYPE__ I64;
 


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


r373950 - Fix for expanding __pragmas in macro arguments

2019-10-07 Thread Amy Huang via cfe-commits
Author: akhuang
Date: Mon Oct  7 12:41:53 2019
New Revision: 373950

URL: http://llvm.org/viewvc/llvm-project?rev=373950=rev
Log:
Fix for expanding __pragmas in macro arguments

Summary:
Avoid parsing __pragma into an annotation token when macro arguments are 
pre-expanded.
This is what clang currently does when parsing _Pragmas.

Fixes https://bugs.llvm.org/show_bug.cgi?id=41128, where clang crashed
when trying to get the length of an annotation token.

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/lib/Lex/Pragma.cpp
cfe/trunk/test/Preprocessor/pragma_microsoft.c

Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=373950=373949=373950=diff
==
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Mon Oct  7 12:41:53 2019
@@ -121,6 +121,40 @@ void PragmaNamespace::HandlePragma(Prepr
 // Preprocessor Pragma Directive Handling.
 
//===--===//
 
+namespace {
+// TokenCollector provides the option to collect tokens that were "read"
+// and return them to the stream to be read later.
+// Currently used when reading _Pragma/__pragma directives.
+struct TokenCollector {
+  Preprocessor 
+  bool Collect;
+  SmallVector Tokens;
+  Token 
+
+  void lex() {
+if (Collect)
+  Tokens.push_back(Tok);
+Self.Lex(Tok);
+  }
+
+  void revert() {
+assert(Collect && "did not collect tokens");
+assert(!Tokens.empty() && "collected unexpected number of tokens");
+
+// Push the ( "string" ) tokens into the token stream.
+auto Toks = std::make_unique(Tokens.size());
+std::copy(Tokens.begin() + 1, Tokens.end(), Toks.get());
+Toks[Tokens.size() - 1] = Tok;
+Self.EnterTokenStream(std::move(Toks), Tokens.size(),
+  /*DisableMacroExpansion*/ true,
+  /*IsReinject*/ true);
+
+// ... and return the pragma token unchanged.
+Tok = *Tokens.begin();
+  }
+};
+} // namespace
+
 /// HandlePragmaDirective - The "\#pragma" directive has been parsed.  Lex the
 /// rest of the pragma, passing it to the registered pragma handlers.
 void Preprocessor::HandlePragmaDirective(PragmaIntroducer Introducer) {
@@ -166,35 +200,6 @@ void Preprocessor::Handle_Pragma(Token &
   // In Case #2, we check the syntax now, but then put the tokens back into the
   // token stream for later consumption.
 
-  struct TokenCollector {
-Preprocessor 
-bool Collect;
-SmallVector Tokens;
-Token 
-
-void lex() {
-  if (Collect)
-Tokens.push_back(Tok);
-  Self.Lex(Tok);
-}
-
-void revert() {
-  assert(Collect && "did not collect tokens");
-  assert(!Tokens.empty() && "collected unexpected number of tokens");
-
-  // Push the ( "string" ) tokens into the token stream.
-  auto Toks = std::make_unique(Tokens.size());
-  std::copy(Tokens.begin() + 1, Tokens.end(), Toks.get());
-  Toks[Tokens.size() - 1] = Tok;
-  Self.EnterTokenStream(std::move(Toks), Tokens.size(),
-/*DisableMacroExpansion*/ true,
-/*IsReinject*/ true);
-
-  // ... and return the _Pragma token unchanged.
-  Tok = *Tokens.begin();
-}
-  };
-
   TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
 
   // Remember the pragma token location.
@@ -328,11 +333,15 @@ void Preprocessor::Handle_Pragma(Token &
 /// HandleMicrosoft__pragma - Like Handle_Pragma except the pragma text
 /// is not enclosed within a string literal.
 void Preprocessor::HandleMicrosoft__pragma(Token ) {
+  // During macro pre-expansion, check the syntax now but put the tokens back
+  // into the token stream for later consumption. Same as Handle_Pragma.
+  TokenCollector Toks = {*this, InMacroArgPreExpansion, {}, Tok};
+
   // Remember the pragma token location.
   SourceLocation PragmaLoc = Tok.getLocation();
 
   // Read the '('.
-  Lex(Tok);
+  Toks.lex();
   if (Tok.isNot(tok::l_paren)) {
 Diag(PragmaLoc, diag::err__Pragma_malformed);
 return;
@@ -341,14 +350,14 @@ void Preprocessor::HandleMicrosoft__prag
   // Get the tokens enclosed within the __pragma(), as well as the final ')'.
   SmallVector PragmaToks;
   int NumParens = 0;
-  Lex(Tok);
+  Toks.lex();
   while (Tok.isNot(tok::eof)) {
 PragmaToks.push_back(Tok);
 if (Tok.is(tok::l_paren))
   NumParens++;
 else if (Tok.is(tok::r_paren) && NumParens-- == 0)
   break;
-Lex(Tok);
+Toks.lex();
   }
 
   if (Tok.is(tok::eof)) {
@@ -356,6 +365,12 @@ void Preprocessor::HandleMicrosoft__prag
 return;
   }
 
+  // If we're expanding a macro argument, put the tokens back.
+  if (InMacroArgPreExpansion) {
+Toks.revert();
+return;
+  }
+
   PragmaToks.front().setFlag(Token::LeadingSpace);
 
   // Replace 

[PATCH] D68587: [hip] Assume host-only compilation if the final phase is ahead of `backend`.

2019-10-07 Thread Michael Liao via Phabricator via cfe-commits
hliao created this revision.
hliao added reviewers: tra, yaxunl.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- There are several scenarios where the compilation needs stopping before 
`backend`, such as `-E`, `-fsyntax-ony`, and even more if developers want to 
diagnose outputs from different phases. Under these cases, the offload bundler 
is not yet required or not valid to run as the output from the device-side 
compilation is not ready yet. As the result, it's assumed that, if the final 
phase is ahead of `backend`, these compilations are host only. If developers 
need the corresponding outputs for those phases from the device-side one, 
`--cuda-device-only` needs specifying to the compiler.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68587

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/hip-pre-backend-phases.hip


Index: clang/test/Driver/hip-pre-backend-phases.hip
===
--- /dev/null
+++ clang/test/Driver/hip-pre-backend-phases.hip
@@ -0,0 +1,11 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -x hip -nogpulib -target x86_64 -M %s 2>&1 | FileCheck %s
+// RUN: %clang -### -x hip -nogpulib -target x86_64 -E %s 2>&1 | FileCheck %s
+// RUN: %clang -### -x hip -nogpulib -target x86_64 -fsyntax-only %s 2>&1 | 
FileCheck %s
+
+// CHECK-NOT: clang{{.*}}" "-cc1" {{.*}} "-fcuda-is-device"
+// CHECK: clang{{.*}}" "-cc1" "-triple" "x86_64"
+// CHECK-NOT: clang-offload-bundler"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2661,6 +2661,13 @@
 getDeviceDependences(OffloadAction::DeviceDependences ,
  phases::ID CurPhase, phases::ID FinalPhase,
  PhasesTy ) override {
+  // If the final phase won't be able to generate the output bundling both
+  // device and host objects, it assumes such usage are host only unless
+  // device only compilation option is specified.
+  if (!CompileDeviceOnly && FinalPhase < phases::Backend) {
+CudaDeviceActions.clear();
+return ABRT_Inactive;
+  }
   // amdgcn does not support linking of object files, therefore we skip
   // backend and assemble phases to output LLVM IR. Except for generating
   // non-relocatable device coee, where we generate fat binary for device


Index: clang/test/Driver/hip-pre-backend-phases.hip
===
--- /dev/null
+++ clang/test/Driver/hip-pre-backend-phases.hip
@@ -0,0 +1,11 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -x hip -nogpulib -target x86_64 -M %s 2>&1 | FileCheck %s
+// RUN: %clang -### -x hip -nogpulib -target x86_64 -E %s 2>&1 | FileCheck %s
+// RUN: %clang -### -x hip -nogpulib -target x86_64 -fsyntax-only %s 2>&1 | FileCheck %s
+
+// CHECK-NOT: clang{{.*}}" "-cc1" {{.*}} "-fcuda-is-device"
+// CHECK: clang{{.*}}" "-cc1" "-triple" "x86_64"
+// CHECK-NOT: clang-offload-bundler"
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2661,6 +2661,13 @@
 getDeviceDependences(OffloadAction::DeviceDependences ,
  phases::ID CurPhase, phases::ID FinalPhase,
  PhasesTy ) override {
+  // If the final phase won't be able to generate the output bundling both
+  // device and host objects, it assumes such usage are host only unless
+  // device only compilation option is specified.
+  if (!CompileDeviceOnly && FinalPhase < phases::Backend) {
+CudaDeviceActions.clear();
+return ABRT_Inactive;
+  }
   // amdgcn does not support linking of object files, therefore we skip
   // backend and assemble phases to output LLVM IR. Except for generating
   // non-relocatable device coee, where we generate fat binary for device
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D67980: [BPF] do compile-once run-everywhere relocation for bitfields

2019-10-07 Thread Alexei Starovoitov via Phabricator via cfe-commits
ast added a comment.

thanks for adding the tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67980



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


r373939 - [OPENMP50]Treat range-based for as canonical loop.

2019-10-07 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Mon Oct  7 11:54:57 2019
New Revision: 373939

URL: http://llvm.org/viewvc/llvm-project?rev=373939=rev
Log:
[OPENMP50]Treat range-based for as canonical loop.

According to OpenMP 5.0, range-based for is also considered as a
canonical form of loops.

Modified:
cfe/trunk/include/clang/AST/StmtOpenMP.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/OpenMP/distribute_parallel_for_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/distribute_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/for_ast_print.cpp
cfe/trunk/test/OpenMP/for_loop_messages.cpp
cfe/trunk/test/OpenMP/for_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_codegen.cpp
cfe/trunk/test/OpenMP/parallel_for_loop_messages.cpp
cfe/trunk/test/OpenMP/parallel_for_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/simd_loop_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_loop_messages.cpp
cfe/trunk/test/OpenMP/target_parallel_for_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/target_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_loop_messages.cpp
cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_loop_messages.cpp

cfe/trunk/test/OpenMP/target_teams_distribute_parallel_for_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/taskloop_loop_messages.cpp
cfe/trunk/test/OpenMP/taskloop_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_loop_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_loop_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_parallel_for_simd_loop_messages.cpp
cfe/trunk/test/OpenMP/teams_distribute_simd_loop_messages.cpp

Modified: cfe/trunk/include/clang/AST/StmtOpenMP.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtOpenMP.h?rev=373939=373938=373939=diff
==
--- cfe/trunk/include/clang/AST/StmtOpenMP.h (original)
+++ cfe/trunk/include/clang/AST/StmtOpenMP.h Mon Oct  7 11:54:57 2019
@@ -17,6 +17,7 @@
 #include "clang/AST/Expr.h"
 #include "clang/AST/OpenMPClause.h"
 #include "clang/AST/Stmt.h"
+#include "clang/AST/StmtCXX.h"
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/SourceLocation.h"
 
@@ -1087,10 +1088,22 @@ public:
 // This relies on the loop form is already checked by Sema.
 const Stmt *Body =
 getInnermostCapturedStmt()->getCapturedStmt()->IgnoreContainers();
-Body = cast(Body)->getBody();
+if (auto *For = dyn_cast(Body)) {
+  Body = For->getBody();
+} else {
+  assert(isa(Body) &&
+ "Expected caonical for loop or range-based for loop.");
+  Body = cast(Body)->getBody();
+}
 for (unsigned Cnt = 1; Cnt < CollapsedNum; ++Cnt) {
   Body = Body->IgnoreContainers();
-  Body = cast(Body)->getBody();
+  if (auto *For = dyn_cast(Body)) {
+Body = For->getBody();
+  } else {
+assert(isa(Body) &&
+   "Expected caonical for loop or range-based for loop.");
+Body = cast(Body)->getBody();
+  }
 }
 return Body;
   }

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=373939=373938=373939=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Oct  7 11:54:57 2019
@@ -9154,6 +9154,10 @@ public:
   /// construct.
   void startOpenMPLoop();
 
+  /// If the current region is a range loop-based region, mark the start of the
+  /// loop construct.
+  void startOpenMPCXXRangeFor();
+
   /// Check if the specified variable is used in 'private' clause.
   /// \param Level Relative level of nested OpenMP construct for that the check
   /// is performed.

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=373939=373938=373939=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Mon Oct  7 11:54:57 2019
@@ -142,6 +142,24 @@ class OMPLoopScope : public CodeGenFunct
   }
 }
 (void)PreCondVars.apply(CGF);
+// Emit init, __range and __end variables for C++ range loops.
+const Stmt *Body =
+S.getInnermostCapturedStmt()->getCapturedStmt()->IgnoreContainers();
+for (unsigned Cnt = 0; Cnt < S.getCollapsedNumber(); ++Cnt) {
+  Body = Body->IgnoreContainers();
+  if (auto *For = dyn_cast(Body)) {
+Body = For->getBody();
+  } else {
+assert(isa(Body) &&
+   "Expected caonical for loop or range-based for loop.");
+auto *CXXFor = 

[PATCH] D67985: CFI: wrong type passed to llvm.type.test with multiple inheritance devirtualization

2019-10-07 Thread Dmitry Mikulin via Phabricator via cfe-commits
dmikulin updated this revision to Diff 223634.
dmikulin added a comment.

Added a new CodeGetCXX test case


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

https://reviews.llvm.org/D67985

Files:
  clang/lib/CodeGen/CGExprCXX.cpp
  clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp
  compiler-rt/test/cfi/multiple-inheritance2.cpp


Index: compiler-rt/test/cfi/multiple-inheritance2.cpp
===
--- /dev/null
+++ compiler-rt/test/cfi/multiple-inheritance2.cpp
@@ -0,0 +1,38 @@
+// Test that virtual functions of the derived class can be called through
+// pointers of both base classes without CFI errors.
+// Related to Bugzilla 43390.
+
+// RUN: %clangxx_cfi -o %t1 %s
+// RUN: %run %t1 2>&1 | FileCheck --check-prefix=CFI %s
+
+// CFI: In f1
+// CFI: In f2
+// CFI-NOT: control flow integrity check
+
+// REQUIRES: cxxabi
+
+#include 
+
+class A1 {
+public:
+virtual void f1() = 0;
+};
+
+class A2 {
+public:
+virtual void f2() = 0;
+};
+
+
+class B : public A1, public A2 {
+public:
+void f2() final { fprintf(stderr, "In f2\n"); }
+void f1() final { fprintf(stderr, "In f1\n"); }
+};
+
+int main() {
+B b;
+
+static_cast()->f1();
+static_cast()->f2();
+}
Index: clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp
@@ -0,0 +1,31 @@
+// Test that correct vtable ptr and type metadata are passed to llvm.type.test
+// Related to Bugzilla 43390.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility hidden -std=c++11 
-fsanitize=cfi-nvcall -emit-llvm -o - %s | FileCheck %s
+
+class A1 {
+public:
+virtual int f1() = 0;
+};
+
+class A2 {
+public:
+virtual int f2() = 0;
+};
+
+
+class B : public A1, public A2 {
+public:
+int f2() final { return 1; }
+int f1() final { return 2; }
+};
+
+// CHECK-LABEL: define hidden i32 @_Z3foov
+int foo() {
+B b;
+return static_cast()->f2();
+// CHECK: [[P:%[^ ]*]] = bitcast %class.B* %b to i8**
+// CHECK: [[V:%[^ ]*]] = load i8*, i8** [[P]], align 8
+// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"_ZTS1B")
+// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"all-vtables")
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ clang/lib/CodeGen/CGExprCXX.cpp
@@ -382,7 +382,7 @@
   const CXXRecordDecl *RD;
   std::tie(VTable, RD) =
   CGM.getCXXABI().LoadVTablePtr(*this, This.getAddress(),
-MD->getParent());
+CalleeDecl->getParent());
   EmitVTablePtrCheckForCall(RD, VTable, CFITCK_NVCall, CE->getBeginLoc());
 }
 


Index: compiler-rt/test/cfi/multiple-inheritance2.cpp
===
--- /dev/null
+++ compiler-rt/test/cfi/multiple-inheritance2.cpp
@@ -0,0 +1,38 @@
+// Test that virtual functions of the derived class can be called through
+// pointers of both base classes without CFI errors.
+// Related to Bugzilla 43390.
+
+// RUN: %clangxx_cfi -o %t1 %s
+// RUN: %run %t1 2>&1 | FileCheck --check-prefix=CFI %s
+
+// CFI: In f1
+// CFI: In f2
+// CFI-NOT: control flow integrity check
+
+// REQUIRES: cxxabi
+
+#include 
+
+class A1 {
+public:
+virtual void f1() = 0;
+};
+
+class A2 {
+public:
+virtual void f2() = 0;
+};
+
+
+class B : public A1, public A2 {
+public:
+void f2() final { fprintf(stderr, "In f2\n"); }
+void f1() final { fprintf(stderr, "In f1\n"); }
+};
+
+int main() {
+B b;
+
+static_cast()->f1();
+static_cast()->f2();
+}
Index: clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cfi-multiple-inheritance.cpp
@@ -0,0 +1,31 @@
+// Test that correct vtable ptr and type metadata are passed to llvm.type.test
+// Related to Bugzilla 43390.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fvisibility hidden -std=c++11 -fsanitize=cfi-nvcall -emit-llvm -o - %s | FileCheck %s
+
+class A1 {
+public:
+virtual int f1() = 0;
+};
+
+class A2 {
+public:
+virtual int f2() = 0;
+};
+
+
+class B : public A1, public A2 {
+public:
+int f2() final { return 1; }
+int f1() final { return 2; }
+};
+
+// CHECK-LABEL: define hidden i32 @_Z3foov
+int foo() {
+B b;
+return static_cast()->f2();
+// CHECK: [[P:%[^ ]*]] = bitcast %class.B* %b to i8**
+// CHECK: [[V:%[^ ]*]] = load i8*, i8** [[P]], align 8
+// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"_ZTS1B")
+// CHECK: call i1 @llvm.type.test(i8* [[V]], metadata !"all-vtables")
+}
Index: clang/lib/CodeGen/CGExprCXX.cpp
===
--- clang/lib/CodeGen/CGExprCXX.cpp
+++ 

[PATCH] D68584: Fix Calling Convention through aliases

2019-10-07 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

lgtm


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

https://reviews.llvm.org/D68584



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


[PATCH] D68526: [Diagnostics] Silence -Wsizeof-array-div for character buffers

2019-10-07 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.

Thanks, I think this is a good change. It fixes a false positive in wayland and 
one somewhere in Chromium's windows sandbox. See the commit thread of r371605 
for examples.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68526



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


[PATCH] D68410: [AttrDocs] document always_inline

2019-10-07 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

In D68410#1694026 , @kristina wrote:

> Also, I'm fairly certain `__forceinline` and `always_inline`, confusingly 
> enough differ in semantics, with `__forceinline` only being a stronger hint 
> on MSVC.


Does clang handle `__forceinline` vs `always_inline` differently, today?  If 
not, then sounds like we may need to split these in two.

In D68410#1696411 , @joerg wrote:

> I wonder if we should actually enumerate evil here, i.e. give the situations 
> in which inlining actually fails.


Which is likely to change over time.  I worry that enumerating such cases is 
compiler version specific, and might lead to developers depending/[ab]using 
that behavior?

> As mentioned on IRC, I wonder if we shouldn't aim for the stronger semantics

As long as we error when we fail to inline, I think that matches GCC's 
behavior.  There's likely differences in what we can inline or not.

> and at least warn by default of any situation that prevents always_inline 
> from doing its job.

Might be hard to recognize all such cases in the frontend?  GCC does warn via 
`-Wattributes` when the attribute is applied to a non-`inline` function.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68410



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


r373936 - [clang] [cmake] Support LLVM_DISTRIBUTION_COMPONENTS in stand-alone build

2019-10-07 Thread Michal Gorny via cfe-commits
Author: mgorny
Date: Mon Oct  7 11:14:56 2019
New Revision: 373936

URL: http://llvm.org/viewvc/llvm-project?rev=373936=rev
Log:
[clang] [cmake] Support LLVM_DISTRIBUTION_COMPONENTS in stand-alone build

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

Modified:
cfe/trunk/CMakeLists.txt

Modified: cfe/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/CMakeLists.txt?rev=373936=373935=373936=diff
==
--- cfe/trunk/CMakeLists.txt (original)
+++ cfe/trunk/CMakeLists.txt Mon Oct  7 11:14:56 2019
@@ -114,6 +114,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
   include(TableGen)
   include(HandleLLVMOptions)
   include(VersionFromVCS)
+  include(LLVMDistributionSupport)
 
   set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
 
@@ -858,6 +859,10 @@ if (LLVM_ADD_NATIVE_VISUALIZERS_TO_SOLUT
 endif()
 add_subdirectory(utils/hmaptool)
 
+if(CLANG_BUILT_STANDALONE)
+  llvm_distribution_add_targets()
+endif()
+
 configure_file(
   ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
   ${CLANG_BINARY_DIR}/include/clang/Config/config.h)


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


[clang-tools-extra] r373932 - Try to get clangd tests passing on Windows.

2019-10-07 Thread Nico Weber via cfe-commits
Author: nico
Date: Mon Oct  7 10:55:05 2019
New Revision: 373932

URL: http://llvm.org/viewvc/llvm-project?rev=373932=rev
Log:
Try to get clangd tests passing on Windows.

Part of PR43592. See also r328645.

Modified:
clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
clang-tools-extra/trunk/clangd/test/type-hierarchy.test

Modified: clang-tools-extra/trunk/clangd/test/semantic-highlighting.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/semantic-highlighting.test?rev=373932=373931=373932=diff
==
--- clang-tools-extra/trunk/clangd/test/semantic-highlighting.test (original)
+++ clang-tools-extra/trunk/clangd/test/semantic-highlighting.test Mon Oct  7 
10:55:05 2019
@@ -65,7 +65,7 @@
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"textDocument": {
-# CHECK-NEXT:  "uri": "file:///clangd-test/foo.cpp"
+# CHECK-NEXT:  "uri": "file://{{.*}}/clangd-test/foo.cpp"
 # CHECK-NEXT:}
 # CHECK-NEXT:  }
 # CHECK-NEXT:}
@@ -84,7 +84,7 @@
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"textDocument": {
-# CHECK-NEXT:  "uri": "file:///clangd-test/foo2.cpp"
+# CHECK-NEXT:  "uri": "file://{{.*}}/clangd-test/foo2.cpp"
 # CHECK-NEXT:}
 # CHECK-NEXT:  }
 # CHECK-NEXT:}
@@ -99,7 +99,7 @@
 # CHECK-NEXT:  }
 # CHECK-NEXT:   ],
 # CHECK-NEXT:"textDocument": {
-# CHECK-NEXT:  "uri": "file:///clangd-test/foo.cpp"
+# CHECK-NEXT:  "uri": "file://{{.*}}/clangd-test/foo.cpp"
 # CHECK-NEXT:}
 # CHECK-NEXT:  }
 # CHECK-NEXT:}
@@ -114,7 +114,7 @@
 # CHECK-NEXT:  }
 # CHECK-NEXT:   ],
 # CHECK-NEXT:"textDocument": {
-# CHECK-NEXT:  "uri": "file:///clangd-test/foo.cpp"
+# CHECK-NEXT:  "uri": "file://{{.*}}/clangd-test/foo.cpp"
 # CHECK-NEXT:}
 # CHECK-NEXT:  }
 # CHECK-NEXT:}

Modified: clang-tools-extra/trunk/clangd/test/type-hierarchy.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/type-hierarchy.test?rev=373932=373931=373932=diff
==
--- clang-tools-extra/trunk/clangd/test/type-hierarchy.test (original)
+++ clang-tools-extra/trunk/clangd/test/type-hierarchy.test Mon Oct  7 10:55:05 
2019
@@ -32,7 +32,7 @@
 # CHECK-NEXT:"line": 3
 # CHECK-NEXT:  }
 # CHECK-NEXT:},
-# CHECK-NEXT:"uri": "file:///clangd-test/main.cpp"
+# CHECK-NEXT:"uri": "file://{{.*}}/clangd-test/main.cpp"
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"kind": 23,
@@ -66,7 +66,7 @@
 # CHECK-NEXT:"line": 0
 # CHECK-NEXT:  }
 # CHECK-NEXT:},
-# CHECK-NEXT:"uri": "file:///clangd-test/main.cpp"
+# CHECK-NEXT:"uri": "file://{{.*}}/clangd-test/main.cpp"
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"range": {
@@ -89,7 +89,7 @@
 # CHECK-NEXT:"line": 1
 # CHECK-NEXT:  }
 # CHECK-NEXT:},
-# CHECK-NEXT:"uri": "file:///clangd-test/main.cpp"
+# CHECK-NEXT:"uri": "file://{{.*}}/clangd-test/main.cpp"
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"range": {
@@ -112,7 +112,7 @@
 # CHECK-NEXT:"line": 2
 # CHECK-NEXT:  }
 # CHECK-NEXT:},
-# CHECK-NEXT:"uri": "file:///clangd-test/main.cpp"
+# CHECK-NEXT:"uri": "file://{{.*}}/clangd-test/main.cpp"
 # CHECK-NEXT:  }
 ---
 
{"jsonrpc":"2.0","id":2,"method":"typeHierarchy/resolve","params":{"item":{"uri":"test:///main.cpp","data":"A6576FE083F2949A","name":"Child3","kind":23,"range":{"end":{"character":13,"line":3},"start":{"character":7,"line":3}},"selectionRange":{"end":{"character":13,"line":3},"start":{"character":7,"line":3}}},"direction":0,"resolve":1}}
@@ -144,7 +144,7 @@
 # CHECK-NEXT:"line": 4
 # CHECK-NEXT:  }
 # CHECK-NEXT:},
-# CHECK-NEXT:"uri": "file:///clangd-test/main.cpp"
+# CHECK-NEXT:"uri": "file://{{.*}}/clangd-test/main.cpp"
 # CHECK-NEXT:  }
 # CHECK-NEXT:],
 # CHECK-NEXT:"data": "A6576FE083F2949A",
@@ -170,7 +170,7 @@
 # CHECK-NEXT:"line": 3
 # CHECK-NEXT:  }
 # CHECK-NEXT:},
-# CHECK-NEXT:"uri": "file:///clangd-test/main.cpp"
+# CHECK-NEXT:"uri": "file://{{.*}}/clangd-test/main.cpp"
 # CHECK-NEXT:  }
 ---
 {"jsonrpc":"2.0","id":3,"method":"shutdown"}


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


[PATCH] D68578: [HIP] Fix device stub name

2019-10-07 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D68578#1697851 , @yaxunl wrote:

> In D68578#1697822 , @tra wrote:
>
> > Could you elaborate on how exactly current implementation does not work?
> >
> > I would expect the kernel and the stub to be two distinct entities, as far 
> > as debugger is concerned. It does have enough information to track each 
> > independently (different address, .stub suffix, perhaps knowledge whether 
> > it's device or host code). Without the details, it looks to me that this is 
> > something that can and should be dealt with in the debugger. I've asked the 
> > same question in D63335  but I don't think 
> > I've got a good answer.
>
>
> HIP debugger is a branch of gdb and the changes to support HIP will be 
> upstreamed. When users set break point on a kernel, they intend to set a 
> break point on the real kernel, not the device stub function. The device stub 
> function is only a compiler generated helper function to help launch the 
> kernel. Therefore it should have a different name so that it does not 
> interfere with the symbol resolution of the real kernel.


I would agree that having distinct names for the device-side kernel and it's 
host-side stub would probably make things easier for debugger. 
However, debugger does have access to mangled names and does see the '.stub' 
suffix in the mangled name. I don't understand why it can't be considered to 
disambiguate between the kernel and the stub? 
I'm clearly missing something here. Is there a chance to get someone from the 
debugger team to chime in on this review directly?

Also, I would not agree that `they intend to set a break point on the real 
kernel` is the only scenario. E.g. quite often when I debug CUDA stuff, I do 
only care about host-side things and I do want to set breakpoint on the stub, 
so I can check kernel call parameters as they are passed to the kernel. It 
would be great if there were a way to explicitly tell debugger whether we want 
host-side stub or the kernel without having user to know how particular 
compiler transforms the name. For the user both entities have the same name, 
but distinct location and there should be a way to express that in the debugger.


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

https://reviews.llvm.org/D68578



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


r373929 - Fix Calling Convention through aliases

2019-10-07 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Mon Oct  7 10:28:03 2019
New Revision: 373929

URL: http://llvm.org/viewvc/llvm-project?rev=373929=rev
Log:
Fix Calling Convention through aliases

r369697 changed the behavior of stripPointerCasts to no longer include
aliases.  However, the code in CGDeclCXX.cpp's createAtExitStub counted
on the looking through aliases to properly set the calling convention of
a call.

The result of the change was that the calling convention mismatch of the
call would be replaced with a llvm.trap, causing a runtime crash.

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

Added:
cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp   (with props)
Modified:
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp

Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=373929=373928=373929=diff
==
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Mon Oct  7 10:28:03 2019
@@ -248,8 +248,8 @@ llvm::Function *CodeGenFunction::createA
   llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr);
 
  // Make sure the call and the callee agree on calling convention.
-  if (llvm::Function *dtorFn =
-  dyn_cast(dtor.getCallee()->stripPointerCasts()))
+  if (auto *dtorFn = dyn_cast(
+  dtor.getCallee()->stripPointerCastsAndAliases()))
 call->setCallingConv(dtorFn->getCallingConv());
 
   CGF.FinishFunction();

Added: cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp?rev=373929=auto
==
--- cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp Mon Oct  7 10:28:03 2019
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple i686-windows-pc -emit-llvm -o - 
-mconstructor-aliases -O1 -disable-llvm-passes %s | FileCheck %s
+
+struct Base { virtual ~Base(); };
+struct Derived : Base {
+  virtual ~Derived();
+  static Derived inst;
+};
+
+Base::~Base(){}
+Derived::~Derived(){}
+Derived Derived::inst;
+
+// CHECK: @"??1Derived@@UAE@XZ" = dso_local unnamed_addr alias void 
(%struct.Derived*), bitcast (void (%struct.Base*)* @"??1Base@@UAE@XZ" to void 
(%struct.Derived*)*)
+
+// CHECK: define dso_local x86_thiscallcc void @"??1Base@@UAE@XZ"
+// CHECK: define internal void @"??__E?inst@Derived@@2U1@A@@YAXXZ"
+// CHECK: call i32 @atexit(void ()* @"??__F?inst@Derived@@2U1@A@@YAXXZ"
+//
+// CHECK: define internal void @"??__F?inst@Derived@@2U1@A@@YAXXZ"
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call x86_thiscallcc void @"??1Derived@@UAE@XZ"

Propchange: cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
--
svn:eol-style = native

Propchange: cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
--
svn:keywords = Author Date Id Rev URL

Propchange: cfe/trunk/test/CodeGenCXX/call-conv-thru-alias.cpp
--
svn:mime-type = text/plain


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


[PATCH] D68412: [clang] [cmake] Support LLVM_DISTRIBUTION_COMPONENTS in stand-alone build

2019-10-07 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai accepted this revision.
smeenai added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D68412



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


r373928 - [libTooling][NFC] Fix build break in r373916.

2019-10-07 Thread Yitzhak Mandelbaum via cfe-commits
Author: ymandel
Date: Mon Oct  7 10:24:23 2019
New Revision: 373928

URL: http://llvm.org/viewvc/llvm-project?rev=373928=rev
Log:
[libTooling][NFC] Fix build break in r373916.

r373916 used raw strings inside macro calls, which breaks some builds.

Modified:
cfe/trunk/unittests/Tooling/StencilTest.cpp

Modified: cfe/trunk/unittests/Tooling/StencilTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/StencilTest.cpp?rev=373928=373927=373928=diff
==
--- cfe/trunk/unittests/Tooling/StencilTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/StencilTest.cpp Mon Oct  7 10:24:23 2019
@@ -392,56 +392,64 @@ TEST(StencilEqualityTest, InEqualityRun)
 
 TEST(StencilToStringTest, RawTextOp) {
   auto S = cat("foo bar baz");
-  EXPECT_EQ(S.toString(), R"("foo bar baz")");
+  StringRef Expected = R"("foo bar baz")";
+  EXPECT_EQ(S.toString(), Expected);
 }
 
 TEST(StencilToStringTest, RawTextOpEscaping) {
   auto S = cat("foo \"bar\" baz\\n");
-  EXPECT_EQ(S.toString(), R"("foo \"bar\" baz\\n")");
+  StringRef Expected = R"("foo \"bar\" baz\\n")";
+  EXPECT_EQ(S.toString(), Expected);
 }
 
 TEST(StencilToStringTest, DebugPrintNodeOp) {
   auto S = cat(dPrint("Id"));
-  EXPECT_EQ(S.toString(), R"repr(dPrint("Id"))repr");
+  StringRef Expected = R"repr(dPrint("Id"))repr";
+  EXPECT_EQ(S.toString(), Expected);
 }
 
 TEST(StencilToStringTest, ExpressionOp) {
   auto S = cat(expression("Id"));
-  EXPECT_EQ(S.toString(), R"repr(expression("Id"))repr");
+  StringRef Expected = R"repr(expression("Id"))repr";
+  EXPECT_EQ(S.toString(), Expected);
 }
 
 TEST(StencilToStringTest, DerefOp) {
   auto S = cat(deref("Id"));
-  EXPECT_EQ(S.toString(), R"repr(deref("Id"))repr");
+  StringRef Expected = R"repr(deref("Id"))repr";
+  EXPECT_EQ(S.toString(), Expected);
 }
 
 TEST(StencilToStringTest, AddressOfOp) {
   auto S = cat(addressOf("Id"));
-  EXPECT_EQ(S.toString(), R"repr(addressOf("Id"))repr");
+  StringRef Expected = R"repr(addressOf("Id"))repr";
+  EXPECT_EQ(S.toString(), Expected);
 }
 
 TEST(StencilToStringTest, AccessOp) {
   auto S = cat(access("Id", text("memberData")));
-  EXPECT_EQ(S.toString(), R"repr(access("Id", "memberData"))repr");
+  StringRef Expected = R"repr(access("Id", "memberData"))repr";
+  EXPECT_EQ(S.toString(), Expected);
 }
 
 TEST(StencilToStringTest, AccessOpStencilPart) {
   auto S = cat(access("Id", access("subId", "memberData")));
-  EXPECT_EQ(S.toString(),
-R"repr(access("Id", access("subId", "memberData")))repr");
+  StringRef Expected = R"repr(access("Id", access("subId", 
"memberData")))repr";
+  EXPECT_EQ(S.toString(), Expected);
 }
 
 TEST(StencilToStringTest, IfBoundOp) {
   auto S = cat(ifBound("Id", text("trueText"), access("exprId", 
"memberData")));
-  EXPECT_EQ(
-  S.toString(),
-  R"repr(ifBound("Id", "trueText", access("exprId", "memberData")))repr");
+  StringRef Expected =
+  R"repr(ifBound("Id", "trueText", access("exprId", "memberData")))repr";
+  EXPECT_EQ(S.toString(), Expected);
 }
 
 TEST(StencilToStringTest, MultipleOp) {
   auto S = cat("foo", access("x", "m()"), "bar",
ifBound("x", text("t"), access("e", "f")));
-  EXPECT_EQ(S.toString(), R"repr("foo", access("x", "m()"), "bar", )repr"
-  R"repr(ifBound("x", "t", access("e", "f")))repr");
+  StringRef Expected = R"repr("foo", access("x", "m()"), "bar", )repr"
+   R"repr(ifBound("x", "t", access("e", "f")))repr";
+  EXPECT_EQ(S.toString(), Expected);
 }
 } // namespace


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


[PATCH] D68584: Fix Calling Convention through aliases

2019-10-07 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc accepted this revision.
pcc added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:251
  // Make sure the call and the callee agree on calling convention.
-  if (llvm::Function *dtorFn =
-  dyn_cast(dtor.getCallee()->stripPointerCasts()))
+  if (llvm::Function *dtorFn = dyn_cast(
+  dtor.getCallee()->stripPointerCastsAndAliases()))

Nit: while here you could change this to `auto *`.


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

https://reviews.llvm.org/D68584



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


[PATCH] D67985: CFI: wrong type passed to llvm.type.test with multiple inheritance devirtualization

2019-10-07 Thread Peter Collingbourne via Phabricator via cfe-commits
pcc added a comment.

Can you add a CodeGenCXX test as well, please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67985



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


[PATCH] D67985: CFI: wrong type passed to llvm.type.test with multiple inheritance devirtualization

2019-10-07 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab added subscribers: pcc, filcab.
filcab added a comment.

It seems there's a FIXME anticipating this problem.

@pcc: Can you double-check, please?

Thank you,
Filipe


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67985



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


[PATCH] D68574: [libTooling] Add `toString` method to the Stencil class

2019-10-07 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel added a comment.

The tests broke the build on some platforms because of the use of raw strings 
in macros. Fixing now...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68574



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


[clang-tools-extra] r373924 - [clangd] Fix raciness in code completion tests

2019-10-07 Thread Kadir Cetinkaya via cfe-commits
Author: kadircet
Date: Mon Oct  7 10:12:18 2019
New Revision: 373924

URL: http://llvm.org/viewvc/llvm-project?rev=373924=rev
Log:
[clangd] Fix raciness in code completion tests

Reviewers: sammccall, ilya-biryukov

Subscribers: MaskRay, jkorous, arphaman, usaxena95, cfe-commits

Tags: #clang

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

Modified:
clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp

Modified: clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp?rev=373924=373923=373924=diff
==
--- clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp (original)
+++ clang-tools-extra/trunk/clangd/unittests/CodeCompleteTests.cpp Mon Oct  7 
10:12:18 2019
@@ -18,6 +18,7 @@
 #include "TestFS.h"
 #include "TestIndex.h"
 #include "TestTU.h"
+#include "Threading.h"
 #include "index/Index.h"
 #include "index/MemIndex.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
@@ -27,6 +28,8 @@
 #include "llvm/Testing/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
+#include 
+#include 
 
 namespace clang {
 namespace clangd {
@@ -1112,8 +1115,9 @@ public:
   bool
   fuzzyFind(const FuzzyFindRequest ,
 llvm::function_ref Callback) const override {
-std::lock_guard Lock(Mut);
+std::unique_lock Lock(Mut);
 Requests.push_back(Req);
+ReceivedRequestCV.notify_one();
 return true;
   }
 
@@ -1131,8 +1135,10 @@ public:
   // isn't used in production code.
   size_t estimateMemoryUsage() const override { return 0; }
 
-  const std::vector consumeRequests() const {
-std::lock_guard Lock(Mut);
+  const std::vector consumeRequests(size_t Num) const {
+std::unique_lock Lock(Mut);
+EXPECT_TRUE(wait(Lock, ReceivedRequestCV, timeoutSeconds(10),
+ [this, Num] { return Requests.size() == Num; }));
 auto Reqs = std::move(Requests);
 Requests = {};
 return Reqs;
@@ -1140,16 +1146,21 @@ public:
 
 private:
   // We need a mutex to handle async fuzzy find requests.
+  mutable std::condition_variable ReceivedRequestCV;
   mutable std::mutex Mut;
   mutable std::vector Requests;
 };
 
-std::vector captureIndexRequests(llvm::StringRef Code) {
+// Clients have to consume exactly Num requests.
+std::vector captureIndexRequests(llvm::StringRef Code,
+   size_t Num = 1) {
   clangd::CodeCompleteOptions Opts;
   IndexRequestCollector Requests;
   Opts.Index = 
   completions(Code, {}, Opts);
-  return Requests.consumeRequests();
+  const auto Reqs = Requests.consumeRequests(Num);
+  EXPECT_EQ(Reqs.size(), Num);
+  return Reqs;
 }
 
 TEST(CompletionTest, UnqualifiedIdQuery) {
@@ -2098,18 +2109,15 @@ TEST(CompletionTest, EnableSpeculativeIn
 
   auto CompleteAtPoint = [&](StringRef P) {
 cantFail(runCodeComplete(Server, File, Test.point(P), Opts));
-// Sleep for a while to make sure asynchronous call (if applicable) is also
-// triggered before callback is invoked.
-std::this_thread::sleep_for(std::chrono::milliseconds(100));
   };
 
   CompleteAtPoint("1");
-  auto Reqs1 = Requests.consumeRequests();
+  auto Reqs1 = Requests.consumeRequests(1);
   ASSERT_EQ(Reqs1.size(), 1u);
   EXPECT_THAT(Reqs1[0].Scopes, UnorderedElementsAre("ns1::"));
 
   CompleteAtPoint("2");
-  auto Reqs2 = Requests.consumeRequests();
+  auto Reqs2 = Requests.consumeRequests(1);
   // Speculation succeeded. Used speculative index result.
   ASSERT_EQ(Reqs2.size(), 1u);
   EXPECT_EQ(Reqs2[0], Reqs1[0]);
@@ -2117,7 +2125,7 @@ TEST(CompletionTest, EnableSpeculativeIn
   CompleteAtPoint("3");
   // Speculation failed. Sent speculative index request and the new index
   // request after sema.
-  auto Reqs3 = Requests.consumeRequests();
+  auto Reqs3 = Requests.consumeRequests(2);
   ASSERT_EQ(Reqs3.size(), 2u);
 }
 


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


[PATCH] D63960: [C++20] Add consteval-specific semantic for functions

2019-10-07 Thread Tyker via Phabricator via cfe-commits
Tyker updated this revision to Diff 223624.

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

https://reviews.llvm.org/D63960

Files:
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp

Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -12,6 +12,7 @@
 }
 
 constexpr auto l_eval = [](int i) consteval {
+// expected-note@-1+ {{declared here}}
 
   return i;
 };
@@ -23,6 +24,7 @@
 
 struct A {
   consteval int f1(int i) const {
+// expected-note@-1 {{declared here}}
 return i;
   }
   consteval A(int i);
@@ -62,3 +64,203 @@
 consteval int main() { // expected-error {{'main' is not allowed to be declared consteval}}
   return 0;
 }
+
+consteval int f_eval(int i) {
+// expected-note@-1+ {{declared here}}
+  return i;
+}
+
+namespace taking_address {
+
+using func_type = int(int);
+
+func_type* p1 = (_eval);
+// expected-error@-1 {{take address}}
+func_type* p7 = __builtin_addressof(f_eval);
+// expected-error@-1 {{take address}}
+
+auto p = f_eval;
+// expected-error@-1 {{take address}}
+
+auto m1 = _sema::A::f1;
+// expected-error@-1 {{take address}}
+auto l1 = (basic_sema::l_eval)::operator();
+// expected-error@-1 {{take address}}
+
+consteval int f(int i) {
+// expected-note@-1+ {{declared here}}
+  return i;
+}
+
+auto ptr = 
+// expected-error@-1 {{take address}}
+
+auto f1() {
+  return 
+// expected-error@-1 {{take address}}
+}
+
+}
+
+namespace invalid_function {
+using size_t = unsigned long;
+struct A {
+  consteval void *operator new(size_t count);
+  // expected-error@-1 {{'operator new' cannot be declared consteval}}
+  consteval void *operator new[](size_t count);
+  // expected-error@-1 {{'operator new[]' cannot be declared consteval}}
+  consteval void operator delete(void* ptr);
+  // expected-error@-1 {{'operator delete' cannot be declared consteval}}
+  consteval void operator delete[](void* ptr);
+  // expected-error@-1 {{'operator delete[]' cannot be declared consteval}}
+};
+
+}
+
+namespace nested {
+consteval int f() {
+  return 0;
+}
+
+consteval int f1(...) {
+  return 1;
+}
+
+enum E {};
+
+using T = int(&)();
+
+consteval auto operator+ (E, int(*a)()) {
+  return 0;
+}
+
+void d() {
+  auto i = f1(E() + );
+}
+
+auto l0 = [](auto) consteval {
+  return 0;
+};
+
+int i0 = l0();
+
+int i1 = f1(l0(4));
+
+int i2 = f1(, , , , , , );
+
+int i3 = f1(f1(f1(, ), f1(, ), f1(f1(, ), )));
+
+}
+
+namespace user_defined_literal {
+
+consteval int operator"" _test(unsigned long long i) {
+// expected-note@-1+ {{declared here}}
+  return 0;
+}
+
+int i = 0_test;
+
+auto ptr = "" _test;
+// expected-error@-1 {{take address}}
+
+}
+
+namespace return_address {
+
+consteval int f() {
+  return 0;
+}
+
+consteval int(*ret1(int i))() {
+  return 
+}
+
+auto ptr = ret1(0);
+// expected-error@-1 {{could not be evaluated}}
+// expected-note@-2 {{pointer to a consteval}}
+
+struct A {
+  consteval int f(int) {
+return 0;
+  }
+};
+
+using mem_ptr_type = int (A::*)(int);
+
+template
+struct C {};
+
+C<::f> c;
+// expected-error@-1 {{is not a constant expression}}
+// expected-note@-2 {{pointer to a consteval}}
+
+consteval mem_ptr_type ret2() {
+  return ::f;
+}
+
+C c1;
+// expected-error@-1 {{is not a constant expression}}
+// expected-note@-2 {{pointer to a consteval}}
+
+}
+
+namespace context {
+
+int g_i;
+// expected-note@-1 {{declared here}}
+
+consteval int f(int) {
+  return 0;
+}
+
+constexpr int c_i = 0;
+
+int t1 = f(g_i);
+// expected-error@-1 {{could not be evaluated}}
+// expected-note@-2 {{read of non-const variable}}
+int t3 = f(c_i);
+
+constexpr int f_c(int i) {
+// expected-note@-1 {{declared here}}
+  int t = f(i);
+// expected-error@-1 {{could not be evaluated}}
+// expected-note@-2 {{read of non-const variable}}
+  return f(0);  
+}
+
+consteval int f_eval(int i) {
+  return f(i);
+}
+
+auto l0 = [](int i) consteval {
+  return f(i);
+};
+
+auto l1 = [](int i) constexpr {
+// expected-note@-1 {{declared here}}
+  int t = f(i);
+// expected-error@-1 {{could not be evaluated}}
+// expected-note@-2 {{read of non-const variable}}
+  return f(0);  
+};
+
+}
+
+namespace cleanup {
+
+struct A {
+  int *p = new int(42);
+  consteval int get() { return *p; }
+  constexpr ~A() { delete p; }
+};
+int k1 = A().get();
+
+struct B {
+  int *p = new int(42);
+  consteval int get() { return *p; }
+  consteval ~B() { delete p; }
+};
+int 

r373922 - [clang-format] [PR27004] omits leading space for noexcept when formatting operator delete()

2019-10-07 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Mon Oct  7 10:03:44 2019
New Revision: 373922

URL: http://llvm.org/viewvc/llvm-project?rev=373922=rev
Log:
[clang-format] [PR27004] omits leading space for noexcept when formatting 
operator delete()

Summary:
clang-format is incorrectly thinking the parameter parens are part of a cast 
operation, this is resulting in there sometimes being not space between the 
paren and the noexcept (and other keywords like volatile etc..)

```
void operator++(int) noexcept;
void operator++(int &) noexcept;
void operator delete(void *, std::size_t, const std::nothrow_t &)noexcept;
```

Reviewers: klimek, owenpan, mitchell-stellar

Reviewed By: mitchell-stellar

Subscribers: cfe-commits

Tags: #clang-format, #clang

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=373922=373921=373922=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Oct  7 10:03:44 2019
@@ -1611,6 +1611,13 @@ private:
 if (Tok.Next->is(tok::question))
   return false;
 
+// Functions which end with decorations like volatile, noexcept are 
unlikely
+// to be casts.
+if (Tok.Next->isOneOf(tok::kw_noexcept, tok::kw_volatile, tok::kw_const,
+  tok::kw_throw, tok::l_square, tok::arrow,
+  Keywords.kw_override, Keywords.kw_final))
+  return false;
+
 // As Java has no function types, a "(" after the ")" likely means that 
this
 // is a cast.
 if (Style.Language == FormatStyle::LK_Java && Tok.Next->is(tok::l_paren))

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=373922=373921=373922=diff
==
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Oct  7 10:03:44 2019
@@ -14678,6 +14678,33 @@ TEST_F(FormatTest, AlternativeOperators)
   */
 }
 
+TEST_F(FormatTest, NotCastRPaen) {
+
+  verifyFormat("void operator++(int) noexcept;");
+  verifyFormat("void operator++(int &) noexcept;");
+  verifyFormat("void operator delete(void *, std::size_t, const std::nothrow_t 
"
+   "&) noexcept;");
+  verifyFormat(
+  "void operator delete(std::size_t, const std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(const std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(std::nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(nothrow_t &) noexcept;");
+  verifyFormat("void operator delete(foo &) noexcept;");
+  verifyFormat("void operator delete(foo) noexcept;");
+  verifyFormat("void operator delete(int) noexcept;");
+  verifyFormat("void operator delete(int &) noexcept;");
+  verifyFormat("void operator delete(int &) volatile noexcept;");
+  verifyFormat("void operator delete(int &) const");
+  verifyFormat("void operator delete(int &) = default");
+  verifyFormat("void operator delete(int &) = delete");
+  verifyFormat("void operator delete(int &) [[noreturn]]");
+  verifyFormat("void operator delete(int &) throw();");
+  verifyFormat("void operator delete(int &) throw(int);");
+  verifyFormat("auto operator delete(int &) -> int;");
+  verifyFormat("auto operator delete(int &) override");
+  verifyFormat("auto operator delete(int &) final");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


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


[PATCH] D68554: [clang-format] Proposal for clang-format to give compiler style warnings

2019-10-07 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar added a comment.

I don't care for the command line switches that try to emulate compiler flags. 
I am also of the opinion that external scripts should be used for this 
functionality. git for Windows gives you a full set of bash utilities to 
utilize, so doing stuff like this on Windows is much easier now.


Repository:
  rC Clang

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

https://reviews.llvm.org/D68554



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


r373921 - [clang-format] [NFC] Ensure clang-format is itself clang-formatted.

2019-10-07 Thread Paul Hoad via cfe-commits
Author: paulhoad
Date: Mon Oct  7 09:53:35 2019
New Revision: 373921

URL: http://llvm.org/viewvc/llvm-project?rev=373921=rev
Log:
[clang-format] [NFC] Ensure clang-format is itself clang-formatted.

Summary:
Before making a proposed change, ensure ClangFormat.cpp is fully 
clang-formatted,

no functional change just clang-formatting using the in tree .clang-format.

Reviewers: mitchell-stellar

Reviewed By: mitchell-stellar

Subscribers: Eugene.Zelenko, cfe-commits

Tags: #clang-format, #clang

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

Modified:
cfe/trunk/tools/clang-format/ClangFormat.cpp

Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=373921=373920=373921=diff
==
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Mon Oct  7 09:53:35 2019
@@ -51,13 +51,14 @@ static cl::list
  "Can only be used with one input file."),
 cl::cat(ClangFormatCategory));
 static cl::list
-LineRanges("lines", cl::desc(": - format a range of\n"
- "lines (both 1-based).\n"
- "Multiple ranges can be formatted by specifying\n"
- "several -lines arguments.\n"
- "Can't be used with -offset and -length.\n"
- "Can only be used with one input file."),
-   cl::cat(ClangFormatCategory));
+LineRanges("lines",
+   cl::desc(": - format a range of\n"
+"lines (both 1-based).\n"
+"Multiple ranges can be formatted by specifying\n"
+"several -lines arguments.\n"
+"Can't be used with -offset and -length.\n"
+"Can only be used with one input file."),
+   cl::cat(ClangFormatCategory));
 static cl::opt
 Style("style", cl::desc(clang::format::StyleOptionHelpDescription),
   cl::init(clang::format::DefaultFormatStyle),
@@ -72,12 +73,12 @@ static cl::opt
   cl::init(clang::format::DefaultFallbackStyle),
   cl::cat(ClangFormatCategory));
 
-static cl::opt
-AssumeFileName("assume-filename",
-   cl::desc("When reading from stdin, clang-format assumes this\n"
-"filename to look for a style config file (with\n"
-"-style=file) and to determine the language."),
-   cl::init(""), cl::cat(ClangFormatCategory));
+static cl::opt AssumeFileName(
+"assume-filename",
+cl::desc("When reading from stdin, clang-format assumes this\n"
+ "filename to look for a style config file (with\n"
+ "-style=file) and to determine the language."),
+cl::init(""), cl::cat(ClangFormatCategory));
 
 static cl::opt Inplace("i",
  cl::desc("Inplace edit s, if specified."),
@@ -249,8 +250,8 @@ static bool format(StringRef FileName) {
   // On Windows, overwriting a file with an open file mapping doesn't work,
   // so read the whole file into memory when formatting in-place.
   ErrorOr> CodeOrErr =
-  !OutputXML && Inplace ? MemoryBuffer::getFileAsStream(FileName) :
-  MemoryBuffer::getFileOrSTDIN(FileName);
+  !OutputXML && Inplace ? MemoryBuffer::getFileAsStream(FileName)
+: MemoryBuffer::getFileOrSTDIN(FileName);
   if (std::error_code EC = CodeOrErr.getError()) {
 errs() << EC.message() << "\n";
 return true;
@@ -264,20 +265,21 @@ static bool format(StringRef FileName) {
   // https://en.wikipedia.org/wiki/Byte_order_mark#Byte_order_marks_by_encoding
   // for more information.
   StringRef BufStr = Code->getBuffer();
-  const char *InvalidBOM = llvm::StringSwitch(BufStr)
-.StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
-  "UTF-32 (BE)")
-.StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
-  "UTF-32 (LE)")
-.StartsWith("\xFE\xFF", "UTF-16 (BE)")
-.StartsWith("\xFF\xFE", "UTF-16 (LE)")
-.StartsWith("\x2B\x2F\x76", "UTF-7")
-.StartsWith("\xF7\x64\x4C", "UTF-1")
-.StartsWith("\xDD\x73\x66\x73", "UTF-EBCDIC")
-.StartsWith("\x0E\xFE\xFF", "SCSU")
-.StartsWith("\xFB\xEE\x28", "BOCU-1")
-.StartsWith("\x84\x31\x95\x33", "GB-18030")
-.Default(nullptr);
+  const char *InvalidBOM =
+  llvm::StringSwitch(BufStr)
+  .StartsWith(llvm::StringLiteral::withInnerNUL("\x00\x00\xFE\xFF"),
+  "UTF-32 (BE)")
+  .StartsWith(llvm::StringLiteral::withInnerNUL("\xFF\xFE\x00\x00"),
+  "UTF-32 (LE)")
+  .StartsWith("\xFE\xFF", "UTF-16 (BE)")
+  

[PATCH] D68578: [HIP] Fix device stub name

2019-10-07 Thread Michael Liao via Phabricator via cfe-commits
hliao added inline comments.



Comment at: lib/CodeGen/CGCUDANV.cpp:235
CGF.CGM.getContext().getTargetInfo().getCXXABI())) ||
+ CGF.getLangOpts().HIP ||
  getDeviceStubName(getDeviceSideName(CGF.CurFuncDecl)) ==

keeping the original assertion in HIP is still valuable to capture naming 
mismatch issue for unnamed types


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

https://reviews.llvm.org/D68578



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


[PATCH] D29039: [clang-format] Proposal for clang-format -r option

2019-10-07 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar added a subscriber: djasper.
mitchell-stellar added a comment.

I agree with @djasper that this is outside the scope of clang-format. git for 
Windows gives you a full set of bash utilities to utilize, so doing stuff like 
this on Windows is much easier now.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D29039



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


[PATCH] D68578: [HIP] Fix device stub name

2019-10-07 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In D68578#1697822 , @tra wrote:

> Could you elaborate on how exactly current implementation does not work?
>
> I would expect the kernel and the stub to be two distinct entities, as far as 
> debugger is concerned. It does have enough information to track each 
> independently (different address, .stub suffix, perhaps knowledge whether 
> it's device or host code). Without the details, it looks to me that this is 
> something that can and should be dealt with in the debugger. I've asked the 
> same question in D63335  but I don't think 
> I've got a good answer.


HIP debugger is a branch of gdb and the changes to support HIP will be 
upstreamed. When users set break point on a kernel, they intend to set a break 
point on the real kernel, not the device stub function. The device stub 
function is only a compiler generated helper function to help launch the 
kernel. Therefore it should have a different name so that it does not interfere 
with the symbol resolution of the real kernel.


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

https://reviews.llvm.org/D68578



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


r373918 - Codegen - silence static analyzer getAs<> null dereference warnings. NFCI.

2019-10-07 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Mon Oct  7 09:42:25 2019
New Revision: 373918

URL: http://llvm.org/viewvc/llvm-project?rev=373918=rev
Log:
Codegen - silence static analyzer getAs<> null dereference warnings. NFCI.

The static analyzer is warning about potential null dereferences, but in these 
cases we should be able to use castAs<> directly and if not assert will fire 
for us.

Modified:
cfe/trunk/lib/CodeGen/CGAtomic.cpp
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/lib/CodeGen/CGClass.cpp
cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
cfe/trunk/lib/CodeGen/TargetInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGAtomic.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGAtomic.cpp?rev=373918=373917=373918=diff
==
--- cfe/trunk/lib/CodeGen/CGAtomic.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGAtomic.cpp Mon Oct  7 09:42:25 2019
@@ -970,7 +970,7 @@ RValue CodeGenFunction::EmitAtomicExpr(A
 auto CastToGenericAddrSpace = [&](llvm::Value *V, QualType PT) {
   if (!E->isOpenCL())
 return V;
-  auto AS = PT->getAs()->getPointeeType().getAddressSpace();
+  auto AS = PT->castAs()->getPointeeType().getAddressSpace();
   if (AS == LangAS::opencl_generic)
 return V;
   auto DestAS = getContext().getTargetAddressSpace(LangAS::opencl_generic);

Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=373918=373917=373918=diff
==
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Mon Oct  7 09:42:25 2019
@@ -104,8 +104,8 @@ bool CodeGenModule::TryEmitBaseDestructo
   // Give up if the calling conventions don't match. We could update the call,
   // but it is probably not worth it.
   const CXXDestructorDecl *BaseD = UniqueBase->getDestructor();
-  if (BaseD->getType()->getAs()->getCallConv() !=
-  D->getType()->getAs()->getCallConv())
+  if (BaseD->getType()->castAs()->getCallConv() !=
+  D->getType()->castAs()->getCallConv())
 return true;
 
   GlobalDecl AliasDecl(D, Dtor_Base);

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=373918=373917=373918=diff
==
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Oct  7 09:42:25 2019
@@ -739,7 +739,7 @@ bool CodeGenFunction::IsConstructorDeleg
 
   // We also disable the optimization for variadic functions because
   // it's impossible to "re-pass" varargs.
-  if (Ctor->getType()->getAs()->isVariadic())
+  if (Ctor->getType()->castAs()->isVariadic())
 return false;
 
   // FIXME: Decide if we can do a delegation of a delegating constructor.

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=373918=373917=373918=diff
==
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Mon Oct  7 09:42:25 2019
@@ -1659,7 +1659,7 @@ void CGDebugInfo::CollectCXXMemberFuncti
 if (!Method || Method->isImplicit() || Method->hasAttr())
   continue;
 
-if (Method->getType()->getAs()->getContainedAutoType())
+if (Method->getType()->castAs()->getContainedAutoType())
   continue;
 
 // Reuse the existing member function declaration if it exists.
@@ -4561,7 +4561,7 @@ void CGDebugInfo::EmitUsingDecl(const Us
   // return type in the definition)
   if (const auto *FD = dyn_cast(USD.getUnderlyingDecl()))
 if (const auto *AT =
-FD->getType()->getAs()->getContainedAutoType())
+FD->getType()->castAs()->getContainedAutoType())
   if (AT->getDeducedType().isNull())
 return;
   if (llvm::DINode *Target =

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=373918=373917=373918=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Oct  7 09:42:25 2019
@@ -997,7 +997,7 @@ EmitComplexPrePostIncDec(const UnaryOper
 // Add the inc/dec to the real part.
 NextVal = Builder.CreateAdd(InVal.first, NextVal, isInc ? "inc" : "dec");
   } else {
-QualType ElemTy = E->getType()->getAs()->getElementType();
+QualType ElemTy = E->getType()->castAs()->getElementType();
 llvm::APFloat FVal(getContext().getFloatTypeSemantics(ElemTy), 1);
 if (!isInc)
   FVal.changeSign();
@@ -2194,7 +2194,7 @@ static void setObjCGCLValueClass(const A
   

[PATCH] D66647: [clangd] DefineInline action apply logic with fully qualified names

2019-10-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp:196
+
+std::string Qualifier = printNamespaceScope(*ND->getDeclContext());
+if (auto Err = Replacements.add(

ilya-biryukov wrote:
> You would want to use `ND->printNestedNameSpecifier()` instead to avoid 
> printing inline namespaces:
> ```
> namespace std { inline namespace v1 { 
>  struct vector {};
> }}
> ```
> 
> ^-- I believe the current code would print `std::v1::` for `vector` and we 
> want `std::`.
> Could you add this example to tests too?
it is the opposite, `printNamespaceScope` skips anonymous and inline 
namespaces, whereas `printNestedNameSpecifier` also prints those. adding a test.



Comment at: clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp:226
+llvm::Expected
+renameParameters(const FunctionDecl *Dest, const FunctionDecl *Source) {
+  const SourceManager  = Dest->getASTContext().getSourceManager();

ilya-biryukov wrote:
> This does not rename any references to those parameters, right?
> E.g.
> ```
> template  void foo(T x);
> 
> template  void foo(U x) {}
> ```
> 
> would turn into
> ```
> template  void foo(T x);
> ```
> right?
yes that's right, just adding a unittest will address this later on


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66647



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


[PATCH] D68535: Fix loop unrolling initialization in the new pass manager

2019-10-07 Thread Alina Sbirlea via Phabricator via cfe-commits
asbirlea added a comment.

Maybe elaborate in the patch description what `determine when and how we will 
unroll loops.` means?
e.g.: 
"The default before and after this patch is for LoopUnroll to be enabled, and 
for it to use a cost model to determine whether to unroll the loop 
(`OnlyWhenForced = false`). Before this patch, disabling loop unroll would not 
run the LoopUnroll pass. After this patch, the LoopUnroll pass is being run, 
but it restricts unrolling to only the loops marked by a pragma 
(`OnlyWhenForced = true`).
In addition, this patch disables the UnrollAndJam pass when disabling 
unrolling."

Otherwise LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68535



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


[PATCH] D53768: Add VerboseOutputStream to CompilerInstance

2019-10-07 Thread Scott Linder via Phabricator via cfe-commits
scott.linder added a comment.

Ping


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

https://reviews.llvm.org/D53768



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


[PATCH] D68551: [clang-format] [NFC] Ensure clang-format is itself clang-formatted.

2019-10-07 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar accepted this revision.
mitchell-stellar added a comment.
This revision is now accepted and ready to land.

LGTM.

I agree that a system in place that either enforces clang-formatting on commit 
or after the fact would be ideal. Otherwise, I don't see a need to have to 
approve these NFC commits.


Repository:
  rC Clang

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

https://reviews.llvm.org/D68551



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


[PATCH] D66647: [clangd] DefineInline action apply logic with fully qualified names

2019-10-07 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 223620.
kadircet marked 9 inline comments as done.
kadircet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D66647

Files:
  clang-tools-extra/clangd/refactor/tweaks/DefineInline.cpp
  clang-tools-extra/clangd/unittests/TweakTesting.cpp
  clang-tools-extra/clangd/unittests/TweakTesting.h
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -25,6 +25,7 @@
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -103,7 +104,7 @@
   EXPECT_UNAVAILABLE(R"cpp(R"(multi )" ^"token " u8"str\ning")cpp"); // nonascii
   EXPECT_UNAVAILABLE(R"cpp(^R^"^(^multi )" "token " "str\ning")cpp"); // raw
   EXPECT_UNAVAILABLE(R"cpp(^"token\n" __FILE__)cpp"); // chunk is macro
-  EXPECT_UNAVAILABLE(R"cpp(^"a\r\n";)cpp"); // forbidden escape char
+  EXPECT_UNAVAILABLE(R"cpp(^"a\r\n";)cpp");   // forbidden escape char
 
   const char *Input = R"cpp(R"(multi
 token)" "\nst^ring\n" "literal")cpp";
@@ -814,6 +815,514 @@
   })cpp");
 }
 
+TEST_F(DefineInlineTest, TransformUsings) {
+  EXPECT_EQ(apply(R"cpp(
+  namespace a {
+  void bar();
+  namespace b {
+  void baz();
+  namespace c {
+  void aux();
+  }
+  }
+  }
+
+  void foo();
+  void f^oo() {
+using namespace a;
+
+using namespace b;
+using namespace a::b;
+
+using namespace c;
+using namespace b::c;
+using namespace a::b::c;
+
+using a::bar;
+
+using b::baz;
+using a::b::baz;
+
+using c::aux;
+using b::c::aux;
+using a::b::c::aux;
+
+namespace d = c;
+namespace d = b::c;
+  }
+  )cpp"),
+R"cpp(
+  namespace a {
+  void bar();
+  namespace b {
+  void baz();
+  namespace c {
+  void aux();
+  }
+  }
+  }
+
+  void foo(){
+using namespace a;
+
+using namespace a::b;
+using namespace a::b;
+
+using namespace a::b::c;
+using namespace a::b::c;
+using namespace a::b::c;
+
+using a::bar;
+
+using a::b::baz;
+using a::b::baz;
+
+using a::b::c::aux;
+using a::b::c::aux;
+using a::b::c::aux;
+
+namespace d = a::b::c;
+namespace d = a::b::c;
+  }
+  
+  )cpp");
+}
+
+TEST_F(DefineInlineTest, TransformDecls) {
+  EXPECT_EQ(apply(R"cpp(
+  void foo()/*Comment -_-*/  ;
+
+  void f^oo() {
+class Foo {
+public:
+  void foo();
+  int x;
+  static int y;
+};
+Foo::y = 0;
+
+enum En { Zero, One };
+En x = Zero;
+
+enum class EnClass { Zero, One };
+EnClass y = EnClass::Zero;
+
+template  class Bar {};
+Bar z;
+  }
+  )cpp"),
+R"cpp(
+  void foo()/*Comment -_-*/  {
+class Foo {
+public:
+  void foo();
+  int x;
+  static int y;
+};
+Foo::y = 0;
+
+enum En { Zero, One };
+En x = Zero;
+
+enum class EnClass { Zero, One };
+EnClass y = EnClass::Zero;
+
+template  class Bar {};
+Bar z;
+  }
+
+  
+  )cpp");
+}
+
+TEST_F(DefineInlineTest, TransformTemplDecls) {
+  EXPECT_EQ(apply(R"cpp(
+  namespace a {
+template  class Bar {
+public:
+  void bar();
+};
+template  T bar;
+template  void aux() {}
+  }
+
+  void foo()/*Comment -_-*/  ;
+
+  void f^oo() {
+using namespace a;
+bar>.bar();
+aux>();
+  }
+  )cpp"),
+R"cpp(
+  namespace a {
+template  class Bar {
+public:
+  void bar();
+};
+template  T bar;
+template  void aux() {}
+  }
+
+  void foo()/*Comment -_-*/  {
+using namespace a;
+a::bar>.bar();
+a::aux>();
+  }
+
+  
+  )cpp");
+}
+
+MATCHER_P2(FileWithContents, FileName, Contents, "") {
+  return arg.first() == FileName && arg.second == Contents;
+}
+
+TEST_F(DefineInlineTest, TransformMembers) {
+  EXPECT_EQ(apply(R"cpp(
+  class Foo {
+void foo()/*Comment -_-*/  ;
+  };
+
+  void Foo::f^oo() {
+return;
+  }
+  )cpp"),
+R"cpp(
+  class Foo {
+void foo()/*Comment -_-*/  {
+return;
+  }
+  };
+
+  
+  )cpp");
+
+  ExtraFiles["a.h"] = R"cpp(
+  class Foo {
+void foo()/*Comment -_-*/  ;
+  };)cpp";
+
+  llvm::StringMap EditedFiles;
+  EXPECT_EQ(apply(R"cpp(
+  #include "a.h"
+  void Foo::f^oo() {
+return;
+  })cpp",
+  ),
+R"cpp(
+  #include "a.h"
+  )cpp");
+  EXPECT_THAT(EditedFiles,
+  testing::ElementsAre(FileWithContents(testPath("a.h"),
+R"cpp(
+  class Foo {
+void foo()/*Comment -_-*/  {
+return;
+  }
+  

[PATCH] D67161: [clang,ARM] Initial ACLE intrinsics for MVE.

2019-10-07 Thread Dave Green via Phabricator via cfe-commits
dmgreen added subscribers: samparker, SjoerdMeijer.
dmgreen added a comment.

This is looking good to me. My understanding is that is has some dependencies? 
The llvm side will likely needed to go in first, plus a couple of clang patches?




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:8529
   "argument should be a multiple of %0">;
+def err_argument_not_power_of_2 : Error<
+  "argument should be a power of 2">;

simon_tatham wrote:
> dmgreen wrote:
> > Do we have any/should we have some tests for these errors?
> By the time we finish implementing all the intrinsics, there will be tests 
> for these errors. The intrinsics that need them aren't in this preliminary 
> commit, though.
OK. That's fair.



Comment at: clang/test/CodeGen/arm-mve-intrinsics/scalar-shifts.c:2
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang --target=arm-arm-none-eabi -march=armv8.1m.main+mve.fp 
-mfloat-abi=hard -O3 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang --target=arm-arm-none-eabi -march=armv8.1m.main+mve.fp 
-mfloat-abi=hard -DPOLYMORPHIC -O3 -S -emit-llvm -o - %s | FileCheck %s

simon_tatham wrote:
> dmgreen wrote:
> > These tests all run -O3, the entire pass pipeline. I see quite a few tests 
> > in the same folder do the same thing, but in this case we will be adding 
> > quite a few tests. Random mid-end optimizations may well keep on altering 
> > them.
> > 
> > Is it possible to use -disable-O0-optnone and pipe them into opt -mem2reg? 
> > What would that do to the codegen, would it be a lot more verbose than it 
> > is now?
> > 
> > Also could/should they be using clang_cc1?
> The immediate problem is that if you use any form of `clang | opt | 
> FileCheck` command line, then `update_cc_test_checks.py` says 'skipping 
> non-FileChecked line', because it doesn't support anything more complicated 
> than a two-stage pipeline consisting of clang and FileCheck.
> 
> I've enhanced `update_cc_test_checks` to handle that case, in D68406, and 
> respun these tests accordingly. But if that patch doesn't get approval then 
> I'll have to rethink this again.
> 
> (For `vld24.c` I ended up running `opt -sroa -early-cse` to avoid the IR 
> becoming noticeably more verbose. The rest worked fine with just `mem2reg`, 
> though.)
> 
> 
> Patching `update_cc_test_checks.py` to support more complex pipelines, it 
> seems to work OK: most codegen changes are trivial ones, such as modifiers 
> not appearing on IR operations (`call` instead of `tail call`, plain `shl` in 
> place of `shl nuw`). Only `vld24` becomes significantly more complicated: for 
> that one file I had to run `opt -mem2reg -sroa -early-cse` instead.
Yeah, they look OK. Thanks for making the change. It looks like a useful 
feature being added.



Comment at: clang/test/CodeGen/arm-mve-intrinsics/vcvt.c:13
+{
+return vcvttq_f16_f32(a, b);
+}

Tests for bottom too would be good to see too. In general, more tests are 
better.



Comment at: clang/test/CodeGen/arm-mve-intrinsics/vcvt.c:20
+// CHECK-NEXT:[[TMP1:%.*]] = call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 
[[TMP0]])
+// CHECK-NEXT:[[TMP2:%.*]] = call <8 x half> 
@llvm.arm.mve.fltnarrow.predicated(<8 x half> [[A:%.*]], <4 x float> [[B:%.*]], 
i32 1, <4 x i1> [[TMP1]])
+// CHECK-NEXT:ret <8 x half> [[TMP2]]

Are these tests still using old names? I'm not missing something about how 
these are generated, am I?



Comment at: clang/utils/TableGen/MveEmitter.cpp:132
+// the pointee type.
+Pointer,
+  };

simon_tatham wrote:
> dmgreen wrote:
> > The gathers are really a Vector of Pointers, in a way. But in the 
> > intrinsics (and IR), they are just treated as a vector of ints, so I 
> > presume a new type is not needed? We may (but not yet) want to make use of 
> > the llvm masked gathers. We would have to add codegen support for them 
> > first though (which I don't think we have plans for in the near term).
> Yes, I'm working so far on the assumption that we don't need to represent 
> scatter/gather address vectors as a special vector-of-pointers type.
> 
> (If nothing else, it would be a bit strange for the 64-bit versions, where 
> the vector element isn't even the same //size// as a pointer.)
> 
> If auto-generation of gather loads during vectorization turns out to need a 
> special representation, then I suppose we'll have to rethink.
Sounds good.



Comment at: clang/utils/TableGen/MveEmitter.cpp:207
+// pointer, especially if the pointee is also const.
+if (isa(Pointee)) {
+  if (Const)

simon_tatham wrote:
> dmgreen wrote:
> > Would making this always east const be simpler? Do we generate anything 
> > with inner pointer types? Should there be a whitespace before the "const " 
> > in Name += "const "?
> There 

[PATCH] D68481: [clang-format] [PR27004] omits leading space for noexcept when formatting operator delete()

2019-10-07 Thread Mitchell via Phabricator via cfe-commits
mitchell-stellar accepted this revision.
mitchell-stellar added a comment.
This revision is now accepted and ready to land.

LGTM


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

https://reviews.llvm.org/D68481



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


[PATCH] D67536: [WIP] [clangd] Add support for an inactive regions notification

2019-10-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D67536#1697696 , @nridge wrote:

> One thing that may be worth considering as well, is that if the client 
> prefers to highlight the text of the line only, it can calculate the length 
> of the line itself. In VSCode for instance, the line lengths are readily 
> available; I imagine other editors are similar since they need that 
> information for many purposes.


So I don't think clients will/should prefer that - for best rendering they 
should know this is a line highlight.

I think this comes down to how line highlights are represented in the protocol:

- by a separate field: no need to send line length
- by a special token bounds (e.g. [0,0)): no need to send line length
- by a special scope: sending line length is a nice-to-have as it provides 
graceful degradation for clients that don't understand this extension




Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:152
+  // Don't bother computing the offset for the end of the line, just 
use
+  // zero. The client will treat this highlighting kind specially, and
+  // highlight the entire line visually (i.e. not just to where the 
text

hokein wrote:
> sammccall wrote:
> > nridge wrote:
> > > hokein wrote:
> > > > This seems too couple with VSCode client, I would prefer to calculate 
> > > > the range of the line and return to the client.
> > > > 
> > > > Is there any big differences in VSCode between highlighting with the 
> > > > `isWholeLine` and highlighting with the range of the line? 
> > > I took some screenshots to illustrate to difference.
> > > 
> > > Highlighting only to the end of the line of text:
> > > 
> > > {F10158508}
> > > 
> > > Highlighting the whole line:
> > > 
> > > {F10158515}
> > > 
> > > I think the first one looks pretty bad, and is inconsistent with existing 
> > > practice.
> > > 
> > > Note also that the suggestion is not to special-case the VSCode client 
> > > specifically; it's to special-case one particular highlighting, which any 
> > > client can implement.
> > > 
> > > If this special-casing is really unpalatable, we could instead try this 
> > > suggestion by @sammccall:
> > > 
> > > > Failing that, I'd suggest encoding a list of line-styles on 
> > > > SemanticHighlightingInformation, that should be combined with any 
> > > > tokens on that line.
> > > 
> > > I guess one consideration when evaluating these options is, do we expect 
> > > to use that "list of line-styles" for anything else in the future? I 
> > > can't think of anything at the moment, but perhaps there are other uses 
> > > for it.
> > > 
> > > If not, we could do something slightly simpler, and add a single 
> > > `isInactive` flag to `SemanticHighlightingInformation`.
> > Three approaches seem feasible here:
> > 1. clients that know about the specific scope can extend it to the whole 
> > line. 
> > 2. [0,0) or so indicates "highlight the whole line"
> > 3. use a dedicated property for line styles (vs token styles)
> > 
> > 3 is clearly better than 2 I think, it's more explicit. I don't have a 
> > strong opinion of 1 vs 3, but if going with 1 I think it's a good idea to 
> > measure the line as Haojian says, so we at least get a basic version of the 
> > feature if the client doesn't know about line styles.
> > 
> > > I guess one consideration when evaluating these options is, do we expect 
> > > to use that "list of line-styles" for anything else in the future? I 
> > > can't think of anything at the moment
> > Preprocessor directives maybe? (Though these are easy enough for clients to 
> > highlight with regex)
> I can't say whether highlighting the line is better than highlighting the 
> range of the line text, but below is the how the inactive TS code is 
> highlighted in VSCode (only the range of text), I personally prefer this 
> style.
> 
> {F10189885}
I think that's an argument for making sure clients clearly distinguish between 
regular tokens and marking lines: overlapping tokens don't compose well, but we 
can easily say lines and token styles should compose.

(That particular style is not for me, but it doesn't matter)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67536



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


r373916 - [libTooling] Add `toString` method to the Stencil class

2019-10-07 Thread Yitzhak Mandelbaum via cfe-commits
Author: ymandel
Date: Mon Oct  7 09:20:22 2019
New Revision: 373916

URL: http://llvm.org/viewvc/llvm-project?rev=373916=rev
Log:
[libTooling] Add `toString` method to the Stencil class

Summary:
`toString` generates a string representation of the stencil.

Patch by Harshal T. Lehri.

Reviewers: gribozavr

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h
cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp
cfe/trunk/unittests/Tooling/StencilTest.cpp

Modified: cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h?rev=373916=373915=373916=diff
==
--- cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h (original)
+++ cfe/trunk/include/clang/Tooling/Refactoring/Stencil.h Mon Oct  7 09:20:22 
2019
@@ -50,6 +50,11 @@ public:
 
   virtual bool isEqual(const StencilPartInterface ) const = 0;
 
+  /// Constructs a string representation of the StencilPart. StencilParts
+  /// generated by the `selection` and `run` functions do not have a unique
+  /// string representation.
+  virtual std::string toString() const = 0;
+
   const void *typeId() const { return TypeId; }
 
 protected:
@@ -86,6 +91,12 @@ public:
 return Impl->isEqual(*Other.Impl);
   }
 
+  std::string toString() const {
+if (Impl == nullptr)
+  return "";
+return Impl->toString();
+  }
+
 private:
   std::shared_ptr Impl;
 };
@@ -120,6 +131,16 @@ public:
 return eval(Result);
   }
 
+  /// Constructs a string representation of the Stencil. The string is not
+  /// guaranteed to be unique.
+  std::string toString() const {
+std::vector PartStrings;
+PartStrings.reserve(Parts.size());
+for (const auto  : Parts)
+  PartStrings.push_back(Part.toString());
+return llvm::join(PartStrings, ", ");
+  }
+
 private:
   friend bool operator==(const Stencil , const Stencil );
   static StencilPart wrap(llvm::StringRef Text);

Modified: cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp?rev=373916=373915=373916=diff
==
--- cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp (original)
+++ cfe/trunk/lib/Tooling/Refactoring/Stencil.cpp Mon Oct  7 09:20:22 2019
@@ -15,6 +15,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Refactoring/SourceCode.h"
 #include "clang/Tooling/Refactoring/SourceCodeBuilders.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/Errc.h"
 #include 
 #include 
@@ -128,6 +129,54 @@ bool isEqualData(const MatchConsumer &) {
+  return "MatchConsumer()";
+}
+
 // The `evalData()` overloads evaluate the given stencil data to a string, 
given
 // the match result, and append it to `Result`. We define an overload for each
 // type of stencil data.
@@ -247,6 +296,8 @@ public:
   return isEqualData(Data, OtherPtr->Data);
 return false;
   }
+
+  std::string toString() const override { return toStringData(Data); }
 };
 } // namespace
 

Modified: cfe/trunk/unittests/Tooling/StencilTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/StencilTest.cpp?rev=373916=373915=373916=diff
==
--- cfe/trunk/unittests/Tooling/StencilTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/StencilTest.cpp Mon Oct  7 09:20:22 2019
@@ -389,4 +389,59 @@ TEST(StencilEqualityTest, InEqualityRun)
   auto S2 = cat(run(F));
   EXPECT_NE(S1, S2);
 }
+
+TEST(StencilToStringTest, RawTextOp) {
+  auto S = cat("foo bar baz");
+  EXPECT_EQ(S.toString(), R"("foo bar baz")");
+}
+
+TEST(StencilToStringTest, RawTextOpEscaping) {
+  auto S = cat("foo \"bar\" baz\\n");
+  EXPECT_EQ(S.toString(), R"("foo \"bar\" baz\\n")");
+}
+
+TEST(StencilToStringTest, DebugPrintNodeOp) {
+  auto S = cat(dPrint("Id"));
+  EXPECT_EQ(S.toString(), R"repr(dPrint("Id"))repr");
+}
+
+TEST(StencilToStringTest, ExpressionOp) {
+  auto S = cat(expression("Id"));
+  EXPECT_EQ(S.toString(), R"repr(expression("Id"))repr");
+}
+
+TEST(StencilToStringTest, DerefOp) {
+  auto S = cat(deref("Id"));
+  EXPECT_EQ(S.toString(), R"repr(deref("Id"))repr");
+}
+
+TEST(StencilToStringTest, AddressOfOp) {
+  auto S = cat(addressOf("Id"));
+  EXPECT_EQ(S.toString(), R"repr(addressOf("Id"))repr");
+}
+
+TEST(StencilToStringTest, AccessOp) {
+  auto S = cat(access("Id", text("memberData")));
+  EXPECT_EQ(S.toString(), R"repr(access("Id", "memberData"))repr");
+}
+
+TEST(StencilToStringTest, AccessOpStencilPart) {
+  auto S = cat(access("Id", access("subId", "memberData")));
+  EXPECT_EQ(S.toString(),
+R"repr(access("Id", access("subId", "memberData")))repr");
+}
+
+TEST(StencilToStringTest, IfBoundOp) {
+  auto S = 

[PATCH] D68578: [HIP] Fix device stub name

2019-10-07 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Could you elaborate on how exactly current implementation does not work?

I would expect the kernel and the stub to be two distinct entities, as far as 
debugger is concerned. It does have enough information to track each 
independently (different address, .stub suffix, perhaps knowledge whether it's 
device or host code). Without the details, it looks to me that this is 
something that can and should be dealt with in the debugger. I've asked the 
same question in D63335  but I don't think 
I've got a good answer.


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

https://reviews.llvm.org/D68578



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


[PATCH] D68574: [libTooling] Add `toString` method to the Stencil class

2019-10-07 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 223619.
ymandel added a comment.

fix comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68574

Files:
  clang/include/clang/Tooling/Refactoring/Stencil.h
  clang/lib/Tooling/Refactoring/Stencil.cpp
  clang/unittests/Tooling/StencilTest.cpp

Index: clang/unittests/Tooling/StencilTest.cpp
===
--- clang/unittests/Tooling/StencilTest.cpp
+++ clang/unittests/Tooling/StencilTest.cpp
@@ -389,4 +389,59 @@
   auto S2 = cat(run(F));
   EXPECT_NE(S1, S2);
 }
+
+TEST(StencilToStringTest, RawTextOp) {
+  auto S = cat("foo bar baz");
+  EXPECT_EQ(S.toString(), R"("foo bar baz")");
+}
+
+TEST(StencilToStringTest, RawTextOpEscaping) {
+  auto S = cat("foo \"bar\" baz\\n");
+  EXPECT_EQ(S.toString(), R"("foo \"bar\" baz\\n")");
+}
+
+TEST(StencilToStringTest, DebugPrintNodeOp) {
+  auto S = cat(dPrint("Id"));
+  EXPECT_EQ(S.toString(), R"repr(dPrint("Id"))repr");
+}
+
+TEST(StencilToStringTest, ExpressionOp) {
+  auto S = cat(expression("Id"));
+  EXPECT_EQ(S.toString(), R"repr(expression("Id"))repr");
+}
+
+TEST(StencilToStringTest, DerefOp) {
+  auto S = cat(deref("Id"));
+  EXPECT_EQ(S.toString(), R"repr(deref("Id"))repr");
+}
+
+TEST(StencilToStringTest, AddressOfOp) {
+  auto S = cat(addressOf("Id"));
+  EXPECT_EQ(S.toString(), R"repr(addressOf("Id"))repr");
+}
+
+TEST(StencilToStringTest, AccessOp) {
+  auto S = cat(access("Id", text("memberData")));
+  EXPECT_EQ(S.toString(), R"repr(access("Id", "memberData"))repr");
+}
+
+TEST(StencilToStringTest, AccessOpStencilPart) {
+  auto S = cat(access("Id", access("subId", "memberData")));
+  EXPECT_EQ(S.toString(),
+R"repr(access("Id", access("subId", "memberData")))repr");
+}
+
+TEST(StencilToStringTest, IfBoundOp) {
+  auto S = cat(ifBound("Id", text("trueText"), access("exprId", "memberData")));
+  EXPECT_EQ(
+  S.toString(),
+  R"repr(ifBound("Id", "trueText", access("exprId", "memberData")))repr");
+}
+
+TEST(StencilToStringTest, MultipleOp) {
+  auto S = cat("foo", access("x", "m()"), "bar",
+   ifBound("x", text("t"), access("e", "f")));
+  EXPECT_EQ(S.toString(), R"repr("foo", access("x", "m()"), "bar", )repr"
+  R"repr(ifBound("x", "t", access("e", "f")))repr");
+}
 } // namespace
Index: clang/lib/Tooling/Refactoring/Stencil.cpp
===
--- clang/lib/Tooling/Refactoring/Stencil.cpp
+++ clang/lib/Tooling/Refactoring/Stencil.cpp
@@ -15,6 +15,7 @@
 #include "clang/Lex/Lexer.h"
 #include "clang/Tooling/Refactoring/SourceCode.h"
 #include "clang/Tooling/Refactoring/SourceCodeBuilders.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/Support/Errc.h"
 #include 
 #include 
@@ -128,6 +129,54 @@
   return false;
 }
 
+std::string toStringData(const RawTextData ) {
+  std::string Result;
+  llvm::raw_string_ostream OS(Result);
+  OS << "\"";
+  OS.write_escaped(Data.Text);
+  OS << "\"";
+  OS.flush();
+  return Result;
+}
+
+std::string toStringData(const DebugPrintNodeData ) {
+  return (llvm::Twine("dPrint(\"") + Data.Id + "\")").str();
+}
+
+std::string toStringData(const UnaryOperationData ) {
+  StringRef OpName;
+  switch (Data.Op) {
+  case UnaryNodeOperator::Parens:
+OpName = "expression";
+break;
+  case UnaryNodeOperator::Deref:
+OpName = "deref";
+break;
+  case UnaryNodeOperator::Address:
+OpName = "addressOf";
+break;
+  }
+  return (OpName + "(\"" + Data.Id + "\")").str();
+}
+
+std::string toStringData(const SelectorData &) { return "SelectorData()"; }
+
+std::string toStringData(const AccessData ) {
+  return (llvm::Twine("access(\"") + Data.BaseId + "\", " +
+  Data.Member.toString() + ")")
+  .str();
+}
+
+std::string toStringData(const IfBoundData ) {
+  return (llvm::Twine("ifBound(\"") + Data.Id + "\", " +
+  Data.TruePart.toString() + ", " + Data.FalsePart.toString() + ")")
+  .str();
+}
+
+std::string toStringData(const MatchConsumer &) {
+  return "MatchConsumer()";
+}
+
 // The `evalData()` overloads evaluate the given stencil data to a string, given
 // the match result, and append it to `Result`. We define an overload for each
 // type of stencil data.
@@ -247,6 +296,8 @@
   return isEqualData(Data, OtherPtr->Data);
 return false;
   }
+
+  std::string toString() const override { return toStringData(Data); }
 };
 } // namespace
 
Index: clang/include/clang/Tooling/Refactoring/Stencil.h
===
--- clang/include/clang/Tooling/Refactoring/Stencil.h
+++ clang/include/clang/Tooling/Refactoring/Stencil.h
@@ -50,6 +50,11 @@
 
   virtual bool isEqual(const StencilPartInterface ) const = 0;
 
+  /// Constructs a string representation of the StencilPart. StencilParts
+  /// generated by the `selection` and `run` functions do not have a 

[PATCH] D68526: [Diagnostics] Silence -Wsizeof-array-div for character buffers

2019-10-07 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

@tkanis wrote in post commit review:

“What do you think about also not emitting the warning if the lhs sizeof is an 
array of signed or unsigned char? The warning wants the rhs sizeof to be 
sizeof(char) which is 1, and dividing by that doesn't really make sense. ”

I agree with him. I think you can land this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68526



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


[PATCH] D68584: Fix Calling Convention through aliases

2019-10-07 Thread Erich Keane via Phabricator via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: rnk, pcc.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

r369697 changed the behavior of stripPointerCasts to no longer include
aliases.  However, the code in CGDeclCXX.cpp's createAtExitStub counted
on the looking through aliases to properly set the calling convention of
a call.

  

The result of the change was that the calling convention mismatch of the
call would be replaced with a llvm.trap, causing a runtime crash.


https://reviews.llvm.org/D68584

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/test/CodeGenCXX/call-conv-thru-alias.cpp
  llvm/include/llvm/IR/Value.h
  llvm/lib/IR/Value.cpp

Index: llvm/lib/IR/Value.cpp
===
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -455,6 +455,7 @@
 // Various metrics for how much to strip off of pointers.
 enum PointerStripKind {
   PSK_ZeroIndices,
+  PSK_ZeroIndicesAndAliases,
   PSK_ZeroIndicesSameRepresentation,
   PSK_ZeroIndicesAndInvariantGroups,
   PSK_InBoundsConstantIndices,
@@ -475,6 +476,7 @@
 if (auto *GEP = dyn_cast(V)) {
   switch (StripKind) {
   case PSK_ZeroIndices:
+  case PSK_ZeroIndicesAndAliases:
   case PSK_ZeroIndicesSameRepresentation:
   case PSK_ZeroIndicesAndInvariantGroups:
 if (!GEP->hasAllZeroIndices())
@@ -497,6 +499,8 @@
   // TODO: If we know an address space cast will not change the
   //   representation we could look through it here as well.
   V = cast(V)->getOperand(0);
+} else if (StripKind == PSK_ZeroIndicesAndAliases && isa(V)) {
+  V = cast(V)->getAliasee();
 } else {
   if (const auto *Call = dyn_cast(V)) {
 if (const Value *RV = Call->getReturnedArgOperand()) {
@@ -526,6 +530,10 @@
   return stripPointerCastsAndOffsets(this);
 }
 
+const Value *Value::stripPointerCastsAndAliases() const {
+  return stripPointerCastsAndOffsets(this);
+}
+
 const Value *Value::stripPointerCastsSameRepresentation() const {
   return stripPointerCastsAndOffsets(this);
 }
Index: llvm/include/llvm/IR/Value.h
===
--- llvm/include/llvm/IR/Value.h
+++ llvm/include/llvm/IR/Value.h
@@ -523,6 +523,16 @@
 static_cast(this)->stripPointerCasts());
   }
 
+  /// Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
+  ///
+  /// Returns the original uncasted value.  If this is called on a non-pointer
+  /// value, it returns 'this'.
+  const Value *stripPointerCastsAndAliases() const;
+  Value *stripPointerCastsAndAliases() {
+return const_cast(
+static_cast(this)->stripPointerCastsAndAliases());
+  }
+
   /// Strip off pointer casts, all-zero GEPs and address space casts
   /// but ensures the representation of the result stays the same.
   ///
Index: clang/test/CodeGenCXX/call-conv-thru-alias.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/call-conv-thru-alias.cpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple i686-windows-pc -emit-llvm -o - -mconstructor-aliases -O1 -disable-llvm-passes %s | FileCheck %s
+
+struct Base { virtual ~Base(); };
+struct Derived : Base {
+  virtual ~Derived();
+  static Derived inst;
+};
+
+Base::~Base(){}
+Derived::~Derived(){}
+Derived Derived::inst;
+
+// CHECK: @"??1Derived@@UAE@XZ" = dso_local unnamed_addr alias void (%struct.Derived*), bitcast (void (%struct.Base*)* @"??1Base@@UAE@XZ" to void (%struct.Derived*)*)
+
+// CHECK: define dso_local x86_thiscallcc void @"??1Base@@UAE@XZ"
+// CHECK: define internal void @"??__E?inst@Derived@@2U1@A@@YAXXZ"
+// CHECK: call i32 @atexit(void ()* @"??__F?inst@Derived@@2U1@A@@YAXXZ"
+//
+// CHECK: define internal void @"??__F?inst@Derived@@2U1@A@@YAXXZ"
+// CHECK-NEXT: entry:
+// CHECK-NEXT: call x86_thiscallcc void @"??1Derived@@UAE@XZ"
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -248,8 +248,8 @@
   llvm::CallInst *call = CGF.Builder.CreateCall(dtor, addr);
 
  // Make sure the call and the callee agree on calling convention.
-  if (llvm::Function *dtorFn =
-  dyn_cast(dtor.getCallee()->stripPointerCasts()))
+  if (llvm::Function *dtorFn = dyn_cast(
+  dtor.getCallee()->stripPointerCastsAndAliases()))
 call->setCallingConv(dtorFn->getCallingConv());
 
   CGF.FinishFunction();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68574: [libTooling] Add `toString` method to the Stencil class

2019-10-07 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr accepted this revision.
gribozavr added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Tooling/Refactoring/Stencil.h:54
+  /// Constructs a string representation of the StencilPart. StencilParts
+  /// generated by the `selection` and `run `functions do not have a unique
+  /// string representation.

No space between "run" and backtick.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68574



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


Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-07 Thread Dávid Bolvanský via cfe-commits
Typo was fixed some days ago :)

Odoslané z iPhonu

> Dňa 7. 10. 2019 o 17:22 užívateľ Arthur O'Dwyer  
> napísal:
> 
> 
>> On Mon, Oct 7, 2019 at 10:59 AM Dávid Bolvanský via cfe-commits 
>>  wrote:
> 
>> Okey, I will see what I can do (I know I need to move checking code 
>> somewhere else).
>> 
>> > Dňa 7. 10. 2019 o 16:54 užívateľ Nico Weber  napísal:
>> > FWIW I found the "always evaluates to 'true'" bit important to understand 
>> > the warning.
> 
> +1, I think "always evaluates to true" is useful, especially for people who 
> don't immediately intuit the difference between "bitwise negation" and 
> "logical negation." (Although the fixit will help clear up the difference.)
> 
> Also, Dávid, you misspelled "logical" as "logicial" in the patch I saw. So 
> you might need to push a fix for that typo, unless you already caught it.
> My suggested message follows—
> 
> -  "bitwise negation of a boolean expression; did you mean a logicial 
> negation?">,
> +  "bitwise negation of a boolean expression is always true; did you mean 
> logical negation?">,
> 
> my $.02,
> –Arthur
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68581: Include leading attributes in DeclStmt's SourceRange

2019-10-07 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg created this revision.
sberg added reviewers: aaron.ballman, rsmith, Nathan-Huckleberry.
Herald added a project: clang.

For a `DeclStmt` like

  [[maybe_unused]] int i;

`getBeginLoc()` returned the start of `int` instead of the start of `[[` (see 
http://lists.llvm.org/pipermail/cfe-dev/2019-September/063434.html "[cfe-dev] 
Poor DeclStmt source range with leading [[attributes]]?").

Is there a good way to write a test for this?


Repository:
  rC Clang

https://reviews.llvm.org/D68581

Files:
  clang/lib/Parse/ParseStmt.cpp


Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -220,6 +220,8 @@
 Decl =
 ParseDeclaration(DeclaratorContext::BlockContext, DeclEnd, Attrs);
   }
+  if (Attrs.Range.getBegin().isValid())
+  DeclStart = Attrs.Range.getBegin();
   return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd);
 }
 


Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -220,6 +220,8 @@
 Decl =
 ParseDeclaration(DeclaratorContext::BlockContext, DeclEnd, Attrs);
   }
+  if (Attrs.Range.getBegin().isValid())
+  DeclStart = Attrs.Range.getBegin();
   return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D68562: [clangd] Add RemoveUsingNamespace tweak.

2019-10-07 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp:86
+  if (const Decl *ParentDecl = Node->Parent->ASTNode.get()) {
+return llvm::isa(ParentDecl);
+  }

NIT: remove redundant `{}`  around this `return`



Comment at: clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp:99
+return false;
+  if (!dyn_cast(TargetDirective->getDeclContext()))
+return false;

I believe this check is redundant in presence of `isTopLevelDecl()`...
(It used to check the 'using namespace' is not inside a function body)



Comment at: 
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp:121
+  for (auto *T : Ref.Targets) {
+// FIXME: handle inline namespaces, unscoped enumerators.
+if (T->getDeclContext() != TargetDirective->getNominatedNamespace())

Could you take a look at handling these?

Also happy if we make it a separate change, but we shouldn't delay this.
Both are important cases.

The examples should roughly be:
```
namespace std {
inline namespace v1 {
  struct vector {};
}
}

using namespace std;
vector v;
```

and
```
namespace tokens {
enum Token {
  comma, identifier, numeric
};
}

using namespace tokens;
auto x = comma; 
```



Comment at: 
clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp:163
+std::string RemoveUsingNamespace::title() const {
+  return llvm::formatv("Remove using namespace, add qualifiers instead");
+}

NIT: could you rephrase as `re-qualify names instead`
"add qualifiers" confuses some people, this can be read as "add a const 
qualifier"



Comment at: clang-tools-extra/clangd/unittests/TweakTests.cpp:781
+namespace bb { struct map {}; }
+using namespace bb; // Qualifies this.
+  }

Argh, this should definitely be fixed :-(
One simple way to handle this particular only qualify references, which come 
**after** the first `using namespace` we are removing.

There's a `SourceManager::isBeforeInTranslationUnit` function that can be used 
to find out whether something is written before or after a particular point.

This won't fix all of the cases, but fixing in the general case seems hard.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68562



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


[PATCH] D67536: [WIP] [clangd] Add support for an inactive regions notification

2019-10-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

One thing that may be worth considering as well, is that if the client prefers 
to highlight the text of the line only, it can calculate the length of the line 
itself. In VSCode for instance, the line lengths are readily available; I 
imagine other editors are similar since they need that information for many 
purposes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67536



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


Re: r371605 - [Diagnostics] Add -Wsizeof-array-div

2019-10-07 Thread Dávid Bolvanský via cfe-commits
D68526 should fix it. Take a look please.


> Dňa 7. 10. 2019 o 17:09 užívateľ Nico Weber  napísal:
> 
> 
> I gave this another try now that we have a compiler with rL372600. Another 
> thing the warning currently warns on is code like this:
> 
>   char memory[kOpcodeMemory];
>   OpcodeFactory opcode_maker(memory, sizeof(memory));
>   size_t count = sizeof(memory) / sizeof(PolicyOpcode);
> 
> or
> 
>   int32_t fds[sizeof(buffer->data) / sizeof(int32_t)], i, count;
>   size_t size;
> 
> (the latter from wayland).
> 
> What do you think about also not emitting the warning if the lhs sizeof is an 
> array of signed or unsigned char? The warning wants the rhs sizeof to be 
> sizeof(char) which is 1, and dividing by that doesn't really make sense. So 
> this might be a change that improves false negative rate while probably not 
> hurting true positive rate.
> 
>> On Mon, Sep 23, 2019 at 9:11 AM Dávid Bolvanský  
>> wrote:
>> Yeah, this needs to be handled a bit differently (if we want so).
>> 
>> po 23. 9. 2019 o 15:07 Nico Weber  napísal(a):
>>> It still warns if the inner array is in a struct. That's probably ok though.
>>> 
>>> struct Point {
>>>   int xy[2];
>>> };
>>> 
>>> void f() {
>>>   Point points[3];
>>>   for (int i = 0; i < sizeof(points) / sizeof(int); ++i)
>>> ([0].xy[0])[i] = 0;
>>> }
>>> 
 On Mon, Sep 23, 2019 at 8:54 AM Nico Weber  wrote:
 That was fast. Thanks much! :)
 
> On Mon, Sep 23, 2019 at 8:52 AM Dávid Bolvanský 
>  wrote:
> Hello,
> 
> Thanks for the proposed idea, implemented in rL372600.
> 
> po 23. 9. 2019 o 14:23 Nico Weber  napísal(a):
>> We're looking at turning this one.
>> 
>> One thing that this warns about that's a false positive where we've seen 
>> it is this code for nested arrays:
>> 
>>   float m[4][4];
>>   for (int i = 0; i < sizeof(m) / sizeof(**m); ++i) (&**m)[i] = 0;
>> 
>> (Why would anyone write code like this? It's a reduced example; consider 
>> e.g. wanting to call std::generate_n() on all elements of a nested 
>> array.)
>> 
>> Can we make the warning not fire when dividing the size of a nested 
>> array by the size of the deepest base type?
>> 
>>> On Wed, Sep 11, 2019 at 6:58 AM David Bolvansky via cfe-commits 
>>>  wrote:
>>> Author: xbolva00
>>> Date: Wed Sep 11 03:59:47 2019
>>> New Revision: 371605
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=371605=rev
>>> Log:
>>> [Diagnostics] Add -Wsizeof-array-div
>>> 
>>> Summary: Clang version of https://www.viva64.com/en/examples/v706/
>>> 
>>> Reviewers: rsmith
>>> 
>>> Differential Revision: https://reviews.llvm.org/D67287
>>> 
>>> Added:
>>> cfe/trunk/test/Sema/div-sizeof-array.cpp
>>> Modified:
>>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> cfe/trunk/lib/Sema/SemaExpr.cpp
>>> 
>>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371605=371604=371605=diff
>>> ==
>>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 11 
>>> 03:59:47 2019
>>> @@ -3406,6 +3406,10 @@ def note_pointer_declared_here : Note<
>>>  def warn_division_sizeof_ptr : Warning<
>>>"'%0' will return the size of the pointer, not the array itself">,
>>>InGroup>;
>>> +def warn_division_sizeof_array : Warning<
>>> +  "expression does not compute the number of elements in this array; 
>>> element "
>>> +  "type is %0, not %1">,
>>> +  InGroup>;
>>> 
>>>  def note_function_warning_silence : Note<
>>>  "prefix with the address-of operator to silence this warning">;
>>> 
>>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>>> URL: 
>>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371605=371604=371605=diff
>>> ==
>>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 11 03:59:47 2019
>>> @@ -9158,17 +9158,28 @@ static void DiagnoseDivisionSizeofPointe
>>>else
>>>  RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
>>> 
>>> -  if (!LHSTy->isPointerType() || RHSTy->isPointerType())
>>> -return;
>>> -  if (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType() 
>>> !=
>>> -  RHSTy.getCanonicalType().getUnqualifiedType())
>>> -return;
>>> +  if (LHSTy->isPointerType() && !RHSTy->isPointerType()) {
>>> +if (!S.Context.hasSameUnqualifiedType(LHSTy->getPointeeType(), 
>>> RHSTy))
>>> +  return;
>>> 

Re: r371605 - [Diagnostics] Add -Wsizeof-array-div

2019-10-07 Thread Nico Weber via cfe-commits
I gave this another try now that we have a compiler with rL372600. Another
thing the warning currently warns on is code like this:

  char memory[kOpcodeMemory];
  OpcodeFactory opcode_maker(memory, sizeof(memory));
  size_t count = sizeof(memory) / sizeof(PolicyOpcode);

or

  int32_t fds[sizeof(buffer->data) / sizeof(int32_t)], i, count;
  size_t size;

(the latter from wayland).

What do you think about also not emitting the warning if the lhs sizeof is
an array of signed or unsigned char? The warning wants the rhs sizeof to be
sizeof(char) which is 1, and dividing by that doesn't really make sense. So
this might be a change that improves false negative rate while probably not
hurting true positive rate.

On Mon, Sep 23, 2019 at 9:11 AM Dávid Bolvanský 
wrote:

> Yeah, this needs to be handled a bit differently (if we want so).
>
> po 23. 9. 2019 o 15:07 Nico Weber  napísal(a):
>
>> It still warns if the inner array is in a struct. That's probably ok
>> though.
>>
>> struct Point {
>>   int xy[2];
>> };
>>
>> void f() {
>>   Point points[3];
>>   for (int i = 0; i < sizeof(points) / sizeof(int); ++i)
>> ([0].xy[0])[i] = 0;
>> }
>>
>> On Mon, Sep 23, 2019 at 8:54 AM Nico Weber  wrote:
>>
>>> That was fast. Thanks much! :)
>>>
>>> On Mon, Sep 23, 2019 at 8:52 AM Dávid Bolvanský <
>>> david.bolvan...@gmail.com> wrote:
>>>
 Hello,

 Thanks for the proposed idea, implemented in rL372600.

 po 23. 9. 2019 o 14:23 Nico Weber  napísal(a):

> We're looking at turning this one.
>
> One thing that this warns about that's a false positive where we've
> seen it is this code for nested arrays:
>
>   float m[4][4];
>   for (int i = 0; i < sizeof(m) / sizeof(**m); ++i) (&**m)[i] = 0;
>
> (Why would anyone write code like this? It's a reduced example;
> consider e.g. wanting to call std::generate_n() on all elements of a 
> nested
> array.)
>
> Can we make the warning not fire when dividing the size of a nested
> array by the size of the deepest base type?
>
> On Wed, Sep 11, 2019 at 6:58 AM David Bolvansky via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: xbolva00
>> Date: Wed Sep 11 03:59:47 2019
>> New Revision: 371605
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=371605=rev
>> Log:
>> [Diagnostics] Add -Wsizeof-array-div
>>
>> Summary: Clang version of https://www.viva64.com/en/examples/v706/
>>
>> Reviewers: rsmith
>>
>> Differential Revision: https://reviews.llvm.org/D67287
>>
>> Added:
>> cfe/trunk/test/Sema/div-sizeof-array.cpp
>> Modified:
>> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> cfe/trunk/lib/Sema/SemaExpr.cpp
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=371605=371604=371605=diff
>>
>> ==
>> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Sep 11
>> 03:59:47 2019
>> @@ -3406,6 +3406,10 @@ def note_pointer_declared_here : Note<
>>  def warn_division_sizeof_ptr : Warning<
>>"'%0' will return the size of the pointer, not the array itself">,
>>InGroup>;
>> +def warn_division_sizeof_array : Warning<
>> +  "expression does not compute the number of elements in this array;
>> element "
>> +  "type is %0, not %1">,
>> +  InGroup>;
>>
>>  def note_function_warning_silence : Note<
>>  "prefix with the address-of operator to silence this warning">;
>>
>> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=371605=371604=371605=diff
>>
>> ==
>> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Sep 11 03:59:47 2019
>> @@ -9158,17 +9158,28 @@ static void DiagnoseDivisionSizeofPointe
>>else
>>  RHSTy = RUE->getArgumentExpr()->IgnoreParens()->getType();
>>
>> -  if (!LHSTy->isPointerType() || RHSTy->isPointerType())
>> -return;
>> -  if
>> (LHSTy->getPointeeType().getCanonicalType().getUnqualifiedType() !=
>> -  RHSTy.getCanonicalType().getUnqualifiedType())
>> -return;
>> +  if (LHSTy->isPointerType() && !RHSTy->isPointerType()) {
>> +if (!S.Context.hasSameUnqualifiedType(LHSTy->getPointeeType(),
>> RHSTy))
>> +  return;
>>
>> -  S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS <<
>> LHS->getSourceRange();
>> -  if (const auto *DRE = dyn_cast(LHSArg)) {
>> -if (const ValueDecl *LHSArgDecl = 

[PATCH] D67536: [WIP] [clangd] Add support for an inactive regions notification

2019-10-07 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D67536#1697533 , @nridge wrote:

> How would one even measure the line length? `SourceManager` doesn't sem to 
> have a method like `getLineLength()` or similar.


Yes, there is no existing API for that, I think you'd need to get the source 
code from the SM at the specific offset, and do the `\n` counting.




Comment at: clang-tools-extra/clangd/ParsedAST.h:100
 
+  const std::vector () const {
+return SkippedRanges;

Instead of adding new member and methods in `ParsedAST`, I think we can do it 
in `CollectMainFileMacros` (adding a new field SkippRanges in 
`MainFileMacros`), then we can get the skipped ranges for preamble region 
within the main file for free.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.cpp:152
+  // Don't bother computing the offset for the end of the line, just 
use
+  // zero. The client will treat this highlighting kind specially, and
+  // highlight the entire line visually (i.e. not just to where the 
text

sammccall wrote:
> nridge wrote:
> > hokein wrote:
> > > This seems too couple with VSCode client, I would prefer to calculate the 
> > > range of the line and return to the client.
> > > 
> > > Is there any big differences in VSCode between highlighting with the 
> > > `isWholeLine` and highlighting with the range of the line? 
> > I took some screenshots to illustrate to difference.
> > 
> > Highlighting only to the end of the line of text:
> > 
> > {F10158508}
> > 
> > Highlighting the whole line:
> > 
> > {F10158515}
> > 
> > I think the first one looks pretty bad, and is inconsistent with existing 
> > practice.
> > 
> > Note also that the suggestion is not to special-case the VSCode client 
> > specifically; it's to special-case one particular highlighting, which any 
> > client can implement.
> > 
> > If this special-casing is really unpalatable, we could instead try this 
> > suggestion by @sammccall:
> > 
> > > Failing that, I'd suggest encoding a list of line-styles on 
> > > SemanticHighlightingInformation, that should be combined with any tokens 
> > > on that line.
> > 
> > I guess one consideration when evaluating these options is, do we expect to 
> > use that "list of line-styles" for anything else in the future? I can't 
> > think of anything at the moment, but perhaps there are other uses for it.
> > 
> > If not, we could do something slightly simpler, and add a single 
> > `isInactive` flag to `SemanticHighlightingInformation`.
> Three approaches seem feasible here:
> 1. clients that know about the specific scope can extend it to the whole 
> line. 
> 2. [0,0) or so indicates "highlight the whole line"
> 3. use a dedicated property for line styles (vs token styles)
> 
> 3 is clearly better than 2 I think, it's more explicit. I don't have a strong 
> opinion of 1 vs 3, but if going with 1 I think it's a good idea to measure 
> the line as Haojian says, so we at least get a basic version of the feature 
> if the client doesn't know about line styles.
> 
> > I guess one consideration when evaluating these options is, do we expect to 
> > use that "list of line-styles" for anything else in the future? I can't 
> > think of anything at the moment
> Preprocessor directives maybe? (Though these are easy enough for clients to 
> highlight with regex)
I can't say whether highlighting the line is better than highlighting the range 
of the line text, but below is the how the inactive TS code is highlighted in 
VSCode (only the range of text), I personally prefer this style.

{F10189885}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67536



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


[PATCH] D67536: [WIP] [clangd] Add support for an inactive regions notification

2019-10-07 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D67536#1697533 , @nridge wrote:

> How would one even measure the line length? `SourceManager` doesn't sem to 
> have a method like `getLineLength()` or similar.


If you look at functions like `offsetToPosition` in SourceCode.h, basically you 
get the buffer as a string (contains utf-8), find the offset you're interested 
in, and then zoom around looking for `\n`. Once you have a substring, calling 
`lspLength()` on it will give you the length in UTF-16 or whatever LSP is 
speaking at the moment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67536



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


Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-07 Thread Dávid Bolvanský via cfe-commits
Okey, I will see what I can do (I know I need to move checking code somewhere 
else).

> Dňa 7. 10. 2019 o 16:54 užívateľ Nico Weber  napísal:
> 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r373743 - [NFCI] Improve the -Wbool-operation's warning message

2019-10-07 Thread Nico Weber via cfe-commits
FWIW I found the "always evaluates to 'true'" bit important to understand
the warning.

We did hit this (at least once) in Chromium after all [1] (looks like a
real bug – nothing for you to do about that, and thanks for the warning),
and I don't think I would've understood what the warning wanted from me if
I hadn't seen the old warning text in the commit.

[1]: https://bugs.chromium.org/p/chromium/issues/detail?id=1011810

On Fri, Oct 4, 2019 at 8:53 AM David Bolvansky via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: xbolva00
> Date: Fri Oct  4 05:55:13 2019
> New Revision: 373743
>
> URL: http://llvm.org/viewvc/llvm-project?rev=373743=rev
> Log:
> [NFCI] Improve the -Wbool-operation's warning message
>
> Based on the request from the post commit review. Also added one new test.
>
>
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=373743=373742=373743=diff
>
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Oct  4
> 05:55:13 2019
> @@ -6638,7 +6638,7 @@ def note_member_declared_here : Note<
>  def note_member_first_declared_here : Note<
>"member %0 first declared here">;
>  def warn_bitwise_negation_bool : Warning<
> -  "bitwise negation of a boolean expression always evaluates to 'true'">,
> +  "bitwise negation of a boolean expression; did you mean a logicial
> negation?">,
>InGroup>;
>  def err_decrement_bool : Error<"cannot decrement expression of type
> bool">;
>  def warn_increment_bool : Warning<
>
> Modified: cfe/trunk/test/Sema/warn-bitwise-negation-bool.c
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-bitwise-negation-bool.c?rev=373743=373742=373743=diff
>
> ==
> --- cfe/trunk/test/Sema/warn-bitwise-negation-bool.c (original)
> +++ cfe/trunk/test/Sema/warn-bitwise-negation-bool.c Fri Oct  4 05:55:13
> 2019
> @@ -12,9 +12,11 @@ typedef _Bool boolean;
>  #endif
>
>  void test(boolean b, int i) {
> -  b = ~b; // expected-warning {{bitwise negation of a boolean expression
> always evaluates to 'true'}}
> +  b = ~b; // expected-warning {{bitwise negation of a boolean expression;
> did you mean a logicial negation?}}
>// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
> -  b = ~(b); // expected-warning {{bitwise negation of a boolean
> expression always evaluates to 'true'}}
> +  b = ~(b); // expected-warning {{bitwise negation of a boolean
> expression; did you mean a logicial negation?}}
>// CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
>b = ~i;
> +  i = ~b; // expected-warning {{bitwise negation of a boolean expression;
> did you mean a logicial negation?}}
> +  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:7-[[@LINE-1]]:8}:"!"
>  }
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D28213: [Frontend] Correct values of ATOMIC_*_LOCK_FREE to match builtin

2019-10-07 Thread James Y Knight via Phabricator via cfe-commits
jyknight reopened this revision.
jyknight added a comment.
This revision is now accepted and ready to land.

The close was due to phabricator problem, reopening.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D28213



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


r373911 - Sema - silence static analyzer getAs<> null dereference warnings. NFCI.

2019-10-07 Thread Simon Pilgrim via cfe-commits
Author: rksimon
Date: Mon Oct  7 07:25:46 2019
New Revision: 373911

URL: http://llvm.org/viewvc/llvm-project?rev=373911=rev
Log:
Sema - silence static analyzer getAs<> null dereference warnings. NFCI.

The static analyzer is warning about potential null dereferences, but in these 
cases we should be able to use castAs<> directly and if not assert will fire 
for us.

Modified:
cfe/trunk/lib/Sema/SemaAccess.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/lib/Sema/SemaCoroutine.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaAccess.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaAccess.cpp?rev=373911=373910=373911=diff
==
--- cfe/trunk/lib/Sema/SemaAccess.cpp (original)
+++ cfe/trunk/lib/Sema/SemaAccess.cpp Mon Oct  7 07:25:46 2019
@@ -1551,7 +1551,7 @@ Sema::AccessResult Sema::CheckUnresolved
 
   QualType BaseType = E->getBaseType();
   if (E->isArrow())
-BaseType = BaseType->getAs()->getPointeeType();
+BaseType = BaseType->castAs()->getPointeeType();
 
   AccessTarget Entity(Context, AccessTarget::Member, E->getNamingClass(),
   Found, BaseType);

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=373911=373910=373911=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Oct  7 07:25:46 2019
@@ -484,7 +484,7 @@ static bool checkOpenCLBlockArgs(Sema 
   const BlockPointerType *BPT =
   cast(BlockArg->getType().getCanonicalType());
   ArrayRef Params =
-  BPT->getPointeeType()->getAs()->getParamTypes();
+  BPT->getPointeeType()->castAs()->getParamTypes();
   unsigned ArgCounter = 0;
   bool IllegalParams = false;
   // Iterate through the block parameters until either one is found that is not
@@ -583,7 +583,7 @@ static bool checkOpenCLEnqueueVariadicAr
   const BlockPointerType *BPT =
   cast(BlockArg->getType().getCanonicalType());
   unsigned NumBlockParams =
-  BPT->getPointeeType()->getAs()->getNumParams();
+  BPT->getPointeeType()->castAs()->getNumParams();
   unsigned TotalNumArgs = TheCall->getNumArgs();
 
   // For each argument passed to the block, a corresponding uint needs to
@@ -676,7 +676,7 @@ static bool SemaOpenCLBuiltinEnqueueKern
 // we have a block type, check the prototype
 const BlockPointerType *BPT =
 cast(Arg3->getType().getCanonicalType());
-if (BPT->getPointeeType()->getAs()->getNumParams() > 0) 
{
+if (BPT->getPointeeType()->castAs()->getNumParams() > 
0) {
   S.Diag(Arg3->getBeginLoc(),
  diag::err_opencl_enqueue_kernel_blocks_no_args);
   return true;
@@ -4664,7 +4664,7 @@ ExprResult Sema::BuildAtomicExpr(SourceR
   << Ptr->getSourceRange();
   return ExprError();
 }
-ValType = AtomTy->getAs()->getValueType();
+ValType = AtomTy->castAs()->getValueType();
   } else if (Form != Load && Form != LoadCopy) {
 if (ValType.isConstQualified()) {
   Diag(ExprRange.getBegin(), diag::err_atomic_op_needs_non_const_pointer)
@@ -5473,7 +5473,7 @@ static bool checkVAStartABI(Sema , uns
   if (IsX64 || IsAArch64) {
 CallingConv CC = CC_C;
 if (const FunctionDecl *FD = S.getCurFunctionDecl())
-  CC = FD->getType()->getAs()->getCallConv();
+  CC = FD->getType()->castAs()->getCallConv();
 if (IsMSVAStart) {
   // Don't allow this in System V ABI functions.
   if (CC == CC_X86_64SysV || (!IsWindows && CC != CC_Win64))
@@ -5603,7 +5603,7 @@ bool Sema::SemaBuiltinVAStart(unsigned B
return false;
  if (!Type->isEnumeralType())
return true;
- const EnumDecl *ED = Type->getAs()->getDecl();
+ const EnumDecl *ED = Type->castAs()->getDecl();
  return !(ED &&
   Context.typesAreCompatible(ED->getPromotionType(), 
Type));
}()) {
@@ -10756,7 +10756,7 @@ static bool AnalyzeBitFieldAssignment(Se
  return false;
 
   if (BitfieldType->isEnumeralType()) {
-EnumDecl *BitfieldEnumDecl = BitfieldType->getAs()->getDecl();
+EnumDecl *BitfieldEnumDecl = BitfieldType->castAs()->getDecl();
 // If the underlying enum type was not explicitly specified as an unsigned
 // type and the enum contain only positive values, MSVC++ will cause an
 // inconsistency by storing this as a signed type.

Modified: cfe/trunk/lib/Sema/SemaCoroutine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCoroutine.cpp?rev=373911=373910=373911=diff
==
--- cfe/trunk/lib/Sema/SemaCoroutine.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCoroutine.cpp Mon Oct  7 07:25:46 2019
@@ -83,7 +83,7 @@ static QualType lookupPromiseType(Sema &
   //  

r373910 - [clang] Add test for FindNextToken in Lexer.

2019-10-07 Thread Utkarsh Saxena via cfe-commits
Author: usaxena95
Date: Mon Oct  7 07:20:46 2019
New Revision: 373910

URL: http://llvm.org/viewvc/llvm-project?rev=373910=rev
Log:
[clang] Add test for FindNextToken in Lexer.

Reviewers: ilya-biryukov

Subscribers: cfe-commits

Tags: #clang

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

Modified:
cfe/trunk/unittests/Lex/LexerTest.cpp

Modified: cfe/trunk/unittests/Lex/LexerTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Lex/LexerTest.cpp?rev=373910=373909=373910=diff
==
--- cfe/trunk/unittests/Lex/LexerTest.cpp (original)
+++ cfe/trunk/unittests/Lex/LexerTest.cpp Mon Oct  7 07:20:46 2019
@@ -11,9 +11,11 @@
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
 #include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
+#include "clang/Basic/TokenKinds.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/HeaderSearchOptions.h"
 #include "clang/Lex/MacroArgs.h"
@@ -21,11 +23,13 @@
 #include "clang/Lex/ModuleLoader.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorOptions.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
-
-using namespace clang;
+#include 
 
 namespace {
+using namespace clang;
+using testing::ElementsAre;
 
 // The test fixture.
 class LexerTest : public ::testing::Test {
@@ -535,4 +539,21 @@ TEST_F(LexerTest, CharRangeOffByOne) {
   EXPECT_EQ(Lexer::getSourceText(CR, SourceMgr, LangOpts), "MOO"); // Was "MO".
 }
 
+TEST_F(LexerTest, FindNextToken) {
+  Lex("int abcd = 0;\n"
+  "int xyz = abcd;\n");
+  std::vector GeneratedByNextToken;
+  SourceLocation Loc =
+  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
+  while (true) {
+auto T = Lexer::findNextToken(Loc, SourceMgr, LangOpts);
+ASSERT_TRUE(T.hasValue());
+if (T->is(tok::eof))
+  break;
+GeneratedByNextToken.push_back(getSourceText(*T, *T));
+Loc = T->getLocation();
+  }
+  EXPECT_THAT(GeneratedByNextToken, ElementsAre("abcd", "=", "0", ";", "int",
+"xyz", "=", "abcd", ";"));
+}
 } // anonymous namespace


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


[PATCH] D68562: [clangd] Add RemoveUsingNamespace tweak.

2019-10-07 Thread UTKARSH SAXENA via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 223592.
usaxena95 marked 3 inline comments as done.
usaxena95 added a comment.

Make the tweak trigger only for TopLevelDecl.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D68562

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/AST.h
  clang-tools-extra/clangd/refactor/tweaks/CMakeLists.txt
  clang-tools-extra/clangd/refactor/tweaks/RemoveUsingNamespace.cpp
  clang-tools-extra/clangd/unittests/TweakTests.cpp

Index: clang-tools-extra/clangd/unittests/TweakTests.cpp
===
--- clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -69,7 +69,8 @@
   EXPECT_EQ(apply("^if (true) {return 100;} else {continue;}"),
 "if (true) {continue;} else {return 100;}");
   EXPECT_EQ(apply("^if () {return 100;} else {continue;}"),
-"if () {continue;} else {return 100;}") << "broken condition";
+"if () {continue;} else {return 100;}")
+  << "broken condition";
   EXPECT_AVAILABLE("^i^f^^(^t^r^u^e^) { return 100; } ^e^l^s^e^ { continue; }");
   EXPECT_UNAVAILABLE("if (true) {^return ^100;^ } else { ^continue^;^ }");
   // Available in subexpressions of the condition;
@@ -100,7 +101,7 @@
   EXPECT_UNAVAILABLE(R"cpp(R"(multi )" ^"token " u8"str\ning")cpp"); // nonascii
   EXPECT_UNAVAILABLE(R"cpp(^R^"^(^multi )" "token " "str\ning")cpp"); // raw
   EXPECT_UNAVAILABLE(R"cpp(^"token\n" __FILE__)cpp"); // chunk is macro
-  EXPECT_UNAVAILABLE(R"cpp(^"a\r\n";)cpp"); // forbidden escape char
+  EXPECT_UNAVAILABLE(R"cpp(^"a\r\n";)cpp");   // forbidden escape char
 
   const char *Input = R"cpp(R"(multi
 token)" "\nst^ring\n" "literal")cpp";
@@ -286,11 +287,11 @@
  void f(int a) {
int y = PLUS([[1+a]]);
  })cpp",
-  /*FIXME: It should be extracted like this.
-   R"cpp(#define PLUS(x) x++
- void f(int a) {
-   auto dummy = 1+a; int y = PLUS(dummy);
- })cpp"},*/
+   /*FIXME: It should be extracted like this.
+R"cpp(#define PLUS(x) x++
+  void f(int a) {
+auto dummy = 1+a; int y = PLUS(dummy);
+  })cpp"},*/
R"cpp(#define PLUS(x) x++
  void f(int a) {
auto dummy = PLUS(1+a); int y = dummy;
@@ -301,13 +302,13 @@
if(1)
 LOOP(5 + [[3]])
  })cpp",
-  /*FIXME: It should be extracted like this. SelectionTree needs to be
-* fixed for macros.
-   R"cpp(#define LOOP(x) while (1) {a = x;}
-   void f(int a) {
- auto dummy = 3; if(1)
-  LOOP(5 + dummy)
-   })cpp"},*/
+   /*FIXME: It should be extracted like this. SelectionTree needs to be
+ * fixed for macros.
+R"cpp(#define LOOP(x) while (1) {a = x;}
+void f(int a) {
+  auto dummy = 3; if(1)
+   LOOP(5 + dummy)
+})cpp"},*/
R"cpp(#define LOOP(x) while (1) {a = x;}
  void f(int a) {
auto dummy = LOOP(5 + 3); if(1)
@@ -403,8 +404,8 @@
  void f() {
auto dummy = S(2) + S(3) + S(4); S x = S(1) + dummy + S(5);
  })cpp"},
-   // Don't try to analyze across macro boundaries
-   // FIXME: it'd be nice to do this someday (in a safe way)
+  // Don't try to analyze across macro boundaries
+  // FIXME: it'd be nice to do this someday (in a safe way)
   {R"cpp(#define ECHO(X) X
  void f() {
int x = 1 + [[ECHO(2 + 3) + 4]] + 5;
@@ -521,7 +522,7 @@
   StartsWith("fail: Could not expand type of lambda expression"));
   // inline namespaces
   EXPECT_EQ(apply("au^to x = inl_ns::Visible();"),
-  "Visible x = inl_ns::Visible();");
+"Visible x = inl_ns::Visible();");
   // local class
   EXPECT_EQ(apply("namespace x { void y() { struct S{}; ^auto z = S(); } }"),
 "namespace x { void y() { struct S{}; S z = S(); } }");
@@ -656,6 +657,160 @@
   EXPECT_THAT(apply(" for(;;) { [[while(1) break; break;]] }"),
   StartsWith("fail"));
 }
+
+TWEAK_TEST(RemoveUsingNamespace);
+TEST_F(RemoveUsingNamespaceTest, All) {
+  std::pair Cases[] = {
+  {// Remove all occurrences of ns. Qualify only unqualified.
+   R"cpp(
+  namespace ns1 { struct vector {}; }
+  namespace ns2 { struct map {}; }
+  using namespace n^s1;
+  using namespace ns2;
+  using namespace ns1;
+  int main() {
+ns1::vector v1;
+vector v2;
+map m1;
+  }
+)cpp",
+   R"cpp(
+  namespace ns1 { struct 

[PATCH] D68213: [LTO] Support for embedding bitcode section during LTO

2019-10-07 Thread Josef Eisl via Phabricator via cfe-commits
zapster added a comment.

(ping)


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

https://reviews.llvm.org/D68213



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


[PATCH] D67536: [WIP] [clangd] Add support for an inactive regions notification

2019-10-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked 2 inline comments as done.
nridge added a comment.

How would one even measure the line length? `SourceManager` doesn't sem to have 
a method like `getLineLength()` or similar.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67536



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


[PATCH] D67536: [WIP] [clangd] Add support for an inactive regions notification

2019-10-07 Thread Nathan Ridge via Phabricator via cfe-commits
nridge marked 5 inline comments as done.
nridge added inline comments.



Comment at: clang-tools-extra/clangd/Compiler.cpp:66
   CI->getLangOpts()->CommentOpts.ParseAllComments = true;
+  CI->getPreprocessorOpts().DetailedRecord = true;
   return CI;

ilya-biryukov wrote:
> hokein wrote:
> > I'm not sure how does this flag impact the size of Preamble/AST, 
> > @ilya-biryukov any thoughts?
> Have no idea, but why do we need this in the first place?
> `PPCallbacks::SourceRangeSkipped` should allow to record all skipped ranges 
> in the main file. Can we use it?
Yes, `PPCallbacks::SourceRangeSkipped` works in place of using 
`DetailedRecord`. Thank you for the suggestion.



Comment at: clang-tools-extra/clangd/SemanticHighlighting.h:43
   Primitive,
+  InactivePreprocessorBranch,
   Macro,

hokein wrote:
> This is a different kind group, I would put it after the Macro,  we'd need to 
> update the LastKind. 
> 
> The name seems too specific, how about "UnreachableCode"?
I changed it to "InactiveCode". ("Unreachable" seemed like the wrong word, it 
brings to mind control flow.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D67536



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


[PATCH] D67837: [CUDA][HIP] Fix host/device check with -fopenmp

2019-10-07 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/Sema/SemaCUDA.cpp:604
 // Do we know that we will eventually codegen the given function?
 static bool IsKnownEmitted(Sema , FunctionDecl *FD) {
+  return S.getEmissionStatus(FD) == Sema::FunctionEmissionStatus::Emitted;

I believe this function can be removed



Comment at: lib/Sema/SemaDecl.cpp:17619
+
+  auto OMPES = FunctionEmissionStatus::Unknown;
+  if (LangOpts.OpenMPIsDevice) {

Better to use real type here, not `auto`



Comment at: lib/Sema/SemaDecl.cpp:17623-17626
+if (DevTy.hasValue())
+  OMPES = (*DevTy == OMPDeclareTargetDeclAttr::DT_Host)
+   ? FunctionEmissionStatus::OMPDiscarded
+   : FunctionEmissionStatus::Emitted;

Enclose in braces



Comment at: lib/Sema/SemaDecl.cpp:17626
+   ? FunctionEmissionStatus::OMPDiscarded
+   : FunctionEmissionStatus::Emitted;
+  } else if (LangOpts.OpenMP) {

Hmm, it must be marked as know-emitted only if 
`S.DeviceKnownEmittedFns.count(FD) > 0`. Otherwise, it must be unknown.



Comment at: lib/Sema/SemaDecl.cpp:17629-17631
+if (LangOpts.OpenMP <= 45)
+  OMPES = FunctionEmissionStatus::Emitted;
+else {

Enclose in braces, not goo to have `else` branch enclosed in braces and `then` 
branch without.



Comment at: lib/Sema/SemaDecl.cpp:17641
+ ? FunctionEmissionStatus::OMPDiscarded
+ : FunctionEmissionStatus::Emitted;
+}

Same here, it must be marked as know-emitted only if 
`S.DeviceKnownEmittedFns.count(FD) > 0`. Otherwise, it must be unknown.



Comment at: lib/Sema/SemaDecl.cpp:17684-17689
+  // If we have
+  //   host fn calls kernel fn calls host+device,
+  // the HD function does not get instantiated on the host.  We model this by
+  // omitting at the call to the kernel from the callgraph.  This ensures
+  // that, when compiling for host, only HD functions actually called from the
+  // host get marked as known-emitted.

Reformat the comment here



Comment at: lib/Sema/SemaOpenMP.cpp:1629-1630
+auto CalleeS = getEmissionStatus(Callee);
+assert(CallerS != FunctionEmissionStatus::CUDADiscarded &&
+   CallerS != FunctionEmissionStatus::CUDADiscarded &&
+   "CUDADiscarded unexpected in OpenMP device function check");

The same condition is checked twice, one of them must be for `CalleeS`, I 
believe



Comment at: lib/Sema/SemaOpenMP.cpp:1674
+(LangOpts.CUDA || (CallerS != FunctionEmissionStatus::CUDADiscarded &&
+   CallerS != FunctionEmissionStatus::CUDADiscarded)) 
&&
+"CUDADiscarded unexpected in OpenMP host function check");

Again, the same condition checked twice.


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

https://reviews.llvm.org/D67837



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


  1   2   >