[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2021-04-28 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4001
+  // probably don't want to allow usage of an ARM ABI on an x86 architecture.
+  auto SupportedCXXABI = [](const llvm::Triple &T, TargetCXXABI::Kind Kind) {
+switch (Kind) {

I'd consider extracting this into a method.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4004-4009
+case TargetCXXABI::iOS:
+case TargetCXXABI::WatchOS:
+  return T.isARM() || T.isAArch64();
+
+case TargetCXXABI::AppleARM64:
+  return T.isARM() && T.isArch64Bit();

These should probably be only supported on Apple platforms?



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:4012
+case TargetCXXABI::Fuchsia:
+  return T.isAArch64() || (T.isX86() && T.isArch64Bit());
+

I think you should be checking OS here, not the architecture since we want to 
use the same ABI across all architectures.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

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


[PATCH] D101259: [clang-tidy] Fix cppcoreguidelines-pro-type-vararg false positives with __builtin_ms_va_list

2021-04-28 Thread Georgy Komarov via Phabricator via cfe-commits
jubnzv updated this revision to Diff 341079.

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

https://reviews.llvm.org/D101259

Files:
  clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg-ms.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg.cpp
@@ -58,3 +58,11 @@
   (void)__builtin_isinf_sign(0.f);
   (void)__builtin_prefetch(nullptr);
 }
+
+// Some implementations of __builtin_va_list and __builtin_ms_va_list desugared
+// as 'char *' or 'void *'. This test checks whether we are handling this case
+// correctly and not generating false positives.
+void no_false_positive_desugar_va_list(char *in) {
+  char *tmp1 = in;
+  void *tmp2 = in;
+}
Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg-ms.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-pro-type-vararg-ms.cpp
@@ -0,0 +1,26 @@
+// Purpose:
+// Ensure that the 'cppcoreguidelines-pro-type-vararg' check works with the
+// built-in va_list on Windows systems.
+
+// REQUIRES: system-windows
+
+// RUN: %check_clang_tidy %s cppcoreguidelines-pro-type-vararg %t
+
+void test_ms_va_list(int a, ...) {
+  __builtin_ms_va_list ap;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare variables of type va_list; use variadic templates instead
+  __builtin_ms_va_start(ap, a);
+  int b = __builtin_va_arg(ap, int);
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use va_arg to define c-style vararg functions; use variadic templates instead
+  __builtin_ms_va_end(ap);
+}
+
+void test_typedefs(int a, ...) {
+  typedef __builtin_ms_va_list my_va_list1;
+  my_va_list1 ap1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare variables of type va_list; use variadic templates instead
+
+  using my_va_list2 = __builtin_ms_va_list;
+  my_va_list2 ap2;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare variables of type va_list; use variadic templates instead
+}
Index: clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
===
--- clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -10,6 +10,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/TargetInfo.h"
 
 using namespace clang::ast_matchers;
 
@@ -60,8 +61,45 @@
 AST_MATCHER(QualType, isVAList) {
   ASTContext &Context = Finder->getASTContext();
   QualType Desugar = Node.getDesugaredType(Context);
-  return Context.getBuiltinVaListType().getDesugaredType(Context) == Desugar ||
- Context.getBuiltinMSVaListType().getDesugaredType(Context) == Desugar;
+  QualType NodeTy = Node.getUnqualifiedType();
+
+  auto CheckVaList = [](const QualType &NodeTy, const QualType &Expected,
+const ASTContext &Context) {
+if (NodeTy == Expected)
+  return true;
+QualType Desugar = NodeTy;
+QualType Ty;
+do {
+  Ty = Desugar;
+  Desugar = Ty.getSingleStepDesugaredType(Context);
+  if (Desugar == Expected)
+return true;
+} while (Desugar != Ty);
+return false;
+  };
+
+  // The internal implementation of __builtin_va_list depends on the target
+  // type. Some targets implements va_list as 'char *' or 'void *'.
+  // In these cases we need to remove all typedefs one by one to check this.
+  using BuiltinVaListKind = TargetInfo::BuiltinVaListKind;
+  BuiltinVaListKind VaListKind = Context.getTargetInfo().getBuiltinVaListKind();
+  if (VaListKind == BuiltinVaListKind::CharPtrBuiltinVaList ||
+  VaListKind == BuiltinVaListKind::VoidPtrBuiltinVaList) {
+if (CheckVaList(NodeTy, Context.getBuiltinVaListType(), Context))
+  return true;
+  } else if (Desugar ==
+ Context.getBuiltinVaListType().getDesugaredType(Context)) {
+return true;
+  }
+
+  // We also need to check the implementation of __builtin_ms_va_list in the
+  // same way, because it may differ from the va_list implementation.
+  if (Desugar == Context.getBuiltinMSVaListType().getDesugaredType(Context)) {
+if (CheckVaList(NodeTy, Context.getBuiltinMSVaListType(), Context))
+  return true;
+  }
+
+  return false;
 }
 
 AST_MATCHER_P(AdjustedType, hasOriginalType,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lis

[PATCH] D101425: Make LValuePathEntry a discriminated union

2021-04-28 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: rsmith, rjmccall, varungandhi-apple, Tyker, EricWF, 
george.burgess.iv, nand.
Herald added a subscriber: martong.
Herald added a reviewer: shafik.
sepavloff requested review of this revision.
Herald added a project: clang.

APValue::LValuePathEntry was implemented as non-discriminated union. It
complicated operations on it and inspection in debugger. This change
turns it into discriminated union.

No functional changed intended.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101425

Files:
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/AbstractBasicReader.h
  clang/include/clang/AST/AbstractBasicWriter.h
  clang/lib/AST/APValue.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/Interp/Pointer.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp

Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ clang/lib/AST/MicrosoftMangle.cpp
@@ -1722,8 +1722,7 @@
 if (T->isArrayType())
   goto mangling_unknown;
 
-const Decl *D = E.getAsBaseOrMember().getPointer();
-auto *FD = dyn_cast(D);
+const FieldDecl *FD = E.getAsFieldOrNull();
 // We don't know how to mangle derived-to-base conversions yet.
 if (!FD)
   goto mangling_unknown;
@@ -1739,10 +1738,8 @@
   Out << "E";
   mangle(VD);
 
-  for (APValue::LValuePathEntry E : V.getLValuePath()) {
-const Decl *D = E.getAsBaseOrMember().getPointer();
-mangleUnqualifiedName(cast(D));
-  }
+  for (APValue::LValuePathEntry E : V.getLValuePath())
+mangleUnqualifiedName(E.getAsField());
   for (unsigned I = 0; I != NumAts; ++I)
 Out << '@';
 }
Index: clang/lib/AST/ItaniumMangle.cpp
===
--- clang/lib/AST/ItaniumMangle.cpp
+++ clang/lib/AST/ItaniumMangle.cpp
@@ -5376,12 +5376,10 @@
   for (APValue::LValuePathEntry E : LV.getLValuePath()) {
 if (const ArrayType *AT = Ctx.getAsArrayType(T))
   T = AT->getElementType();
-else if (const FieldDecl *FD =
- dyn_cast(E.getAsBaseOrMember().getPointer()))
+else if (const FieldDecl *FD = E.getAsFieldOrNull())
   T = FD->getType();
 else
-  T = Ctx.getRecordType(
-  cast(E.getAsBaseOrMember().getPointer()));
+  T = Ctx.getRecordType(E.getAsBase());
   }
   return T;
 }
@@ -5682,8 +5680,7 @@
 OnePastTheEnd |= CAT->getSize() == E.getAsArrayIndex();
   TypeSoFar = AT->getElementType();
 } else {
-  const Decl *D = E.getAsBaseOrMember().getPointer();
-  if (auto *FD = dyn_cast(D)) {
+  if (const FieldDecl *FD = E.getAsFieldOrNull()) {
 //  ::= _ 
 if (FD->getParent()->isUnion()) {
   Out << '_';
@@ -5692,7 +5689,7 @@
 }
 TypeSoFar = FD->getType();
   } else {
-TypeSoFar = Ctx.getRecordType(cast(D));
+TypeSoFar = Ctx.getRecordType(E.getAsBase());
   }
 }
   }
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -116,8 +116,8 @@
 
   // Create a path entry for the field.
   Descriptor *Desc = Ptr.getFieldDesc();
-  if (auto *BaseOrMember = Desc->asDecl()) {
-Path.push_back(APValue::LValuePathEntry({BaseOrMember, IsVirtual}));
+  if (auto *D = Desc->asDecl()) {
+Path.push_back(APValue::LValuePathEntry::Declaration(D, IsVirtual));
 Ptr = Ptr.getBase();
 continue;
   }
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -82,22 +82,6 @@
 return B.getType();
   }
 
-  /// Get an LValue path entry, which is known to not be an array index, as a
-  /// field declaration.
-  static const FieldDecl *getAsField(APValue::LValuePathEntry E) {
-return dyn_cast_or_null(E.getAsBaseOrMember().getPointer());
-  }
-  /// Get an LValue path entry, which is known to not be an array index, as a
-  /// base class declaration.
-  static const CXXRecordDecl *getAsBaseClass(APValue::LValuePathEntry E) {
-return dyn_cast_or_null(E.getAsBaseOrMember().getPointer());
-  }
-  /// Determine whether this LValue path entry for a base class names a virtual
-  /// base class.
-  static bool isVirtualBaseClass(APValue::LValuePathEntry E) {
-return E.getAsBaseOrMember().getInt();
-  }
-
   /// Given an expression, determine the type used to store the result of
   /// evaluating that expression.
   static QualType getStorageType(const ASTContext &Ctx, const Expr *E) {
@@ -218,7 +202,7

[PATCH] D101426: [RISCV] Update subset naming convertion for the latest spec

2021-04-28 Thread Jim Lin via Phabricator via cfe-commits
Jim created this revision.
Herald added subscribers: vkmr, frasercrmck, evandro, luismarques, apazos, 
sameer.abuasal, s.egerton, benna, psnobl, jocewei, PkmX, the_o, brucehoult, 
MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, 
niosHD, sabuasal, simoncook, johnrusso, rbar, asb.
Jim requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Update arch string rules for the latest spec 20191213. It introduced
new multi-letter extension prefix with 'h' and 'z', and drop `sx`.
And the canonical order is 's', 'h', 'z' and 'x'.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101426

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

Index: clang/test/Driver/riscv-arch.c
===
--- clang/test/Driver/riscv-arch.c
+++ clang/test/Driver/riscv-arch.c
@@ -181,31 +181,25 @@
 // RV32-STD: error: invalid arch name 'rv32imqc',
 // RV32-STD: unsupported standard user-level extension 'q'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32xabc -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X %s
-// RV32X: error: invalid arch name 'rv32xabc',
-// RV32X: first letter should be 'e', 'i' or 'g'
-
-// RUN: %clang -target riscv32-unknown-elf -march=rv32sxabc -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32SX %s
-// RV32SX: error: invalid arch name 'rv32sxabc',
-// RV32SX: first letter should be 'e', 'i' or 'g'
-
 // RUN: %clang -target riscv32-unknown-elf -march=rv32sabc -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32S %s
 // RV32S: error: invalid arch name 'rv32sabc',
 // RV32S: first letter should be 'e', 'i' or 'g'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32ix -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X-NAME %s
-// RV32X-NAME: error: invalid arch name 'rv32ix',
-// RV32X-NAME: non-standard user-level extension name missing after 'x'
+// RUN: %clang -target riscv32-unknown-elf -march=rv32habc -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32H %s
+// RV32H: error: invalid arch name 'rv32habc',
+// RV32H: first letter should be 'e', 'i' or 'g'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32isx -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32SX-NAME %s
-// RV32SX-NAME: error: invalid arch name 'rv32isx',
-// RV32SX-NAME: non-standard supervisor-level extension
-// RV32SX-NAME: name missing after 'sx'
+// RUN: %clang -target riscv32-unknown-elf -march=rv32zabc -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32Z %s
+// RV32Z: error: invalid arch name 'rv32zabc',
+// RV32Z: first letter should be 'e', 'i' or 'g'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32xabc -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X %s
+// RV32X: error: invalid arch name 'rv32xabc',
+// RV32X: first letter should be 'e', 'i' or 'g'
 
 // RUN: %clang -target riscv32-unknown-elf -march=rv32is -### %s \
 // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32S-NAME %s
@@ -213,31 +207,53 @@
 // RV32S-NAME: standard supervisor-level extension
 // RV32S-NAME: name missing after 's'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32ix_s_sx -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32ALL-NAME %s
-// RV32ALL-NAME: error: invalid arch name 'rv32ix_s_sx',
-// RV32ALL-NAME: non-standard user-level extension
-// RV32ALL-NAME: name missing after 'x'
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ih -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32H-NAME %s
+// RV32H-NAME: error: invalid arch name 'rv32ih',
+// RV32H-NAME: standard hypervisor-level extension
+// RV32H-NAME: name missing after 'h'
 
-// RUN: %clang -target riscv32-unknown-elf -march=rv32ixabc -### %s \
-// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X-UNS %s
-// RV32X-UNS: error: invalid arch name 'rv32ixabc',
-// RV32X-UNS: unsupported non-standard user-level extension 'xabc'
+// RUN: %clang -target riscv32-unknown-elf -march=rv32iz -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32Z-NAME %s
+// RV32Z-NAME: error: invalid arch name 'rv32iz',
+// RV32Z-NAME: standard machine-level extension
+// RV32Z-NAME: name missing after 'z'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32ix -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X-NAME %s
+// RV32X-NAME: error: invalid arch name 'rv32ix',
+// RV32X-NAME: non-standard extension name missing after 'x'
+
+// RUN: %clang -target riscv32-unknown-elf -march=rv32is_h_z_x -### %s \
+// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32ALL-NAME %s
+// RV32ALL-NAME: error: invalid arch name 'rv32is_h_z_x',
+// RV32ALL-NAME: standard supervisor-level extension
+// RV32ALL-NAME: name missing after 's'
 
 // RUN: %clang -target riscv32-unknown-elf -mar

[PATCH] D101426: [RISCV] Update subset naming convertion for the latest spec

2021-04-28 Thread Jim Lin via Phabricator via cfe-commits
Jim added a comment.

GCC has been updated from 
https://github.com/gcc-mirror/gcc/commit/ca1a9763a1f635d2687ebd5009dd61d4fd0ab5fb#diff-622e89d94803bb804711d5d492a5d4dfa60399bd7a5a7e70a49155534aa6a81f


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101426

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


[PATCH] D101429: PR45879: Use LValue object to evaluate active union members

2021-04-28 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff created this revision.
sepavloff added a reviewer: rsmith.
sepavloff requested review of this revision.
Herald added a project: clang.

The function HandleUnionActiveMemberChange determined union members that
become active by analyzing LHS expression. It works for assignment
operator but in the case of C++ assignment operator LHS is not easily
available. Actually RHS was used instead, wich resulted in crash
reported in PR45879.

This change uses LValue object to find union members.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101429

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/constant-expression-cxx2a.cpp

Index: clang/test/SemaCXX/constant-expression-cxx2a.cpp
===
--- clang/test/SemaCXX/constant-expression-cxx2a.cpp
+++ clang/test/SemaCXX/constant-expression-cxx2a.cpp
@@ -379,10 +379,10 @@
 return *p; // expected-note {{read of uninitialized object}}
   }
   static_assert(read_uninitialized() == 0); // expected-error {{constant}} expected-note {{in call}}
