[PATCH] D72227: Add options for clang to align branches within 32B boundary

2020-01-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2010
 
+static void AlignBranchesOptions(const Driver , const ArgList ,
+ ArgStringList ) {

The convention is `camelCase`. This file is inconsistent but some newly added 
functions follow this convention.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2012
+ ArgStringList ) {
+  if (const Arg *A = Args.getLastArg(options::OPT_malign_branch_boundary_EQ)) {
+StringRef Value = A->getValue();

if (!TC.getTriple().isX86()) {
  D.Diag(diag::err_drv_unsupported_opt_for_target)
  << A->getAsString(Args) << TripleStr;
return;
  }

I will add Triple::isX86 in D72247.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:2045
+
+  if (Args.hasFlag(options::OPT_mbranches_within_32B_boundaries,
+   options::OPT_mno_branches_within_32B_boundaries, false)) {

`OPT_mbranches_within_32B_boundaries` should provide default values which can 
be overridden by more specific options.



Comment at: clang/test/Driver/intel-align-branch.c:28
+//
+// // RUN: %clang -target x86_64-unknown-unknown 
-mbranches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-TOTAL
+// CHECK-TOTAL: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" 
"-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=4"

Since you have a `-mno.. -m..` test, the `-m..` test is redundant.



Comment at: clang/test/Driver/intel-align-branch.c:35
+// RUN: %clang -target x86_64-unknown-unknown -mbranches-within-32B-boundaries 
-mno-branches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s 
--check-prefix=CHECK-TOTAL3
+// CHECK-TOTAL3-NOT: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" 
"-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=4"

Add a `-target aarch64` test that other targets will get an error.

(I am lazy and usually just write `-target x86_64` (generic ELF) and omit 
`-unknown-known`)


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

https://reviews.llvm.org/D72227



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


[PATCH] D72236: [Clang] Force rtlib=platform in test to avoid fails with CLANG_DEFAULT_RTLIB

2020-01-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72236



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


[PATCH] D72247: Add Triple::isX86()

2020-01-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: craig.topper, jyknight, reames, skan.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith, hiraditya.
Herald added projects: clang, LLVM.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72247

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Parse/ParseStmtAsm.cpp
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp

Index: llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
===
--- llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
+++ llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
@@ -1253,8 +1253,7 @@
 
 bool DevirtModule::shouldExportConstantsAsAbsoluteSymbols() {
   Triple T(M.getTargetTriple());
-  return (T.getArch() == Triple::x86 || T.getArch() == Triple::x86_64) &&
- T.getObjectFormat() == Triple::ELF;
+  return T.isX86() && T.getObjectFormat() == Triple::ELF;
 }
 
 void DevirtModule::exportGlobal(VTableSlot Slot, ArrayRef Args,
Index: llvm/lib/IR/AutoUpgrade.cpp
===
--- llvm/lib/IR/AutoUpgrade.cpp
+++ llvm/lib/IR/AutoUpgrade.cpp
@@ -4163,9 +4163,7 @@
 
   // If X86, and the datalayout matches the expected format, add pointer size
   // address spaces to the datalayout.
-  Triple::ArchType Arch = Triple(TT).getArch();
-  if ((Arch != llvm::Triple::x86 && Arch != llvm::Triple::x86_64) ||
-  DL.contains(AddrSpaces))
+  if (!Triple(TT).isX86() || DL.contains(AddrSpaces))
 return DL;
 
   SmallVector Groups;
Index: llvm/include/llvm/ADT/Triple.h
===
--- llvm/include/llvm/ADT/Triple.h
+++ llvm/include/llvm/ADT/Triple.h
@@ -730,6 +730,11 @@
 return getArch() == Triple::riscv32 || getArch() == Triple::riscv64;
   }
 
+  /// Tests whether the target is x86 (32- or 64-bit).
+  bool isX86() const {
+return getArch() == Triple::x86 || getArch() == Triple::x86_64;
+  }
+
   /// Tests whether the target supports comdat
   bool supportsCOMDAT() const {
 return !isOSBinFormatMachO();
Index: clang/lib/Parse/ParseStmtAsm.cpp
===
--- clang/lib/Parse/ParseStmtAsm.cpp
+++ clang/lib/Parse/ParseStmtAsm.cpp
@@ -547,12 +547,9 @@
 
   // We need an actual supported target.
   const llvm::Triple  = Actions.Context.getTargetInfo().getTriple();
-  llvm::Triple::ArchType ArchTy = TheTriple.getArch();
   const std::string  = TheTriple.getTriple();
   const llvm::Target *TheTarget = nullptr;
-  bool UnsupportedArch =
-  (ArchTy != llvm::Triple::x86 && ArchTy != llvm::Triple::x86_64);
-  if (UnsupportedArch) {
+  if (!TheTriple.isX86()) {
 Diag(AsmLoc, diag::err_msasm_unsupported_arch) << TheTriple.getArchName();
   } else {
 std::string Error;
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -2983,7 +2983,7 @@
  Arch != llvm::Triple::x86;
 emitError |= (DefaultCC == LangOptions::DCC_VectorCall ||
   DefaultCC == LangOptions::DCC_RegCall) &&
- !(Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64);
+ !T.isX86();
 if (emitError)
   Diags.Report(diag::err_drv_argument_not_allowed_with)
   << A->getSpelling() << T.getTriple();
Index: clang/lib/Driver/ToolChains/Darwin.cpp
===
--- clang/lib/Driver/ToolChains/Darwin.cpp
+++ clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2491,7 +2491,7 @@
 
 bool MachO::SupportsProfiling() const {
   // Profiling instrumentation is only supported on x86.
-  return getArch() == llvm::Triple::x86 || getArch() == llvm::Triple::x86_64;
+  return getTriple().isX86();
 }
 
 void Darwin::addMinVersionArgs(const ArgList ,
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -821,8 +821,7 @@
 
   // X86 has special BT, BTC, BTR, and BTS instructions that handle the array
   // indexing operation internally. Use them if possible.
-  llvm::Triple::ArchType Arch = CGF.getTarget().getTriple().getArch();
-  if (Arch == llvm::Triple::x86 || Arch == llvm::Triple::x86_64)
+  if (CGF.getTarget().getTriple().isX86())
 return EmitX86BitTestIntrinsic(CGF, BT, E, BitBase, BitPos);
 
   // Otherwise, use generic code to load one byte and test the bit. Use all but
Index: clang/lib/AST/MicrosoftMangle.cpp
===
--- clang/lib/AST/MicrosoftMangle.cpp
+++ 

[PATCH] D72236: [Clang] Force rtlib=platform in test to avoid fails with CLANG_DEFAULT_RTLIB

2020-01-05 Thread Kristina Brooks via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGce67db418537: [Clang] Force rtlib=platform in test to avoid 
fails with CLANG_DEFAULT_RTLIB (authored by kristina).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72236

Files:
  clang/test/Driver/cross-linux.c


Index: clang/test/Driver/cross-linux.c
===
--- clang/test/Driver/cross-linux.c
+++ clang/test/Driver/cross-linux.c
@@ -52,6 +52,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_32bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI32-X86-64 %s
 // CHECK-MULTI32-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"
@@ -70,6 +71,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=i386-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-I386 %s
 // CHECK-MULTI64-I386: "-cc1" "-triple" "i386-unknown-linux"
@@ -88,6 +90,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-X86-64 %s
 // CHECK-MULTI64-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"


Index: clang/test/Driver/cross-linux.c
===
--- clang/test/Driver/cross-linux.c
+++ clang/test/Driver/cross-linux.c
@@ -52,6 +52,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_32bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI32-X86-64 %s
 // CHECK-MULTI32-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"
@@ -70,6 +71,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=i386-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-I386 %s
 // CHECK-MULTI64-I386: "-cc1" "-triple" "i386-unknown-linux"
@@ -88,6 +90,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-X86-64 %s
 // CHECK-MULTI64-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] ce67db4 - [Clang] Force rtlib=platform in test to avoid fails with CLANG_DEFAULT_RTLIB

2020-01-05 Thread Kristina Brooks via cfe-commits

Author: Kristina Brooks
Date: 2020-01-06T07:21:15Z
New Revision: ce67db4185374016a9f5745869f9dbedfc12e6d2

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

LOG: [Clang] Force rtlib=platform in test to avoid fails with 
CLANG_DEFAULT_RTLIB

Driver test `cross-linux.c` fails when CLANG_DEFAULT_RTLIB is "compiler-rt"
as the it expects a GCC-style `"crtbegin.o"` after `"crti.o"` but instead
receives something akin to this in the frontend invocation:

```
"crt1.o" "crti.o"
"/o/b/llvm/bin/../lib/clang/10.0.0/lib/linux/clang_rt.crtbegin-x86_64.o"
```

This patch adds an override to `cross-linux.c` tests so the expected result
is produced regardless of the compile-time default rtlib, as having tests
fail due to that is fairly confusing. After applying the patch, the test
passes regardless of the CLANG_DEFAULT_RTLIB setting.

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

Added: 


Modified: 
clang/test/Driver/cross-linux.c

Removed: 




diff  --git a/clang/test/Driver/cross-linux.c b/clang/test/Driver/cross-linux.c
index a5ea832e77ea..6c2dab260695 100644
--- a/clang/test/Driver/cross-linux.c
+++ b/clang/test/Driver/cross-linux.c
@@ -52,6 +52,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_32bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI32-X86-64 %s
 // CHECK-MULTI32-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"
@@ -70,6 +71,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=i386-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-I386 %s
 // CHECK-MULTI64-I386: "-cc1" "-triple" "i386-unknown-linux"
@@ -88,6 +90,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-X86-64 %s
 // CHECK-MULTI64-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"



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


[PATCH] D72239: [clang-tidy] new opencl recursion not supported check

2020-01-05 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri requested changes to this revision.
lebedev.ri added a comment.
This revision now requires changes to proceed.

I was just going to look into this kind of check.
This can be implemented without recursion in the check itself.
Let me write it and post my variant.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D72239



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


[PATCH] D72239: [clang-tidy] new opencl recursion not supported check

2020-01-05 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

I think will be good idea to separate module code in own review or refer to 
previous one of previous reviews as dependency.




Comment at: clang-tidy/opencl/RecursionNotSupportedCheck.cpp:28
+void RecursionNotSupportedCheck::check(const MatchFinder::MatchResult ) 
{
+  auto MatchedFunDecl = Result.Nodes.getNodeAs("functionDecl");
+  auto MatchedFunCall = Result.Nodes.getNodeAs("functionCall");

const auto *



Comment at: clang-tidy/opencl/RecursionNotSupportedCheck.cpp:29
+  auto MatchedFunDecl = Result.Nodes.getNodeAs("functionDecl");
+  auto MatchedFunCall = Result.Nodes.getNodeAs("functionCall");
+

const auto *



Comment at: clang-tidy/opencl/RecursionNotSupportedCheck.cpp:53
+  }
+  for (std::pair  : Locations) {
+if (SM->isPointWithin(FunCall->getLocation(), Loc.second.getBegin(),

const auto &, because Loc is iterator.



Comment at: clang-tidy/opencl/RecursionNotSupportedCheck.cpp:76
+  if (Depth == MaxRecursionDepth) {
+return "";
+  }

{}



Comment at: clang-tidy/opencl/RecursionNotSupportedCheck.cpp:78
+  }
+  for (std::pair  : Callers[CallerName]) {
+if (Caller.second.compare(FunCallName) == 0) {

const auto &, because Caller is iterator.



Comment at: clang-tidy/opencl/RecursionNotSupportedCheck.cpp:108
+   << FilePath << ":" << LineNum << ":" << ColNum;
+  std::string StringPath = StringStream.str();
+  return StringPath;

Are two steps and temporary variable are really necessary?



Comment at: docs/ReleaseNotes.rst:131
+
+  Finds recursive function calls, which are not supported by OpenCL. 
+

Please synchronize with first statement in documentation.



Comment at: docs/clang-tidy/checks/opencl-recursion-not-supported.rst:38
+   Defines the maximum depth of function calls through which the lint check 
will
+   attempt to find instances of recursion. Default is 100.

Please highlight 100 with single back-quotes.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D72239



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


[PATCH] D72241: [clang-tidy] new altera single work item barrier check

2020-01-05 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

I think will be good idea to separate module code in own review or refer to 
previous one of previous reviews as dependency.




Comment at: clang-tidy/altera/SingleWorkItemBarrierCheck.cpp:51
+if (Attribute->getKind() == attr::Kind::ReqdWorkGroupSize) {
+  auto RWGSAttribute =
+  static_cast(Attribute);

const auto *.



Comment at: clang-tidy/altera/SingleWorkItemBarrierCheck.cpp:69
+  } else {
+if (IsNDRange == true) { // No warning if kernel is treated as an NDRange.
+  return;

Just IsNDRange. See readability-simplify-boolean-expr.



Comment at: docs/clang-tidy/checks/altera-single-work-item-barrier.rst:51
+
+   Defines the version of the Altera Offline Compiler. Defaults to 1600
+   (corresponding to version 16.00).

Please highlight 1600 with single back-quotes.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D72241



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


[PATCH] D72245: [PoC][RISCV][LTO] Pass target-abi via module flag metadata

2020-01-05 Thread Kuan Hsu Chen (Zakk) via Phabricator via cfe-commits
khchen updated this revision to Diff 236296.

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

https://reviews.llvm.org/D72245

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.h
  clang/test/CodeGen/riscv-metadata.c
  clang/test/Driver/gold-lto.c
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
  llvm/test/CodeGen/RISCV/subtarget-features-std-ext.ll
  llvm/test/CodeGen/RISCV/subtarget-features-target-abi.ll
  llvm/tools/llc/llc.cpp

Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -456,6 +456,18 @@
   Options.MCOptions.IASSearchPaths = IncludeDirs;
   Options.MCOptions.SplitDwarfFile = SplitDwarfFile;
 
+  if (const MDString *ModuleTargetABI =
+  dyn_cast_or_null(M->getModuleFlag("target-abi"))) {
+if (Options.MCOptions.ABIName != "" &&
+Options.MCOptions.ABIName != ModuleTargetABI->getString()) {
+  WithColor::warning(errs(), argv[0])
+  << ": warning: -target-abi option != target-abi module flag(ignoring "
+ "target-abi option)\n";
+}
+Options.MCOptions.ABIName = ModuleTargetABI->getString();
+  }
+
+
   std::unique_ptr Target(TheTarget->createTargetMachine(
   TheTriple.getTriple(), CPUStr, FeaturesStr, Options, getRelocModel(),
   getCodeModel(), OLvl));
Index: llvm/test/CodeGen/RISCV/subtarget-features-target-abi.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/subtarget-features-target-abi.ll
@@ -0,0 +1,26 @@
+; RUN: llc -mtriple=riscv32 < %s 2>&1 \
+; RUN:   | FileCheck -check-prefix=DEFAULT %s
+; RUN: llc -mtriple=riscv32 -target-abi ilp32 < %s 2>&1 \
+; RUN:   | FileCheck -check-prefix=RV32IF-ILP32 %s
+; RUN: llc -mtriple=riscv32 -target-abi ilp32f < %s 2>&1 \
+; RUN:   | FileCheck -check-prefix=RV32IF-ILP32F %s
+; RUN: llc -mtriple=riscv32 -filetype=obj < %s | llvm-readelf -h - | FileCheck -check-prefixes=FLAGS %s
+
+; RV32IF-ILP32: -target-abi option != target-abi module flag(ignoring target-abi option)
+
+; FLAGS: Flags: 0x2, single-float ABI
+
+define float @foo(i32 %a) nounwind #0 {
+; DEFAULT: # %bb.0:
+; DEFAULT-NEXT: fcvt.s.w  fa0, a0
+; DEFAULT-NEXT: ret
+; RV32IF-ILP32F: # %bb.0:
+; RV32IF-ILP32F-NEXT: fcvt.s.w  fa0, a0
+; RV32IF-ILP32F-NEXT: ret
+  %conv = sitofp i32 %a to float
+  ret float %conv
+}
+
+attributes #0 = { "target-features"="+f"}
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"target-abi", !"ilp32f"}
Index: llvm/test/CodeGen/RISCV/subtarget-features-std-ext.ll
===
--- llvm/test/CodeGen/RISCV/subtarget-features-std-ext.ll
+++ llvm/test/CodeGen/RISCV/subtarget-features-std-ext.ll
@@ -2,12 +2,17 @@
 ; RUN:   | FileCheck -check-prefix=RV32IF-ILP32 %s
 ; RUN: llc -mtriple=riscv32 -target-abi ilp32f < %s 2>&1 \
 ; RUN:   | FileCheck -check-prefix=RV32IF-ILP32F %s
+; RUN: llc -mtriple=riscv32 -mattr=-f -target-abi ilp32f <%s 2>&1 \
+; RUN:   | FileCheck -check-prefix=RV32I-ILP32F-FAILED %s
+
+; RV32I-ILP32F-FAILED: Hard-float 'f' ABI can't be used for a target that doesn't support the F instruction set extension
 
-; RV32IF-ILP32F: Hard-float 'f' ABI can't be used for a target that doesn't support the F instruction set extension (ignoring target-abi)
 
 define float @foo(i32 %a) nounwind #0 {
-; RV32IF-ILP32: # %bb.0:
-; RV32IF-ILP32-NEXT: fcvt.s.w  ft0, a0
+; RV32IF-ILP32: fcvt.s.w  ft0, a0
+; RV32IF-ILP32-NEXT: fmv.x.w a0, ft0
+; RV32IF-ILP32F: fcvt.s.w fa0, a0
+; RV32IF-ILP32F-NEXT: ret
   %conv = sitofp i32 %a to float
   ret float %conv
 }
Index: llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
===
--- llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
+++ llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
@@ -202,6 +202,8 @@
 ABI computeTargetABI(const Triple , FeatureBitset FeatureBits,
  StringRef ABIName);
 
+ABI getTargetABI(StringRef ABIName);
+
 // Returns the register used to hold the stack pointer after realignment.
 Register getBPReg();
 
Index: llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp
===
--- llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp
+++ llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp
@@ -12,16 +12,7 @@
 namespace RISCVABI {
 ABI computeTargetABI(const Triple , FeatureBitset FeatureBits,
  StringRef ABIName) {
-  auto TargetABI = StringSwitch(ABIName)
-   .Case("ilp32", ABI_ILP32)
-   .Case("ilp32f", ABI_ILP32F)
-   .Case("ilp32d", 

[PATCH] D64305: [clangd] Add path mappings functionality

2020-01-05 Thread William Wagner via Phabricator via cfe-commits
wwagner19 updated this revision to Diff 236295.
wwagner19 added a comment.

To be honest, I'm not sure how to remedy this. So I just rebased all my commits 
into one and dropped the `git show HEAD -U99` into here.

Please let me know if you need me to fix anything / open a new diff.


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

https://reviews.llvm.org/D64305

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/PathMapping.cpp
  clang-tools-extra/clangd/PathMapping.h
  clang-tools-extra/clangd/test/Inputs/path-mappings/server/foo.h
  clang-tools-extra/clangd/test/path-mappings.test
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/PathMappingTests.cpp

Index: clang-tools-extra/clangd/unittests/PathMappingTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/PathMappingTests.cpp
@@ -0,0 +1,216 @@
+//===-- PathMappingTests.cpp  *- C++ -*---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "PathMapping.h"
+#include "llvm/Support/JSON.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+namespace clang {
+namespace clangd {
+namespace {
+using ::testing::ElementsAre;
+MATCHER_P2(Mapping, ClientPath, ServerPath, "") {
+  return arg.ClientPath == ClientPath && arg.ServerPath == ServerPath;
+}
+
+bool failedParse(llvm::StringRef RawMappings) {
+  llvm::Expected Mappings = parsePathMappings(RawMappings);
+  if (!Mappings) {
+consumeError(Mappings.takeError());
+return true;
+  }
+  return false;
+}
+
+TEST(ParsePathMappingTests, WindowsPath) {
+  // Relative path to C drive
+  EXPECT_TRUE(failedParse(R"(C:a=/root)"));
+  EXPECT_TRUE(failedParse(R"(\C:a=/root)"));
+  // Relative path to current drive.
+  EXPECT_TRUE(failedParse(R"(\a=/root)"));
+  // Absolute paths
+  llvm::Expected ParsedMappings =
+  parsePathMappings(R"(C:\a=/root)");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping("/C:/a", "/root")));
+  // Absolute UNC path
+  ParsedMappings = parsePathMappings(R"(\\Server\C$=/root)");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping("//Server/C$", "/root")));
+}
+
+TEST(ParsePathMappingTests, UnixPath) {
+  // Relative unix path
+  EXPECT_TRUE(failedParse("a/b=/root"));
+  // Absolute unix path
+  llvm::Expected ParsedMappings = parsePathMappings("/A/b=/root");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping("/A/b", "/root")));
+  // Aboslute unix path w/ backslash
+  ParsedMappings = parsePathMappings(R"(/a/b\\ar=/root)");
+  ASSERT_TRUE(bool(ParsedMappings));
+  EXPECT_THAT(*ParsedMappings, ElementsAre(Mapping(R"(/a/b\\ar)", "/root")));
+}
+
+TEST(ParsePathMappingTests, ImproperFormat) {
+  // uneven mappings
+  EXPECT_TRUE(failedParse("/home/myuser1="));
+  // mappings need to be absolute
+  EXPECT_TRUE(failedParse("home/project=/workarea/project"));
+  // duplicate delimiter
+  EXPECT_TRUE(failedParse("/home==/workarea"));
+  // no delimiter
+  EXPECT_TRUE(failedParse("/home"));
+  // improper delimiter
+  EXPECT_TRUE(failedParse("/home,/workarea"));
+}
+
+TEST(ParsePathMappingTests, ParsesMultiple) {
+  std::string RawPathMappings =
+  "/home/project=/workarea/project,/home/project/.includes=/opt/include";
+  auto Parsed = parsePathMappings(RawPathMappings);
+  ASSERT_TRUE(bool(Parsed));
+  EXPECT_THAT(*Parsed,
+  ElementsAre(Mapping("/home/project", "/workarea/project"),
+  Mapping("/home/project/.includes", "/opt/include")));
+}
+
+bool mapsProperly(llvm::StringRef Orig, llvm::StringRef Expected,
+  llvm::StringRef RawMappings, PathMapping::Direction Dir) {
+  llvm::Expected Mappings = parsePathMappings(RawMappings);
+  if (!Mappings)
+return false;
+  llvm::Optional MappedPath = doPathMapping(Orig, Dir, *Mappings);
+  std::string Actual = MappedPath ? *MappedPath : Orig.str();
+  EXPECT_STREQ(Expected.str().c_str(), Actual.c_str());
+  return Expected == Actual;
+}
+
+TEST(DoPathMappingTests, PreservesOriginal) {
+  // Preserves original path when no mapping
+  EXPECT_TRUE(mapsProperly("file:///home", "file:///home", "",
+   PathMapping::Direction::ClientToServer));
+}
+
+TEST(DoPathMappingTests, UsesFirstMatch) {
+  EXPECT_TRUE(mapsProperly("file:///home/foo.cpp", "file:///workarea1/foo.cpp",
+   "/home=/workarea1,/home=/workarea2",
+   PathMapping::Direction::ClientToServer));
+}
+
+TEST(DoPathMappingTests, 

[PATCH] D72245: [PoC][RISCV][LTO] Pass target-abi via module flag metadata

2020-01-05 Thread Kuan Hsu Chen (Zakk) via Phabricator via cfe-commits
khchen created this revision.
Herald added subscribers: llvm-commits, cfe-commits, luismarques, apazos, 
sameer.abuasal, pzheng, s.egerton, lenary, Jim, benna, psnobl, dang, jocewei, 
PkmX, rkruppe, dexonsmith, the_o, brucehoult, MartinMosbeck, rogfer01, 
steven_wu, edward-jones, zzheng, MaskRay, jrtc27, shiva0217, kito-cheng, 
niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, inglorion, 
mehdi_amini.
Herald added projects: clang, LLVM.

1. Support ABI checking with per function target-features

if users don't specific -mattr, the default target-feature come from IR 
attribute.

2. Enable LTO for RISCV
3. Init MCOptions.ABIName via module flag metadata


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72245

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.cpp
  clang/lib/Driver/ToolChains/RISCVToolchain.h
  clang/test/CodeGen/riscv-metadata.c
  clang/test/Driver/gold-lto.c
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/lib/Target/RISCV/RISCVISelLowering.cpp
  llvm/lib/Target/RISCV/RISCVTargetMachine.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.cpp
  llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
  llvm/test/CodeGen/RISCV/subtarget-features-std-ext.ll
  llvm/test/CodeGen/RISCV/subtarget-features-target-abi.ll
  llvm/tools/llc/llc.cpp

Index: llvm/tools/llc/llc.cpp
===
--- llvm/tools/llc/llc.cpp
+++ llvm/tools/llc/llc.cpp
@@ -472,6 +472,17 @@
   if (FloatABIForCalls != FloatABI::Default)
 Options.FloatABIType = FloatABIForCalls;
 
+  if (const MDString *ModuleTargetABI =
+  dyn_cast_or_null(M->getModuleFlag("target-abi"))) {
+if (Options.MCOptions.ABIName != "" &&
+Options.MCOptions.ABIName != ModuleTargetABI->getString()) {
+  WithColor::warning(errs(), argv[0])
+  << ": warning: -target-abi option != target-abi module flag(ignoring "
+ "target-abi option)\n";
+}
+Options.MCOptions.ABIName = ModuleTargetABI->getString();
+  }
+
   // Figure out where we are going to send the output.
   std::unique_ptr Out =
   GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]);
Index: llvm/test/CodeGen/RISCV/subtarget-features-target-abi.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/subtarget-features-target-abi.ll
@@ -0,0 +1,26 @@
+; RUN: llc -mtriple=riscv32 < %s 2>&1 \
+; RUN:   | FileCheck -check-prefix=DEFAULT %s
+; RUN: llc -mtriple=riscv32 -target-abi ilp32 < %s 2>&1 \
+; RUN:   | FileCheck -check-prefix=RV32IF-ILP32 %s
+; RUN: llc -mtriple=riscv32 -target-abi ilp32f < %s 2>&1 \
+; RUN:   | FileCheck -check-prefix=RV32IF-ILP32F %s
+; RUN: llc -mtriple=riscv32 -filetype=obj < %s | llvm-readelf -h - | FileCheck -check-prefixes=FLAGS %s
+
+; RV32IF-ILP32: -target-abi option != target-abi module flag(ignoring target-abi option)
+
+; FLAGS: Flags: 0x2, single-float ABI
+
+define float @foo(i32 %a) nounwind #0 {
+; DEFAULT: # %bb.0:
+; DEFAULT-NEXT: fcvt.s.w  fa0, a0
+; DEFAULT-NEXT: ret
+; RV32IF-ILP32F: # %bb.0:
+; RV32IF-ILP32F-NEXT: fcvt.s.w  fa0, a0
+; RV32IF-ILP32F-NEXT: ret
+  %conv = sitofp i32 %a to float
+  ret float %conv
+}
+
+attributes #0 = { "target-features"="+f"}
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"target-abi", !"ilp32f"}
Index: llvm/test/CodeGen/RISCV/subtarget-features-std-ext.ll
===
--- llvm/test/CodeGen/RISCV/subtarget-features-std-ext.ll
+++ llvm/test/CodeGen/RISCV/subtarget-features-std-ext.ll
@@ -2,12 +2,17 @@
 ; RUN:   | FileCheck -check-prefix=RV32IF-ILP32 %s
 ; RUN: llc -mtriple=riscv32 -target-abi ilp32f < %s 2>&1 \
 ; RUN:   | FileCheck -check-prefix=RV32IF-ILP32F %s
+; RUN: llc -mtriple=riscv32 -mattr=-f -target-abi ilp32f <%s 2>&1 \
+; RUN:   | FileCheck -check-prefix=RV32I-ILP32F-FAILED %s
+
+; RV32I-ILP32F-FAILED: Hard-float 'f' ABI can't be used for a target that doesn't support the F instruction set extension
 
-; RV32IF-ILP32F: Hard-float 'f' ABI can't be used for a target that doesn't support the F instruction set extension (ignoring target-abi)
 
 define float @foo(i32 %a) nounwind #0 {
-; RV32IF-ILP32: # %bb.0:
-; RV32IF-ILP32-NEXT: fcvt.s.w  ft0, a0
+; RV32IF-ILP32: fcvt.s.w  ft0, a0
+; RV32IF-ILP32-NEXT: fmv.x.w a0, ft0
+; RV32IF-ILP32F: fcvt.s.w fa0, a0
+; RV32IF-ILP32F-NEXT: ret
   %conv = sitofp i32 %a to float
   ret float %conv
 }
Index: llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
===
--- llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
+++ llvm/lib/Target/RISCV/Utils/RISCVBaseInfo.h
@@ -202,6 +202,8 @@
 ABI computeTargetABI(const Triple , FeatureBitset FeatureBits,
  StringRef ABIName);
 
+ABI getTargetABI(StringRef ABIName);
+
 // Returns the register used to hold the stack pointer after realignment.
 Register 

[PATCH] D64305: [clangd] Add path mappings functionality

2020-01-05 Thread William Wagner via Phabricator via cfe-commits
wwagner19 updated this revision to Diff 236293.
wwagner19 added a comment.

The last diff was broken, this most recent one

- Changes IsIncoming boolean to an enum
- Refactors the matching path logic


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

https://reviews.llvm.org/D64305

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


Index: clang-tools-extra/clangd/PathMapping.cpp
===
--- clang-tools-extra/clangd/PathMapping.cpp
+++ clang-tools-extra/clangd/PathMapping.cpp
@@ -128,21 +128,6 @@
  llvm::inconvertibleErrorCode());
 }
 
-// Returns whether a path mapping should take place for OrigPath
-// i.e. MappingPath is a proper sub-path of  OrigPath
-bool mappingMatches(llvm::StringRef OrigPath, llvm::StringRef MappingPath) {
-  namespace path = llvm::sys::path;
-  auto OrigPathItr = path::begin(OrigPath, path::Style::posix);
-  auto OrigPathEnd = path::end(OrigPath);
-  auto MappingPathItr = path::begin(MappingPath, path::Style::posix);
-  auto MappingPathEnd = path::end(MappingPath);
-  if (std::distance(OrigPathItr, OrigPathEnd) <
-  std::distance(MappingPathItr, MappingPathEnd)) {
-return false;
-  }
-  return std::equal(MappingPathItr, MappingPathEnd, OrigPathItr);
-}
-
 // Converts a unix/windows path to the path portion of a file URI
 // e.g. "C:\foo" -> "/C:/foo"
 llvm::Expected parsePath(llvm::StringRef Path) {
@@ -207,11 +192,11 @@
 const std::string  = Dir == PathMapping::Direction::ClientToServer
 ? Mapping.ServerPath
 : Mapping.ClientPath;
-if (mappingMatches(Uri->body(), From)) {
-  std::string MappedBody = std::move(Uri->body());
-  MappedBody.replace(MappedBody.find(From), From.length(), To);
-  auto MappedUri = URI(Uri->scheme(), Uri->authority(), 
MappedBody.c_str());
-  return MappedUri.toString();
+llvm::StringRef Body = Uri->body();
+if (Body.consume_front(From) && (Body.empty() || Body.front() == '/')) {
+  std::string MappedBody = (To + Body).str();
+  return URI(Uri->scheme(), Uri->authority(), MappedBody.c_str())
+  .toString();
 }
   }
   return llvm::None;


Index: clang-tools-extra/clangd/PathMapping.cpp
===
--- clang-tools-extra/clangd/PathMapping.cpp
+++ clang-tools-extra/clangd/PathMapping.cpp
@@ -128,21 +128,6 @@
  llvm::inconvertibleErrorCode());
 }
 
-// Returns whether a path mapping should take place for OrigPath
-// i.e. MappingPath is a proper sub-path of  OrigPath
-bool mappingMatches(llvm::StringRef OrigPath, llvm::StringRef MappingPath) {
-  namespace path = llvm::sys::path;
-  auto OrigPathItr = path::begin(OrigPath, path::Style::posix);
-  auto OrigPathEnd = path::end(OrigPath);
-  auto MappingPathItr = path::begin(MappingPath, path::Style::posix);
-  auto MappingPathEnd = path::end(MappingPath);
-  if (std::distance(OrigPathItr, OrigPathEnd) <
-  std::distance(MappingPathItr, MappingPathEnd)) {
-return false;
-  }
-  return std::equal(MappingPathItr, MappingPathEnd, OrigPathItr);
-}
-
 // Converts a unix/windows path to the path portion of a file URI
 // e.g. "C:\foo" -> "/C:/foo"
 llvm::Expected parsePath(llvm::StringRef Path) {
@@ -207,11 +192,11 @@
 const std::string  = Dir == PathMapping::Direction::ClientToServer
 ? Mapping.ServerPath
 : Mapping.ClientPath;
-if (mappingMatches(Uri->body(), From)) {
-  std::string MappedBody = std::move(Uri->body());
-  MappedBody.replace(MappedBody.find(From), From.length(), To);
-  auto MappedUri = URI(Uri->scheme(), Uri->authority(), MappedBody.c_str());
-  return MappedUri.toString();
+llvm::StringRef Body = Uri->body();
+if (Body.consume_front(From) && (Body.empty() || Body.front() == '/')) {
+  std::string MappedBody = (To + Body).str();
+  return URI(Uri->scheme(), Uri->authority(), MappedBody.c_str())
+  .toString();
 }
   }
   return llvm::None;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72110: [X86] ABI compat bugfix for MSVC vectorcall

2020-01-05 Thread Craig Topper via Phabricator via cfe-commits
craig.topper accepted this revision.
craig.topper added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72110



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


[PATCH] D72242: Fix crash on value dependent bitfields in if conditions in templates

2020-01-05 Thread Elizabeth Andrews via Phabricator via cfe-commits
eandrews created this revision.
eandrews added reviewers: rnk, erichkeane, alexfh, alexfh_.

This patch is a follow up to D69950 , to fix a 
new crash on CXX condition expressions in templates, for value dependent 
bitfields.  Clang currently crashes when integral promotion is attempted on the 
condition. This patch adds a guard to prevent the promotion for value dependent 
bitfields. Prior to D69950 , the guard was 
unnecessary because incorrect type dependency of bitfield prevented the 
compiler from reaching this code.


https://reviews.llvm.org/D72242

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp


Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template
+class a {
+  int c : b;
+  void f() {
+if (c)
+  ;
+  }
+};
+
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -2158,6 +2158,7 @@
 if (FieldDecl *MemberDecl = From->getSourceBitField()) {
   llvm::APSInt BitWidth;
   if (FromType->isIntegralType(Context) &&
+  !MemberDecl->getBitWidth()->isValueDependent() &&
   MemberDecl->getBitWidth()->isIntegerConstantExpr(BitWidth, Context)) 
{
 llvm::APSInt ToSize(BitWidth.getBitWidth(), BitWidth.isUnsigned());
 ToSize = Context.getTypeSize(ToType);


Index: clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/value-dependent-bitfield-cond.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+template
+class a {
+  int c : b;
+  void f() {
+if (c)
+  ;
+  }
+};
+
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -2158,6 +2158,7 @@
 if (FieldDecl *MemberDecl = From->getSourceBitField()) {
   llvm::APSInt BitWidth;
   if (FromType->isIntegralType(Context) &&
+  !MemberDecl->getBitWidth()->isValueDependent() &&
   MemberDecl->getBitWidth()->isIntegerConstantExpr(BitWidth, Context)) {
 llvm::APSInt ToSize(BitWidth.getBitWidth(), BitWidth.isUnsigned());
 ToSize = Context.getTypeSize(ToType);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72241: [clang-tidy] new altera single work item barrier check

2020-01-05 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies created this revision.
ffrankies added reviewers: aaron.ballman, alexfh, hokein, Eugene.Zelenko.
ffrankies added projects: clang-tools-extra, clang.
Herald added subscribers: mgehre, jfb, arphaman, xazax.hun, Anastasia, mgorny.

This lint check is a part of the FLOCL (FPGA Linters for OpenCL) project out of 
the Synergy Lab at Virginia Tech.

FLOCL is a set of lint checks aimed at FPGA developers who write code in OpenCL.

The altera single work item barrier check finds OpenCL kernel functions that 
call a barrier function but do not call an ID function. These kernel functions 
will be treated as single work-item kernels, which could be inefficient or lead 
to errors.

Based on the "Altera SDK for OpenCL: Best Practices Guide."

Depends on https://reviews.llvm.org/D66564 due to the altera module being 
introduced there.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D72241

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/ClangTidyForceLinker.h
  clang-tidy/altera/AlteraTidyModule.cpp
  clang-tidy/altera/CMakeLists.txt
  clang-tidy/altera/SingleWorkItemBarrierCheck.cpp
  clang-tidy/altera/SingleWorkItemBarrierCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/altera-single-work-item-barrier.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/checkers/altera-single-work-item-barrier.cpp

Index: test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
===
--- /dev/null
+++ test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
@@ -0,0 +1,294 @@
+// RUN: %check_clang_tidy -check-suffix=OLD %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h -DOLD
+// RUN: %check_clang_tidy -check-suffix=NEW %s altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c --include opencl-c.h -DNEW
+// RUN: %check_clang_tidy -check-suffix=AOCOLD %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h -DAOCOLD
+// RUN: %check_clang_tidy -check-suffix=AOCNEW %s altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* "--" -cl-std=CL2.0 -c --include opencl-c.h -DAOCNEW
+
+#ifdef OLD
+void __kernel error_barrier_no_id(__global int * foo, int size) {
+  for (int j = 0; j < 256; j++) {
+	for (int i = 256; i < size; i+= 256) {
+  foo[j] += foo[j+i];
+}
+  }
+  barrier(CLK_GLOBAL_MEM_FENCE);
+  // CHECK-MESSAGES-OLD: :[[@LINE-7]]:15: warning: Kernel function 'error_barrier_no_id' does not call get_global_id or get_local_id and will be treated as single-work-item.{{[[:space:]]}}Barrier call at {{(\/)?([^\/\0]+(\/)?)+}}:[[@LINE-1]]:3 may error out [altera-single-work-item-barrier]
+  for (int i = 1; i < 256; i++) {
+	foo[0] += foo[i];
+  }
+}
+
+void __kernel success_barrier_global_id(__global int * foo, int size) {
+  barrier(CLK_GLOBAL_MEM_FENCE);
+  int tid = get_global_id(0);
+}
+
+void __kernel success_barrier_local_id(__global int * foo, int size) {
+  barrier(CLK_GLOBAL_MEM_FENCE);
+  int tid = get_local_id(0);
+}
+
+void __kernel success_barrier_both_ids(__global int * foo, int size) {
+  barrier(CLK_GLOBAL_MEM_FENCE);
+  int gid = get_global_id(0);
+  int lid = get_local_id(0);
+}
+
+void success_nokernel_barrier_no_id(__global int * foo, int size) {
+  for (int j = 0; j < 256; j++) {
+	for (int i = 256; i < size; i+= 256) {
+  foo[j] += foo[j+i];
+}
+  }
+  barrier(CLK_GLOBAL_MEM_FENCE);
+  for (int i = 1; i < 256; i++) {
+	foo[0] += foo[i];
+  }
+}
+
+void success_nokernel_barrier_global_id(__global int * foo, int size) {
+  barrier(CLK_GLOBAL_MEM_FENCE);
+  int tid = get_global_id(0);
+}
+
+void success_nokernel_barrier_local_id(__global int * foo, int size) {
+  barrier(CLK_GLOBAL_MEM_FENCE);
+  int tid = get_local_id(0);
+}
+
+void success_nokernel_barrier_both_ids(__global int * foo, int size) {
+  barrier(CLK_GLOBAL_MEM_FENCE);
+  int gid = get_global_id(0);
+  int lid = get_local_id(0);
+}
+#endif
+
+#ifdef NEW
+void __kernel error_barrier_no_id(__global int * foo, int size) {
+  for (int j = 0; j < 256; j++) {
+	for (int i = 256; i < size; i+= 256) {
+  foo[j] += foo[j+i];
+}
+  }
+  work_group_barrier(CLK_GLOBAL_MEM_FENCE);
+  // CHECK-MESSAGES-NEW: :[[@LINE-7]]:15: warning: Kernel function 'error_barrier_no_id' does not call get_global_id or get_local_id and will be treated as single-work-item.{{[[:space:]]}}Barrier call at {{(\/)?([^\/\0]+(\/)?)+}}:[[@LINE-1]]:3 may error out [altera-single-work-item-barrier]
+  for (int i = 1; i < 256; i++) {
+	foo[0] += foo[i];
+  }
+}
+
+void __kernel success_barrier_global_id(__global int * foo, int size) {
+  work_group_barrier(CLK_GLOBAL_MEM_FENCE);
+  int tid = get_global_id(0);
+}
+
+void __kernel 

[PATCH] D72227: Add options for clang to align branches within 32B boundary

2020-01-05 Thread Kan Shengchen via Phabricator via cfe-commits
skan updated this revision to Diff 236280.

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

https://reviews.llvm.org/D72227

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/intel-align-branch.c

Index: clang/test/Driver/intel-align-branch.c
===
--- /dev/null
+++ clang/test/Driver/intel-align-branch.c
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch-boundary=32 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOUNDARY
+// CHECK-BOUNDARY: "-mllvm" "-x86-align-branch-boundary=32"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=jcc -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-JCC
+// CHECK-JCC: "-mllvm" "-x86-align-branch=jcc"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=fused -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-FUSED
+// CHECK-FUSED: "-mllvm" "-x86-align-branch=fused"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=jmp -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-JMP
+// CHECK-JMP: "-mllvm" "-x86-align-branch=jmp"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=call -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-CALL
+// CHECK-CALL: "-mllvm" "-x86-align-branch=call"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=ret -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-RET
+// CHECK-RET: "-mllvm" "-x86-align-branch=ret"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=indirect -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-INDIRECT
+// CHECK-INDIRECT: "-mllvm" "-x86-align-branch=indirect"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=fused+jcc+jmp+ret+call+indirect -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BRANCH
+// CHECK-BRANCH: "-mllvm" "-x86-align-branch=fused+jcc+jmp+ret+call+indirect"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch-prefix-size=4 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-PREFIX
+// CHECK-PREFIX: "-mllvm" "-x86-align-branch-prefix-size=4"
+//
+// // RUN: %clang -target x86_64-unknown-unknown -mbranches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-TOTAL
+// CHECK-TOTAL: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=4"
+//
+// RUN: %clang -target x86_64-unknown-unknown -mno-branches-within-32B-boundaries -mbranches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-TOTAL2
+// CHECK-TOTAL2: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=4"
+//
+// RUN: %clang -target x86_64-unknown-unknown -mbranches-within-32B-boundaries -mno-branches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-TOTAL3
+// CHECK-TOTAL3-NOT: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=4"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2007,8 +2007,55 @@
 CmdArgs.push_back("-mpacked-stack");
 }
 
+static void AlignBranchesOptions(const Driver , const ArgList ,
+ ArgStringList ) {
+  if (const Arg *A = Args.getLastArg(options::OPT_malign_branch_boundary_EQ)) {
+StringRef Value = A->getValue();
+uint64_t Num;
+if (!Value.getAsInteger(10, Num) && Num >= 32 && llvm::isPowerOf2_64(Num)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back(
+  Args.MakeArgString("-x86-align-branch-boundary=" + Value));
+} else {
+  D.Diag(diag::err_drv_unsupported_option_argument)
+  << A->getOption().getName() << Value;
+}
+  }
+
+  if (const Arg *A = Args.getLastArg(options::OPT_malign_branch_EQ)) {
+StringRef Value = A->getValue();
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-x86-align-branch=" + Value));
+  }
+
+  if (const Arg *A =
+  Args.getLastArg(options::OPT_malign_branch_prefix_size_EQ)) {
+StringRef Value = A->getValue();
+uint8_t Num;
+if (!Value.getAsInteger(10, Num) && Num <= 4) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back(
+  Args.MakeArgString("-x86-align-branch-prefix-size=" + Value));
+} else {
+  D.Diag(diag::err_drv_unsupported_option_argument)
+  << A->getOption().getName() << Value;
+}
+  }
+
+  if (Args.hasFlag(options::OPT_mbranches_within_32B_boundaries,
+   options::OPT_mno_branches_within_32B_boundaries, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-x86-align-branch-boundary=32"));
+CmdArgs.push_back("-mllvm");
+

[PATCH] D72239: [clang-tidy] new opencl recursion not supported check

2020-01-05 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies created this revision.
ffrankies added reviewers: aaron.ballman, alexfh, hokein.
ffrankies added projects: clang, clang-tools-extra, LLVM.
Herald added subscribers: mgehre, arphaman, xazax.hun, Anastasia, yaxunl, 
mgorny.

This lint check is part of the FLOCL (FPGA Linters for OpenCL) project out of 
the Synergy Lab at Virginia Tech.

FLOCL is a set of lint checks aimed at FPGA developers who code in OpenCL.

The opencl recursion not supported check is placed in a new "opencl" module.

The check finds and flags recursive function calls, which are not supported by 
the OpenCL standard.

As per the official OpenCL restrictions list.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D72239

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/ClangTidyForceLinker.h
  clang-tidy/opencl/CMakeLists.txt
  clang-tidy/opencl/OpenCLTidyModule.cpp
  clang-tidy/opencl/RecursionNotSupportedCheck.cpp
  clang-tidy/opencl/RecursionNotSupportedCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/opencl-recursion-not-supported.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/checkers/opencl-recursion-not-supported.cpp

Index: test/clang-tidy/checkers/opencl-recursion-not-supported.cpp
===
--- /dev/null
+++ test/clang-tidy/checkers/opencl-recursion-not-supported.cpp
@@ -0,0 +1,57 @@
+// RUN: %check_clang_tidy -expect-clang-tidy-error %s opencl-recursion-not-supported %t -- -config="{CheckOptions: [{key: "opencl-recursion-not-supported.MaxRecursionDepth", value: 3}]}" -header-filter=.* "--" --include opencl-c.h -cl-std=CL1.2 -c
+
+// Simple recursive function should trigger an error
+void recfun() {
+  recfun();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: error: The call to function recfun is recursive, which is not supported by OpenCL.
+  // CHECK-NEXT: recfun is called by recfun in {{.*:\d+:\d+}}
+}
+
+// Declare functions first
+void recfun1();
+void recfun2();
+void recfun3();
+
+void recfundeep1();
+void recfundeep2();
+void recfundeep3();
+void recfundeep4();
+
+// Recursive function with depth 3 should trigger error
+void recfun1() {
+  recfun2();
+}
+
+void recfun2() {
+  recfun3();
+}
+
+void recfun3() {
+  recfun1();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: error: The call to function recfun1 is recursive, which is not supported by OpenCL.
+  // CHECK-NEXT: recfun1 is called by recfun3 in {{.*:\d+:\d+}}
+  // CHECK-NEXT: recfun3 is called by recfun2 in {{.*:\d+:\d+}}
+  // CHECK-NEXT: recfun2 is called by recfun1 in {{.*:\d+:\d+}}
+}
+
+// Non-recursive function should not trigger an error
+int nonrecursivefun() {
+  return 100; 
+}
+
+// Recursive function with depth greater than 3 should not trigger an error
+void recfundeep1() {
+  recfundeep2();
+}
+
+void recfundeep2() {
+  recfundeep3();
+}
+
+void recfundeep3() {
+  recfundeep4();
+}
+
+void recfundeep4() {
+  recfundeep1();
+}
Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -73,6 +73,7 @@
means "C++11") language constructs.
 ``mpi-``   Checks related to MPI (Message Passing Interface).
 ``objc-``  Checks related to Objective-C coding conventions.
+``opencl-``Checks related to OpenCL usage and API.
 ``openmp-``Checks related to OpenMP API.
 ``performance-``   Checks that target performance-related issues.
 ``portability-``   Checks that target portability-related issues that don't
Index: docs/clang-tidy/checks/opencl-recursion-not-supported.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/opencl-recursion-not-supported.rst
@@ -0,0 +1,38 @@
+.. title:: clang-tidy - opencl-recursion-not-supported
+
+opencl-recursion-not-supported
+==
+
+Finds recursive function calls and flags them as compiler errors, since 
+recursion is not supported in OpenCL.
+
+Based on the official list of `OpenCL Restrictions
+`_.
+Examples:
+
+.. code-block:: c++
+
+  int fibonacci(int num) {
+if (num < 2) {
+  return 1;
+}
+// error: fibonacci calls itself
+return fibonacci(num-2) + fibonacci(num-1);
+  }
+
+  void recursiveA() {
+recursiveB();
+  }
+
+  void recursiveB() {
+// error: recursiveB calls recursiveA, and recursiveA calls recursiveB
+recursiveA();
+  }
+
+Options
+---
+
+.. option:: MaxRecursionDepth
+
+   Defines the maximum depth of function calls through which the lint check will
+   attempt to find instances of recursion. Default is 100.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -332,6 +332,7 @@
objc-missing-hash

[PATCH] D72235: [clang-tidy] new altera unroll loops check

2020-01-05 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

I think will be good idea to separate module code in own review or refer to 
previous one of previous reviews as dependency.




Comment at: clang-tidy/altera/UnrollLoopsCheck.cpp:31
+void UnrollLoopsCheck::check(const MatchFinder::MatchResult ) {
+  const Stmt *MatchedLoop = Result.Nodes.getNodeAs("loop");
+  const ASTContext *Context = Result.Context;

Could be const auto *, because type is spelled in same sentence. See 
modernize-use-auto.



Comment at: clang-tidy/altera/UnrollLoopsCheck.cpp:69
+  for (const Attr* Attribute: ParentStmt->getAttrs()) {
+const LoopHintAttr *LoopHint;
+if ((LoopHint = static_cast(Attribute))) {

May be merge declaration with initialization and use const auto *?



Comment at: clang-tidy/altera/UnrollLoopsCheck.cpp:96
+  if (isa(Conditional)) {
+const BinaryOperator *BinaryOp =
+static_cast(Conditional);

Could be const auto *, because type is spelled in same sentence.



Comment at: clang-tidy/altera/UnrollLoopsCheck.cpp:113
+  if (isa(Statement)) {
+const ForStmt *ForLoop = static_cast(Statement);
+Conditional = ForLoop->getCond();

Could be const auto *, because type is spelled in same sentence.



Comment at: clang-tidy/altera/UnrollLoopsCheck.cpp:117
+  if (isa(Statement)) {
+const WhileStmt *WhileLoop = static_cast(Statement);
+Conditional = WhileLoop->getCond();

Could be const auto *, because type is spelled in same sentence.



Comment at: clang-tidy/altera/UnrollLoopsCheck.cpp:121
+  if (isa(Statement)) {
+const DoStmt *DoWhileLoop = static_cast(Statement);
+Conditional = DoWhileLoop->getCond();

Could be const auto *, because type is spelled in same sentence.



Comment at: clang-tidy/altera/UnrollLoopsCheck.cpp:134
+  if (isa(Conditional)) {
+const BinaryOperator *BinaryOp =
+static_cast(Conditional);

Could be const auto *, because type is spelled in same sentence.



Comment at: docs/ReleaseNotes.rst:79
+
+  Finds inner loops that have not been unrolled, as well as fully unrolled 
loops
+  with unknown loops bounds or a large number of iterations.

Please synchronize with first statement in documentation.



Comment at: docs/clang-tidy/checks/altera-unroll-loops.rst:68
+
+   Defines the maximum number of loop iterations that a fully unrolled loop
+   can have.

Please document default value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72235



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- added a comment.

In D54943#1804943 , @JonasToth wrote:

> - Merge branch 'master' into feature_transform_const.patch
> - link clangAnalysis to the cppcoreguidelines-module
> - fix InitListExpr as well


This last version too builds with RelWithDebInfo and fails with Debug 
configuration (both clean builds).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[PATCH] D72236: [Clang] Force rtlib=platform in test to avoid fails with CLANG_DEFAULT_RTLIB

2020-01-05 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61250 tests passed, 0 failed 
and 736 were skipped.

{icon times-circle color=red} clang-tidy: fail. Please fix clang-tidy findings 
.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72236



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


[PATCH] D72236: [Clang] Force rtlib=platform in test to avoid fails with CLANG_DEFAULT_RTLIB

2020-01-05 Thread Kristina Brooks via Phabricator via cfe-commits
kristina created this revision.
kristina added reviewers: sammccall, lebedev.ri, sthibaul.
Herald added a project: clang.

Driver test `cross-linux.c` fails when CLANG_DEFAULT_RTLIB is "compiler-rt"
as the it expects a GCC-style `"crtbegin.o"` after `"crti.o"` but instead
receives something akin to this in the frontend invocation:

  "crt1.o" "crti.o" 
"/o/b/llvm-test/v10.0.4010/bin/../lib/clang/10.0.4010/lib/linux/clang_rt.crtbegin-x86_64.o"

In `lib/Driver/ToolChain.cpp` it's implied that using `--rtlib=platform` is
acceptable in tests to override the configuration-time default.

  // Only use "platform" in tests to override CLANG_DEFAULT_RTLIB
  // ...
  else if (LibName == "platform")
return GetDefaultRuntimeLibType();

This patch adds said override to `cross-linux.c` tests so the expected result
is produced regardless of the compile-time default rtlib, as having tests
fail due to that is fairly confusing. After applying the patch, the test passes
regardless of the CLANG_DEFAULT_RTLIB setting.

nb. Originally ran across this issue in D69758 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72236

Files:
  clang/test/Driver/cross-linux.c


Index: clang/test/Driver/cross-linux.c
===
--- clang/test/Driver/cross-linux.c
+++ clang/test/Driver/cross-linux.c
@@ -52,6 +52,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_32bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI32-X86-64 %s
 // CHECK-MULTI32-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"
@@ -70,6 +71,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=i386-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-I386 %s
 // CHECK-MULTI64-I386: "-cc1" "-triple" "i386-unknown-linux"
@@ -88,6 +90,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-X86-64 %s
 // CHECK-MULTI64-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"


Index: clang/test/Driver/cross-linux.c
===
--- clang/test/Driver/cross-linux.c
+++ clang/test/Driver/cross-linux.c
@@ -52,6 +52,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_32bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI32-X86-64 %s
 // CHECK-MULTI32-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"
@@ -70,6 +71,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=i386-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-I386 %s
 // CHECK-MULTI64-I386: "-cc1" "-triple" "i386-unknown-linux"
@@ -88,6 +90,7 @@
 // RUN: %clang -### -o %t %s 2>&1 -no-integrated-as -fuse-ld=ld \
 // RUN:   --gcc-toolchain=%S/Inputs/multilib_64bit_linux_tree/usr \
 // RUN:   --target=x86_64-unknown-linux \
+// RUN:   --rtlib=platform \
 // RUN:   --sysroot=%S/Inputs/basic_linux_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-MULTI64-X86-64 %s
 // CHECK-MULTI64-X86-64: "-cc1" "-triple" "x86_64-unknown-linux"
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72235: [clang-tidy] new altera unroll loops check

2020-01-05 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies updated this revision to Diff 236270.

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

https://reviews.llvm.org/D72235

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/ClangTidyForceLinker.h
  clang-tidy/altera/AlteraTidyModule.cpp
  clang-tidy/altera/CMakeLists.txt
  clang-tidy/altera/UnrollLoopsCheck.cpp
  clang-tidy/altera/UnrollLoopsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/altera-unroll-loops.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/checkers/altera-unroll-loops.cpp

Index: test/clang-tidy/checkers/altera-unroll-loops.cpp
===
--- /dev/null
+++ test/clang-tidy/checkers/altera-unroll-loops.cpp
@@ -0,0 +1,359 @@
+// RUN: %check_clang_tidy %s altera-unroll-loops %t -- -config="{CheckOptions: [{key: "altera-unroll-loops.MaxLoopIterations", value: 50}]}" -header-filter=.* "--" --include opencl-c.h -cl-std=CL1.2 -c
+
+// Inner loops should be unrolled
+__kernel void nested_simple_loops(__global int *A) {
+for (int i = 0; i < 1000; ++i) {
+for (int j = 0; j < 2000; ++j) { 
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[0] += i + j;
+}
+}
+
+for (int i = 0; i < 1000; ++i) {
+int j = 0;
+while (j < 2000) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[1] += i + j;
+j++;
+}
+}
+
+for (int i = 0; i < 1000; ++i) {
+int j = 0; 
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[2] += i + j;
+j++;
+} while (j < 2000);
+}
+
+int i = 0;
+while (i < 1000) {
+for (int j = 0; j < 2000; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[3] += i + j;
+}
+i++;
+}
+
+i = 0;
+while (i < 1000) {
+int j = 0;
+while (j < 2000) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[4] += i + j;
+j++;
+}
+i++;
+}
+
+i = 0;
+while (i < 1000) {
+int j = 0;
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[5] += i + j;
+j++;
+} while (j < 2000);
+i++;
+}
+
+i = 0;
+do {
+for (int j = 0; j < 2000; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[6] += i + j;
+}
+i++;
+} while (i < 1000);
+
+i = 0;
+do {
+int j = 0;
+while (j < 2000) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[7] += i + j;
+j++;
+}
+i++;
+} while (i < 1000);
+
+i = 0;
+do {
+int j = 0;
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[8] += i + j;
+j++;
+} while (j < 2000);
+i++;
+} while (i < 1000);
+
+for (int i = 0; i < 100; ++i) {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+printf("Hello");
+}
+
+i = 0;
+while (i < 100) {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+i++;
+}
+
+i = 0;
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+i++;
+} while (i < 100);
+}
+
+// These loops are all correctly unrolled
+__kernel void unrolled_nested_simple_loops(__global int *A) {
+for (int i = 0; i < 1000; ++i) {
+#pragma unroll
+for (int j = 0; j < 50; ++j) {
+A[0] += i + j;
+}
+}
+
+for (int i = 0; i < 1000; ++i) {
+  

[PATCH] D72235: [clang-tidy] new altera unroll loops check

2020-01-05 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies created this revision.
ffrankies added reviewers: aaron.ballman, hokein, alexfh.
ffrankies added projects: clang-tools-extra, clang, LLVM.
Herald added subscribers: mgehre, arphaman, zzheng, xazax.hun, Anastasia, 
mgorny.
ffrankies updated this revision to Diff 236270.
ffrankies updated this revision to Diff 236271.

This lint check is a part of the FLOCL (FPGA Linters for OpenCL) project out of 
the Synergy Lab at Virginia Tech.

FLOCL is a set of lint checks aimed at FPGA developers who write code in OpenCL.

The altera unroll loops check finds inner loops that have not been unrolled, as 
well as fully-unrolled loops that should be partially unrolled due to unknown 
loop bounds or a large number of loop iterations.

Based on the Altera SDK for OpenCL: Best Practices Guide


https://reviews.llvm.org/D72235

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/ClangTidyForceLinker.h
  clang-tidy/altera/AlteraTidyModule.cpp
  clang-tidy/altera/CMakeLists.txt
  clang-tidy/altera/UnrollLoopsCheck.cpp
  clang-tidy/altera/UnrollLoopsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/altera-unroll-loops.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/checkers/altera-unroll-loops.cpp

Index: test/clang-tidy/checkers/altera-unroll-loops.cpp
===
--- /dev/null
+++ test/clang-tidy/checkers/altera-unroll-loops.cpp
@@ -0,0 +1,359 @@
+// RUN: %check_clang_tidy %s altera-unroll-loops %t -- -config="{CheckOptions: [{key: "altera-unroll-loops.MaxLoopIterations", value: 50}]}" -header-filter=.* "--" --include opencl-c.h -cl-std=CL1.2 -c
+
+// Inner loops should be unrolled
+__kernel void nested_simple_loops(__global int *A) {
+for (int i = 0; i < 1000; ++i) {
+for (int j = 0; j < 2000; ++j) { 
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[0] += i + j;
+}
+}
+
+for (int i = 0; i < 1000; ++i) {
+int j = 0;
+while (j < 2000) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[1] += i + j;
+j++;
+}
+}
+
+for (int i = 0; i < 1000; ++i) {
+int j = 0; 
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[2] += i + j;
+j++;
+} while (j < 2000);
+}
+
+int i = 0;
+while (i < 1000) {
+for (int j = 0; j < 2000; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[3] += i + j;
+}
+i++;
+}
+
+i = 0;
+while (i < 1000) {
+int j = 0;
+while (j < 2000) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[4] += i + j;
+j++;
+}
+i++;
+}
+
+i = 0;
+while (i < 1000) {
+int j = 0;
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[5] += i + j;
+j++;
+} while (j < 2000);
+i++;
+}
+
+i = 0;
+do {
+for (int j = 0; j < 2000; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[6] += i + j;
+}
+i++;
+} while (i < 1000);
+
+i = 0;
+do {
+int j = 0;
+while (j < 2000) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[7] += i + j;
+j++;
+}
+i++;
+} while (i < 1000);
+
+i = 0;
+do {
+int j = 0;
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[8] += i + j;
+j++;
+} while (j < 2000);
+i++;
+} while (i < 1000);
+
+for (int i = 0; i < 100; ++i) {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+printf("Hello");
+}
+
+i = 0;
+while (i < 100) {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: 

[PATCH] D72235: [clang-tidy] new altera unroll loops check

2020-01-05 Thread Frank Derry Wanye via Phabricator via cfe-commits
ffrankies updated this revision to Diff 236271.

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

https://reviews.llvm.org/D72235

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/ClangTidyForceLinker.h
  clang-tidy/altera/AlteraTidyModule.cpp
  clang-tidy/altera/CMakeLists.txt
  clang-tidy/altera/UnrollLoopsCheck.cpp
  clang-tidy/altera/UnrollLoopsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/altera-unroll-loops.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/index.rst
  test/clang-tidy/checkers/altera-unroll-loops.cpp

Index: test/clang-tidy/checkers/altera-unroll-loops.cpp
===
--- /dev/null
+++ test/clang-tidy/checkers/altera-unroll-loops.cpp
@@ -0,0 +1,359 @@
+// RUN: %check_clang_tidy %s altera-unroll-loops %t -- -config="{CheckOptions: [{key: "altera-unroll-loops.MaxLoopIterations", value: 50}]}" -header-filter=.* "--" --include opencl-c.h -cl-std=CL1.2 -c
+
+// Inner loops should be unrolled
+__kernel void nested_simple_loops(__global int *A) {
+for (int i = 0; i < 1000; ++i) {
+for (int j = 0; j < 2000; ++j) { 
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[0] += i + j;
+}
+}
+
+for (int i = 0; i < 1000; ++i) {
+int j = 0;
+while (j < 2000) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[1] += i + j;
+j++;
+}
+}
+
+for (int i = 0; i < 1000; ++i) {
+int j = 0; 
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[2] += i + j;
+j++;
+} while (j < 2000);
+}
+
+int i = 0;
+while (i < 1000) {
+for (int j = 0; j < 2000; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[3] += i + j;
+}
+i++;
+}
+
+i = 0;
+while (i < 1000) {
+int j = 0;
+while (j < 2000) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[4] += i + j;
+j++;
+}
+i++;
+}
+
+i = 0;
+while (i < 1000) {
+int j = 0;
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[5] += i + j;
+j++;
+} while (j < 2000);
+i++;
+}
+
+i = 0;
+do {
+for (int j = 0; j < 2000; ++j) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[6] += i + j;
+}
+i++;
+} while (i < 1000);
+
+i = 0;
+do {
+int j = 0;
+while (j < 2000) {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[7] += i + j;
+j++;
+}
+i++;
+} while (i < 1000);
+
+i = 0;
+do {
+int j = 0;
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:9: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+A[8] += i + j;
+j++;
+} while (j < 2000);
+i++;
+} while (i < 1000);
+
+for (int i = 0; i < 100; ++i) {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+printf("Hello");
+}
+
+i = 0;
+while (i < 100) {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+i++;
+}
+
+i = 0;
+do {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: The performance of the kernel could be improved by unrolling this loop with a #pragma unroll directive [altera-unroll-loops]
+i++;
+} while (i < 100);
+}
+
+// These loops are all correctly unrolled
+__kernel void unrolled_nested_simple_loops(__global int *A) {
+for (int i = 0; i < 1000; ++i) {
+#pragma unroll
+for (int j = 0; j < 50; ++j) {
+A[0] += i + j;
+}
+}
+
+for (int i = 0; i < 1000; ++i) {
+  

[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

> Patch by sthibaul (Samuel Thibault)

@kristina As a belated advice... since LLVM has moved from svn to git, we can 
ask contributors's names and emails, and then do `git commit --amend --author 
'name '`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69758



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


Re: [clang] 4711512 - Fix oversight in AST traversal helper

2020-01-05 Thread Stephen Kelly via cfe-commits


Sorry, will do. This was something I had intended to do in the original 
commit.


Thanks,

Stephen.

On 05/01/2020 22:00, Aaron Ballman wrote:
Can you also include more detail in commit logs than this? It doesn't 
explain why this is an oversight, which makes code archaeology harder 
later.


On Sun, Jan 5, 2020, 3:32 PM Stephen Kelly via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:



Author: Stephen Kelly
Date: 2020-01-05T20:27:37Z
New Revision: 471151238438201f3fe365a7784f1a091328e46c

URL:

https://github.com/llvm/llvm-project/commit/471151238438201f3fe365a7784f1a091328e46c
DIFF:

https://github.com/llvm/llvm-project/commit/471151238438201f3fe365a7784f1a091328e46c.diff

LOG: Fix oversight in AST traversal helper

Added:


Modified:
    clang/lib/AST/Expr.cpp

Removed:





diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 5c9ceac854cf..73ddbc62482d 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3026,7 +3026,7 @@ Expr *Expr::IgnoreUnlessSpelledInSource() {
   Expr *LastE = nullptr;
   while (E != LastE) {
     LastE = E;
-    E = E->IgnoreImplicit();
+    E = E->IgnoreParenImpCasts();

     auto SR = E->getSourceRange();




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

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


[clang] 445f4d2 - Clang-format previous commit

2020-01-05 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2020-01-05T22:58:32Z
New Revision: 445f4d2310e751a6ab18f84b1d4ad13037ffd819

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

LOG: Clang-format previous commit

Added: 


Modified: 
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index a127a666ea67..6ca54df06571 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1699,7 +1699,6 @@ void bar()
   functionDecl(hasName("foo"), traverse(ast_type_traits::TK_AsIs,
 hasDescendant(floatLiteral());
 
-
   EXPECT_TRUE(
   matches(R"cpp(
 void foo()
@@ -1708,8 +1707,7 @@ void foo()
 }
 )cpp",
   traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
-
varDecl(hasInitializer(integerLiteral(equals(3)));
-
+   varDecl(hasInitializer(integerLiteral(equals(3)));
 }
 
 template 



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


Re: [clang] 4711512 - Fix oversight in AST traversal helper

2020-01-05 Thread Aaron Ballman via cfe-commits
Can you also include more detail in commit logs than this? It doesn't
explain why this is an oversight, which makes code archaeology harder later.

On Sun, Jan 5, 2020, 3:32 PM Stephen Kelly via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

>
> Author: Stephen Kelly
> Date: 2020-01-05T20:27:37Z
> New Revision: 471151238438201f3fe365a7784f1a091328e46c
>
> URL:
> https://github.com/llvm/llvm-project/commit/471151238438201f3fe365a7784f1a091328e46c
> DIFF:
> https://github.com/llvm/llvm-project/commit/471151238438201f3fe365a7784f1a091328e46c.diff
>
> LOG: Fix oversight in AST traversal helper
>
> Added:
>
>
> Modified:
> clang/lib/AST/Expr.cpp
>
> Removed:
>
>
>
>
> 
> diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
> index 5c9ceac854cf..73ddbc62482d 100644
> --- a/clang/lib/AST/Expr.cpp
> +++ b/clang/lib/AST/Expr.cpp
> @@ -3026,7 +3026,7 @@ Expr *Expr::IgnoreUnlessSpelledInSource() {
>Expr *LastE = nullptr;
>while (E != LastE) {
>  LastE = E;
> -E = E->IgnoreImplicit();
> +E = E->IgnoreParenImpCasts();
>
>  auto SR = E->getSourceRange();
>
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Kristina Brooks via Phabricator via cfe-commits
kristina added a comment.

For future - Since you seem to put up a lot of (well, almost all) patches 
related to Hurd support, may I suggest requesting commit access so you can land 
patches yourself after review?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69758



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


Re: [clang] 4711512 - Fix oversight in AST traversal helper

2020-01-05 Thread Stephen Kelly via cfe-commits

Added in 35efef5351e.


Thanks,

Stephen.


On 05/01/2020 20:33, Roman Lebedev wrote:

Is there a test for this missing?

On Sun, Jan 5, 2020 at 11:32 PM Stephen Kelly via cfe-commits
 wrote:


Author: Stephen Kelly
Date: 2020-01-05T20:27:37Z
New Revision: 471151238438201f3fe365a7784f1a091328e46c

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

LOG: Fix oversight in AST traversal helper

Added:


Modified:
 clang/lib/AST/Expr.cpp

Removed:




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 5c9ceac854cf..73ddbc62482d 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3026,7 +3026,7 @@ Expr *Expr::IgnoreUnlessSpelledInSource() {
Expr *LastE = nullptr;
while (E != LastE) {
  LastE = E;
-E = E->IgnoreImplicit();
+E = E->IgnoreParenImpCasts();

  auto SR = E->getSourceRange();




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

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


[clang] 35efef5 - Add missing test

2020-01-05 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2020-01-05T21:55:52Z
New Revision: 35efef5351e3b3a4e50bcd862407ef7edc0b2166

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

LOG: Add missing test

Added: 


Modified: 
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index 327ed979962f..a127a666ea67 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1698,6 +1698,18 @@ void bar()
   VarDeclCode,
   functionDecl(hasName("foo"), traverse(ast_type_traits::TK_AsIs,
 hasDescendant(floatLiteral());
+
+
+  EXPECT_TRUE(
+  matches(R"cpp(
+void foo()
+{
+  int i = (3);
+}
+)cpp",
+  traverse(ast_type_traits::TK_IgnoreUnlessSpelledInSource,
+
varDecl(hasInitializer(integerLiteral(equals(3)));
+
 }
 
 template 



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


[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Kristina Brooks via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Revision".
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb18cb9c47166: [Gnu toolchain] Look at standard GCC paths for 
libstdcxx by default (authored by kristina).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69758

Files:
  clang/lib/Driver/ToolChains/Gnu.cpp
  clang/lib/Driver/ToolChains/Gnu.h
  clang/lib/Driver/ToolChains/Hurd.cpp
  clang/lib/Driver/ToolChains/Hurd.h
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/lib/Driver/ToolChains/Linux.h

Index: clang/lib/Driver/ToolChains/Linux.h
===
--- clang/lib/Driver/ToolChains/Linux.h
+++ clang/lib/Driver/ToolChains/Linux.h
@@ -26,9 +26,6 @@
   void
   AddClangSystemIncludeArgs(const llvm::opt::ArgList ,
 llvm::opt::ArgStringList ) const override;
-  void addLibCxxIncludePaths(
-  const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ) const override;
   void addLibStdCxxIncludePaths(
   const llvm::opt::ArgList ,
   llvm::opt::ArgStringList ) const override;
@@ -52,6 +49,10 @@
 protected:
   Tool *buildAssembler() const override;
   Tool *buildLinker() const override;
+
+  std::string getMultiarchTriple(const Driver ,
+ const llvm::Triple ,
+ StringRef SysRoot) const override;
 };
 
 } // end namespace toolchains
Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -37,9 +37,9 @@
 /// a target-triple directory in the library and header search paths.
 /// Unfortunately, this triple does not align with the vanilla target triple,
 /// so we provide a rough mapping here.
-static std::string getMultiarchTriple(const Driver ,
+std::string Linux::getMultiarchTriple(const Driver ,
   const llvm::Triple ,
-  StringRef SysRoot) {
+  StringRef SysRoot) const {
   llvm::Triple::EnvironmentType TargetEnvironment =
   TargetTriple.getEnvironment();
   bool IsAndroid = TargetTriple.isAndroid();
@@ -865,86 +865,23 @@
 addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
 }
 
-static std::string DetectLibcxxIncludePath(llvm::vfs::FileSystem ,
-   StringRef base) {
-  std::error_code EC;
-  int MaxVersion = 0;
-  std::string MaxVersionString = "";
-  for (llvm::vfs::directory_iterator LI = vfs.dir_begin(base, EC), LE;
-   !EC && LI != LE; LI = LI.increment(EC)) {
-StringRef VersionText = llvm::sys::path::filename(LI->path());
-int Version;
-if (VersionText[0] == 'v' &&
-!VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
-  if (Version > MaxVersion) {
-MaxVersion = Version;
-MaxVersionString = VersionText;
-  }
-}
-  }
-  return MaxVersion ? (base + "/" + MaxVersionString).str() : "";
-}
-
-void Linux::addLibCxxIncludePaths(const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ) const {
-  const std::string& SysRoot = computeSysRoot();
-  auto AddIncludePath = [&](std::string Path) {
-std::string IncludePath = DetectLibcxxIncludePath(getVFS(), Path);
-if (IncludePath.empty() || !getVFS().exists(IncludePath))
-  return false;
-addSystemInclude(DriverArgs, CC1Args, IncludePath);
-return true;
-  };
-  // Android never uses the libc++ headers installed alongside the toolchain,
-  // which are generally incompatible with the NDK libraries anyway.
-  if (!getTriple().isAndroid())
-if (AddIncludePath(getDriver().Dir + "/../include/c++"))
-  return;
-  // If this is a development, non-installed, clang, libcxx will
-  // not be found at ../include/c++ but it likely to be found at
-  // one of the following two locations:
-  if (AddIncludePath(SysRoot + "/usr/local/include/c++"))
-return;
-  if (AddIncludePath(SysRoot + "/usr/include/c++"))
-return;
-}
-
 void Linux::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,
  llvm::opt::ArgStringList ) const {
+  // Try generic GCC detection first.
+  if (Generic_GCC::addGCCLibStdCxxIncludePaths(DriverArgs, CC1Args))
+return;
+
   // We need a detected GCC installation on Linux to provide libstdc++'s
-  // headers.
+  // headers in odd Linuxish places.
   if (!GCCInstallation.isValid())
 return;
 
-  // By default, look for the C++ headers in an include directory adjacent to
-  // the lib directory of the GCC installation. Note that this is expect to be
-  // equivalent to '/usr/include/c++/X.Y' in almost all cases.
   StringRef LibDir = GCCInstallation.getParentLibPath();
-  

[clang] b18cb9c - [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Kristina Brooks via cfe-commits

Author: Kristina Brooks
Date: 2020-01-05T21:43:18Z
New Revision: b18cb9c4716677b048a88125be14d59a56865b9c

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

LOG: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

Linux' current addLibCxxIncludePaths and addLibStdCxxIncludePaths
are actually almost non-Linux-specific at all, and can be reused
almost as such for all gcc toolchains. Only keep
Android/Freescale/Cray hacks in Linux's version.

Patch by sthibaul (Samuel Thibault)

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Gnu.h
clang/lib/Driver/ToolChains/Hurd.cpp
clang/lib/Driver/ToolChains/Hurd.h
clang/lib/Driver/ToolChains/Linux.cpp
clang/lib/Driver/ToolChains/Linux.h

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 7c0bcdcaf074..91076709fd76 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2686,19 +2686,49 @@ void Generic_GCC::AddClangCXXStdlibIncludeArgs(const 
ArgList ,
   }
 }
 
-void
-Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList ,
-   llvm::opt::ArgStringList ) const {
-  // FIXME: The Linux behavior would probaby be a better approach here.
-  addSystemInclude(DriverArgs, CC1Args,
-   getDriver().SysRoot + "/usr/include/c++/v1");
+static std::string DetectLibcxxIncludePath(llvm::vfs::FileSystem ,
+   StringRef base) {
+  std::error_code EC;
+  int MaxVersion = 0;
+  std::string MaxVersionString;
+  for (llvm::vfs::directory_iterator LI = vfs.dir_begin(base, EC), LE;
+   !EC && LI != LE; LI = LI.increment(EC)) {
+StringRef VersionText = llvm::sys::path::filename(LI->path());
+int Version;
+if (VersionText[0] == 'v' &&
+!VersionText.slice(1, StringRef::npos).getAsInteger(10, Version)) {
+  if (Version > MaxVersion) {
+MaxVersion = Version;
+MaxVersionString = VersionText;
+  }
+}
+  }
+  return MaxVersion ? (base + "/" + MaxVersionString).str() : "";
 }
 
 void
-Generic_GCC::addLibStdCxxIncludePaths(const llvm::opt::ArgList ,
-  llvm::opt::ArgStringList ) const 
{
-  // By default, we don't assume we know where libstdc++ might be installed.
-  // FIXME: If we have a valid GCCInstallation, use it.
+Generic_GCC::addLibCxxIncludePaths(const llvm::opt::ArgList ,
+   llvm::opt::ArgStringList ) const {
+  const std::string& SysRoot = getDriver().SysRoot;
+  auto AddIncludePath = [&](std::string Path) {
+std::string IncludePath = DetectLibcxxIncludePath(getVFS(), Path);
+if (IncludePath.empty() || !getVFS().exists(IncludePath))
+  return false;
+addSystemInclude(DriverArgs, CC1Args, IncludePath);
+return true;
+  };
+  // Android never uses the libc++ headers installed alongside the toolchain,
+  // which are generally incompatible with the NDK libraries anyway.
+  if (!getTriple().isAndroid())
+if (AddIncludePath(getDriver().Dir + "/../include/c++"))
+  return;
+  // If this is a development, non-installed, clang, libcxx will
+  // not be found at ../include/c++ but it likely to be found at
+  // one of the following two locations:
+  if (AddIncludePath(SysRoot + "/usr/local/include/c++"))
+return;
+  if (AddIncludePath(SysRoot + "/usr/include/c++"))
+return;
 }
 
 /// Helper to add the variant paths of a libstdc++ installation.
@@ -2734,6 +2764,60 @@ bool Generic_GCC::addLibStdCXXIncludePaths(
   return true;
 }
 
+bool
+Generic_GCC::addGCCLibStdCxxIncludePaths(const llvm::opt::ArgList ,
+ llvm::opt::ArgStringList ) 
const {
+  // Use GCCInstallation to know where libstdc++ headers are installed.
+  if (!GCCInstallation.isValid())
+return false;
+
+  // By default, look for the C++ headers in an include directory adjacent to
+  // the lib directory of the GCC installation. Note that this is expect to be
+  // equivalent to '/usr/include/c++/X.Y' in almost all cases.
+  StringRef LibDir = GCCInstallation.getParentLibPath();
+  StringRef InstallDir = GCCInstallation.getInstallPath();
+  StringRef TripleStr = GCCInstallation.getTriple().str();
+  const Multilib  = GCCInstallation.getMultilib();
+  const std::string GCCMultiarchTriple = getMultiarchTriple(
+  getDriver(), GCCInstallation.getTriple(), getDriver().SysRoot);
+  const std::string TargetMultiarchTriple =
+  getMultiarchTriple(getDriver(), getTriple(), getDriver().SysRoot);
+  const GCCVersion  = GCCInstallation.getVersion();
+
+  // The primary search for libstdc++ supports 

[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Samuel Thibault via Phabricator via cfe-commits
sthibaul added a comment.

> Let me know if you need this committed.

Yes, please commit.


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

https://reviews.llvm.org/D69758



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


[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Kristina Brooks via Phabricator via cfe-commits
kristina accepted this revision.
kristina added a comment.

On second look this seems to be caused by `compiler-rt` being used as the 
default runtime, which is not accounted for in that particular test.

Test is expecting a GCCesque crtbegin here which is missing with `compiler-rt`:

  "crt1.o" "crti.o" 
"/o/b/llvm-test/v10.0.4010/bin/../lib/clang/10.0.4010/lib/linux/clang_rt.crtbegin-x86_64.o"

Which fails for obvious reasons:

  llvm-project/clang/test/Driver/cross-linux.c:62:26: error: 
CHECK-MULTI32-X86-64: expected string not found in input
  // CHECK-MULTI32-X86-64: "crti.o" 
"[[gcc_install:.*/Inputs/multilib_32bit_linux_tree/usr/lib/gcc/i386-unknown-linux/4.6.0]]/64{{/|}}crtbegin.o"

This seems unrelated, apologies for the false alarm, I'll have to look into 
fixing the test for when `compiler-rt` is the default CRT myself.

I'm happy to sign off on this. Let me know if you need this committed.


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

https://reviews.llvm.org/D69758



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


[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Samuel Thibault via Phabricator via cfe-commits
sthibaul added a comment.

(I don't see anything looking like what you have, so can't investigate)


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

https://reviews.llvm.org/D69758



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


[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Samuel Thibault via Phabricator via cfe-commits
sthibaul added a comment.

I am actually getting many failures with ninja check-all on my build box:

  Expected Passes: 56258
  Expected Failures  : 203
  Unsupported Tests  : 1485
  Unexpected Failures: 164

I  have attached the whole check log: F11178531: check.log 



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

https://reviews.llvm.org/D69758



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


[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Kristina Brooks via Phabricator via cfe-commits
kristina added a comment.

I ran `check-clang` on a x86_64 Ubuntu 18.04 machine (toolchain compiled with 
`compiler-rt` as the default CRT and `libc++`/`libc++abi`/`libunwind_llvm`). I 
think one of the driver tests for multilib stuff may be broken, in which case 
it should probably be investigated/fixed before this lands. And yes you are 
right, this test seems to fail with this configuration even without the patch 
applied. Is this the same test you're referring to (`cross-linux.c`)?


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

https://reviews.llvm.org/D69758



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


[clang] ad0a458 - Allow using traverse() with bindings

2020-01-05 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2020-01-05T20:48:56Z
New Revision: ad0a45833b940057cc74364c82271247bd7925e1

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

LOG: Allow using traverse() with bindings

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 7db5f7a5de82..54ccaabadbe4 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -714,6 +714,17 @@ internal::Matcher 
traverse(ast_type_traits::TraversalKind TK,
   .template unconditionalConvertTo();
 }
 
+template 
+internal::BindableMatcher
+traverse(ast_type_traits::TraversalKind TK,
+ const internal::BindableMatcher ) {
+  return internal::BindableMatcher(
+  internal::DynTypedMatcher::constructRestrictedWrapper(
+  new internal::TraversalMatcher(TK, InnerMatcher),
+  InnerMatcher.getID().first)
+  .template unconditionalConvertTo());
+}
+
 template 
 internal::TraversalWrapper>
 traverse(ast_type_traits::TraversalKind TK,

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index efa628cfeefc..75846ab2d4b1 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -112,6 +112,11 @@ class IdDynMatcher : public DynMatcherInterface {
 return Result;
   }
 
+  llvm::Optional
+  TraversalKind() const override {
+return InnerMatcher->TraversalKind();
+  }
+
 private:
   const std::string ID;
   const IntrusiveRefCntPtr InnerMatcher;

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
index ea1ad424c94d..327ed979962f 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -1700,6 +1700,28 @@ void bar()
 hasDescendant(floatLiteral());
 }
 
+template 
+bool matcherTemplateWithBinding(StringRef Code, const MatcherT ) {
+  return matchAndVerifyResultTrue(
+  Code, M.bind("matchedStmt"),
+  std::make_unique>("matchedStmt", 1));
+}
+
+TEST(Traversal, traverseWithBinding) {
+  // Some existing matcher code expects to take a matcher as a
+  // template arg and bind to it.  Verify that that works.
+
+  EXPECT_TRUE(matcherTemplateWithBinding(
+  R"cpp(
+int foo()
+{
+  return 42.0;
+}
+)cpp",
+  traverse(ast_type_traits::TK_AsIs,
+   returnStmt(has(implicitCastExpr(has(floatLiteral(;
+}
+
 TEST(Traversal, traverseMatcherNesting) {
 
   StringRef Code = R"cpp(



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


Re: [clang] 4711512 - Fix oversight in AST traversal helper

2020-01-05 Thread Roman Lebedev via cfe-commits
Is there a test for this missing?

On Sun, Jan 5, 2020 at 11:32 PM Stephen Kelly via cfe-commits
 wrote:
>
>
> Author: Stephen Kelly
> Date: 2020-01-05T20:27:37Z
> New Revision: 471151238438201f3fe365a7784f1a091328e46c
>
> URL: 
> https://github.com/llvm/llvm-project/commit/471151238438201f3fe365a7784f1a091328e46c
> DIFF: 
> https://github.com/llvm/llvm-project/commit/471151238438201f3fe365a7784f1a091328e46c.diff
>
> LOG: Fix oversight in AST traversal helper
>
> Added:
>
>
> Modified:
> clang/lib/AST/Expr.cpp
>
> Removed:
>
>
>
> 
> diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
> index 5c9ceac854cf..73ddbc62482d 100644
> --- a/clang/lib/AST/Expr.cpp
> +++ b/clang/lib/AST/Expr.cpp
> @@ -3026,7 +3026,7 @@ Expr *Expr::IgnoreUnlessSpelledInSource() {
>Expr *LastE = nullptr;
>while (E != LastE) {
>  LastE = E;
> -E = E->IgnoreImplicit();
> +E = E->IgnoreParenImpCasts();
>
>  auto SR = E->getSourceRange();
>
>
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4711512 - Fix oversight in AST traversal helper

2020-01-05 Thread Stephen Kelly via cfe-commits

Author: Stephen Kelly
Date: 2020-01-05T20:27:37Z
New Revision: 471151238438201f3fe365a7784f1a091328e46c

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

LOG: Fix oversight in AST traversal helper

Added: 


Modified: 
clang/lib/AST/Expr.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 5c9ceac854cf..73ddbc62482d 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -3026,7 +3026,7 @@ Expr *Expr::IgnoreUnlessSpelledInSource() {
   Expr *LastE = nullptr;
   while (E != LastE) {
 LastE = E;
-E = E->IgnoreImplicit();
+E = E->IgnoreParenImpCasts();
 
 auto SR = E->getSourceRange();
 



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 236259.
JonasToth added a comment.

- Merge branch 'master' into feature_transform_const.patch
- link clangAnalysis to the cppcoreguidelines-module
- fix InitListExpr as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-const-correctness.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-cxx17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -62,13 +62,18 @@
   const auto *const S = selectFirst("stmt", Results);
   SmallVector Chain;
   ExprMutationAnalyzer Analyzer(*S, AST->getASTContext());
+
+  std::string buffer;
   for (const auto *E = selectFirst("expr", Results); E != nullptr;) {
 const Stmt *By = Analyzer.findMutation(E);
-std::string buffer;
+if (!By)
+  break;
+
 llvm::raw_string_ostream stream(buffer);
 By->printPretty(stream, nullptr, AST->getASTContext().getPrintingPolicy());
-Chain.push_back(StringRef(stream.str()).trim().str());
+Chain.emplace_back(StringRef(stream.str()).trim().str());
 E = dyn_cast(By);
+buffer.clear();
   }
   return Chain;
 }
@@ -882,38 +887,36 @@
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithAnAssigment) {
-  const auto AST =
-  buildASTFromCodeWithArgs("void f() { int x; int y; (x, y) = 5; }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "void f() { int x; int y; (x, y) = 5; }", {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("y")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithDecOp) {
-  const auto AST =
-  buildASTFromCodeWithArgs("void f() { int x; int y; (x, y)++; }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "void f() { int x; int y; (x, y)++; }", {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("y")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithNonConstMemberCall) {
-  const auto AST =
-  buildASTFromCodeWithArgs("class A { public: int mem; void f() { mem ++; } };"
-   "void fn() { A o1, o2; (o1, o2).f(); }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "class A { public: int mem; void f() { mem ++; } };"
+  "void fn() { A o1, o2; (o1, o2).f(); }",
+  {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("o2")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithConstMemberCall) {
-  const auto AST =
-  buildASTFromCodeWithArgs("class A { public: int mem; void f() const  { } };"
-   "void fn() { A o1, o2; (o1, o2).f(); }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "class A { public: int mem; void f() const  { } };"
+  "void fn() { A o1, o2; (o1, o2).f(); }",
+  {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("o2")), AST->getASTContext());
   EXPECT_FALSE(isMutated(Results, AST.get()));
@@ -957,11 +960,10 @@
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithAmpersandOp) {
-  const auto AST =
-  buildASTFromCodeWithArgs("class A { public: int mem;};"
-

[PATCH] D72231: [Sema] Adds the pointer-to-int-cast diagnostic

2020-01-05 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

In D72231#1804929 , @xbolva00 wrote:

> >> The diagnostic is not enabled by default
>
> But GCC enables it for C even without "-Wall or -Wextra". Clang should follow 
> it..


I'll have a look what the impact is. When I tested it about 20 tests failed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72231



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


[PATCH] D72231: [Sema] Adds the pointer-to-int-cast diagnostic

2020-01-05 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61248 tests passed, 0 failed 
and 736 were skipped.

{icon times-circle color=red} clang-tidy: fail. Please fix clang-tidy findings 
.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72231



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


[PATCH] D72231: [Sema] Adds the pointer-to-int-cast diagnostic

2020-01-05 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

>> The diagnostic is not enabled by default

But GCC enables it for C even without "-Wall or -Wextra". Clang should follow 
it..


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72231



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


[PATCH] D72231: [Sema] Adds the pointer-to-int-cast diagnostic

2020-01-05 Thread Mark de Wever via Phabricator via cfe-commits
Mordante created this revision.
Mordante added reviewers: dblaikie, rsmith.
Mordante added a project: clang.

Converting a pointer to an integer whose result cannot represented in the 
integer type is undefined behavior is C and prohibited in C++. C++ already has 
a diagnostic when casting. This adds a diagnostic for C.

The diagnostic is not enabled by default due to the number of diagnostics it 
triggered while running the tests.

Since this diagnostic uses the range of the conversion it also modifies 
int-to-pointer-cast diagnostic to use a range.

Fixes PR8718: No warning on casting between pointer and non-pointer-sized int


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72231

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaCast.cpp
  clang/test/Sema/cast.c

Index: clang/test/Sema/cast.c
===
--- clang/test/Sema/cast.c
+++ clang/test/Sema/cast.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown %s -verify
+// RUN: %clang_cc1 -fsyntax-only -triple x86_64-unknown-unknown -Wpointer-to-int-cast %s -verify
 
 typedef struct { unsigned long bits[(((1) + (64) - 1) / (64))]; } cpumask_t;
 cpumask_t x;
@@ -151,19 +151,31 @@
 }
 
 void testVoidPtr(VoidPtr v) {
-  (void) (Bool) v;
-  (void) (Int) v;
+  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' (aka '_Bool') from 'VoidPtr' (aka 'void *')}}
+  (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'VoidPtr' (aka 'void *')}}
   (void) (Long) v;
   (void) (VoidPtr) v;
   (void) (CharPtr) v;
+  // Test that casts to void* can be controlled separately
+  // from other -Wpointer-to-int-cast warnings.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
+  (void) (Bool) v; // no-warning
+#pragma clang diagnostic pop
 }
 
 void testCharPtr(CharPtr v) {
-  (void) (Bool) v;
-  (void) (Int) v;
+  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' (aka '_Bool') from 'CharPtr' (aka 'char *')}}
+  (void) (Int) v; // expected-warning{{cast to smaller integer type 'Int' (aka 'int') from 'CharPtr' (aka 'char *')}}
   (void) (Long) v;
   (void) (VoidPtr) v;
   (void) (CharPtr) v;
+  // Test that casts to void* can be controlled separately
+  // from other -Wpointer-to-int-cast warnings.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wvoid-pointer-to-int-cast"
+  (void) (Bool) v; // expected-warning{{cast to smaller integer type 'Bool' (aka '_Bool') from 'CharPtr' (aka 'char *')}}
+#pragma clang diagnostic pop
 }
 
 typedef enum { x_a, x_b } X;
Index: clang/lib/Sema/SemaCast.cpp
===
--- clang/lib/Sema/SemaCast.cpp
+++ clang/lib/Sema/SemaCast.cpp
@@ -1961,7 +1961,7 @@
   << FD << DstCCName << FixItHint::CreateInsertion(NameLoc, CCAttrText);
 }
 
-static void checkIntToPointerCast(bool CStyle, SourceLocation Loc,
+static void checkIntToPointerCast(bool CStyle, const SourceRange ,
   const Expr *SrcExpr, QualType DestType,
   Sema ) {
   QualType SrcType = SrcExpr->getType();
@@ -1983,7 +1983,7 @@
 unsigned Diag = DestType->isVoidPointerType() ?
   diag::warn_int_to_void_pointer_cast
 : diag::warn_int_to_pointer_cast;
-Self.Diag(Loc, Diag) << SrcType << DestType;
+Self.Diag(OpRange.getBegin(), Diag) << SrcType << DestType << OpRange;
   }
 }
 
@@ -2218,8 +2218,7 @@
 
   if (SrcType->isIntegralOrEnumerationType()) {
 assert(destIsPtr && "One type must be a pointer");
-checkIntToPointerCast(CStyle, OpRange.getBegin(), SrcExpr.get(), DestType,
-  Self);
+checkIntToPointerCast(CStyle, OpRange, SrcExpr.get(), DestType, Self);
 // C++ 5.2.10p5: A value of integral or enumeration type can be explicitly
 //   converted to a pointer.
 // C++ 5.2.10p9: [Note: ...a null pointer constant of integral type is not
@@ -2734,8 +2733,8 @@
   SrcExpr = ExprError();
   return;
 }
-checkIntToPointerCast(/* CStyle */ true, OpRange.getBegin(), SrcExpr.get(),
-  DestType, Self);
+checkIntToPointerCast(/* CStyle */ true, OpRange, SrcExpr.get(), DestType,
+  Self);
   } else if (!SrcType->isArithmeticType()) {
 if (!DestType->isIntegralType(Self.Context) &&
 DestType->isArithmeticType()) {
@@ -2745,6 +2744,19 @@
   SrcExpr = ExprError();
   return;
 }
+
+if ((Self.Context.getTypeSize(SrcType) >
+ Self.Context.getTypeSize(DestType))) {
+  // C 6.3.2.3p6: Any pointer type may be converted to an integer type.
+  // Except as previously specified, the result is implementation-defined.
+  // If the result 

[PATCH] D72014: [PowerPC]: Add powerpcspe target triple subarch component

2020-01-05 Thread Justin Hibbits via Phabricator via cfe-commits
jhibbits added a comment.

Any more feedback on this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72014



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


[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-05 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

fixed some of the code guidelines issues. Will tackle some of the more pressing 
issues like ensuring correctness


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

https://reviews.llvm.org/D72217



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


[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-05 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 236255.
njames93 marked 13 inline comments as done.

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

https://reviews.llvm.org/D72217

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
  clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.h
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst
  clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp
@@ -0,0 +1,100 @@
+// RUN: %check_clang_tidy %s readability-qualified-auto %t -- -- -std=c++17
+
+int getInt();
+int *getIntPtr();
+const int *getCIntPtr();
+
+void foo() {
+  // make sure check disregards named types
+  int TypedInt = getInt();
+  int *TypedPtr = getIntPtr();
+  const int *TypedConstPtr = getCIntPtr();
+  int  = *getIntPtr();
+  const int  = *getCIntPtr();
+
+  // make sure check disregards auto types that aren't pointers or references
+  auto AutoInt = getInt();
+
+  auto NakedPtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto variable' can be declared as an 'auto pointer'
+  // CHECK-FIXES: {{^}}  auto * NakedPtr = getIntPtr();
+  auto NakedCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto variable' can be declared as a 'const auto pointer'
+  // CHECK-FIXES: {{^}}  const auto * NakedCPtr = getCIntPtr();
+
+  const auto ConstPtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto variable' can be declared as an 'auto pointer'
+  // CHECK-FIXES: {{^}}  auto *const  ConstPtr = getIntPtr();
+  const auto ConstCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto variable' can be declared as a 'const auto pointer'
+  // CHECK-FIXES: {{^}}  const auto *const  ConstCPtr = getCIntPtr();
+
+  auto *QualPtr = getIntPtr();
+  auto *QualCPtr = getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto pointer' can be declared as a 'const auto pointer'
+  // CHECK-FIXES: {{^}}  const auto *QualCPtr = getCIntPtr();
+  const auto *ConstQualCPtr = getCIntPtr();
+
+  auto  = *getIntPtr();
+  auto  = *getCIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto reference' can be declared as a 'const auto reference'
+  // CHECK-FIXES: {{^}}  const auto  = *getCIntPtr();
+  const auto  = *getCIntPtr();
+
+  if (auto X = getCIntPtr()) {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'auto variable' can be declared as a 'const auto pointer'
+// CHECK-FIXES: {{^}}  if (const auto * X = getCIntPtr()) {
+  }
+  if (auto X = getIntPtr(); X != nullptr) {
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'auto variable' can be declared as an 'auto pointer'
+// CHECK-FIXES: {{^}}  if (auto * X = getIntPtr(); X != nullptr) {
+  }
+}
+
+namespace std {
+template 
+class vector { // dummy impl
+  T _data[1];
+
+public:
+  T *begin() { return _data; }
+  const T *begin() const { return _data; }
+  T *end() { return &_data[1]; }
+  const T *end() const { return &_data[1]; }
+};
+} // namespace std
+
+void change(int &);
+void observe(const int &);
+
+void loopRef(std::vector , const std::vector ) {
+  for (auto  : Mutate) {
+change(Data);
+  }
+  for (auto  : Constant) {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'auto reference' can be declared as a 'const auto reference'
+// CHECK-FIXES: {{^}}  for (const auto  : Constant) {
+observe(Data);
+  }
+}
+
+void loopPtr(const std::vector , const std::vector ) {
+  for (auto Data : Mutate) {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'auto variable' can be declared as an 'auto pointer'
+// CHECK-FIXES: {{^}}  for (auto * Data : Mutate) {
+change(*Data);
+  }
+  for (auto Data : Constant) {
+// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: 'auto variable' can be declared as a 'const auto pointer'
+// CHECK-FIXES: {{^}}  for (const auto * Data : Constant) {
+observe(*Data);
+  }
+}
+
+void bar() {
+  std::vector Vec;
+  std::vector PtrVec;
+  std::vector CPtrVec;
+  loopRef(Vec, Vec);
+  loopPtr(PtrVec, CPtrVec);
+}
Index: clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst
@@ -0,0 +1,48 @@
+.. title:: clang-tidy - readability-qualified-auto
+
+readability-qualified-auto
+==
+
+Adds pointer and const qualifications to auto typed variables  that are deduced
+to pointers and const pointers.
+`LLVM Coding Standards 

[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D54943#1804905 , @0x8000- wrote:

> In D54943#1804904 , @JonasToth wrote:
>
> > In D54943#1804890 , @0x8000- 
> > wrote:
> >
> > > I can't build this on top of current llvm-project tree 
> > > (6a6e6f04ec2cd2f4f07ec4943036c5c2d47ce0c7 
> > > ):
> > >
> > >   /usr/bin/ld: 
> > > lib/libclangTidyCppCoreGuidelinesModule.a(ConstCorrectnessCheck.cpp.o): 
> > > in function 
> > > `clang::tidy::cppcoreguidelines::ConstCorrectnessCheck::registerMatchers(clang::ast_matchers::MatchFinder*)':
> > >   
> > > /home/florin/tools/llvm-project/clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:65:
> > >  undefined reference to `clang::ast_matchers::decompositionDecl'
> > >
> > >
> > > I am building using clang++-9 from Debian, and diff7 applied cleanly.
> > >
> > > Jonas, is it possible to rebase this on top of llvm-project and push it 
> > > to a branch on https://github.com/JonasToth/llvm-project ?
> >
> >
> > I just merged master into the branch and pushed to 
> > `feature_transform_const.patch` branch in my fork. Maybe that works?
> >  If you want you can join IRC, its faster to get this fixed there :)
>
>
> Strange - I have checked out your branch, and the patch is correct (no 
> difference between when I apply the phabricator diff7 on top of upstream 
> llvm-project and when i look at feature_transform_const.patch)
>
> I am using the following cmake configuration:
>
>   cmake ../llvm \
>  -DCMAKE_INSTALL_PREFIX=/opt/clang10 \
>  -DCMAKE_C_COMPILER=/usr/bin/clang-9 \
>  -DCMAKE_CXX_COMPILER=/usr/bin/clang++-9 \
>  -DCMAKE_BUILD_TYPE=Debug \
>  -DLLVM_TARGETS_TO_BUILD=X86 \
>  -DLLVM_ENABLE_THREADS=On \
>  -DLLVM_INSTALL_TOOLCHAIN_ONLY=On \
>  -DLLVM_USE_SPLIT_DWARF=On \
>  -DLLVM_BUILD_TESTS=ON \
>  
> -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;libunwind;lldb;compiler-rt;lld;clang-tools-extra;"
>  \
>  -GNinja
>
>
> What cmake configuration are you using?
>
> (Sorry - I need to go, no time for IRC today)


s weird. it builds both on my laptop and my workstation with comparable 
configuration (not debug, but RelWithDebInfo). i do use lld and ninja, not sure 
if that makes any difference (it shouldnt)
i have no idea why it does not link. are those builds clean?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- added a comment.

In D54943#1804904 , @JonasToth wrote:

> In D54943#1804890 , @0x8000- 
> wrote:
>
> > I can't build this on top of current llvm-project tree 
> > (6a6e6f04ec2cd2f4f07ec4943036c5c2d47ce0c7 
> > ):
> >
> >   /usr/bin/ld: 
> > lib/libclangTidyCppCoreGuidelinesModule.a(ConstCorrectnessCheck.cpp.o): in 
> > function 
> > `clang::tidy::cppcoreguidelines::ConstCorrectnessCheck::registerMatchers(clang::ast_matchers::MatchFinder*)':
> >   
> > /home/florin/tools/llvm-project/clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:65:
> >  undefined reference to `clang::ast_matchers::decompositionDecl'
> >
> >
> > I am building using clang++-9 from Debian, and diff7 applied cleanly.
> >
> > Jonas, is it possible to rebase this on top of llvm-project and push it to 
> > a branch on https://github.com/JonasToth/llvm-project ?
>
>
> I just merged master into the branch and pushed to 
> `feature_transform_const.patch` branch in my fork. Maybe that works?
>  If you want you can join IRC, its faster to get this fixed there :)


Strange - I have checked out your branch, and the patch is correct (no 
difference between when I apply the phabricator diff7 on top of upstream 
llvm-project and when i look at feature_transform_const.patch)

I am using the following cmake configuration:

  cmake ../llvm \
 -DCMAKE_INSTALL_PREFIX=/opt/clang10 \
 -DCMAKE_C_COMPILER=/usr/bin/clang-9 \
 -DCMAKE_CXX_COMPILER=/usr/bin/clang++-9 \
 -DCMAKE_BUILD_TYPE=Debug \
 -DLLVM_TARGETS_TO_BUILD=X86 \
 -DLLVM_ENABLE_THREADS=On \
 -DLLVM_INSTALL_TOOLCHAIN_ONLY=On \
 -DLLVM_USE_SPLIT_DWARF=On \
 -DLLVM_BUILD_TESTS=ON \
 
-DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;libunwind;lldb;compiler-rt;lld;clang-tools-extra;"
 \
 -GNinja

What cmake configuration are you using?

(Sorry - I need to go, no time for IRC today)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

In D54943#1804890 , @0x8000- wrote:

> I can't build this on top of current llvm-project tree 
> (6a6e6f04ec2cd2f4f07ec4943036c5c2d47ce0c7 
> ):
>
>   /usr/bin/ld: 
> lib/libclangTidyCppCoreGuidelinesModule.a(ConstCorrectnessCheck.cpp.o): in 
> function 
> `clang::tidy::cppcoreguidelines::ConstCorrectnessCheck::registerMatchers(clang::ast_matchers::MatchFinder*)':
>   
> /home/florin/tools/llvm-project/clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:65:
>  undefined reference to `clang::ast_matchers::decompositionDecl'
>
>
> I am building using clang++-9 from Debian, and diff7 applied cleanly.
>
> Jonas, is it possible to rebase this on top of llvm-project and push it to a 
> branch on https://github.com/JonasToth/llvm-project ?


I just merged master into the branch and pushed to 
`feature_transform_const.patch` branch in my fork. Maybe that works?
If you want you can join IRC, its faster to get this fixed there :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-05 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

+1 for the check from me as well :)




Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:19
+  if (!getLangOpts().CPlusPlus) {
+// auto deduction not used in c
+return;

Please make the comments full sentences with punctuation.

This `if` has only one statement, so please ellide the braces - by coding 
standard.



Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:48
+  return CharSourceRange::getTokenRange(Var->getBeginLoc(),
+getTokLocationBeforeName(Var));
+}

thats dangerous. Your source location could be invalid or a macroID, I would 
rather make these `llvm::Optional`-



Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:61
+  Diag << FixItHint::CreateReplacement(
+  FixItRange, IsPtrConst ? "const auto *const " : "auto *const ");
+} else {

the outer const might be debatable. some code-bases don't want the `* const`, i 
think neither does LLVM. maybe that could be configurable?



Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:71
+if (!Var->getType().getTypePtr()->getPointeeType().isConstQualified()) {
+  // Pointer isn't const, no need to add const qualifier
+  return;

please make that comment a full sentence with punctuation and ellide the braces.



Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:79
+.isConstQualified();
+if (!IsAutoPtrConst) {
+  return;

braces.



Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:87
+
+if (Var->getType().isConstQualified()) {
+  Diag << FixItHint::CreateReplacement(FixItRange, "const auto *const ");

braces.



Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:96
+if (!Var->getType().getTypePtr()->getPointeeType().isConstQualified()) {
+  // Reference isn't const, no need to add const qualifier
+  return;

full sentence.



Comment at: clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp:104
+.isConstQualified();
+if (!IsAutoRefConst) {
+  return;

braces.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability-qualified-auto.rst:45
+This check helps to enforce this `LLVM Coding Standards recommendation
+`_.

I think this justifies an alias into the llvm-module we have.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp:53
+}
+
+namespace std {

please add some tests with typedefs and macro-interference in the definitions.

Typedefs i am interested in: (names are up to you, just to get the idea)
```
using MyPtr = int *;
using MyRef = int&;
using CMyPtr = const int *;
using CCMyPtr = const int * const;
using CMyRef = const int&;
```
I believe resolves the typedefs and becomes the reference/pointer, but that 
needs some test.

The transformation should not happen if the code comes from a macro ID
```
int* get_ptr() { return new int(42); }
#define AUTO auto
AUTO my_variable = get_pointer();
```
Transformation should not happen in this case, because the macro might be used 
in different places and macros are complicated.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp:100
+  loopPtr(PtrVec, CPtrVec);
+}

What about 
```
auto my_function -> int * { /* foo */ }
```
other contexts for `auto` need to be considered (lambdas, others?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72217



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- added a comment.

I can't build this on top of current llvm-project tree 
(6a6e6f04ec2cd2f4f07ec4943036c5c2d47ce0c7 
):

  /usr/bin/ld: 
lib/libclangTidyCppCoreGuidelinesModule.a(ConstCorrectnessCheck.cpp.o): in 
function 
`clang::tidy::cppcoreguidelines::ConstCorrectnessCheck::registerMatchers(clang::ast_matchers::MatchFinder*)':
  
/home/florin/tools/llvm-project/clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp:65:
 undefined reference to `clang::ast_matchers::decompositionDecl'

I am building using clang++-9 from Debian, and diff7 applied cleanly.

Jonas, is it possible to rebase this on top of llvm-project and push it to a 
branch on https://github.com/JonasToth/llvm-project ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

`clang/lib` almost transforms cleanly.
issues still left:

- `InitListExpr` can initialize non-const references. Such cases are not 
figured out yet (see `create_false_positive` at the end of the testcases)
- I found a case in clang, where `const` was correctly added to a variable, but 
that variable was used in a conditional operator (`foo ? const_var : 
non_const_var`) which broke compilation. I will not fix this, as this is 
extremly rare (I suppose) and in a sense defeats the purpose of our analysis. I 
think something like this should be fixed by hand with a `NOLINT`.

I continue to investigate false positives. But I think most of the real world 
problems are somewhat figured out now and i will start bringing the patch into 
better shape and might even split it up in `ExprMutAnalyzer` part and 
`clang-tidy` part.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 236253.
JonasToth added a comment.

- find more false positives
- fix false positive with refernces to containers in range-for. This introduces 
false negative though
- new test-case for check
- fix range-for iterator speciality; start working on complex conditional and 
comma-operator expression that result in a mutation on a variable
- ignore implicit casts for member-call expr
- fix another false positive in typeDependent contexts and memberExpr instead 
of cxxMemberCallExpr
- add test for overloaded operator>>
- add test for templated operator>>
- another case fixed
- add test for member access in for loop init
- fix false positive with member access with implicit cast between sub and 
base-class
- address explicit cast to references of an element


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943

Files:
  clang-tools-extra/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.cpp
  clang-tools-extra/clang-tidy/cppcoreguidelines/ConstCorrectnessCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-const-correctness.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-cxx17.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-pointer-as-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-transform-values.cpp
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
  clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Index: clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
===
--- clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -62,13 +62,18 @@
   const auto *const S = selectFirst("stmt", Results);
   SmallVector Chain;
   ExprMutationAnalyzer Analyzer(*S, AST->getASTContext());
+
+  std::string buffer;
   for (const auto *E = selectFirst("expr", Results); E != nullptr;) {
 const Stmt *By = Analyzer.findMutation(E);
-std::string buffer;
+if (!By)
+  break;
+
 llvm::raw_string_ostream stream(buffer);
 By->printPretty(stream, nullptr, AST->getASTContext().getPrintingPolicy());
-Chain.push_back(StringRef(stream.str()).trim().str());
+Chain.emplace_back(StringRef(stream.str()).trim().str());
 E = dyn_cast(By);
+buffer.clear();
   }
   return Chain;
 }
@@ -882,38 +887,36 @@
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithAnAssigment) {
-  const auto AST =
-  buildASTFromCodeWithArgs("void f() { int x; int y; (x, y) = 5; }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "void f() { int x; int y; (x, y) = 5; }", {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("y")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithDecOp) {
-  const auto AST =
-  buildASTFromCodeWithArgs("void f() { int x; int y; (x, y)++; }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "void f() { int x; int y; (x, y)++; }", {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("y")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithNonConstMemberCall) {
-  const auto AST =
-  buildASTFromCodeWithArgs("class A { public: int mem; void f() { mem ++; } };"
-   "void fn() { A o1, o2; (o1, o2).f(); }",
-   {"-Wno-unused-value"});
+  const auto AST = buildASTFromCodeWithArgs(
+  "class A { public: int mem; void f() { mem ++; } };"
+  "void fn() { A o1, o2; (o1, o2).f(); }",
+  {"-Wno-unused-value"});
   const auto Results =
   match(withEnclosingCompound(declRefTo("o2")), AST->getASTContext());
   EXPECT_TRUE(isMutated(Results, AST.get()));
 }
 
 TEST(ExprMutationAnalyzerTest, CommaExprWithConstMemberCall) {
-  const auto AST =
-  buildASTFromCodeWithArgs("class A { public: int mem; void f() const  { } };"
-   "void fn() { A o1, o2; (o1, o2).f(); }",

[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-05 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru added a comment.

In D72217#1804533 , @njames93 wrote:

> side note when creating this, the add_new_check.py file hasn't been updated 
> in relation to this commit 
> https://github.com/llvm/llvm-project/commit/d2c9c9157b0528436d3b9f5e22c872f0ee6509a2.
>  This results in a malformed rst file. In this patch I have just manually set 
> it up correctly, but a fix will need to be made for the add_new_check.py


My bad, sorry, I will have a look!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72217



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


[PATCH] D71221: [HIP] Add option --gpu-max-threads-per-block=n

2020-01-05 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

ping


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

https://reviews.llvm.org/D71221



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


[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Samuel Thibault via Phabricator via cfe-commits
sthibaul added a comment.

Which checksuite are you running? I had been using ninja check-all, and I do 
indeed get unexpected failures, but exactly the same set of failures as when 
building against master.


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

https://reviews.llvm.org/D69758



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Florin Iucha via Phabricator via cfe-commits
0x8000- marked an inline comment as done.
0x8000- added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp:608
+}
+
+template 

JonasToth wrote:
> JonasToth wrote:
> > 0x8000- wrote:
> > > JonasToth wrote:
> > > > 0x8000- wrote:
> > > > > 0x8000- wrote:
> > > > > > JonasToth wrote:
> > > > > > > JonasToth wrote:
> > > > > > > > 0x8000- wrote:
> > > > > > > > > Please insert the this test code here:
> > > > > > > > > 
> > > > > > > > > ```
> > > > > > > > > struct IntWrapper {
> > > > > > > > > 
> > > > > > > > >unsigned low;
> > > > > > > > >unsigned high;
> > > > > > > > > 
> > > > > > > > >IntWrapper& operator=(unsigned value) {
> > > > > > > > >   low = value & 0x;
> > > > > > > > >   high = (value >> 16) & 0x;
> > > > > > > > >}
> > > > > > > > > 
> > > > > > > > >template
> > > > > > > > >friend Istream& operator>>(Istream& is, IntWrapper& rhs) {
> > > > > > > > >   unsigned someValue = 0;   // false positive now
> > > > > > > > >   if (is >> someValue) {
> > > > > > > > >  rhs = someValue;
> > > > > > > > >   }
> > > > > > > > >   return is;
> > > > > > > > >}
> > > > > > > > > };
> > > > > > > > > 
> > > > > > > > > unsigned TestHiddenFriend(IntMaker& im) {
> > > > > > > > >IntWrapper iw;
> > > > > > > > > 
> > > > > > > > >im >> iw;
> > > > > > > > > 
> > > > > > > > >return iw.low;
> > > > > > > > > }
> > > > > > > > > ```
> > > > > > > > clang gives me no error when I add the const there. sure it 
> > > > > > > > does reproduce properly?
> > > > > > > Here for reference: https://godbolt.org/z/DXKMYh
> > > > > > Probably I wasn't clear - I suggested adding my test code at line 
> > > > > > 608, because it needs the "IntMaker" definition at line 594.
> > > > > > 
> > > > > > The false positive from this const check is reported on the 
> > > > > > "unsigned someValue = 0;" line inside the template extraction 
> > > > > > operator.
> > > > > Oh, I got it - don't think "shift" think "overloaded extraction 
> > > > > operator".
> > > > > 
> > > > > In my code above, you don't know what ">>" does, and it clearly takes 
> > > > > a mutable reference as the right side.
> > > > > 
> > > > > ```
> > > > > const int foo;
> > > > > std::cin >> foo;
> > > > > ```
> > > > > 
> > > > > should not compile, either :)
> > > > no. something else is going on.
> > > > https://godbolt.org/z/xm8eVC
> > > > ```
> > > > | |   |-CXXOperatorCallExpr  ''
> > > > | |   | |-UnresolvedLookupExpr  '' 
> > > > lvalue (ADL) = 'operator>>' 0x55a26b885938 0x55a26b857238
> > > > | |   | |-DeclRefExpr  'Istream' lvalue ParmVar 0x55a26b885748 
> > > > 'is' 'Istream &'
> > > > | |   | `-DeclRefExpr  'const unsigned int' lvalue Var 
> > > > 0x55a26b885a38 'someValue' 'const unsigned int'
> > > > ```
> > > > This code is only a false positive in the sense, that the "we can not 
> > > > know if something bad happens" is not detected. The operator>> is not 
> > > > resolved. That is because the template is not instantiated and the 
> > > > expressions can therefore not be resolved yet.
> > > > There seems to be no instantiation of this template function.
> > > > 
> > > > Somehow the `im >> iw;` does not instantiate the `friend operator<<`. I 
> > > > reduced it to something i think is minimal and that shows the same 
> > > > behaviour. (https://godbolt.org/z/MMG_4q)
> > > https://godbolt.org/z/7QEdHJ
> > > 
> > > ```
> > > struct IntMaker {
> > >   operator bool() const;
> > > 
> > >   friend IntMaker >>(IntMaker &, unsigned &);
> > >   //friend IntMaker >>(IntMaker &, const unsigned &) = delete;
> > > };
> > > ```
> > > 
> > > If you uncomment the deleted overload then
> > > 
> > > ```
> > > template 
> > > Istream& operator>>(Istream& is, IntWrapper& rhs)  {
> > > unsigned const someValue = 0;
> > > if (is >> someValue) {
> > > rhs = someValue;
> > > }
> > > return is;
> > > }
> > > ```
> > > 
> > > Fails to compile.
> > > 
> > > Depending on what else is around, it seems that somehow the compiler 
> > > would try to use the (bool) conversion to obtain an integral then use it 
> > > as an argument to the built-in integral left shift.
> > > 
> > > https://godbolt.org/z/-JFL5o - this does not compile, as expected:
> > > 
> > > ```
> > > #include 
> > > 
> > > int readInt() {
> > > const int foo = 0;
> > > std::cin >> foo;
> > > return foo;
> > > }
> > > ```
> > > 
> > > so this check should not recommend making foo constant.
> > I see. Implicit conversions are great... :)
> > 
> > I will recheck that. And the `std::cin` example is analyzed correctly. I 
> > added a test for that, too.
> > Thank you for researching the issue!
> https://godbolt.org/z/VerWce
> Minimal example that shows the issue.
As much as I would have liked to contribute a good test to your new checker, 
I'm happier that I have 

[PATCH] D72053: [RFC] Handling implementation limits

2020-01-05 Thread Mark de Wever via Phabricator via cfe-commits
Mordante updated this revision to Diff 236248.
Mordante marked an inline comment as done.
Mordante added a comment.

Made some improvements based on feedback of @craig.topper:

- Adds a not
- Implements an example of the maximum string length when using -Wpedantic


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

https://reviews.llvm.org/D72053

Files:
  clang/docs/ImplementationQuantities.rst
  clang/docs/UsersManual.rst
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/Type.h
  clang/include/clang/Basic/CMakeLists.txt
  clang/include/clang/Basic/ImplementationQuantities.h
  clang/include/clang/Basic/ImplementationQuantities.td
  clang/lib/CodeGen/CGRecordLayout.h
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Lex/LiteralSupport.cpp
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/ClangImplementationQuantitiesEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -81,8 +81,14 @@
  llvm::raw_ostream );
 void EmitClangCommentCommandList(llvm::RecordKeeper ,
  llvm::raw_ostream );
+
 void EmitClangOpcodes(llvm::RecordKeeper , llvm::raw_ostream );
 
+void EmitClangImplementationQuantitiesDocs(llvm::RecordKeeper ,
+   llvm::raw_ostream );
+void EmitClangImplementationQuantities(llvm::RecordKeeper ,
+   llvm::raw_ostream );
+
 void EmitNeon(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitFP16(llvm::RecordKeeper , llvm::raw_ostream );
 void EmitNeonSema(llvm::RecordKeeper , llvm::raw_ostream );
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -60,6 +60,8 @@
   GenClangCommentHTMLNamedCharacterReferences,
   GenClangCommentCommandInfo,
   GenClangCommentCommandList,
+  GenClangImplementationQuantitiesDocs,
+  GenClangImplementationQuantities,
   GenClangOpenCLBuiltins,
   GenArmNeon,
   GenArmFP16,
@@ -172,6 +174,14 @@
 clEnumValN(GenClangCommentCommandList, "gen-clang-comment-command-list",
"Generate list of commands that are used in "
"documentation comments"),
+clEnumValN(GenClangImplementationQuantitiesDocs,
+   "gen-clang-implementation-quantities-docs",
+   "Generate documentation of the implementation quantities "
+   "as defined in the C++ standard"),
+clEnumValN(GenClangImplementationQuantities,
+   "gen-clang-implementation-quantities",
+   "Generate of the implementation quantities "
+   "as defined in the C++ standard"),
 clEnumValN(GenClangOpenCLBuiltins, "gen-clang-opencl-builtins",
"Generate OpenCL builtin declaration handlers"),
 clEnumValN(GenArmNeon, "gen-arm-neon", "Generate arm_neon.h for clang"),
@@ -321,6 +331,12 @@
   case GenClangCommentCommandList:
 EmitClangCommentCommandList(Records, OS);
 break;
+  case GenClangImplementationQuantitiesDocs:
+EmitClangImplementationQuantitiesDocs(Records, OS);
+break;
+  case GenClangImplementationQuantities:
+EmitClangImplementationQuantities(Records, OS);
+break;
   case GenClangOpenCLBuiltins:
 EmitClangOpenCLBuiltins(Records, OS);
 break;
Index: clang/utils/TableGen/ClangImplementationQuantitiesEmitter.cpp
===
--- /dev/null
+++ clang/utils/TableGen/ClangImplementationQuantitiesEmitter.cpp
@@ -0,0 +1,135 @@
+//===--- ClangCommentCommandInfoEmitter.cpp - Generate command lists -//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/StringMatcher.h"
+#include "llvm/TableGen/TableGenBackend.h"
+#include 
+
+using namespace llvm;
+
+namespace clang {
+
+void EmitClangImplementationQuantitiesDocs(RecordKeeper ,
+   raw_ostream ) {
+  // Get the documentation introduction paragraph.
+  const Record *Documentation = Records.getDef("GlobalDocumentation");
+  if (!Documentation) {
+llvm::PrintFatalError("The Documentation top-level definition is missing, "
+  "no documentation will be generated.");
+return;
+  }
+
+  auto WriteValueAndSuffix = [](Record *Tag) {
+if 

[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-05 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

I'll address those issues tonight. As for the ** case, I'll. Hadn't even 
thought of that, I'll try and sort that out


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72217



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


[PATCH] D71499: Add builtins for aligning and checking alignment of pointers and integers

2020-01-05 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri accepted this revision.
lebedev.ri added a subscriber: erichkeane.
lebedev.ri added a comment.
This revision is now accepted and ready to land.

Nice. Thank you for working on this.
I think this finally fully looks good to me.

Not sure whether we should be really adding an attribute to AST,
or just calling `EmitAlignmentAssumption()` like it is done now.
I'll defer to @erichkeane on that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71499



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


[PATCH] D71499: Add builtins for aligning and checking alignment of pointers and integers

2020-01-05 Thread pre-merge checks [bot] via Phabricator via cfe-commits
merge_guards_bot added a comment.

{icon check-circle color=green} Unit tests: pass. 61248 tests passed, 0 failed 
and 736 were skipped.

{icon times-circle color=red} clang-tidy: fail. Please fix clang-tidy findings 
.

{icon times-circle color=red} clang-format: fail. Please format your changes 
with clang-format by running `git-clang-format HEAD^` or applying this patch 
.

Build artifacts 
: 
diff.json 
,
 clang-tidy.txt 
,
 clang-format.patch 
,
 CMakeCache.txt 
,
 console-log.txt 
,
 test-results.xml 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71499



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


[PATCH] D72217: [clang-tidy] Added readability-qualified-auto check

2020-01-05 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added a comment.

Nice to see this patch! I intended to look at a similar patch, but that's no 
longer required.

One question does it also handle cases like `std::vector PtrPtrVec;` 
properly?




Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp:19
+  auto NakedPtr = getIntPtr();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto variable' can be declared 
as an 'auto pointer'
+  // CHECK-FIXES: {{^}}  auto * NakedPtr = getIntPtr();

Wouldn't it be nicer to write 'auto NakedPtr' can be declared as an 'auto 
*NakedPtr' ?
(Likewise for the other warnings.)



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp:23
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto variable' can be declared 
as a 'const auto pointer'
+  // CHECK-FIXES: {{^}}  const auto * NakedCPtr = getCIntPtr();
+

I looks like the fix adds an extra space character after the `*` in `auto * 
NakedCPtr`



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/readability-qualified-auto.cpp:27
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'auto variable' can be declared 
as an 'auto pointer'
+  // CHECK-FIXES: {{^}}  auto *const  ConstPtr = getIntPtr();
+  const auto ConstCPtr = getCIntPtr();

I looks like the fix adds an extra space character, giving two spaces in `const 
 ConstPtr`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72217



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


[PATCH] D71903: [Coroutines][6/6] Clang schedules new passes

2020-01-05 Thread Brian Gesiak via Phabricator via cfe-commits
modocache updated this revision to Diff 236245.
modocache removed a subscriber: wenlei.
modocache added a comment.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Thanks for the reviews. Based on my latest revision of D71899 
, the coro-split diff, this patch now no 
longer manually enqueues coro-split twice. In addition, it uses the PassBuilder 
registration callbacks to enqueue coroutine passes in appropriate spots in the 
pipeline. coro-split now restarts the entire `MainCGPipeline` that's built as 
part of module optimization. As discussed, the coroutine passes are enqueued at 
`-O0`, and they're not enqueued when `-disable-llvm-passes` is specified.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71903

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp

Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -711,6 +711,8 @@
   EarlyFPM.addPass(SROA());
   EarlyFPM.addPass(EarlyCSEPass());
   EarlyFPM.addPass(LowerExpectIntrinsicPass());
+  if (PTO.Coroutines)
+EarlyFPM.addPass(CoroEarlyPass());
   if (Level == O3)
 EarlyFPM.addPass(CallSiteSplittingPass());
 
@@ -825,6 +827,11 @@
 IP.HotCallSiteThreshold = 0;
   MainCGPipeline.addPass(InlinerPass(IP));
 
+  if (PTO.Coroutines) {
+MainCGPipeline.addPass(CoroSplitPass());
+MainCGPipeline.addPass(createCGSCCToFunctionPassAdaptor(CoroElidePass()));
+  }
+
   // Now deduce any function attributes based in the current code.
   MainCGPipeline.addPass(PostOrderFunctionAttrsPass());
 
@@ -1020,6 +1027,9 @@
   // inserting redundancies into the program. This even includes SimplifyCFG.
   OptimizePM.addPass(SpeculateAroundPHIsPass());
 
+  if (PTO.Coroutines)
+OptimizePM.addPass(CoroCleanupPass());
+
   for (auto  : OptimizerLastEPCallbacks)
 C(OptimizePM, Level);
 
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h
+++ llvm/include/llvm/Passes/PassBuilder.h
@@ -92,6 +92,12 @@
   /// is that of the flag: `-forget-scev-loop-unroll`.
   bool ForgetAllSCEVInLoopUnroll;
 
+  /// Tuning option to enable/disable coroutine intrinsic lowering. Its default
+  /// value is false. Frontends such as Clang may enable this conditionally. For
+  /// example, Clang enables this option if the flags `-std=c++2a` or above, or
+  /// `-fcoroutines-ts`, have been specified.
+  bool Coroutines;
+
   /// Tuning option to cap the number of calls to retrive clobbering accesses in
   /// MemorySSA, in LICM.
   unsigned LicmMssaOptCap;
Index: clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp
===
--- /dev/null
+++ clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp
@@ -0,0 +1,70 @@
+// Tests that coroutine passes are added to and run by the new pass manager
+// pipeline, at -O0 and above.
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null \
+// RUN:   -fexperimental-new-pass-manager -fdebug-pass-manager -fcoroutines-ts \
+// RUN:   -O0 %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null \
+// RUN:   -fexperimental-new-pass-manager -fdebug-pass-manager -fcoroutines-ts \
+// RUN:   -O1 %s 2>&1 | FileCheck %s --check-prefix=CHECK-O1
+//
+// CHECK: Starting llvm::Module pass manager run.
+// CHECK: Running pass:{{.*}}CoroEarlyPass
+// CHECK-O1: Starting llvm::Module pass manager run.
+// CHECK-O1: Running pass:{{.*}}CoroEarlyPass
+//
+// The first coro-split pass enqueues a second run of the entire CGSCC pipeline.
+// CHECK: Starting CGSCC pass manager run.
+// CHECK: Running pass: CoroSplitPass on (_Z3foov)
+// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on (_Z3foov)
+// CHECK: Finished CGSCC pass manager run.
+// CHECK-O1: Starting CGSCC pass manager run.
+// CHECK-O1: Running pass: CoroSplitPass on (_Z3foov)
+// CHECK-O1: Running pass:{{.*}}CoroElidePass{{.*}} on (_Z3foov)
+// CHECK-O1: Finished CGSCC pass manager run.
+//
+// The second coro-split pass splits coroutine 'foo' into funclets
+// 'foo.resume', 'foo.destroy', and 'foo.cleanup'. Above -O0, these are inlined
+// and removed.
+// CHECK: Starting CGSCC pass manager run.
+// CHECK: Running pass: CoroSplitPass on (_Z3foov)
+// CHECK: Running pass:{{.*}}CoroElidePass{{.*}} on (_Z3foov, _Z3foov.resume, _Z3foov.destroy, _Z3foov.cleanup)
+// CHECK: Finished CGSCC pass manager run.
+// CHECK-O1: Starting CGSCC pass manager run.
+// CHECK-O1: Running pass: CoroSplitPass on (_Z3foov)
+// CHECK-O1: Running pass:{{.*}}CoroElidePass{{.*}} on (_Z3foov)
+// CHECK-O1: Finished CGSCC 

[PATCH] D71499: Add builtins for aligning and checking alignment of pointers and integers

2020-01-05 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson updated this revision to Diff 236243.
arichardson added a comment.

- Add a test that the new alignment is propagated to e.g. llvm.memcpy

To do this emit a llvm.assume for pointer types and mark the builtin
as having an alloc_align attribute (although that does not seem to do anything)

- Update docs to mention C17 6.5.6p8, C++ [expr.add]

- Use getLangOpts().isSignedOverflowDefined() in codegen.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71499

Files:
  clang/docs/LanguageExtensions.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGen/builtin-align-array.c
  clang/test/CodeGen/builtin-align-assumption.c
  clang/test/CodeGen/builtin-align.c
  clang/test/Sema/builtin-align.c
  clang/test/SemaCXX/builtin-align-cxx.cpp

Index: clang/test/SemaCXX/builtin-align-cxx.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/builtin-align-cxx.cpp
@@ -0,0 +1,236 @@
+// C++-specific checks for the alignment builtins
+// RUN: %clang_cc1 -triple=x86_64-unknown-unknown -std=c++11 -o - %s -fsyntax-only -verify
+
+// Check that we don't crash when using dependent types in __builtin_align:
+template 
+void *c(void *d) { // expected-note{{candidate template ignored}}
+  return __builtin_align_down(d, b);
+}
+
+struct x {};
+x foo;
+void test(void *value) {
+  c(value);
+  c(value); // expected-error{{no matching function for call to 'c'}}
+}
+
+template 
+void test_templated_arguments() {
+  T array[ArraySize];   // expected-error{{variable has incomplete type 'fwddecl'}}
+  static_assert(__is_same(decltype(__builtin_align_up(array, Alignment)), T *), // expected-error{{requested alignment is not a power of 2}}
+"return type should be the decayed array type");
+  static_assert(__is_same(decltype(__builtin_align_down(array, Alignment)), T *),
+"return type should be the decayed array type");
+  static_assert(__is_same(decltype(__builtin_is_aligned(array, Alignment)), bool),
+"return type should be bool");
+  T *x1 = __builtin_align_up(array, Alignment);
+  T *x2 = __builtin_align_down(array, Alignment);
+  bool x3 = __builtin_align_up(array, Alignment);
+}
+
+void test() {
+  test_templated_arguments(); // fine
+  test_templated_arguments();
+  // expected-note@-1{{in instantiation of function template specialization 'test_templated_arguments'}}
+  // expected-note@-2{{forward declaration of 'fwddecl'}}
+  test_templated_arguments(); // invalid alignment value
+  // expected-note@-1{{in instantiation of function template specialization 'test_templated_arguments'}}
+}
+
+template 
+void test_incorrect_alignment_without_instatiation(T value) {
+  int array[32];
+  static_assert(__is_same(decltype(__builtin_align_up(array, 31)), int *), // expected-error{{requested alignment is not a power of 2}}
+"return type should be the decayed array type");
+  static_assert(__is_same(decltype(__builtin_align_down(array, 7)), int *), // expected-error{{requested alignment is not a power of 2}}
+"return type should be the decayed array type");
+  static_assert(__is_same(decltype(__builtin_is_aligned(array, -1)), bool), // expected-error{{requested alignment must be 1 or greater}}
+"return type should be bool");
+  __builtin_align_up(array);   // expected-error{{too few arguments to function call, expected 2, have 1}}
+  __builtin_align_up(array, 31);   // expected-error{{requested alignment is not a power of 2}}
+  __builtin_align_down(array, 31); // expected-error{{requested alignment is not a power of 2}}
+  __builtin_align_up(array, 31);   // expected-error{{requested alignment is not a power of 2}}
+  __builtin_align_up(value, 31);   // This shouldn't want since the type is dependent
+  __builtin_align_up(value);   // Same here
+}
+
+// The original fix for the issue above broke some legitimate code.
+// Here is a regression test:
+typedef __SIZE_TYPE__ size_t;
+void *allocate_impl(size_t size);
+template 
+T *allocate() {
+  constexpr size_t allocation_size =
+  __builtin_align_up(sizeof(T), sizeof(void *));
+  return static_cast(
+  __builtin_assume_aligned(allocate_impl(allocation_size), sizeof(void *)));
+}
+struct Foo {
+  int value;
+};
+void *test2() {
+  return allocate();
+}
+
+// Check that pointers-to-members cannot be used:
+class MemPtr {
+public:
+  int data;
+  void func();
+  virtual void vfunc();
+};
+void test_member_ptr() {
+  __builtin_align_up(::data, 64);// expected-error{{operand of type 'int MemPtr::*' where 

[PATCH] D72227: Add options for clang to align branches within 32B boundary

2020-01-05 Thread Kan Shengchen via Phabricator via cfe-commits
skan created this revision.
skan added reviewers: craig.topper, LuoYuanke, annita.zhang, jyknight, reames, 
MaskRay.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  Add an option -mbranches-within-32B-boundaries to align branches within a
  32-Byte boundary to reduce the potential performance loss of the microcode
  update. The option is equivalent to the combination of three options:
  
  -malign-branch-boundary=32
  -malign-branch=fused+jcc+jmp
  -malign-branch-prefix-size=4
  
  More fine options added for clang:
  1. -malign-branch-boundary=NUM aligns branches within NUM byte boundary.
  2. -malign-branch=TYPE[+TYPE...] specifies types of branches to align.
  3. -malign-branch-prefix-size=NUM limits the prefix size by NUM
  per instruction.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D72227

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/intel-align-branch.c

Index: clang/test/Driver/intel-align-branch.c
===
--- /dev/null
+++ clang/test/Driver/intel-align-branch.c
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch-boundary=32 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOUNDARY
+// CHECK-BOUNDARY: "-mllvm" "-x86-align-branch-boundary=32"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=jcc -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-JCC
+// CHECK-JCC: "-mllvm" "-x86-align-branch=jcc"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=fused -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-FUSED
+// CHECK-FUSED: "-mllvm" "-x86-align-branch=fused"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=jmp -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-JMP
+// CHECK-JMP: "-mllvm" "-x86-align-branch=jmp"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=call -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-CALL
+// CHECK-CALL: "-mllvm" "-x86-align-branch=call"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=ret -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-RET
+// CHECK-RET: "-mllvm" "-x86-align-branch=ret"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=indirect -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-INDIRECT
+// CHECK-INDIRECT: "-mllvm" "-x86-align-branch=indirect"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch=fused+jcc+jmp+ret+call+indirect -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BRANCH
+// CHECK-BRANCH: "-mllvm" "-x86-align-branch=fused+jcc+jmp+ret+call+indirect"
+//
+// RUN: %clang -target x86_64-unknown-unknown -malign-branch-prefix-size=4 -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-PREFIX
+// CHECK-PREFIX: "-mllvm" "-x86-align-branch-prefix-size=4"
+//
+// // RUN: %clang -target x86_64-unknown-unknown -mbranches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-TOTAL
+// CHECK-TOTAL: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=4"
+//
+// RUN: %clang -target x86_64-unknown-unknown -mno-branches-within-32B-boundaries -mbranches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-TOTAL2
+// CHECK-TOTAL2: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=4"
+//
+// RUN: %clang -target x86_64-unknown-unknown -mbranches-within-32B-boundaries -mno-branches-within-32B-boundaries -### -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-TOTAL3
+// CHECK-TOTAL3-NOT: "-mllvm" "-x86-align-branch-boundary=32" "-mllvm" "-x86-align-branch=fused+jcc+jmp" "-mllvm" "-x86-align-branch-prefix-size=4"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2007,8 +2007,55 @@
 CmdArgs.push_back("-mpacked-stack");
 }
 
+static void AlignBranchesOptions(const Driver , const ArgList ,
+ ArgStringList ) {
+  if (const Arg *A = Args.getLastArg(options::OPT_malign_branch_boundary_EQ)) {
+StringRef Value = A->getValue();
+uint64_t Num;
+if (!Value.getAsInteger(10, Num) && Num >= 32 && llvm::isPowerOf2_64(Num)) {
+  CmdArgs.push_back("-mllvm");
+  CmdArgs.push_back(
+  Args.MakeArgString("-x86-align-branch-boundary=" + Value));
+} else {
+  D.Diag(diag::err_drv_unsupported_option_argument)
+  << A->getOption().getName() << Value;
+}
+  }
+
+  if (const Arg *A = Args.getLastArg(options::OPT_malign_branch_EQ)) {
+StringRef Value = A->getValue();
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back(Args.MakeArgString("-x86-align-branch=" + Value));
+  }
+
+  if (const Arg *A =
+  

[PATCH] D72213: [clang-tidy] Add `bugprone-reserved-identifier` to flag usages of reserved C++ names

2020-01-05 Thread Mark de Wever via Phabricator via cfe-commits
Mordante added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp:70
+  const bool IsInGlobalNamespace) {
+  return IsInGlobalNamespace && Name.size() > 1 && Name[0] == '_';
+}

logan-5 wrote:
> Mordante wrote:
> > `Name.size() > 1` doesn't catch `_` in the global namespace. Catching `_` 
> > will probably also cause issues with the automatic renaming.
> > What about renaming `__`?
> Good point. Perhaps the check should catch these but simply not propose a fix.
Agreed.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/bugprone-reserved-identifier.cpp:68
+
+} // namespace __ns
+

logan-5 wrote:
> Mordante wrote:
> > Should it not suggest to change this to `namespace ns` ?
> That's a fair point. I'll point out (again) that this is an existing case 
> missed by the logic factored out of readability-identifier-naming, so it 
> might be better suited for a separate patch?
Ok. I think a separate patch will be better.


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

https://reviews.llvm.org/D72213



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


[PATCH] D72212: [Sema] Improve -Wrange-loop-analysis warnings

2020-01-05 Thread Mark de Wever via Phabricator via cfe-commits
Mordante marked 3 inline comments as done.
Mordante added inline comments.



Comment at: clang/lib/Sema/SemaStmt.cpp:2806
-  // constructors.
-  if (VariableType.isPODType(SemaRef.Context))
 return;

xbolva00 wrote:
> Mordante wrote:
> > xbolva00 wrote:
> > > assert it?
> > Sorry I don't understand what you mean. What do you want to assert?
> if (isTriviallyCopyableType) {
>  assert(isPOD);
> }
> 
> But probably not very useful to have an assert here.
That will not work. Every POD type is TriviallyCopyable, but not every 
TriviallyCopyable type is a POD type.

In the tests I have separate tests for POD types and TriviallyCopyable types.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72212



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


[PATCH] D54943: [clang-tidy] implement const-transformation for cppcoreguidelines-const-correctness

2020-01-05 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth marked 4 inline comments as done.
JonasToth added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-const-correctness-values.cpp:608
+}
+
+template 

JonasToth wrote:
> 0x8000- wrote:
> > JonasToth wrote:
> > > 0x8000- wrote:
> > > > 0x8000- wrote:
> > > > > JonasToth wrote:
> > > > > > JonasToth wrote:
> > > > > > > 0x8000- wrote:
> > > > > > > > Please insert the this test code here:
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > struct IntWrapper {
> > > > > > > > 
> > > > > > > >unsigned low;
> > > > > > > >unsigned high;
> > > > > > > > 
> > > > > > > >IntWrapper& operator=(unsigned value) {
> > > > > > > >   low = value & 0x;
> > > > > > > >   high = (value >> 16) & 0x;
> > > > > > > >}
> > > > > > > > 
> > > > > > > >template
> > > > > > > >friend Istream& operator>>(Istream& is, IntWrapper& rhs) {
> > > > > > > >   unsigned someValue = 0;   // false positive now
> > > > > > > >   if (is >> someValue) {
> > > > > > > >  rhs = someValue;
> > > > > > > >   }
> > > > > > > >   return is;
> > > > > > > >}
> > > > > > > > };
> > > > > > > > 
> > > > > > > > unsigned TestHiddenFriend(IntMaker& im) {
> > > > > > > >IntWrapper iw;
> > > > > > > > 
> > > > > > > >im >> iw;
> > > > > > > > 
> > > > > > > >return iw.low;
> > > > > > > > }
> > > > > > > > ```
> > > > > > > clang gives me no error when I add the const there. sure it does 
> > > > > > > reproduce properly?
> > > > > > Here for reference: https://godbolt.org/z/DXKMYh
> > > > > Probably I wasn't clear - I suggested adding my test code at line 
> > > > > 608, because it needs the "IntMaker" definition at line 594.
> > > > > 
> > > > > The false positive from this const check is reported on the "unsigned 
> > > > > someValue = 0;" line inside the template extraction operator.
> > > > Oh, I got it - don't think "shift" think "overloaded extraction 
> > > > operator".
> > > > 
> > > > In my code above, you don't know what ">>" does, and it clearly takes a 
> > > > mutable reference as the right side.
> > > > 
> > > > ```
> > > > const int foo;
> > > > std::cin >> foo;
> > > > ```
> > > > 
> > > > should not compile, either :)
> > > no. something else is going on.
> > > https://godbolt.org/z/xm8eVC
> > > ```
> > > | |   |-CXXOperatorCallExpr  ''
> > > | |   | |-UnresolvedLookupExpr  '' 
> > > lvalue (ADL) = 'operator>>' 0x55a26b885938 0x55a26b857238
> > > | |   | |-DeclRefExpr  'Istream' lvalue ParmVar 0x55a26b885748 
> > > 'is' 'Istream &'
> > > | |   | `-DeclRefExpr  'const unsigned int' lvalue Var 
> > > 0x55a26b885a38 'someValue' 'const unsigned int'
> > > ```
> > > This code is only a false positive in the sense, that the "we can not 
> > > know if something bad happens" is not detected. The operator>> is not 
> > > resolved. That is because the template is not instantiated and the 
> > > expressions can therefore not be resolved yet.
> > > There seems to be no instantiation of this template function.
> > > 
> > > Somehow the `im >> iw;` does not instantiate the `friend operator<<`. I 
> > > reduced it to something i think is minimal and that shows the same 
> > > behaviour. (https://godbolt.org/z/MMG_4q)
> > https://godbolt.org/z/7QEdHJ
> > 
> > ```
> > struct IntMaker {
> >   operator bool() const;
> > 
> >   friend IntMaker >>(IntMaker &, unsigned &);
> >   //friend IntMaker >>(IntMaker &, const unsigned &) = delete;
> > };
> > ```
> > 
> > If you uncomment the deleted overload then
> > 
> > ```
> > template 
> > Istream& operator>>(Istream& is, IntWrapper& rhs)  {
> > unsigned const someValue = 0;
> > if (is >> someValue) {
> > rhs = someValue;
> > }
> > return is;
> > }
> > ```
> > 
> > Fails to compile.
> > 
> > Depending on what else is around, it seems that somehow the compiler would 
> > try to use the (bool) conversion to obtain an integral then use it as an 
> > argument to the built-in integral left shift.
> > 
> > https://godbolt.org/z/-JFL5o - this does not compile, as expected:
> > 
> > ```
> > #include 
> > 
> > int readInt() {
> > const int foo = 0;
> > std::cin >> foo;
> > return foo;
> > }
> > ```
> > 
> > so this check should not recommend making foo constant.
> I see. Implicit conversions are great... :)
> 
> I will recheck that. And the `std::cin` example is analyzed correctly. I 
> added a test for that, too.
> Thank you for researching the issue!
https://godbolt.org/z/VerWce
Minimal example that shows the issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D54943



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


[clang] 170de3d - [ParserTest] Move raw string literal out of macro

2020-01-05 Thread David Green via cfe-commits

Author: David Green
Date: 2020-01-05T11:24:04Z
New Revision: 170de3de2eea8eb7f514dfa64d3f845ef10d8425

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

LOG: [ParserTest] Move raw string literal out of macro

Some combinations of gcc and ccache do not deal well with raw strings in
macros. Moving the string out to attempt to fix the bots.

Added: 


Modified: 
clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Removed: 




diff  --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp 
b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
index 67fc70790296..6c07c8390256 100644
--- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -437,9 +437,9 @@ decl()))matcher";
 )matcher";
 M = Parser::parseMatcherExpression(Code, nullptr, nullptr, );
 EXPECT_FALSE(M.hasValue());
-EXPECT_EQ(R"error(1:1: Error parsing argument 1 for matcher varDecl.
-2:3: Matcher not found: doesNotExist)error",
-  Error.toStringFull());
+StringRef Expected = R"error(1:1: Error parsing argument 1 for matcher 
varDecl.
+2:3: Matcher not found: doesNotExist)error";
+EXPECT_EQ(Expected, Error.toStringFull());
   }
 }
 



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


[PATCH] D69758: [Gnu toolchain] Look at standard GCC paths for libstdcxx by default

2020-01-05 Thread Kristina Brooks via Phabricator via cfe-commits
kristina requested changes to this revision.
kristina added a comment.

Sorry for responding late, was away. This seems to be tripping up a regression 
test:

  FAIL: Clang :: Driver/cross-linux.c (5312 of 16608)
  llvm-project/clang/test/Driver/cross-linux.c:62:26: error: 
CHECK-MULTI32-X86-64: expected string not found in input
  // CHECK-MULTI32-X86-64: "crti.o" 
"[[gcc_install:.*/Inputs/multilib_32bit_linux_tree/usr/lib/gcc/i386-unknown-linux/4.6.0]]/64{{/|}}crtbegin.o"

Do you mind looking into it?


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

https://reviews.llvm.org/D69758



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