-  constexpr void write_wrong_member_indirect() { // expected-error {{never produces a constant}}
+  constexpr void write_wrong_member_indirect() {
 B b = {.b = 1};
 int *p = &b.a.y;
-*p = 1; // expected-note {{assignment to member 'a' of union with active member 'b'}}
+*p = 1;
   }
   constexpr int write_uninitialized() {
 B b = {.b = 1};
@@ -1447,3 +1447,9 @@
   constexpr bool b = [a = S(), b = S()] { return a.p == b.p; }();
   static_assert(!b);
 }
+
+namespace PR45879 {
+  struct Base { int m; };
+  struct Derived : Base {};
+  constexpr int k = ((Base{} = Derived{}), 0);
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -5871,7 +5871,7 @@
 /// operator whose left-hand side might involve a union member access. If it
 /// does, implicitly start the lifetime of any accessed union elements per
 /// C++20 [class.union]5.
-static bool HandleUnionActiveMemberChange(EvalInfo &Info, const Expr *LHSExpr,
+static bool HandleUnionActiveMemberChange(EvalInfo &Info, const Expr *E,
   const LValue &LHS) {
   if (LHS.InvalidBase || LHS.Designator.Invalid)
 return false;
@@ -5879,11 +5879,11 @@
   llvm::SmallVector, 4> UnionPathLengths;
   // C++ [class.union]p5:
   //   define the set S(E) of subexpressions of E as follows:
-  unsigned PathLength = LHS.Designator.Entries.size();
-  for (const Expr *E = LHSExpr; E != nullptr;) {
+  for (unsigned PathLength = LHS.Designator.Entries.size(); PathLength;
+   --PathLength) {
+SubobjectDesignator::PathEntry PE = LHS.Designator.Entries[PathLength - 1];
 //   -- If E is of the form A.B, S(E) contains the elements of S(A)...
-if (auto *ME = dyn_cast(E)) {
-  auto *FD = dyn_cast(ME->getMemberDecl());
+if (auto *FD = PE.getAsFieldOrNull()) {
   // Note that we can't implicitly start the lifetime of a reference,
   // so we don't need to proceed any further if we reach one.
   if (!FD || FD->getType()->isReferenceType())
@@ -5900,41 +5900,10 @@
   UnionPathLengths.push_back({PathLength - 1, FD});
   }
 
-  E = ME->getBase();
-  --PathLength;
-  assert(declaresSameEntity(
-  FD, LHS.Designator.Entries[PathLength].getAsBaseOrMember()));
-
   //   -- If E is of the form A[B] and is interpreted as a built-in array
   //  subscripting operator, S(E) is [S(the array operand, if any)].
-} else if (auto *ASE = dyn_cast(E)) {
-  // Step over an ArrayToPointerDecay implicit cast.
-  auto *Base = ASE->getBase()->IgnoreImplicit();
-  if (!Base->getType()->isArrayType())
-break;
-
-  E = Base;
-  --PathLength;
-
-} else if (auto *ICE = dyn_cast(E)) {
-  // Step over a derived-to-base conversion.
-  E = ICE->getSubExpr();
-  if (ICE->getCastKind() == CK_NoOp)
-continue;
-  if (ICE->getCastKind() != CK_DerivedToBase &&
-  ICE->getCastKind() != CK_UncheckedDerivedToBase)
-break;
-  // Walk path backwards as we walk up from the base to the derived class.
-  for (const CXXBaseSpecifier *Elt : llvm::reverse(ICE->path())) {
---PathLength;
-(void)Elt;
-assert(
-declaresSameEntity(Elt->getType()->getAsCXXRecordDecl(),
-   LHS.Designator.Entries[PathLength].getAsBase()));
-  }
-
-//   -- Otherwise, S(E) is empty.
-} else {
+  //   -- Otherwise, S(E) is empty.
+} else if (!PE.isArrayIndex() && !PE.isAnyBase()) {
   break;
 }
   }
@@ -5946,7 +5915,7 @@
   //   if modification of X [would access an inactive union member], an object
   //   of the type of X is implicitly created
   CompleteObject Obj =
-  findCompleteObject(Info, LHSExpr, AK_Assign, LHS, LHSExpr->getType());
+  findCompl

[PATCH] D99741: [RISCV][Clang] Add some RVV Floating-Point intrinsic functions. (vfclass, vfmerge, vfrec7, vfrsqrt7, vfsqrt)

2021-04-28 Thread Hsiangkai Wang via Phabricator via cfe-commits
HsiangKai added a comment.

In D99741#2721669 , @craig.topper 
wrote:

> In D99741#2721596 , @thakis wrote:
>
>> In D99741#2721235 , @craig.topper 
>> wrote:
>>
>>> I believe we had reductions at builds 7601 and 8175.
>>>
>>> It looks like there may have been an increase between builds 7979 and 7991 
>>> the build failed for a while there. I suspect "e951b04 
>>>  
>>> [AArch64][SVE] Regression test all ACLE tests with C++" as it added a quite 
>>> a few RUN lines.
>>>
>>> I think we also caused an increase at build 8202 when these 4 commits went 
>>> in 
>>> bd32c2d 
>>>  
>>> [RISCV] Implement the vwcvt{u}.x.x.v/vncvt.x.x.w builtin.   
>>> 
>>> 
>>> 
>>> 645c5f2 
>>>  
>>> [RISCV] Implement the pseudo compare builtin.   
>>> 
>>> 
>>> 
>>> bfb3fca 
>>>  
>>> [RISCV] Implement the vfabs.v/vfneg.v builtin.  
>>> 
>>> 
>>> 
>>> 4b24341 
>>>  
>>> [RISCV] Implement the vmmv.m/vmnot.m builtin.
>>
>> Any disagreement about reverting riscv builtin changes until there's some 
>> way to test them without increasing check-clang time by 20%?
>
> We're preparing a patch to remove to stop testing both rv32 and rv64 on every 
> test. That should reduce the time by half. What is an acceptable number?

I have removed rv32 test cases for vector intrinsics in 
https://github.com/llvm/llvm-project/commit/b358a2be52480c008a0789c78f5df1bb2053bfd8.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99741

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


[PATCH] D101139: Create install targets for scan-build-py.

2021-04-28 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D101139#2718112 , @aabbaabb wrote:

> In D101139#2718057 , @phosek wrote:
>
>> In D101139#2713530 , @aabbaabb 
>> wrote:
>>
>>> The python script assumes relative directory while finding things. For 
>>> example, for resources folder, it uses os.path.join(this_dir, 'resources') 
>>> in report.py, which means resource need to be in the same dir as report.py. 
>>> Similarly for the libscanbuild. it assumes the library is always at one 
>>> level up from bin folder. Installing them to different directories would 
>>> break the script.
>>
>> We could reorganize things to match the final layout, that's the strategy 
>> that https://github.com/llvm/llvm-project/tree/main/clang/tools/scan-build 
>> uses as well.
>>
>> In D101139#2713551 , @aabbaabb 
>> wrote:
>>
>>> libear is built dynamically at runtime from build_libear function in 
>>> libear/__init__.py which would be called by libscanbuild/analyze.py. It is 
>>> not built statically.
>>
>> Could we modify the code to avoid building libear at runtime and instead 
>> build it with CMake. Is libear even needed when using compilation database?
>
> If i copy libscanbuild/resources to out/share/, libscanbuild to 
> out/libscanbuild, bin/* to bin, then resources would be in a different layout 
> than the original src. You mean modifying the original source and move 
> libscanbuild/resources out to share/resources and update the code reference?

Do we still keep the source in sync with 
https://github.com/rizsotto/scan-build? I was under the impression that the two 
codebases have already started diverging.

> We are not using libear, we are only using analyze-build not scan-build. For 
> our usage, I could define a target that only copies analyze-build, not 
> scan-build. However, I am not sure whether this is appropriate. On the other 
> hand, building libear statically might require significant change to the code.

We may consider introducing a CMake option to control whether to include libear 
or not (which would also control whether to include `scan-build` or not).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101139

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


[PATCH] D101275: [clangd] Hide inlay hints capability behind a command-line flag

2021-04-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/clangd/tool/ClangdMain.cpp:312
+ desc("Enable preview of InlayHints feature"), init(false),
+ Hidden};
+

njames93 wrote:
> Does it make sense to hide this flag? This is a feature that's basically in a 
> shippable state disregarding any LSP standardization.
We may or may not *want* to ship it without further standardization, it can 
make maintenance more complicated.

But I agree if it's behind a flag it doesn't necessarily need to be hidden, esp 
if we plan to make a call closer to the release cut.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101275

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


[clang] 789549b - [clang-cl] Map /QIntel-jcc-erratum to -mbranches-within-32B-boundaries

2021-04-28 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2021-04-28T11:10:08+02:00
New Revision: 789549bea441f1347458505307db322aea3ac289

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

LOG: [clang-cl] Map /QIntel-jcc-erratum to -mbranches-within-32B-boundaries

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e70b793079ac..06a21a9b6e9c 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5935,6 +5935,9 @@ def _SLASH_openmp_experimental : 
CLFlag<"openmp:experimental">,
 def _SLASH_tune : CLCompileJoined<"tune:">,
   HelpText<"Set CPU for optimization without affecting instruction set">,
   Alias;
+def _SLASH_QIntel_jcc_erratum : CLFlag<"QIntel-jcc-erratum">,
+  HelpText<"Align branches within 32-byte boundaries to mitigate the 
performance impact of the Intel JCC erratum.">,
+  Alias;
 
 // Non-aliases:
 
@@ -6131,7 +6134,6 @@ def _SLASH_LN : CLFlag<"LN">;
 def _SLASH_MP : CLJoined<"MP">;
 def _SLASH_Qfast_transcendentals : CLFlag<"Qfast_transcendentals">;
 def _SLASH_QIfist : CLFlag<"QIfist">;
-def _SLASH_QIntel_jcc_erratum : CLFlag<"QIntel-jcc-erratum">;
 def _SLASH_Qimprecise_fwaits : CLFlag<"Qimprecise_fwaits">;
 def _SLASH_Qpar : CLFlag<"Qpar">;
 def _SLASH_Qpar_report : CLJoined<"Qpar-report">;

diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index 77427f9daa95..be90b3fc6cc2 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -299,6 +299,10 @@
 // RUN: %clang_cl /d1PP -### -- %s 2>&1 | FileCheck -check-prefix=d1PP %s
 // d1PP: -dD
 
+// RUN: %clang_cl /c /QIntel-jcc-erratum -### -- %s 2>&1 | FileCheck 
-check-prefix=jcceratum %s
+// jcceratum: "-mllvm" "-x86-branches-within-32B-boundaries"
+
+
 // We forward any unrecognized -W diagnostic options to cc1.
 // RUN: %clang_cl -Wunused-pragmas -### -- %s 2>&1 | FileCheck 
-check-prefix=WJoined %s
 // WJoined: "-cc1"



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


[PATCH] D98726: [analyzer] Enabling MallocChecker to take up after SmartPtrModelling

2021-04-28 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

In D98726#2721228 , @NoQ wrote:

>> when the visitor encounters an `ExplodedNode`
>
> Weird. `finalizeVisitor()` accepts not any node but the error node. Your 
> screenshot suggests that the error node is not in the standard library but in 
> user code. Might it be that there are multiple error nodes and you're looking 
> at the wrong one? As usual, you can set conditional breakpoints by node IDs.

I had set a breakpoint on the function `finalizeVisitor()`, unconditionally. 
And it stops exactly once, on the node I had sent the screenshot of. That said, 
I am going to repeat the experiment, removing all use of `std::cout` (and 
`iostream`), and report back.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98726

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


[PATCH] D101388: [clangd] Add SymbolID to LocatedSymbol.

2021-04-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

LG, but can you amend the description a bit?

> We do not have to both locate the symbol and also query the SymbolID (using 
> getSymbolInfo).

IIRC this isn't really the reason, it's because getSymbolInfo and 
locateSymbolAt don't have the same semantics *for choosing symbols* and we want 
the ID of the symbol that matches the latter.




Comment at: clang-tools-extra/clangd/XRefs.cpp:260
   Macro.Definition = Loc;
+  Macro.ID = getSymbolID(M->Name, M->Info, AST.getSourceManager());
   return Macro;

note that this populates SymbolID even if there's no ID available, so it's 
incorrect if the type is Optional



Comment at: clang-tools-extra/clangd/XRefs.h:51
   llvm::Optional Definition;
+  // SymbolID of the symbol. Not present for file referents.
+  llvm::Optional ID;

There are other cases too, maybe just "if available"



Comment at: clang-tools-extra/clangd/XRefs.h:52
+  // SymbolID of the symbol. Not present for file referents.
+  llvm::Optional ID;
 };

SymbolID is already inherently optional (it has a zero value for a whil enow)



Comment at: clang-tools-extra/clangd/unittests/XRefsTests.cpp:924
   EXPECT_EQ(Results[0].PreferredDeclaration.range, *WantDecl) << Test;
+  EXPECT_THAT(Results[0], HasID()) << Test;
   llvm::Optional GotDef;

nit, just `EXPECT_TRUE(Results[0].ID)`, and remove the matcher?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101388

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


[clang] 2d37f21 - Try to fix clang/test/Driver/cl-options.c on non-x86 hosts

2021-04-28 Thread Hans Wennborg via cfe-commits

Author: Hans Wennborg
Date: 2021-04-28T11:57:09+02:00
New Revision: 2d37f2115d173a2c9117c6dbb4720dc7aefb9f42

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

LOG: Try to fix clang/test/Driver/cl-options.c on non-x86 hosts

The /QIntel-jcc-erratum flag only works when targeting x86,
so pass --target to the driver to do that also on non-x86 hosts.

Added: 


Modified: 
clang/test/Driver/cl-options.c

Removed: 




diff  --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index be90b3fc6cc2..c74a6de1e625 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -299,7 +299,7 @@
 // RUN: %clang_cl /d1PP -### -- %s 2>&1 | FileCheck -check-prefix=d1PP %s
 // d1PP: -dD
 
-// RUN: %clang_cl /c /QIntel-jcc-erratum -### -- %s 2>&1 | FileCheck 
-check-prefix=jcceratum %s
+// RUN: %clang_cl --target=i686-pc-windows-msvc /c /QIntel-jcc-erratum -### -- 
%s 2>&1 | FileCheck -check-prefix=jcceratum %s
 // jcceratum: "-mllvm" "-x86-branches-within-32B-boundaries"
 
 
@@ -471,7 +471,6 @@
 // RUN: /openmp:experimental \
 // RUN: /Qfast_transcendentals \
 // RUN: /QIfist \
-// RUN: /QIntel-jcc-erratum \
 // RUN: /Qimprecise_fwaits \
 // RUN: /Qpar \
 // RUN: /Qpar-report:1 \



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


[PATCH] D100980: [OpenCL] Allow use of double type without extension pragma

2021-04-28 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

In D100980#2719322 , @Anastasia wrote:

> In D100980#2719196 , @azabaznov 
> wrote:
>
>>> When the pragma is parsed we can't know why it is in the code to be able to 
>>> issue any warning.
>>
>> I mean diagnose once when, for example in your particular case, double type 
>> is parsed.  Does it require much effort? I think this warning might be 
>> useful for developers who already rely on pragma usage in their kernels.
>
> I am not sure I understand your suggestion. Could you show an example perhaps?

All right. Currently, what we do have for OpenCL C < 1.2  
(https://godbolt.org/z/rjYWMj7v1):

  :6:5: error: use of type 'double' requires cl_khr_fp64 support
  double d;
  ^
  1 error generated.

What I suggest is to have:

  :6:5: warning: pragma enable is no longer required for use of type 
'double'
  double d;
  ^
  1 warning generated.

We can issue the warning if certain flag is provided for example. Does it make 
sense?


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

https://reviews.llvm.org/D100980

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


[PATCH] D100983: [OpenCL] Fix optional image types

2021-04-28 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added inline comments.



Comment at: clang/include/clang/Basic/OpenCLImageTypes.def:68
 IMAGE_WRITE_TYPE(image2d_array_msaa_depth, OCLImage2dArrayMSAADepth, 
"cl_khr_gl_msaa_sharing")
-IMAGE_WRITE_TYPE(image3d, OCLImage3d, "cl_khr_3d_image_writes")
+IMAGE_WRITE_TYPE(image3d, OCLImage3d, "")
 

Anastasia wrote:
> azabaznov wrote:
> > Maybe we should add a test to check that` image3d_t`  is reserved?
> Do you mean something like:
> 
> ```typedef int image3d_t;```
> 
> And then check that this gives an error?
Yes, exactly. But currently there is already an expected behaviour: 
https://godbolt.org/z/4afjf5brn. I don't think that your patch changes that, 
but still, it's good to add a test since you are removing 
`cl_khr_3d_image_writes` from image descriptions.


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

https://reviews.llvm.org/D100983

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


[PATCH] D92024: [clang] Implement P0692R1 from C++20 (access checking on specializations and instantiations)

2021-04-28 Thread Kristina Bessonova via Phabricator via cfe-commits
krisb added a comment.

Thank you! It looks more consistent now.




Comment at: clang/lib/Parse/ParseDecl.cpp:3080
+// For instance this marked as unavailable:
+//class __attribute((unavailable)) UnavailableClass;`
+auto RemoveAccessCheckingDiagnostics = [&TemplateInfo, this]() {

Basically, if `__attribute((unavailable))` should trigger the error for any use 
of an unavailable class, we have it already broken.
For example, for this code clang-12 doesn't produce any diagnostics:
```
class __attribute((unavailable)) X {
  template  class __attribute((unavailable)) Y {};
};
class __attribute((unavailable)) A { 
class __attribute((unavailable)) C {}; 
};
template <> class X::Y {};
```
So, I don't see much sense in inventing something new to workaround only the 
cases that come with this patch. It's better to either fix it globally or leave 
it broken atm with the corresponding FIXME.



Comment at: clang/test/CXX/temp/temp.spec/func.spec.cpp:54
+  template <> void func2>() {
+  } template <> void func3() {
+  }

Formatting seems broken here and below.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D92024

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


[PATCH] D101087: [OpenCL] Introduce new method for validating OpenCL target

2021-04-28 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov updated this revision to Diff 341119.
azabaznov added a comment.

Add test for C++ for OpenCL diagnostics


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101087

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenCLOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Misc/nvptx.unsupported_core.cl
  clang/test/Misc/r600.unsupported_core.cl

Index: clang/test/Misc/r600.unsupported_core.cl
===
--- /dev/null
+++ clang/test/Misc/r600.unsupported_core.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple r600-unknown-unknown -Wpedantic-core-features %s 2> %t
+// RUN: FileCheck < %t %s
+
+// CHECK: cl_khr_byte_addressable_store is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_global_int32_base_atomics is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_global_int32_extended_atomics is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_local_int32_base_atomics is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_local_int32_extended_atomics is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_3d_image_writes is a core feature in OpenCL C version 2.0 but not supported on this target
Index: clang/test/Misc/nvptx.unsupported_core.cl
===
--- /dev/null
+++ clang/test/Misc/nvptx.unsupported_core.cl
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple nvptx-unknown-unknown -Wpedantic-core-features %s 2> %t
+// RUN: FileCheck --check-prefixes=CHECK-C < %t %s
+// RUN: %clang_cc1 -cl-std=CLC++ -triple nvptx-unknown-unknown -Wpedantic-core-features %s 2> %t
+// RUN: FileCheck --check-prefixes=CHECK-CPP < %t %s
+
+// CHECK-C: cl_khr_3d_image_writes is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK-CPP: cl_khr_3d_image_writes is a core feature in C++ for OpenCL version 1.0 but not supported on this target
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -601,6 +601,29 @@
 Builder.defineMacro("__cpp_coroutines", "201703L");
 }
 
+/// InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target
+/// settings and language version
+void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI,
+   const LangOptions &Opts,
+   MacroBuilder &Builder) {
+  const llvm::StringMap &OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
+  // FIXME: OpenCL options which affect language semantics/syntax
+  // should be moved into LangOptions.
+  auto defineOpenCLExtMacro = [&](llvm::StringRef Name, auto... OptArgs) {
+// Check if extension is supported by target and is available in this
+// OpenCL version
+if (TI.hasFeatureEnabled(OpenCLFeaturesMap, Name) &&
+OpenCLOptions::isOpenCLOptionAvailableIn(Opts, OptArgs...))
+  Builder.defineMacro(Name);
+  };
+#define OPENCL_GENERIC_EXTENSION(Ext, ...) \
+  defineOpenCLExtMacro(#Ext, __VA_ARGS__);
+#include "clang/Basic/OpenCLExtensions.def"
+
+  // Assume compiling for FULL profile
+  Builder.defineMacro("__opencl_c_int64");
+}
+
 static void InitializePredefinedMacros(const TargetInfo &TI,
const LangOptions &LangOpts,
const FrontendOptions &FEOpts,
@@ -1138,7 +1161,7 @@
 
   // OpenCL definitions.
   if (LangOpts.OpenCL) {
-TI.getOpenCLFeatureDefines(LangOpts, Builder);
+InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
 
 if (TI.getTriple().isSPIR())
   Builder.defineMacro("__IMAGE_SUPPORT__");
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -133,6 +133,11 @@
 // FIXME: can we disable FEnvAccess?
   }
 
+  // We should do it here because target knows nothing about
+  // language options when it's being created.
+  if (getLangOpts().OpenCL)
+getTarget().validateOpenCLTarget(getLangOpts(), getDiagnostics());
+
   // Inform the target of the language options.
   // FIXME: We shouldn't need to do this, the target should be immutable once
   //

[PATCH] D99975: [clangd][ObjC] Improve support for class properties

2021-04-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:309-313
+// FIXME: visiting this here allows us to hover on UIColor in
+// `UIColor.blackColor` but then `blackColor` no longer refers to the
+// method.
+// if (OPRE->isClassReceiver())
+//   Outer.add(OPRE->getClassReceiver(), Flags);

dgoldman wrote:
> sammccall wrote:
> > dgoldman wrote:
> > > Is there a good way to handle this case where the expression can refer to 
> > > multiple decls?
> > TL;DR: yes, fix the AST :-)
> > 
> > The design assumption is that an AST node (specifically: the tokens owned 
> > by exactly that AST node and not a descendant of it) refers to one thing. I 
> > don't see an easy way to hack around this.
> > 
> > Expressions like this are supposed to be split into multiple AST nodes. But 
> > ObjC seems to be missing AST nodes in a bunch of places (Protocol lists is 
> > another).
> > 
> > e.g. in C++ equivalent DeclRefExpr `UIColor::blackColor` there'd be both a 
> > NestedNameSpecifier for `UIColor::` and a TagTypeLoc for `UIColor`. And 
> > objc `[Test foo]` has an `ObjCInterfaceTypeLoc` for `Test`.
> > 
> > ---
> > 
> > I'm not sure this is the right place for this comment, the problem isn't 
> > what VisitObjCPropertyRefExpr is doing, the issue is that the caller is 
> > passing the wrong kind of node to findTarget() because there's no right one.
> That seems a bit invasive - is it really "fixing" the AST - is there anything 
> wrong with the current AST design or rather any notable improvements by 
> adding more nodes to the AST beside this one use case here? 
> 
> It seems like the design could be adapted if we had a SourceLocation hint 
> here (from the caller) to disambiguate which one we mean, but I'm guessing 
> not all of the callers/users of this would have one?
> That seems a bit invasive
I'm not sure it actually requires any changes to AST classes, just to 
RecursiveASTVisitor to wrap the getClassReceiverType() & getReceiverLocation() 
into n ObjCInterfaceTypeLoc (which is a value object) and visit it.

> is it really "fixing" the AST

It's inconsistent with the design of the rest of the AST.
There are very few other cases where AST nodes have this kind of compound 
meaning rather than being to split into sub-nodes.
(In fact ObjC protocol lists are the only example I can think of. I suspect 
this dates back to early clang days, maybe before the patterns became 
established)
And similarly, there are few/no places where types are referenced that don't 
have a TypeLoc node traversed by RecursiveASTVisitor.

> is there anything wrong with the current AST design or rather any notable 
> improvements by adding more nodes to the AST beside this one use case here?

I guess the use case here is "precisely communicating a selection in an IDE".
Expand-selection features and show-ast-structure features don't work in clangd 
for a similar reason.

Outside clangd I'm less familiar of course! Matchers, clang-tidy checks and 
refactorings spring to mind.
For instance, if you want to write a tool to rename/split an ObjC class, then 
something like `typeLoc(loc(asString("FooClass")))` would match all usages... 
except this one, so your tool would have a bug.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99975

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


[clang-tools-extra] 858a958 - [clang-query] Add check to prevent setting srcloc when no introspection is available.

2021-04-28 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2021-04-28T11:21:35+01:00
New Revision: 858a9583e1fed24aa57e5f2769f4117883264ceb

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

LOG: [clang-query] Add check to prevent setting srcloc when no introspection is 
available.

Checks if introspection support is available set output kind parser.
If it isn't present the auto complete will not suggest `srcloc` and an error 
query will be reported if a user tries to access it.

Reviewed By: steveire

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

Added: 


Modified: 
clang-tools-extra/clang-query/Query.h
clang-tools-extra/clang-query/QueryParser.cpp
clang-tools-extra/unittests/clang-query/QueryParserTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-query/Query.h 
b/clang-tools-extra/clang-query/Query.h
index 38be29101c96a..f96bf196a6420 100644
--- a/clang-tools-extra/clang-query/Query.h
+++ b/clang-tools-extra/clang-query/Query.h
@@ -149,6 +149,7 @@ struct SetExclusiveOutputQuery : Query {
 QS.DiagOutput = false;
 QS.DetailedASTOutput = false;
 QS.PrintOutput = false;
+QS.SrcLocOutput = false;
 QS.*Var = true;
 return true;
   }

diff  --git a/clang-tools-extra/clang-query/QueryParser.cpp 
b/clang-tools-extra/clang-query/QueryParser.cpp
index b444162cfc0a8..b80ad04726bcd 100644
--- a/clang-tools-extra/clang-query/QueryParser.cpp
+++ b/clang-tools-extra/clang-query/QueryParser.cpp
@@ -11,6 +11,7 @@
 #include "QuerySession.h"
 #include "clang/ASTMatchers/Dynamic/Parser.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Tooling/NodeIntrospection.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include 
@@ -104,17 +105,19 @@ QueryRef QueryParser::parseSetBool(bool 
QuerySession::*Var) {
 
 template  QueryRef QueryParser::parseSetOutputKind() {
   StringRef ValStr;
-  unsigned OutKind = LexOrCompleteWord(this, ValStr)
- .Case("diag", OK_Diag)
- .Case("print", OK_Print)
- .Case("detailed-ast", OK_DetailedAST)
- .Case("srcloc", OK_SrcLoc)
- .Case("dump", OK_DetailedAST)
- .Default(~0u);
+  bool HasIntrospection = 
tooling::NodeIntrospection::hasIntrospectionSupport();
+  unsigned OutKind =
+  LexOrCompleteWord(this, ValStr)
+  .Case("diag", OK_Diag)
+  .Case("print", OK_Print)
+  .Case("detailed-ast", OK_DetailedAST)
+  .Case("srcloc", OK_SrcLoc, /*IsCompletion=*/HasIntrospection)
+  .Case("dump", OK_DetailedAST)
+  .Default(~0u);
   if (OutKind == ~0u) {
-return new InvalidQuery(
-"expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr +
-"'");
+return new InvalidQuery("expected 'diag', 'print', 'detailed-ast'" +
+StringRef(HasIntrospection ? ", 'srcloc'" : "") +
+" or 'dump', got '" + ValStr + "'");
   }
 
   switch (OutKind) {
@@ -125,7 +128,9 @@ template  QueryRef 
QueryParser::parseSetOutputKind() {
   case OK_Print:
 return new QueryType(&QuerySession::PrintOutput);
   case OK_SrcLoc:
-return new QueryType(&QuerySession::SrcLocOutput);
+if (HasIntrospection)
+  return new QueryType(&QuerySession::SrcLocOutput);
+return new InvalidQuery("'srcloc' output support is not available.");
   }
 
   llvm_unreachable("Invalid output kind");

diff  --git a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp 
b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
index 713a6c23848a6..06b0d7b365904 100644
--- a/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
+++ b/clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
@@ -9,6 +9,7 @@
 #include "QueryParser.h"
 #include "Query.h"
 #include "QuerySession.h"
+#include "clang/Tooling/NodeIntrospection.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "gtest/gtest.h"
 
@@ -59,6 +60,8 @@ TEST_F(QueryParserTest, Quit) {
 }
 
 TEST_F(QueryParserTest, Set) {
+
+  bool HasIntrospection = 
tooling::NodeIntrospection::hasIntrospectionSupport();
   QueryRef Q = parse("set");
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("expected variable name", cast(Q)->ErrStr);
@@ -69,8 +72,13 @@ TEST_F(QueryParserTest, Set) {
 
   Q = parse("set output");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got ''",
-cast(Q)->ErrStr);
+  if (HasIntrospection)
+EXPECT_EQ(
+"expected 'diag', 'print', 'detailed-ast', 'srcloc' or 'dump', got ''",
+cast(Q)->ErrStr);
+  else
+EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got ''",
+  cast(Q)->ErrStr);
 
   Q = parse("set bind-root true foo");
 

[PATCH] D101365: [clang-query] Add check to prevent setting srcloc when no introspection is available.

2021-04-28 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG858a9583e1fe: [clang-query] Add check to prevent setting 
srcloc when no introspection is… (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101365

Files:
  clang-tools-extra/clang-query/Query.h
  clang-tools-extra/clang-query/QueryParser.cpp
  clang-tools-extra/unittests/clang-query/QueryParserTest.cpp

Index: clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
===
--- clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
+++ clang-tools-extra/unittests/clang-query/QueryParserTest.cpp
@@ -9,6 +9,7 @@
 #include "QueryParser.h"
 #include "Query.h"
 #include "QuerySession.h"
+#include "clang/Tooling/NodeIntrospection.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "gtest/gtest.h"
 
@@ -59,6 +60,8 @@
 }
 
 TEST_F(QueryParserTest, Set) {
+
+  bool HasIntrospection = tooling::NodeIntrospection::hasIntrospectionSupport();
   QueryRef Q = parse("set");
   ASSERT_TRUE(isa(Q));
   EXPECT_EQ("expected variable name", cast(Q)->ErrStr);
@@ -69,8 +72,13 @@
 
   Q = parse("set output");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got ''",
-cast(Q)->ErrStr);
+  if (HasIntrospection)
+EXPECT_EQ(
+"expected 'diag', 'print', 'detailed-ast', 'srcloc' or 'dump', got ''",
+cast(Q)->ErrStr);
+  else
+EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got ''",
+  cast(Q)->ErrStr);
 
   Q = parse("set bind-root true foo");
   ASSERT_TRUE(isa(Q));
@@ -78,8 +86,13 @@
 
   Q = parse("set output foo");
   ASSERT_TRUE(isa(Q));
-  EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got 'foo'",
-cast(Q)->ErrStr);
+  if (HasIntrospection)
+EXPECT_EQ("expected 'diag', 'print', 'detailed-ast', 'srcloc' or 'dump', "
+  "got 'foo'",
+  cast(Q)->ErrStr);
+  else
+EXPECT_EQ("expected 'diag', 'print', 'detailed-ast' or 'dump', got 'foo'",
+  cast(Q)->ErrStr);
 
   Q = parse("set output dump");
   ASSERT_TRUE(isa(Q));
@@ -217,8 +230,10 @@
   EXPECT_EQ("output ", Comps[0].TypedText);
   EXPECT_EQ("output", Comps[0].DisplayText);
 
+  bool HasIntrospection = tooling::NodeIntrospection::hasIntrospectionSupport();
+
   Comps = QueryParser::complete("enable output ", 14, QS);
-  ASSERT_EQ(5u, Comps.size());
+  ASSERT_EQ(HasIntrospection ? 5u : 4u, Comps.size());
 
   EXPECT_EQ("diag ", Comps[0].TypedText);
   EXPECT_EQ("diag", Comps[0].DisplayText);
@@ -226,10 +241,12 @@
   EXPECT_EQ("print", Comps[1].DisplayText);
   EXPECT_EQ("detailed-ast ", Comps[2].TypedText);
   EXPECT_EQ("detailed-ast", Comps[2].DisplayText);
-  EXPECT_EQ("srcloc ", Comps[3].TypedText);
-  EXPECT_EQ("srcloc", Comps[3].DisplayText);
-  EXPECT_EQ("dump ", Comps[4].TypedText);
-  EXPECT_EQ("dump", Comps[4].DisplayText);
+  if (HasIntrospection) {
+EXPECT_EQ("srcloc ", Comps[3].TypedText);
+EXPECT_EQ("srcloc", Comps[3].DisplayText);
+  }
+  EXPECT_EQ("dump ", Comps[HasIntrospection ? 4 : 3].TypedText);
+  EXPECT_EQ("dump", Comps[HasIntrospection ? 4 : 3].DisplayText);
 
   Comps = QueryParser::complete("set traversal ", 14, QS);
   ASSERT_EQ(2u, Comps.size());
Index: clang-tools-extra/clang-query/QueryParser.cpp
===
--- clang-tools-extra/clang-query/QueryParser.cpp
+++ clang-tools-extra/clang-query/QueryParser.cpp
@@ -11,6 +11,7 @@
 #include "QuerySession.h"
 #include "clang/ASTMatchers/Dynamic/Parser.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Tooling/NodeIntrospection.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include 
@@ -104,17 +105,19 @@
 
 template  QueryRef QueryParser::parseSetOutputKind() {
   StringRef ValStr;
-  unsigned OutKind = LexOrCompleteWord(this, ValStr)
- .Case("diag", OK_Diag)
- .Case("print", OK_Print)
- .Case("detailed-ast", OK_DetailedAST)
- .Case("srcloc", OK_SrcLoc)
- .Case("dump", OK_DetailedAST)
- .Default(~0u);
+  bool HasIntrospection = tooling::NodeIntrospection::hasIntrospectionSupport();
+  unsigned OutKind =
+  LexOrCompleteWord(this, ValStr)
+  .Case("diag", OK_Diag)
+  .Case("print", OK_Print)
+  .Case("detailed-ast", OK_DetailedAST)
+  .Case("srcloc", OK_SrcLoc, /*IsCompletion=*/HasIntrospection)
+  .Case("dump", OK_DetailedAST)
+  .Default(~0u);
   if (OutKind == ~0u) {
-return new InvalidQuery(
-"expected 'diag', 'print', 'detailed-ast' or 'dump', got '" + ValStr +
-"'");
+return new InvalidQuery("expected 'diag', 'print', 'detailed-ast'" +
+

[PATCH] D100980: [OpenCL] Allow use of double type without extension pragma

2021-04-28 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D100980#2722112 , @azabaznov wrote:

> In D100980#2719322 , @Anastasia 
> wrote:
>
>> In D100980#2719196 , @azabaznov 
>> wrote:
>>
 When the pragma is parsed we can't know why it is in the code to be able 
 to issue any warning.
>>>
>>> I mean diagnose once when, for example in your particular case, double type 
>>> is parsed.  Does it require much effort? I think this warning might be 
>>> useful for developers who already rely on pragma usage in their kernels.
>>
>> I am not sure I understand your suggestion. Could you show an example 
>> perhaps?
>
> All right. Currently, what we do have for OpenCL C < 1.2  
> (https://godbolt.org/z/rjYWMj7v1):
>
>   :6:5: error: use of type 'double' requires cl_khr_fp64 support
>   double d;
>   ^
>   1 error generated.
>
> What I suggest is to have:
>
>   :6:5: warning: pragma enable is no longer required for use of type 
> 'double'
>   double d;
>   ^
>   1 warning generated.
>
> We can issue the warning if certain flag is provided for example. Does it 
> make sense?

Not sure what do we want to achieve with this? Do you want to point out that 
the code might be somehow less portable let's say between clang revisions, etc? 
I think we could do it as it should not be too complicated but adds a bit extra 
complexity into the command line interface.


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

https://reviews.llvm.org/D100980

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


[PATCH] D100980: [OpenCL] Allow use of double type without extension pragma

2021-04-28 Thread Anton Zabaznov via Phabricator via cfe-commits
azabaznov added a comment.

> Not sure what do we want to achieve with this? Do you want to point out that 
> the code might be somehow less portable let's say between clang revisions, 
> etc?

My main worry is that you are changing the behaviour here: kernels which fail 
to compile will compile successfully. I suggest not to do it silently but issue 
a warning/note instead.


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

https://reviews.llvm.org/D100980

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


[PATCH] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2021-04-28 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added a comment.
This revision is now accepted and ready to land.

This is a pretty straightforward cleanup now, which adds additional 
functionality by deferring work to CMake.  There are a couple of minor points 
about inconsistent quoting but this seems good otherwise.




Comment at: clang-tools-extra/clang-doc/tool/CMakeLists.txt:26
 install(FILES ../assets/index.js
-  DESTINATION share/clang
+  DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
   COMPONENT clang-doc)

Why are these quoted but other uses not?



Comment at: flang/CMakeLists.txt:442
   install(DIRECTORY include/flang
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 COMPONENT flang-headers

Why is this quoted but other uses not?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

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


[PATCH] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2021-04-28 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added inline comments.



Comment at: clang-tools-extra/clang-doc/tool/CMakeLists.txt:26
 install(FILES ../assets/index.js
-  DESTINATION share/clang
+  DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
   COMPONENT clang-doc)

compnerd wrote:
> Why are these quoted but other uses not?
I confess I have no clue when quoting is required or advisable with CMake. I 
started out converting things by hand and then did some auto-conversions, this 
must have been one of the by-hand ones.

Happy to normalize either way, just tell me which one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

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


[PATCH] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2021-04-28 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 341072.
Ericson2314 added a comment.

Quote variable usages


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

Files:
  clang-tools-extra/clang-doc/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/find-all-symbols/tool/CMakeLists.txt
  clang-tools-extra/clang-include-fixer/tool/CMakeLists.txt
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/tool/CMakeLists.txt
  clang-tools-extra/modularize/CMakeLists.txt
  clang/CMakeLists.txt
  clang/cmake/modules/AddClang.cmake
  clang/tools/c-index-test/CMakeLists.txt
  clang/tools/clang-format/CMakeLists.txt
  clang/tools/clang-rename/CMakeLists.txt
  clang/tools/libclang/CMakeLists.txt
  clang/tools/scan-build/CMakeLists.txt
  clang/tools/scan-view/CMakeLists.txt
  clang/utils/hmaptool/CMakeLists.txt
  flang/CMakeLists.txt
  flang/cmake/modules/AddFlang.cmake
  flang/tools/f18/CMakeLists.txt
  flang/tools/flang-driver/CMakeLists.txt
  libc/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/cmake/Modules/HandleLibCXXABI.cmake
  libcxx/include/CMakeLists.txt
  libcxx/src/CMakeLists.txt
  libcxxabi/CMakeLists.txt
  libunwind/CMakeLists.txt
  libunwind/src/CMakeLists.txt
  lld/CMakeLists.txt
  lld/cmake/modules/AddLLD.cmake
  lld/tools/lld/CMakeLists.txt
  lldb/CMakeLists.txt
  lldb/cmake/modules/AddLLDB.cmake
  lldb/cmake/modules/LLDBConfig.cmake
  mlir/CMakeLists.txt
  mlir/cmake/modules/AddMLIR.cmake
  openmp/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt
  openmp/tools/multiplex/CMakeLists.txt
  polly/CMakeLists.txt
  polly/cmake/CMakeLists.txt
  polly/lib/External/CMakeLists.txt
  pstl/CMakeLists.txt

Index: pstl/CMakeLists.txt
===
--- pstl/CMakeLists.txt
+++ pstl/CMakeLists.txt
@@ -7,6 +7,8 @@
 #===--===##
 cmake_minimum_required(VERSION 3.13.4)
 
+include(GNUInstallDirs)
+
 set(PARALLELSTL_VERSION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/pstl/internal/pstl_config.h")
 file(STRINGS "${PARALLELSTL_VERSION_FILE}" PARALLELSTL_VERSION_SOURCE REGEX "#define _PSTL_VERSION .*$")
 string(REGEX REPLACE "#define _PSTL_VERSION (.*)$" "\\1" PARALLELSTL_VERSION_SOURCE "${PARALLELSTL_VERSION_SOURCE}")
@@ -86,10 +88,10 @@
   "${CMAKE_CURRENT_BINARY_DIR}/ParallelSTLConfigVersion.cmake"
 DESTINATION lib/cmake/ParallelSTL)
 install(DIRECTORY include/
-DESTINATION include
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
 PATTERN "*.in" EXCLUDE)
 install(FILES "${PSTL_CONFIG_SITE_PATH}"
-DESTINATION include)
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
 
 add_custom_target(install-pstl
   COMMAND "${CMAKE_COMMAND}" -P "${PROJECT_BINARY_DIR}/cmake_install.cmake" -DCOMPONENT=ParallelSTL)
Index: polly/lib/External/CMakeLists.txt
===
--- polly/lib/External/CMakeLists.txt
+++ polly/lib/External/CMakeLists.txt
@@ -290,7 +290,7 @@
 install(DIRECTORY
   ${ISL_SOURCE_DIR}/include/
   ${ISL_BINARY_DIR}/include/
-  DESTINATION include/polly
+  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/polly"
   FILES_MATCHING
   PATTERN "*.h"
   PATTERN "CMakeFiles" EXCLUDE
Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -83,14 +83,15 @@
 set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
 set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}")
 set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}")
+get_filename_component(base_includedir "${CMAKE_INSTALL_INCLUDEDIR}" ABSOLUTE BASE_DIR "${POLLY_INSTALL_PREFIX}")
 if (POLLY_BUNDLED_ISL)
   set(POLLY_CONFIG_INCLUDE_DIRS
-"${POLLY_INSTALL_PREFIX}/include"
-"${POLLY_INSTALL_PREFIX}/include/polly"
+"${base_includedir}"
+"${base_includedir}/polly"
 )
 else()
   set(POLLY_CONFIG_INCLUDE_DIRS
-"${POLLY_INSTALL_PREFIX}/include"
+"${base_includedir}"
 ${ISL_INCLUDE_DIRS}
 )
 endif()
@@ -100,12 +101,12 @@
 foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS)
   get_target_property(tgt_type ${tgt} TYPE)
   if (tgt_type STREQUAL "EXECUTABLE")
-set(tgt_prefix "bin/")
+set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/")
   else()
-set(tgt_prefix "lib/")
+set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/")
   endif()
 
-  set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$")
+  set(tgt_path "${tgt_prefix}$")
   file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path})
 
   if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY")
Index: polly/CMakeLists.txt
===
--- polly/CMakeLists.txt
+++ polly/CMakeLists.txt
@@ -2,7 +2,11 

[PATCH] D99484: Use `GNUInstallDirs` to support custom installation dirs.

2021-04-28 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 added inline comments.



Comment at: clang-tools-extra/clang-doc/tool/CMakeLists.txt:26
 install(FILES ../assets/index.js
-  DESTINATION share/clang
+  DESTINATION "${CMAKE_INSTALL_DATADIR}/clang"
   COMPONENT clang-doc)

Ericson2314 wrote:
> compnerd wrote:
> > Why are these quoted but other uses not?
> I confess I have no clue when quoting is required or advisable with CMake. I 
> started out converting things by hand and then did some auto-conversions, 
> this must have been one of the by-hand ones.
> 
> Happy to normalize either way, just tell me which one.
I looked it up, 
https://stackoverflow.com/questions/35847655/when-should-i-quote-cmake-variables
 says I'm slightly better off quoting all of these so I did.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99484

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


[PATCH] D89013: [libcxx] Support per-target __config_site in per-target runtime build

2021-04-28 Thread Petr Hosek via Phabricator via cfe-commits
phosek updated this revision to Diff 341088.
Herald added a subscriber: arichardson.
Herald added a project: libc++abi.
Herald added a reviewer: libc++abi.
This revision now requires review to proceed.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D89013

Files:
  clang/lib/Driver/ToolChains/Fuchsia.cpp
  clang/lib/Driver/ToolChains/Gnu.cpp
  
clang/test/Driver/Inputs/basic_fuchsia_tree/include/aarch64-unknown-fuchsia/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_fuchsia_tree/include/riscv64-unknown-fuchsia/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_fuchsia_tree/include/x86_64-unknown-fuchsia/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_linux_libcxx_tree/usr/include/x86_64-unknown-linux-gnu/c++/v1/.keep
  
clang/test/Driver/Inputs/basic_linux_libcxxv2_tree/usr/include/x86_64-unknown-linux-gnu/c++/v2/.keep
  
clang/test/Driver/Inputs/basic_linux_libstdcxx_libcxxv2_tree/usr/include/x86_64-unknown-linux-gnu/c++/v2/.keep
  clang/test/Driver/fuchsia.cpp
  clang/test/Driver/linux-header-search.cpp
  libcxx/CMakeLists.txt
  libcxx/benchmarks/CMakeLists.txt
  libcxx/include/CMakeLists.txt
  libcxx/utils/libcxx/test/config.py
  libcxxabi/test/libcxxabi/test/config.py

Index: libcxxabi/test/libcxxabi/test/config.py
===
--- libcxxabi/test/libcxxabi/test/config.py
+++ libcxxabi/test/libcxxabi/test/config.py
@@ -69,6 +69,11 @@
 if not os.path.isdir(cxx_headers):
 self.lit_config.fatal("cxx_headers='%s' is not a directory."
   % cxx_headers)
+cxx_target_headers = os.path.join(
+os.path.dirname(os.path.dirname(cxx_headers)),
+self.get_lit_conf('target_triple', None), 'c++', 'v1')
+if os.path.isdir(cxx_target_headers):
+self.cxx.compile_flags += ['-I' + cxx_target_headers]
 self.cxx.compile_flags += ['-I' + cxx_headers]
 
 libcxxabi_headers = self.get_lit_conf(
Index: libcxx/utils/libcxx/test/config.py
===
--- libcxx/utils/libcxx/test/config.py
+++ libcxx/utils/libcxx/test/config.py
@@ -354,6 +354,11 @@
 self.cxx.compile_flags += ['-nostdinc++']
 if not os.path.isdir(cxx_headers):
 self.lit_config.fatal("cxx_headers='{}' is not a directory.".format(cxx_headers))
+cxx_target_headers = os.path.join(
+os.path.dirname(os.path.dirname(cxx_headers)),
+self.get_lit_conf('target_triple', None), 'c++', 'v1')
+if os.path.isdir(cxx_target_headers):
+self.cxx.compile_flags += ['-I' + cxx_target_headers]
 self.cxx.compile_flags += ['-I' + cxx_headers]
 if self.libcxx_obj_root is not None:
 cxxabi_headers = os.path.join(self.libcxx_obj_root, 'include',
Index: libcxx/include/CMakeLists.txt
===
--- libcxx/include/CMakeLists.txt
+++ libcxx/include/CMakeLists.txt
@@ -209,9 +209,9 @@
   wctype.h
   )
 
-configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_DIR}/__config_site" @ONLY)
+configure_file("__config_site.in" "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site" @ONLY)
 
-set(_all_includes "${LIBCXX_GENERATED_INCLUDE_DIR}/__config_site")
+set(_all_includes "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site")
 foreach(f ${files})
   set(src "${CMAKE_CURRENT_SOURCE_DIR}/${f}")
   set(dst "${LIBCXX_GENERATED_INCLUDE_DIR}/${f}")
@@ -228,24 +228,26 @@
 add_dependencies(cxx-headers generate-cxx-headers ${LIBCXX_CXX_ABI_HEADER_TARGET})
 # TODO: Use target_include_directories once we figure out why that breaks the runtimes build
 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC" OR "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC")
-  target_compile_options(cxx-headers INTERFACE /I "${LIBCXX_GENERATED_INCLUDE_DIR}")
+  target_compile_options(cxx-headers INTERFACE /I "${LIBCXX_GENERATED_INCLUDE_DIR}"
+ INTERFACE /I "${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}")
 else()
-  target_compile_options(cxx-headers INTERFACE -I "${LIBCXX_GENERATED_INCLUDE_DIR}")
+  target_compile_options(cxx-headers INTERFACE -I${LIBCXX_GENERATED_INCLUDE_DIR}
+ INTERFACE -I${LIBCXX_GENERATED_INCLUDE_TARGET_DIR})
 endif()
 
 if (LIBCXX_INSTALL_HEADERS)
   foreach(file ${files})
 get_filename_component(dir ${file} DIRECTORY)
 install(FILES ${file}
-  DESTINATION include/c++/v1/${dir}
+  DESTINATION ${LIBCXX_INSTALL_INCLUDE_DIR}/${dir}
   COMPONENT cxx-headers
   PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
 )
   endforeach()
 
   # Install the generated __config_site.
-  install(FILES ${LIBCXX_GENERATED_INCLUDE_DIR}/__config_site
-DESTINATION include/c++/v1
+  install(FILES ${LIBCXX_GENERATED_INCLUDE_TARGET_DIR}/__config_site
+DESTINATION ${LIBCXX_INSTA

[PATCH] D101087: [OpenCL] Introduce new method for validating OpenCL target

2021-04-28 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.

Cool! Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101087

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


[PATCH] D101439: [clang-cl] Add parsing support for a bunch of new flags

2021-04-28 Thread Hans Wennborg via Phabricator via cfe-commits
hans created this revision.
hans added reviewers: thakis, rnk.
Herald added a subscriber: dang.
hans requested review of this revision.
Herald added a project: clang.

MSVC has added some new flags. Although they're not supported, this adds 
parsing support for them so clang-cl doesn't treat them as filenames.

Except for /fsanitize=address which we do support. (clang-cl already exposes 
the -fsanitize= option, but this allows using the MSVC-spelling with a slash.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101439

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
@@ -56,6 +56,9 @@
 // fpstrict-NOT: -menable-unsafe-fp-math
 // fpstrict-NOT: -ffast-math
 
+// RUN: %clang_cl /fsanitize=address -### -- %s 2>&1 | FileCheck 
-check-prefix=fsanitize_address %s
+// fsanitize_address: -fsanitize=address
+
 // RUN: %clang_cl -### /FA -fprofile-instr-generate -- %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-INSTR-GENERATE %s
 // RUN: %clang_cl -### /FA -fprofile-instr-generate=/tmp/somefile.profraw -- 
%s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-INSTR-GENERATE-FILE %s
 // CHECK-PROFILE-INSTR-GENERATE: "-fprofile-instrument=clang" 
"--dependent-lib=clang_rt.profile{{[^"]*}}.lib"
@@ -425,6 +428,10 @@
 // RUN: /clr:pure \
 // RUN: /d2FH4 \
 // RUN: /docname \
+// RUN: /experimental:module \
+// RUN: /experimental:preprocessor \
+// RUN: /exportHeader /headerName:foo \
+// RUN: /headerUnit foo.h=foo.ifc /headerUnit:quote foo.h=foo.ifc 
/headerUnit:angle foo.h=foo.ifc \
 // RUN: /EHsc \
 // RUN: /F 42 \
 // RUN: /FA \
@@ -433,6 +440,8 @@
 // RUN: /FAs \
 // RUN: /FAu \
 // RUN: /favor:blend \
+// RUN: /fsanitize-address-use-after-return \
+// RUN: /fno-sanitize-address-vcasan-lib \
 // RUN: /Fifoo \
 // RUN: /Fmfoo \
 // RUN: /FpDebug\main.pch \
@@ -479,6 +488,10 @@
 // RUN: /Qspectre-load \
 // RUN: /Qspectre-load-cf \
 // RUN: /Qvec-report:2 \
+// RUN: /reference foo=foo.ifc /reference foo.ifc \
+// RUN: /sourceDependencies foo.json \
+// RUN: /sourceDependencies:directives foo.json \
+// RUN: /translateInclude \
 // RUN: /u \
 // RUN: /V \
 // RUN: /volatile:ms \
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5753,6 +5753,9 @@
 def _SLASH_fp_precise : CLFlag<"fp:precise">,
   HelpText<"">, Alias;
 def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, Alias;
+def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
+  HelpText<"Enable AddressSanitizer">,
+  Alias, AliasArgs<["address"]>;
 def _SLASH_GA : CLFlag<"GA">, Alias, AliasArgs<["local-exec"]>,
   HelpText<"Assume thread-local variables are defined in the executable">;
 def _SLASH_GR : CLFlag<"GR">, HelpText<"Emit RTTI data (default)">;
@@ -6107,8 +6110,12 @@
 def _SLASH_clr : CLJoined<"clr">;
 def _SLASH_d2 : CLJoined<"d2">;
 def _SLASH_doc : CLJoined<"doc">;
+def _SLASH_experimental : CLJoined<"experimental:">;
+def _SLASH_exportHeader : CLFlag<"exportHeader">;
 def _SLASH_FA_joined : CLJoined<"FA">;
 def _SLASH_favor : CLJoined<"favor">;
+def _SLASH_fsanitize_address_use_after_return : 
CLJoined<"fsanitize-address-use-after-return">;
+def _SLASH_fno_sanitize_address_vcasan_lib : 
CLJoined<"fno-sanitize-address-vcasan-lib">;
 def _SLASH_F : CLJoinedOrSeparate<"F">;
 def _SLASH_Fm : CLJoined<"Fm">;
 def _SLASH_Fr : CLJoined<"Fr">;
@@ -6127,6 +6134,10 @@
 def _SLASH_GT : CLFlag<"GT">;
 def _SLASH_GZ : CLFlag<"GZ">;
 def _SLASH_H : CLFlag<"H">;
+def _SLASH_headername : CLJoined<"headerName:">;
+def _SLASH_headerUnit : CLJoinedOrSeparate<"headerUnit">;
+def _SLASH_headerUnitAngle : CLJoinedOrSeparate<"headerUnit:angle">;
+def _SLASH_headerUnitQuote : CLJoinedOrSeparate<"headerUnit:quote">;
 def _SLASH_homeparams : CLFlag<"homeparams">;
 def _SLASH_hotpatch : CLFlag<"hotpatch">;
 def _SLASH_kernel : CLFlag<"kernel">;
@@ -6142,6 +6153,10 @@
 def _SLASH_Qspectre_load : CLFlag<"Qspectre-load">;
 def _SLASH_Qspectre_load_cf : CLFlag<"Qspectre-load-cf">;
 def _SLASH_Qvec_report : CLJoined<"Qvec-report">;
+def _SLASH_reference : CLJoinedOrSeparate<"reference">;
+def _SLASH_sourceDependencies : CLJoinedOrSeparate<"sourceDependencies">;
+def _SLASH_sourceDependenciesDirectives : 
CLJoinedOrSeparate<"sourceDependencies:directives">;
+def _SLASH_translateInclude : CLFlag<"translateInclude">;
 def _SLASH_u : CLFlag<"u">;
 def _SLASH_V : CLFlag<"V">;
 def _SLASH_WL : CLFlag<"WL">;


Index: clang/test/Driver/cl-options.c
===
--- clang/test/Driver/cl-options.c
+++ clang/test/Driver/cl-options.c
@@ -56,6 +56,9 @

[PATCH] D100980: [OpenCL] Allow use of double type without extension pragma

2021-04-28 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D100980#2722207 , @azabaznov wrote:

>> Not sure what do we want to achieve with this? Do you want to point out that 
>> the code might be somehow less portable let's say between clang revisions, 
>> etc?
>
> My main worry is that you are changing the behaviour here: kernels which fail 
> to compile will compile successfully. I suggest not to do it silently but 
> issue a warning/note instead.

Ok, this should technically not be an issue as it does not break backward 
compatibility but it could still be useful for the portability reasons 
especially in the transition period while we still accept but deprecate 
pragmas. Perhaps we could even use such a flag elsewhere for similar purposes.

However, what I don't like about it is that we will still need to check for 
whether the pragma is enabled in the compiler source code so it won't be 
simpler. Anyway I guess the best way is to prepare a patch and then we can take 
a look and decide whether we can go ahead with it or stick to an old solution 
with pragma for the time being.


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

https://reviews.llvm.org/D100980

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


[PATCH] D100742: [clangd] Parameter hints for dependent calls

2021-04-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/clangd/InlayHints.cpp:56
+auto CalleeDecls = Resolver->resolveCalleeOfCallExpr(E);
+if (CalleeDecls.empty())
+  return true;

should we conservatively make this size != 1?
e.g. if the callee ends up being an OverloadExpr of some kind, picking the 
first overload seems pretty arbitrary and maybe misleading.



Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:247
 
-TEST(ParameterHints, DependentCall) {
-  // FIXME: This doesn't currently produce a hint but should.
+TEST(ParameterHints, DependentCalls) {
   assertParameterHints(R"cpp(

can we add a test involving overloads?

i think:
```
void foo(int anInt);
void foo(double aDouble);
template  go {
  foo(T{}); // expect no hints
}
```



Comment at: clang-tools-extra/clangd/unittests/InlayHintTests.cpp:264
+// FIXME: This one does not work yet.
+A::static_member($par3[[t]]);
   }

nridge wrote:
> This is an interesting case. Clang builds a `CXXDependentScopeMemberExpr` for 
> this callee, but `HeuristicResolver` [currently 
> assumes](https://searchfox.org/llvm/rev/92880ab7a2b2145f0605f367cd6d53d6892903c3/clang-tools-extra/clangd/HeuristicResolver.cpp#108)
>  that such expressions are only built for non-static member accesses (since, 
> for static member accesses, clang usually builds a 
> `DependentScopeDeclRefExpr` instead).
> 
> The `CXXDependentScopeMemberExpr` is created 
> [here](https://searchfox.org/llvm/rev/92880ab7a2b2145f0605f367cd6d53d6892903c3/clang/lib/Sema/SemaTemplate.cpp#757),
>  and I note the dependence on whether the //enclosing context// is an 
> [instance 
> method](https://searchfox.org/llvm/rev/92880ab7a2b2145f0605f367cd6d53d6892903c3/clang/lib/Sema/SemaTemplate.cpp#750).
>  I guess it must think that, after instantiation, `A` could turn out to be 
> a base class, and thus this could be a "non-static member access with 
> qualifier".
> 
> I don't see anything obvious on `CXXDependentScopeMemberExpr` that would let 
> us tell apart "definitely a non-static member" from "maybe static, maybe 
> non-static", so I guess the appropriate solution is to drop the 
> `NonStaticFilter` 
> [here](https://searchfox.org/llvm/rev/92880ab7a2b2145f0605f367cd6d53d6892903c3/clang-tools-extra/clangd/HeuristicResolver.cpp#108)
>  altogether?
> I guess it must think that, after instantiation, A could turn out to be a 
> base class, and thus this could be a "non-static member access with 
> qualifier".

Argh, C++ is so tricky :-( That sounds plausible to me.

> drop the NonStaticFilter here altogether

Yeah. The other thing is that `some_instance.some_static_member` is perfectly 
legal I think? So the NonStaticFilter is probably not correct anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100742

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


[PATCH] D97265: [clang] Allow clang-check to customize analyzer output file or dir name

2021-04-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Really sorry about the long delays. Working on clearing my backlog...
This seems reasonable to me!


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

https://reviews.llvm.org/D97265

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


[PATCH] D99350: [OPENMP]Fix PR49649: The introduction of $ref globals is not always valid.

2021-04-28 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In D99350#2721724 , @jdoerfert wrote:

> The cast was never the problem but the fact that the `$ref` lives in the 
> global address space while the global value might be in the shared one.
> D101030  gives a way out here by not 
> creating `$ref` variables if there is no host version of a global. This makes 
> sense because we don't need to copy to the global ever.
> So, users can have static globals in shared memory by ensuring they are not 
> host accessible. We probably should emit an error if they try to do global in 
> shared memory
> that has a host version.
>
> Long story short, this cast won't help.

I checked that this cast helps to fix a problem with ptxas with shared/global 
memory refs. I'm not saying that this is the best solution, but better to have 
a fix while the final solution is not landed. Plus. maybe, it will fix some 
other potential issues until the `$ref`s will go away. Maybe need a new 
attribute to avoid early optimization of the internal vars.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99350

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


[PATCH] D100972: [clang-tidy] cppcoreguidelines-avoid-non-const-global-variables: add fixes to checks

2021-04-28 Thread Marco Gartmann via Phabricator via cfe-commits
mgartmann updated this revision to Diff 341155.
mgartmann added a comment.

Replaced string comparison to check if a character is a space with 
`std::isspace()`. 
Added test case for this scenario.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100972

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidNonConstGlobalVariablesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-non-const-global-variables.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-non-const-global-variables.cpp
@@ -2,20 +2,33 @@
 
 int nonConstInt = 0;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'nonConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-FIXES: const int nonConstInt = 0;
 
 int &nonConstIntReference = nonConstInt;
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: variable 'nonConstIntReference' provides global access to a non-const object; consider making the referenced data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-FIXES: const int &nonConstIntReference = nonConstInt;
 
 int *pointerToNonConstInt = &nonConstInt;
 // CHECK-MESSAGES: :[[@LINE-1]]:6: warning: variable 'pointerToNonConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
 // CHECK-MESSAGES: :[[@LINE-2]]:6: warning: variable 'pointerToNonConstInt' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-FIXES: const int *const pointerToNonConstInt = &nonConstInt;
+
+// clang-format off
+// because the space after * is intended.
+int * pointerToNonConstIntWithSpace = &nonConstInt;
+// clang-format on
+// CHECK-MESSAGES: :[[@LINE-2]]:7: warning: variable 'pointerToNonConstIntWithSpace' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-MESSAGES: :[[@LINE-3]]:7: warning: variable 'pointerToNonConstIntWithSpace' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-FIXES: const int *const pointerToNonConstIntWithSpace = &nonConstInt;
 
 int *const constPointerToNonConstInt = &nonConstInt;
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'constPointerToNonConstInt' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-FIXES: const int *const constPointerToNonConstInt = &nonConstInt;
 
 namespace namespace_name {
 int nonConstNamespaceInt = 0;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'nonConstNamespaceInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-FIXES: const int nonConstNamespaceInt = 0;
 
 const int constNamespaceInt = 0;
 } // namespace namespace_name
@@ -24,6 +37,7 @@
 
 const int *pointerToConstInt = &constInt;
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'pointerToConstInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-FIXES: const int *const pointerToConstInt = &constInt;
 
 const int *const constPointerToConstInt = &constInt;
 
@@ -39,6 +53,7 @@
 namespace {
 int nonConstAnonymousNamespaceInt = 0;
 // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'nonConstAnonymousNamespaceInt' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-FIXES: const int nonConstAnonymousNamespaceInt = 0;
 } // namespace
 
 class DummyClass {
@@ -53,27 +68,35 @@
 
 DummyClass nonConstClassInstance;
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: variable 'nonConstClassInstance' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
+// CHECK-FIXES: const DummyClass nonConstClassInstance;
 
 DummyClass *pointerToNonConstDummyClass = &nonConstClassInstance;
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: variable 'pointerToNonConstDummyClass' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]
 // CHECK-MESSAGES: 

[PATCH] D97955: [clang-tidy] Refactor loop-convert to bring most of the checking into matchers

2021-04-28 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.
Herald added a project: clang-tools-extra.

Ping?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97955

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


[clang] c835630 - [OPENMP]Fix PR49098: respect firstprivate of declare target variable.

2021-04-28 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2021-04-28T05:39:10-07:00
New Revision: c835630c25a4f9925517949579f66a43b113fbc9

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

LOG: [OPENMP]Fix PR49098: respect firstprivate of declare target variable.

Need to respect mapping/privatization of declare target variables in the
target regions if explicitly specified by the user.

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

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/target_firstprivate_codegen.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 2a45a095eb0fd..25ee46d95aa55 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2187,15 +2187,11 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool 
CheckScopeInfo,
   //
   if (VD && !VD->hasLocalStorage() &&
   (getCurCapturedRegion() || getCurBlock() || getCurLambda())) {
-if (isInOpenMPDeclareTargetContext()) {
-  // Try to mark variable as declare target if it is used in capturing
-  // regions.
-  if (LangOpts.OpenMP <= 45 &&
-  !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD))
-checkDeclIsAllowedInOpenMPTarget(nullptr, VD);
-  return nullptr;
-}
 if (isInOpenMPTargetExecutionDirective()) {
+  DSAStackTy::DSAVarData DVarTop =
+  DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
+  if (DVarTop.CKind != OMPC_unknown && DVarTop.RefExpr)
+return VD;
   // If the declaration is enclosed in a 'declare target' directive,
   // then it should not be captured.
   //
@@ -2220,6 +2216,14 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool 
CheckScopeInfo,
   if (Regions[CSI->OpenMPCaptureLevel] != OMPD_task)
 return VD;
 }
+if (isInOpenMPDeclareTargetContext()) {
+  // Try to mark variable as declare target if it is used in capturing
+  // regions.
+  if (LangOpts.OpenMP <= 45 &&
+  !OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD))
+checkDeclIsAllowedInOpenMPTarget(nullptr, VD);
+  return nullptr;
+}
   }
 
   if (CheckScopeInfo) {

diff  --git a/clang/test/OpenMP/target_firstprivate_codegen.cpp 
b/clang/test/OpenMP/target_firstprivate_codegen.cpp
index 8522cac3afa3c..3535371b1f60b 100644
--- a/clang/test/OpenMP/target_firstprivate_codegen.cpp
+++ b/clang/test/OpenMP/target_firstprivate_codegen.cpp
@@ -43,6 +43,9 @@ struct TT {
   tx X;
   ty Y;
 };
+#pragma omp declare target
+int ga = 5;
+#pragma omp end declare target
 
 // CHECK-DAG:  [[TT:%.+]] = type { i64, i8 }
 // CHECK-DAG:  [[TTII:%.+]] = type { i32, i32 }
@@ -52,9 +55,9 @@ struct TT {
 // TCHECK-DAG:  [[TTII:%.+]] = type { i32, i32 }
 // TCHECK-DAG:  [[S1:%.+]] = type { double }
 
-// CHECK-DAG:  [[FP_E:@__omp_offloading_firstprivate_.+_e_l76]] = internal 
global [[TTII]] zeroinitializer
-// CHECK-DAG:  [[SIZET:@.+]] = private unnamed_addr constant [2 x i{{32|64}}] 
[i[[SZ:32|64]] 4, i{{64|32}} {{8|4}}]
-// CHECK-DAG:  [[MAPT:@.+]] = private unnamed_addr constant [2 x i64] [i64 
288, i64 49]
+// CHECK-DAG:  [[FP_E:@__omp_offloading_firstprivate_.+_e_l79]] = internal 
global [[TTII]] zeroinitializer
+// CHECK-DAG:  [[SIZET:@.+]] = private unnamed_addr constant [3 x i{{32|64}}] 
[i[[SZ:32|64]] 4, i{{64|32}} {{8|4}}, i[[SZ:32|64]] 4]
+// CHECK-DAG:  [[MAPT:@.+]] = private unnamed_addr constant [3 x i64] [i64 
288, i64 49, i64 288]
 // CHECK-DAG:  [[MAPT2:@.+]] = private unnamed_addr constant [9 x i64] [i64 
288, i64 161, i64 800, i64 161, i64 161, i64 800, i64 800, i64 161, i64 161]
 // CHECK-DAG:  [[SIZET3:@.+]] = private unnamed_addr constant [2 x i{{32|64}}] 
[i{{32|64}} 0, i{{32|64}} 8]
 // CHECK-DAG:  [[MAPT3:@.+]] = private unnamed_addr constant [2 x i64] [i64 
32, i64 37]
@@ -76,7 +79,7 @@ int foo(int n, double *ptr) {
   const TT e = {n, n};
   int *p __attribute__ ((aligned (64))) = &a;
 
-#pragma omp target firstprivate(a, p)
+#pragma omp target firstprivate(a, p, ga)
   {
   }
 
@@ -91,8 +94,8 @@ int foo(int n, double *ptr) {
   // CHECK:  [[D:%.+]] = alloca [[TT]],
   // CHECK:  [[P:%.+]] = alloca i32*, align 64
   // CHECK:  [[ACAST:%.+]] = alloca i{{[0-9]+}},
-  // CHECK:  [[BASE_PTR_ARR:%.+]] = alloca [2 x i8*],
-  // CHECK:  [[PTR_ARR:%.+]] = alloca [2 x i8*],
+  // CHECK:  [[BASE_PTR_ARR:%.+]] = alloca [3 x i8*],
+  // CHECK:  [[PTR_ARR:%.+]] = alloca [3 x i8*],
   // CHECK:  [[A2CAST:%.+]] = alloca i{{[0-9]+}},
   // CHECK:  [[BASE_PTR_ARR2:%.+]] = alloca [9 x i8*],
   // CHECK:  [[PTR_ARR2:%.+]] = alloca [9 x i8*],
@@ -116,29 +119,37 @@ int foo(int n, double *ptr) {
   // CHECK-32:  store i{{[0-9]+}} [[AVAL]], i{{[0-9]+}}* [[ACAST]],
   // CHECK:  [[ACAST_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]

[PATCH] D99530: [OPENMP]Fix PR49098: respect firstprivate of declare target variable.

2021-04-28 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc835630c25a4: [OPENMP]Fix PR49098: respect firstprivate of 
declare target variable. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99530

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_firstprivate_codegen.cpp

Index: clang/test/OpenMP/target_firstprivate_codegen.cpp
===
--- clang/test/OpenMP/target_firstprivate_codegen.cpp
+++ clang/test/OpenMP/target_firstprivate_codegen.cpp
@@ -43,6 +43,9 @@
   tx X;
   ty Y;
 };
+#pragma omp declare target
+int ga = 5;
+#pragma omp end declare target
 
 // CHECK-DAG:  [[TT:%.+]] = type { i64, i8 }
 // CHECK-DAG:  [[TTII:%.+]] = type { i32, i32 }
@@ -52,9 +55,9 @@
 // TCHECK-DAG:  [[TTII:%.+]] = type { i32, i32 }
 // TCHECK-DAG:  [[S1:%.+]] = type { double }
 
-// CHECK-DAG:  [[FP_E:@__omp_offloading_firstprivate_.+_e_l76]] = internal global [[TTII]] zeroinitializer
-// CHECK-DAG:  [[SIZET:@.+]] = private unnamed_addr constant [2 x i{{32|64}}] [i[[SZ:32|64]] 4, i{{64|32}} {{8|4}}]
-// CHECK-DAG:  [[MAPT:@.+]] = private unnamed_addr constant [2 x i64] [i64 288, i64 49]
+// CHECK-DAG:  [[FP_E:@__omp_offloading_firstprivate_.+_e_l79]] = internal global [[TTII]] zeroinitializer
+// CHECK-DAG:  [[SIZET:@.+]] = private unnamed_addr constant [3 x i{{32|64}}] [i[[SZ:32|64]] 4, i{{64|32}} {{8|4}}, i[[SZ:32|64]] 4]
+// CHECK-DAG:  [[MAPT:@.+]] = private unnamed_addr constant [3 x i64] [i64 288, i64 49, i64 288]
 // CHECK-DAG:  [[MAPT2:@.+]] = private unnamed_addr constant [9 x i64] [i64 288, i64 161, i64 800, i64 161, i64 161, i64 800, i64 800, i64 161, i64 161]
 // CHECK-DAG:  [[SIZET3:@.+]] = private unnamed_addr constant [2 x i{{32|64}}] [i{{32|64}} 0, i{{32|64}} 8]
 // CHECK-DAG:  [[MAPT3:@.+]] = private unnamed_addr constant [2 x i64] [i64 32, i64 37]
@@ -76,7 +79,7 @@
   const TT e = {n, n};
   int *p __attribute__ ((aligned (64))) = &a;
 
-#pragma omp target firstprivate(a, p)
+#pragma omp target firstprivate(a, p, ga)
   {
   }
 
@@ -91,8 +94,8 @@
   // CHECK:  [[D:%.+]] = alloca [[TT]],
   // CHECK:  [[P:%.+]] = alloca i32*, align 64
   // CHECK:  [[ACAST:%.+]] = alloca i{{[0-9]+}},
-  // CHECK:  [[BASE_PTR_ARR:%.+]] = alloca [2 x i8*],
-  // CHECK:  [[PTR_ARR:%.+]] = alloca [2 x i8*],
+  // CHECK:  [[BASE_PTR_ARR:%.+]] = alloca [3 x i8*],
+  // CHECK:  [[PTR_ARR:%.+]] = alloca [3 x i8*],
   // CHECK:  [[A2CAST:%.+]] = alloca i{{[0-9]+}},
   // CHECK:  [[BASE_PTR_ARR2:%.+]] = alloca [9 x i8*],
   // CHECK:  [[PTR_ARR2:%.+]] = alloca [9 x i8*],
@@ -116,29 +119,37 @@
   // CHECK-32:  store i{{[0-9]+}} [[AVAL]], i{{[0-9]+}}* [[ACAST]],
   // CHECK:  [[ACAST_VAL:%.+]] = load i{{[0-9]+}}, i{{[0-9]+}}* [[ACAST]],
   // CHECK:  [[P_PTR:%.+]] = load i32*, i32** [[P]], align 64
-  // CHECK:  [[BASE_PTR_GEP:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BASE_PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
+  // CHECK:  [[BASE_PTR_GEP:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BASE_PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
   // CHECK:  [[ACAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP]] to i{{[0-9]+}}*
   // CHECK:  store i{{[0-9]+}} [[ACAST_VAL]], i{{[0-9]+}}* [[ACAST_TOPTR]],
-  // CHECK:  [[PTR_GEP:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
+  // CHECK:  [[PTR_GEP:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
   // CHECK:  [[ACAST_TOPTR2:%.+]] = bitcast i8** [[PTR_GEP]] to i{{[0-9]+}}*
   // CHECK:  store i{{[0-9]+}} [[ACAST_VAL]], i{{[0-9]+}}* [[ACAST_TOPTR2]],
-  // CHECK:  [[BASE_PTR_GEP:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BASE_PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
+  // CHECK:  [[BASE_PTR_GEP:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[BASE_PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
   // CHECK:  [[PCAST_TOPTR:%.+]] = bitcast i8** [[BASE_PTR_GEP]] to i32***
   // CHECK:  store i32** [[P]], i32*** [[PCAST_TOPTR]],
-  // CHECK:  [[PTR_GEP:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
+  // CHECK:  [[PTR_GEP:%.+]] = getelementptr inbounds [3 x i8*], [3 x i8*]* [[PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 1
   // CHECK:  [[PCAST_TOPTR2:%.+]] = bitcast i8** [[PTR_GEP]] to i32**
   // CHECK:  store i32* [[P_PTR]], i32** [[PCAST_TOPTR2]],
-  // CHECK:  [[BASE_PTR_GEP_ARG:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[BASE_PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
-  // CHECK:  [[PTR_GEP_ARG:%.+]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[PTR_ARR]], i{{[0-9]+}} 0, i{{[0-9]+}} 0
-  // CHECK:  {{.+}} = call i32 @__tgt_target_mapper(%struct.ident_t* @{{.+}}, i64 -1, {{.+}}, i32 2, i8** [[BASE_PTR_GEP_ARG]], i8** [[PTR_GEP_ARG]], i[[SZ]]* getelementptr inbounds ([2 x i[[SZ]]], [2 x i[[SZ]]]* [[SIZET]], i32 0, i32

[PATCH] D97121: [clang-tidy] Add a Standalone diagnostics mode to clang-tidy

2021-04-28 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 341167.
njames93 added a comment.

Rebase and fix up new checks added and changes to tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D97121

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp
  
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/PreferMemberInitializerCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tools-extra/clang-tidy/misc/UniqueptrResetReleaseCheck.cpp
  clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
  clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
  clang-tools-extra/clang-tidy/performance/TypePromotionInMathFnCheck.cpp
  clang-tools-extra/clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
  clang-tools-extra/clang-tidy/utils/IncludeInserter.h
  clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
  clang-tools-extra/clangd/ParsedAST.cpp
  clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
  clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/IncludeInserterTest.cpp
@@ -30,8 +30,10 @@
 public:
   IncludeInserterCheckBase(StringRef CheckName, ClangTidyContext *Context,
utils::IncludeSorter::IncludeStyle Style =
-   utils::IncludeSorter::IS_Google)
-  : ClangTidyCheck(CheckName, Context), Inserter(Style) {}
+   utils::IncludeSorter::IS_Google,
+   bool SelfContainedDiags = false)
+  : ClangTidyCheck(CheckName, Context),
+Inserter(Style, SelfContainedDiags) {}
 
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override {
@@ -85,6 +87,19 @@
   }
 };
 
+class MultipleHeaderSingleInserterCheck : public IncludeInserterCheckBase {
+public:
+  MultipleHeaderSingleInserterCheck(StringRef CheckName,
+ClangTidyContext *Context)
+  : IncludeInserterCheckBase(CheckName, Context,
+ utils::IncludeSorter::IS_Google,
+ /*SelfContainedDiags=*/true) {}
+
+  std::vector headersToInclude() const override {
+return {"path/to/header.h", "path/to/header2.h", "path/to/header.h"};
+  }
+};
+
 class CSystemIncludeInserterCheck : public IncludeInserterCheckBase {
 public:
   CSystemIncludeInserterCheck(StringRef CheckName, ClangTidyContext *Context)
@@ -246,6 +261,41 @@
 PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
 }
 
+TEST(IncludeInserterTest, InsertMultipleIncludesNoDeduplicate) {
+  const char *PreCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include 
+#include 
+
+#include "path/to/a/header.h"
+
+void foo() {
+  int a = 0;
+})";
+  // FIXME: ClangFormat bug - https://bugs.llvm.org/show_bug.cgi?id=49298
+  // clang-format off
+  const char *PostCode = R"(
+#include "clang_tidy/tests/insert_includes_test_header.h"
+
+#include 
+#include 
+
+#include "path/to/a/header.h"
+#include "path/to/header.h"
+#include "path/to/header2.h"
+#include "path/to/header.h"
+
+void foo() {
+  int a = 0;
+})";
+  // clang-format on
+
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, "clang_tidy/tests/insert_includes_test_input2.cc"));
+}
+
 TEST(IncludeInserterTest, InsertBeforeFirstNonSystemInclude) {
   const char *PreCode = R"(
 #include "clang_tidy/tests/insert_includes_test_header.h"
Index: clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
===
--- clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -519,6 +519,67 @@
   ElementsAre(Diag(Main.range(), "do not use 'else' after 'return'")));
 }
 
+TEST(DiagnosticTest, ClangTidySelfContainedDiags) {
+  Annotations Main(R"cpp($MathHeader[[]]
+struct Foo{
+  int A, B;
+  Foo()$Fix[[]] {
+$A[[A = 1;]]
+$B[[B = 1;]]
+  }
+};
+vo

[PATCH] D100919: [AArch64] Support customizing stack protector guard

2021-04-28 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.h:385
   /// On x86 this can be "fs" or "gs".
+  /// On AArch64 this can be any value of llvm::AArch64SysReg::SysReg.
   std::string StackProtectorGuardReg;

This is now used for TLS on x86 and sysreg on AArch64 so how about:
```
  /// The TLS base register when StackProtectorGuard is "tls", or register
  /// used to store the stack canary for "sysreg".
  /// On x86 this can be "fs" or "gs".
  /// On AArch64 this can only be "sp_el0".
```




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:3110
+}
+if (EffectiveTriple.isAArch64() && Value != "sysreg" && Value != "global") 
{
+  D.Diag(diag::err_drv_invalid_value_with_suggestion)

nickdesaulniers wrote:
> DavidSpickett wrote:
> > Shouldn't this also allow "tls"? At least that's what the previous code 
> > works out to, I don't know if that actually works on AArch64 or if it just 
> > didn't error.
> I don't think so; GCC seems to support `tls` for x86 but not for aarch64.
> https://godbolt.org/z/6WjEPfhT5
Fair enough, seems unlikely it would work in any case.



Comment at: llvm/test/CodeGen/AArch64/stack-guard-sysreg.ll:20
+; RUN:   --stack-protector-guard-offset=-1 -o - | \
+; RUN: FileCheck --check-prefix=CHECK --check-prefix=CHECK-NPOT-NEG-OFFSET %s
+

What does NPOT stand for here, something to do with the offset not being a 
multiple of 8 bytes?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100919

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


[PATCH] D101388: [clangd] Add SymbolID to LocatedSymbol.

2021-04-28 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 341168.
usaxena95 marked 4 inline comments as done.
usaxena95 edited the summary of this revision.
usaxena95 added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101388

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -306,6 +306,7 @@
 
 MATCHER_P(RangeIs, R, "") { return arg.Loc.range == R; }
 MATCHER_P(AttrsAre, A, "") { return arg.Attributes == A; }
+MATCHER_P(HasID, ID, "") { return arg.ID == ID; }
 
 TEST(LocateSymbol, WithIndex) {
   Annotations SymbolHeader(R"cpp(
@@ -919,6 +920,7 @@
 } else {
   ASSERT_THAT(Results, ::testing::SizeIs(1)) << Test;
   EXPECT_EQ(Results[0].PreferredDeclaration.range, *WantDecl) << Test;
+  EXPECT_TRUE(Results[0].ID) << Test;
   llvm::Optional GotDef;
   if (Results[0].Definition)
 GotDef = Results[0].Definition->range;
@@ -926,6 +928,24 @@
 }
   }
 }
+TEST(LocateSymbol, ValidSymbolID) {
+  auto T = Annotations(R"cpp(
+#define MACRO(x, y) ((x) + (y))
+int add(int x, int y) { return $MACRO^MACRO(x, y); }
+int sum = $add^add(1, 2);
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto Index = TU.index();
+  EXPECT_THAT(locateSymbolAt(AST, T.point("add"), Index.get()),
+  ElementsAre(AllOf(Sym("add"),
+HasID(getSymbolID(&findDecl(AST, "add"));
+  EXPECT_THAT(
+  locateSymbolAt(AST, T.point("MACRO"), Index.get()),
+  ElementsAre(AllOf(Sym("MACRO"),
+HasID(findSymbol(TU.headerSymbols(), "MACRO").ID;
+}
 
 TEST(LocateSymbol, AllMulti) {
   // Ranges in tests:
@@ -1072,8 +1092,10 @@
   auto TU = TestTU::withCode(T.code());
   auto AST = TU.build();
   auto Index = TU.index();
-  EXPECT_THAT(locateSymbolAt(AST, T.point(), Index.get()),
-  ElementsAre(Sym("MyClass", T.range(), T.range(;
+  EXPECT_THAT(
+  locateSymbolAt(AST, T.point(), Index.get()),
+  ElementsAre(AllOf(Sym("MyClass", T.range(), T.range()),
+HasID(getSymbolID(&findDecl(AST, "MyClass"));
 }
 
 TEST(LocateSymbol, Textual) {
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -16,6 +16,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "index/Index.h"
+#include "index/SymbolID.h"
 #include "index/SymbolLocation.h"
 #include "support/Path.h"
 #include "clang/AST/ASTTypeTraits.h"
@@ -47,6 +48,8 @@
   Location PreferredDeclaration;
   // Where the symbol is defined, if known. May equal PreferredDeclaration.
   llvm::Optional Definition;
+  // SymbolID of the located symbol if available.
+  SymbolID ID;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const LocatedSymbol &);
 /// Get definition of symbol at a specified \p Pos.
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -257,6 +257,7 @@
   Macro.Name = std::string(M->Name);
   Macro.PreferredDeclaration = *Loc;
   Macro.Definition = Loc;
+  Macro.ID = getSymbolID(M->Name, M->Info, AST.getSourceManager());
   return Macro;
 }
   }
@@ -361,6 +362,7 @@
 Result.emplace_back();
 Result.back().Name = printName(AST.getASTContext(), *D);
 Result.back().PreferredDeclaration = *Loc;
+Result.back().ID = getSymbolID(D);
 if (const NamedDecl *Def = getDefinition(D))
   Result.back().Definition = makeLocation(
   AST.getASTContext(), nameLocation(*Def, SM), MainFilePath);
@@ -516,6 +518,7 @@
 Results.emplace_back();
 Results.back().Name = printName(ASTContext, *D);
 Results.back().PreferredDeclaration = *Loc;
+Results.back().ID = getSymbolID(D);
 if (const NamedDecl *Def = getDefinition(D))
   Results.back().Definition =
   makeLocation(ASTContext, nameLocation(*Def, SM), *MainFilePath);
@@ -605,6 +608,7 @@
 LocatedSymbol Located;
 Located.PreferredDeclaration = *MaybeDeclLoc;
 Located.Name = (Sym.Name + Sym.TemplateSpecializationArgs).str();
+Located.ID = Sym.ID;
 if (Sym.Definition) {
   auto MaybeDefLoc = indexToLSPLocation(Sym.Definition, MainFilePath);
   if (!MaybeDefLoc) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f0efc00 - [OpenCL] Introduce new method for validating OpenCL target

2021-04-28 Thread Anton Zabaznov via cfe-commits

Author: Anton Zabaznov
Date: 2021-04-28T16:00:02+03:00
New Revision: f0efc00751313779671746492ded4014b715df6a

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

LOG: [OpenCL] Introduce new method for validating OpenCL target

Language options are not available when a target is being created,
thus, a new method is introduced. Also, some refactoring is done,
such as removing OpenCL feature macros setting from TargetInfo.

Reviewed By: Anastasia

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

Added: 
clang/test/Misc/nvptx.unsupported_core.cl
clang/test/Misc/r600.unsupported_core.cl

Modified: 
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/include/clang/Basic/OpenCLOptions.h
clang/include/clang/Basic/TargetInfo.h
clang/lib/Basic/OpenCLOptions.cpp
clang/lib/Basic/Targets.cpp
clang/lib/Basic/Targets/X86.cpp
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/InitPreprocessor.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index eab8206b104dc..06c2647149dfa 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -360,4 +360,8 @@ def note_suggest_disabling_all_checkers : Note<
 def warn_poison_system_directories : Warning <
   "include location '%0' is unsafe for cross-compilation">,
   InGroup>, DefaultIgnore;
+
+def warn_opencl_unsupported_core_feature : Warning<
+  "%0 is a core feature in %select{OpenCL C|C++ for OpenCL}1 version %2 but 
not supported on this target">,
+  InGroup, DefaultIgnore;
 }

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index b91cee9a9e5f8..7d4e670c7e7d5 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1286,3 +1286,5 @@ in addition with the pragmas or -fmax-tokens flag to get 
any warnings.
 def WebAssemblyExceptionSpec : DiagGroup<"wasm-exception-spec">;
 
 def RTTI : DiagGroup<"rtti">;
+
+def OpenCLCoreFeaturesDiagGroup : DiagGroup<"pedantic-core-features">;

diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 8b3da909dd118..274ed728d94d5 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1246,7 +1246,8 @@ def warn_pragma_unknown_extension : Warning<
 def warn_pragma_unsupported_extension : Warning<
   "unsupported OpenCL extension %0 - ignoring">, InGroup;
 def warn_pragma_extension_is_core : Warning<
-  "OpenCL extension %0 is core feature or supported optional core feature - 
ignoring">, InGroup>, DefaultIgnore;
+  "OpenCL extension %0 is core feature or supported optional core feature - 
ignoring">,
+  InGroup, DefaultIgnore;
 
 // OpenCL errors.
 def err_opencl_taking_function_address_parser : Error<

diff  --git a/clang/include/clang/Basic/OpenCLOptions.h 
b/clang/include/clang/Basic/OpenCLOptions.h
index 17923d2b8d3cb..44fda029411f1 100644
--- a/clang/include/clang/Basic/OpenCLOptions.h
+++ b/clang/include/clang/Basic/OpenCLOptions.h
@@ -59,6 +59,7 @@ static inline bool isOpenCLVersionContainedInMask(const 
LangOptions &LO,
   OpenCLVersionID Code = encodeOpenCLVersion(CLVer);
   return Mask & Code;
 }
+
 } // end anonymous namespace
 
 /// OpenCL supported extensions and optional core features
@@ -167,6 +168,17 @@ class OpenCLOptions {
 
   using OpenCLOptionInfoMap = llvm::StringMap;
 
+  template 
+  static bool isOpenCLOptionCoreIn(const LangOptions &LO, Args &&... args) {
+return OpenCLOptionInfo(std::forward(args)...).isCoreIn(LO);
+  }
+
+  template 
+  static bool isOpenCLOptionAvailableIn(const LangOptions &LO,
+Args &&... args) {
+return OpenCLOptionInfo(std::forward(args)...).isAvailableIn(LO);
+  }
+
 private:
   // Option is enabled via pragma
   bool isEnabled(llvm::StringRef Ext) const;

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 77b4746333597..3300fe012aa81 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1234,6 +1234,12 @@ class TargetInfo : public virtual 
TransferrableTargetInfo,
 return false;
   }
 
+  /// Check if target has a given feature enabled
+  virtual bool hasFeatureEnabled(const llvm::StringMap &Features,
+ StringRef Name) const {
+return Features.lookup(Name);
+  }
+
   /// Enable or disable a specific target feature;
   /// the feature name

[PATCH] D101087: [OpenCL] Introduce new method for validating OpenCL target

2021-04-28 Thread Anton Zabaznov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf0efc0075131: [OpenCL] Introduce new method for validating 
OpenCL target (authored by azabaznov).

Changed prior to commit:
  https://reviews.llvm.org/D101087?vs=341119&id=341170#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101087

Files:
  clang/include/clang/Basic/DiagnosticCommonKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/OpenCLOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/lib/Basic/OpenCLOptions.cpp
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/test/Misc/nvptx.unsupported_core.cl
  clang/test/Misc/r600.unsupported_core.cl

Index: clang/test/Misc/r600.unsupported_core.cl
===
--- /dev/null
+++ clang/test/Misc/r600.unsupported_core.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple r600-unknown-unknown -Wpedantic-core-features %s 2> %t
+// RUN: FileCheck < %t %s
+
+// CHECK: cl_khr_byte_addressable_store is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_global_int32_base_atomics is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_global_int32_extended_atomics is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_local_int32_base_atomics is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_local_int32_extended_atomics is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK: cl_khr_3d_image_writes is a core feature in OpenCL C version 2.0 but not supported on this target
Index: clang/test/Misc/nvptx.unsupported_core.cl
===
--- /dev/null
+++ clang/test/Misc/nvptx.unsupported_core.cl
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple nvptx-unknown-unknown -Wpedantic-core-features %s 2> %t
+// RUN: FileCheck --check-prefixes=CHECK-C < %t %s
+// RUN: %clang_cc1 -cl-std=CLC++ -triple nvptx-unknown-unknown -Wpedantic-core-features %s 2> %t
+// RUN: FileCheck --check-prefixes=CHECK-CPP < %t %s
+
+// CHECK-C: cl_khr_3d_image_writes is a core feature in OpenCL C version 2.0 but not supported on this target
+// CHECK-CPP: cl_khr_3d_image_writes is a core feature in C++ for OpenCL version 1.0 but not supported on this target
Index: clang/lib/Frontend/InitPreprocessor.cpp
===
--- clang/lib/Frontend/InitPreprocessor.cpp
+++ clang/lib/Frontend/InitPreprocessor.cpp
@@ -601,6 +601,29 @@
 Builder.defineMacro("__cpp_coroutines", "201703L");
 }
 
+/// InitializeOpenCLFeatureTestMacros - Define OpenCL macros based on target
+/// settings and language version
+void InitializeOpenCLFeatureTestMacros(const TargetInfo &TI,
+   const LangOptions &Opts,
+   MacroBuilder &Builder) {
+  const llvm::StringMap &OpenCLFeaturesMap = TI.getSupportedOpenCLOpts();
+  // FIXME: OpenCL options which affect language semantics/syntax
+  // should be moved into LangOptions.
+  auto defineOpenCLExtMacro = [&](llvm::StringRef Name, auto... OptArgs) {
+// Check if extension is supported by target and is available in this
+// OpenCL version
+if (TI.hasFeatureEnabled(OpenCLFeaturesMap, Name) &&
+OpenCLOptions::isOpenCLOptionAvailableIn(Opts, OptArgs...))
+  Builder.defineMacro(Name);
+  };
+#define OPENCL_GENERIC_EXTENSION(Ext, ...) \
+  defineOpenCLExtMacro(#Ext, __VA_ARGS__);
+#include "clang/Basic/OpenCLExtensions.def"
+
+  // Assume compiling for FULL profile
+  Builder.defineMacro("__opencl_c_int64");
+}
+
 static void InitializePredefinedMacros(const TargetInfo &TI,
const LangOptions &LangOpts,
const FrontendOptions &FEOpts,
@@ -1137,7 +1160,7 @@
 
   // OpenCL definitions.
   if (LangOpts.OpenCL) {
-TI.getOpenCLFeatureDefines(LangOpts, Builder);
+InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
 
 if (TI.getTriple().isSPIR())
   Builder.defineMacro("__IMAGE_SUPPORT__");
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -133,6 +133,11 @@
 // FIXME: can we disable FEnvAccess?
   }
 
+  // We should do it here because target knows nothing about
+  // language options when it's being created.
+  if (getLangOpts().OpenCL)
+getTarget().validateOpenCLTarget(getLangOp

[clang-tools-extra] d7cb230 - [clangd] Add SymbolID to LocatedSymbol.

2021-04-28 Thread Utkarsh Saxena via cfe-commits

Author: Utkarsh Saxena
Date: 2021-04-28T15:05:53+02:00
New Revision: d7cb2305a1e86809af6f818a225af0fbe9441b2f

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

LOG: [clangd] Add SymbolID to LocatedSymbol.

This is useful for running in batch mode.
Getting the SymbolID from via getSymbolInfo may give SymbolID
of a symbol different from that located by LocateSymbolAt (they
have different semantics of choosing the symbol.)

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

Added: 


Modified: 
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/XRefs.h
clang-tools-extra/clangd/unittests/XRefsTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/XRefs.cpp 
b/clang-tools-extra/clangd/XRefs.cpp
index e4c8db24eb20f..bb51b4a48d09a 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -257,6 +257,7 @@ locateMacroReferent(const syntax::Token &TouchedIdentifier, 
ParsedAST &AST,
   Macro.Name = std::string(M->Name);
   Macro.PreferredDeclaration = *Loc;
   Macro.Definition = Loc;
+  Macro.ID = getSymbolID(M->Name, M->Info, AST.getSourceManager());
   return Macro;
 }
   }
@@ -361,6 +362,7 @@ locateASTReferent(SourceLocation CurLoc, const 
syntax::Token *TouchedIdentifier,
 Result.emplace_back();
 Result.back().Name = printName(AST.getASTContext(), *D);
 Result.back().PreferredDeclaration = *Loc;
+Result.back().ID = getSymbolID(D);
 if (const NamedDecl *Def = getDefinition(D))
   Result.back().Definition = makeLocation(
   AST.getASTContext(), nameLocation(*Def, SM), MainFilePath);
@@ -516,6 +518,7 @@ std::vector locateSymbolForType(const 
ParsedAST &AST,
 Results.emplace_back();
 Results.back().Name = printName(ASTContext, *D);
 Results.back().PreferredDeclaration = *Loc;
+Results.back().ID = getSymbolID(D);
 if (const NamedDecl *Def = getDefinition(D))
   Results.back().Definition =
   makeLocation(ASTContext, nameLocation(*Def, SM), *MainFilePath);
@@ -605,6 +608,7 @@ locateSymbolTextually(const SpelledWord &Word, ParsedAST 
&AST,
 LocatedSymbol Located;
 Located.PreferredDeclaration = *MaybeDeclLoc;
 Located.Name = (Sym.Name + Sym.TemplateSpecializationArgs).str();
+Located.ID = Sym.ID;
 if (Sym.Definition) {
   auto MaybeDefLoc = indexToLSPLocation(Sym.Definition, MainFilePath);
   if (!MaybeDefLoc) {

diff  --git a/clang-tools-extra/clangd/XRefs.h 
b/clang-tools-extra/clangd/XRefs.h
index 3f69106611dc6..aa0eaa7454c04 100644
--- a/clang-tools-extra/clangd/XRefs.h
+++ b/clang-tools-extra/clangd/XRefs.h
@@ -16,6 +16,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "index/Index.h"
+#include "index/SymbolID.h"
 #include "index/SymbolLocation.h"
 #include "support/Path.h"
 #include "clang/AST/ASTTypeTraits.h"
@@ -47,6 +48,8 @@ struct LocatedSymbol {
   Location PreferredDeclaration;
   // Where the symbol is defined, if known. May equal PreferredDeclaration.
   llvm::Optional Definition;
+  // SymbolID of the located symbol if available.
+  SymbolID ID;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const LocatedSymbol &);
 /// Get definition of symbol at a specified \p Pos.

diff  --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 2fbf1f98db8a7..8c37532507d45 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -306,6 +306,7 @@ MATCHER_P(Sym, Name, "") { return arg.Name == Name; }
 
 MATCHER_P(RangeIs, R, "") { return arg.Loc.range == R; }
 MATCHER_P(AttrsAre, A, "") { return arg.Attributes == A; }
+MATCHER_P(HasID, ID, "") { return arg.ID == ID; }
 
 TEST(LocateSymbol, WithIndex) {
   Annotations SymbolHeader(R"cpp(
@@ -919,6 +920,7 @@ TEST(LocateSymbol, All) {
 } else {
   ASSERT_THAT(Results, ::testing::SizeIs(1)) << Test;
   EXPECT_EQ(Results[0].PreferredDeclaration.range, *WantDecl) << Test;
+  EXPECT_TRUE(Results[0].ID) << Test;
   llvm::Optional GotDef;
   if (Results[0].Definition)
 GotDef = Results[0].Definition->range;
@@ -926,6 +928,24 @@ TEST(LocateSymbol, All) {
 }
   }
 }
+TEST(LocateSymbol, ValidSymbolID) {
+  auto T = Annotations(R"cpp(
+#define MACRO(x, y) ((x) + (y))
+int add(int x, int y) { return $MACRO^MACRO(x, y); }
+int sum = $add^add(1, 2);
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto Index = TU.index();
+  EXPECT_THAT(locateSymbolAt(AST, T.point("add"), Index.get()),
+  ElementsAre(AllOf(Sym("add"),
+HasID(getSymbolID(&findDecl(AST, "add"));
+  EXPECT_THAT(
+  locateSymbolAt(AST, T.p

[PATCH] D101388: [clangd] Add SymbolID to LocatedSymbol.

2021-04-28 Thread Utkarsh Saxena via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd7cb2305a1e8: [clangd] Add SymbolID to LocatedSymbol. 
(authored by usaxena95).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101388

Files:
  clang-tools-extra/clangd/XRefs.cpp
  clang-tools-extra/clangd/XRefs.h
  clang-tools-extra/clangd/unittests/XRefsTests.cpp

Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -306,6 +306,7 @@
 
 MATCHER_P(RangeIs, R, "") { return arg.Loc.range == R; }
 MATCHER_P(AttrsAre, A, "") { return arg.Attributes == A; }
+MATCHER_P(HasID, ID, "") { return arg.ID == ID; }
 
 TEST(LocateSymbol, WithIndex) {
   Annotations SymbolHeader(R"cpp(
@@ -919,6 +920,7 @@
 } else {
   ASSERT_THAT(Results, ::testing::SizeIs(1)) << Test;
   EXPECT_EQ(Results[0].PreferredDeclaration.range, *WantDecl) << Test;
+  EXPECT_TRUE(Results[0].ID) << Test;
   llvm::Optional GotDef;
   if (Results[0].Definition)
 GotDef = Results[0].Definition->range;
@@ -926,6 +928,24 @@
 }
   }
 }
+TEST(LocateSymbol, ValidSymbolID) {
+  auto T = Annotations(R"cpp(
+#define MACRO(x, y) ((x) + (y))
+int add(int x, int y) { return $MACRO^MACRO(x, y); }
+int sum = $add^add(1, 2);
+  )cpp");
+
+  TestTU TU = TestTU::withCode(T.code());
+  auto AST = TU.build();
+  auto Index = TU.index();
+  EXPECT_THAT(locateSymbolAt(AST, T.point("add"), Index.get()),
+  ElementsAre(AllOf(Sym("add"),
+HasID(getSymbolID(&findDecl(AST, "add"));
+  EXPECT_THAT(
+  locateSymbolAt(AST, T.point("MACRO"), Index.get()),
+  ElementsAre(AllOf(Sym("MACRO"),
+HasID(findSymbol(TU.headerSymbols(), "MACRO").ID;
+}
 
 TEST(LocateSymbol, AllMulti) {
   // Ranges in tests:
@@ -1072,8 +1092,10 @@
   auto TU = TestTU::withCode(T.code());
   auto AST = TU.build();
   auto Index = TU.index();
-  EXPECT_THAT(locateSymbolAt(AST, T.point(), Index.get()),
-  ElementsAre(Sym("MyClass", T.range(), T.range(;
+  EXPECT_THAT(
+  locateSymbolAt(AST, T.point(), Index.get()),
+  ElementsAre(AllOf(Sym("MyClass", T.range(), T.range()),
+HasID(getSymbolID(&findDecl(AST, "MyClass"));
 }
 
 TEST(LocateSymbol, Textual) {
Index: clang-tools-extra/clangd/XRefs.h
===
--- clang-tools-extra/clangd/XRefs.h
+++ clang-tools-extra/clangd/XRefs.h
@@ -16,6 +16,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "index/Index.h"
+#include "index/SymbolID.h"
 #include "index/SymbolLocation.h"
 #include "support/Path.h"
 #include "clang/AST/ASTTypeTraits.h"
@@ -47,6 +48,8 @@
   Location PreferredDeclaration;
   // Where the symbol is defined, if known. May equal PreferredDeclaration.
   llvm::Optional Definition;
+  // SymbolID of the located symbol if available.
+  SymbolID ID;
 };
 llvm::raw_ostream &operator<<(llvm::raw_ostream &, const LocatedSymbol &);
 /// Get definition of symbol at a specified \p Pos.
Index: clang-tools-extra/clangd/XRefs.cpp
===
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -257,6 +257,7 @@
   Macro.Name = std::string(M->Name);
   Macro.PreferredDeclaration = *Loc;
   Macro.Definition = Loc;
+  Macro.ID = getSymbolID(M->Name, M->Info, AST.getSourceManager());
   return Macro;
 }
   }
@@ -361,6 +362,7 @@
 Result.emplace_back();
 Result.back().Name = printName(AST.getASTContext(), *D);
 Result.back().PreferredDeclaration = *Loc;
+Result.back().ID = getSymbolID(D);
 if (const NamedDecl *Def = getDefinition(D))
   Result.back().Definition = makeLocation(
   AST.getASTContext(), nameLocation(*Def, SM), MainFilePath);
@@ -516,6 +518,7 @@
 Results.emplace_back();
 Results.back().Name = printName(ASTContext, *D);
 Results.back().PreferredDeclaration = *Loc;
+Results.back().ID = getSymbolID(D);
 if (const NamedDecl *Def = getDefinition(D))
   Results.back().Definition =
   makeLocation(ASTContext, nameLocation(*Def, SM), *MainFilePath);
@@ -605,6 +608,7 @@
 LocatedSymbol Located;
 Located.PreferredDeclaration = *MaybeDeclLoc;
 Located.Name = (Sym.Name + Sym.TemplateSpecializationArgs).str();
+Located.ID = Sym.ID;
 if (Sym.Definition) {
   auto MaybeDefLoc = indexToLSPLocation(Sym.Definition, MainFilePath);
   if (!MaybeDefLoc) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101439: [clang-cl] Add parsing support for a bunch of new flags

2021-04-28 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

Do we silently ignore those all now? Are any of them semantically important 
enough that we should emit an "not implemented, ignoring" diag instead?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101439

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


[PATCH] D101439: [clang-cl] Add parsing support for a bunch of new flags

2021-04-28 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/include/clang/Driver/Options.td:6117
 def _SLASH_favor : CLJoined<"favor">;
+def _SLASH_fsanitize_address_use_after_return : 
CLJoined<"fsanitize-address-use-after-return">;
+def _SLASH_fno_sanitize_address_vcasan_lib : 
CLJoined<"fno-sanitize-address-vcasan-lib">;

Can we ask (or check) how this one is implemented? Does it inject a custom 
__asan_default_options that returns `detect_stack_use_after_return=1` or is it 
more involved?



Comment at: clang/include/clang/Driver/Options.td:6118
+def _SLASH_fsanitize_address_use_after_return : 
CLJoined<"fsanitize-address-use-after-return">;
+def _SLASH_fno_sanitize_address_vcasan_lib : 
CLJoined<"fno-sanitize-address-vcasan-lib">;
 def _SLASH_F : CLJoinedOrSeparate<"F">;

I guess this one controls library search paths and they have vc libs built with 
and without asan?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101439

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


[PATCH] D101439: [clang-cl] Add parsing support for a bunch of new flags

2021-04-28 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In D101439#2722540 , @thakis wrote:

> Do we silently ignore those all now? Are any of them semantically important 
> enough that we should emit an "not implemented, ignoring" diag instead?

No, this patch makes us parse them as opposed to mistaking them for filenames, 
but they're still unsupported and we'll print a warning about them being unused 
during compilation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101439

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


[PATCH] D98726: [analyzer] Enabling MallocChecker to take up after SmartPtrModelling

2021-04-28 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added a comment.

In D98726#2721228 , @NoQ wrote:

>> when the visitor encounters an `ExplodedNode`
>
> Weird. `finalizeVisitor()` accepts not any node but the error node. Your 
> screenshot suggests that the error node is not in the standard library but in 
> user code. Might it be that there are multiple error nodes and you're looking 
> at the wrong one? As usual, you can set conditional breakpoints by node IDs.

Okay no you are right. I was looking at the wrong error node. There are two. 
Lets take the following code:

  #include 
  
  int foo() {
std::unique_ptr P(new int(10));
int *raw = new int(13);
int b = *raw;
return b;
  }

There is clearly a leak but that is getting squelched. Now for the two error 
nodes:

- This is the error node we expect, it points to our source code.

F16513445: Screenshot 2021-04-28 at 19-14-34 Screenshot.png 


- This is another error, somewhere in the `unique_ptr.h` file.

F16513472: Screenshot 2021-04-28 at 19-15-04 Screenshot.png 


The second one is the one that causes the first one to get squelched. I suppose 
how this point was reached was due to the `StaticAnalyzer` trying to reason 
about the destructor of `unique_ptr`, which is implicitly called in at the end 
of the function.  
For reference, here  is the dot file for the exploded 
graph dump.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98726

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


[PATCH] D99975: [clangd][ObjC] Improve support for class properties

2021-04-28 Thread David Goldman via Phabricator via cfe-commits
dgoldman marked 2 inline comments as done.
dgoldman added inline comments.



Comment at: clang-tools-extra/clangd/FindTarget.cpp:309-313
+// FIXME: visiting this here allows us to hover on UIColor in
+// `UIColor.blackColor` but then `blackColor` no longer refers to the
+// method.
+// if (OPRE->isClassReceiver())
+//   Outer.add(OPRE->getClassReceiver(), Flags);

sammccall wrote:
> dgoldman wrote:
> > sammccall wrote:
> > > dgoldman wrote:
> > > > Is there a good way to handle this case where the expression can refer 
> > > > to multiple decls?
> > > TL;DR: yes, fix the AST :-)
> > > 
> > > The design assumption is that an AST node (specifically: the tokens owned 
> > > by exactly that AST node and not a descendant of it) refers to one thing. 
> > > I don't see an easy way to hack around this.
> > > 
> > > Expressions like this are supposed to be split into multiple AST nodes. 
> > > But ObjC seems to be missing AST nodes in a bunch of places (Protocol 
> > > lists is another).
> > > 
> > > e.g. in C++ equivalent DeclRefExpr `UIColor::blackColor` there'd be both 
> > > a NestedNameSpecifier for `UIColor::` and a TagTypeLoc for `UIColor`. And 
> > > objc `[Test foo]` has an `ObjCInterfaceTypeLoc` for `Test`.
> > > 
> > > ---
> > > 
> > > I'm not sure this is the right place for this comment, the problem isn't 
> > > what VisitObjCPropertyRefExpr is doing, the issue is that the caller is 
> > > passing the wrong kind of node to findTarget() because there's no right 
> > > one.
> > That seems a bit invasive - is it really "fixing" the AST - is there 
> > anything wrong with the current AST design or rather any notable 
> > improvements by adding more nodes to the AST beside this one use case here? 
> > 
> > It seems like the design could be adapted if we had a SourceLocation hint 
> > here (from the caller) to disambiguate which one we mean, but I'm guessing 
> > not all of the callers/users of this would have one?
> > That seems a bit invasive
> I'm not sure it actually requires any changes to AST classes, just to 
> RecursiveASTVisitor to wrap the getClassReceiverType() & 
> getReceiverLocation() into n ObjCInterfaceTypeLoc (which is a value object) 
> and visit it.
> 
> > is it really "fixing" the AST
> 
> It's inconsistent with the design of the rest of the AST.
> There are very few other cases where AST nodes have this kind of compound 
> meaning rather than being to split into sub-nodes.
> (In fact ObjC protocol lists are the only example I can think of. I suspect 
> this dates back to early clang days, maybe before the patterns became 
> established)
> And similarly, there are few/no places where types are referenced that don't 
> have a TypeLoc node traversed by RecursiveASTVisitor.
> 
> > is there anything wrong with the current AST design or rather any notable 
> > improvements by adding more nodes to the AST beside this one use case here?
> 
> I guess the use case here is "precisely communicating a selection in an IDE".
> Expand-selection features and show-ast-structure features don't work in 
> clangd for a similar reason.
> 
> Outside clangd I'm less familiar of course! Matchers, clang-tidy checks and 
> refactorings spring to mind.
> For instance, if you want to write a tool to rename/split an ObjC class, then 
> something like `typeLoc(loc(asString("FooClass")))` would match all usages... 
> except this one, so your tool would have a bug.
> I'm not sure it actually requires any changes to AST classes, just to 
> RecursiveASTVisitor to wrap the getClassReceiverType() & 
> getReceiverLocation() into n ObjCInterfaceTypeLoc (which is a value object) 
> and visit it.

Thanks, I'll look into that in a follow up - I'd imagine it could affect lots 
of other things but I'm not sure.

> Outside clangd I'm less familiar of course! Matchers, clang-tidy checks and 
> refactorings spring to mind.
> For instance, if you want to write a tool to rename/split an ObjC class, then 
> something like typeLoc(loc(asString("FooClass"))) would match all usages... 
> except this one, so your tool would have a bug.

Interesting, I wonder how Xcode works with this (e.g. for refactorings), I'll 
ask around to see if anyone has suggestions/further context here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99975

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


[clang-tools-extra] 39866d2 - [clangd][ObjC] Improve support for class properties

2021-04-28 Thread David Goldman via cfe-commits

Author: David Goldman
Date: 2021-04-28T10:06:27-04:00
New Revision: 39866d249a21fc3c05942a1a4fbbd88acc4660bc

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

LOG: [clangd][ObjC] Improve support for class properties

Class properties are always implicit short-hands for the getter/setter
class methods.

We need to explicitly visit the interface decl `UIColor` in `UIColor.blueColor`,
otherwise we instead show the method decl even while hovering over
`UIColor` in the expression.

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

Added: 


Modified: 
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/FindTarget.cpp 
b/clang-tools-extra/clangd/FindTarget.cpp
index 6032676b0acd..d4cb2fe79111 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -306,6 +306,9 @@ struct TargetFinder {
 Outer.add(OME->getMethodDecl(), Flags);
   }
   void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE) {
+// FIXME: We miss visiting the class receiver if one exists, which
+// means we skip the corresponding ObjCInterfaceDecl ref since it
+// doesn't have a corresponding node.
 if (OPRE->isExplicitProperty())
   Outer.add(OPRE->getExplicitProperty(), Flags);
 else {
@@ -763,6 +766,13 @@ llvm::SmallVector refInStmt(const Stmt *S,
 }
 
 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *E) {
+  // There's no contained TypeLoc node for a class receiver type.
+  if (E->isClassReceiver()) {
+Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
+E->getReceiverLocation(),
+/*IsDecl=*/false,
+{E->getClassReceiver()}});
+  }
   Refs.push_back(ReferenceLoc{
   NestedNameSpecifierLoc(), E->getLocation(),
   /*IsDecl=*/false,

diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 5bcbdbd2f1cd..f32081ac472c 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -969,6 +969,33 @@ TEST_F(TargetDeclTest, ObjC) {
   )cpp";
   // FIXME: We currently can't disambiguate between multiple protocols.
   EXPECT_DECLS("ObjCObjectTypeLoc", "@protocol Foo", "@protocol Bar");
+
+  Code = R"cpp(
+@interface Foo
++ (id)sharedInstance;
+@end
+@implementation Foo
++ (id)sharedInstance { return 0; }
+@end
+void test() {
+  id value = [[Foo]].sharedInstance;
+}
+  )cpp";
+  // FIXME: We currently can't identify the interface here.
+  EXPECT_DECLS("ObjCPropertyRefExpr", "+ (id)sharedInstance");
+
+  Code = R"cpp(
+@interface Foo
++ (id)sharedInstance;
+@end
+@implementation Foo
++ (id)sharedInstance { return 0; }
+@end
+void test() {
+  id value = Foo.[[sharedInstance]];
+}
+  )cpp";
+  EXPECT_DECLS("ObjCPropertyRefExpr", "+ (id)sharedInstance");
 }
 
 class FindExplicitReferencesTest : public ::testing::Test {
@@ -1610,6 +1637,41 @@ TEST_F(FindExplicitReferencesTest, All) {
"0: targets = {f}\n"
"1: targets = {I::x}\n"
"2: targets = {I::setY:}\n"},
+   // Objective-C: class properties
+   {
+   R"cpp(
+@interface I {}
+@property(class) I *x;
+@end
+id local;
+void foo() {
+  $0^I.$1^x = 0;
+  $2^local = $3^I.$4^x;
+}
+  )cpp",
+   "0: targets = {I}\n"
+   "1: targets = {I::setX:}\n"
+   "2: targets = {local}\n"
+   "3: targets = {I}\n"
+   "4: targets = {I::x}\n"},
+   // Objective-C: implicit class properties
+   {
+   R"cpp(
+@interface I {}
++(I*)x;
++(void)setX:(I*)x;
+@end
+id local;
+void foo() {
+  $0^I.$1^x = 0;
+  $2^local = $3^I.$4^x;
+}
+  )cpp",
+   "0: targets = {I}\n"
+   "1: targets = {I::setX:}\n"
+   "2: targets = {local}\n"
+   "3: targets = {I}\n"
+   "4: targets = {I::x}\n"},
{// Objective-C: methods
 R"cpp(
 @interface I



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


[PATCH] D99975: [clangd][ObjC] Improve support for class properties

2021-04-28 Thread David Goldman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
dgoldman marked an inline comment as done.
Closed by commit rG39866d249a21: [clangd][ObjC] Improve support for class 
properties (authored by dgoldman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99975

Files:
  clang-tools-extra/clangd/FindTarget.cpp
  clang-tools-extra/clangd/unittests/FindTargetTests.cpp

Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp
===
--- clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -969,6 +969,33 @@
   )cpp";
   // FIXME: We currently can't disambiguate between multiple protocols.
   EXPECT_DECLS("ObjCObjectTypeLoc", "@protocol Foo", "@protocol Bar");
+
+  Code = R"cpp(
+@interface Foo
++ (id)sharedInstance;
+@end
+@implementation Foo
++ (id)sharedInstance { return 0; }
+@end
+void test() {
+  id value = [[Foo]].sharedInstance;
+}
+  )cpp";
+  // FIXME: We currently can't identify the interface here.
+  EXPECT_DECLS("ObjCPropertyRefExpr", "+ (id)sharedInstance");
+
+  Code = R"cpp(
+@interface Foo
++ (id)sharedInstance;
+@end
+@implementation Foo
++ (id)sharedInstance { return 0; }
+@end
+void test() {
+  id value = Foo.[[sharedInstance]];
+}
+  )cpp";
+  EXPECT_DECLS("ObjCPropertyRefExpr", "+ (id)sharedInstance");
 }
 
 class FindExplicitReferencesTest : public ::testing::Test {
@@ -1610,6 +1637,41 @@
"0: targets = {f}\n"
"1: targets = {I::x}\n"
"2: targets = {I::setY:}\n"},
+   // Objective-C: class properties
+   {
+   R"cpp(
+@interface I {}
+@property(class) I *x;
+@end
+id local;
+void foo() {
+  $0^I.$1^x = 0;
+  $2^local = $3^I.$4^x;
+}
+  )cpp",
+   "0: targets = {I}\n"
+   "1: targets = {I::setX:}\n"
+   "2: targets = {local}\n"
+   "3: targets = {I}\n"
+   "4: targets = {I::x}\n"},
+   // Objective-C: implicit class properties
+   {
+   R"cpp(
+@interface I {}
++(I*)x;
++(void)setX:(I*)x;
+@end
+id local;
+void foo() {
+  $0^I.$1^x = 0;
+  $2^local = $3^I.$4^x;
+}
+  )cpp",
+   "0: targets = {I}\n"
+   "1: targets = {I::setX:}\n"
+   "2: targets = {local}\n"
+   "3: targets = {I}\n"
+   "4: targets = {I::x}\n"},
{// Objective-C: methods
 R"cpp(
 @interface I
Index: clang-tools-extra/clangd/FindTarget.cpp
===
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -306,6 +306,9 @@
 Outer.add(OME->getMethodDecl(), Flags);
   }
   void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *OPRE) {
+// FIXME: We miss visiting the class receiver if one exists, which
+// means we skip the corresponding ObjCInterfaceDecl ref since it
+// doesn't have a corresponding node.
 if (OPRE->isExplicitProperty())
   Outer.add(OPRE->getExplicitProperty(), Flags);
 else {
@@ -763,6 +766,13 @@
 }
 
 void VisitObjCPropertyRefExpr(const ObjCPropertyRefExpr *E) {
+  // There's no contained TypeLoc node for a class receiver type.
+  if (E->isClassReceiver()) {
+Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(),
+E->getReceiverLocation(),
+/*IsDecl=*/false,
+{E->getClassReceiver()}});
+  }
   Refs.push_back(ReferenceLoc{
   NestedNameSpecifierLoc(), E->getLocation(),
   /*IsDecl=*/false,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101457: [clang] remove dead code after 2a1332245fc

2021-04-28 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: hans.
Herald added a reviewer: aaron.ballman.
thakis requested review of this revision.

Commit 2a1332245fc extracted this code to a new function checkSectionName() and
added a call to it, but didn't remove the original code. The original code
is dead since the checkSectionName() early return would fire when it would
trigger. (If it weren't dead, it'd make clang crash since
err_attribute_section_invalid_for_target now takes two args instead of just the
one that's passed.)

No behavior change.


https://reviews.llvm.org/D101457

Files:
  clang/lib/Sema/SemaDeclAttr.cpp


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3006,13 +3006,6 @@
   if (!S.checkSectionName(LiteralLoc, Str))
 return;
 
-  // If the target wants to validate the section specifier, make it happen.
-  if (llvm::Error E = S.Context.getTargetInfo().isValidSectionSpecifier(Str)) {
-S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
-<< toString(std::move(E));
-return;
-  }
-
   SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str);
   if (NewAttr) {
 D->addAttr(NewAttr);


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3006,13 +3006,6 @@
   if (!S.checkSectionName(LiteralLoc, Str))
 return;
 
-  // If the target wants to validate the section specifier, make it happen.
-  if (llvm::Error E = S.Context.getTargetInfo().isValidSectionSpecifier(Str)) {
-S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
-<< toString(std::move(E));
-return;
-  }
-
   SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str);
   if (NewAttr) {
 D->addAttr(NewAttr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101457: [clang] remove dead code after 2a1332245fc

2021-04-28 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm

The real question is how did you find this? :)


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

https://reviews.llvm.org/D101457

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


[clang] 5d49329 - [clang] remove dead code after 2a1332245fc

2021-04-28 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-04-28T10:27:31-04:00
New Revision: 5d493291bd010bbba0fdc1e7da0922fd214fdffd

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

LOG: [clang] remove dead code after 2a1332245fc

Commit 2a1332245fc extracted this code to a new function checkSectionName() and
added a call to it, but didn't remove the original code. The original code
is dead since the checkSectionName() early return would fire when it would
trigger. (If it weren't dead, it'd make clang crash since
err_attribute_section_invalid_for_target now takes two args instead of just the
one that's passed.)

No behavior change.

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

Added: 


Modified: 
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index b31f9ecb2aceb..7db720f6c57d3 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3006,13 +3006,6 @@ static void handleSectionAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
   if (!S.checkSectionName(LiteralLoc, Str))
 return;
 
-  // If the target wants to validate the section specifier, make it happen.
-  if (llvm::Error E = S.Context.getTargetInfo().isValidSectionSpecifier(Str)) {
-S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
-<< toString(std::move(E));
-return;
-  }
-
   SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str);
   if (NewAttr) {
 D->addAttr(NewAttr);



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


[PATCH] D101457: [clang] remove dead code after 2a1332245fc

2021-04-28 Thread Nico Weber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5d493291bd01: [clang] remove dead code after 2a1332245fc 
(authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101457

Files:
  clang/lib/Sema/SemaDeclAttr.cpp


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3006,13 +3006,6 @@
   if (!S.checkSectionName(LiteralLoc, Str))
 return;
 
-  // If the target wants to validate the section specifier, make it happen.
-  if (llvm::Error E = S.Context.getTargetInfo().isValidSectionSpecifier(Str)) {
-S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
-<< toString(std::move(E));
-return;
-  }
-
   SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str);
   if (NewAttr) {
 D->addAttr(NewAttr);


Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -3006,13 +3006,6 @@
   if (!S.checkSectionName(LiteralLoc, Str))
 return;
 
-  // If the target wants to validate the section specifier, make it happen.
-  if (llvm::Error E = S.Context.getTargetInfo().isValidSectionSpecifier(Str)) {
-S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
-<< toString(std::move(E));
-return;
-  }
-
   SectionAttr *NewAttr = S.mergeSectionAttr(D, AL, Str);
   if (NewAttr) {
 D->addAttr(NewAttr);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D101457: [clang] remove dead code after 2a1332245fc

2021-04-28 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

> The real question is how did you find this? :)

No exciting answer, I'm afraid: I just happened to read this code while looking 
at something else.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101457

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


[PATCH] D101461: [clangd][NFC] Reserve storage when creating semantic token encoding.

2021-04-28 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: sammccall, kadircet.
Herald added subscribers: usaxena95, arphaman.
njames93 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101461

Files:
  clang-tools-extra/clangd/Protocol.cpp


Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -1075,6 +1075,7 @@
 constexpr unsigned SemanticTokenEncodingSize = 5;
 static llvm::json::Value encodeTokens(llvm::ArrayRef Toks) {
   llvm::json::Array Result;
+  Result.reserve(SemanticTokenEncodingSize * Toks.size());
   for (const auto &Tok : Toks) {
 Result.push_back(Tok.deltaLine);
 Result.push_back(Tok.deltaStart);


Index: clang-tools-extra/clangd/Protocol.cpp
===
--- clang-tools-extra/clangd/Protocol.cpp
+++ clang-tools-extra/clangd/Protocol.cpp
@@ -1075,6 +1075,7 @@
 constexpr unsigned SemanticTokenEncodingSize = 5;
 static llvm::json::Value encodeTokens(llvm::ArrayRef Toks) {
   llvm::json::Array Result;
+  Result.reserve(SemanticTokenEncodingSize * Toks.size());
   for (const auto &Tok : Toks) {
 Result.push_back(Tok.deltaLine);
 Result.push_back(Tok.deltaStart);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D100810: Use `GNUInstallDirs` to support custom installation dirs. -- LLVM

2021-04-28 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 341211.
Ericson2314 added a comment.

Fix stray ':' typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100810

Files:
  clang/tools/scan-build/CMakeLists.txt
  libclc/CMakeLists.txt
  lldb/cmake/modules/FindLibEdit.cmake
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/AddSphinxTarget.cmake
  llvm/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/LLVMInstallSymlink.cmake
  llvm/docs/CMake.rst
  llvm/examples/Bye/CMakeLists.txt
  llvm/include/llvm/CMakeLists.txt
  llvm/tools/llvm-config/BuildVariables.inc.in
  llvm/tools/llvm-config/llvm-config.cpp
  llvm/tools/lto/CMakeLists.txt
  llvm/tools/opt-viewer/CMakeLists.txt
  llvm/tools/remarks-shlib/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt

Index: openmp/runtime/src/CMakeLists.txt
===
--- openmp/runtime/src/CMakeLists.txt
+++ openmp/runtime/src/CMakeLists.txt
@@ -319,7 +319,7 @@
 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\"
   \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/bin)")
 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\"
-  \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR})")
+  \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")")
   endforeach()
 else()
 
@@ -331,7 +331,7 @@
 foreach(alias IN LISTS LIBOMP_ALIASES)
   install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
 \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY
-\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR})")
+\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")")
 endforeach()
   endif()
 endif()
Index: llvm/tools/remarks-shlib/CMakeLists.txt
===
--- llvm/tools/remarks-shlib/CMakeLists.txt
+++ llvm/tools/remarks-shlib/CMakeLists.txt
@@ -19,7 +19,7 @@
   endif()
   
   install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h
-DESTINATION include/llvm-c
+DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-c"
 COMPONENT Remarks)
 
   if (APPLE)
Index: llvm/tools/opt-viewer/CMakeLists.txt
===
--- llvm/tools/opt-viewer/CMakeLists.txt
+++ llvm/tools/opt-viewer/CMakeLists.txt
@@ -8,7 +8,7 @@
 
 foreach (file ${files})
   install(PROGRAMS ${file}
-DESTINATION share/opt-viewer
+DESTINATION "${CMAKE_INSTALL_DATADIR}/opt-viewer"
 COMPONENT opt-viewer)
 endforeach (file)
 
Index: llvm/tools/lto/CMakeLists.txt
===
--- llvm/tools/lto/CMakeLists.txt
+++ llvm/tools/lto/CMakeLists.txt
@@ -25,7 +25,7 @@
 intrinsics_gen)
 
 install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h
-  DESTINATION include/llvm-c
+  DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/llvm-c"
   COMPONENT LTO)
 
 if (APPLE)
Index: llvm/tools/llvm-config/llvm-config.cpp
===
--- llvm/tools/llvm-config/llvm-config.cpp
+++ llvm/tools/llvm-config/llvm-config.cpp
@@ -357,10 +357,16 @@
 ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include");
   } else {
 ActivePrefix = CurrentExecPrefix;
-ActiveIncludeDir = ActivePrefix + "/include";
-SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR));
-sys::fs::make_absolute(ActivePrefix, path);
-ActiveBinDir = std::string(path.str());
+{
+  SmallString<256> Path(StringRef(LLVM_INSTALL_INCLUDEDIR));
+  sys::fs::make_absolute(ActivePrefix, Path);
+  ActiveIncludeDir = std::string(Path.str());
+}
+{
+  SmallString<256> Path(StringRef(LLVM_INSTALL_BINDIR));
+  sys::fs::make_absolute(ActivePrefix, Path);
+  ActiveBinDir = std::string(Path.str());
+}
 ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX;
 ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
 ActiveIncludeOption = "-I" + ActiveIncludeDir;
Index: llvm/tools/llvm-config/BuildVariables.inc.in
===
--- llvm/tools/llvm-config/BuildVariables.inc.in
+++ llvm/tools/llvm-config/BuildVariables.inc.in
@@ -23,6 +23,8 @@
 #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@"
 #define LLVM_BUILDMODE "@LLVM_BUILDMODE@"
 #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@"
+#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@"
+#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@"
 #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
 #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
 #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
Index: llvm/includ

[PATCH] D101463: [clang] Make libBasic not depend on MC

2021-04-28 Thread Nico Weber via Phabricator via cfe-commits
thakis created this revision.
thakis added a reviewer: hans.
Herald added subscribers: dexonsmith, dang, mgorny.
Herald added a reviewer: aaron.ballman.
thakis requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

Reduces numbers of files built for clang-format from 575 to 449.

Requires two small changes.

1. Don't use llvm::ExceptionHandling in LangOptions. This isn't even quite the 
right type since we don't use all of its values. Tweaks the changes made in:
  - https://reviews.llvm.org/D93215
  - https://reviews.llvm.org/D93216

2. Move section name validation code added (long ago) in commit 30ba67439 out 
of libBasic into Sema and base the check on the triple. This is a bit less 
OOP-y, but completely in line with what we do in many other places in Sema.

No behavior change.


https://reviews.llvm.org/D101463

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/CMakeLists.txt
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
  llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn

Index: llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
+++ llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
@@ -12,6 +12,7 @@
 "//clang/lib/Frontend/",
 "//clang/lib/Sema/",
 "//llvm/lib/IR",
+"//llvm/lib/MC",
   ]
   sources = [ "ClangFormat.cpp" ]
 }
Index: llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
@@ -25,6 +25,7 @@
 "//clang/lib/Edit",
 "//clang/lib/Lex",
 "//llvm/lib/Frontend/OpenMP",
+"//llvm/lib/MC",
 "//llvm/lib/Support",
   ]
   sources = [
Index: llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
@@ -49,7 +49,6 @@
 "//clang/include/clang/Sema:AttrParsedAttrKinds",
 "//clang/include/clang/Sema:AttrSpellingListIndex",
 "//llvm/include/llvm/Config:llvm-config",
-"//llvm/lib/MC",
 "//llvm/lib/Support",
   ]
   include_dirs = [ "." ]
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -40,6 +40,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Assumptions.h"
+#include "llvm/MC/MCSectionMachO.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
@@ -2985,9 +2986,29 @@
   return ::new (Context) SectionAttr(Context, CI, Name);
 }
 
+/// Used to implement to perform semantic checking on
+/// attribute((section("foo"))) specifiers.
+///
+/// In this case, "foo" is passed in to be checked.  If the section
+/// specifier is invalid, return an Error that indicates the problem.
+///
+/// This is a simple quality of implementation feature to catch errors
+/// and give good diagnostics in cases when the assembler or code generator
+/// would otherwise reject the section specifier.
+llvm::Error Sema::isValidSectionSpecifier(StringRef SecName) {
+  if (!Context.getTargetInfo().getTriple().isOSDarwin())
+return llvm::Error::success();
+
+  // Let MCSectionMachO validate this.
+  StringRef Segment, Section;
+  unsigned TAA, StubSize;
+  bool HasTAA;
+  return llvm::MCSectionMachO::ParseSectionSpecifier(SecName, Segment, Section,
+ TAA, HasTAA, StubSize);
+}
+
 bool Sema::checkSectionName(SourceLocation LiteralLoc, StringRef SecName) {
-  if (llvm::Error E =
-  Context.getTargetInfo().isValidSectionSpecifier(SecName)) {
+  if (llvm::Error E = isValidSectionSpecifier(SecName)) {
 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
 << toString(std::move(E)) << 1 /*'section'*/;
 return false;
@@ -3021,8 +3042,7 @@
 // `#pragma code_seg("segname")` uses checkSectionName() instead.
 static bool checkCodeSegName(Sema &S, SourceLocation LiteralLoc,
  StringRef CodeSegName) {
-  if (llvm::Error E =
-  S.Context.getTargetInfo().isValidSectionSpecifier(CodeSegName)) {
+  if (llvm::Error E = S.isValidSectionSpecifier(CodeSegName)) {
 S.Diag(LiteralLoc, diag::err_attribute_se

[PATCH] D101439: [clang-cl] Add parsing support for a bunch of new flags

2021-04-28 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Great :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101439

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


[PATCH] D99079: [ARM][AArch64] Require appropriate features for crypto algorithms

2021-04-28 Thread David Candler via Phabricator via cfe-commits
dcandler added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.h:36
+  bool HasSHA3;
+  bool HasSM4;
   bool HasUnaligned;

rsanthir.quic wrote:
> Would it make sense to further differentiate SM3 and SM4? I see that we 
> differentiate between the two in arm_neon.td ("ARM_FEATURE_SM3" & 
> "ARM_FEATURE_SM4") but we don't include this differentiation as flags (only 
> HasSM4, +sm4 etc)
It might make more sense in the code to differentiate them, however the current 
feature and command line options align with GCC, so changing them would go 
beyond the scope of this patch.


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

https://reviews.llvm.org/D99079

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


[clang] b8baa2a - [ARM][AArch64] Require appropriate features for crypto algorithms

2021-04-28 Thread David Candler via cfe-commits

Author: David Candler
Date: 2021-04-28T16:26:18+01:00
New Revision: b8baa2a9132498ea286dbb0d03f005760ecc6fdb

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

LOG: [ARM][AArch64] Require appropriate features for crypto algorithms

This patch changes the AArch32 crypto instructions (sha2 and aes) to
require the specific sha2 or aes features. These features have
already been implemented and can be controlled through the command
line, but do not have the expected result (i.e. `+noaes` will not
disable aes instructions). The crypto feature retains its existing
meaning of both sha2 and aes.

Several small changes are included due to the knock-on effect this has:

- The AArch32 driver has been modified to ensure sha2/aes is correctly
  set based on arch/cpu/fpu selection and feature ordering.
- Crypto extensions are permitted for AArch32 v8-R profile, but not
  enabled by default.
- ACLE feature macros have been updated with the fine grained crypto
  algorithms. These are also used by AArch64.
- Various tests updated due to the change in feature lists and macros.

Reviewed By: lenary

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

Added: 
llvm/test/MC/ARM/directive-arch_extension-aes-sha2.s

Modified: 
clang/include/clang/Basic/arm_neon.td
clang/lib/Basic/Targets/AArch64.cpp
clang/lib/Basic/Targets/AArch64.h
clang/lib/Basic/Targets/ARM.cpp
clang/lib/Basic/Targets/ARM.h
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/test/CodeGen/aarch64-neon-range-checks.c
clang/test/CodeGen/aarch64-neon-sha3.c
clang/test/CodeGen/aarch64-neon-sm4-sm3.c
clang/test/CodeGen/arm-target-features.c
clang/test/CodeGen/arm64_crypto.c
clang/test/CodeGen/neon-crypto.c
clang/test/Driver/aarch64-cpus.c
clang/test/Driver/arm-cortex-cpus.c
clang/test/Driver/arm-features.c
clang/test/Driver/arm-mfpu.c
clang/test/Driver/armv8.1m.main.c
clang/test/Preprocessor/aarch64-target-features.c
clang/test/Preprocessor/arm-target-features.c
llvm/include/llvm/Support/ARMTargetParser.def
llvm/lib/Support/ARMTargetParser.cpp
llvm/lib/Target/ARM/ARMInstrNEON.td
llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
llvm/test/Bindings/llvm-c/ARM/disassemble.test
llvm/test/MC/ARM/directive-arch_extension-crypto.s
llvm/test/MC/ARM/neon-crypto.s

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index 6e3ed6ebbd39f..0d97f0a1c2dc5 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1117,12 +1117,14 @@ def VEXT_A64 : WInst<"vext", "...I", "dQdPlQPl">;
 
 

 // Crypto
-let ArchGuard = "__ARM_ARCH >= 8 && defined(__ARM_FEATURE_CRYPTO)" in {
+let ArchGuard = "__ARM_ARCH >= 8 && defined(__ARM_FEATURE_AES)" in {
 def AESE : SInst<"vaese", "...", "QUc">;
 def AESD : SInst<"vaesd", "...", "QUc">;
 def AESMC : SInst<"vaesmc", "..", "QUc">;
 def AESIMC : SInst<"vaesimc", "..", "QUc">;
+}
 
+let ArchGuard = "__ARM_ARCH >= 8 && defined(__ARM_FEATURE_SHA2)" in {
 def SHA1H : SInst<"vsha1h", "11", "Ui">;
 def SHA1SU1 : SInst<"vsha1su1", "...", "QUi">;
 def SHA256SU0 : SInst<"vsha256su0", "...", "QUi">;
@@ -1134,7 +1136,9 @@ def SHA1SU0 : SInst<"vsha1su0", "", "QUi">;
 def SHA256H : SInst<"vsha256h", "", "QUi">;
 def SHA256H2 : SInst<"vsha256h2", "", "QUi">;
 def SHA256SU1 : SInst<"vsha256su1", "", "QUi">;
+}
 
+let ArchGuard = "__ARM_ARCH >= 8 && defined(__ARM_FEATURE_SHA3) && 
defined(__aarch64__)" in {
 def BCAX : SInst<"vbcax", "", "QUcQUsQUiQUlQcQsQiQl">;
 def EOR3 : SInst<"veor3", "", "QUcQUsQUiQUlQcQsQiQl">;
 def RAX1 : SInst<"vrax1", "...", "QUl">;
@@ -1142,12 +1146,17 @@ def RAX1 : SInst<"vrax1", "...", "QUl">;
 let isVXAR = 1 in {
 def XAR :  SInst<"vxar", "...I", "QUl">;
 }
+}
+
+let ArchGuard = "__ARM_ARCH >= 8 && defined(__ARM_FEATURE_SHA512) && 
defined(__aarch64__)" in {
 
 def SHA512SU0 : SInst<"vsha512su0", "...", "QUl">;
 def SHA512su1 : SInst<"vsha512su1", "", "QUl">;
 def SHA512H : SInst<"vsha512h", "", "QUl">;
 def SHA512H2 : SInst<"vsha512h2", "", "QUl">;
+}
 
+let ArchGuard = "__ARM_ARCH >= 8 && defined(__ARM_FEATURE_SM3) && 
defined(__aarch64__)" in {
 def SM3SS1 : SInst<"vsm3ss1", "", "QUi">;
 def SM3TT1A : SInst<"vsm3tt1a", "I", "QUi">;
 def SM3TT1B : SInst<"vsm3tt1b", "I", "QUi">;
@@ -1155,7 +1164,9 @@ def SM3TT2A : SInst<"vsm3tt2a", "I", "QUi">;
 def SM3TT2B : SInst<"vsm3tt2b", "I", "QUi">;
 def SM3PARTW1 : SInst<"vsm3partw1", "", "QUi">;
 def SM3PARTW2 : SInst<"vsm3partw2", "", "QUi">;
+}
 
+let ArchGuard = "__ARM_ARCH >= 8 && defined(__ARM_FEATURE_SM4) && 
defined(__aarch64__)" i

[PATCH] D99079: [ARM][AArch64] Require appropriate features for crypto algorithms

2021-04-28 Thread David Candler via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb8baa2a91324: [ARM][AArch64] Require appropriate features 
for crypto algorithms (authored by dcandler).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99079

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/Basic/Targets/ARM.h
  clang/lib/Driver/ToolChains/Arch/ARM.cpp
  clang/test/CodeGen/aarch64-neon-range-checks.c
  clang/test/CodeGen/aarch64-neon-sha3.c
  clang/test/CodeGen/aarch64-neon-sm4-sm3.c
  clang/test/CodeGen/arm-target-features.c
  clang/test/CodeGen/arm64_crypto.c
  clang/test/CodeGen/neon-crypto.c
  clang/test/Driver/aarch64-cpus.c
  clang/test/Driver/arm-cortex-cpus.c
  clang/test/Driver/arm-features.c
  clang/test/Driver/arm-mfpu.c
  clang/test/Driver/armv8.1m.main.c
  clang/test/Preprocessor/aarch64-target-features.c
  clang/test/Preprocessor/arm-target-features.c
  llvm/include/llvm/Support/ARMTargetParser.def
  llvm/lib/Support/ARMTargetParser.cpp
  llvm/lib/Target/ARM/ARMInstrNEON.td
  llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp
  llvm/test/Bindings/llvm-c/ARM/disassemble.test
  llvm/test/MC/ARM/directive-arch_extension-aes-sha2.s
  llvm/test/MC/ARM/directive-arch_extension-crypto.s
  llvm/test/MC/ARM/neon-crypto.s

Index: llvm/test/MC/ARM/neon-crypto.s
===
--- llvm/test/MC/ARM/neon-crypto.s
+++ llvm/test/MC/ARM/neon-crypto.s
@@ -9,10 +9,10 @@
 @ CHECK: aese.8 q0, q1  @ encoding: [0x02,0x03,0xb0,0xf3]
 @ CHECK: aesimc.8 q0, q1@ encoding: [0xc2,0x03,0xb0,0xf3]
 @ CHECK: aesmc.8 q0, q1 @ encoding: [0x82,0x03,0xb0,0xf3]
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
+@ CHECK-V7: instruction requires: aes armv8
+@ CHECK-V7: instruction requires: aes armv8
+@ CHECK-V7: instruction requires: aes armv8
+@ CHECK-V7: instruction requires: aes armv8
 
 sha1h.32  q0, q1
 sha1su1.32  q0, q1
@@ -20,9 +20,9 @@
 @ CHECK: sha1h.32  q0, q1   @ encoding: [0xc2,0x02,0xb9,0xf3]
 @ CHECK: sha1su1.32 q0, q1  @ encoding: [0x82,0x03,0xba,0xf3]
 @ CHECK: sha256su0.32 q0, q1@ encoding: [0xc2,0x03,0xba,0xf3]
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
+@ CHECK-V7: instruction requires: sha2 armv8
+@ CHECK-V7: instruction requires: sha2 armv8
+@ CHECK-V7: instruction requires: sha2 armv8
 
 sha1c.32  q0, q1, q2
 sha1m.32  q0, q1, q2
@@ -38,14 +38,14 @@
 @ CHECK: sha256h.32  q0, q1, q2  @ encoding: [0x44,0x0c,0x02,0xf3]
 @ CHECK: sha256h2.32 q0, q1, q2  @ encoding: [0x44,0x0c,0x12,0xf3]
 @ CHECK: sha256su1.32 q0, q1, q2 @ encoding: [0x44,0x0c,0x22,0xf3]
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
-@ CHECK-V7: instruction requires: crypto armv8
+@ CHECK-V7: instruction requires: sha2 armv8
+@ CHECK-V7: instruction requires: sha2 armv8
+@ CHECK-V7: instruction requires: sha2 armv8
+@ CHECK-V7: instruction requires: sha2 armv8
+@ CHECK-V7: instruction requires: sha2 armv8
+@ CHECK-V7: instruction requires: sha2 armv8
+@ CHECK-V7: instruction requires: sha2 armv8
 
 vmull.p64 q8, d16, d17
 @ CHECK: vmull.p64  q8, d16, d17@ encoding: [0xa1,0x0e,0xe0,0xf2]
-@ CHECK-V7: instruction requires: crypto armv8
+@ CHECK-V7: instruction requires: aes armv8
Index: llvm/test/MC/ARM/directive-arch_extension-crypto.s
===
--- llvm/test/MC/ARM/directive-arch_extension-crypto.s
+++ llvm/test/MC/ARM/directive-arch_extension-crypto.s
@@ -17,38 +17,38 @@
 	.type crypto,%function
 crypto:
 	vmull.p64 q0, d0, d1
-@ CHECK-V7: error: instruction requires: crypto armv8
+@ CHECK-V7: error: instruction requires: aes armv8
 
 	aesd.8 q0, q1
-@ CHECK-V7: error: instruction requires: crypto armv8
+@ CHECK-V7: error: instruction requires: aes armv8
 	aese.8 q0, q1
-@ CHECK-V7: error: instruction requires: crypto armv8
+@ CHECK-V7: error: instruction requires: aes armv8
 	aesimc.8 q0, q1
-@ CHECK-V7: error: instruction requires: crypto armv8
+@ CHECK-V7: error: instruction requires: aes armv8
 	aesmc.8 q0, q1
-@ CHECK-V7: error: instruction requires: crypto armv8
+@ CHECK-V7: error: instruction requires: aes armv8
 
 	sha1h.32 q0, q1
-@ CHECK-V7: error: instruction requires: crypto armv8
+@ CHECK-V7: error: instruction requires: sha2 armv8
 	sha1su1.32 q0, q1
-@ CHECK-V7: error: instruction requires:

[PATCH] D101461: [clangd][NFC] Reserve storage when creating semantic token encoding.

2021-04-28 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101461

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


[clang] 1dad8c5 - [analyzer][NFC] Remove duplicated work from retain count leak report

2021-04-28 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-04-28T18:37:37+03:00
New Revision: 1dad8c5036bc912078f7859d89e3ea571616fc4a

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

LOG: [analyzer][NFC] Remove duplicated work from retain count leak report

Allocation site is the key location for the leak checker.  It is a
uniqueing location for the report and a source of information for
the warning's message.

Before this patch, we calculated and used it twice in bug report and
in bug report visitor.  Such duplication is not only harmful
performance-wise (not much, but still), but also design-wise.  Because
changing something about the end piece of the report should've been
repeated for description as well.

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

Added: 


Modified: 

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index 1fc3ee03d2e10..a004d78bfe397 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -337,11 +337,15 @@ class RefCountReportVisitor : public BugReporterVisitor {
 
 class RefLeakReportVisitor : public RefCountReportVisitor {
 public:
-  RefLeakReportVisitor(SymbolRef sym) : RefCountReportVisitor(sym) {}
+  RefLeakReportVisitor(SymbolRef Sym, const MemRegion *FirstBinding)
+  : RefCountReportVisitor(Sym), FirstBinding(FirstBinding) {}
 
   PathDiagnosticPieceRef getEndPath(BugReporterContext &BRC,
 const ExplodedNode *N,
 PathSensitiveBugReport &BR) override;
+
+private:
+  const MemRegion *FirstBinding;
 };
 
 } // end namespace retaincountchecker
@@ -729,14 +733,6 @@ RefLeakReportVisitor::getEndPath(BugReporterContext &BRC,
   // assigned to 
diff erent variables, etc.
   BR.markInteresting(Sym);
 
-  // We are reporting a leak.  Walk up the graph to get to the first node where
-  // the symbol appeared, and also get the first VarDecl that tracked object
-  // is stored to.
-  AllocationInfo AllocI = GetAllocationSite(BRC.getStateManager(), EndN, Sym);
-
-  const MemRegion* FirstBinding = AllocI.R;
-  BR.markInteresting(AllocI.InterestingMethodContext);
-
   PathDiagnosticLocation L = cast(BR).getEndOfPath();
 
   std::string sbuf;
@@ -902,15 +898,15 @@ void RefLeakReport::createDescription(CheckerContext 
&Ctx) {
 }
 
 RefLeakReport::RefLeakReport(const RefCountBug &D, const LangOptions &LOpts,
- ExplodedNode *n, SymbolRef sym,
+ ExplodedNode *N, SymbolRef Sym,
  CheckerContext &Ctx)
-: RefCountReport(D, LOpts, n, sym, /*isLeak=*/true) {
+: RefCountReport(D, LOpts, N, Sym, /*isLeak=*/true) {
 
-  deriveAllocLocation(Ctx, sym);
+  deriveAllocLocation(Ctx, Sym);
   if (!AllocBinding)
-deriveParamLocation(Ctx, sym);
+deriveParamLocation(Ctx, Sym);
 
   createDescription(Ctx);
 
-  addVisitor(std::make_unique(sym));
+  addVisitor(std::make_unique(Sym, AllocBinding));
 }



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


[clang] 61ae2db - [analyzer] Adjust the reported variable name in retain count checker

2021-04-28 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-04-28T18:37:37+03:00
New Revision: 61ae2db2d7a97af5206afe609a303071711f9e6e

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

LOG: [analyzer] Adjust the reported variable name in retain count checker

When reporting leaks, we try to attach the leaking object to some
variable, so it's easier to understand.  Before the patch, we always
tried to use the first variable that stored the object in question.
This can get very confusing for the user, if that variable doesn't
contain that object at the moment of the actual leak.  In many cases,
the warning is dismissed as false positive and it is effectively a
false positive when we fail to properly explain the warning to the
user.

This patch addresses the bigest issue in cases like this.  Now we
check if the variable still contains the leaking symbolic object.
If not, we look for the last variable to actually hold it and use
that variable instead.

rdar://76645710

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

Added: 


Modified: 

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h
clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
clang/test/Analysis/osobject-retain-release.cpp
clang/test/Analysis/retain-release-path-notes.m
clang/test/Analysis/retain-release.m

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index a004d78bfe397..48b5f8d9ba7c9 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -13,6 +13,8 @@
 
 #include "RetainCountDiagnostics.h"
 #include "RetainCountChecker.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 
 using namespace clang;
 using namespace ento;
@@ -337,15 +339,15 @@ class RefCountReportVisitor : public BugReporterVisitor {
 
 class RefLeakReportVisitor : public RefCountReportVisitor {
 public:
-  RefLeakReportVisitor(SymbolRef Sym, const MemRegion *FirstBinding)
-  : RefCountReportVisitor(Sym), FirstBinding(FirstBinding) {}
+  RefLeakReportVisitor(SymbolRef Sym, const MemRegion *LastBinding)
+  : RefCountReportVisitor(Sym), LastBinding(LastBinding) {}
 
   PathDiagnosticPieceRef getEndPath(BugReporterContext &BRC,
 const ExplodedNode *N,
 PathSensitiveBugReport &BR) override;
 
 private:
-  const MemRegion *FirstBinding;
+  const MemRegion *LastBinding;
 };
 
 } // end namespace retaincountchecker
@@ -614,6 +616,41 @@ static Optional describeRegion(const 
MemRegion *MR) {
   return None;
 }
 
+using Bindings = llvm::SmallVector;
+
+class VarBindingsCollector : public StoreManager::BindingsHandler {
+  SymbolRef Sym;
+  Bindings &Result;
+
+public:
+  VarBindingsCollector(SymbolRef Sym, Bindings &ToFill)
+  : Sym(Sym), Result(ToFill) {}
+
+  bool HandleBinding(StoreManager &SMgr, Store Store, const MemRegion *R,
+ SVal Val) override {
+SymbolRef SymV = Val.getAsLocSymbol();
+if (!SymV || SymV != Sym)
+  return true;
+
+if (isa(R))
+  Result.push_back(R);
+
+return true;
+  }
+};
+
+Bindings getAllVarBindingsForSymbol(ProgramStateManager &Manager,
+const ExplodedNode *Node, SymbolRef Sym) {
+  Bindings Result;
+  VarBindingsCollector Collector{Sym, Result};
+  while (Result.empty() && Node) {
+Manager.iterBindings(Node->getState(), Collector);
+Node = Node->getFirstPred();
+  }
+
+  return Result;
+}
+
 namespace {
 // Find the first node in the current function context that referred to the
 // tracked symbol and the memory location that value was stored to. Note, the
@@ -740,7 +777,7 @@ RefLeakReportVisitor::getEndPath(BugReporterContext &BRC,
 
   os << "Object leaked: ";
 
-  Optional RegionDescription = describeRegion(FirstBinding);
+  Optional RegionDescription = describeRegion(LastBinding);
   if (RegionDescription) {
 os << "object allocated and stored into '" << *RegionDescription << '\'';
   } else {
@@ -749,7 +786,7 @@ RefLeakReportVisitor::getEndPath(BugReporterContext &BRC,
   }
 
   // Get the retain count.
-  const RefVal* RV = getRefBinding(EndN->getState(), Sym);
+  const RefVal *RV = getRefBinding(EndN->getState()

[PATCH] D100626: [analyzer][NFC] Remove duplicated work from retain count leak report

2021-04-28 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1dad8c5036bc: [analyzer][NFC] Remove duplicated work from 
retain count leak report (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100626

Files:
  
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp


Index: 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
===
--- 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -337,11 +337,15 @@
 
 class RefLeakReportVisitor : public RefCountReportVisitor {
 public:
-  RefLeakReportVisitor(SymbolRef sym) : RefCountReportVisitor(sym) {}
+  RefLeakReportVisitor(SymbolRef Sym, const MemRegion *FirstBinding)
+  : RefCountReportVisitor(Sym), FirstBinding(FirstBinding) {}
 
   PathDiagnosticPieceRef getEndPath(BugReporterContext &BRC,
 const ExplodedNode *N,
 PathSensitiveBugReport &BR) override;
+
+private:
+  const MemRegion *FirstBinding;
 };
 
 } // end namespace retaincountchecker
@@ -729,14 +733,6 @@
   // assigned to different variables, etc.
   BR.markInteresting(Sym);
 
-  // We are reporting a leak.  Walk up the graph to get to the first node where
-  // the symbol appeared, and also get the first VarDecl that tracked object
-  // is stored to.
-  AllocationInfo AllocI = GetAllocationSite(BRC.getStateManager(), EndN, Sym);
-
-  const MemRegion* FirstBinding = AllocI.R;
-  BR.markInteresting(AllocI.InterestingMethodContext);
-
   PathDiagnosticLocation L = cast(BR).getEndOfPath();
 
   std::string sbuf;
@@ -902,15 +898,15 @@
 }
 
 RefLeakReport::RefLeakReport(const RefCountBug &D, const LangOptions &LOpts,
- ExplodedNode *n, SymbolRef sym,
+ ExplodedNode *N, SymbolRef Sym,
  CheckerContext &Ctx)
-: RefCountReport(D, LOpts, n, sym, /*isLeak=*/true) {
+: RefCountReport(D, LOpts, N, Sym, /*isLeak=*/true) {
 
-  deriveAllocLocation(Ctx, sym);
+  deriveAllocLocation(Ctx, Sym);
   if (!AllocBinding)
-deriveParamLocation(Ctx, sym);
+deriveParamLocation(Ctx, Sym);
 
   createDescription(Ctx);
 
-  addVisitor(std::make_unique(sym));
+  addVisitor(std::make_unique(Sym, AllocBinding));
 }


Index: clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -337,11 +337,15 @@
 
 class RefLeakReportVisitor : public RefCountReportVisitor {
 public:
-  RefLeakReportVisitor(SymbolRef sym) : RefCountReportVisitor(sym) {}
+  RefLeakReportVisitor(SymbolRef Sym, const MemRegion *FirstBinding)
+  : RefCountReportVisitor(Sym), FirstBinding(FirstBinding) {}
 
   PathDiagnosticPieceRef getEndPath(BugReporterContext &BRC,
 const ExplodedNode *N,
 PathSensitiveBugReport &BR) override;
+
+private:
+  const MemRegion *FirstBinding;
 };
 
 } // end namespace retaincountchecker
@@ -729,14 +733,6 @@
   // assigned to different variables, etc.
   BR.markInteresting(Sym);
 
-  // We are reporting a leak.  Walk up the graph to get to the first node where
-  // the symbol appeared, and also get the first VarDecl that tracked object
-  // is stored to.
-  AllocationInfo AllocI = GetAllocationSite(BRC.getStateManager(), EndN, Sym);
-
-  const MemRegion* FirstBinding = AllocI.R;
-  BR.markInteresting(AllocI.InterestingMethodContext);
-
   PathDiagnosticLocation L = cast(BR).getEndOfPath();
 
   std::string sbuf;
@@ -902,15 +898,15 @@
 }
 
 RefLeakReport::RefLeakReport(const RefCountBug &D, const LangOptions &LOpts,
- ExplodedNode *n, SymbolRef sym,
+ ExplodedNode *N, SymbolRef Sym,
  CheckerContext &Ctx)
-: RefCountReport(D, LOpts, n, sym, /*isLeak=*/true) {
+: RefCountReport(D, LOpts, N, Sym, /*isLeak=*/true) {
 
-  deriveAllocLocation(Ctx, sym);
+  deriveAllocLocation(Ctx, Sym);
   if (!AllocBinding)
-deriveParamLocation(Ctx, sym);
+deriveParamLocation(Ctx, Sym);
 
   createDescription(Ctx);
 
-  addVisitor(std::make_unique(sym));
+  addVisitor(std::make_unique(Sym, AllocBinding));
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e273918 - [analyzer] Track leaking object through stores

2021-04-28 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-04-28T18:37:38+03:00
New Revision: e273918038a7aa300cb8e6afebd9714bf647eed0

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

LOG: [analyzer] Track leaking object through stores

Since we can report memory leaks on one variable, while the originally
allocated object was stored into another one, we should explain
how did it get there.

rdar://76645710

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

Added: 


Modified: 

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
clang/test/Analysis/osobject-retain-release.cpp
clang/test/Analysis/retain-release-path-notes.m

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
index 48b5f8d9ba7c9..eaa1e35f62bef 100644
--- 
a/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
+++ 
b/clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
@@ -616,7 +616,7 @@ static Optional describeRegion(const MemRegion 
*MR) {
   return None;
 }
 
-using Bindings = llvm::SmallVector;
+using Bindings = llvm::SmallVector, 4>;
 
 class VarBindingsCollector : public StoreManager::BindingsHandler {
   SymbolRef Sym;
@@ -633,7 +633,7 @@ class VarBindingsCollector : public 
StoreManager::BindingsHandler {
   return true;
 
 if (isa(R))
-  Result.push_back(R);
+  Result.emplace_back(R, Val);
 
 return true;
   }
@@ -968,11 +968,28 @@ void RefLeakReport::findBindingToReport(CheckerContext 
&Ctx,
   // `AllocFirstBinding` to be one of them.  In situations like this,
   // it would still be the easiest case to explain to our users.
   if (!AllVarBindings.empty() &&
-  llvm::count(AllVarBindings, AllocFirstBinding) == 0)
+  llvm::count_if(AllVarBindings,
+ [this](const std::pair Binding) {
+   return Binding.first == AllocFirstBinding;
+ }) == 0) {
 // Let's pick one of them at random (if there is something to pick from).
-AllocBindingToReport = AllVarBindings[0];
-  else
+AllocBindingToReport = AllVarBindings[0].first;
+
+// Because 'AllocBindingToReport' is not the the same as
+// 'AllocFirstBinding', we need to explain how the leaking object
+// got from one to another.
+//
+// NOTE: We use the actual SVal stored in AllocBindingToReport here because
+//   FindLastStoreBRVisitor compares SVal's and it can get trickier for
+//   something like derived regions if we want to construct SVal from
+//   Sym. Instead, we take the value that is definitely stored in that
+//   region, thus guaranteeing that FindLastStoreBRVisitor will work.
+addVisitor(std::make_unique(
+AllVarBindings[0].second.castAs(), AllocBindingToReport,
+false, bugreporter::TrackingKind::Thorough));
+  } else {
 AllocBindingToReport = AllocFirstBinding;
+  }
 }
 
 RefLeakReport::RefLeakReport(const RefCountBug &D, const LangOptions &LOpts,

diff  --git a/clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist 
b/clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
index 0665e976efe9d..62cd52b7aa822 100644
--- a/clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
+++ b/clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
@@ -21827,6 +21827,35 @@

   
 
+
+ kindevent
+ location
+ 
+  line566
+  col3
+  file0
+ 
+ ranges
+ 
+   
+
+ line566
+ col3
+ file0
+
+
+ line566
+ col11
+ file0
+
+   
+ 
+ depth0
+ extended_message
+ 'garply' initialized here
+ message
+ 'garply' initialized here
+
 
  kindcontrol
  edges

diff  --git 
a/clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist 
b/clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
index 185525c3a8473..3b0ce877b76e6 100644
--- 
a/clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
+++ 
b/clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
@@ -5155,6 +5155,35 @@
  message
  Method returns an instance of MyObj with a +1 retain 
count
 
+
+ kindevent
+ location
+ 
+  line215

[clang] ab58238 - [analyzer] Find better description for tracked symbolic values

2021-04-28 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-04-28T18:37:38+03:00
New Revision: ab5823867c4aee7f3e02ddfaa217905c87471bf9

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

LOG: [analyzer] Find better description for tracked symbolic values

When searching for stores and creating corresponding notes, the
analyzer is more specific about the target region of the store
as opposed to the stored value.  While this description was tweaked
for constant and undefined values, it lacked in the most general
case of symbolic values.

This patch tries to find a memory region, where this value is stored,
to use it as a better alias for the value.

rdar://76645710

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
clang/test/Analysis/diagnostics/deref-track-symbolic-region.cpp
clang/test/Analysis/osobject-retain-release.cpp
clang/test/Analysis/retain-release-path-notes.m
clang/test/Analysis/uninit-const.c
clang/test/Analysis/uninit-const.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index fd334b0bc9c36..c0526469909b3 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -153,6 +153,28 @@ const Expr *bugreporter::getDerefExpr(const Stmt *S) {
   return E;
 }
 
+static const MemRegion *
+getLocationRegionIfReference(const Expr *E, const ExplodedNode *N,
+ bool LookingForReference = true) {
+  if (const auto *DR = dyn_cast(E)) {
+if (const auto *VD = dyn_cast(DR->getDecl())) {
+  if (LookingForReference && !VD->getType()->isReferenceType())
+return nullptr;
+  return N->getState()
+  ->getLValue(VD, N->getLocationContext())
+  .getAsRegion();
+}
+  }
+
+  // FIXME: This does not handle other kinds of null references,
+  // for example, references from FieldRegions:
+  //   struct Wrapper { int &ref; };
+  //   Wrapper w = { *(int *)0 };
+  //   w.ref = 1;
+
+  return nullptr;
+}
+
 /// Comparing internal representations of symbolic values (via
 /// SVal::operator==()) is a valid way to check if the value was updated,
 /// unless it's a LazyCompoundVal that may have a 
diff erent internal
@@ -1241,16 +1263,17 @@ static bool isInitializationOfVar(const ExplodedNode 
*N, const VarRegion *VR) {
 
 /// Show diagnostics for initializing or declaring a region \p R with a bad 
value.
 static void showBRDiagnostics(const char *action, llvm::raw_svector_ostream 
&os,
-  const MemRegion *R, SVal V, const DeclStmt *DS) {
-  if (R->canPrintPretty()) {
-R->printPretty(os);
+  const MemRegion *NewR, SVal V,
+  const MemRegion *OldR, const DeclStmt *DS) {
+  if (NewR->canPrintPretty()) {
+NewR->printPretty(os);
 os << " ";
   }
 
   if (V.getAs()) {
 bool b = false;
-if (R->isBoundable()) {
-  if (const auto *TR = dyn_cast(R)) {
+if (NewR->isBoundable()) {
+  if (const auto *TR = dyn_cast(NewR)) {
 if (TR->getValueType()->isObjCObjectPointerType()) {
   os << action << "nil";
   b = true;
@@ -1262,29 +1285,31 @@ static void showBRDiagnostics(const char *action, 
llvm::raw_svector_ostream &os,
 
   } else if (auto CVal = V.getAs()) {
 os << action << CVal->getValue();
+  } else if (OldR && OldR->canPrintPretty()) {
+os << action << "the value of ";
+OldR->printPretty(os);
   } else if (DS) {
 if (V.isUndef()) {
-  if (isa(R)) {
+  if (isa(NewR)) {
 const auto *VD = cast(DS->getSingleDecl());
 if (VD->getInit()) {
-  os << (R->canPrintPretty() ? "initialized" : "Initializing")
-<< " to a garbage value";
+  os << (NewR->canPrintPretty() ? "initialized" : "Initializing")
+ << " to a garbage value";
 } else {
-  os << (R->canPrintPretty() ? "declared" : "Declaring")
-<< " without an initial value";
+  os << (NewR->canPrintPretty() ? "declared" : "Declaring")
+ << " without an initial value";
 }
   }
 } else {
-  os << (R->canPrintPretty() ? "initialized" : "Initialized")
-<< " here";
+  os << (NewR->canPrintPretty() ? "initialized" : "Initialized") << " 
here";
 }
   }
 }
 
 /// Display diagnostics for passing bad region as a parameter.
-static void showBRParamDiagnostics(llvm::raw_svector_ostream& os,
-const VarRegion *VR,
-SVal V) {
+static void showBRParamDiagnostics(llvm::raw_svector_ostream &os,
+ 

[PATCH] D100839: [analyzer] Adjust the reported variable name in retain count checker

2021-04-28 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG61ae2db2d7a9: [analyzer] Adjust the reported variable name 
in retain count checker (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100839

Files:
  
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
  clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.h
  clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
  clang/test/Analysis/osobject-retain-release.cpp
  clang/test/Analysis/retain-release-path-notes.m
  clang/test/Analysis/retain-release.m

Index: clang/test/Analysis/retain-release.m
===
--- clang/test/Analysis/retain-release.m
+++ clang/test/Analysis/retain-release.m
@@ -2282,7 +2282,7 @@
 
 void testAutoreleaseReturnsInput() {
   extern CFTypeRef CFCreateSomething();
-  CFTypeRef obj = CFCreateSomething(); // expected-warning{{Potential leak of an object stored into 'obj'}}
+  CFTypeRef obj = CFCreateSomething(); // expected-warning{{Potential leak of an object stored into 'second'}}
   CFTypeRef second = CFAutorelease(obj);
   CFRetain(second);
 }
@@ -2302,7 +2302,7 @@
 }
 
 void autoreleaseReturningTypedObject() {
-  CFArrayRef arr = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{Potential leak of an object stored into 'arr'}}
+  CFArrayRef arr = CFArrayCreateMutable(0, 10, &kCFTypeArrayCallBacks); // expected-warning{{Potential leak of an object stored into 'alias'}}
   CFArrayRef alias = (CFArrayRef)CFAutorelease((CFTypeRef)arr);
   CFRetain(alias);
 }
Index: clang/test/Analysis/retain-release-path-notes.m
===
--- clang/test/Analysis/retain-release-path-notes.m
+++ clang/test/Analysis/retain-release-path-notes.m
@@ -212,7 +212,7 @@
 }
 
 -(id)initY {
-  self = [super init]; //expected-note {{Method returns an instance of MyObj with a +1 retain count}}
+  self = [super init]; // expected-note 6 {{Method returns an instance of MyObj with a +1 retain count}}
   return self;
 }
 
@@ -327,5 +327,74 @@
 
 @end
 
+int seed();
 
+@interface LeakReassignmentTests : MyObj
+@end
+
+@implementation LeakReassignmentTests
++(void)testLeakAliasSimple {
+  id Original = [[MyObj alloc] initY]; // expected-note {{Calling 'initY'}}
+   // expected-note@-1 {{Returning from 'initY'}}
+  id New = Original;
+  Original = [[MyObj alloc] initZ];
+  (void)New;
+  [Original release]; // expected-warning {{Potential leak of an object stored into 'New'}}
+  // expected-note@-1 {{Object leaked: object allocated and stored into 'New' is not referenced later in this execution path and has a retain count of +1}}
+}
+
++(void)testLeakAliasChain {
+  id Original = [[MyObj alloc] initY]; // expected-note {{Calling 'initY'}}
+   // expected-note@-1 {{Returning from 'initY'}}
+  id Intermediate = Original;
+  id New = Intermediate;
+  Original = [[MyObj alloc] initZ];
+  (void)New;
+  [Original release]; // expected-warning {{Potential leak of an object stored into 'New'}}
+  // expected-note@-1 {{Object leaked: object allocated and stored into 'New' is not referenced later in this execution path and has a retain count of +1}}
+}
+
++(void)log:(id)Obj with:(int)Num {
+  Num *= 42;
+  if (Obj )
+Num /= 2;
+}
+
++(int)calculate {
+  int x = 10;
+  int y = 25;
+  x += y * x + seed();
+  return y - x * y;
+}
+
++(void)testLeakAliasDeathInExpr {
+  id Original = [[MyObj alloc] initY]; // expected-note {{Calling 'initY'}}
+   // expected-note@-1 {{Returning from 'initY'}}
+  id New = Original;
+  Original = [[MyObj alloc] initZ];
+  [self log:New with:[self calculate]];
+  [Original release]; // expected-warning {{Potential leak of an object stored into 'New'}}
+  // expected-note@-1 {{Object leaked: object allocated and stored into 'New' is not referenced later in this execution path and has a retain count of +1}}
+}
+
++(void)testLeakReassign {
+  id Original = [[MyObj alloc] initY]; // expected-note {{Calling 'initY'}}
+   // expected-note@-1 {{Returning from 'initY'}}
+  // TODO: move warning here
+  Original = [[MyObj alloc] initZ];
+  [Original release]; // expected-warning {{Potential leak of an object stored into 'Original'}}
+  // expected-note@-1 {{Object leaked: object allocated and stored into 'Original' is not

[PATCH] D100852: [analyzer] Track leaking object through stores

2021-04-28 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe273918038a7: [analyzer] Track leaking object through stores 
(authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100852

Files:
  
clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
  clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
  clang/test/Analysis/osobject-retain-release.cpp
  clang/test/Analysis/retain-release-path-notes.m

Index: clang/test/Analysis/retain-release-path-notes.m
===
--- clang/test/Analysis/retain-release-path-notes.m
+++ clang/test/Analysis/retain-release-path-notes.m
@@ -335,8 +335,11 @@
 @implementation LeakReassignmentTests
 +(void)testLeakAliasSimple {
   id Original = [[MyObj alloc] initY]; // expected-note {{Calling 'initY'}}
-   // expected-note@-1 {{Returning from 'initY'}}
-  id New = Original;
+   // expected-note@215 {{Value assigned to 'self'}}
+   // expected-note@216 {{Returning pointer (loaded from 'self')}}
+   // expected-note@-3 {{Returning from 'initY'}}
+   // expected-note@-4 {{'Original' initialized here}}
+  id New = Original;   // expected-note {{'New' initialized here}}
   Original = [[MyObj alloc] initZ];
   (void)New;
   [Original release]; // expected-warning {{Potential leak of an object stored into 'New'}}
@@ -345,9 +348,12 @@
 
 +(void)testLeakAliasChain {
   id Original = [[MyObj alloc] initY]; // expected-note {{Calling 'initY'}}
-   // expected-note@-1 {{Returning from 'initY'}}
-  id Intermediate = Original;
-  id New = Intermediate;
+   // expected-note@215 {{Value assigned to 'self'}}
+   // expected-note@216 {{Returning pointer (loaded from 'self')}}
+   // expected-note@-3 {{Returning from 'initY'}}
+   // expected-note@-4 {{'Original' initialized here}}
+  id Intermediate = Original;  // expected-note {{'Intermediate' initialized here}}
+  id New = Intermediate;   // expected-note {{'New' initialized here}}
   Original = [[MyObj alloc] initZ];
   (void)New;
   [Original release]; // expected-warning {{Potential leak of an object stored into 'New'}}
@@ -369,8 +375,12 @@
 
 +(void)testLeakAliasDeathInExpr {
   id Original = [[MyObj alloc] initY]; // expected-note {{Calling 'initY'}}
-   // expected-note@-1 {{Returning from 'initY'}}
-  id New = Original;
+   // expected-note@215 {{Value assigned to 'self'}}
+   // expected-note@216 {{Returning pointer (loaded from 'self')}}
+   // expected-note@-3 {{Returning from 'initY'}}
+   // expected-note@-4 {{'Original' initialized here}}
+  id New = 0;
+  New = Original; // expected-note {{Value assigned to 'New'}}
   Original = [[MyObj alloc] initZ];
   [self log:New with:[self calculate]];
   [Original release]; // expected-warning {{Potential leak of an object stored into 'New'}}
Index: clang/test/Analysis/osobject-retain-release.cpp
===
--- clang/test/Analysis/osobject-retain-release.cpp
+++ clang/test/Analysis/osobject-retain-release.cpp
@@ -526,19 +526,58 @@
 
 void check_dynamic_cast_null_check() {
   OSArray *arr = OSDynamicCast(OSArray, OSObject::generateObject(1)); // expected-note{{Call to method 'OSObject::generateObject' returns an OSObject}}
-// expected-warning@-1{{Potential leak of an object}}
-// expected-note@-2{{Object leaked}}
-// expected-note@-3{{Assuming dynamic cast returns null due to type mismatch}}
+  // expected-warning@-1{{Potential leak of an object}}
+  // expected-note@-2{{Object leaked}}
+  // expected-note@-3{{Assuming dynamic cast returns null due to type mismatch}}
   if (!arr)
 return;
   arr->release();
 }
 
+void check_dynamic_cast_alias() {
+  OSObject *originalPtr = OSObject::generateObject(1);   // expected-note {{Call to method 'OSObject::generateObject' returns an OSObject}}
+  OSArray *newPtr 

[PATCH] D101041: [analyzer] Find better description for tracked symbolic values

2021-04-28 Thread Valeriy Savchenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGab5823867c4a: [analyzer] Find better description for tracked 
symbolic values (authored by vsavchenko).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101041

Files:
  clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
  clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
  clang/test/Analysis/diagnostics/deref-track-symbolic-region.cpp
  clang/test/Analysis/osobject-retain-release.cpp
  clang/test/Analysis/retain-release-path-notes.m
  clang/test/Analysis/uninit-const.c
  clang/test/Analysis/uninit-const.cpp

Index: clang/test/Analysis/uninit-const.cpp
===
--- clang/test/Analysis/uninit-const.cpp
+++ clang/test/Analysis/uninit-const.cpp
@@ -63,7 +63,7 @@
 }
 
 void f6_1(void) {
-  int t; // expected-note{{'t' declared without an initial value}}
+  int t;   // expected-note{{'t' declared without an initial value}}
   int p = f6_1_sub(t); //expected-warning {{Assigned value is garbage or undefined}}
//expected-note@-1 {{Passing value via 1st parameter 'p'}}
//expected-note@-2 {{Calling 'f6_1_sub'}}
@@ -76,8 +76,8 @@
 void f6_2(void) {
   int t;   //expected-note {{'t' declared without an initial value}}
   int &p = t;  //expected-note {{'p' initialized here}}
-  int &s = p;  //expected-note {{'s' initialized here}}
-  int &q = s;  //expected-note {{'q' initialized here}}
+  int &s = p;  //expected-note {{'s' initialized to the value of 'p'}}
+  int &q = s;  //expected-note {{'q' initialized to the value of 's'}}
   doStuff6(q); //expected-warning {{1st function call argument is an uninitialized value}}
//expected-note@-1 {{1st function call argument is an uninitialized value}}
 }
Index: clang/test/Analysis/uninit-const.c
===
--- clang/test/Analysis/uninit-const.c
+++ clang/test/Analysis/uninit-const.c
@@ -37,7 +37,7 @@
 void f_1_1(void) {
   int t; // expected-note {{'t' declared without an initial value}}
   int *tp1 = &t; // expected-note {{'tp1' initialized here}}
-  int* tp2 = tp1;// expected-note {{'tp2' initialized here}}
+  int *tp2 = tp1;// expected-note {{'tp2' initialized to the value of 'tp1'}}
   doStuff_pointerToConstInt(tp2);  // expected-warning {{1st function call argument is a pointer to uninitialized value}}
// expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
 }
@@ -53,7 +53,7 @@
 // expected-note@-1{{Calling 'f_2_sub'}}
 // expected-note@-2{{Returning from 'f_2_sub'}}
 // expected-note@-3{{'p' initialized here}}
-  int* tp = p; // expected-note {{'tp' initialized here}}
+  int *tp = p;  // expected-note {{'tp' initialized to the value of 'p'}}
   doStuff_pointerToConstInt(tp); // expected-warning {{1st function call argument is a pointer to uninitialized value}}
   // expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
 }
@@ -70,7 +70,7 @@
 
 void f_5(void) {
   int ta[5];   // expected-note {{'ta' initialized here}}
-  int* tp = ta;// expected-note {{'tp' initialized here}}
+  int *tp = ta;// expected-note {{'tp' initialized here}}
   doStuff_pointerToConstInt(tp);  // expected-warning {{1st function call argument is a pointer to uninitialized value}}
// expected-note@-1 {{1st function call argument is a pointer to uninitialized value}}
 }
Index: clang/test/Analysis/retain-release-path-notes.m
===
--- clang/test/Analysis/retain-release-path-notes.m
+++ clang/test/Analysis/retain-release-path-notes.m
@@ -339,7 +339,7 @@
// expected-note@216 {{Returning pointer (loaded from 'self')}}
// expected-note@-3 {{Returning from 'initY'}}
// expected-note@-4 {{'Original' initialized here}}
-  id New = Original;   // expected-note {{'New' initialized here}}
+  id New = Original;   // expected-note {{'New' initialized to the value of 'Original'}}
   Original = [[MyObj alloc] initZ];
   (void)New;
   [Original release]; // expected-warning {{Potential leak of an object stored into 'New'}}
@@ -352,8 +352,8 @@
// expected-note@216 {{Returning pointer (loaded from 'self')}}
// expected-note@-3 {{Returning from 'initY'}}
// expected-note@-4 {{'Original' initialized here}}
-  id Intermediate = Or

[PATCH] D101209: [PowerPC] Provide fastmath sqrt and div functions in altivec.h

2021-04-28 Thread Bardia Mahjour via Phabricator via cfe-commits
bmahjour requested changes to this revision.
bmahjour added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:15130
+  Value *Y = EmitScalarExpr(E->getArg(1));
+  auto Ret = Builder.CreateFDiv(X, Y, "recipdiv");
+  Builder.setFastMathFlags(FMF);

I wonder if we can do better than "fdiv fast"... does the current lowering of 
"fdiv fast" employ an estimation algorithm via iterative refinement on POWER?



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:15134
+}
+llvm::Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType);
+auto Ret = Builder.CreateCall(F, X);

This doesn't implement a reciprocal square root, it just performs a square 
root! At the very least we need a divide instruction following the call to the 
intrinsic, but I'm not sure if that'll result in the most optimal codegen at 
the end. Perhaps we need a new builtin?



Comment at: clang/test/CodeGen/builtins-ppc-vsx.c:2297
+  // CHECK-LABEL: test_rsqrtd
+  // CHECK: call fast <2 x double> @llvm.sqrt.v2f64
+  // CHECK-LE-LABEL: test_rsqrtd

See my comment above about the missing reciprocal operation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101209

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


[clang] 602c8b4 - [analyzer][NFC] Fix tests failing after a rebase

2021-04-28 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-04-28T18:55:20+03:00
New Revision: 602c8b4db5dbe88be7080b411455538c9b4cd117

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

LOG: [analyzer][NFC] Fix tests failing after a rebase

Added: 


Modified: 
clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist

Removed: 




diff  --git 
a/clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist 
b/clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
index fb92943d00dc..e9f4f7577649 100644
--- 
a/clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
+++ 
b/clang/test/Analysis/Inputs/expected-plists/retain-release-path-notes.m.plist
@@ -6561,12 +6561,12 @@
 start
  
   
-   line381
+   line391
col3
file0
   
   
-   line381
+   line391
col4
file0
   
@@ -6574,12 +6574,12 @@
 end
  
   
-   line381
+   line391
col17
file0
   
   
-   line381
+   line391
col17
file0
   
@@ -6591,7 +6591,7 @@
  kindevent
  location
  
-  line381
+  line391
   col17
   file0
  
@@ -6599,12 +6599,12 @@
  

 
- line381
+ line391
  col17
  file0
 
 
- line381
+ line391
  col37
  file0
 
@@ -6731,7 +6731,7 @@
  kindevent
  location
  
-  line381
+  line391
   col17
   file0
  
@@ -6739,12 +6739,12 @@
  

 
- line381
+ line391
  col17
  file0
 
 
- line381
+ line391
  col37
  file0
 
@@ -6764,12 +6764,12 @@
 start
  
   
-   line381
+   line391
col17
file0
   
   
-   line381
+   line391
col17
file0
   
@@ -6777,12 +6777,12 @@
 end
  
   
-   line381
+   line391
col3
file0
   
   
-   line381
+   line391
col4
file0
   
@@ -6798,12 +6798,12 @@
 start
  
   
-   line381
+   line391
col3
file0
   
   
-   line381
+   line391
col4
file0
   
@@ -6811,12 +6811,12 @@
 end
  
   
-   line385
+   line395
col3
file0
   
   
-   line385
+   line395
col3
file0
   
@@ -6828,7 +6828,7 @@
  kindevent
  location
  
-  line385
+  line395
   col3
   file0
  
@@ -6836,12 +6836,12 @@
  

 
- line385
+ line395
  col3
  file0
 
 
- line385
+ line395
  col20
  file0
 
@@ -6865,7 +6865,7 @@
   issue_hash_function_offset1
   location
   
-   line385
+   line395
col3
file0
   
@@ -6879,10 +6879,10 @@
 219
 220
 221
-380
-381
-384
-385
+390
+391
+394
+395

   
   
@@ -6897,12 +6897,12 @@
 start
  
   
-   line390
+   line400
col3
file0
   
   
-   line390
+   line400
col4
file0
   
@@ -6910,12 +6910,12 @@
 end
  
   
-   line390
+   line400
col17
file0
   
   
-   line390
+   line400
col17
file0
   
@@ -6927,7 +6927,7 @@
  kindevent
  location
  
-  line390
+  line400
   col17
   file0
  
@@ -6935,12 +6935,12 @@
  

 
- line390
+ line400
  col17
  file0
 
 
- line390
+ line400
  col37
  file0
 
@@ -7067,7 +7067,7 @@
  kindevent
  location
  
-  line390
+  line400
   col17
   file0
  
@@ -7075,12 +7075,12 @@
  

 
- line390
+ line400
  col17
  file0
 
 
- line390
+ line400
  col37
  file0
 
@@ -7100,12 +7100,12 @@
 start
  
   
-   line390
+   line400
col17

[PATCH] D101426: [RISCV] Update subset naming convertion for the latest spec

2021-04-28 Thread Zakk Chen via Phabricator via cfe-commits
khchen added inline comments.



Comment at: clang/lib/Driver/ToolChains/Arch/RISCV.cpp:180
+  // as described in RISC-V User-Level ISA 20191213.
   SmallVector Split;
   Exts.split(Split, StringRef("_"));

If we want to update the arch string rules to ISA 20191213, should we also need 
to handle `Zicsr`, `Zifencei`, `Zam` and `Ztso`?



Comment at: clang/lib/Driver/ToolChains/Arch/RISCV.cpp:294
   // The canonical order specified in ISA manual.
   // Ref: Table 22.1 in RISC-V User-Level ISA V2.2
   StringRef StdExts = "mafdqlcbjtpvn";

nit: Table 27.1 in RISC-V User-Level ISA 20191213


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101426

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


[clang] 671f0e2 - [clang] Make libBasic not depend on MC

2021-04-28 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-04-28T12:16:22-04:00
New Revision: 671f0e2e189c561512511331d95de382e2d6d15d

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

LOG: [clang] Make libBasic not depend on MC

Reduces numbers of files built for clang-format from 575 to 449.

Requires two small changes:

1. Don't use llvm::ExceptionHandling in LangOptions. This isn't
   even quite the right type since we don't use all of its values.
   Tweaks the changes made in:
   - https://reviews.llvm.org/D93215
   - https://reviews.llvm.org/D93216

2. Move section name validation code added (long ago) in commit 30ba67439 out
   of libBasic into Sema and base the check on the triple. This is a bit less
   OOP-y, but completely in line with what we do in many other places in Sema.

No behavior change.

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Basic/TargetInfo.h
clang/include/clang/Driver/Options.td
clang/include/clang/Sema/Sema.h
clang/lib/Basic/CMakeLists.txt
clang/lib/Basic/Targets/OSTargets.h
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Sema/CMakeLists.txt
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaDeclAttr.cpp
llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 39fdefc77fbee..5122770316cde 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -112,7 +112,7 @@ def err_fe_action_not_available : Error<
 def err_fe_invalid_alignment : Error<
 "invalid value '%1' in '%0'; alignment must be a power of 2">;
 def err_fe_invalid_exception_model
-   : Error<"invalid exception model 
'%select{none|dwarf|sjlj|arm|seh|wasm|aix}0' for target '%1'">;
+   : Error<"invalid exception model '%select{none|sjlj|seh|dwarf|wasm}0' for 
target '%1'">;
 def warn_fe_concepts_ts_flag : Warning<
   "-fconcepts-ts is deprecated - use '-std=c++20' for Concepts support">,
   InGroup;

diff  --git a/clang/include/clang/Basic/LangOptions.h 
b/clang/include/clang/Basic/LangOptions.h
index c898ef19a6cfd..85fe4af720235 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -23,7 +23,6 @@
 #include "llvm/ADT/FloatingPointMode.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Triple.h"
-#include "llvm/MC/MCTargetOptions.h"
 #include 
 #include 
 
@@ -222,7 +221,7 @@ class LangOptions : public LangOptionsBase {
   };
 
   /// Possible exception handling behavior.
-  using ExceptionHandlingKind = llvm::ExceptionHandling;
+  enum class ExceptionHandlingKind { None, SjLj, WinEH, DwarfCFI, Wasm };
 
   enum class LaxVectorConversionKind {
 /// Permit no implicit vector bitcasts.
@@ -410,19 +409,19 @@ class LangOptions : public LangOptionsBase {
   }
 
   bool hasSjLjExceptions() const {
-return getExceptionHandling() == llvm::ExceptionHandling::SjLj;
+return getExceptionHandling() == ExceptionHandlingKind::SjLj;
   }
 
   bool hasSEHExceptions() const {
-return getExceptionHandling() == llvm::ExceptionHandling::WinEH;
+return getExceptionHandling() == ExceptionHandlingKind::WinEH;
   }
 
   bool hasDWARFExceptions() const {
-return getExceptionHandling() == llvm::ExceptionHandling::DwarfCFI;
+return getExceptionHandling() == ExceptionHandlingKind::DwarfCFI;
   }
 
   bool hasWasmExceptions() const {
-return getExceptionHandling() == llvm::ExceptionHandling::Wasm;
+return getExceptionHandling() == ExceptionHandlingKind::Wasm;
   }
 };
 

diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index 3300fe012aa81..532ff4554656c 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1147,21 +1147,6 @@ class TargetInfo : public virtual 
TransferrableTargetInfo,
 getTriple().getVendor() == llvm::Triple::SCEI);
   }
 
-  /// An optional hook that targets can implement to perform semantic
-  /// checking on attribute((section("foo"))) specifiers.
-  ///
-  /// In this case, "foo" is passed in to be checked.  If the section
-  /// specifier is invalid, the backend should return an Error that indicates
-  /// the problem.
-  ///
-  /// This hook is a simple quality of implementation feature to catch errors
-  /// and give good diagnostics in cases when the assembler or code generator
-  /// would otherwise reject the section specifier.
- 

[PATCH] D101463: [clang] Make libBasic not depend on MC

2021-04-28 Thread Nico Weber via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG671f0e2e189c: [clang] Make libBasic not depend on MC 
(authored by thakis).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101463

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Basic/CMakeLists.txt
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/CMakeLists.txt
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
  llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
  llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn

Index: llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
+++ llvm/utils/gn/secondary/clang/tools/clang-format/BUILD.gn
@@ -12,6 +12,7 @@
 "//clang/lib/Frontend/",
 "//clang/lib/Sema/",
 "//llvm/lib/IR",
+"//llvm/lib/MC",
   ]
   sources = [ "ClangFormat.cpp" ]
 }
Index: llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Sema/BUILD.gn
@@ -25,6 +25,7 @@
 "//clang/lib/Edit",
 "//clang/lib/Lex",
 "//llvm/lib/Frontend/OpenMP",
+"//llvm/lib/MC",
 "//llvm/lib/Support",
   ]
   sources = [
Index: llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Basic/BUILD.gn
@@ -49,7 +49,6 @@
 "//clang/include/clang/Sema:AttrParsedAttrKinds",
 "//clang/include/clang/Sema:AttrSpellingListIndex",
 "//llvm/include/llvm/Config:llvm-config",
-"//llvm/lib/MC",
 "//llvm/lib/Support",
   ]
   include_dirs = [ "." ]
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -40,6 +40,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/IR/Assumptions.h"
+#include "llvm/MC/MCSectionMachO.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/raw_ostream.h"
@@ -2985,9 +2986,29 @@
   return ::new (Context) SectionAttr(Context, CI, Name);
 }
 
+/// Used to implement to perform semantic checking on
+/// attribute((section("foo"))) specifiers.
+///
+/// In this case, "foo" is passed in to be checked.  If the section
+/// specifier is invalid, return an Error that indicates the problem.
+///
+/// This is a simple quality of implementation feature to catch errors
+/// and give good diagnostics in cases when the assembler or code generator
+/// would otherwise reject the section specifier.
+llvm::Error Sema::isValidSectionSpecifier(StringRef SecName) {
+  if (!Context.getTargetInfo().getTriple().isOSDarwin())
+return llvm::Error::success();
+
+  // Let MCSectionMachO validate this.
+  StringRef Segment, Section;
+  unsigned TAA, StubSize;
+  bool HasTAA;
+  return llvm::MCSectionMachO::ParseSectionSpecifier(SecName, Segment, Section,
+ TAA, HasTAA, StubSize);
+}
+
 bool Sema::checkSectionName(SourceLocation LiteralLoc, StringRef SecName) {
-  if (llvm::Error E =
-  Context.getTargetInfo().isValidSectionSpecifier(SecName)) {
+  if (llvm::Error E = isValidSectionSpecifier(SecName)) {
 Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
 << toString(std::move(E)) << 1 /*'section'*/;
 return false;
@@ -3021,8 +3042,7 @@
 // `#pragma code_seg("segname")` uses checkSectionName() instead.
 static bool checkCodeSegName(Sema &S, SourceLocation LiteralLoc,
  StringRef CodeSegName) {
-  if (llvm::Error E =
-  S.Context.getTargetInfo().isValidSectionSpecifier(CodeSegName)) {
+  if (llvm::Error E = S.isValidSectionSpecifier(CodeSegName)) {
 S.Diag(LiteralLoc, diag::err_attribute_section_invalid_for_target)
 << toString(std::move(E)) << 0 /*'code-seg'*/;
 return false;
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -269,8 +269,10 @@
   AlignPackStack.Act(PragmaLoc, Action, StringRef(), Info);
 }
 
-void Sema::ActOnPragmaClangSection(SourceLocation PragmaLoc, PragmaClangSectionAction Action,
-   Pragm

[PATCH] D100667: [clang] Fix assert() crash when checking undeduced arg alignment

2021-04-28 Thread Adam Czachorowski via Phabricator via cfe-commits
adamcz updated this revision to Diff 341244.
adamcz added a comment.

moved the test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100667

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast 
-frecovery-ast-type -o - %s -fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast 
-frecovery-ast-type -o - %s -std=c++17 -fsyntax-only -verify
 
 namespace test0 {
 struct Indestructible {
@@ -26,7 +26,10 @@
 void foo(); // expected-note 3{{requires 0 arguments}}
 void func() {
   // verify that "field has incomplete type" diagnostic is suppressed.
-  typeof(foo(42)) var; // expected-error {{no matching function}}
+  typeof(foo(42)) var; // expected-error {{no matching function}} \
+   // expected-error {{use of undeclared identifier 
'typeof'}} \
+   // expected-error {{expected ';' after expression}} \
+   // expected-error {{use of undeclared identifier 'var'}}
 
   // FIXME: suppress the "cannot initialize a variable" diagnostic.
   int a = foo(1); // expected-error {{no matching function}} \
@@ -116,3 +119,23 @@
 template const int k = f(T()); // expected-error {{no matching 
function}}
 static_assert(k == 1, ""); // expected-note {{instantiation of}}
 }
+
+namespace test11 {
+// Verify we do not assert()-fail here.
+template  void foo(T &t);
+template 
+void bar(T t) {
+  foo(t);
+}
+
+template 
+struct S { // expected-note {{candidate}}
+  S(T t);  // expected-note {{candidate}}
+  ~S();
+};
+template  S(T t) -> S;
+
+void baz() {
+  bar(S(123)); // expected-error {{no matching conversion}}
+}
+} // namespace test11
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -19661,8 +19661,10 @@
   if (isSFINAEContext())
 return ExprError();
 
-  if (T.isNull() || !Context.getLangOpts().RecoveryASTType)
+  if (T.isNull() || T->isUndeducedType() ||
+  !Context.getLangOpts().RecoveryASTType)
 // We don't know the concrete type, fallback to dependent type.
 T = Context.DependentTy;
+
   return RecoveryExpr::Create(Context, T, Begin, End, SubExprs);
 }
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -4540,8 +4540,7 @@
 
   // Find expected alignment, and the actual alignment of the passed object.
   // getTypeAlignInChars requires complete types
-  if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType() ||
-  ParamTy->isUndeducedType() || ArgTy->isUndeducedType())
+  if (ParamTy->isIncompleteType() || ArgTy->isIncompleteType())
 return;
 
   CharUnits ParamAlign = Context.getTypeAlignInChars(ParamTy);


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -fsyntax-only -verify
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -frecovery-ast -frecovery-ast-type -o - %s -std=c++17 -fsyntax-only -verify
 
 namespace test0 {
 struct Indestructible {
@@ -26,7 +26,10 @@
 void foo(); // expected-note 3{{requires 0 arguments}}
 void func() {
   // verify that "field has incomplete type" diagnostic is suppressed.
-  typeof(foo(42)) var; // expected-error {{no matching function}}
+  typeof(foo(42)) var; // expected-error {{no matching function}} \
+   // expected-error {{use of undeclared identifier 'typeof'}} \
+   // expected-error {{expected ';' after expression}} \
+   // expected-error {{use of undeclared identifier 'var'}}
 
   // FIXME: suppress the "cannot initialize a variable" diagnostic.
   int a = foo(1); // expected-error {{no matching function}} \
@@ -116,3 +119,23 @@
 template const int k = f(T()); // expected-error {{no matching function}}
 static_assert(k == 1, ""); // expected-note {{instantiation of}}
 }
+
+namespace test11 {
+// Verify we do not assert()-fail here.
+template  void foo(T &t);
+template 
+void bar(T t) {
+  foo(t);
+}
+
+template 
+struct S { // expected-note {{candidate}}
+  S(T t);  // expected-note {{candidate}}
+  ~S();
+};
+template  S(T t) -> S;
+
+void baz() {
+  bar(S(123)); // expected-error {{no matching conversion}}
+}
+} // namespace test11
Index: clang/lib/Sem

[PATCH] D101471: [clang-tidy] Add proper emplace checks to modernize-use-emplace

2021-04-28 Thread Nicolas van Kempen via Phabricator via cfe-commits
nicovank created this revision.
nicovank added reviewers: alexfh, Prazek, kuhar.
nicovank added projects: clang, clang-tools-extra.
Herald added a subscriber: xazax.hun.
nicovank requested review of this revision.
Herald added a subscriber: cfe-commits.

modernize-use-emplace only recommends going from a push_back to an
emplace_back, but does not provide a recommendation when emplace_back is
improperly used. This adds the functionality of warning the user when
an unecessary temporary is created while calling emplace_back or other "emplacy"
functions from the STL containers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101471

Files:
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
  clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.h
  clang-tools-extra/test/clang-tidy/checkers/modernize-use-emplace.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-use-emplace.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/modernize-use-emplace.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-use-emplace.cpp
@@ -10,15 +10,36 @@
 
 namespace std {
 template 
-class initializer_list
-{
+class initializer_list {
 public:
   initializer_list() noexcept {}
 };
 
+template 
+class pair {
+public:
+  pair() = default;
+  pair(const pair &) = default;
+  pair(pair &&) = default;
+
+  pair(const T1 &, const T2 &) {}
+  pair(T1 &&, T2 &&) {}
+
+  template 
+  pair(const pair &){};
+  template 
+  pair(pair &&){};
+};
+
 template 
 class vector {
 public:
+  using value_type = T;
+
+  class iterator {};
+  class const_iterator {};
+  const_iterator begin() { return const_iterator{}; }
+
   vector() = default;
   vector(initializer_list) {}
 
@@ -26,55 +47,231 @@
   void push_back(T &&) {}
 
   template 
-  void emplace_back(Args &&... args){};
+  void emplace_back(Args &&...args){};
+  template 
+  iterator emplace(const_iterator pos, Args &&...args){};
   ~vector();
 };
+
 template 
 class list {
 public:
+  using value_type = T;
+
+  class iterator {};
+  class const_iterator {};
+  const_iterator begin() { return const_iterator{}; }
+
   void push_back(const T &) {}
   void push_back(T &&) {}
 
   template 
-  void emplace_back(Args &&... args){};
+  iterator emplace(const_iterator pos, Args &&...args){};
+  template 
+  void emplace_back(Args &&...args){};
+  template 
+  void emplace_front(Args &&...args){};
   ~list();
 };
 
 template 
 class deque {
 public:
+  using value_type = T;
+
+  class iterator {};
+  class const_iterator {};
+  const_iterator begin() { return const_iterator{}; }
+
   void push_back(const T &) {}
   void push_back(T &&) {}
 
   template 
-  void emplace_back(Args &&... args){};
+  iterator emplace(const_iterator pos, Args &&...args){};
+  template 
+  void emplace_back(Args &&...args){};
+  template 
+  void emplace_front(Args &&...args){};
   ~deque();
 };
 
-template  struct remove_reference { using type = T; };
-template  struct remove_reference { using type = T; };
-template  struct remove_reference { using type = T; };
+template 
+class forward_list {
+public:
+  using value_type = T;
+
+  class iterator {};
+  class const_iterator {};
+  const_iterator begin() { return const_iterator{}; }
+
+  template 
+  void emplace_front(Args &&...args){};
+  template 
+  iterator emplace_after(const_iterator pos, Args &&...args){};
+};
 
-template  class pair {
+template 
+class set {
 public:
-  pair() = default;
-  pair(const pair &) = default;
-  pair(pair &&) = default;
+  using value_type = T;
 
-  pair(const T1 &, const T2 &) {}
-  pair(T1 &&, T2 &&) {}
+  class iterator {};
+  class const_iterator {};
+  const_iterator begin() { return const_iterator{}; }
+
+  template 
+  void emplace(Args &&...args){};
+  template 
+  iterator emplace_hint(const_iterator pos, Args &&...args){};
+};
+
+template 
+class map {
+public:
+  using value_type = std::pair;
+
+  class iterator {};
+  class const_iterator {};
+  const_iterator begin() { return const_iterator{}; }
+
+  template 
+  void emplace(Args &&...args){};
+  template 
+  iterator emplace_hint(const_iterator pos, Args &&...args){};
+};
+
+template 
+class multiset {
+public:
+  using value_type = T;
+
+  class iterator {};
+  class const_iterator {};
+  const_iterator begin() { return const_iterator{}; }
+
+  template 
+  void emplace(Args &&...args){};
+  template 
+  iterator emplace_hint(const_iterator pos, Args &&...args){};
+};
+
+template 
+class multimap {
+public:
+  using value_type = std::pair;
+
+  class iterator {};
+  class const_iterator {};
+  const_iterator begin() { return const_iterator{}; }
+
+  template 
+  void emplace(Args &&...args){};
+  template 
+  iterator emplace_hint(const_iterator pos, Args &&...args){};
+};
+
+template 
+class unordered_set {
+public:
+  using value_type = T;
+
+  class iterator {};
+  class const_iterator {};
+  const_iterator begin() { return const_iterator{}; }
 
-  t

[PATCH] D101471: [clang-tidy] Add proper emplace checks to modernize-use-emplace

2021-04-28 Thread Nicolas van Kempen via Phabricator via cfe-commits
nicovank added a comment.

As you can see, this will fail some tests as there is one corner case which is 
tricky to handle:

  std::vector>> vec;
  // This is valid and should not be changed.
  vec.emplace_back(std::make_tuple(13, 31));

Does anyone have a suggestion for a good way to handle this?

Ideally, it would be nice to just check that the type of the temporary matches 
the type of the `value_type`, but I've tried that with a simple `==`, and it 
then becomes a problem with strings, where for example

  std::vector> vec;
  vec.emplace_back(std::make_pair("foo", "bar"));

would not be changed as it would list the pair as a `std::pair`, and not match with `std::pair`.
Is there some way that I couldn't find to check if two `clang::Types` are 
"compatible"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101471

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


[PATCH] D101122: introduce flag -fsanitize-address-detect-stack-use-after-return-mode. No functional change.

2021-04-28 Thread Dan Liew via Phabricator via cfe-commits
delcypher added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:225-228
+ENUM_CODEGENOPT(SanitizeAddressDetectStackUseAfterReturnMode,
+llvm::AsanDetectStackUseAfterReturnMode, 2,
+llvm::AsanDetectStackUseAfterReturnMode::Runtime
+) ///< Set detection mode for stack-use-after-return.

vitalybuka wrote:
> vitalybuka wrote:
> > Mode->Kind to be consistent with the file
> I believe for consistency we need:
> 1. Var name (SanitizeAddressDetectStackUseAfterReturn) no Mode/Kind suffix
> 2. Enum type AsanDetectStackUseAfterReturnKind uses "kind"
> 3. Actual flag includes no "kind" 
> -fsanitize-address-detect-stack-use-after-return=
> 
> BTW. @delcypher  -fsanitize-address-destructor-kind was not consistent with 
> the rest of file, but I am not sure it's worth of fixing now.
> 
> 
@vitalybuka It's not too late to fix this because the 
`-fsanitize-address-destructor-kind=` flag hasn't been adopted yet AFAIK.

Am I right in understanding that what I landed doesn't match points 1 and 3 
above? If you can confirm that's what you'd like to be changed I can put up 
some patches to fix this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101122

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


[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-04-28 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield added a comment.

In D100581#2721705 , @dbabokin wrote:

> One more false-positive:
>
>   void foo() {
> extern int yydebug;
> yydebug = 1;
>   }
>
> It was triggered in ISPC build.

Thanks for the report. It seems the thing to do is to modify the warning so 
that variables marked extern are not candidates for this warning. I will make a 
new commit with that modification unless there are other suggestions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-04-28 Thread Dmitry Babokin via Phabricator via cfe-commits
dbabokin added a comment.

> Thanks for the report. It seems the thing to do is to modify the warning so 
> that variables marked extern are not candidates for this warning. I will make 
> a new commit with that modification unless there are other suggestions.

I agree, this seems to be the right fix. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


[PATCH] D101389: [clang][CodeGen] Fix address space for sret

2021-04-28 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 341257.
yaxunl added a comment.

cast return value to default address space since it is expected. also fix debug 
info


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

https://reviews.llvm.org/D101389

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/test/CodeGenCUDA/amdgpu-sret.cu

Index: clang/test/CodeGenCUDA/amdgpu-sret.cu
===
--- /dev/null
+++ clang/test/CodeGenCUDA/amdgpu-sret.cu
@@ -0,0 +1,101 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx906 \
+// RUN:   -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device \
+// RUN:   -emit-llvm -o - -x hip %s -debug-info-kind=limited \
+// RUN:   | FileCheck %s
+
+// Check no assertion with debug info.
+
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx906 \
+// RUN:   -aux-triple x86_64-unknown-linux-gnu -fcuda-is-device \
+// RUN:   -S -o %t.s -x hip %s \
+// RUN:   -debug-info-kind=limited
+
+#include "Inputs/cuda.h"
+ 
+struct A {
+  int x[100];
+  __device__ A();
+};
+
+struct B {
+  int x[100];
+};
+
+__device__ B b;
+
+__device__ void callee(A *a);
+
+// CHECK-LABEL: @_Z5func1v(
+// CHECK-SAME: %struct.A addrspace(5)* noalias sret(%struct.A) align 4 %[[RET:.*]])
+// CHECK: %x = alloca [100 x i32], align 16, addrspace(5)
+// CHECK: %x.ascast = addrspacecast [100 x i32] addrspace(5)* %x to [100 x i32]*
+// CHECK: %p = alloca %struct.A*, align 8, addrspace(5)
+// CHECK: %p.ascast = addrspacecast %struct.A* addrspace(5)* %p to %struct.A**
+// CHECK: %[[RET_CAST:.*]] = addrspacecast %struct.A addrspace(5)* %[[RET]] to %struct.A*
+// CHECK: call void @llvm.dbg.declare(metadata %struct.A addrspace(5)* %[[RET]]
+// CHECK: call void @_ZN1AC1Ev(%struct.A* nonnull dereferenceable(400) %[[RET_CAST]])
+// CHECK: call void @llvm.dbg.declare(metadata [100 x i32] addrspace(5)* %x
+// CHECK: call void @_Z6calleeP1A(%struct.A* %[[RET_CAST]])
+// CHECK: %[[RET_CAST2:.*]] = bitcast %struct.A* %[[RET_CAST]] to i8*
+// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %[[RET_CAST2]], i8* align 16 %{{.*}}, i64 400, i1 false)
+// CHECK: call void @llvm.dbg.declare(metadata %struct.A* addrspace(5)* %p
+// CHECK: store %struct.A* %[[RET_CAST]], %struct.A** %p.ascast
+__device__ A func1() {
+  A a;
+  int x[100];
+  callee(&a);
+  __builtin_memcpy(&a, x, 400);
+  A *p = &a;
+  return a;
+}
+
+// CHECK-LABEL: @_Z6func1av(%struct.B addrspace(5)* noalias sret(%struct.B) align 4 
+__device__ B func1a() {
+  B b;
+  return b;
+}
+
+// Check returning the return value again.
+
+// CHECK-LABEL: @_Z5func2v(
+// CHECK-SAME: %struct.A addrspace(5)* noalias sret(%struct.A) align 4 %[[RET:.*]])
+// CHECK: %[[CAST1:.*]] = addrspacecast %struct.A addrspace(5)* %[[RET]] to %struct.A*
+// CHECK: %[[CAST2:.*]] = addrspacecast %struct.A* %[[CAST1]] to %struct.A addrspace(5)*
+// CHECK: call void @_Z5func1v(%struct.A addrspace(5)* sret(%struct.A) align 4 %[[CAST2]])
+__device__ A func2() {
+  A a = func1();
+  return a;
+}
+
+// Check assigning the return value to a global variable.
+
+// CHECK-LABEL: @_Z5func3v(
+// CHECK: %[[RET:.*]] = alloca %struct.B, align 4, addrspace(5)
+// CHECK: %[[CAST1:.*]] = addrspacecast %struct.B addrspace(5)* %[[RET]] to %struct.B*
+// CHECK: %[[CAST2:.*]] = addrspacecast %struct.B* %[[CAST1]] to %struct.B addrspace(5)*
+// CHECK: call void @_Z6func1av(%struct.B addrspace(5)* sret(%struct.B) align 4 %[[CAST2]]
+// CHECK: %[[CAST3:.*]] = bitcast %struct.B* %[[CAST1]] to i8*
+// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64{{.*}}@b{{.*}}%[[CAST3]]
+__device__ void func3() {
+  b = func1a();
+}
+
+// Check assigning the return value to a temporary variable.
+
+// CHECK-LABEL: @_Z5func4v(
+// CHECK: %[[TMP:.*]] = alloca %struct.A, align 4, addrspace(5)
+// CHECK: %[[TMP_CAST1:.*]] = addrspacecast %struct.A addrspace(5)* %[[TMP]] to %struct.A*
+// CHECK: %[[RET:.*]] = alloca %struct.A, align 4, addrspace(5)
+// CHECK: %[[RET_CAST1:.*]] = addrspacecast %struct.A addrspace(5)* %[[RET]] to %struct.A*
+// CHECK: call void @_ZN1AC1Ev(%struct.A* nonnull dereferenceable(400) %[[TMP_CAST1]])
+// CHECK: %[[RET_CAST2:.*]] = addrspacecast %struct.A* %[[RET_CAST1]] to %struct.A addrspace(5)*
+// CHECK: call void @_Z5func1v(%struct.A addrspace(5)* sret(%struct.A) align 4 %[[RET_CAST2]]
+// CHECK: %[[TMP_CAST2:.*]] = bitcast %struct.A* %[[TMP_CAST1]] to i8*
+// CHECK: %[[RET_CAST3:.*]] = bitcast %struct.A* %[[RET_CAST1]] to i8*
+// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64{{.*}}%[[TMP_CAST2]]{{.*}}%[[RET_CAST3]]
+__device__ void func4() {
+  A a;
+  a = func1();
+}
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1084,6 +1084,22 @@
 RetTy->isObjCRetainableType())
  

[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-04-28 Thread Nathan Chancellor via Phabricator via cfe-commits
nathanchance added a comment.

In D100581#2721430 , @nickdesaulniers 
wrote:

> Huh, maybe not: https://godbolt.org/z/PnE1fMGWo

This difference has caused some confusion already for the Linux kernel: 
https://lore.kernel.org/r/202104280827.lsczw8xg-...@intel.com

I am not sure it is appropriate to warn there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-04-28 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In D100581#2723329 , @nathanchance 
wrote:

> In D100581#2721430 , 
> @nickdesaulniers wrote:
>
>> Huh, maybe not: https://godbolt.org/z/PnE1fMGWo
>
> This difference has caused some confusion already for the Linux kernel:

It's quite obviously used, since it's the condition variable for the loop.
Is clang CFG not modelling that correctly?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-04-28 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Also, from the reviewer list, it doesn't look like anyone with much familiarity 
with clang/clang diags actually participated in the review?
I think this might be the point to revert and re-review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


[PATCH] D101122: introduce flag -fsanitize-address-detect-stack-use-after-return-mode. No functional change.

2021-04-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/include/clang/Basic/CodeGenOptions.def:225-228
+ENUM_CODEGENOPT(SanitizeAddressDetectStackUseAfterReturnMode,
+llvm::AsanDetectStackUseAfterReturnMode, 2,
+llvm::AsanDetectStackUseAfterReturnMode::Runtime
+) ///< Set detection mode for stack-use-after-return.

delcypher wrote:
> vitalybuka wrote:
> > vitalybuka wrote:
> > > Mode->Kind to be consistent with the file
> > I believe for consistency we need:
> > 1. Var name (SanitizeAddressDetectStackUseAfterReturn) no Mode/Kind suffix
> > 2. Enum type AsanDetectStackUseAfterReturnKind uses "kind"
> > 3. Actual flag includes no "kind" 
> > -fsanitize-address-detect-stack-use-after-return=
> > 
> > BTW. @delcypher  -fsanitize-address-destructor-kind was not consistent with 
> > the rest of file, but I am not sure it's worth of fixing now.
> > 
> > 
> @vitalybuka It's not too late to fix this because the 
> `-fsanitize-address-destructor-kind=` flag hasn't been adopted yet AFAIK.
> 
> Am I right in understanding that what I landed doesn't match points 1 and 3 
> above? If you can confirm that's what you'd like to be changed I can put up 
> some patches to fix this.
Correct
I'd expect 

```
ENUM_CODEGENOPT(SanitizeAddressDtor, llvm::AsanDtorKind, 2,
llvm::AsanDtorKind::Global)
```

and 

```
def sanitize_address_destructor_EQ
: Joined<["-"], "fsanitize-address-destructor=">,
  MetaVarName<"">,
  Flags<[CC1Option]>,
  HelpText<"Set destructor type used in ASan instrumentation">,
  Group,
  Values<"none,global">,
  NormalizedValuesScope<"llvm::AsanDtorKind">,
  NormalizedValues<["None", "Global"]>,
  MarshallingInfoEnum, "Global">;
```

And one more thing, probably not very important, and matter of personal 
preferences.
Maybe we don't need MetaVarName<""> for both of these flags.
Without MetaVarName documentation is going to be 
-fsanitize-address-destructor= 
MetaVarName just lets use to replace  with more common and specific 
, .. etc.
To me  is almost generic as , so why not to stick to default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101122

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


[PATCH] D101209: [PowerPC] Provide fastmath sqrt and div functions in altivec.h

2021-04-28 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:15130
+  Value *Y = EmitScalarExpr(E->getArg(1));
+  auto Ret = Builder.CreateFDiv(X, Y, "recipdiv");
+  Builder.setFastMathFlags(FMF);

bmahjour wrote:
> I wonder if we can do better than "fdiv fast"... does the current lowering of 
> "fdiv fast" employ an estimation algorithm via iterative refinement on POWER?
Yes. This `fast` includes `arcp` which will trigger the estimation+refinement 
algorithm in the back end.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:15134
+}
+llvm::Function *F = CGM.getIntrinsic(Intrinsic::sqrt, ResultType);
+auto Ret = Builder.CreateCall(F, X);

bmahjour wrote:
> This doesn't implement a reciprocal square root, it just performs a square 
> root! At the very least we need a divide instruction following the call to 
> the intrinsic, but I'm not sure if that'll result in the most optimal codegen 
> at the end. Perhaps we need a new builtin?
Oh, I misread the documentation. This really seems like a bizarre thing to 
offer a user. I will change this to `1/sqrt()`.
In terms of providing optimal performance, with fast-math, the optimizer should 
get rid of the divide. If compiled at `-O0`, it isn't reasonable to expect 
optimal performance to begin with.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101209

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


[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-04-28 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield added a comment.

In D100581#2723348 , @lebedev.ri 
wrote:

> Also, from the reviewer list, it doesn't look like anyone with much 
> familiarity with clang/clang diags actually participated in the review?
> I think this might be the point to revert and re-review.

Alright, someone with the capability please revert if that's the correct action.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


[PATCH] D101344: [clang-format] Add `SpacesInAngles: Leave` option to keep spacing inside angle brackets as is.

2021-04-28 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

Looks good, and I'm always in favor of having a `Leave` Option. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101344

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


[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-04-28 Thread Andi via Phabricator via cfe-commits
Abpostelnicu added a comment.

Please revert this. This change hasn’t been tested nor reviewed enough. Also I 
don’t remember seeing this proposed on cfe dev mailing list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


[PATCH] D101479: [Driver] Support libc++ in MSVC

2021-04-28 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: hans, rnk, thakis.
phosek requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This implements support for using libc++ headers in MSVC toolchain.
We only support libc++ headers that are part of the toolchain, and
not headers installed elsewhere on the system.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101479

Files:
  clang/lib/Driver/ToolChains/MSVC.cpp
  clang/test/Driver/msvc-libcxx.cpp


Index: clang/test/Driver/msvc-libcxx.cpp
===
--- /dev/null
+++ clang/test/Driver/msvc-libcxx.cpp
@@ -0,0 +1,3 @@
+// RUN: %clangxx -target x86_64-pc-windows-msvc --stdlib=libc++ -### %s 2>&1 | 
FileCheck %s -check-prefix MSVC-LIBCXX
+
+// MSVC-LIBCXX: "-internal-isystem" 
"{{.*[/\\]}}include{{/|}}c++{{/|}}v1"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1323,7 +1323,34 @@
 
 void MSVCToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
  ArgStringList &CC1Args) const 
{
-  // FIXME: There should probably be logic here to find libc++ on Windows.
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+  DriverArgs.hasArg(options::OPT_nostdincxx))
+return;
+
+  const Driver &D = getDriver();
+
+  auto AddLibcxxIncludePath = [&](StringRef Path) {
+std::string Version = detectLibcxxVersion(Path);
+if (Version.empty())
+  return;
+
+SmallString<128> Dir(Path);
+llvm::sys::path::append(Dir, "c++", Version);
+addSystemInclude(DriverArgs, CC1Args, Dir);
+  };
+
+  switch (GetCXXStdlibType(DriverArgs)) {
+  case ToolChain::CST_Libcxx: {
+SmallString<128> P(D.Dir);
+llvm::sys::path::append(P, "..", "include");
+AddLibcxxIncludePath(P);
+break;
+  }
+
+  default:
+// TODO: Shall we report an error for other C++ standard libraries?
+break;
+  }
 }
 
 VersionTuple MSVCToolChain::computeMSVCVersion(const Driver *D,


Index: clang/test/Driver/msvc-libcxx.cpp
===
--- /dev/null
+++ clang/test/Driver/msvc-libcxx.cpp
@@ -0,0 +1,3 @@
+// RUN: %clangxx -target x86_64-pc-windows-msvc --stdlib=libc++ -### %s 2>&1 | FileCheck %s -check-prefix MSVC-LIBCXX
+
+// MSVC-LIBCXX: "-internal-isystem" "{{.*[/\\]}}include{{/|}}c++{{/|}}v1"
Index: clang/lib/Driver/ToolChains/MSVC.cpp
===
--- clang/lib/Driver/ToolChains/MSVC.cpp
+++ clang/lib/Driver/ToolChains/MSVC.cpp
@@ -1323,7 +1323,34 @@
 
 void MSVCToolChain::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs,
  ArgStringList &CC1Args) const {
-  // FIXME: There should probably be logic here to find libc++ on Windows.
+  if (DriverArgs.hasArg(options::OPT_nostdlibinc) ||
+  DriverArgs.hasArg(options::OPT_nostdincxx))
+return;
+
+  const Driver &D = getDriver();
+
+  auto AddLibcxxIncludePath = [&](StringRef Path) {
+std::string Version = detectLibcxxVersion(Path);
+if (Version.empty())
+  return;
+
+SmallString<128> Dir(Path);
+llvm::sys::path::append(Dir, "c++", Version);
+addSystemInclude(DriverArgs, CC1Args, Dir);
+  };
+
+  switch (GetCXXStdlibType(DriverArgs)) {
+  case ToolChain::CST_Libcxx: {
+SmallString<128> P(D.Dir);
+llvm::sys::path::append(P, "..", "include");
+AddLibcxxIncludePath(P);
+break;
+  }
+
+  default:
+// TODO: Shall we report an error for other C++ standard libraries?
+break;
+  }
 }
 
 VersionTuple MSVCToolChain::computeMSVCVersion(const Driver *D,
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2021-04-28 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 341279.
leonardchan marked 3 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetCXXABI.def
  clang/include/clang/Basic/TargetCXXABI.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenCXX/cxx-abi-switch.cpp
  clang/test/Frontend/invalid-cxx-abi.cpp

Index: clang/test/Frontend/invalid-cxx-abi.cpp
===
--- /dev/null
+++ clang/test/Frontend/invalid-cxx-abi.cpp
@@ -0,0 +1,34 @@
+// These should succeed.
+// RUN: %clang -c -fc++-abi=itanium %s
+// RUN: %clang -c -fc++-abi=arm -target arm64 %s
+// RUN: %clang -c -fc++-abi=ios -target arm64-apple-ios %s
+// RUN: %clang -c -fc++-abi=aarch64 -target arm64 %s
+// RUN: %clang -c -fc++-abi=mips -target mips %s
+// RUN: %clang -c -fc++-abi=webassembly -target wasm64 %s
+// RUN: %clang -c -fc++-abi=fuchsia -target x86_64-unknown-fuchsia %s
+// RUN: %clang -S -fc++-abi=xl -target powerpc-unknown-aix %s -o /dev/null
+// RUN: %clang -c -fc++-abi=microsoft -target x86_64-windows-msvc %s
+// RUN: %clang_cc1 -fc++-abi=itanium %s
+// RUN: %clang_cc1 -fc++-abi=arm -triple arm64 %s
+// RUN: %clang_cc1 -fc++-abi=ios -triple arm64-apple-ios %s
+// RUN: %clang_cc1 -fc++-abi=aarch64 -triple arm64 %s
+// RUN: %clang_cc1 -fc++-abi=mips -triple mips %s
+// RUN: %clang_cc1 -fc++-abi=webassembly -triple wasm64 %s
+// RUN: %clang_cc1 -fc++-abi=fuchsia -triple x86_64-unknown-fuchsia %s
+// RUN: %clang_cc1 -S -fc++-abi=xl -triple powerpc-unknown-aix %s -o /dev/null
+// RUN: %clang_cc1 -fc++-abi=microsoft -triple x86_64-windows-msvc %s
+
+// RUN: not %clang -c -fc++-abi=InvalidABI %s 2>&1 | FileCheck %s -check-prefix=INVALID
+// RUN: not %clang -c -fc++-abi=Fuchsia %s 2>&1 | FileCheck %s -check-prefix=CASE-SENSITIVE
+// RUN: not %clang_cc1 -fc++-abi=InvalidABI %s 2>&1 | FileCheck %s -check-prefix=INVALID
+// RUN: not %clang_cc1 -fc++-abi=Fuchsia %s 2>&1 | FileCheck %s -check-prefix=CASE-SENSITIVE
+// INVALID: error: Invalid C++ ABI name 'InvalidABI'
+// CASE-SENSITIVE: error: Invalid C++ ABI name 'Fuchsia'
+
+// The flag is propgated from the driver to cc1.
+// RUN: %clang -fc++-abi=InvalidABI %s -### 2>&1 | FileCheck %s -check-prefix=CC1-FLAG
+// CC1-FLAG: -fc++-abi=InvalidABI
+
+// Some C++ ABIs are not supported on some platforms.
+// RUN: not %clang_cc1 -c -fc++-abi=fuchsia -triple i386 %s 2>&1 | FileCheck %s -check-prefix=UNSUPPORTED-FUCHSIA
+// UNSUPPORTED-FUCHSIA: error: C++ ABI 'fuchsia' is not supported on target triple 'i386'
Index: clang/test/CodeGenCXX/cxx-abi-switch.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx-abi-switch.cpp
@@ -0,0 +1,28 @@
+// Assert that the ABI switch uses the proper codegen. Fuchsia uses the
+// "return this" ABI on constructors and destructors by default, but if we
+// explicitly choose the generic itanium C++ ABI, we should not return "this" on
+// ctors/dtors.
+//
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-linux-gnu -fc++-abi=itanium | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-linux-gnu -fc++-abi=itanium | FileCheck %s
+
+class A {
+public:
+  virtual ~A();
+  int x_;
+};
+
+class B : public A {
+public:
+  B(int *i);
+  virtual ~B();
+  int *i_;
+};
+
+B::B(int *i) : i_(i) {}
+B::~B() {}
+
+// CHECK: define{{.*}} void @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* %i)
+// CHECK: define{{.*}} void @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* %i)
+// CHECK: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
+// CHECK: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3506,6 +3506,10 @@
   if (Opts.getSignReturnAddressKey() ==
   LangOptions::SignReturnAddressKeyKind::BKey)
 GenerateArg(Args, OPT_msign_return_address_key_EQ, "b_key", SA);
+
+  if (Opts.CXXABI)
+GenerateArg(Args, OPT_fcxx_abi_EQ, TargetCXXABI::getSpelling(*Opts.CXXABI),
+SA);
 }
 
 bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
@@ -3989,6 +3993,20 @@
 }
   }
 
+  // The value can be empty, which indicates the system default should be used.
+  StringRef CXXABI = Args.getLastArgValue(OPT_fcxx_abi_EQ);
+  if (!CXXABI.empty()) {
+if (!TargetCXXABI::isABI(CXXABI)) {
+  Diags.Report(diag::err_invalid_cxx_abi) <<

[PATCH] D85802: [clang] Add -fc++-abi= flag for specifying which C++ ABI to use

2021-04-28 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 341280.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85802

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Basic/TargetCXXABI.def
  clang/include/clang/Basic/TargetCXXABI.h
  clang/include/clang/Driver/Options.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGenCXX/cxx-abi-switch.cpp
  clang/test/Frontend/invalid-cxx-abi.cpp

Index: clang/test/Frontend/invalid-cxx-abi.cpp
===
--- /dev/null
+++ clang/test/Frontend/invalid-cxx-abi.cpp
@@ -0,0 +1,34 @@
+// These should succeed.
+// RUN: %clang -c -fc++-abi=itanium %s
+// RUN: %clang -c -fc++-abi=arm -target arm64 %s
+// RUN: %clang -c -fc++-abi=ios -target arm64-apple-ios %s
+// RUN: %clang -c -fc++-abi=aarch64 -target arm64 %s
+// RUN: %clang -c -fc++-abi=mips -target mips %s
+// RUN: %clang -c -fc++-abi=webassembly -target wasm64 %s
+// RUN: %clang -c -fc++-abi=fuchsia -target x86_64-unknown-fuchsia %s
+// RUN: %clang -S -fc++-abi=xl -target powerpc-unknown-aix %s -o /dev/null
+// RUN: %clang -c -fc++-abi=microsoft -target x86_64-windows-msvc %s
+// RUN: %clang_cc1 -fc++-abi=itanium %s
+// RUN: %clang_cc1 -fc++-abi=arm -triple arm64 %s
+// RUN: %clang_cc1 -fc++-abi=ios -triple arm64-apple-ios %s
+// RUN: %clang_cc1 -fc++-abi=aarch64 -triple arm64 %s
+// RUN: %clang_cc1 -fc++-abi=mips -triple mips %s
+// RUN: %clang_cc1 -fc++-abi=webassembly -triple wasm64 %s
+// RUN: %clang_cc1 -fc++-abi=fuchsia -triple x86_64-unknown-fuchsia %s
+// RUN: %clang_cc1 -S -fc++-abi=xl -triple powerpc-unknown-aix %s -o /dev/null
+// RUN: %clang_cc1 -fc++-abi=microsoft -triple x86_64-windows-msvc %s
+
+// RUN: not %clang -c -fc++-abi=InvalidABI %s 2>&1 | FileCheck %s -check-prefix=INVALID
+// RUN: not %clang -c -fc++-abi=Fuchsia %s 2>&1 | FileCheck %s -check-prefix=CASE-SENSITIVE
+// RUN: not %clang_cc1 -fc++-abi=InvalidABI %s 2>&1 | FileCheck %s -check-prefix=INVALID
+// RUN: not %clang_cc1 -fc++-abi=Fuchsia %s 2>&1 | FileCheck %s -check-prefix=CASE-SENSITIVE
+// INVALID: error: Invalid C++ ABI name 'InvalidABI'
+// CASE-SENSITIVE: error: Invalid C++ ABI name 'Fuchsia'
+
+// The flag is propgated from the driver to cc1.
+// RUN: %clang -fc++-abi=InvalidABI %s -### 2>&1 | FileCheck %s -check-prefix=CC1-FLAG
+// CC1-FLAG: -fc++-abi=InvalidABI
+
+// Some C++ ABIs are not supported on some platforms.
+// RUN: not %clang_cc1 -c -fc++-abi=fuchsia -triple i386 %s 2>&1 | FileCheck %s -check-prefix=UNSUPPORTED-FUCHSIA
+// UNSUPPORTED-FUCHSIA: error: C++ ABI 'fuchsia' is not supported on target triple 'i386'
Index: clang/test/CodeGenCXX/cxx-abi-switch.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/cxx-abi-switch.cpp
@@ -0,0 +1,28 @@
+// Assert that the ABI switch uses the proper codegen. Fuchsia uses the
+// "return this" ABI on constructors and destructors by default, but if we
+// explicitly choose the generic itanium C++ ABI, we should not return "this" on
+// ctors/dtors.
+//
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=x86_64-unknown-fuchsia -fc++-abi=itanium | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple=aarch64-unknown-fuchsia -fc++-abi=itanium | FileCheck %s
+
+class A {
+public:
+  virtual ~A();
+  int x_;
+};
+
+class B : public A {
+public:
+  B(int *i);
+  virtual ~B();
+  int *i_;
+};
+
+B::B(int *i) : i_(i) {}
+B::~B() {}
+
+// CHECK: define{{.*}} void @_ZN1BC2EPi(%class.B* {{[^,]*}} %this, i32* %i)
+// CHECK: define{{.*}} void @_ZN1BC1EPi(%class.B* {{[^,]*}} %this, i32* %i)
+// CHECK: define{{.*}} void @_ZN1BD2Ev(%class.B* {{[^,]*}} %this)
+// CHECK: define{{.*}} void @_ZN1BD1Ev(%class.B* {{[^,]*}} %this)
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -3506,6 +3506,10 @@
   if (Opts.getSignReturnAddressKey() ==
   LangOptions::SignReturnAddressKeyKind::BKey)
 GenerateArg(Args, OPT_msign_return_address_key_EQ, "b_key", SA);
+
+  if (Opts.CXXABI)
+GenerateArg(Args, OPT_fcxx_abi_EQ, TargetCXXABI::getSpelling(*Opts.CXXABI),
+SA);
 }
 
 bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
@@ -3989,6 +3993,20 @@
 }
   }
 
+  // The value can be empty, which indicates the system default should be used.
+  StringRef CXXABI = Args.getLastArgValue(OPT_fcxx_abi_EQ);
+  if (!CXXABI.empty()) {
+if (!TargetCXXABI::isABI(CXXABI)) {
+  Diags.Report(diag::err_invalid_cxx_abi) << CXXABI;
+} else {
+  auto Kind = TargetCX

[PATCH] D99381: [compiler-rt][hwasan] Add Fuchsia-specific sanitizer platform limits

2021-04-28 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D99381#2721619 , @phosek wrote:

> What I think @vitalybuka meant is keeping 
> `sanitizer_platform_limits_fuchsia.h` as you had it, but including it 
> unconditionally. Since the entire file is wrapped in `#if SANITIZER_FUCHSIA 
> ... #endif`, the inclusion would be a no-op on platforms other than Fuchsia 
> so no need to wrap the `#include` in `#if SANITIZER_FUCHSIA` as well.

Correct., Just:

  #include "sanitizer_common/sanitizer_platform_limits_fuchsia.h"
  #include "sanitizer_common/sanitizer_platform_limits_posix.h"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99381

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


[clang] 0395f9e - [ARM] Neon Polynomial vadd Intrinsic fix

2021-04-28 Thread Ryan Santhirarajan via cfe-commits

Author: Ryan Santhirarajan
Date: 2021-04-28T11:59:40-07:00
New Revision: 0395f9e70b8f2dc55d3ef0bb7195c3542deffc5a

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

LOG: [ARM] Neon Polynomial vadd Intrinsic fix

The Neon vadd intrinsics were added to the ARMSIMD intrinsic map,
however due to being defined under an AArch64 guard in arm_neon.td,
were not previously useable on ARM. This change rectifies that.

It is important to note that poly128 is not valid on ARM, thus it was
extracted out of the original arm_neon.td definition and separated
for the sake of AArch64.

Reviewed By: DavidSpickett

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

Added: 
clang/test/CodeGen/arm-poly-add.c

Modified: 
clang/include/clang/Basic/arm_neon.td
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index 0d97f0a1c2dc..fdd82692223c 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -708,6 +708,11 @@ def SCALAR_HALF_SET_LANE : IOpInst<"vset_lane", ".1.I", 
"h", OP_SCALAR_HALF_SET_
 def SCALAR_HALF_GET_LANEQ : IOpInst<"vget_lane", "1.I", "Qh", 
OP_SCALAR_HALF_GET_LNQ>;
 def SCALAR_HALF_SET_LANEQ : IOpInst<"vset_lane", ".1.I", "Qh", 
OP_SCALAR_HALF_SET_LNQ>;
 
+
+// Non poly128_t vaddp for Arm and AArch64
+// TODO: poly128_t not implemented on arm32
+def VADDP   : WInst<"vadd", "...", "PcPsPlQPcQPsQPl">;
+
 

 // AArch64 Intrinsics
 
@@ -1171,7 +1176,9 @@ def SM4E : SInst<"vsm4e", "...", "QUi">;
 def SM4EKEY : SInst<"vsm4ekey", "...", "QUi">;
 }
 
-def VADDP   : WInst<"vadd", "...", "PcPsPlQPcQPsQPlQPk">;
+
+// poly128_t vadd for AArch64 only see VADDP for the rest
+def VADDP_Q   : WInst<"vadd", "...", "QPk">;
 
 

 // Float -> Int conversions with explicit rounding mode

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 9681a8ad5cd3..8990cd825af3 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5460,7 +5460,6 @@ static const ARMVectorIntrinsicInfo ARMSIMDIntrinsicMap 
[] = {
   NEONMAP1(vabsq_v, arm_neon_vabs, 0),
   NEONMAP0(vadd_v),
   NEONMAP0(vaddhn_v),
-  NEONMAP0(vaddq_p128),
   NEONMAP0(vaddq_v),
   NEONMAP1(vaesdq_v, arm_neon_aesd, 0),
   NEONMAP1(vaeseq_v, arm_neon_aese, 0),

diff  --git a/clang/test/CodeGen/arm-poly-add.c 
b/clang/test/CodeGen/arm-poly-add.c
new file mode 100644
index ..fe2afca00d47
--- /dev/null
+++ b/clang/test/CodeGen/arm-poly-add.c
@@ -0,0 +1,86 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple armv8.2a-arm-none-eabi \
+// RUN:   -target-feature +neon \
+// RUN:   -mfloat-abi hard \
+// RUN: -disable-O0-optnone -emit-llvm -o - %s | opt -S -mem2reg \
+// RUN:  | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @test_vadd_p8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = xor <8 x i8> [[A:%.*]], [[B:%.*]]
+// CHECK-NEXT:ret <8 x i8> [[TMP0]]
+//
+poly8x8_t test_vadd_p8(poly8x8_t a, poly8x8_t b) {
+  return vadd_p8 (a, b);
+}
+
+// CHECK-LABEL: @test_vadd_p16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i16> [[A:%.*]] to <8 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <4 x i16> [[B:%.*]] to <8 x i8>
+// CHECK-NEXT:[[TMP2:%.*]] = xor <8 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[TMP3:%.*]] = bitcast <8 x i8> [[TMP2]] to <4 x i16>
+// CHECK-NEXT:ret <4 x i16> [[TMP3]]
+//
+poly16x4_t test_vadd_p16(poly16x4_t a, poly16x4_t b) {
+  return vadd_p16 (a, b);
+}
+
+// CHECK-LABEL: @test_vadd_p64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <1 x i64> [[A:%.*]] to <8 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <1 x i64> [[B:%.*]] to <8 x i8>
+// CHECK-NEXT:[[TMP2:%.*]] = xor <8 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[TMP3:%.*]] = bitcast <8 x i8> [[TMP2]] to <1 x i64>
+// CHECK-NEXT:ret <1 x i64> [[TMP3]]
+//
+poly64x1_t test_vadd_p64(poly64x1_t a, poly64x1_t b) {
+  return vadd_p64(a, b);
+}
+
+// CHECK-LABEL: @test_vaddq_p8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = xor <16 x i8> [[A:%.*]], [[B:%.*]]
+// CHECK-NEXT:ret <16 x i8> [[TMP0]]
+//
+poly8x16_t test_vaddq_p8(poly8x16_t a, poly8x16_t b){
+  return vaddq_p8(a, b);
+}
+
+// CHECK-LABEL: @test_vaddq_p16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <8 x i16> [[A:%.*]] to <16 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <8 x i16> 

[PATCH] D100772: [ARM] Neon Polynomial vadd Intrinsic fix

2021-04-28 Thread Ryan Santhirarajan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0395f9e70b8f: [ARM] Neon Polynomial vadd Intrinsic fix 
(authored by rsanthir.quic).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100772

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/arm-poly-add.c

Index: clang/test/CodeGen/arm-poly-add.c
===
--- /dev/null
+++ clang/test/CodeGen/arm-poly-add.c
@@ -0,0 +1,86 @@
+// REQUIRES: arm-registered-target
+// RUN: %clang_cc1 -triple armv8.2a-arm-none-eabi \
+// RUN:   -target-feature +neon \
+// RUN:   -mfloat-abi hard \
+// RUN: -disable-O0-optnone -emit-llvm -o - %s | opt -S -mem2reg \
+// RUN:  | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @test_vadd_p8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = xor <8 x i8> [[A:%.*]], [[B:%.*]]
+// CHECK-NEXT:ret <8 x i8> [[TMP0]]
+//
+poly8x8_t test_vadd_p8(poly8x8_t a, poly8x8_t b) {
+  return vadd_p8 (a, b);
+}
+
+// CHECK-LABEL: @test_vadd_p16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i16> [[A:%.*]] to <8 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <4 x i16> [[B:%.*]] to <8 x i8>
+// CHECK-NEXT:[[TMP2:%.*]] = xor <8 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[TMP3:%.*]] = bitcast <8 x i8> [[TMP2]] to <4 x i16>
+// CHECK-NEXT:ret <4 x i16> [[TMP3]]
+//
+poly16x4_t test_vadd_p16(poly16x4_t a, poly16x4_t b) {
+  return vadd_p16 (a, b);
+}
+
+// CHECK-LABEL: @test_vadd_p64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <1 x i64> [[A:%.*]] to <8 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <1 x i64> [[B:%.*]] to <8 x i8>
+// CHECK-NEXT:[[TMP2:%.*]] = xor <8 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[TMP3:%.*]] = bitcast <8 x i8> [[TMP2]] to <1 x i64>
+// CHECK-NEXT:ret <1 x i64> [[TMP3]]
+//
+poly64x1_t test_vadd_p64(poly64x1_t a, poly64x1_t b) {
+  return vadd_p64(a, b);
+}
+
+// CHECK-LABEL: @test_vaddq_p8(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = xor <16 x i8> [[A:%.*]], [[B:%.*]]
+// CHECK-NEXT:ret <16 x i8> [[TMP0]]
+//
+poly8x16_t test_vaddq_p8(poly8x16_t a, poly8x16_t b){
+  return vaddq_p8(a, b);
+}
+
+// CHECK-LABEL: @test_vaddq_p16(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <8 x i16> [[A:%.*]] to <16 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <8 x i16> [[B:%.*]] to <16 x i8>
+// CHECK-NEXT:[[TMP2:%.*]] = xor <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[TMP2]] to <8 x i16>
+// CHECK-NEXT:ret <8 x i16> [[TMP3]]
+//
+poly16x8_t test_vaddq_p16(poly16x8_t a, poly16x8_t b){
+  return vaddq_p16(a, b);
+}
+
+// CHECK-LABEL: @test_vaddq_p64(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast <2 x i64> [[A:%.*]] to <16 x i8>
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast <2 x i64> [[B:%.*]] to <16 x i8>
+// CHECK-NEXT:[[TMP2:%.*]] = xor <16 x i8> [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[TMP2]] to <2 x i64>
+// CHECK-NEXT:ret <2 x i64> [[TMP3]]
+//
+poly64x2_t test_vaddq_p64(poly64x2_t a, poly64x2_t b){
+  return vaddq_p64(a, b);
+}
+
+// TODO: poly128_t not implemented on aarch32
+// CHCK-LABEL: @test_vaddq_p128(
+// CHCK-NEXT:  entry:
+// CHCK-NEXT:[[TMP0:%.*]] = bitcast i128 [[A:%.*]] to <16 x i8>
+// CHCK-NEXT:[[TMP1:%.*]] = bitcast i128 [[B:%.*]] to <16 x i8>
+// CHCK-NEXT:[[TMP2:%.*]] = xor <16 x i8> [[TMP0]], [[TMP1]]
+// CHCK-NEXT:[[TMP3:%.*]] = bitcast <16 x i8> [[TMP2]] to i128
+// CHCK-NEXT:ret i128 [[TMP3]]
+//
+//poly128_t test_vaddq_p128 (poly128_t a, poly128_t b){
+//  return vaddq_p128(a, b);
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -5460,7 +5460,6 @@
   NEONMAP1(vabsq_v, arm_neon_vabs, 0),
   NEONMAP0(vadd_v),
   NEONMAP0(vaddhn_v),
-  NEONMAP0(vaddq_p128),
   NEONMAP0(vaddq_v),
   NEONMAP1(vaesdq_v, arm_neon_aesd, 0),
   NEONMAP1(vaeseq_v, arm_neon_aese, 0),
Index: clang/include/clang/Basic/arm_neon.td
===
--- clang/include/clang/Basic/arm_neon.td
+++ clang/include/clang/Basic/arm_neon.td
@@ -708,6 +708,11 @@
 def SCALAR_HALF_GET_LANEQ : IOpInst<"vget_lane", "1.I", "Qh", OP_SCALAR_HALF_GET_LNQ>;
 def SCALAR_HALF_SET_LANEQ : IOpInst<"vset_lane", ".1.I", "Qh", OP_SCALAR_HALF_SET_LNQ>;
 
+
+// Non poly128_t vaddp for Arm and AArch64
+// TODO: poly128_t not implemented on arm32
+def VADDP   : WInst<"vadd", "...", "PcPsPlQPcQPsQPl">;
+
 
 // AArch6

[PATCH] D101480: Revert "[Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable"

2021-04-28 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield created this revision.
mbenfield added reviewers: aeubanks, george.burgess.iv, lebedev.ri, 
Abpostelnicu.
Herald added subscribers: frasercrmck, luismarques, apazos, sameer.abuasal, 
pengfei, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, 
rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, 
rbar, asb.
mbenfield requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This reverts commit 9b0501abc7b515b740fb5ee929817442dd3029a5 
.

There are false positives in the linux kernel and other projects.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101480

Files:
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaStmt.cpp
  clang/test/CodeGen/X86/x86_32-xsave.c
  clang/test/CodeGen/X86/x86_64-xsave.c
  clang/test/CodeGen/builtins-arm.c
  clang/test/CodeGen/builtins-riscv.c
  clang/test/FixIt/fixit.cpp
  clang/test/Misc/warning-wall.c
  clang/test/Sema/shift.c
  clang/test/Sema/vector-gcc-compat.c
  clang/test/Sema/warn-unused-but-set-parameters.c
  clang/test/Sema/warn-unused-but-set-variables.c
  clang/test/SemaCXX/goto.cpp
  clang/test/SemaCXX/shift.cpp
  clang/test/SemaCXX/sizeless-1.cpp
  clang/test/SemaCXX/warn-unused-but-set-parameters-cpp.cpp
  clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
  clang/test/SemaObjC/foreach.m

Index: clang/test/SemaObjC/foreach.m
===
--- clang/test/SemaObjC/foreach.m
+++ clang/test/SemaObjC/foreach.m
@@ -1,4 +1,4 @@
-/* RUN: %clang_cc1 -Wall -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -fsyntax-only -verify -std=c89 -pedantic %s
+/* RUN: %clang_cc1 -Wall -fsyntax-only -verify -std=c89 -pedantic %s
  */
 
 @class NSArray;
Index: clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
===
--- clang/test/SemaCXX/warn-unused-but-set-variables-cpp.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-// RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused-but-set-variable -verify %s
-
-struct S {
-  int i;
-};
-
-int f0() {
-  int y; // expected-warning{{variable 'y' set but not used}}
-  y = 0;
-
-  int z __attribute__((unused));
-  z = 0;
-
-  // In C++, don't warn for structs. (following gcc's behavior)
-  struct S s;
-  struct S t;
-  s = t;
-
-  int x;
-  x = 0;
-  return x + 5;
-}
-
-void f1(void) {
-  (void)^() {
-int y; // expected-warning{{variable 'y' set but not used}}
-y = 0;
-
-int x;
-x = 0;
-return x;
-  };
-}
-
-void f2() {
-  // Don't warn for either of these cases.
-  constexpr int x = 2;
-  const int y = 1;
-  char a[x];
-  char b[y];
-}
Index: clang/test/SemaCXX/warn-unused-but-set-parameters-cpp.cpp
===
--- clang/test/SemaCXX/warn-unused-but-set-parameters-cpp.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// RUN: %clang_cc1 -fblocks -fsyntax-only -Wunused-but-set-parameter -verify %s
-
-int f0(int x,
-   int y, // expected-warning{{parameter 'y' set but not used}}
-   int z __attribute__((unused))) {
-  y = 0;
-  return x;
-}
-
-void f1(void) {
-  (void)^(int x,
-  int y, // expected-warning{{parameter 'y' set but not used}}
-  int z __attribute__((unused))) {
-y = 0;
-return x;
-  };
-}
-
-struct S {
-  int i;
-};
-
-// In C++, don't warn for a struct (following gcc).
-void f3(struct S s) {
-  struct S t;
-  s = t;
-}
-
-// Make sure this doesn't warn.
-struct A {
-  int i;
-  A(int j) : i(j) {}
-};
Index: clang/test/SemaCXX/sizeless-1.cpp
===
--- clang/test/SemaCXX/sizeless-1.cpp
+++ clang/test/SemaCXX/sizeless-1.cpp
@@ -1,7 +1,7 @@
-// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++98 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++11 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++17 %s
-// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wno-unused-but-set-parameter -Wno-unused-but-set-variable -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=gnu++17 %s
+// RUN: %clang_cc1 -fcxx-exceptions -fsyntax-only -verify -W -Wall -Wrange-loop-analysis -triple arm64-linux-gnu -target-feature +sve -std=c++98 %s
+// RUN: %clang_

[PATCH] D100581: [Clang] -Wunused-but-set-parameter and -Wunused-but-set-variable

2021-04-28 Thread Michael Benfield via Phabricator via cfe-commits
mbenfield added a comment.

Link for the revert: https://reviews.llvm.org/D101480


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100581

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


  1   2   >