[PATCH] D77776: [Driver] Drop support for FreeBSD < 10

2020-04-09 Thread Jan Beich via Phabricator via cfe-commits
jbeich updated this revision to Diff 256202.
jbeich added a comment.

- Attempt to unbreak tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D6

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/FreeBSD.cpp
  clang/test/Driver/freebsd.c
  clang/test/Driver/freebsd.cpp


Index: clang/test/Driver/freebsd.cpp
===
--- clang/test/Driver/freebsd.cpp
+++ clang/test/Driver/freebsd.cpp
@@ -1,13 +1,13 @@
-// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd10.0 
-stdlib=platform 2>&1 \
+// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd -stdlib=libc++ 
2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-TEN %s
-// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd9.2 
-stdlib=platform 2>&1 \
+// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd 
-stdlib=libstdc++ 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NINE %s
 // CHECK-TEN: "-lc++" "-lm"
 // CHECK-NINE: "-lstdc++" "-lm"
 
-// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd10.0 
-stdlib=platform 2>&1 \
+// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd 
-stdlib=libc++ 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PG-TEN %s
-// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd9.2 
-stdlib=platform 2>&1 \
+// RUN: %clangxx %s -### -pg -o %t.o -target amd64-unknown-freebsd 
-stdlib=libstdc++ 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PG-NINE %s
 // CHECK-PG-TEN: "-lc++_p" "-lm_p"
 // CHECK-PG-NINE: "-lstdc++_p" "-lm_p"
Index: clang/test/Driver/freebsd.c
===
--- clang/test/Driver/freebsd.c
+++ clang/test/Driver/freebsd.c
@@ -73,19 +73,11 @@
 // CHECK-RV64I-LD: ld{{.*}}" {{.*}} "-m" "elf64lriscv"
 //
 // Check that the new linker flags are passed to FreeBSD
-// RUN: %clang -no-canonical-prefixes -target x86_64-pc-freebsd8 -m32 %s \
-// RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS8 %s
-// RUN: %clang -no-canonical-prefixes -target x86_64-pc-freebsd9 -m32 %s \
-// RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS9 %s
-// RUN: %clang -no-canonical-prefixes -target x86_64-pc-freebsd10.0 -m32 %s \
+// RUN: %clang -no-canonical-prefixes -target x86_64-pc-freebsd -m32 %s \
 // RUN:   --sysroot=%S/Inputs/multiarch_freebsd64_tree -### 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS9 %s
-// CHECK-LDFLAGS8-NOT: --hash-style=both
-// CHECK-LDFLAGS8: --enable-new-dtags
-// CHECK-LDFLAGS9: --hash-style=both
-// CHECK-LDFLAGS9: --enable-new-dtags
+// RUN:   | FileCheck --check-prefix=CHECK-LDFLAGS %s
+// CHECK-LDFLAGS: --hash-style=both
+// CHECK-LDFLAGS: --enable-new-dtags
 //
 // Check that we do not pass --hash-style=gnu and --hash-style=both to linker
 // and provide correct path to the dynamic linker for MIPS platforms.
Index: clang/lib/Driver/ToolChains/FreeBSD.cpp
===
--- clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -172,9 +172,8 @@
   CmdArgs.push_back("/libexec/ld-elf.so.1");
 }
 const llvm::Triple &T = ToolChain.getTriple();
-if (T.getOSMajorVersion() >= 9) {
-  if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc || 
T.isX86())
-CmdArgs.push_back("--hash-style=both");
+if (Arch == llvm::Triple::arm || Arch == llvm::Triple::sparc || T.isX86()) 
{
+  CmdArgs.push_back("--hash-style=both");
 }
 CmdArgs.push_back("--enable-new-dtags");
   }
@@ -378,9 +377,7 @@
 }
 
 ToolChain::CXXStdlibType FreeBSD::GetDefaultCXXStdlibType() const {
-  if (getTriple().getOSMajorVersion() >= 10)
-return ToolChain::CST_Libcxx;
-  return ToolChain::CST_Libstdcxx;
+  return ToolChain::CST_Libcxx;
 }
 
 unsigned FreeBSD::GetDefaultDwarfVersion() const {
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -2224,7 +2224,7 @@
 const llvm::Triple &Triple = getTarget().getTriple();
 if (Triple.isOSDarwin() || Triple.getOS() == llvm::Triple::PS4)
   return false;
-if (Triple.isOSFreeBSD() && Triple.getOSMajorVersion() >= 10)
+if (Triple.isOSFreeBSD())
   return false;
 return true;
   }


Index: clang/test/Driver/freebsd.cpp
===
--- clang/test/Driver/freebsd.cpp
+++ clang/test/Driver/freebsd.cpp
@@ -1,13 +1,13 @@
-// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd10.0 -stdlib=platform 2>&1 \
+// RUN: %clangxx %s -### -o %t.o -target amd64-unknown-freebsd -stdlib=libc++ 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-TEN 

[PATCH] D77379: [FPEnv] Use single enum to represent rounding mode

2020-04-09 Thread Serge Pavlov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7ff5b38f27f: [FPEnv] Use single enum to represent rounding 
mode (authored by sepavloff).

Changed prior to commit:
  https://reviews.llvm.org/D77379?vs=255949&id=256203#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77379

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Serialization/ASTReader.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/ADT/APFloat.h
  llvm/include/llvm/ADT/FloatingPointMode.h
  llvm/include/llvm/IR/FPEnv.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/IR/FPEnv.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/IR/IntrinsicInst.cpp
  llvm/lib/Support/APFloat.cpp
  llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
  llvm/unittests/IR/IRBuilderTest.cpp

Index: llvm/unittests/IR/IRBuilderTest.cpp
===
--- llvm/unittests/IR/IRBuilderTest.cpp
+++ llvm/unittests/IR/IRBuilderTest.cpp
@@ -257,51 +257,51 @@
   ASSERT_TRUE(isa(V));
   auto *CII = cast(V);
   EXPECT_EQ(fp::ebStrict, CII->getExceptionBehavior());
-  EXPECT_EQ(fp::rmDynamic, CII->getRoundingMode());
+  EXPECT_EQ(RoundingMode::Dynamic, CII->getRoundingMode());
 
   Builder.setDefaultConstrainedExcept(fp::ebIgnore);
-  Builder.setDefaultConstrainedRounding(fp::rmUpward);
+  Builder.setDefaultConstrainedRounding(RoundingMode::TowardPositive);
   V = Builder.CreateFAdd(V, V);
   CII = cast(V);
   EXPECT_EQ(fp::ebIgnore, CII->getExceptionBehavior());
-  EXPECT_EQ(CII->getRoundingMode(), fp::rmUpward);
+  EXPECT_EQ(CII->getRoundingMode(), RoundingMode::TowardPositive);
 
   Builder.setDefaultConstrainedExcept(fp::ebIgnore);
-  Builder.setDefaultConstrainedRounding(fp::rmToNearest);
+  Builder.setDefaultConstrainedRounding(RoundingMode::NearestTiesToEven);
   V = Builder.CreateFAdd(V, V);
   CII = cast(V);
   EXPECT_EQ(fp::ebIgnore, CII->getExceptionBehavior());
-  EXPECT_EQ(fp::rmToNearest, CII->getRoundingMode());
+  EXPECT_EQ(RoundingMode::NearestTiesToEven, CII->getRoundingMode());
 
   Builder.setDefaultConstrainedExcept(fp::ebMayTrap);
-  Builder.setDefaultConstrainedRounding(fp::rmDownward);
+  Builder.setDefaultConstrainedRounding(RoundingMode::TowardNegative);
   V = Builder.CreateFAdd(V, V);
   CII = cast(V);
   EXPECT_EQ(fp::ebMayTrap, CII->getExceptionBehavior());
-  EXPECT_EQ(fp::rmDownward, CII->getRoundingMode());
+  EXPECT_EQ(RoundingMode::TowardNegative, CII->getRoundingMode());
 
   Builder.setDefaultConstrainedExcept(fp::ebStrict);
-  Builder.setDefaultConstrainedRounding(fp::rmTowardZero);
+  Builder.setDefaultConstrainedRounding(RoundingMode::TowardZero);
   V = Builder.CreateFAdd(V, V);
   CII = cast(V);
   EXPECT_EQ(fp::ebStrict, CII->getExceptionBehavior());
-  EXPECT_EQ(fp::rmTowardZero, CII->getRoundingMode());
+  EXPECT_EQ(RoundingMode::TowardZero, CII->getRoundingMode());
 
   Builder.setDefaultConstrainedExcept(fp::ebIgnore);
-  Builder.setDefaultConstrainedRounding(fp::rmDynamic);
+  Builder.setDefaultConstrainedRounding(RoundingMode::Dynamic);
   V = Builder.CreateFAdd(V, V);
   CII = cast(V);
   EXPECT_EQ(fp::ebIgnore, CII->getExceptionBehavior());
-  EXPECT_EQ(fp::rmDynamic, CII->getRoundingMode());
+  EXPECT_EQ(RoundingMode::Dynamic, CII->getRoundingMode());
 
   // Now override the defaults.
   Call = Builder.CreateConstrainedFPBinOp(
 Intrinsic::experimental_constrained_fadd, V, V, nullptr, "", nullptr,
-fp::rmDownward, fp::ebMayTrap);
+RoundingMode::TowardNegative, fp::ebMayTrap);
   CII = cast(Call);
   EXPECT_EQ(CII->getIntrinsicID(), Intrinsic::experimental_constrained_fadd);
   EXPECT_EQ(fp::ebMayTrap, CII->getExceptionBehavior());
-  EXPECT_EQ(fp::rmDownward, CII->getRoundingMode());
+  EXPECT_EQ(RoundingMode::TowardNegative, CII->getRoundingMode());
 
   Builder.CreateRetVoid();
   EXPECT_FALSE(verifyModule(*M));
Index: llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
===
--- llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -270,7 +270,7 @@
 }
 
 void FAddendCoef::operator+=(const FAddendCoef &That) {
-  enum APFloat::roundingMode RndMode = APFloat::rmNearestTiesToEven;
+  RoundingMode RndMode = RoundingMode::NearestTiesToEven;
   if (isInt() == That.isInt()) {
 if (isInt())
   IntVal += That.IntVal;
Index: llvm/lib/Support/APFloat.cpp
===
--- llvm/lib/Support/APFloat.cpp
+++ llvm/lib/Support/APFloat.cpp
@@ -171,6 +171,12 @

[PATCH] D68049: Propeller: Clang options for basic block sections

2020-04-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D68049#1970825 , @tmsriram wrote:

> Ping.


@rsmith ^^^

More specific question, do you think `clang/test/CodeGen/basicblock-sections.c` 
should be converted to a `-S -emit-llvm` test?


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

https://reviews.llvm.org/D68049



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


[PATCH] D73845: [Gnu toolchain] Move GCC multilib/multiarch paths support from Linux to Gnu

2020-04-09 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Moving functions from Linux.cpp to Gnu.cpp is definitely appropriate. Have you 
made any adjustment?


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

https://reviews.llvm.org/D73845



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


[PATCH] D77766: [clangd] Set up machinery for gtests of ClangdLSPServer.

2020-04-09 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

LGTM, mostly nits.

Unfortunately I don't see any way to make it simpler :/




Comment at: clang-tools-extra/clangd/unittests/ClangdLSPServerTests.cpp:104
+
+MATCHER_P(DiagMessage, M, "") {
+  if (const auto *O = arg.getAsObject()) {

nit: move this to top of the file



Comment at: clang-tools-extra/clangd/unittests/LSPClient.cpp:65
+
+  void reply(llvm::json::Value ID,
+ llvm::Expected V) override {

put methods before fields



Comment at: clang-tools-extra/clangd/unittests/LSPClient.cpp:68
+if (V)
+  logBody("reply", *V, /*Send=*/false);
+std::lock_guard Lock(Mu);

i think logging errors here could help with debugging.



Comment at: clang-tools-extra/clangd/unittests/LSPClient.cpp:71
+if (auto I = ID.getAsInteger()) {
+  if (*I >= 0 && *I < (int64_t)CallResults.size()) {
+CallResults[*I].set(std::move(V));

nit: static_cast



Comment at: clang-tools-extra/clangd/unittests/LSPClient.cpp:99
+  Lock.unlock();
+  if (!Action) // stop!
+return llvm::Error::success();

this check should happen before accessing Actions.front



Comment at: clang-tools-extra/clangd/unittests/LSPClient.cpp:106
+
+public:
+  std::pair addCallSlot() {

put public before private



Comment at: clang-tools-extra/clangd/unittests/LSPClient.cpp:157
+
+void LSPClient::stop() { T->enqueue(nullptr); }
+

ah, the `!Action` check for stop now makes sense :D maybe get rid of the `Stop` 
flag inside transportimpl and say `an empty action terminates the loop` or make 
this invoke a T->stop(); which sets the flag



Comment at: clang-tools-extra/clangd/unittests/LSPClient.cpp:197
+  auto U = PubDiagsParams->getString("uri");
+  if (!U || *U != uri(Path))
+continue;

URI is not an optional field, so shouldn't `!U` -> ADD_FAILURE() ?



Comment at: clang-tools-extra/clangd/unittests/LSPClient.cpp:199
+continue;
+  if (const auto *Diagnostics = PubDiagsParams->getArray("diagnostics"))
+return std::vector(Diagnostics->begin(),

again `diagnostics` is not optional



Comment at: clang-tools-extra/clangd/unittests/LSPClient.h:44
+friend TransportImpl;
+void set(llvm::Expected V);
+  };

nit: put it before members, also some comments about "multiple call is failure" 
might be nice


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77766



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


[PATCH] D73845: [Gnu toolchain] Move GCC multilib/multiarch paths support from Linux to Gnu

2020-04-09 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2694
+
+void Generic_GCC::AddGCCMultilibPaths(const Driver &D,
+  const std::string &SysRoot,

The class already has `GCC` in the name, so there's no need to repeat `GCC` in 
the name of the method, i.e. this can be just `Generic_GCC::AddMultilibPaths`. 
The same for other new methods.


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

https://reviews.llvm.org/D73845



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


[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-09 Thread Balázs Kéri via Phabricator via cfe-commits
balazske added inline comments.



Comment at: clang/include/clang/AST/Expr.h:1494
 SourceLocation l, unsigned Scale);
-
   // Store the int as is without any bit shifting.

This line removal is not needed and can cause disturbances, it is better to 
remove it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721



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


[PATCH] D77637: [SanitizerCoverage] Add -fsanitize-coverage=inline-bool-flag

2020-04-09 Thread Pratyai Mazumder via Phabricator via cfe-commits
pratyai updated this revision to Diff 256206.
pratyai marked an inline comment as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77637

Files:
  clang/docs/SanitizerCoverage.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/autocomplete.c
  clang/test/Driver/fsanitize-coverage.c

Index: clang/test/Driver/fsanitize-coverage.c
===
--- clang/test/Driver/fsanitize-coverage.c
+++ clang/test/Driver/fsanitize-coverage.c
@@ -105,9 +105,18 @@
 // CHECK_INLINE8BIT-NOT: warning
 // CHECK_INLINE8BIT: -fsanitize-coverage-inline-8bit-counters
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// CHECK_PC_TABLE: -fsanitize-coverage-pc-table
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// CHECK_PC_TABLE_FOR_INLINE8BIT: -fsanitize-coverage-pc-table
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=bb,inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// CHECK_INLINE_BOOL_FLAG-NOT: warning
+// CHECK_INLINE_BOOL_FLAG: -fsanitize-coverage-inline-bool-flag
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// CHECK_PC_TABLE_FOR_INLINEBOOL: -fsanitize-coverage-pc-table
 
 // RUN: %clang_cl --target=i386-pc-win32 -fsanitize=address -fsanitize-coverage=func,trace-pc-guard -c -### -- %s 2>&1 | FileCheck %s -check-prefix=CLANG-CL-COVERAGE
 // CLANG-CL-COVERAGE-NOT: error:
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -54,6 +54,7 @@
 // FNOSANICOVERALL-NEXT: func
 // FNOSANICOVERALL-NEXT: indirect-calls
 // FNOSANICOVERALL-NEXT: inline-8bit-counters
+// FNOSANICOVERALL-NEXT: inline-bool-flag
 // FNOSANICOVERALL-NEXT: no-prune
 // FNOSANICOVERALL-NEXT: trace-bb
 // FNOSANICOVERALL-NEXT: trace-cmp
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1176,6 +1176,8 @@
   Opts.SanitizeCoverageNoPrune = Args.hasArg(OPT_fsanitize_coverage_no_prune);
   Opts.SanitizeCoverageInline8bitCounters =
   Args.hasArg(OPT_fsanitize_coverage_inline_8bit_counters);
+  Opts.SanitizeCoverageInlineBoolFlag =
+  Args.hasArg(OPT_fsanitize_coverage_inline_bool_flag);
   Opts.SanitizeCoveragePCTable = Args.hasArg(OPT_fsanitize_coverage_pc_table);
   Opts.SanitizeCoverageStackDepth =
   Args.hasArg(OPT_fsanitize_coverage_stack_depth);
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -77,17 +77,18 @@
   CoverageBB = 1 << 1,
   CoverageEdge = 1 << 2,
   CoverageIndirCall = 1 << 3,
-  CoverageTraceBB = 1 << 4,  // Deprecated.
+  CoverageTraceBB = 1 << 4, // Deprecated.
   CoverageTraceCmp = 1 << 5,
   CoverageTraceDiv = 1 << 6,
   CoverageTraceGep = 1 << 7,
-  Coverage8bitCounters = 1 << 8,  // Deprecated.
+  Coverage8bitCounters = 1 << 8, // Deprecated.
   CoverageTracePC = 1 << 9,
   CoverageTracePCGuard = 1 << 10,
   CoverageNoPrune = 1 << 11,
   CoverageInline8bitCounters = 1 << 12,
   CoveragePCTable = 1 << 13,
   CoverageStackDepth = 1 << 14,
+  CoverageInlineBoolFlag = 1 << 15,
 };
 
 /// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any
@@ -380,7 +381,8 @@
 
   // Enable coverage if the fuzzing flag is set.
   if (Add & SanitizerKind::FuzzerNoLink) {
-CoverageFeatures |= CoverageInline8bitCounters | CoverageIndirCall |
+CoverageFeatures |= CoverageInline8bitCounters |
+CoverageInlineBoolFlag | CoverageInd

[PATCH] D77571: [clang-tidy] Add check to find calls to NSInvocation methods under ARC that don't have proper object argument lifetimes.

2020-04-09 Thread Michael Wyman via Phabricator via cfe-commits
mwyman updated this revision to Diff 256210.
mwyman added a comment.

Add matching MemberRefExpr case, not just the non-matching case there was 
before.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77571

Files:
  clang-tools-extra/clang-tidy/objc/CMakeLists.txt
  clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp
  clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.h
  clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/objc-nsinvocation-argument-lifetime.rst
  
clang-tools-extra/test/clang-tidy/checkers/objc-nsinvocation-argument-lifetime.m

Index: clang-tools-extra/test/clang-tidy/checkers/objc-nsinvocation-argument-lifetime.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/objc-nsinvocation-argument-lifetime.m
@@ -0,0 +1,91 @@
+// RUN: %check_clang_tidy %s objc-nsinvocation-argument-lifetime %t
+
+__attribute__((objc_root_class))
+@interface NSObject
+@end
+
+@interface NSInvocation : NSObject
+- (void)getArgument:(void *)Arg atIndex:(int)Index;
+- (void)getReturnValue:(void *)ReturnValue;
+@end
+
+@interface OtherClass : NSObject
+- (void)getArgument:(void *)Arg atIndex:(int)Index;
+@end
+
+void foo(NSInvocation *Invocation) {
+  __unsafe_unretained id Arg2;
+  id Arg3;
+  // CHECK-FIXES: __unsafe_unretained id Arg3;
+  NSObject __strong *Arg4;
+  // CHECK-FIXES: NSObject __unsafe_unretained *Arg4;
+  __weak id Arg5;
+  // CHECK-FIXES: __unsafe_unretained id Arg5;
+  id ReturnValue;
+  // CHECK-FIXES: __unsafe_unretained id ReturnValue;
+  void (^BlockArg1)();
+  // CHECK-FIXES: __unsafe_unretained void (^BlockArg1)();
+  __unsafe_unretained void (^BlockArg2)();
+
+  [Invocation getArgument:&Arg2 atIndex:2];
+
+  [Invocation getArgument:&Arg3 atIndex:3];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:&Arg4 atIndex:4];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:&Arg5 atIndex:5];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:&BlockArg1 atIndex:6];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:&BlockArg2 atIndex:6];
+
+  [Invocation getReturnValue:&ReturnValue];
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: NSInvocation '-getReturnValue:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:(void *)0 atIndex:6];
+}
+
+void bar(OtherClass *OC) {
+  id Arg;
+  [OC getArgument:&Arg atIndex:2];
+}
+
+struct Foo {
+  __unsafe_unretained id Field1;
+  id Field2;
+};
+
+@interface TestClass : NSObject {
+@public
+  id Argument1;
+  __unsafe_unretained id Argument2;
+  struct Foo Bar;
+}
+@end
+
+@implementation TestClass
+
+- (void)processInvocation:(NSInvocation *)Invocation {
+  [Invocation getArgument:&Argument1 atIndex:2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+  [Invocation getArgument:&self->Argument1 atIndex:2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+  [Invocation getArgument:&Argument2 atIndex:2];
+  [Invocation getArgument:&self->Argument2 atIndex:2];
+
+  [Invocation getReturnValue:&(self->Bar.Field1)];
+  [Invocation getReturnValue:&(self->Bar.Field2)];
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: NSInvocation '-getReturnValue:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+}
+
+@end
+
+void baz(NSInvocation *Invocation, TestClass *Obj) {
+  [Invocation getArgument:&Obj->Argument1 atIndex:2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+  [Invocation getArgument:&Obj->Argument2 atIndex:2];
+}
Index: clang-tools-extra/docs/clang-tidy/checks/objc-nsinvoc

[PATCH] D76768: [analyzer] Added support of scan-build and exploded-graph-rewriter regression tests for Windows

2020-04-09 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov added a comment.

@thakis

> 'perl' is not recognized as an internal or external command,

I think you got another problem, that Perl isn't just presented in your PATH. 
It is not the case for buildbot logs.

> perl wasn't required to run tests on Win for a long time. If we do want to 
> run these tests on Windows, could we make the config lit file check if perl 
> is available and set a feature and require that in the tests?

This is a good idea, to make tests more robust and friendly verbal.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76768



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


[PATCH] D75665: [analyzer] On-demand parsing capability for CTU

2020-04-09 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 updated this revision to Diff 256212.
gamesh411 added a comment.
Herald added a subscriber: ASDenysPetrov.

Refactored the test
Copying the compile_commands.json in case of test for C files
results in the extdef mapping tool finding the correct compiler
flags for the C to be imported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75665

Files:
  clang/include/clang/CrossTU/CrossTranslationUnit.h
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/CrossTU/CMakeLists.txt
  clang/lib/CrossTU/CrossTranslationUnit.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.on-the-fly.txt
  clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.on-the-fly.txt
  clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.txt
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/ctu-different-triples.cpp
  clang/test/Analysis/ctu-main.c
  clang/test/Analysis/ctu-main.cpp
  clang/test/Analysis/ctu-on-demand-parsing.c
  clang/test/Analysis/ctu-on-demand-parsing.cpp
  clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
  clang/unittests/CrossTU/CrossTranslationUnitTest.cpp

Index: clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
===
--- clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
+++ clang/unittests/CrossTU/CrossTranslationUnitTest.cpp
@@ -7,10 +7,11 @@
 //===--===//
 
 #include "clang/CrossTU/CrossTranslationUnit.h"
-#include "clang/Frontend/CompilerInstance.h"
 #include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/FrontendAction.h"
 #include "clang/Tooling/Tooling.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ToolOutputFile.h"
@@ -162,7 +163,7 @@
   IndexFile.os().flush();
   EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
   llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFileName, "");
+  parseCrossTUIndex(IndexFileName);
   EXPECT_TRUE((bool)IndexOrErr);
   llvm::StringMap ParsedIndex = IndexOrErr.get();
   for (const auto &E : Index) {
@@ -173,25 +174,5 @@
 EXPECT_TRUE(Index.count(E.getKey()));
 }
 
-TEST(CrossTranslationUnit, CTUDirIsHandledCorrectly) {
-  llvm::StringMap Index;
-  Index["a"] = "/b/c/d";
-  std::string IndexText = createCrossTUIndexString(Index);
-
-  int IndexFD;
-  llvm::SmallString<256> IndexFileName;
-  ASSERT_FALSE(llvm::sys::fs::createTemporaryFile("index", "txt", IndexFD,
-  IndexFileName));
-  llvm::ToolOutputFile IndexFile(IndexFileName, IndexFD);
-  IndexFile.os() << IndexText;
-  IndexFile.os().flush();
-  EXPECT_TRUE(llvm::sys::fs::exists(IndexFileName));
-  llvm::Expected> IndexOrErr =
-  parseCrossTUIndex(IndexFileName, "/ctudir");
-  EXPECT_TRUE((bool)IndexOrErr);
-  llvm::StringMap ParsedIndex = IndexOrErr.get();
-  EXPECT_EQ(ParsedIndex["a"], "/ctudir/b/c/d");
-}
-
 } // end namespace cross_tu
 } // end namespace clang
Index: clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
===
--- clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
+++ clang/test/Analysis/ctu-unknown-parts-in-triples.cpp
@@ -5,7 +5,7 @@
 // RUN: mkdir -p %t/ctudir
 // RUN: %clang_cc1 -std=c++14 -triple x86_64-pc-linux-gnu \
 // RUN:   -emit-pch -o %t/ctudir/ctu-other.cpp.ast %S/Inputs/ctu-other.cpp
-// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.txt %t/ctudir/externalDefMap.txt
+// RUN: cp %S/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt %t/ctudir/externalDefMap.txt
 // RUN: %clang_analyze_cc1 -std=c++14 -triple x86_64-unknown-linux-gnu \
 // RUN:   -analyzer-checker=core,debug.ExprInspection \
 // RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
Index: clang/test/Analysis/ctu-on-demand-parsing.cpp
===
--- /dev/null
+++ clang/test/Analysis/ctu-on-demand-parsing.cpp
@@ -0,0 +1,100 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+// RUN: cp %S/Inputs/ctu-chain.cpp %t/ctudir/ctu-chain.cpp
+// RUN: echo '[{"directory":"%S/Inputs","command":"clang++ -c ctu-chain.cpp","file":"ctu-chain.cpp"},{"directory":"%S/Inputs","command":"clang++ -c ctu-other.cpp","file":"ctu-other.cpp"}]' | sed -e 's/\\//g' > %t/ctudir/compile_commands.json
+// RUN: %clang_extdef_map %S/Inputs/ctu-chain.cpp %S/Inputs/ctu-other.cpp > %t/ctudir/externalDefMap.txt
+// RUN: %clang_analyze_cc1 -triple x86_64-pc-linux-

[PATCH] D77571: [clang-tidy] Add check to find calls to NSInvocation methods under ARC that don't have proper object argument lifetimes.

2020-04-09 Thread Michael Wyman via Phabricator via cfe-commits
mwyman updated this revision to Diff 256209.
mwyman marked an inline comment as done.
mwyman added a comment.

Updating per Stephane's comments. To deal with struct fields needed to match 
MemberRefExprs.

However, in doing so I discovered that the match conditions I thought were 
catching ObjcIvarRefExpr or MemberRefExpr were sometimes incorrectly matching 
on the self reference, which is itself a DeclRefExpr to an object with strong 
lifetime semantics. This meant correct usages would sometimes be caught, 
because the ObjcIvarRefExpr wouldn't match but the DeclRefExpr (to self) did.

That self (or other object) that is dereferenced (implicity or explicitly) has 
a parent ImplicitCastExpr in the AST, so I've dealt with this situation by 
excluding that case from matching the declRefExpr.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77571

Files:
  clang-tools-extra/clang-tidy/objc/CMakeLists.txt
  clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp
  clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.h
  clang-tools-extra/clang-tidy/objc/ObjCTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/objc-nsinvocation-argument-lifetime.rst
  
clang-tools-extra/test/clang-tidy/checkers/objc-nsinvocation-argument-lifetime.m

Index: clang-tools-extra/test/clang-tidy/checkers/objc-nsinvocation-argument-lifetime.m
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/objc-nsinvocation-argument-lifetime.m
@@ -0,0 +1,88 @@
+// RUN: %check_clang_tidy %s objc-nsinvocation-argument-lifetime %t
+
+__attribute__((objc_root_class))
+@interface NSObject
+@end
+
+@interface NSInvocation : NSObject
+- (void)getArgument:(void *)Arg atIndex:(int)Index;
+- (void)getReturnValue:(void *)ReturnValue;
+@end
+
+@interface OtherClass : NSObject
+- (void)getArgument:(void *)Arg atIndex:(int)Index;
+@end
+
+void foo(NSInvocation *Invocation) {
+  __unsafe_unretained id Arg2;
+  id Arg3;
+  // CHECK-FIXES: __unsafe_unretained id Arg3;
+  NSObject __strong *Arg4;
+  // CHECK-FIXES: NSObject __unsafe_unretained *Arg4;
+  __weak id Arg5;
+  // CHECK-FIXES: __unsafe_unretained id Arg5;
+  id ReturnValue;
+  // CHECK-FIXES: __unsafe_unretained id ReturnValue;
+  void (^BlockArg1)();
+  // CHECK-FIXES: __unsafe_unretained void (^BlockArg1)();
+  __unsafe_unretained void (^BlockArg2)();
+
+  [Invocation getArgument:&Arg2 atIndex:2];
+
+  [Invocation getArgument:&Arg3 atIndex:3];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:&Arg4 atIndex:4];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:&Arg5 atIndex:5];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:&BlockArg1 atIndex:6];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:&BlockArg2 atIndex:6];
+
+  [Invocation getReturnValue:&ReturnValue];
+  // CHECK-MESSAGES: :[[@LINE-1]]:30: warning: NSInvocation '-getReturnValue:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+
+  [Invocation getArgument:(void *)0 atIndex:6];
+}
+
+void bar(OtherClass *OC) {
+  id Arg;
+  [OC getArgument:&Arg atIndex:2];
+}
+
+struct Foo {
+  __unsafe_unretained id Field;
+};
+
+@interface TestClass : NSObject {
+@public
+  id Argument1;
+  __unsafe_unretained id Argument2;
+  struct Foo Bar;
+}
+@end
+
+@implementation TestClass
+
+- (void)processInvocation:(NSInvocation *)Invocation {
+  [Invocation getArgument:&Argument1 atIndex:2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+  [Invocation getArgument:&self->Argument1 atIndex:2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation '-getArgument:atIndex:' should only pass pointers to objects with ownership __unsafe_unretained [objc-nsinvocation-argument-lifetime]
+  [Invocation getArgument:&Argument2 atIndex:2];
+  [Invocation getArgument:&self->Argument2 atIndex:2];
+
+  [Invocation getReturnValue:&(self->Bar.Field)];
+}
+
+@end
+
+void baz(NSInvocation *Invocatio

[PATCH] D77571: [clang-tidy] Add check to find calls to NSInvocation methods under ARC that don't have proper object argument lifetimes.

2020-04-09 Thread Michael Wyman via Phabricator via cfe-commits
mwyman marked 4 inline comments as done.
mwyman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/objc/NSInvocationArgumentLifetimeCheck.cpp:49
+  QT->getScalarTypeKind() == Type::STK_BlockPointer) &&
+ QT.getQualifiers().getObjCLifetime() > Qualifiers::OCL_ExplicitNone;
+}

stephanemoore wrote:
> I'm not sure but I guess it's okay to assume that the enumeration ordering 
> will remain stable?
I don't know why anyone would change the ordering, but FWIW this is the same 
approach used by the ARC migrator code.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/objc-nsinvocation-argument-lifetime.m:64-69
+- (void)processInvocation:(NSInvocation *)Invocation {
+  [Invocation getArgument:&Argument atIndex:2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation 
'-getArgument:atIndex:' should only pass pointers to objects with ownership 
__unsafe_unretained [objc-nsinvocation-argument-lifetime]
+  [Invocation getArgument:&self->Argument atIndex:2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation 
'-getArgument:atIndex:' should only pass pointers to objects with ownership 
__unsafe_unretained [objc-nsinvocation-argument-lifetime]
+}

stephanemoore wrote:
> stephanemoore wrote:
> > How about a test case where we take the address of something on an ivar?
> > 
> > For example, I think the code below should not produce a diagnostic 
> > finding, right?
> > ```
> > struct Example {
> >   __unsafe_unretained id Field;
> > };
> > 
> > @interface TestClass : NSObject {
> >   struct Example ExampleIvar;
> > }
> > 
> > @end
> > 
> > @implementation TestClass
> > 
> > - (void)processInvocation:(NSInvocation *)Invocation {
> >   [Invocation getArgument:&(self->ExampleIvar.Field) atIndex:2];
> > }
> > 
> > @end
> > ```
> Maybe worth adding an ivar case that doesn't produce a diagnostic?
This required checking MemberRefExprs too. Added both a matching and 
non-matching case here.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/objc-nsinvocation-argument-lifetime.m:64-69
+- (void)processInvocation:(NSInvocation *)Invocation {
+  [Invocation getArgument:&Argument atIndex:2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation 
'-getArgument:atIndex:' should only pass pointers to objects with ownership 
__unsafe_unretained [objc-nsinvocation-argument-lifetime]
+  [Invocation getArgument:&self->Argument atIndex:2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:27: warning: NSInvocation 
'-getArgument:atIndex:' should only pass pointers to objects with ownership 
__unsafe_unretained [objc-nsinvocation-argument-lifetime]
+}

mwyman wrote:
> stephanemoore wrote:
> > stephanemoore wrote:
> > > How about a test case where we take the address of something on an ivar?
> > > 
> > > For example, I think the code below should not produce a diagnostic 
> > > finding, right?
> > > ```
> > > struct Example {
> > >   __unsafe_unretained id Field;
> > > };
> > > 
> > > @interface TestClass : NSObject {
> > >   struct Example ExampleIvar;
> > > }
> > > 
> > > @end
> > > 
> > > @implementation TestClass
> > > 
> > > - (void)processInvocation:(NSInvocation *)Invocation {
> > >   [Invocation getArgument:&(self->ExampleIvar.Field) atIndex:2];
> > > }
> > > 
> > > @end
> > > ```
> > Maybe worth adding an ivar case that doesn't produce a diagnostic?
> This required checking MemberRefExprs too. Added both a matching and 
> non-matching case here.
Added a non-matching ivar case, and in doing so discovered it was often 
actually matching the "self" reference, which is an ImplicitParamDecl, itself a 
type of VarDecl, which matched the declRefExpr(), leading to even cases that 
shouldn't have produced diagnostics to produce them.

Have fixed this by excluding the self case (by ensuring the declRefExpr's 
parent is not an implicitCastExpr, which only appears in the AST that I've seen 
around the self—or other dereferenced object—reference).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77571



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


[PATCH] D77637: [SanitizerCoverage] Add -fsanitize-coverage=inline-bool-flag

2020-04-09 Thread Pratyai Mazumder via Phabricator via cfe-commits
pratyai updated this revision to Diff 256211.
pratyai added a comment.

Was unintentionally enabling the bool-flag coverage in SanitizerArgs.cpp before 
(line#383, `if (Add & SanitizerKind::FuzzerNoLink) { CoverageFeatures |= ... }`

Couldn't catch it before because `cmake -G Ninja ../llvm` didn't generate 
check-fuzzer target for me. Is there any option to enable fuzzer target 
generation?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77637

Files:
  clang/docs/SanitizerCoverage.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/autocomplete.c
  clang/test/Driver/fsanitize-coverage.c

Index: clang/test/Driver/fsanitize-coverage.c
===
--- clang/test/Driver/fsanitize-coverage.c
+++ clang/test/Driver/fsanitize-coverage.c
@@ -105,9 +105,18 @@
 // CHECK_INLINE8BIT-NOT: warning
 // CHECK_INLINE8BIT: -fsanitize-coverage-inline-8bit-counters
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// CHECK_PC_TABLE: -fsanitize-coverage-pc-table
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// CHECK_PC_TABLE_FOR_INLINE8BIT: -fsanitize-coverage-pc-table
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=bb,inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// CHECK_INLINE_BOOL_FLAG-NOT: warning
+// CHECK_INLINE_BOOL_FLAG: -fsanitize-coverage-inline-bool-flag
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// CHECK_PC_TABLE_FOR_INLINEBOOL: -fsanitize-coverage-pc-table
 
 // RUN: %clang_cl --target=i386-pc-win32 -fsanitize=address -fsanitize-coverage=func,trace-pc-guard -c -### -- %s 2>&1 | FileCheck %s -check-prefix=CLANG-CL-COVERAGE
 // CLANG-CL-COVERAGE-NOT: error:
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -54,6 +54,7 @@
 // FNOSANICOVERALL-NEXT: func
 // FNOSANICOVERALL-NEXT: indirect-calls
 // FNOSANICOVERALL-NEXT: inline-8bit-counters
+// FNOSANICOVERALL-NEXT: inline-bool-flag
 // FNOSANICOVERALL-NEXT: no-prune
 // FNOSANICOVERALL-NEXT: trace-bb
 // FNOSANICOVERALL-NEXT: trace-cmp
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1176,6 +1176,8 @@
   Opts.SanitizeCoverageNoPrune = Args.hasArg(OPT_fsanitize_coverage_no_prune);
   Opts.SanitizeCoverageInline8bitCounters =
   Args.hasArg(OPT_fsanitize_coverage_inline_8bit_counters);
+  Opts.SanitizeCoverageInlineBoolFlag =
+  Args.hasArg(OPT_fsanitize_coverage_inline_bool_flag);
   Opts.SanitizeCoveragePCTable = Args.hasArg(OPT_fsanitize_coverage_pc_table);
   Opts.SanitizeCoverageStackDepth =
   Args.hasArg(OPT_fsanitize_coverage_stack_depth);
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -77,17 +77,18 @@
   CoverageBB = 1 << 1,
   CoverageEdge = 1 << 2,
   CoverageIndirCall = 1 << 3,
-  CoverageTraceBB = 1 << 4,  // Deprecated.
+  CoverageTraceBB = 1 << 4, // Deprecated.
   CoverageTraceCmp = 1 << 5,
   CoverageTraceDiv = 1 << 6,
   CoverageTraceGep = 1 << 7,
-  Coverage8bitCounters = 1 << 8,  // Deprecated.
+  Coverage8bitCounters = 1 << 8, // Deprecated.
   CoverageTracePC = 1 << 9,
   CoverageTracePCGuard = 1 << 10,
   CoverageNoPrune = 1 << 11,
   CoverageInline8bitCounters = 1 << 12,
   CoveragePCTable = 1 << 13,
   CoverageStackDepth = 1 << 14,
+  CoverageInlineBoolFlag = 1 << 15,
 };
 
 /// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any
@@ -723,8 +724,9 @

[clang-tools-extra] 340d111 - [clang-tidy] [doc] Fix hicpp-noexcept-move alias links.

2020-04-09 Thread Marek Kurdej via cfe-commits

Author: Marek Kurdej
Date: 2020-04-09T10:48:08+02:00
New Revision: 340d1119eddaa30446853832c3ad1e95c6ff96dc

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

LOG: [clang-tidy] [doc] Fix hicpp-noexcept-move alias links.

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/hicpp-noexcept-move.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/checks/hicpp-noexcept-move.rst 
b/clang-tools-extra/docs/clang-tidy/checks/hicpp-noexcept-move.rst
index 10573eca7fc0..d96be9f8446e 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/hicpp-noexcept-move.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/hicpp-noexcept-move.rst
@@ -1,9 +1,9 @@
 .. title:: clang-tidy - hicpp-noexcept-move
 .. meta::
-   :http-equiv=refresh: 5;URL=misc-noexcept-moveconstructor.html
+   :http-equiv=refresh: 5;URL=performance-noexcept-move-constructor.html
 
 hicpp-noexcept-move
 ===
 
-This check is an alias for `misc-noexcept-moveconstructor 
`_.
+This check is an alias for `performance-noexcept-move-constructor 
`_.
 Checks `rule 12.5.4 
`_
 to mark move assignment and move construction `noexcept`.

diff  --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst 
b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 28a98e828ca0..768e10ef714f 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -404,7 +404,7 @@ Clang-Tidy Checks
`hicpp-new-delete-operators `_, 
`misc-new-delete-overloads `_,
`hicpp-no-array-decay `_, 
`cppcoreguidelines-pro-bounds-array-to-pointer-decay 
`_,
`hicpp-no-malloc `_, `cppcoreguidelines-no-malloc 
`_,
-   `hicpp-noexcept-move `_, 
`misc-noexcept-moveconstructor `_,
+   `hicpp-noexcept-move `_, 
`performance-noexcept-move-constructor 
`_,
`hicpp-special-member-functions `_, 
`cppcoreguidelines-special-member-functions 
`_,
`hicpp-static-assert `_, `misc-static-assert 
`_, "Yes"
`hicpp-undelegated-constructor `_, 
`bugprone-undelegated-constructor `_,



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


[PATCH] D77491: [Sema] Fix incompatible builtin redeclarations in non-global scope

2020-04-09 Thread Raul Tambre via Phabricator via cfe-commits
tambre added a comment.

rsmith: ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77491



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


[PATCH] D77637: [SanitizerCoverage] Add -fsanitize-coverage=inline-bool-flag

2020-04-09 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

In D77637#1971417 , @pratyai wrote:

> Was unintentionally enabling the bool-flag coverage in SanitizerArgs.cpp 
> before (line#383, `if (Add & SanitizerKind::FuzzerNoLink) { CoverageFeatures 
> |= ... }`
>
> Couldn't catch it before because `cmake -G Ninja ../llvm` didn't generate 
> check-fuzzer target for me. Is there any option to enable fuzzer target 
> generation?


i have
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt;lld" 
-DCOMPILER_RT_BUILD_LIBFUZZER=ON
try to check-all as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77637



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


[PATCH] D75665: [analyzer] On-demand parsing capability for CTU

2020-04-09 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 added a comment.

In D75665#1907938 , @martong wrote:

> > As the CTUDir string prefix is only needed in case of the old approach, I 
> > have refactored the external definition mapping storage to NOT include that.
>
> Both `ctu-main.c` and `ctu-on-demand-parsing.c` use the `-analyzer-config 
> ctu-dir=%t/ctudir2` setting. So it is not clear for me why we don't need the 
> prefix. I believe we still need that directory setting otherwise where could 
> we find the externalDefMap file?


You are right, the ctudir2 prefix is not needed as the %t substitution is 
test-file-level unique.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75665



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


[PATCH] D75665: [analyzer] On-demand parsing capability for CTU

2020-04-09 Thread Endre Fülöp via Phabricator via cfe-commits
gamesh411 added a comment.



In D75665#1907914 , @martong wrote:

> The warning below suggests that we parse the ctu-other.c file (and presumably 
> every file) as a C++ file, even if it should be parsed as a C file. Perhaps 
> the invocation of the parser is missing some setting? Also, could this be the 
> reason why on-the-fly and pch driven ctu gives different statistics?
>
>   warning: treating 'c' input as 'c++' when in C++ mode, this behavior is 
> deprecated [-Wdeprecated]
>   
> /mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/clang/test/Analysis/Inputs/ctu-other.c:47:26:
>  error: 'DataType' cannot be defined in a parameter type
>   int structInProto(struct DataType {int a;int b; } * d) {
>^
>   1 error generated.
>   Error while processing 
> /mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/clang/test/Analysis/Inputs/ctu-other.c.
>  
>


I have investigated the issue, and the compiler flags were looked up using the 
heuristic implemented in tooling.
This heuristic looks for the suitable compilation database in an upward 
ascending fashion inside the directory tree startin from the input source file.
By copying both the source file and the compilation database to the test 
directory this heuristic does the right thing now. (up until now the found 
compile_commands.json was the one used for llvm-project itself, and picked up a 
c++ specific compilation).

This issue is solved, however the ASTImporter still cannot import the inline 
definition of the struct, and emits an error.
Right now I am debugging the master branch that uses the AST-dumps wheter I 
also encounter this error inside the ASTImporter (just to see if I am operating 
on sane assumptions).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75665



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


[PATCH] D77637: [SanitizerCoverage] Add -fsanitize-coverage=inline-bool-flag

2020-04-09 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGced398fdc813: [SanitizerCoverage] Add 
-fsanitize-coverage=inline-bool-flag (authored by pratyai, committed by 
vitalybuka).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77637

Files:
  clang/docs/SanitizerCoverage.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/CC1Options.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/Driver/autocomplete.c
  clang/test/Driver/fsanitize-coverage.c

Index: clang/test/Driver/fsanitize-coverage.c
===
--- clang/test/Driver/fsanitize-coverage.c
+++ clang/test/Driver/fsanitize-coverage.c
@@ -105,9 +105,18 @@
 // CHECK_INLINE8BIT-NOT: warning
 // CHECK_INLINE8BIT: -fsanitize-coverage-inline-8bit-counters
 
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE
-// CHECK_PC_TABLE: -fsanitize-coverage-pc-table
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-8bit-counters,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINE8BIT
+// CHECK_PC_TABLE_FOR_INLINE8BIT: -fsanitize-coverage-pc-table
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=bb,inline-bool-flag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_INLINE_BOOL_FLAG
+// CHECK_INLINE_BOOL_FLAG-NOT: warning
+// CHECK_INLINE_BOOL_FLAG: -fsanitize-coverage-inline-bool-flag
+
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=inline-bool-flag,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-coverage=trace-pc-guard,pc-table %s -### 2>&1 | FileCheck %s --check-prefix=CHECK_PC_TABLE_FOR_INLINEBOOL
+// CHECK_PC_TABLE_FOR_INLINEBOOL: -fsanitize-coverage-pc-table
 
 // RUN: %clang_cl --target=i386-pc-win32 -fsanitize=address -fsanitize-coverage=func,trace-pc-guard -c -### -- %s 2>&1 | FileCheck %s -check-prefix=CLANG-CL-COVERAGE
 // CLANG-CL-COVERAGE-NOT: error:
Index: clang/test/Driver/autocomplete.c
===
--- clang/test/Driver/autocomplete.c
+++ clang/test/Driver/autocomplete.c
@@ -54,6 +54,7 @@
 // FNOSANICOVERALL-NEXT: func
 // FNOSANICOVERALL-NEXT: indirect-calls
 // FNOSANICOVERALL-NEXT: inline-8bit-counters
+// FNOSANICOVERALL-NEXT: inline-bool-flag
 // FNOSANICOVERALL-NEXT: no-prune
 // FNOSANICOVERALL-NEXT: trace-bb
 // FNOSANICOVERALL-NEXT: trace-cmp
Index: clang/lib/Frontend/CompilerInvocation.cpp
===
--- clang/lib/Frontend/CompilerInvocation.cpp
+++ clang/lib/Frontend/CompilerInvocation.cpp
@@ -1176,6 +1176,8 @@
   Opts.SanitizeCoverageNoPrune = Args.hasArg(OPT_fsanitize_coverage_no_prune);
   Opts.SanitizeCoverageInline8bitCounters =
   Args.hasArg(OPT_fsanitize_coverage_inline_8bit_counters);
+  Opts.SanitizeCoverageInlineBoolFlag =
+  Args.hasArg(OPT_fsanitize_coverage_inline_bool_flag);
   Opts.SanitizeCoveragePCTable = Args.hasArg(OPT_fsanitize_coverage_pc_table);
   Opts.SanitizeCoverageStackDepth =
   Args.hasArg(OPT_fsanitize_coverage_stack_depth);
Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -77,17 +77,18 @@
   CoverageBB = 1 << 1,
   CoverageEdge = 1 << 2,
   CoverageIndirCall = 1 << 3,
-  CoverageTraceBB = 1 << 4,  // Deprecated.
+  CoverageTraceBB = 1 << 4, // Deprecated.
   CoverageTraceCmp = 1 << 5,
   CoverageTraceDiv = 1 << 6,
   CoverageTraceGep = 1 << 7,
-  Coverage8bitCounters = 1 << 8,  // Deprecated.
+  Coverage8bitCounters = 1 << 8, // Deprecated.
   CoverageTracePC = 1 << 9,
   CoverageTracePCGuard = 1 << 10,
   CoverageNoPrune = 1 << 11,
   CoverageInline8bitCounters = 1 << 12,
   CoveragePCTable = 1 << 13,
   CoverageStackDepth = 1 << 14,
+  CoverageInlineBoolFlag = 1 << 15,
 };
 
 /// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any
@@ -723,8 +724,9 @@
 << "-fsanitize-coverage=trace-pc-guard";
 
   int InsertionPointTypes = CoverageFunc | CoverageBB | CoverageEdge;
-  int InstrumentationTypes =
-  CoverageTracePC

[clang] ced398f - [SanitizerCoverage] Add -fsanitize-coverage=inline-bool-flag

2020-04-09 Thread Vitaly Buka via cfe-commits

Author: Pratyai Mazumder
Date: 2020-04-09T02:40:55-07:00
New Revision: ced398fdc813930bfe88df5252c0f5405af541fc

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

LOG: [SanitizerCoverage] Add -fsanitize-coverage=inline-bool-flag

Reviewers: kcc, vitalybuka

Reviewed By: vitalybuka

Subscribers: cfe-commits, llvm-commits

Tags: #clang

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

Added: 


Modified: 
clang/docs/SanitizerCoverage.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/CC1Options.td
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/Driver/autocomplete.c
clang/test/Driver/fsanitize-coverage.c

Removed: 




diff  --git a/clang/docs/SanitizerCoverage.rst 
b/clang/docs/SanitizerCoverage.rst
index 303152309e1a..fdb07a7d967a 100644
--- a/clang/docs/SanitizerCoverage.rst
+++ b/clang/docs/SanitizerCoverage.rst
@@ -139,6 +139,28 @@ Users need to implement a single function to capture the 
counters at startup.
 // Capture this array in order to read/modify the counters.
   }
 
+
+Inline bool-flag
+
+
+**Experimental, may change or disappear in future**
+
+With ``-fsanitize-coverage=inline-bool-flag`` the compiler will insert
+setting an inline boolean to true on every edge.
+This is similar to ``-fsanitize-coverage=inline-8bit-counter`` but instead of
+an increment of a counter, it just sets a boolean to true.
+
+Users need to implement a single function to capture the flags at startup.
+
+.. code-block:: c++
+
+  extern "C"
+  void __sanitizer_cov_bool_flag_init(bool *start, bool *end) {
+// [start,end) is the array of boolean flags created for the current DSO.
+// Capture this array in order to read/modify the flags.
+  }
+
+
 PC-Table
 
 
@@ -150,8 +172,8 @@ significant binary size overhead. For more information, see
 `Bug 34636 `_.
 
 With ``-fsanitize-coverage=pc-table`` the compiler will create a table of
-instrumented PCs. Requires either ``-fsanitize-coverage=inline-8bit-counters`` 
or
-``-fsanitize-coverage=trace-pc-guard``.
+instrumented PCs. Requires either ``-fsanitize-coverage=inline-8bit-counters``,
+or ``-fsanitize-coverage=inline-bool-flag``, or 
``-fsanitize-coverage=trace-pc-guard``.
 
 Users need to implement a single function to capture the PC table at startup:
 
@@ -164,8 +186,9 @@ Users need to implement a single function to capture the PC 
table at startup:
 // pairs [PC,PCFlags] for every instrumented block in the current DSO.
 // Capture this array in order to read the PCs and their Flags.
 // The number of PCs and PCFlags for a given DSO is the same as the number
-// of 8-bit counters (-fsanitize-coverage=inline-8bit-counters) or
-// trace_pc_guard callbacks (-fsanitize-coverage=trace-pc-guard)
+// of 8-bit counters (-fsanitize-coverage=inline-8bit-counters), or
+// boolean flags (-fsanitize-coverage=inline=bool-flags), or trace_pc_guard
+// callbacks (-fsanitize-coverage=trace-pc-guard).
 // A PCFlags describes the basic block:
 //  * bit0: 1 if the block is the function entry block, 0 otherwise.
   }

diff  --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 0faa013ac497..bc7108edece9 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -232,6 +232,7 @@ CODEGENOPT(SanitizeCoverageTracePC, 1, 0) ///< Enable PC 
tracing
 CODEGENOPT(SanitizeCoverageTracePCGuard, 1, 0) ///< Enable PC tracing with 
guard
///< in sanitizer coverage.
 CODEGENOPT(SanitizeCoverageInline8bitCounters, 1, 0) ///< Use inline 8bit 
counters.
+CODEGENOPT(SanitizeCoverageInlineBoolFlag, 1, 0) ///< Use inline bool flag.
 CODEGENOPT(SanitizeCoveragePCTable, 1, 0) ///< Create a PC Table.
 CODEGENOPT(SanitizeCoverageNoPrune, 1, 0) ///< Disable coverage pruning.
 CODEGENOPT(SanitizeCoverageStackDepth, 1, 0) ///< Enable max stack depth 
tracing

diff  --git a/clang/include/clang/Driver/CC1Options.td 
b/clang/include/clang/Driver/CC1Options.td
index ebefb20c4639..e7912dd27ea6 100644
--- a/clang/include/clang/Driver/CC1Options.td
+++ b/clang/include/clang/Driver/CC1Options.td
@@ -355,6 +355,9 @@ def fsanitize_coverage_8bit_counters
 def fsanitize_coverage_inline_8bit_counters
 : Flag<["-"], "fsanitize-coverage-inline-8bit-counters">,
   HelpText<"Enable inline 8-bit counters in sanitizer coverage">;
+def fsanitize_coverage_inline_bool_flag
+: Flag<["-"], "fsanitize-coverage-inline-bool-flag">,
+  HelpText<"Enable inline boo

[PATCH] D77776: [Driver] Drop support for FreeBSD < 10

2020-04-09 Thread Alexander Richardson via Phabricator via cfe-commits
arichardson added a comment.

Alternatively, the checks could be changed to also handle OSMajorVersion == 0 
and translate that to 10.
This seems to be what NetBSD.cpp does. Darwin.cpp also infers the version from 
the host when running on macos.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D6



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


[PATCH] D76291: [Support] Fix formatted_raw_ostream for UTF-8

2020-04-09 Thread Oliver Stannard (Linaro) via Phabricator via cfe-commits
ostannard added a comment.

Ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76291



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


[PATCH] D76612: [Matrix] Add draft specification for matrix support in Clang.

2020-04-09 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added inline comments.



Comment at: clang/docs/MatrixSupport.rst:254
+
+Example
+===

Hi Florian, just reading this for the first time, this is cool stuff, and just 
a drive-by comment:

this section, Example, looks like a good candidate to be moved to the 
"Matrixes" section in 
clang/docs/LanguageExtensions.rst. This is Clang/LLVM specific, may not be that 
relevant for a language draft spec? But anyway, it may also be some of the 
user-facing examples missing in the language extension doc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76612



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


[PATCH] D77540: [PATCH] [ARM]: Armv8.6-a Matrix Mul Asm and Intrinsics Support

2020-04-09 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D77540#1970034 , @LukeGeeson wrote:

> In D77540#1969873 , @fhahn wrote:
>
> > This patch is quite big and I think it would be easier to review if it 
> > would be split up into distinct clang/llvm parts and maybe NEON/SVE parts 
> > on the LLVM side.
>
>
> That's a good suggestion, I shouldn't have pushed my luck!
>
> Luckily this patch doesn't introduce any new C types or IR types and so the 
> frontend code is light, relatively speaking. That said, there is so little 
> intrinsics work needed here that it might make sense to split the subsequent 
> patches up to include intrinsics out-of-the-box as AArch64 asm+intrinsics, 
> AArch32 asm+intrinsics, AArch64SVE asm + intrinsics etc... instead.
>
> Does that sound ok?


Yeah that sounds good. In particular separating the clang/llvm changes would be 
helpful.


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

https://reviews.llvm.org/D77540



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


[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-09 Thread Vince Bridgers via Phabricator via cfe-commits
vabridgers updated this revision to Diff 256234.
vabridgers added a comment.

Address comment from @balazske


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721

Files:
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/ASTMatchers/ASTMatchersInternal.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -255,6 +255,7 @@
 struct ImportExpr : TestImportBase {};
 struct ImportType : TestImportBase {};
 struct ImportDecl : TestImportBase {};
+struct ImportFixedPointExpr : ImportExpr {};
 
 struct CanonicalRedeclChain : ASTImporterOptionSpecificTestBase {};
 
@@ -527,6 +528,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportFixedPointExpr, ImportFixedPointerLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport("void declToImport() { (void)1.0k; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+  testImport("void declToImport() { (void)0.75r; }", Lang_C, "", Lang_C,
+ Verifier, functionDecl(hasDescendant(fixedPointLiteral(;
+}
+
 TEST_P(ImportExpr, ImportImaginaryLiteralExpr) {
   MatchVerifier Verifier;
   testImport(
@@ -5931,6 +5940,9 @@
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportExpr,
 DefaultTestValuesForRunOptions, );
 
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
+::testing::Values(ArgVector{"-ffixed-point"}), );
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
 DefaultTestValuesForRunOptions, );
 
Index: clang/lib/ASTMatchers/ASTMatchersInternal.cpp
===
--- clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -804,6 +804,8 @@
 integerLiteral;
 const internal::VariadicDynCastAllOfMatcher 
floatLiteral;
 const internal::VariadicDynCastAllOfMatcher 
imaginaryLiteral;
+const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
 const internal::VariadicDynCastAllOfMatcher
 userDefinedLiteral;
 const internal::VariadicDynCastAllOfMatcher
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -588,6 +588,7 @@
 ExpectedStmt VisitIntegerLiteral(IntegerLiteral *E);
 ExpectedStmt VisitFloatingLiteral(FloatingLiteral *E);
 ExpectedStmt VisitImaginaryLiteral(ImaginaryLiteral *E);
+ExpectedStmt VisitFixedPointLiteral(FixedPointLiteral *E);
 ExpectedStmt VisitCharacterLiteral(CharacterLiteral *E);
 ExpectedStmt VisitStringLiteral(StringLiteral *E);
 ExpectedStmt VisitCompoundLiteralExpr(CompoundLiteralExpr *E);
@@ -6503,6 +6504,20 @@
   *ToSubExprOrErr, *ToTypeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitFixedPointLiteral(FixedPointLiteral *E) {
+  auto ToTypeOrErr = import(E->getType());
+  if (!ToTypeOrErr)
+return ToTypeOrErr.takeError();
+
+  ExpectedSLoc ToLocationOrErr = import(E->getLocation());
+  if (!ToLocationOrErr)
+return ToLocationOrErr.takeError();
+
+  return new (Importer.getToContext()) FixedPointLiteral(
+  Importer.getToContext(), E->getValue(), *ToTypeOrErr, *ToLocationOrErr,
+  Importer.getToContext().getFixedPointScale(*ToTypeOrErr));
+}
+
 ExpectedStmt ASTNodeImporter::VisitCharacterLiteral(CharacterLiteral *E) {
   ExpectedType ToTypeOrErr = import(E->getType());
   if (!ToTypeOrErr)
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -2271,6 +2271,10 @@
 extern const internal::VariadicDynCastAllOfMatcher
 imaginaryLiteral;
 
+/// Matches fixed point literals
+extern const internal::VariadicDynCastAllOfMatcher
+fixedPointLiteral;
+
 /// Matches user defined literal operator call.
 ///
 /// Example match: "foo"_suffix


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -255,6 +255,7 @@
 struct ImportExpr : TestImportBase {};
 struct ImportType : TestImportBase {};
 struct ImportDecl : TestImportBase {};
+struct ImportFixedPointExpr : ImportExpr {};
 
 struct CanonicalRedeclChain : ASTImporterOptionSpecificTestBase {};
 
@@ -527,6 +528,14 @@
   floatLiteral(equals(1.0e-5f), hasType(asString("float"));
 }
 
+TEST_P(ImportFixedPointExpr, ImportFixedPointerLiteralExpr) {
+  MatchVerifier Verifier;
+  testImport("void d

[PATCH] D77503: [ASTMatchers] Fixed CastKind being parsed incorrectly for dynamic matchers

2020-04-09 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 256237.
njames93 added a comment.

Fixed up documentation for CastKind matcher.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77503

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
  clang/lib/ASTMatchers/Dynamic/Marshallers.h


Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -170,7 +170,7 @@
 private:
   static Optional getCastKind(llvm::StringRef AttrKind) {
 return llvm::StringSwitch>(AttrKind)
-#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#define CAST_OPERATION(Name) .Case("CK_" #Name, CK_##Name)
 #include "clang/AST/OperationKinds.def"
 .Default(llvm::None);
   }
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -75,11 +75,12 @@
 clang::ast_matchers::dynamic::internal::ArgTypeTraits<
 clang::CastKind>::getBestGuess(const VariantValue &Value) {
   static constexpr llvm::StringRef Allowed[] = {
-#define CAST_OPERATION(Name) #Name,
+#define CAST_OPERATION(Name) "CK_" #Name,
 #include "clang/AST/OperationKinds.def"
   };
   if (Value.isString())
-return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed));
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),
+  "CK_");
   return llvm::None;
 }
 
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4913,7 +4913,7 @@
 /// \endcode
 ///
 /// If the matcher is use from clang-query, CastKind parameter
-/// should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
+/// should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
 AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
   return Node.getCastKind() == Kind;
 }
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -2790,7 +2790,7 @@
   int *p = 0;
 
 If the matcher is use from clang-query, CastKind parameter
-should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
+should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
 
 
 


Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -170,7 +170,7 @@
 private:
   static Optional getCastKind(llvm::StringRef AttrKind) {
 return llvm::StringSwitch>(AttrKind)
-#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#define CAST_OPERATION(Name) .Case("CK_" #Name, CK_##Name)
 #include "clang/AST/OperationKinds.def"
 .Default(llvm::None);
   }
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -75,11 +75,12 @@
 clang::ast_matchers::dynamic::internal::ArgTypeTraits<
 clang::CastKind>::getBestGuess(const VariantValue &Value) {
   static constexpr llvm::StringRef Allowed[] = {
-#define CAST_OPERATION(Name) #Name,
+#define CAST_OPERATION(Name) "CK_" #Name,
 #include "clang/AST/OperationKinds.def"
   };
   if (Value.isString())
-return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed));
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),
+  "CK_");
   return llvm::None;
 }
 
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4913,7 +4913,7 @@
 /// \endcode
 ///
 /// If the matcher is use from clang-query, CastKind parameter
-/// should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
+/// should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
 AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
   return Node.getCastKind() == Kind;
 }
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -2790,7 +2790,7 @@
   int *p = 0;
 
 If the matcher is use from clang-query, CastKind parame

[PATCH] D61716: [libclang] Expose AtomicType

2020-04-09 Thread Jorn Vernee via Phabricator via cfe-commits
JornVernee added a comment.

Would like to try to draw attention to this patch again, since it seems to have 
gone under the radar. Can someone review this/help get it integrated? We are 
still having to work around _Atomic types because we can't get to the 
underlying value type. Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61716



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


[clang] 792b109 - [Driver][X86] Add -mpad-max-prefix-size

2020-04-09 Thread Shengchen Kan via cfe-commits

Author: Shengchen Kan
Date: 2020-04-09T19:34:12+08:00
New Revision: 792b10978dfdd424721fbf0ffd99c35d628f2321

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

LOG: [Driver][X86] Add -mpad-max-prefix-size

Summary:
The option `-mpad-max-prefix-size` performs some checking and delegate to MC 
option `-x86-pad-max-prefix-size`. This option is designed for eliminate NOPs 
when we need to align something by adding redundant prefixes to instructions, 
e.g. it can be used along with `-malign-branch`, `-malign-branch-boundary` to 
prefix padding branch.

It has similar (but slightly different) effect as GAS's option 
`-malign-branch-prefix-size`, e.g. `-mpad-max-prefix-size` can also elminate 
NOPs emitted by align directive, so we use a different name here. I remove the 
option `-malign-branch-prefix-size` since is unimplemented and not needed. If 
we need to be compatible with GAS, we can make `-malign-branch-prefix-size` an 
alias for this option later.

Reviewers: jyknight, reames, MaskRay, craig.topper, LuoYuanke

Reviewed By: MaskRay, LuoYuanke

Subscribers: annita.zhang, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/x86-malign-branch.c
clang/test/Driver/x86-malign-branch.s

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 430e7292757e..a395b680eb88 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2187,7 +2187,8 @@ def malign_branch_EQ : CommaJoined<["-"], 
"malign-branch=">, Group, Fla
   HelpText<"Specify types of branches to align">;
 def malign_branch_boundary_EQ : Joined<["-"], "malign-branch-boundary=">, 
Group, Flags<[DriverOption]>,
   HelpText<"Specify the boundary's size to align branches">;
-def malign_branch_prefix_size_EQ : Joined<["-"], 
"malign-branch-prefix-size=">, Group;
+def mpad_max_prefix_size_EQ : Joined<["-"], "mpad-max-prefix-size=">, 
Group, Flags<[DriverOption]>,
+  HelpText<"Specify maximum number of prefixes to use for padding">;
 def mbranches_within_32B_boundaries : Flag<["-"], 
"mbranches-within-32B-boundaries">, Flags<[DriverOption]>, Group,
   HelpText<"Align selected branches (fused, jcc, jmp) within 32-byte 
boundary">;
 def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, 
Group;

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 2b368131f5cc..5f9b6d813416 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2078,17 +2078,16 @@ static void addX86AlignBranchArgs(const Driver &D, 
const ArgList &Args,
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back(Args.MakeArgString("-x86-align-branch=" + AlignBranch));
   }
-  if (const Arg *A =
-  Args.getLastArg(options::OPT_malign_branch_prefix_size_EQ)) {
+  if (const Arg *A = Args.getLastArg(options::OPT_mpad_max_prefix_size_EQ)) {
 StringRef Value = A->getValue();
 unsigned PrefixSize;
-if (Value.getAsInteger(10, PrefixSize) || PrefixSize > 5) {
+if (Value.getAsInteger(10, PrefixSize)) {
   D.Diag(diag::err_drv_invalid_argument_to_option)
   << Value << A->getOption().getName();
 } else {
   CmdArgs.push_back("-mllvm");
-  CmdArgs.push_back(Args.MakeArgString("-x86-align-branch-prefix-size=" +
-   Twine(PrefixSize)));
+  CmdArgs.push_back(
+  Args.MakeArgString("-x86-pad-max-prefix-size=" + Twine(PrefixSize)));
 }
   }
 }

diff  --git a/clang/test/Driver/x86-malign-branch.c 
b/clang/test/Driver/x86-malign-branch.c
index 6098caf0b5d4..5180eb0a1619 100644
--- a/clang/test/Driver/x86-malign-branch.c
+++ b/clang/test/Driver/x86-malign-branch.c
@@ -18,14 +18,11 @@
 // TYPE-ERR: invalid argument 'foo' to -malign-branch=; each element must be 
one of: fused, jcc, jmp, call, ret, indirect
 // TYPE-ERR: invalid argument 'bar' to -malign-branch=; each element must be 
one of: fused, jcc, jmp, call, ret, indirect
 
-/// Test -malign-branch-prefix-size=
-// RUN: %clang -target x86_64 -malign-branch-prefix-size=0 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-0
-// PREFIX-0: "-mllvm" "-x86-align-branch-prefix-size=0"
-// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-5
-// PREFIX-5: "-mllvm" "-x86-align-branch-prefix-size=5"
-
-// RUN: %clang -target x86_64 -malign-branch-prefix-size=6 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-6
-// PREFIX-6: invalid argument
+/// Test -mpad-max-prefix-size=
+// RUN: %clang -target x86_64 -mpad-max-prefix-size=0 %s -c -### 2>&

[PATCH] D77249: [MSan] Pass command line options to MSan with new pass manager

2020-04-09 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added inline comments.



Comment at: compiler-rt/test/msan/chained_origin_empty_stack_npm.cpp:4
+// this test.
+// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 \
+// RUN: -fexperimental-new-pass-manager -O3 %s -o %t && \

leonardchan wrote:
> nemanjai wrote:
> > nemanjai wrote:
> > > vitalybuka wrote:
> > > > Why not to add RUN: section with -fexperimental-new-pass-manager into 
> > > > original tests?
> > > I just felt that this is a simpler way forward for a couple of reasons:
> > > 1. Once the default switches, it is a very obvious change to just delete 
> > > these files rather than digging through the code inside the existing ones
> > > 2. Many of the tests actually contain the testing that is split up into 
> > > multiple steps so I would have to duplicate all the steps for the NPM vs. 
> > > default builds:
> > > - compile/link
> > > - run with one option set and FileCheck
> > > - run with another option set and FileCheck
> > > - rinse/repeat
> > > (example: chained_origin_limits.cpp)
> > > 
> > > But of course, if there are strong objections to this approach, I can 
> > > certainly go the other way.
> > Seems Phabricator reformatted what I wrote here. Points 3, 4, 5, 6 were 
> > supposed to be sub-bullets for 2.
> > Basically, I tried to describe that in the mentioned test case, I would 
> > have to replicate a number of subsequent steps for each `RUN` directive 
> > that invokes the compiler.
> If we're going this way, I think the original tests should explicitly have 
> `-fno-experimental-new-pass-manager`. Also no strong preference towards 
> either way.
I don't think we should even make changes to the tests in compiler-rt. We 
should write a targeted test in clang/test/CodeGen that ensures these options 
are passed down correctly to the MSan instrumentation pass. It should be easy 
to FileCheck the IR to look for the appropriate instrumentation callbacks. We 
can run that test with the new and old PM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77249



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


[PATCH] D61716: [libclang] Expose AtomicType

2020-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I'm sorry about the delay in review, this did fall off my radar. Thank you for 
bringing it to my attention!

Looks mostly good to me, just a few small nits.




Comment at: clang/include/clang-c/Index.h:3953
+/**
+ * Gets the type contained by this atomic type
+ *

Missing a full stop at the end of the comment.



Comment at: clang/tools/c-index-test/c-index-test.c:1585
+  CXType VT = clang_Type_getValueType(T);
+  if (VT.kind != CXType_Invalid) {
+PrintTypeAndTypeKind(VT, " [valuetype=%s] [valuetypekind=%s]");

Should elide braces here.



Comment at: clang/tools/libclang/CXType.cpp:1326-1329
+  const Type *TP = T.getTypePtrOrNull();
+
+  if (TP && TP->getTypeClass() == Type::Atomic)
+return MakeCXType(cast(TP)->getValueType(), GetTU(CT));

I would probably rewrite this function to:
```
QualType T = GetQualType(CT);
if (T.isNull() || !T->isAtomicType())
  return MakeCXType(QualType(), GetTU(CT));
const auto *AT = T->castAs();
return MakeCXType(AT->getValueType(), GetTU(CT));
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61716



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


[PATCH] D77503: [ASTMatchers] Fixed CastKind being parsed incorrectly for dynamic matchers

2020-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Can you also add some unit tests to the dynamic matcher tests?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77503



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


[PATCH] D76066: [ARM][MachineOutliner] Add Machine Outliner support for ARM

2020-04-09 Thread Yvan Roux via Phabricator via cfe-commits
yroux added inline comments.



Comment at: llvm/lib/Target/ARM/ARMTargetMachine.cpp:553
   addPass(createARMConstantIslandPass());
-  addPass(createARMLowOverheadLoopsPass());
+  if (!MachineOutlinerEnabled)
+addPass(createARMLowOverheadLoopsPass());

samparker wrote:
> yroux wrote:
> > samparker wrote:
> > > We'll need the LowOverheadLoops pass to run for correctness, so we should 
> > > instead only add the MachineOutliner if the subtarget doesn't support LOB.
> > What do you mean by "for correctness" ?
> > 
> > I think that it makes more sense that until MachineOutliner and 
> > LowOverheadLoops can work together, we have loloops enabled on targets 
> > which have LOB support unless it is explicitly disabled by 
> > -disable-arm-loloops flag or if the user wants machine outlining with the 
> > flag -moutline.   If we do that in the opposite way it means that passing 
> > the flag -moutline will have no impact on such targets unless the 
> > -disable-arm-loloops flag is used
> > 
> Ok. Well, the HardwareLoops pass inserts intrinsics, which are lowered to 
> pseudos and then finalised by ARMLowOverheadLoops so the compiler could crash 
> with this logic. TTI controls whether we generate a low-overhead loop and it 
> also controls whether the vectorizer tries to optimise for those loops too... 
> So, I think TTI will need to understand when we're trying to use the outliner 
> too.
Ah Ok thanks, I'll try to find how to add that info into TTI


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76066



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


[PATCH] D77628: [Driver][X86] Add -mpad-max-prefix-size

2020-04-09 Thread Kan Shengchen via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG792b10978dfd: [Driver][X86] Add -mpad-max-prefix-size 
(authored by skan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77628

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/x86-malign-branch.c
  clang/test/Driver/x86-malign-branch.s


Index: clang/test/Driver/x86-malign-branch.s
===
--- clang/test/Driver/x86-malign-branch.s
+++ clang/test/Driver/x86-malign-branch.s
@@ -6,8 +6,8 @@
 // RUN: %clang -target x86_64 -malign-branch=fused,jcc,jmp %s -c -### %s 2>&1 
| FileCheck %s --check-prefix=TYPE
 // TYPE: "-mllvm" "-x86-align-branch=fused+jcc+jmp"
 
-// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX
-// PREFIX: "-mllvm" "-x86-align-branch-prefix-size=5"
+// RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX
+// PREFIX: "-mllvm" "-x86-pad-max-prefix-size=5"
 
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 
| FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/test/Driver/x86-malign-branch.c
===
--- clang/test/Driver/x86-malign-branch.c
+++ clang/test/Driver/x86-malign-branch.c
@@ -18,14 +18,11 @@
 // TYPE-ERR: invalid argument 'foo' to -malign-branch=; each element must be 
one of: fused, jcc, jmp, call, ret, indirect
 // TYPE-ERR: invalid argument 'bar' to -malign-branch=; each element must be 
one of: fused, jcc, jmp, call, ret, indirect
 
-/// Test -malign-branch-prefix-size=
-// RUN: %clang -target x86_64 -malign-branch-prefix-size=0 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-0
-// PREFIX-0: "-mllvm" "-x86-align-branch-prefix-size=0"
-// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-5
-// PREFIX-5: "-mllvm" "-x86-align-branch-prefix-size=5"
-
-// RUN: %clang -target x86_64 -malign-branch-prefix-size=6 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-6
-// PREFIX-6: invalid argument
+/// Test -mpad-max-prefix-size=
+// RUN: %clang -target x86_64 -mpad-max-prefix-size=0 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-0
+// PREFIX-0: "-mllvm" "-x86-pad-max-prefix-size=0"
+// RUN: %clang -target x86_64 -mpad-max-prefix-size=15 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-15
+// PREFIX-15: "-mllvm" "-x86-pad-max-prefix-size=15"
 
 /// Test -mbranches-within-32B-boundaries
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 
| FileCheck %s --check-prefix=32B
@@ -34,6 +31,6 @@
 /// Unsupported on other targets.
 // RUN: %clang -target aarch64 -malign-branch=jmp %s -c -### 2>&1 | FileCheck 
--check-prefix=UNUSED %s
 // RUN: %clang -target aarch64 -malign-branch-boundary=7 %s -c -### 2>&1 | 
FileCheck --check-prefix=UNUSED %s
-// RUN: %clang -target aarch64 -malign-branch-prefix-size=15 %s -c -### 2>&1 | 
FileCheck --check-prefix=UNUSED %s
+// RUN: %clang -target aarch64 -mpad-max-prefix-size=15 %s -c -### 2>&1 | 
FileCheck --check-prefix=UNUSED %s
 // RUN: %clang -target aarch64 -mbranches-within-32B-boundaries %s -c -### 
2>&1 | FileCheck --check-prefix=UNUSED %s
 // UNUSED: warning: argument unused
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2078,17 +2078,16 @@
 CmdArgs.push_back("-mllvm");
 CmdArgs.push_back(Args.MakeArgString("-x86-align-branch=" + AlignBranch));
   }
-  if (const Arg *A =
-  Args.getLastArg(options::OPT_malign_branch_prefix_size_EQ)) {
+  if (const Arg *A = Args.getLastArg(options::OPT_mpad_max_prefix_size_EQ)) {
 StringRef Value = A->getValue();
 unsigned PrefixSize;
-if (Value.getAsInteger(10, PrefixSize) || PrefixSize > 5) {
+if (Value.getAsInteger(10, PrefixSize)) {
   D.Diag(diag::err_drv_invalid_argument_to_option)
   << Value << A->getOption().getName();
 } else {
   CmdArgs.push_back("-mllvm");
-  CmdArgs.push_back(Args.MakeArgString("-x86-align-branch-prefix-size=" +
-   Twine(PrefixSize)));
+  CmdArgs.push_back(
+  Args.MakeArgString("-x86-pad-max-prefix-size=" + Twine(PrefixSize)));
 }
   }
 }
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2187,7 +2187,8 @@
   HelpText<"Specify types of branches to align">;
 def malign_branch_boundary_EQ : Joined<["-"], "malign-branch-boundary=">, 
Group,

[PATCH] D77791: [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher

2020-04-09 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: klimek, aaron.ballman.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Adds support for using the ofKind in clang-query and other dynamic matcher use 
cases


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77791

Files:
  clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -95,9 +95,6 @@
 RegistryMaps::RegistryMaps() {
   // TODO: Here is the list of the missing matchers, grouped by reason.
   //
-  // Need Variant/Parser fixes:
-  // ofKind
-  //
   // Polymorphic + argument overload:
   // findAll
   //
@@ -458,6 +455,7 @@
   REGISTER_MATCHER(objcThrowStmt);
   REGISTER_MATCHER(objcTryStmt);
   REGISTER_MATCHER(ofClass);
+  REGISTER_MATCHER(ofKind);
   REGISTER_MATCHER(ompDefaultClause);
   REGISTER_MATCHER(ompExecutableDirective);
   REGISTER_MATCHER(on);
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -27,6 +27,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/OpenMPKinds.h"
+#include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
@@ -214,6 +215,34 @@
   static llvm::Optional getBestGuess(const VariantValue &Value);
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static Optional
+  getUnaryOrTypeTraitKind(llvm::StringRef ClauseKind) {
+// FIXME: Typetraits should probably be in a `.def` to make less error 
prone
+return llvm::StringSwitch>(ClauseKind)
+.Case("UETT_SizeOf", UETT_SizeOf)
+.Case("UETT_AlignOf", UETT_AlignOf)
+.Case("UETT_VecStep", UETT_VecStep)
+.Case("UETT_OpenMPRequiredSimdAlign", UETT_OpenMPRequiredSimdAlign)
+.Case("UETT_PreferredAlignOf", UETT_PreferredAlignOf)
+.Default(llvm::None);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() && getUnaryOrTypeTraitKind(Value.getString());
+  }
+
+  static UnaryExprOrTypeTrait get(const VariantValue &Value) {
+return *getUnaryOrTypeTraitKind(Value.getString());
+  }
+
+  static ArgKind getKind() { return ArgKind(ArgKind::AK_String); }
+
+  static llvm::Optional getBestGuess(const VariantValue &Value);
+};
+
 /// Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -95,3 +95,18 @@
   "OMPC_");
   return llvm::None;
 }
+
+llvm::Optional
+clang::ast_matchers::dynamic::internal::ArgTypeTraits<
+clang::UnaryExprOrTypeTrait>::getBestGuess(const VariantValue &Value) {
+  static constexpr llvm::StringRef Allowed[] = {
+  "UETT_SizeOf",   "UETT_AlignOf",
+  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
+  "UETT_PreferredAlignOf",
+  };
+  if (Value.isString()) {
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),
+  "UETT_");
+  }
+  return llvm::None;
+}


Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -95,9 +95,6 @@
 RegistryMaps::RegistryMaps() {
   // TODO: Here is the list of the missing matchers, grouped by reason.
   //
-  // Need Variant/Parser fixes:
-  // ofKind
-  //
   // Polymorphic + argument overload:
   // findAll
   //
@@ -458,6 +455,7 @@
   REGISTER_MATCHER(objcThrowStmt);
   REGISTER_MATCHER(objcTryStmt);
   REGISTER_MATCHER(ofClass);
+  REGISTER_MATCHER(ofKind);
   REGISTER_MATCHER(ompDefaultClause);
   REGISTER_MATCHER(ompExecutableDirective);
   REGISTER_MATCHER(on);
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -27,6 +27,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/OpenMPKinds.h"
+#include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
@@ -214,6 +215,34 @@
   static llvm::Optional getBestGuess(const VariantValue &Value);
 };
 
+template <> struct ArgTypeTraits {
+private:
+ 

[PATCH] D77728: [Driver][X86] Add an alias for -mpad-max-prefix-size

2020-04-09 Thread Kan Shengchen via Phabricator via cfe-commits
skan updated this revision to Diff 256250.
skan added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77728

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/x86-malign-branch.c
  clang/test/Driver/x86-malign-branch.s


Index: clang/test/Driver/x86-malign-branch.s
===
--- clang/test/Driver/x86-malign-branch.s
+++ clang/test/Driver/x86-malign-branch.s
@@ -9,5 +9,7 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX
 // PREFIX: "-mllvm" "-x86-pad-max-prefix-size=5"
 
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX
+
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 
| FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/test/Driver/x86-malign-branch.c
===
--- clang/test/Driver/x86-malign-branch.c
+++ clang/test/Driver/x86-malign-branch.c
@@ -27,6 +27,9 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=6 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-6
 // PREFIX-6: invalid argument
 
+/// Test -malign-branch-prefix-size= for GCC compatibilty
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-5
+
 /// Test -mbranches-within-32B-boundaries
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 
| FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2189,6 +2189,8 @@
   HelpText<"Specify the boundary's size to align branches">;
 def mpad_max_prefix_size_EQ : Joined<["-"], "mpad-max-prefix-size=">, 
Group, Flags<[DriverOption]>,
   HelpText<"Specify maximum number of prefixes to use for padding">;
+def malign_branch_prefix_size_EQ : Joined<["-"], 
"malign-branch-prefix-size=">, Group, 
Flags<[DriverOption]>,Alias,
+  HelpText<"Alias for -mpad-max-prefix-size">;// Alias for GCC compatibility
 def mbranches_within_32B_boundaries : Flag<["-"], 
"mbranches-within-32B-boundaries">, Flags<[DriverOption]>, Group,
   HelpText<"Align selected branches (fused, jcc, jmp) within 32-byte 
boundary">;
 def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, 
Group;


Index: clang/test/Driver/x86-malign-branch.s
===
--- clang/test/Driver/x86-malign-branch.s
+++ clang/test/Driver/x86-malign-branch.s
@@ -9,5 +9,7 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX
 // PREFIX: "-mllvm" "-x86-pad-max-prefix-size=5"
 
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX
+
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/test/Driver/x86-malign-branch.c
===
--- clang/test/Driver/x86-malign-branch.c
+++ clang/test/Driver/x86-malign-branch.c
@@ -27,6 +27,9 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=6 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-6
 // PREFIX-6: invalid argument
 
+/// Test -malign-branch-prefix-size= for GCC compatibilty
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-5
+
 /// Test -mbranches-within-32B-boundaries
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2189,6 +2189,8 @@
   HelpText<"Specify the boundary's size to align branches">;
 def mpad_max_prefix_size_EQ : Joined<["-"], "mpad-max-prefix-size=">, Group, Flags<[DriverOption]>,
   HelpText<"Specify maximum number of prefixes to use for padding">;
+def malign_branch_prefix_size_EQ : Joined<["-"], "malign-branch-prefix-size=">, Group, Flags<[DriverOption]>,Alias,
+  HelpText<"Alias for -mpad-max-prefix-size">;// Alias for GCC compatibility
 def mbranches_within_32B_boundaries : Flag<["-"], "mbranches-within-32B-boundaries">, Flags<[DriverOption]>, Group,
   HelpText<"Align selected branches (fused, jcc, jmp) within 32-byte boundary">;
 def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, Group;
_

[PATCH] D77791: [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher

2020-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Thank you for this! It basically LG, but can you also add a dynamic matcher 
unit test for this functionality?




Comment at: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp:102-106
+  static constexpr llvm::StringRef Allowed[] = {
+  "UETT_SizeOf",   "UETT_AlignOf",
+  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
+  "UETT_PreferredAlignOf",
+  };

Did clang-format produce this formatting?



Comment at: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp:107
+  };
+  if (Value.isString()) {
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),

Elide braces



Comment at: clang/lib/ASTMatchers/Dynamic/Marshallers.h:222
+  getUnaryOrTypeTraitKind(llvm::StringRef ClauseKind) {
+// FIXME: Typetraits should probably be in a `.def` to make less error 
prone
+return llvm::StringSwitch>(ClauseKind)

Typetraits - > Type traits
Also, missing a full stop at the end of the comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77791



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


[PATCH] D77792: [analyzer] Extend constraint manager to be able to compare simple SymSymExprs

2020-04-09 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, baloghadamsoftware, Charusso, Szelethus.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, dkrupp, 
donat.nagy, mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun, whisperity.
Herald added a project: clang.

This patch extends the constraint manager to be able to reason about trivial 
sym-sym comparisons.

We all know that `a < b` if the maximum value of `a` is still less than the 
minimum value of `b`.
This reasoning can be applied for the <,<=,>,>= relation operators.
This patch solely implements this functionality.

This patch does not address transitity like:
If `a < b` and `b < c` than `a < c`.

This patch is necessary to be able to express //hidden function preconditions//.
For example, with the `D69726` we could express the connection between the 
extent size of `src` and the size (`n`) parameter of the function.

  #define ANALYZER_ASSERT assert
  
  void my_memcpy(char *dst, char *src, int n) {
ANALYZER_ASSERT(clang_analyzer_getExtent(src) >= n)
ANALYZER_ASSERT(clang_analyzer_getExtent(dst) >= n)

for (int i = 0; i < n; ++i) {
  // The extent of dst would be compared to the index i.
  dst[i] = src[i]; // each memory access in-bound, no-warning
}
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77792

Files:
  
clang/include/clang/StaticAnalyzer/Core/PathSensitive/RangedConstraintManager.h
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/lib/StaticAnalyzer/Core/RangedConstraintManager.cpp
  clang/test/Analysis/constraint-manager-sym-sym.c

Index: clang/test/Analysis/constraint-manager-sym-sym.c
===
--- /dev/null
+++ clang/test/Analysis/constraint-manager-sym-sym.c
@@ -0,0 +1,172 @@
+// RUN: %clang_analyze_cc1 -verify -analyzer-checker=core,debug.ExprInspection \
+// RUN:   -analyzer-config eagerly-assume=false %s
+
+
+void clang_analyzer_eval(int);
+
+extern void __assert_fail(__const char *__assertion, __const char *__file,
+  unsigned int __line, __const char *__function)
+__attribute__((__noreturn__));
+#define assert(expr) \
+  ((expr) ? (void)(0) : __assert_fail(#expr, __FILE__, __LINE__, __func__))
+
+
+// Given [a1,a2] and [b1,b2] intervals.
+// Pin the [b1,b2] interval to eg. [5,10]
+// Choose the a1,a2 points from 0,2,5,7,10,12 where a1 < a2.
+// There will be 5+4+3+2+1 cases.
+
+// [0,2] and [5,10]
+void test_range1(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 2);
+  clang_analyzer_eval(l <  r); // expected-warning{{TRUE}}
+  clang_analyzer_eval(l <= r); // expected-warning{{TRUE}}
+  clang_analyzer_eval(l >  r); // expected-warning{{FALSE}}
+  clang_analyzer_eval(l >= r); // expected-warning{{FALSE}}
+}
+
+// [0,5] and [5,10]
+void test_range2(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 5);
+  clang_analyzer_eval(l <  r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{TRUE}}
+  clang_analyzer_eval(l >  r); // expected-warning{{FALSE}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [0,7] and [5,10]
+void test_range3(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 7);
+  clang_analyzer_eval(l <  r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >  r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [0,10] and [5,10]
+void test_range4(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 10);
+  clang_analyzer_eval(l <  r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >  r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [0,12] and [5,10]
+void test_range5(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(0 <= l && l <= 12);
+  clang_analyzer_eval(l <  r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >  r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+
+// [2,5] and [5,10]
+void test_range6(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(2 <= l && l <= 5);
+  clang_analyzer_eval(l <  r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{TRUE}}
+  clang_analyzer_eval(l >  r); // expected-warning{{FALSE}}
+  clang_analyzer_eval(l >= r); // expected-warning{{UNKNOWN}}
+}
+
+// [2,7] and [5,10]
+void test_range7(int l, int r) {
+  assert(5 <= r && r <= 10);
+  assert(2 <= l && l <= 7);
+  clang_analyzer_eval(l <  r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l <= r); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(l >  r); // expected-warning{{UNKNOWN}}
+  clang

[PATCH] D77477: tsan: don't instrument __attribute__((naked)) functions

2020-04-09 Thread Anton Bikineev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9e1ccec8d529: tsan: don't instrument 
__attribute__((naked)) functions (authored by AntonBikineev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77477

Files:
  llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
  llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll


Index: llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
===
--- llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
+++ llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
@@ -78,5 +78,18 @@
   call void @SwiftError(i8** %0)
   ret void
 }
+
+; CHECK-LABEL: @NakedTest(i32* %a)
+; CHECK-NEXT:   call void @foo()
+; CHECK-NEXT:   %tmp1 = load i32, i32* %a, align 4
+; CHECK-NEXT:   ret i32 %tmp1
+define i32 @NakedTest(i32* %a) naked sanitize_thread {
+  call void @foo()
+  %tmp1 = load i32, i32* %a, align 4
+  ret i32 %tmp1
+}
+
+declare void @foo() nounwind
+
 ; CHECK: define internal void @tsan.module_ctor()
 ; CHECK: call void @__tsan_init()
Index: llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -441,6 +441,11 @@
   // the module constructor.
   if (F.getName() == kTsanModuleCtorName)
 return false;
+  // Naked functions can not have prologue/epilogue
+  // (__tsan_func_entry/__tsan_func_exit) generated, so don't instrument them 
at
+  // all.
+  if (F.hasFnAttribute(Attribute::Naked))
+return false;
   initialize(*F.getParent());
   SmallVector AllLoadsAndStores;
   SmallVector LocalLoadsAndStores;


Index: llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
===
--- llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
+++ llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
@@ -78,5 +78,18 @@
   call void @SwiftError(i8** %0)
   ret void
 }
+
+; CHECK-LABEL: @NakedTest(i32* %a)
+; CHECK-NEXT:   call void @foo()
+; CHECK-NEXT:   %tmp1 = load i32, i32* %a, align 4
+; CHECK-NEXT:   ret i32 %tmp1
+define i32 @NakedTest(i32* %a) naked sanitize_thread {
+  call void @foo()
+  %tmp1 = load i32, i32* %a, align 4
+  ret i32 %tmp1
+}
+
+declare void @foo() nounwind
+
 ; CHECK: define internal void @tsan.module_ctor()
 ; CHECK: call void @__tsan_init()
Index: llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
===
--- llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -441,6 +441,11 @@
   // the module constructor.
   if (F.getName() == kTsanModuleCtorName)
 return false;
+  // Naked functions can not have prologue/epilogue
+  // (__tsan_func_entry/__tsan_func_exit) generated, so don't instrument them at
+  // all.
+  if (F.hasFnAttribute(Attribute::Naked))
+return false;
   initialize(*F.getParent());
   SmallVector AllLoadsAndStores;
   SmallVector LocalLoadsAndStores;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D75591: [OpenMP] Add firstprivate as a default data-sharing attribute to clang

2020-04-09 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1125
+DVar.CKind = OMPC_firstprivate;
+DVar.PrivateCopy = nullptr;
+return DVar;

Need to add `DVar.ImplicitDSALoc = Iter->DefaultAttrLoc;` 



Comment at: clang/lib/Sema/SemaOpenMP.cpp:3211-3213
+  VD->getStorageClass() == SC_Static &&
+  (CanonicalVD->getDeclContext()->isNamespace() ||
+   !VD->isLocalVarDeclOrParm())) {

I think just `!VD->hasLocalStorage()` should be enough here. Shall it work for 
static locals too or just for globals?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:12616-12621
   if (Kind == OMP_DEFAULT_none)
 DSAStack->setDefaultDSANone(KindKwLoc);
   else if (Kind == OMP_DEFAULT_shared)
 DSAStack->setDefaultDSAShared(KindKwLoc);
+  else if (Kind == OMP_DEFAULT_firstprivate)
+DSAStack->setDefaultDSAFirstPrivate(KindKwLoc);

Better to turn it to `switch`



Comment at: clang/test/OpenMP/parallel_master_codegen.cpp:145
+
+// CK31:   define internal {{.*}}void [[OMP_OUTLINED]](i32* noalias 
[[GTID:%.+]], i32* noalias [[BTID:%.+]], i32* dereferenceable(4) [[A_VAL]])
+// CK31:   [[GTID_ADDR:%.+]] = alloca i32*

Some extra work is required. The variable should not be captured by reference, 
must be captured by value. Also, a test with calling constructors/destructors 
is required.



Comment at: clang/test/OpenMP/parallel_master_codegen.cpp:149
+// CK31:   [[A_ADDR:%.+]] = alloca i32*
+// CK31:   [[A_VAL]]1 = alloca i32, align 4
+// CK31:   store i32* [[GTID]], i32** [[GTID_ADDR]]

This check may not work in some cases, better to rework it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75591



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


[PATCH] D77477: tsan: don't instrument __attribute__((naked)) functions

2020-04-09 Thread Anton Bikineev via Phabricator via cfe-commits
AntonBikineev added a comment.

Thanks for taking a look!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77477



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


[PATCH] D77791: [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher

2020-04-09 Thread Nathan James via Phabricator via cfe-commits
njames93 added inline comments.



Comment at: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp:102-106
+  static constexpr llvm::StringRef Allowed[] = {
+  "UETT_SizeOf",   "UETT_AlignOf",
+  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
+  "UETT_PreferredAlignOf",
+  };

aaron.ballman wrote:
> Did clang-format produce this formatting?
when I ran git-clang-format I dont think it did, but when i went to upload the 
patch i got this in the pre-upload linting
```
--- /home/nathan/src/llvm-project/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp 
2020-04-09 12:12:28.810339833 +0100
+++ /tmp/6p7zxlltj4g8wgcc/9888-onMes8   2020-04-09 12:44:11.187257096 +0100
@@ -99,11 +99,11 @@
 llvm::Optional
 clang::ast_matchers::dynamic::internal::ArgTypeTraits<
 clang::UnaryExprOrTypeTrait>::getBestGuess(const VariantValue &Value) {
-  static constexpr llvm::StringRef Allowed[] = {"UETT_SizeOf",
-"UETT_AlignOf",
-"UETT_VecStep",
-"UETT_OpenMPRequiredSimdAlign",
-"UETT_PreferredAlignOf",};
+  static constexpr llvm::StringRef Allowed[] = {
+  "UETT_SizeOf",   "UETT_AlignOf",
+  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
+  "UETT_PreferredAlignOf",
+  };
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77791



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


[PATCH] D77794: [clangd] Pull installed gRPC and introduce shared-index-(server|client)

2020-04-09 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev created this revision.
kbobyrev added a reviewer: sammccall.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous, 
MaskRay, ilya-biryukov, mgorny.
Herald added a project: clang.
kbobyrev updated this revision to Diff 256263.
kbobyrev added a comment.

Rebase on top of the correct revision


This patch allows using installed gRPC to build two simple tools which
currently provide the functionality of looking up the symbol by name.
shared-index-client is a simplified version of dexp which connects to
shared-index-server passes lookup requests.

This patch still needs a couple of cleanups and fixes:

- For some reason currently only some names are successfully looked up (e.g.) 
namespaces) while some classes can not be discovered. I will investigate it and 
update the patch with a fix.
- LLVM's custom CMake error breaks build saying some source files are not used 
even each is used within its target. For now, I just commented out the code 
producing the error but this needs to be addressed in this patch.
- It is very hard to move the Protobuf generation CMake code from the inner 
directory above. This is probably OK for this patch, but whenever the generated 
files will be used outside of these two tools, this needs to be fixed.

I also significantly reduced the scope of this patch to prevent large changelist
and more bugs. The next steps would be:

- Extending Protocol for deep copies of Symbol and inherit SharedIndex from 
Index to unify the interfaces
- Make shareed-index-server more generic and merge the shared index client with 
dexp
- Modify Clangd to allow using shared index instead of the local one for all 
global index requests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77794

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/shared/CMakeLists.txt
  clang-tools-extra/clangd/index/shared/SharedIndex.proto
  clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp
  clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
  llvm/cmake/modules/LLVMProcessSources.cmake

Index: llvm/cmake/modules/LLVMProcessSources.cmake
===
--- llvm/cmake/modules/LLVMProcessSources.cmake
+++ llvm/cmake/modules/LLVMProcessSources.cmake
@@ -109,8 +109,8 @@
   else()
   set(fn_relative "${fn}")
   endif()
-  message(SEND_ERROR "Found unknown source file ${fn_relative}
-Please update ${CMAKE_CURRENT_LIST_FILE}\n")
+#   message(SEND_ERROR "Found unknown source file ${fn_relative}
+# Please update ${CMAKE_CURRENT_LIST_FILE}\n")
 endif()
   endif()
 endif()
Index: clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
@@ -0,0 +1,123 @@
+//===--- SharedIndexServer.cpp - gRPC-based Shared Index Server  --===//
+//
+// 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 "index/Index.h"
+#include "index/Serialization.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+
+#include "grpcpp/grpcpp.h"
+
+#include "SharedIndex.grpc.pb.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+static const std::string Overview = R"(
+This is an experimental shared index implementation. The server opens Dex and
+awaits gRPC lookup requests from the client.
+)";
+
+llvm::cl::opt IndexPath(llvm::cl::desc("[PATH TO INDEX]"),
+ llvm::cl::Positional, llvm::cl::Required);
+
+llvm::cl::opt ServerAddress("server-address",
+ llvm::cl::init("0.0.0.0:50051"));
+
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*UseIndex=*/true);
+}
+
+// FIXME(kbobyrev): This is copied
+std::vector getSymbolIDsFromIndex(llvm::StringRef QualifiedName,
+const SymbolIndex *Index) {
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {std::string(Names.first)};
+  else
+// QualifiedName refers to a symbol in global scope (e.g. "GlobalSymbol"),
+// add the global scope to the request.
+Reque

[PATCH] D77791: [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher

2020-04-09 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 256262.
njames93 marked 4 inline comments as done.
njames93 added a comment.

Added test cases and address nits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77791

Files:
  clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -242,6 +242,14 @@
   EXPECT_TRUE(matches("void f(int a, int x);", M));
   EXPECT_FALSE(matches("void f(int x, int a);", M));
 
+  Code = "unaryExprOrTypeTraitExpr(ofKind(\"UETT_SizeOf\"))";
+  llvm::Optional UnaryExprSizeOf(
+  Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error));
+  EXPECT_EQ("", Error.toStringFull());
+  Matcher MStmt = UnaryExprSizeOf->unconditionalConvertTo();
+  EXPECT_TRUE(matches("unsigned X = sizeof(int);", MStmt));
+  EXPECT_FALSE(matches("unsigned X = alignof(int);", MStmt));
+
   Code = "hasInitializer(\nbinaryOperator(hasLHS(\"A\")))";
   EXPECT_TRUE(!Parser::parseMatcherExpression(Code, &Error).hasValue());
   EXPECT_EQ("1:1: Error parsing argument 1 for matcher hasInitializer.\n"
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -95,9 +95,6 @@
 RegistryMaps::RegistryMaps() {
   // TODO: Here is the list of the missing matchers, grouped by reason.
   //
-  // Need Variant/Parser fixes:
-  // ofKind
-  //
   // Polymorphic + argument overload:
   // findAll
   //
@@ -458,6 +455,7 @@
   REGISTER_MATCHER(objcThrowStmt);
   REGISTER_MATCHER(objcTryStmt);
   REGISTER_MATCHER(ofClass);
+  REGISTER_MATCHER(ofKind);
   REGISTER_MATCHER(ompDefaultClause);
   REGISTER_MATCHER(ompExecutableDirective);
   REGISTER_MATCHER(on);
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -27,6 +27,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/OpenMPKinds.h"
+#include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
@@ -214,6 +215,35 @@
   static llvm::Optional getBestGuess(const VariantValue &Value);
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static Optional
+  getUnaryOrTypeTraitKind(llvm::StringRef ClauseKind) {
+// FIXME: Type traits should probably be in a `.def` to make less error
+// prone.
+return llvm::StringSwitch>(ClauseKind)
+.Case("UETT_SizeOf", UETT_SizeOf)
+.Case("UETT_AlignOf", UETT_AlignOf)
+.Case("UETT_VecStep", UETT_VecStep)
+.Case("UETT_OpenMPRequiredSimdAlign", UETT_OpenMPRequiredSimdAlign)
+.Case("UETT_PreferredAlignOf", UETT_PreferredAlignOf)
+.Default(llvm::None);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() && getUnaryOrTypeTraitKind(Value.getString());
+  }
+
+  static UnaryExprOrTypeTrait get(const VariantValue &Value) {
+return *getUnaryOrTypeTraitKind(Value.getString());
+  }
+
+  static ArgKind getKind() { return ArgKind(ArgKind::AK_String); }
+
+  static llvm::Optional getBestGuess(const VariantValue &Value);
+};
+
 /// Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -95,3 +95,17 @@
   "OMPC_");
   return llvm::None;
 }
+
+llvm::Optional
+clang::ast_matchers::dynamic::internal::ArgTypeTraits<
+clang::UnaryExprOrTypeTrait>::getBestGuess(const VariantValue &Value) {
+  static constexpr llvm::StringRef Allowed[] = {
+  "UETT_SizeOf",   "UETT_AlignOf",
+  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
+  "UETT_PreferredAlignOf",
+  };
+  if (Value.isString())
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),
+  "UETT_");
+  return llvm::None;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77794: [clangd] Pull installed gRPC and introduce shared-index-(server|client)

2020-04-09 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 256263.
kbobyrev added a comment.

Rebase on top of the correct revision


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/shared/CMakeLists.txt
  clang-tools-extra/clangd/index/shared/SharedIndex.proto
  clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp
  clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
  llvm/cmake/modules/LLVMProcessSources.cmake

Index: llvm/cmake/modules/LLVMProcessSources.cmake
===
--- llvm/cmake/modules/LLVMProcessSources.cmake
+++ llvm/cmake/modules/LLVMProcessSources.cmake
@@ -109,8 +109,8 @@
   else()
   set(fn_relative "${fn}")
   endif()
-  message(SEND_ERROR "Found unknown source file ${fn_relative}
-Please update ${CMAKE_CURRENT_LIST_FILE}\n")
+#   message(SEND_ERROR "Found unknown source file ${fn_relative}
+# Please update ${CMAKE_CURRENT_LIST_FILE}\n")
 endif()
   endif()
 endif()
Index: clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
@@ -0,0 +1,123 @@
+//===--- SharedIndexServer.cpp - gRPC-based Shared Index Server  --===//
+//
+// 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 "index/Index.h"
+#include "index/Serialization.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+
+#include "grpcpp/grpcpp.h"
+
+#include "SharedIndex.grpc.pb.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+static const std::string Overview = R"(
+This is an experimental shared index implementation. The server opens Dex and
+awaits gRPC lookup requests from the client.
+)";
+
+llvm::cl::opt IndexPath(llvm::cl::desc("[PATH TO INDEX]"),
+ llvm::cl::Positional, llvm::cl::Required);
+
+llvm::cl::opt ServerAddress("server-address",
+ llvm::cl::init("0.0.0.0:50051"));
+
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*UseIndex=*/true);
+}
+
+// FIXME(kbobyrev): This is copied
+std::vector getSymbolIDsFromIndex(llvm::StringRef QualifiedName,
+const SymbolIndex *Index) {
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {std::string(Names.first)};
+  else
+// QualifiedName refers to a symbol in global scope (e.g. "GlobalSymbol"),
+// add the global scope to the request.
+Request.Scopes = {""};
+
+  Request.Query = std::string(Names.second);
+  std::vector SymIDs;
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
+class SharedIndexServer final : public SharedIndex::Service {
+public:
+  SharedIndexServer(std::unique_ptr Index)
+  : Index(std::move(Index)) {}
+
+private:
+  grpc::Status requestLookup(grpc::ServerContext *Context,
+ const LookupRequestProto *Request,
+ grpc::ServerWriter *Reply) override {
+llvm::outs() << "Lookup of symbol with ID " << Request->name() << '\n';
+LookupRequest Req;
+for (const auto &ID : getSymbolIDsFromIndex(Request->name(), Index.get())) {
+  Req.IDs.insert(ID);
+}
+Index->lookup(Req, [&](const Symbol &Sym) {
+  LookupReply NextSymbol;
+  NextSymbol.set_symbolyaml(toYAML(Sym));
+  Reply->Write(NextSymbol);
+});
+return grpc::Status::OK;
+  }
+
+  std::unique_ptr Index;
+};
+
+void runServer(std::unique_ptr Index,
+   const std::string &ServerAddress) {
+  SharedIndexServer Service(std::move(Index));
+
+  grpc::EnableDefaultHealthCheckService(true);
+  grpc::ServerBuilder Builder;
+  Builder.AddListeningPort(ServerAddress, grpc::InsecureServerCredentials());
+  Builder.RegisterService(&Service);
+  std::unique_ptr Server(Builder.BuildAndStart());

[PATCH] D77794: [clangd] Pull installed gRPC and introduce shared-index-(server|client)

2020-04-09 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 256265.
kbobyrev added a comment.

Discard Dexp.cpp formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794

Files:
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/shared/SharedIndex.proto
  clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp
  clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
  llvm/cmake/modules/LLVMProcessSources.cmake

Index: llvm/cmake/modules/LLVMProcessSources.cmake
===
--- llvm/cmake/modules/LLVMProcessSources.cmake
+++ llvm/cmake/modules/LLVMProcessSources.cmake
@@ -109,8 +109,8 @@
   else()
   set(fn_relative "${fn}")
   endif()
-  message(SEND_ERROR "Found unknown source file ${fn_relative}
-Please update ${CMAKE_CURRENT_LIST_FILE}\n")
+#   message(SEND_ERROR "Found unknown source file ${fn_relative}
+# Please update ${CMAKE_CURRENT_LIST_FILE}\n")
 endif()
   endif()
 endif()
Index: clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
===
--- clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
+++ clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
@@ -25,6 +25,8 @@
 namespace {
 
 static const std::string Overview = R"(
+This is an experimental shared index implementation. The server opens Dex and
+awaits gRPC lookup requests from the client.
 )";
 
 llvm::cl::opt IndexPath(llvm::cl::desc("[PATH TO INDEX]"),
@@ -37,21 +39,48 @@
   return loadIndex(Index, /*UseIndex=*/true);
 }
 
+// FIXME(kbobyrev): This is copied
+std::vector getSymbolIDsFromIndex(llvm::StringRef QualifiedName,
+const SymbolIndex *Index) {
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {std::string(Names.first)};
+  else
+// QualifiedName refers to a symbol in global scope (e.g. "GlobalSymbol"),
+// add the global scope to the request.
+Request.Scopes = {""};
+
+  Request.Query = std::string(Names.second);
+  std::vector SymIDs;
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
 class SharedIndexServer final : public SharedIndex::Service {
 public:
   SharedIndexServer(std::unique_ptr Index)
   : Index(std::move(Index)) {}
 
 private:
-  grpc::Status FuzzyFind(grpc::ServerContext *Context,
- const FuzzyFindProtoRequest *Request,
- grpc::ServerWriter *Reply) override {
-FuzzyFindRequest Req;
-Index->fuzzyFind(Req, [&](const Symbol &Sym) {
-  FuzzyFindReply NextSymbol;
-  NextSymbol.set_name(Sym.Name.str());
-  NextSymbol.set_scope(Sym.Scope.str());
-  NextSymbol.set_id(Sym.ID.str());
+  grpc::Status requestLookup(grpc::ServerContext *Context,
+ const LookupRequestProto *Request,
+ grpc::ServerWriter *Reply) override {
+llvm::outs() << "Lookup of symbol with ID " << Request->name() << '\n';
+LookupRequest Req;
+for (const auto &ID : getSymbolIDsFromIndex(Request->name(), Index.get())) {
+  Req.IDs.insert(ID);
+}
+Index->lookup(Req, [&](const Symbol &Sym) {
+  LookupReply NextSymbol;
+  NextSymbol.set_symbolyaml(toYAML(Sym));
   Reply->Write(NextSymbol);
 });
 return grpc::Status::OK;
@@ -60,8 +89,8 @@
   std::unique_ptr Index;
 };
 
-int runServer(std::unique_ptr Index,
-  const std::string &ServerAddress) {
+void runServer(std::unique_ptr Index,
+   const std::string &ServerAddress) {
   SharedIndexServer Service(std::move(Index));
 
   grpc::EnableDefaultHealthCheckService(true);
@@ -71,10 +100,7 @@
   std::unique_ptr Server(Builder.BuildAndStart());
   llvm::outs() << "Server listening on " << ServerAddress << '\n';
 
-  // Wait for the server to shutdown.
   Server->Wait();
-
-  return 0;
 }
 
 } // namespace
@@ -93,5 +119,5 @@
 return -1;
   }
 
-  return runServer(std::move(Index), ServerAddress);
+  runServer(std::move(Index), ServerAddress);
 }
Index: clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp
===
--- clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp
+++ clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp
@@ -37,11 +37,9 @@
 
 static const std::string Overview = R"(
 This is an **experimental** interactive tool to process us

[PATCH] D74387: [SYCL] Defer __float128 type usage diagnostics

2020-04-09 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

In D74387#1970374 , @jdoerfert wrote:

> In D74387#1969891 , @Fznamznon wrote:
>
> > In D74387#1967386 , @jdoerfert 
> > wrote:
> >
> > > In D74387#1967289 , @Fznamznon 
> > > wrote:
> > >
> > > > In D74387#1965634 , @jdoerfert 
> > > > wrote:
> > > >
> > > > > In D74387#1964483 , 
> > > > > @Fznamznon wrote:
> > > > >
> > > > > > In D74387#1950593 , 
> > > > > > @jdoerfert wrote:
> > > > > >
> > > > > > > This is needed for OpenMP as well. Does it make sense to include 
> > > > > > > it in this patch or in another one?
> > > > > >
> > > > > >
> > > > > > I thought OpenMP already has diagnostics for unsupported types (at 
> > > > > > least looking into this commit 
> > > > > > https://github.com/llvm/llvm-project/commit/123ad1969171d0b22d0c5d0ec23468586c4d8fa7).
> > > > > >  Am I wrong?
> > > > > >  The diagnostic which I'm implementing here is stricter than 
> > > > > > existing OpenMP diagnostic, the main goal is do not emit 
> > > > > > unsupported type at all. Does OpenMP need such restriction as well?
> > > > >
> > > > >
> > > > > OpenMP handling needs to be reverted/redone:
> > > > >
> > > > > 1. If no aux triple is available it just crashes.
> > > > > 2. If the unavailable type is not used in one of the pattern matched 
> > > > > expressions it crashes (usually during instruction selection but not 
> > > > > always). Try a call with long double arguments for example.
> > > > >
> > > > >   I'm not sure this patch fits the bill but what I was thinking we 
> > > > > need is roughly: If you have a expression with operands or function 
> > > > > definition with return/argument types which are not supported on the 
> > > > > target, mark the definition as unavailable with the type note you 
> > > > > have. We should especially allow members to have unavailable types if 
> > > > > the member is not accessed. Memcpy like operations (=mapping) are OK 
> > > > > though. I think this should be the same for OpenMP and Sycl (and HIP, 
> > > > > and ...).
> > > >
> > > >
> > > > Why we should allow members to have unavailable types if the member is 
> > > > not accessed? I don't think that we always can do it, especially for 
> > > > SYCL. Even if the member is not accessed directly, the whole struct 
> > > > with unavailable type inside will get into resulting LLVM IR module 
> > > > anyway, this can be a problem, I guess.
> > >
> > >
> > > On the host you know how large the type is so you can replace it in the 
> > > device module with a placeholder of the appropriate size. You want to do 
> > > this (in OpenMP for sure) because things you map might have constitutes 
> > > you don't want to access on the device but you can also not (easily) 
> > > split out of your mapped type.
> >
> >
> > Okay, I see. Am I right that OpenMP already has such thing implemented, but 
> > only for functions return types? I suppose, for SYCL, we might need to 
> > replace unsupported type in device module everywhere...
> >  BTW, one more question, we also have a diagnostic which is emitted on 
> > attempt to declare a variable with unsupported type inside the device code 
> > for this __float128 type and other ones 
> > (https://github.com/intel/llvm/pull/1465/files). Does OpenMP (and probably 
> > HIP, CUDA etc) need such diagnostic as well?
>
>
> I'm not sure we want this and I'm not sure why you would. To me, it seems 
> user hostile to disallow unsupported types categorically. We also know from 
> our codes that people have unsupported types in structs that they would 
> rather not refactor. Given that there is not really a need for this anyway, 
> why should we make them? Arguably you cannot "use" unsupported types but an 
> error like that makes sense to people. So as long as you don't use the 
> unsupported type as an operand in an expression you should be fine.
>
> We have some detection for this in clang for OpenMP but it is not sufficient. 
> We also should generalize this (IMHO) and stop duplicating logic between 
> HIP/CUDA/OpenMP/SYCL/... That said, we cannot error out because the types are 
> present but only if they are used. I would hope you would reconsider and do 
> the same. Arguably, mapping/declaring a unsupported type explicitly could be 
> diagnosed (with a warning) but as part of a struct I would advice against.
>
> Maybe I just don't understand. Could you elaborate why you think sycl has to 
> forbid them categorically?


Roughly speaking, SYCL is a wrapper over OpenCL. SYCL device compiler should be 
able to produce device code module in a form acceptable by OpenCL backends. For 
this purpose we use SPIR-V intermediate language 
(https://www.khronos.org/registry/spir-v/specs/unified1/SPIRV.html). 

[PATCH] D77794: [clangd] Pull installed gRPC and introduce shared-index-(server|client)

2020-04-09 Thread Kirill Bobyrev via Phabricator via cfe-commits
kbobyrev updated this revision to Diff 256267.
kbobyrev added a comment.

Rebase on top of the correct revision again


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77794

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/dex/dexp/Dexp.cpp
  clang-tools-extra/clangd/index/shared/CMakeLists.txt
  clang-tools-extra/clangd/index/shared/SharedIndex.proto
  clang-tools-extra/clangd/index/shared/SharedIndexClient.cpp
  clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
  llvm/cmake/modules/LLVMProcessSources.cmake

Index: llvm/cmake/modules/LLVMProcessSources.cmake
===
--- llvm/cmake/modules/LLVMProcessSources.cmake
+++ llvm/cmake/modules/LLVMProcessSources.cmake
@@ -109,8 +109,8 @@
   else()
   set(fn_relative "${fn}")
   endif()
-  message(SEND_ERROR "Found unknown source file ${fn_relative}
-Please update ${CMAKE_CURRENT_LIST_FILE}\n")
+#   message(SEND_ERROR "Found unknown source file ${fn_relative}
+# Please update ${CMAKE_CURRENT_LIST_FILE}\n")
 endif()
   endif()
 endif()
Index: clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/index/shared/SharedIndexServer.cpp
@@ -0,0 +1,123 @@
+//===--- SharedIndexServer.cpp - gRPC-based Shared Index Server  --===//
+//
+// 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 "index/Index.h"
+#include "index/Serialization.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/LineEditor/LineEditor.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Signals.h"
+
+#include "grpcpp/grpcpp.h"
+
+#include "SharedIndex.grpc.pb.h"
+
+namespace clang {
+namespace clangd {
+namespace {
+
+static const std::string Overview = R"(
+This is an experimental shared index implementation. The server opens Dex and
+awaits gRPC lookup requests from the client.
+)";
+
+llvm::cl::opt IndexPath(llvm::cl::desc("[PATH TO INDEX]"),
+ llvm::cl::Positional, llvm::cl::Required);
+
+llvm::cl::opt ServerAddress("server-address",
+ llvm::cl::init("0.0.0.0:50051"));
+
+std::unique_ptr openIndex(llvm::StringRef Index) {
+  return loadIndex(Index, /*UseIndex=*/true);
+}
+
+// FIXME(kbobyrev): This is copied
+std::vector getSymbolIDsFromIndex(llvm::StringRef QualifiedName,
+const SymbolIndex *Index) {
+  FuzzyFindRequest Request;
+  // Remove leading "::" qualifier as FuzzyFind doesn't need leading "::"
+  // qualifier for global scope.
+  bool IsGlobalScope = QualifiedName.consume_front("::");
+  auto Names = splitQualifiedName(QualifiedName);
+  if (IsGlobalScope || !Names.first.empty())
+Request.Scopes = {std::string(Names.first)};
+  else
+// QualifiedName refers to a symbol in global scope (e.g. "GlobalSymbol"),
+// add the global scope to the request.
+Request.Scopes = {""};
+
+  Request.Query = std::string(Names.second);
+  std::vector SymIDs;
+  Index->fuzzyFind(Request, [&](const Symbol &Sym) {
+std::string SymQualifiedName = (Sym.Scope + Sym.Name).str();
+if (QualifiedName == SymQualifiedName)
+  SymIDs.push_back(Sym.ID);
+  });
+  return SymIDs;
+}
+
+class SharedIndexServer final : public SharedIndex::Service {
+public:
+  SharedIndexServer(std::unique_ptr Index)
+  : Index(std::move(Index)) {}
+
+private:
+  grpc::Status requestLookup(grpc::ServerContext *Context,
+ const LookupRequestProto *Request,
+ grpc::ServerWriter *Reply) override {
+llvm::outs() << "Lookup of symbol with ID " << Request->name() << '\n';
+LookupRequest Req;
+for (const auto &ID : getSymbolIDsFromIndex(Request->name(), Index.get())) {
+  Req.IDs.insert(ID);
+}
+Index->lookup(Req, [&](const Symbol &Sym) {
+  LookupReply NextSymbol;
+  NextSymbol.set_symbolyaml(toYAML(Sym));
+  Reply->Write(NextSymbol);
+});
+return grpc::Status::OK;
+  }
+
+  std::unique_ptr Index;
+};
+
+void runServer(std::unique_ptr Index,
+   const std::string &ServerAddress) {
+  SharedIndexServer Service(std::move(Index));
+
+  grpc::EnableDefaultHealthCheckService(true);
+  grpc::ServerBuilder Builder;
+  Builder.AddListeningPort(ServerAddress, grpc::InsecureServerCredentials());
+  Builder.RegisterService(&Service);
+  std::unique_ptr Server(Builder.BuildAndStar

[PATCH] D77791: [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher

2020-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!




Comment at: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp:102-106
+  static constexpr llvm::StringRef Allowed[] = {
+  "UETT_SizeOf",   "UETT_AlignOf",
+  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
+  "UETT_PreferredAlignOf",
+  };

njames93 wrote:
> aaron.ballman wrote:
> > Did clang-format produce this formatting?
> when I ran git-clang-format I dont think it did, but when i went to upload 
> the patch i got this in the pre-upload linting
> ```
> --- 
> /home/nathan/src/llvm-project/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp 
> 2020-04-09 12:12:28.810339833 +0100
> +++ /tmp/6p7zxlltj4g8wgcc/9888-onMes8   2020-04-09 12:44:11.187257096 +0100
> @@ -99,11 +99,11 @@
>  llvm::Optional
>  clang::ast_matchers::dynamic::internal::ArgTypeTraits<
>  clang::UnaryExprOrTypeTrait>::getBestGuess(const VariantValue &Value) {
> -  static constexpr llvm::StringRef Allowed[] = {"UETT_SizeOf",
> -"UETT_AlignOf",
> -"UETT_VecStep",
> -
> "UETT_OpenMPRequiredSimdAlign",
> -"UETT_PreferredAlignOf",};
> +  static constexpr llvm::StringRef Allowed[] = {
> +  "UETT_SizeOf",   "UETT_AlignOf",
> +  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
> +  "UETT_PreferredAlignOf",
> +  };
> ```
I think the pre-upload linting is wrong (I can't find many instances of lists 
that look like that in LLVM anyway, but I know of plenty of instances of the 
other style). Not a huge deal though.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77791



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


[PATCH] D77728: [Driver][X86] Add an alias for -mpad-max-prefix-size

2020-04-09 Thread Kan Shengchen via Phabricator via cfe-commits
skan updated this revision to Diff 256268.
skan edited the summary of this revision.
skan added a comment.

Rebase(didn't rebase correctly last time)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77728

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/x86-malign-branch.c
  clang/test/Driver/x86-malign-branch.s


Index: clang/test/Driver/x86-malign-branch.s
===
--- clang/test/Driver/x86-malign-branch.s
+++ clang/test/Driver/x86-malign-branch.s
@@ -9,5 +9,7 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX
 // PREFIX: "-mllvm" "-x86-pad-max-prefix-size=5"
 
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX
+
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 
| FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/test/Driver/x86-malign-branch.c
===
--- clang/test/Driver/x86-malign-branch.c
+++ clang/test/Driver/x86-malign-branch.c
@@ -24,6 +24,9 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=15 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-15
 // PREFIX-15: "-mllvm" "-x86-pad-max-prefix-size=15"
 
+/// Test -malign-branch-prefix-size= for GCC compatibilty
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-5
+
 /// Test -mbranches-within-32B-boundaries
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 
| FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2189,6 +2189,8 @@
   HelpText<"Specify the boundary's size to align branches">;
 def mpad_max_prefix_size_EQ : Joined<["-"], "mpad-max-prefix-size=">, 
Group, Flags<[DriverOption]>,
   HelpText<"Specify maximum number of prefixes to use for padding">;
+def malign_branch_prefix_size_EQ : Joined<["-"], 
"malign-branch-prefix-size=">, Group, Flags<[DriverOption]>, 
Alias,
+  HelpText<"Alias for -mpad-max-prefix-size">;// Alias for GCC compatibility
 def mbranches_within_32B_boundaries : Flag<["-"], 
"mbranches-within-32B-boundaries">, Flags<[DriverOption]>, Group,
   HelpText<"Align selected branches (fused, jcc, jmp) within 32-byte 
boundary">;
 def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, 
Group;


Index: clang/test/Driver/x86-malign-branch.s
===
--- clang/test/Driver/x86-malign-branch.s
+++ clang/test/Driver/x86-malign-branch.s
@@ -9,5 +9,7 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX
 // PREFIX: "-mllvm" "-x86-pad-max-prefix-size=5"
 
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX
+
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/test/Driver/x86-malign-branch.c
===
--- clang/test/Driver/x86-malign-branch.c
+++ clang/test/Driver/x86-malign-branch.c
@@ -24,6 +24,9 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=15 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-15
 // PREFIX-15: "-mllvm" "-x86-pad-max-prefix-size=15"
 
+/// Test -malign-branch-prefix-size= for GCC compatibilty
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-5
+
 /// Test -mbranches-within-32B-boundaries
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2189,6 +2189,8 @@
   HelpText<"Specify the boundary's size to align branches">;
 def mpad_max_prefix_size_EQ : Joined<["-"], "mpad-max-prefix-size=">, Group, Flags<[DriverOption]>,
   HelpText<"Specify maximum number of prefixes to use for padding">;
+def malign_branch_prefix_size_EQ : Joined<["-"], "malign-branch-prefix-size=">, Group, Flags<[DriverOption]>, Alias,
+  HelpText<"Alias for -mpad-max-prefix-size">;// Alias for GCC compatibility
 def mbranches_within_32B_boundaries : Flag<["-"], "mbranches-within-32B-boundaries">, Flags<[DriverOption]>, Group,
   HelpText<"Align selected bran

[PATCH] D75851: [Analyzer][StreamChecker] Added evaluation of fseek.

2020-04-09 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus accepted this revision.
Szelethus added a comment.
This revision is now accepted and ready to land.

LGTM! You seem to have a firm grasp on where you want this checker to go, and I 
like everything about it.

The code needs seme `clang-format` treatment, and another eye might not hurt, 
but as far as I'm concerned, I'm super happy how this patch turned out.




Comment at: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp:103-110
+  /// Return if the specified error kind is possible on the stream in the
+  /// current state.
+  /// This depends on the stored `LastOperation` value.
+  /// If the error is not possible returns empty value.
+  /// If the error is possible returns the remaining possible error type
+  /// (after taking out `ErrorKind`). If a single error is possible it will
+  /// return that value, otherwise unknown error.

balazske wrote:
> Szelethus wrote:
> > This feels clunky to me.
> > 
> > Suppose that we're curious about the stream reaching `EOF`. We know that 
> > the last operation on the stream could cause `EOF` and `ERROR`. This 
> > function then would return `FError`. That doesn't really feel like the 
> > answer to the question "isErrorPossible".
> > 
> > In what contexts do you see calling this function that isn't like this?:
> > 
> > ```lang=c++
> >   Optional NewError =
> >   SS->isErrorPossible(ErrorKind);
> >   if (!NewError) {
> > // This kind of error is not possible, function returns zero.
> > // Error state remains unknown.
> > AddTransition(bindInt(0, State, C, CE), StreamState::UnknownError);
> >   } else {
> > // Add state with true returned.
> > AddTransition(bindAndAssumeTrue(State, C, CE), ErrorKind);
> > // Add state with false returned and the new remaining error type.
> > AddTransition(bindInt(0, State, C, CE), *NewError);
> >   }
> > ```
> > 
> > Would it make more sense to move the logic of creating state transitions 
> > into a function instead?
> The name of the function may be misleading. The non-empty `Optional` means 
> "yes" and an empty means "no". And if yes additional information is returned 
> in the optional value. If the transitions would be included in this function 
> it needs more parameters. This function is for the part of the operation that 
> computes the remaining error ( `getRemainingPossibleError` is a better 
> name?). Later it will turn out in what way the function is used and if there 
> is code repetition a new function can be introduced, but not now (the needed 
> state transitions may be different).
`getRemainingPossibleError` sounds great! You convinced me, if we ever need to 
stuff more things into this function, we will do that then.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75851



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


[clang] bf968e2 - [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher

2020-04-09 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-04-09T14:33:04+01:00
New Revision: bf968e28ee82efce6a34a4dffd904c3c5df4eae4

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

LOG: [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher

Summary: Adds support for using the ofKind in clang-query and other dynamic 
matcher use cases

Reviewers: klimek, aaron.ballman, jdoerfert

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
clang/lib/ASTMatchers/Dynamic/Marshallers.h
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Removed: 




diff  --git a/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp 
b/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
index 46312284e088..de1a97814e42 100644
--- a/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -95,3 +95,17 @@ clang::ast_matchers::dynamic::internal::ArgTypeTraits<
   "OMPC_");
   return llvm::None;
 }
+
+llvm::Optional
+clang::ast_matchers::dynamic::internal::ArgTypeTraits<
+clang::UnaryExprOrTypeTrait>::getBestGuess(const VariantValue &Value) {
+  static constexpr llvm::StringRef Allowed[] = {
+  "UETT_SizeOf",   "UETT_AlignOf",
+  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
+  "UETT_PreferredAlignOf",
+  };
+  if (Value.isString())
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),
+  "UETT_");
+  return llvm::None;
+}

diff  --git a/clang/lib/ASTMatchers/Dynamic/Marshallers.h 
b/clang/lib/ASTMatchers/Dynamic/Marshallers.h
index 3d36ed6ea187..288155217d5c 100644
--- a/clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ b/clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -27,6 +27,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/OpenMPKinds.h"
+#include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
@@ -214,6 +215,35 @@ template <> struct ArgTypeTraits {
   static llvm::Optional getBestGuess(const VariantValue &Value);
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static Optional
+  getUnaryOrTypeTraitKind(llvm::StringRef ClauseKind) {
+// FIXME: Type traits should probably be in a `.def` to make less error
+// prone.
+return llvm::StringSwitch>(ClauseKind)
+.Case("UETT_SizeOf", UETT_SizeOf)
+.Case("UETT_AlignOf", UETT_AlignOf)
+.Case("UETT_VecStep", UETT_VecStep)
+.Case("UETT_OpenMPRequiredSimdAlign", UETT_OpenMPRequiredSimdAlign)
+.Case("UETT_PreferredAlignOf", UETT_PreferredAlignOf)
+.Default(llvm::None);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() && getUnaryOrTypeTraitKind(Value.getString());
+  }
+
+  static UnaryExprOrTypeTrait get(const VariantValue &Value) {
+return *getUnaryOrTypeTraitKind(Value.getString());
+  }
+
+  static ArgKind getKind() { return ArgKind(ArgKind::AK_String); }
+
+  static llvm::Optional getBestGuess(const VariantValue &Value);
+};
+
 /// Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index 259b81ab19f0..e7659feaf1e9 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -95,9 +95,6 @@ void RegistryMaps::registerMatcher(
 RegistryMaps::RegistryMaps() {
   // TODO: Here is the list of the missing matchers, grouped by reason.
   //
-  // Need Variant/Parser fixes:
-  // ofKind
-  //
   // Polymorphic + argument overload:
   // findAll
   //
@@ -458,6 +455,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(objcThrowStmt);
   REGISTER_MATCHER(objcTryStmt);
   REGISTER_MATCHER(ofClass);
+  REGISTER_MATCHER(ofKind);
   REGISTER_MATCHER(ompDefaultClause);
   REGISTER_MATCHER(ompExecutableDirective);
   REGISTER_MATCHER(on);

diff  --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp 
b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
index 71c2e3e5addf..1b553ffe73ed 100644
--- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -242,6 +242,14 @@ TEST(ParserTest, FullParserTest) {
   EXPECT_TRUE(matches("void f(int a, int x);", M));
   EXPECT_FALSE(matches("void f(int x, int a);", M));
 
+  Code = "unaryExprOrTypeTraitExpr(ofKind(\"UETT_SizeOf\"))";
+  llvm::Optional UnaryExprSizeOf(
+  Parser::parseMatcherExpression(Code, nullptr, nullpt

[clang] 9bda29a - [Hexagon] Default linker tests can fail if CLANG_DEFAULT_LINKER is used.

2020-04-09 Thread Sid Manning via cfe-commits

Author: Sid Manning
Date: 2020-04-09T08:36:50-05:00
New Revision: 9bda29ab0fdfee4e4b5cbe17f87a16f673e91e1f

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

LOG: [Hexagon] Default linker tests can fail if CLANG_DEFAULT_LINKER is used.

These values are not always known since there is a configuration
option to set the default linker, CLANG_DEFAULT_LINKER.

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

Added: 


Modified: 
clang/test/Driver/hexagon-toolchain-elf.c
clang/test/Driver/hexagon-toolchain-linux.c

Removed: 




diff  --git a/clang/test/Driver/hexagon-toolchain-elf.c 
b/clang/test/Driver/hexagon-toolchain-elf.c
index 4590522d2b40..0a6c86424955 100644
--- a/clang/test/Driver/hexagon-toolchain-elf.c
+++ b/clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,10 +597,3 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
-// 
-
-// Check default linker for elf
-// 
-
-// RUN: %clang -### -target hexagon-unknown-elf %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK092 %s
-// CHECK092:  hexagon-link
-// 
-

diff  --git a/clang/test/Driver/hexagon-toolchain-linux.c 
b/clang/test/Driver/hexagon-toolchain-linux.c
index 6c47044a2c0c..354a924f1209 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -95,7 +95,3 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK007 %s
 // CHECK007:  "-internal-isystem" 
"{{.*}}hexagon{{/|}}include{{/|}}c++{{/|}}v1"
-// 
-
-// RUN: %clang -### -target hexagon-unknown-linux-musl %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK008 %s
-// CHECK008:  ld.lld



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


[PATCH] D77503: [ASTMatchers] Fixed CastKind being parsed incorrectly for dynamic matchers

2020-04-09 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 256275.
njames93 added a comment.

Added unit test for matcher


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77503

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp


Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -221,6 +221,15 @@
   EXPECT_FALSE(matches("int x = 1 - false;", M));
   EXPECT_FALSE(matches("int x = true - 1;", M));
 
+  Code = "implicitCastExpr(hasCastKind(\"CK_IntegralToBoolean\"))";
+  llvm::Optional implicitIntBooleanCast(
+  Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error));
+  EXPECT_EQ("", Error.toStringFull());
+  Matcher MCastStmt =
+  implicitIntBooleanCast->unconditionalConvertTo();
+  EXPECT_TRUE(matches("bool X = 1;", MCastStmt));
+  EXPECT_FALSE(matches("bool X = true;", MCastStmt));
+
   Code = "functionDecl(hasParameter(1, hasName(\"x\")))";
   llvm::Optional HasParameter(
   Parser::parseMatcherExpression(Code, &Error));
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -170,7 +170,7 @@
 private:
   static Optional getCastKind(llvm::StringRef AttrKind) {
 return llvm::StringSwitch>(AttrKind)
-#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#define CAST_OPERATION(Name) .Case("CK_" #Name, CK_##Name)
 #include "clang/AST/OperationKinds.def"
 .Default(llvm::None);
   }
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -75,11 +75,12 @@
 clang::ast_matchers::dynamic::internal::ArgTypeTraits<
 clang::CastKind>::getBestGuess(const VariantValue &Value) {
   static constexpr llvm::StringRef Allowed[] = {
-#define CAST_OPERATION(Name) #Name,
+#define CAST_OPERATION(Name) "CK_" #Name,
 #include "clang/AST/OperationKinds.def"
   };
   if (Value.isString())
-return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed));
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),
+  "CK_");
   return llvm::None;
 }
 
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4913,7 +4913,7 @@
 /// \endcode
 ///
 /// If the matcher is use from clang-query, CastKind parameter
-/// should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
+/// should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
 AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
   return Node.getCastKind() == Kind;
 }
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -2790,7 +2790,7 @@
   int *p = 0;
 
 If the matcher is use from clang-query, CastKind parameter
-should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
+should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
 
 
 


Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -221,6 +221,15 @@
   EXPECT_FALSE(matches("int x = 1 - false;", M));
   EXPECT_FALSE(matches("int x = true - 1;", M));
 
+  Code = "implicitCastExpr(hasCastKind(\"CK_IntegralToBoolean\"))";
+  llvm::Optional implicitIntBooleanCast(
+  Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error));
+  EXPECT_EQ("", Error.toStringFull());
+  Matcher MCastStmt =
+  implicitIntBooleanCast->unconditionalConvertTo();
+  EXPECT_TRUE(matches("bool X = 1;", MCastStmt));
+  EXPECT_FALSE(matches("bool X = true;", MCastStmt));
+
   Code = "functionDecl(hasParameter(1, hasName(\"x\")))";
   llvm::Optional HasParameter(
   Parser::parseMatcherExpression(Code, &Error));
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -170,7 +170,7 @@
 private:
   static Optional getCastKind(llvm::StringRef AttrKind) {
 return llvm::Str

[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-04-09 Thread Digger via Phabricator via cfe-commits
DiggerLin marked 2 inline comments as done.
DiggerLin added inline comments.



Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1500
+  if (cast(Name)->hasContainingCsect())
+emitLinkage(&F, Name);
+

jasonliu wrote:
> DiggerLin wrote:
> > jasonliu wrote:
> > > 1. We need to rebase here, as it is called `hasRepresentedCsectSet()` 
> > > instead of `hasContainingCsect()` now.
> > > 2. I'm slightly worried here to rely on `hasRepresentedCsectSet()` to 
> > > check if a linkage should be emitted. This is based on the assumption 
> > > that we will not ever change our implementation for `.bl foo` to `.bl 
> > > foo[PR]`. But in https://reviews.llvm.org/D77080#inline-706207, we 
> > > discussed about this possibility. So this assumption might not be true in 
> > > the future. However, I'm not sure if there is another way to check if 
> > > this function have been called directly. 
> > > So if there is another way to check, we should pursue the alternative 
> > > instead. If there is not, then we need to add an assert here, like 
> > > `assert(Name->getName().equals(cast(Name)->getUnqualifiedName())`
> > >  to make sure we don't get a qualname here. 
> > > 3. 
> > > Have a comment here and tell people what we are doing here.
> > > For example, 
> > > // If there is a direct call to external function, then we need to emit 
> > > linkage for its function entry point. 
> > when we implement .bl foo to .bl foo[PR]
> > the SymbolName will change from .bl[SMC] and check the 
> > .bl[SMC]->hasRepresentedCsectSet()
> Yes, but foo[PR]->hasRepresentedCsectSet() will always return true, because 
> whenever we created a qualname will always have csect set. How will we know 
> if foo() function is called directly then? 
we only deal with extern function(we do not deal with definition function) 
here, for extern function, it not always has MCSectionXCOFF, it only create the 
extern function be called directly in the 
llvm/lib/CodeGen/MachineModuleInfo.cpp line 108~116, unless we delete the code 
later. if the code is not changed. for extern function foo , the .foo[PR] -> 
hasRepresentedCsectSet()  when directly call. otherwise false.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932



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


[PATCH] D77791: [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher

2020-04-09 Thread Nathan James via Phabricator via cfe-commits
njames93 marked an inline comment as done.
njames93 added inline comments.



Comment at: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp:102-106
+  static constexpr llvm::StringRef Allowed[] = {
+  "UETT_SizeOf",   "UETT_AlignOf",
+  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
+  "UETT_PreferredAlignOf",
+  };

aaron.ballman wrote:
> njames93 wrote:
> > aaron.ballman wrote:
> > > Did clang-format produce this formatting?
> > when I ran git-clang-format I dont think it did, but when i went to upload 
> > the patch i got this in the pre-upload linting
> > ```
> > --- 
> > /home/nathan/src/llvm-project/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp 
> > 2020-04-09 12:12:28.810339833 +0100
> > +++ /tmp/6p7zxlltj4g8wgcc/9888-onMes8   2020-04-09 12:44:11.187257096 +0100
> > @@ -99,11 +99,11 @@
> >  llvm::Optional
> >  clang::ast_matchers::dynamic::internal::ArgTypeTraits<
> >  clang::UnaryExprOrTypeTrait>::getBestGuess(const VariantValue &Value) {
> > -  static constexpr llvm::StringRef Allowed[] = {"UETT_SizeOf",
> > -"UETT_AlignOf",
> > -"UETT_VecStep",
> > -
> > "UETT_OpenMPRequiredSimdAlign",
> > -"UETT_PreferredAlignOf",};
> > +  static constexpr llvm::StringRef Allowed[] = {
> > +  "UETT_SizeOf",   "UETT_AlignOf",
> > +  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
> > +  "UETT_PreferredAlignOf",
> > +  };
> > ```
> I think the pre-upload linting is wrong (I can't find many instances of lists 
> that look like that in LLVM anyway, but I know of plenty of instances of the 
> other style). Not a huge deal though.
I tried to manually invoke clang-format on it (using trunk) and it suggested 
the same format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77791



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


[PATCH] D77792: [analyzer] Extend constraint manager to be able to compare simple SymSymExprs

2020-04-09 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

You seem to have forgotten `-U` :^)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77792



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


[PATCH] D77684: [Hexagon] Remove testcases that check for default linker.

2020-04-09 Thread Sid Manning via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9bda29ab0fdf: [Hexagon] Default linker tests can fail if 
CLANG_DEFAULT_LINKER is used. (authored by sidneym).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77684

Files:
  clang/test/Driver/hexagon-toolchain-elf.c
  clang/test/Driver/hexagon-toolchain-linux.c


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -95,7 +95,3 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK007 %s
 // CHECK007:  "-internal-isystem" 
"{{.*}}hexagon{{/|}}include{{/|}}c++{{/|}}v1"
-// 
-
-// RUN: %clang -### -target hexagon-unknown-linux-musl %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK008 %s
-// CHECK008:  ld.lld
Index: clang/test/Driver/hexagon-toolchain-elf.c
===
--- clang/test/Driver/hexagon-toolchain-elf.c
+++ clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,10 +597,3 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
-// 
-
-// Check default linker for elf
-// 
-
-// RUN: %clang -### -target hexagon-unknown-elf %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK092 %s
-// CHECK092:  hexagon-link
-// 
-


Index: clang/test/Driver/hexagon-toolchain-linux.c
===
--- clang/test/Driver/hexagon-toolchain-linux.c
+++ clang/test/Driver/hexagon-toolchain-linux.c
@@ -95,7 +95,3 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK007 %s
 // CHECK007:  "-internal-isystem" "{{.*}}hexagon{{/|}}include{{/|}}c++{{/|}}v1"
-// -
-// RUN: %clang -### -target hexagon-unknown-linux-musl %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK008 %s
-// CHECK008:  ld.lld
Index: clang/test/Driver/hexagon-toolchain-elf.c
===
--- clang/test/Driver/hexagon-toolchain-elf.c
+++ clang/test/Driver/hexagon-toolchain-elf.c
@@ -597,10 +597,3 @@
 // RUN:   %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=CHECK084 %s
 // CHECK084:  "-fno-use-init-array"
-// -
-// Check default linker for elf
-// -
-// RUN: %clang -### -target hexagon-unknown-elf %s 2>&1 \
-// RUN:   | FileCheck -check-prefix=CHECK092 %s
-// CHECK092:  hexagon-link
-// -
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77791: [ASTMatchers] Add support for dynamic matching of ofKind narrowing matcher

2020-04-09 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbf968e28ee82: [ASTMatchers] Add support for dynamic matching 
of ofKind narrowing matcher (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77791

Files:
  clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/lib/ASTMatchers/Dynamic/Registry.cpp
  clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -242,6 +242,14 @@
   EXPECT_TRUE(matches("void f(int a, int x);", M));
   EXPECT_FALSE(matches("void f(int x, int a);", M));
 
+  Code = "unaryExprOrTypeTraitExpr(ofKind(\"UETT_SizeOf\"))";
+  llvm::Optional UnaryExprSizeOf(
+  Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error));
+  EXPECT_EQ("", Error.toStringFull());
+  Matcher MStmt = UnaryExprSizeOf->unconditionalConvertTo();
+  EXPECT_TRUE(matches("unsigned X = sizeof(int);", MStmt));
+  EXPECT_FALSE(matches("unsigned X = alignof(int);", MStmt));
+
   Code = "hasInitializer(\nbinaryOperator(hasLHS(\"A\")))";
   EXPECT_TRUE(!Parser::parseMatcherExpression(Code, &Error).hasValue());
   EXPECT_EQ("1:1: Error parsing argument 1 for matcher hasInitializer.\n"
Index: clang/lib/ASTMatchers/Dynamic/Registry.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -95,9 +95,6 @@
 RegistryMaps::RegistryMaps() {
   // TODO: Here is the list of the missing matchers, grouped by reason.
   //
-  // Need Variant/Parser fixes:
-  // ofKind
-  //
   // Polymorphic + argument overload:
   // findAll
   //
@@ -458,6 +455,7 @@
   REGISTER_MATCHER(objcThrowStmt);
   REGISTER_MATCHER(objcTryStmt);
   REGISTER_MATCHER(ofClass);
+  REGISTER_MATCHER(ofKind);
   REGISTER_MATCHER(ompDefaultClause);
   REGISTER_MATCHER(ompExecutableDirective);
   REGISTER_MATCHER(on);
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -27,6 +27,7 @@
 #include "clang/Basic/AttrKinds.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/OpenMPKinds.h"
+#include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
@@ -214,6 +215,35 @@
   static llvm::Optional getBestGuess(const VariantValue &Value);
 };
 
+template <> struct ArgTypeTraits {
+private:
+  static Optional
+  getUnaryOrTypeTraitKind(llvm::StringRef ClauseKind) {
+// FIXME: Type traits should probably be in a `.def` to make less error
+// prone.
+return llvm::StringSwitch>(ClauseKind)
+.Case("UETT_SizeOf", UETT_SizeOf)
+.Case("UETT_AlignOf", UETT_AlignOf)
+.Case("UETT_VecStep", UETT_VecStep)
+.Case("UETT_OpenMPRequiredSimdAlign", UETT_OpenMPRequiredSimdAlign)
+.Case("UETT_PreferredAlignOf", UETT_PreferredAlignOf)
+.Default(llvm::None);
+  }
+
+public:
+  static bool is(const VariantValue &Value) {
+return Value.isString() && getUnaryOrTypeTraitKind(Value.getString());
+  }
+
+  static UnaryExprOrTypeTrait get(const VariantValue &Value) {
+return *getUnaryOrTypeTraitKind(Value.getString());
+  }
+
+  static ArgKind getKind() { return ArgKind(ArgKind::AK_String); }
+
+  static llvm::Optional getBestGuess(const VariantValue &Value);
+};
+
 /// Matcher descriptor interface.
 ///
 /// Provides a \c create() method that constructs the matcher from the provided
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -95,3 +95,17 @@
   "OMPC_");
   return llvm::None;
 }
+
+llvm::Optional
+clang::ast_matchers::dynamic::internal::ArgTypeTraits<
+clang::UnaryExprOrTypeTrait>::getBestGuess(const VariantValue &Value) {
+  static constexpr llvm::StringRef Allowed[] = {
+  "UETT_SizeOf",   "UETT_AlignOf",
+  "UETT_VecStep",  "UETT_OpenMPRequiredSimdAlign",
+  "UETT_PreferredAlignOf",
+  };
+  if (Value.isString())
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),
+  "UETT_");
+  return llvm::None;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D76360: [PPC][AIX] Emit correct Vaarg for 32BIT-AIX in clang

2020-04-09 Thread Sean Fertile via Phabricator via cfe-commits
sfertile added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:4205
+
+class PPCAIX32TargetCodeGenInfo : public TargetCodeGenInfo {
+public:

Xiangling_L wrote:
> I have a question here. AIX32 falls into PPC32 target, so why we don't 
> inherit from `PPC32TargetCodeGenInfo` instead?
Do we need a separate AIX specific class? We are implementing 2 functions, 1 of 
which is the same implementation as its `PPC32TargetCodeGenInfo` counterpart. 
If we have access to the triple, we can  return true when the OS is AIX in 
`PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable`. With the implementations 
being nearly identical (and after enabling DwarfEHRegSizeTable they will be 
identical) I think we are better to not add a new class if we can avoid it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76360



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


[clang] 30e5c7e - [analyzer] NFCi: Refactor CStringChecker: use strongly typed internal API

2020-04-09 Thread Balazs Benics via cfe-commits

Author: Balazs Benics
Date: 2020-04-09T16:06:32+02:00
New Revision: 30e5c7e82fa1c5318540feb83d54757c632e2599

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

LOG: [analyzer] NFCi: Refactor CStringChecker: use strongly typed internal API

Summary:
I wanted to extend the diagnostics of the CStringChecker with taintedness.
This requires the CStringChecker to be refactored to support a more flexible
reporting mechanism.

This patch does only refactorings, such:
 - eliminates always false parameters (like WarnAboutSize)
 - reduces the number of parameters
 - makes strong types differentiating *source* and *destination* buffers
   (same with size expressions)
 - binds the argument expression and the index, making diagnostics accurate
   and easy to emit
 - removes a bunch of default parameters to make it more readable
 - remove random const char* warning message parameters, making clear where
   and what is going to be emitted

Note that:
 - CheckBufferAccess now checks *only* one buffer, this removed about 100 LOC
   code duplication
 - not every function was refactored to use the /new/ strongly typed API, since
   the CString related functions are really closely coupled monolithic beasts,
   I will refactor them separately
 - all tests are preserved and passing; only the message changed at some places.
   In my opinion, these messages are holding the same information.

I would also highlight that this refactoring caught a bug in
clang/test/Analysis/string.c:454 where the diagnostic did not reflect reality.
This catch backs my effort on simplifying this monolithic CStringChecker.

Reviewers: NoQ, baloghadamsoftware, Szelethus, rengolin, Charusso

Reviewed By: NoQ

Subscribers: whisperity, xazax.hun, szepet, rnkovacs, a.sidorin,
mikhail.ramalho, donat.nagy, dkrupp, Charusso, martong, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
clang/test/Analysis/bsd-string.c
clang/test/Analysis/bstring.c
clang/test/Analysis/null-deref-ps-region.c
clang/test/Analysis/string.c

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
index 4558b6936e7f..40467b346f69 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
@@ -30,6 +30,47 @@ using namespace clang;
 using namespace ento;
 
 namespace {
+struct AnyArgExpr {
+  // FIXME: Remove constructor in C++17 to turn it into an aggregate.
+  AnyArgExpr(const Expr *Expression, unsigned ArgumentIndex)
+  : Expression{Expression}, ArgumentIndex{ArgumentIndex} {}
+  const Expr *Expression;
+  unsigned ArgumentIndex;
+};
+
+struct SourceArgExpr : AnyArgExpr {
+  using AnyArgExpr::AnyArgExpr; // FIXME: Remove using in C++17.
+};
+
+struct DestinationArgExpr : AnyArgExpr {
+  using AnyArgExpr::AnyArgExpr; // FIXME: Same.
+};
+
+struct SizeArgExpr : AnyArgExpr {
+  using AnyArgExpr::AnyArgExpr; // FIXME: Same.
+};
+
+using ErrorMessage = SmallString<128>;
+enum class AccessKind { write, read };
+
+static ErrorMessage createOutOfBoundErrorMsg(StringRef FunctionDescription,
+ AccessKind Access) {
+  ErrorMessage Message;
+  llvm::raw_svector_ostream Os(Message);
+
+  // Function classification like: Memory copy function
+  Os << toUppercase(FunctionDescription.front())
+ << &FunctionDescription.data()[1];
+
+  if (Access == AccessKind::write) {
+Os << " overflows the destination buffer";
+  } else { // read access
+Os << " accesses out-of-bound array element";
+  }
+
+  return Message;
+}
+
 enum class ConcatFnKind { none = 0, strcat = 1, strlcat = 2 };
 class CStringChecker : public Checker< eval::Call,
  check::PreStmt,
@@ -113,12 +154,9 @@ class CStringChecker : public Checker< eval::Call,
   void evalMemmove(CheckerContext &C, const CallExpr *CE) const;
   void evalBcopy(CheckerContext &C, const CallExpr *CE) const;
   void evalCopyCommon(CheckerContext &C, const CallExpr *CE,
-  ProgramStateRef state,
-  const Expr *Size,
-  const Expr *Source,
-  const Expr *Dest,
-  bool Restricted = false,
-  bool IsMempcpy = false) const;
+  ProgramStateRef state, SizeArgExpr Size,
+  DestinationArgExpr Dest, SourceArgExpr Source,
+  bool Restricted, bool IsMempcpy) const;
 
   void evalMemcmp(CheckerContext &C, const CallExpr *CE) const;
 
@@ -195,40 +233,17 @@ class CStringChecker : public Checker< eval::Call,
   

[clang] db71354 - [ASTMatchers] Fixed CastKind being parsed incorrectly for dynamic matchers

2020-04-09 Thread Nathan James via cfe-commits

Author: Nathan James
Date: 2020-04-09T15:09:45+01:00
New Revision: db71354e4ff13e8f5c6ab38da6339c7583209be0

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

LOG: [ASTMatchers] Fixed CastKind being parsed incorrectly for dynamic matchers

Summary: Requires hasCastKind arguments to have `CK_` prefixed to bring it in 
line with the documentation and other matchers that take enumerations.

Reviewers: klimek, aaron.ballman

Reviewed By: aaron.ballman

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/docs/LibASTMatchersReference.html
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
clang/lib/ASTMatchers/Dynamic/Marshallers.h
clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp

Removed: 




diff  --git a/clang/docs/LibASTMatchersReference.html 
b/clang/docs/LibASTMatchersReference.html
index 7490ecd89186..f5106f0e0ba2 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -2790,7 +2790,7 @@ Narrowing Matchers
   int *p = 0;
 
 If the matcher is use from clang-query, CastKind parameter
-should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
+should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
 
 
 

diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 9d7b4dcaacfd..070c38295ba7 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4913,7 +4913,7 @@ AST_POLYMORPHIC_MATCHER_P(hasSourceExpression,
 /// \endcode
 ///
 /// If the matcher is use from clang-query, CastKind parameter
-/// should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
+/// should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
 AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
   return Node.getCastKind() == Kind;
 }

diff  --git a/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp 
b/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
index de1a97814e42..d45965d013cf 100644
--- a/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -75,11 +75,12 @@ llvm::Optional
 clang::ast_matchers::dynamic::internal::ArgTypeTraits<
 clang::CastKind>::getBestGuess(const VariantValue &Value) {
   static constexpr llvm::StringRef Allowed[] = {
-#define CAST_OPERATION(Name) #Name,
+#define CAST_OPERATION(Name) "CK_" #Name,
 #include "clang/AST/OperationKinds.def"
   };
   if (Value.isString())
-return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed));
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),
+  "CK_");
   return llvm::None;
 }
 

diff  --git a/clang/lib/ASTMatchers/Dynamic/Marshallers.h 
b/clang/lib/ASTMatchers/Dynamic/Marshallers.h
index 288155217d5c..582a060842b9 100644
--- a/clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ b/clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -171,7 +171,7 @@ template <> struct ArgTypeTraits {
 private:
   static Optional getCastKind(llvm::StringRef AttrKind) {
 return llvm::StringSwitch>(AttrKind)
-#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#define CAST_OPERATION(Name) .Case("CK_" #Name, CK_##Name)
 #include "clang/AST/OperationKinds.def"
 .Default(llvm::None);
   }

diff  --git a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp 
b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
index 1b553ffe73ed..0d3a2d4ce776 100644
--- a/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ b/clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -221,6 +221,15 @@ TEST(ParserTest, FullParserTest) {
   EXPECT_FALSE(matches("int x = 1 - false;", M));
   EXPECT_FALSE(matches("int x = true - 1;", M));
 
+  Code = "implicitCastExpr(hasCastKind(\"CK_IntegralToBoolean\"))";
+  llvm::Optional implicitIntBooleanCast(
+  Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error));
+  EXPECT_EQ("", Error.toStringFull());
+  Matcher MCastStmt =
+  implicitIntBooleanCast->unconditionalConvertTo();
+  EXPECT_TRUE(matches("bool X = 1;", MCastStmt));
+  EXPECT_FALSE(matches("bool X = true;", MCastStmt));
+
   Code = "functionDecl(hasParameter(1, hasName(\"x\")))";
   llvm::Optional HasParameter(
   Parser::parseMatcherExpression(Code, &Error));



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


[clang] a2b6ece - [analyzer] Display the checker name in the text output

2020-04-09 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-04-09T16:21:45+02:00
New Revision: a2b6ece1fd4e13f2f463c5075eb0e513af47e656

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

LOG: [analyzer] Display the checker name in the text output

Exactly what it says on the tin! There is no reason I think not to have this.

Also, I added test files for checkers that emit warning under the wrong name.

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

Added: 
clang/test/Analysis/incorrect-checker-names.cpp
clang/test/Analysis/incorrect-checker-names.mm

Modified: 
clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/dispatch-once.m
clang/test/Analysis/explain-svals.c
clang/test/Analysis/explain-svals.cpp
clang/test/Analysis/explain-svals.m

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def 
b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
index ee67f60df948..597a65c21318 100644
--- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
+++ b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
@@ -310,6 +310,10 @@ ANALYZER_OPTION(bool, ShouldApplyFixIts, "apply-fixits",
 "Apply the fix-it hints to the files",
 false)
 
+ANALYZER_OPTION(bool, ShouldDisplayCheckerNameForText, "display-checker-name",
+"Display the checker name for textual outputs",
+true)
+
 
//===--===//
 // Unsigned analyzer options.
 
//===--===//

diff  --git a/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp 
b/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
index 07e5685e604c..f4c7e5978e19 100644
--- a/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
+++ b/clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
@@ -35,17 +35,19 @@ namespace {
 /// diagnostics in textual format for the 'text' output type.
 class TextDiagnostics : public PathDiagnosticConsumer {
   DiagnosticsEngine &DiagEng;
-  LangOptions LO;
+  const LangOptions &LO;
   const bool IncludePath = false;
   const bool ShouldEmitAsError = false;
   const bool ApplyFixIts = false;
+  const bool ShouldDisplayCheckerName = false;
 
 public:
-  TextDiagnostics(DiagnosticsEngine &DiagEng, LangOptions LO,
+  TextDiagnostics(DiagnosticsEngine &DiagEng, const LangOptions &LO,
   bool ShouldIncludePath, const AnalyzerOptions &AnOpts)
   : DiagEng(DiagEng), LO(LO), IncludePath(ShouldIncludePath),
 ShouldEmitAsError(AnOpts.AnalyzerWerror),
-ApplyFixIts(AnOpts.ShouldApplyFixIts) {}
+ApplyFixIts(AnOpts.ShouldApplyFixIts),
+ShouldDisplayCheckerName(AnOpts.ShouldDisplayCheckerNameForText) {}
   ~TextDiagnostics() override {}
 
   StringRef getName() const override { return "TextDiagnostics"; }
@@ -90,9 +92,13 @@ class TextDiagnostics : public PathDiagnosticConsumer {
  E = Diags.end();
  I != E; ++I) {
   const PathDiagnostic *PD = *I;
+  std::string WarningMsg =
+  (ShouldDisplayCheckerName ? " [" + PD->getCheckerName() + "]" : "")
+  .str();
+
   reportPiece(WarnID, PD->getLocation().asLocation(),
-  PD->getShortDescription(), PD->path.back()->getRanges(),
-  PD->path.back()->getFixits());
+  (PD->getShortDescription() + WarningMsg).str(),
+  PD->path.back()->getRanges(), PD->path.back()->getFixits());
 
   // First, add extra notes, even if paths should not be included.
   for (const auto &Piece : PD->path) {
@@ -100,7 +106,8 @@ class TextDiagnostics : public PathDiagnosticConsumer {
   continue;
 
 reportPiece(NoteID, Piece->getLocation().asLocation(),
-Piece->getString(), Piece->getRanges(), 
Piece->getFixits());
+Piece->getString(), Piece->getRanges(),
+Piece->getFixits());
   }
 
   if (!IncludePath)
@@ -113,7 +120,8 @@ class TextDiagnostics : public PathDiagnosticConsumer {
   continue;
 
 reportPiece(NoteID, Piece->getLocation().asLocation(),
-Piece->getString(), Piece->getRanges(), 
Piece->getFixits());
+Piece->getString(), Piece->getRanges(),
+Piece->getFixits());
   }
 }
 

diff  --git a/clang/test/Analysis/analyzer-config.c 
b/clang/test/Analysis/analyzer-config.c
index 068930e6e57f..7069ee4a938d 100644
--- a/clang/test/Analysis/analyzer-config.c
+++ b/clang/test/Analysis/analyzer-config.c
@@ -52,6 +52,7 @@
 // CHECK-NEXT: debug.Analysi

[PATCH] D77802: [analyzer] Improved RangeSet::Negate support of unsigned ranges

2020-04-09 Thread Denys Petrov via Phabricator via cfe-commits
ASDenysPetrov created this revision.
ASDenysPetrov added reviewers: NoQ, baloghadamsoftware.
ASDenysPetrov added a project: clang.
Herald added subscribers: cfe-commits, martong, Charusso, dkrupp, donat.nagy, 
Szelethus, mikhail.ramalho, a.sidorin, rnkovacs, szepet, xazax.hun.

This fixes https://bugs.llvm.org/show_bug.cgi?id=41588
RangeSet Negate function shall handle unsigned ranges as well as signed ones.
RangeSet getRangeForMinusSymbol function shall use wider variety of ranges, not 
only concrete value ranges.
RangeSet Intersect functions shall not produce assertions.

Changes:
Improved safety of RangeSet::Intersect function. Added isEmpty() check to 
prevent an assertion.
Added support of handling unsigned ranges to RangeSet::Negate and 
RangeSet::getRangeForMinusSymbol.
Extended RangeSet::getRangeForMinusSymbol to return not only range sets with 
single value [n,n], but with wide ranges [n,m].


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77802

Files:
  clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
  clang/test/Analysis/constraint_manager_negate_difference.c

Index: clang/test/Analysis/constraint_manager_negate_difference.c
===
--- clang/test/Analysis/constraint_manager_negate_difference.c
+++ clang/test/Analysis/constraint_manager_negate_difference.c
@@ -110,3 +110,9 @@
   clang_analyzer_eval(m - n == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}}
   clang_analyzer_eval(n - m == 0); // expected-warning{{TRUE}} expected-warning{{FALSE}}
 }
+
+void negated_unsigned_range(unsigned x, unsigned y) {
+  clang_analyzer_eval(x - y != 0); // expected-warning{{FALSE}} expected-warning{{TRUE}}
+  clang_analyzer_eval(y - x != 0); // expected-warning{{FALSE}} expected-warning{{TRUE}}
+  clang_analyzer_eval(x - y != 0); // expected-warning{{FALSE}} expected-warning{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
===
--- clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
+++ clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp
@@ -155,11 +155,11 @@
 // or, alternatively, /removing/ all integers between Upper and Lower.
 RangeSet RangeSet::Intersect(BasicValueFactory &BV, Factory &F,
  llvm::APSInt Lower, llvm::APSInt Upper) const {
-  if (!pin(Lower, Upper))
-return F.getEmptySet();
-
   PrimRangeSet newRanges = F.getEmptySet();
 
+  if (isEmpty() || !pin(Lower, Upper))
+return newRanges;
+
   PrimRangeSet::iterator i = begin(), e = end();
   if (Lower <= Upper)
 IntersectInRange(BV, F, Lower, Upper, newRanges, i, e);
@@ -190,32 +190,54 @@
   return newRanges;
 }
 
-// Turn all [A, B] ranges to [-B, -A]. Ranges [MIN, B] are turned to range set
-// [MIN, MIN] U [-B, MAX], when MIN and MAX are the minimal and the maximal
-// signed values of the type.
+// Turn all [A, B] ranges to [-B, -A], when "-" is a C-like unary minus
+// operation under the values of the type.
+// Negate also restores disrupted ranges on bounds,
+// e.g. [MIN, B] => [MIN, MIN] U [-B, MAX] => [MIN, B]
 RangeSet RangeSet::Negate(BasicValueFactory &BV, Factory &F) const {
   PrimRangeSet newRanges = F.getEmptySet();
 
+  if (isEmpty())
+return newRanges;
+
+  const llvm::APSInt sampleValue = getMinValue();
+  const bool isUnsigned = sampleValue.isUnsigned();
+  const llvm::APSInt &MIN = BV.getMinValue(sampleValue);
+  const llvm::APSInt &MAX = BV.getMaxValue(sampleValue);
+  bool hasNewRangesMinValue = false;
+
   for (iterator i = begin(), e = end(); i != e; ++i) {
-const llvm::APSInt &from = i->From(), &to = i->To();
-const llvm::APSInt &newTo = (from.isMinSignedValue() ?
- BV.getMaxValue(from) :
- BV.getValue(- from));
-if (to.isMaxSignedValue() && !newRanges.isEmpty() &&
-newRanges.begin()->From().isMinSignedValue()) {
-  assert(newRanges.begin()->To().isMinSignedValue() &&
- "Ranges should not overlap");
-  assert(!from.isMinSignedValue() && "Ranges should not overlap");
-  const llvm::APSInt &newFrom = newRanges.begin()->From();
-  newRanges =
-F.add(F.remove(newRanges, *newRanges.begin()), Range(newFrom, newTo));
-} else if (!to.isMinSignedValue()) {
-  const llvm::APSInt &newFrom = BV.getValue(- to);
-  newRanges = F.add(newRanges, Range(newFrom, newTo));
-}
-if (from.isMinSignedValue()) {
-  newRanges = F.add(newRanges, Range(BV.getMinValue(from),
- BV.getMinValue(from)));
+const llvm::APSInt &from = i->From();
+const llvm::APSInt &to = i->To();
+
+const bool isFromMinValue =
+isUnsigned ? from.isMinValue() : from.isMinSignedValue();
+const bool isToMinValue =
+isUnsigned ? to.isMinValue() : to.isMinSignedValue();
+
+// handle a special case for MIN value
+if (isFromMi

[PATCH] D77503: [ASTMatchers] Fixed CastKind being parsed incorrectly for dynamic matchers

2020-04-09 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman 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/D77503/new/

https://reviews.llvm.org/D77503



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


[PATCH] D76360: [PPC][AIX] Emit correct Vaarg for 32BIT-AIX in clang

2020-04-09 Thread Xiangling Liao via Phabricator via cfe-commits
Xiangling_L added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:4205
+
+class PPCAIX32TargetCodeGenInfo : public TargetCodeGenInfo {
+public:

sfertile wrote:
> Xiangling_L wrote:
> > I have a question here. AIX32 falls into PPC32 target, so why we don't 
> > inherit from `PPC32TargetCodeGenInfo` instead?
> Do we need a separate AIX specific class? We are implementing 2 functions, 1 
> of which is the same implementation as its `PPC32TargetCodeGenInfo` 
> counterpart. If we have access to the triple, we can  return true when the OS 
> is AIX in `PPC32TargetCodeGenInfo::initDwarfEHRegSizeTable`. With the 
> implementations being nearly identical (and after enabling 
> DwarfEHRegSizeTable they will be identical) I think we are better to not add 
> a new class if we can avoid it.
Not adding a new class makes sense to me if we are sure that 
`DwarfEHRegSizeTable` will be identical/viable for AIX.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76360



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


[PATCH] D77806: [analyzer] Do not report CFError null dereference for nonnull params

2020-04-09 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko created this revision.
vsavchenko added reviewers: NoQ, dcoughlin.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, 
dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, JDevlieghere, 
szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

We want to trust user type annotations and stop assuming pointers declared
as nonnull still can be null.  This functionality is implemented as part
of NonNullParamChecker because it already checks parameter attributes.
Whenever we start analyzing a new function, we assume that all parameters
with 'nonnull' attribute are indeed non-null.

Depends on D77722 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77806

Files:
  clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  clang/test/Analysis/CheckNSError.m
  clang/test/Analysis/nonnull.cpp

Index: clang/test/Analysis/nonnull.cpp
===
--- /dev/null
+++ clang/test/Analysis/nonnull.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core -verify %s
+
+void nonnull [[gnu::nonnull]] (int *q);
+
+void f1(int *p) {
+  if (p)
+return;
+  nonnull(p); //expected-warning{{nonnull}}
+}
+
+void f2(int *p) {
+  if (p)
+return;
+  auto lambda = [](int *q) __attribute__((nonnull)){};
+  lambda(p); //expected-warning{{nonnull}}
+}
+
+template 
+void variadicNonnull(ARGS... args) __attribute__((nonnull));
+
+void f3(int a, float b, int *p) {
+  if (p)
+return;
+  variadicNonnull(a, b, p); //expected-warning{{nonnull}}
+}
Index: clang/test/Analysis/CheckNSError.m
===
--- clang/test/Analysis/CheckNSError.m
+++ clang/test/Analysis/CheckNSError.m
@@ -62,4 +62,17 @@
   return 0;
 }
 
+int __attribute__((nonnull)) f4(CFErrorRef *error) {
+  *error = 0; // no-warning
+  return 0;
+}
 
+int __attribute__((nonnull(1))) f5(int *x, CFErrorRef *error) {
+  *error = 0; // expected-warning {{Potential null dereference}}
+  return 0;
+}
+
+int __attribute__((nonnull(2))) f6(int *x, CFErrorRef *error) {
+  *error = 0; // no-warning
+  return 0;
+}
Index: clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
@@ -14,8 +14,9 @@
 //
 //===--===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/AST/Attr.h"
+#include "clang/Analysis/AnyCall.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -28,44 +29,78 @@
 
 namespace {
 class NonNullParamChecker
-  : public Checker< check::PreCall, EventDispatcher > {
+: public Checker> {
   mutable std::unique_ptr BTAttrNonNull;
   mutable std::unique_ptr BTNullRefArg;
 
 public:
-
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
+  void checkBeginFunction(CheckerContext &C) const;
 
   std::unique_ptr
-  genReportNullAttrNonNull(const ExplodedNode *ErrorN,
-   const Expr *ArgE,
+  genReportNullAttrNonNull(const ExplodedNode *ErrorN, const Expr *ArgE,
unsigned IdxOfArg) const;
   std::unique_ptr
   genReportReferenceToNullPointer(const ExplodedNode *ErrorN,
   const Expr *ArgE) const;
 };
-} // end anonymous namespace
 
-/// \return Bitvector marking non-null attributes.
-static llvm::SmallBitVector getNonNullAttrs(const CallEvent &Call) {
+template 
+void setBitsAccordingToFunctionAttributes(const CallType &Call,
+  llvm::SmallBitVector &AttrNonNull) {
   const Decl *FD = Call.getDecl();
-  unsigned NumArgs = Call.getNumArgs();
-  llvm::SmallBitVector AttrNonNull(NumArgs);
+
   for (const auto *NonNull : FD->specific_attrs()) {
 if (!NonNull->args_size()) {
-  AttrNonNull.set(0, NumArgs);
+  // Lack of attribute parameters means that all of the parameters are
+  // implicitly marked as non-null.
+  AttrNonNull.set();
   break;
 }
+
 for (const ParamIdx &Idx : NonNull->args()) {
+  // 'nonnull' attribute's parameters are 1-based and should be adjusted to
+  // match actual AST parameter/argument indices.
   unsigned IdxAST = Idx.getASTIndex();
-  if (IdxAST >= NumArgs)
+  if (IdxAST >= AttrNonNull.size())
 continue;
   AttrNonNull.set(IdxAST);
 }
   }
+}
+
+template 
+void setBitsAccordingToParameterAttributes(const CallType &Call,
+   llvm::SmallBitVector &AttrNonNull) {
+  for (const ParmVarDecl *Parameter :

[PATCH] D77391: [analyzer][AnalysisOrder] Display the CallEvent type for preCall/postCall

2020-04-09 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked an inline comment as done.
Szelethus added inline comments.



Comment at: clang/test/Analysis/Inputs/system-header-simulator-cxx.h:971-972
 #else
-void* operator new(std::size_t, const std::nothrow_t&) throw();
-void* operator new[](std::size_t, const std::nothrow_t&) throw();
-void operator delete(void*, const std::nothrow_t&) throw();
-void operator delete[](void*, const std::nothrow_t&) throw();
+// C++20 standard draft 17.6.1, from "Header  synopsis", but with throw()
+// instead of noexcept:
+

NoQ wrote:
> Does it need to be guarded with `#if __cplusplus >= ...` then?
It wasn't guarded before, so I don't think so?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77391



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


[PATCH] D74806: [analyzer] NFCi: Refactor CStringChecker: use strongly typed internal API

2020-04-09 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG30e5c7e82fa1: [analyzer] NFCi: Refactor CStringChecker: use 
strongly typed internal API (authored by steakhal).
Herald added a subscriber: ASDenysPetrov.

Changed prior to commit:
  https://reviews.llvm.org/D74806?vs=245300&id=256301#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74806

Files:
  clang/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  clang/test/Analysis/bsd-string.c
  clang/test/Analysis/bstring.c
  clang/test/Analysis/null-deref-ps-region.c
  clang/test/Analysis/string.c

Index: clang/test/Analysis/string.c
===
--- clang/test/Analysis/string.c
+++ clang/test/Analysis/string.c
@@ -353,7 +353,7 @@
 void strcpy_overflow(char *y) {
   char x[4];
   if (strlen(y) == 4)
-strcpy(x, y); // expected-warning{{String copy function overflows destination buffer}}
+strcpy(x, y); // expected-warning{{String copy function overflows the destination buffer}}
 }
 #endif
 
@@ -394,7 +394,7 @@
 void stpcpy_overflow(char *y) {
   char x[4];
   if (strlen(y) == 4)
-stpcpy(x, y); // expected-warning{{String copy function overflows destination buffer}}
+stpcpy(x, y); // expected-warning{{String copy function overflows the destination buffer}}
 }
 #endif
 
@@ -451,19 +451,19 @@
 void strcat_overflow_0(char *y) {
   char x[4] = "12";
   if (strlen(y) == 4)
-strcat(x, y); // expected-warning{{String copy function overflows destination buffer}}
+strcat(x, y); // expected-warning{{String concatenation function overflows the destination buffer}}
 }
 
 void strcat_overflow_1(char *y) {
   char x[4] = "12";
   if (strlen(y) == 3)
-strcat(x, y); // expected-warning{{String copy function overflows destination buffer}}
+strcat(x, y); // expected-warning{{String concatenation function overflows the destination buffer}}
 }
 
 void strcat_overflow_2(char *y) {
   char x[4] = "12";
   if (strlen(y) == 2)
-strcat(x, y); // expected-warning{{String copy function overflows destination buffer}}
+strcat(x, y); // expected-warning{{String concatenation function overflows the destination buffer}}
 }
 #endif
 
@@ -547,25 +547,28 @@
 // of the C-string checker.
 void cstringchecker_bounds_nocrash() {
   char *p = malloc(2);
-  strncpy(p, "AAA", sizeof("AAA")); // expected-warning {{Size argument is greater than the length of the destination buffer}}
+  strncpy(p, "AAA", sizeof("AAA"));
+  // expected-warning@-1 {{String copy function overflows the destination buffer}}
   free(p);
 }
 
 void strncpy_overflow(char *y) {
   char x[4];
   if (strlen(y) == 4)
-strncpy(x, y, 5); // expected-warning{{Size argument is greater than the length of the destination buffer}}
+strncpy(x, y, 5);
+// expected-warning@-1 {{String copy function overflows the destination buffer}}
 #ifndef VARIANT
-  // expected-warning@-2{{size argument is too large; destination buffer has size 4, but size argument is 5}}
+// expected-warning@-3 {{size argument is too large; destination buffer has size 4, but size argument is 5}}
 #endif
 }
 
 void strncpy_no_overflow(char *y) {
   char x[4];
   if (strlen(y) == 3)
-strncpy(x, y, 5); // expected-warning{{Size argument is greater than the length of the destination buffer}}
+strncpy(x, y, 5);
+// expected-warning@-1 {{String copy function overflows the destination buffer}}
 #ifndef VARIANT
-  // expected-warning@-2{{size argument is too large; destination buffer has size 4, but size argument is 5}}
+// expected-warning@-3 {{size argument is too large; destination buffer has size 4, but size argument is 5}}
 #endif
 }
 
@@ -575,7 +578,8 @@
 
   char x[4];
   if (strlen(y) == 3)
-strncpy(x, y, n); // expected-warning{{Size argument is greater than the length of the destination buffer}}
+strncpy(x, y, n);
+  // expected-warning@-1 {{String copy function overflows the destination buffer}}
 }
 #endif
 
@@ -658,25 +662,29 @@
 void strncat_overflow_0(char *y) {
   char x[4] = "12";
   if (strlen(y) == 4)
-strncat(x, y, strlen(y)); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
+strncat(x, y, strlen(y));
+  // expected-warning@-1 {{String concatenation function overflows the destination buffer}}
 }
 
 void strncat_overflow_1(char *y) {
   char x[4] = "12";
   if (strlen(y) == 3)
-strncat(x, y, strlen(y)); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
+strncat(x, y, strlen(y));
+  // expected-warning@-1 {{String concatenation function overflows the destination buffer}}
 }
 
 void strncat_overflow_2(char *y) {
   char x[4] = "12";
   if (strlen(y) == 2)
-strncat(x, y, strlen(y)); // expected-warning{{Size argument is greater than the free space in the destination buffer}}
+strncat(x, y, strlen(y));

[PATCH] D77503: [ASTMatchers] Fixed CastKind being parsed incorrectly for dynamic matchers

2020-04-09 Thread Nathan James via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdb71354e4ff1: [ASTMatchers] Fixed CastKind being parsed 
incorrectly for dynamic matchers (authored by njames93).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77503

Files:
  clang/docs/LibASTMatchersReference.html
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
  clang/lib/ASTMatchers/Dynamic/Marshallers.h
  clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp


Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -221,6 +221,15 @@
   EXPECT_FALSE(matches("int x = 1 - false;", M));
   EXPECT_FALSE(matches("int x = true - 1;", M));
 
+  Code = "implicitCastExpr(hasCastKind(\"CK_IntegralToBoolean\"))";
+  llvm::Optional implicitIntBooleanCast(
+  Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error));
+  EXPECT_EQ("", Error.toStringFull());
+  Matcher MCastStmt =
+  implicitIntBooleanCast->unconditionalConvertTo();
+  EXPECT_TRUE(matches("bool X = 1;", MCastStmt));
+  EXPECT_FALSE(matches("bool X = true;", MCastStmt));
+
   Code = "functionDecl(hasParameter(1, hasName(\"x\")))";
   llvm::Optional HasParameter(
   Parser::parseMatcherExpression(Code, &Error));
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -171,7 +171,7 @@
 private:
   static Optional getCastKind(llvm::StringRef AttrKind) {
 return llvm::StringSwitch>(AttrKind)
-#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
+#define CAST_OPERATION(Name) .Case("CK_" #Name, CK_##Name)
 #include "clang/AST/OperationKinds.def"
 .Default(llvm::None);
   }
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
@@ -75,11 +75,12 @@
 clang::ast_matchers::dynamic::internal::ArgTypeTraits<
 clang::CastKind>::getBestGuess(const VariantValue &Value) {
   static constexpr llvm::StringRef Allowed[] = {
-#define CAST_OPERATION(Name) #Name,
+#define CAST_OPERATION(Name) "CK_" #Name,
 #include "clang/AST/OperationKinds.def"
   };
   if (Value.isString())
-return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed));
+return ::getBestGuess(Value.getString(), llvm::makeArrayRef(Allowed),
+  "CK_");
   return llvm::None;
 }
 
Index: clang/include/clang/ASTMatchers/ASTMatchers.h
===
--- clang/include/clang/ASTMatchers/ASTMatchers.h
+++ clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -4913,7 +4913,7 @@
 /// \endcode
 ///
 /// If the matcher is use from clang-query, CastKind parameter
-/// should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
+/// should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
 AST_MATCHER_P(CastExpr, hasCastKind, CastKind, Kind) {
   return Node.getCastKind() == Kind;
 }
Index: clang/docs/LibASTMatchersReference.html
===
--- clang/docs/LibASTMatchersReference.html
+++ clang/docs/LibASTMatchersReference.html
@@ -2790,7 +2790,7 @@
   int *p = 0;
 
 If the matcher is use from clang-query, CastKind parameter
-should be passed as a quoted string. e.g., ofKind("CK_NullToPointer").
+should be passed as a quoted string. e.g., hasCastKind("CK_NullToPointer").
 
 
 


Index: clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
===
--- clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ clang/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -221,6 +221,15 @@
   EXPECT_FALSE(matches("int x = 1 - false;", M));
   EXPECT_FALSE(matches("int x = true - 1;", M));
 
+  Code = "implicitCastExpr(hasCastKind(\"CK_IntegralToBoolean\"))";
+  llvm::Optional implicitIntBooleanCast(
+  Parser::parseMatcherExpression(Code, nullptr, nullptr, &Error));
+  EXPECT_EQ("", Error.toStringFull());
+  Matcher MCastStmt =
+  implicitIntBooleanCast->unconditionalConvertTo();
+  EXPECT_TRUE(matches("bool X = 1;", MCastStmt));
+  EXPECT_FALSE(matches("bool X = true;", MCastStmt));
+
   Code = "functionDecl(hasParameter(1, hasName(\"x\")))";
   llvm::Optional HasParameter(
   Parser::parseMatcherExpression(Code, &Error));
Index: clang/lib/ASTMatchers/Dynamic/Marshallers.h
===
--- clang/lib/ASTMatchers/Dynamic/Marshallers.h
+++ clang/lib/ASTMatchers/Dynamic/Marshallers.h
@@ -17

[PATCH] D76605: [analyzer] Display the checker name in the text output

2020-04-09 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa2b6ece1fd4e: [analyzer] Display the checker name in the 
text output (authored by Szelethus).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76605

Files:
  clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.def
  clang/lib/StaticAnalyzer/Core/TextDiagnostics.cpp
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/dispatch-once.m
  clang/test/Analysis/explain-svals.c
  clang/test/Analysis/explain-svals.cpp
  clang/test/Analysis/explain-svals.m
  clang/test/Analysis/incorrect-checker-names.cpp
  clang/test/Analysis/incorrect-checker-names.mm

Index: clang/test/Analysis/incorrect-checker-names.mm
===
--- /dev/null
+++ clang/test/Analysis/incorrect-checker-names.mm
@@ -0,0 +1,116 @@
+// RUN: %clang_analyze_cc1 -fblocks -verify %s -Wno-objc-root-class \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=nullability \
+// RUN:   -analyzer-checker=osx
+
+#include "Inputs/system-header-simulator-for-nullability.h"
+#include "os_object_base.h"
+
+struct OSIterator : public OSObject {
+  static const OSMetaClass * const metaClass;
+};
+
+@interface TestObject : NSObject
+- (int *_Nonnull)returnsNonnull;
+- (int *_Nullable)returnsNullable;
+- (int *)returnsUnspecified;
+- (void)takesNonnull:(int *_Nonnull)p;
+- (void)takesNullable:(int *_Nullable)p;
+- (void)takesUnspecified:(int *)p;
+@property(readonly, strong) NSString *stuff;
+@end
+
+TestObject * getUnspecifiedTestObject();
+TestObject *_Nonnull getNonnullTestObject();
+TestObject *_Nullable getNullableTestObject();
+
+int getRandom();
+
+typedef struct Dummy { int val; } Dummy;
+
+void takesNullable(Dummy *_Nullable);
+void takesNonnull(Dummy *_Nonnull);
+void takesUnspecified(Dummy *);
+
+Dummy *_Nullable returnsNullable();
+Dummy *_Nonnull returnsNonnull();
+Dummy *returnsUnspecified();
+int *_Nullable returnsNullableInt();
+
+template  T *eraseNullab(T *p) { return p; }
+
+void takesAttrNonnull(Dummy *p) __attribute((nonnull(1)));
+
+void testBasicRules() {
+  // FIXME: None of these should be tied to a modeling checker.
+  Dummy *p = returnsNullable();
+  int *ptr = returnsNullableInt();
+  // Make every dereference a different path to avoid sinks after errors.
+  switch (getRandom()) {
+  case 0: {
+Dummy &r = *p; // expected-warning {{Nullable pointer is dereferenced [nullability.NullabilityBase]}}
+  } break;
+  case 1: {
+int b = p->val; // expected-warning {{Nullable pointer is dereferenced [nullability.NullabilityBase]}}
+  } break;
+  case 2: {
+int stuff = *ptr; // expected-warning {{Nullable pointer is dereferenced [nullability.NullabilityBase]}}
+  } break;
+  case 3:
+takesNonnull(p); // expected-warning {{Nullable pointer is passed to a callee that requires a non-null 1st parameter [nullability.NullabilityBase]}}
+break;
+  case 4: {
+Dummy d;
+takesNullable(&d);
+Dummy dd(d);
+break;
+  }
+  case 5: takesAttrNonnull(p); break; // expected-warning {{Nullable pointer is passed to a callee that requires a non-null [nullability.NullabilityBase]}}
+  default: { Dummy d = *p; } break; // expected-warning {{Nullable pointer is dereferenced [nullability.NullabilityBase]}}
+  }
+  if (p) {
+takesNonnull(p);
+if (getRandom()) {
+  Dummy &r = *p;
+} else {
+  int b = p->val;
+}
+  }
+  Dummy *q = 0;
+  if (getRandom()) {
+takesNullable(q);
+  // FIXME: This shouldn't be tied to a modeling checker.
+takesNonnull(q); // expected-warning {{Null passed to a callee that requires a non-null 1st parameter [nullability.NullabilityBase]}}
+  }
+  Dummy a;
+  Dummy *_Nonnull nonnull = &a;
+  // FIXME: This shouldn't be tied to a modeling checker.
+  nonnull = q; // expected-warning {{Null assigned to a pointer which is expected to have non-null value [nullability.NullabilityBase]}}
+  q = &a;
+  takesNullable(q);
+  takesNonnull(q);
+}
+
+typedef int NSInteger;
+typedef struct _NSZone NSZone;
+@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
+@class NSDictionary;
+@interface NSError : NSObject  {}
++ (id)errorWithDomain:(NSString *)domain code:(NSInteger)code userInfo:(NSDictionary *)dict;
+@end
+
+struct __CFError {};
+typedef struct __CFError* CFErrorRef;
+
+void foo(CFErrorRef* error) { // expected-warning{{Function accepting CFErrorRef* should have a non-void return value to indicate whether or not an error occurred [osx.coreFoundation.CFError]}}
+  // FIXME: This shouldn't be tied to a modeling checker.
+  *error = 0;  // expected-warning {{Potential null dereference.  According to coding standards documented in CoreFoundation/CFError.h the parameter may be null [osx.NSOrCFErrorDerefChecker]}}
+}
+
+bool write_into_out_param_on_success(OS_RETURNS_RETAINED OSObject **obj);
+
+void use_out_param_leak() {

[PATCH] D77391: [analyzer][AnalysisOrder] Display the CallEvent type for preCall/postCall

2020-04-09 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus marked 2 inline comments as done.
Szelethus added inline comments.



Comment at: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h:202
   virtual Kind getKind() const = 0;
+  virtual StringRef getKindAsString() const = 0;
 

NoQ wrote:
> Maybe make a `static StringRef getKindAsString(Kind);` in the base class and 
> defer to it instead so that they all were in one place near the enum itself?
> 
> (i'm not sure it's actually better)
Well, each of these kinds are tied to a `CallEvent` class, so this made sense 
when I wrote it. I think these approaches are equivalent, so I'll stick with 
this one if you don't mind :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77391



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


[clang] 56c3b2b - [OPENMP]Fix capturing of global variables in OpenMP regions.

2020-04-09 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-04-09T10:36:09-04:00
New Revision: 56c3b2b091bf94ed5c3d614f3d10e8e973a72d17

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

LOG: [OPENMP]Fix capturing of global variables in OpenMP regions.

Summary:
The global variable should be captured in the region only if it was
privitized in the region or in any of the outer regions. Otherwise, it
should not be captured.

Reviewers: jdoerfert

Subscribers: yaxunl, guansong, cfe-commits, caomhin

Tags: #clang

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6718656f6133..c675672f4f29 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2110,21 +2110,22 @@ VarDecl *Sema::isOpenMPCapturedDecl(ValueDecl *D, bool 
CheckScopeInfo,
  isImplicitOrExplicitTaskingRegion(DSAStack->getCurrentDirective())) ||
 (VD && DSAStack->isForceVarCapturing()))
   return VD ? VD : Info.second;
-DSAStackTy::DSAVarData DVarPrivate =
+DSAStackTy::DSAVarData DVarTop =
 DSAStack->getTopDSA(D, DSAStack->isClauseParsingMode());
-if (DVarPrivate.CKind != OMPC_unknown && 
isOpenMPPrivate(DVarPrivate.CKind))
-  return VD ? VD : cast(DVarPrivate.PrivateCopy->getDecl());
+if (DVarTop.CKind != OMPC_unknown && isOpenMPPrivate(DVarTop.CKind))
+  return VD ? VD : cast(DVarTop.PrivateCopy->getDecl());
 // Threadprivate variables must not be captured.
-if (isOpenMPThreadPrivate(DVarPrivate.CKind))
-  return nullptr;
-// Global shared must not be captured.
-if (VD && !VD->hasLocalStorage() && DVarPrivate.CKind == OMPC_shared)
+if (isOpenMPThreadPrivate(DVarTop.CKind))
   return nullptr;
 // The variable is not private or it is the variable in the directive with
 // default(none) clause and not used in any clause.
-DVarPrivate = DSAStack->hasDSA(D, isOpenMPPrivate,
-   [](OpenMPDirectiveKind) { return true; },
-   DSAStack->isClauseParsingMode());
+DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
+D, isOpenMPPrivate, [](OpenMPDirectiveKind) { return true; },
+DSAStack->isClauseParsingMode());
+// Global shared must not be captured.
+if (VD && !VD->hasLocalStorage() && DVarPrivate.CKind == OMPC_unknown &&
+(DSAStack->getDefaultDSA() != DSA_none || DVarTop.CKind == 
OMPC_shared))
+  return nullptr;
 if (DVarPrivate.CKind != OMPC_unknown ||
 (VD && DSAStack->getDefaultDSA() == DSA_none))
   return VD ? VD : cast(DVarPrivate.PrivateCopy->getDecl());

diff  --git a/clang/test/OpenMP/parallel_codegen.cpp 
b/clang/test/OpenMP/parallel_codegen.cpp
index d42312193709..b38e9ae706bd 100644
--- a/clang/test/OpenMP/parallel_codegen.cpp
+++ b/clang/test/OpenMP/parallel_codegen.cpp
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -triple 
%itanium_abi_triple -fexceptions -fcxx-exceptions -o - | FileCheck %s 
--check-prefixes=ALL,CHECK
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s 
-emit-llvm -o - | FileCheck --check-prefixes=ALL-DEBUG,CHECK-DEBUG %s
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ 
-emit-llvm %s -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -o - | 
FileCheck %s --check-prefixes=ALL,IRBUILDER
-// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -std=c++11 
-triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
--check-prefixes=ALL-DEBUG,IRBUILDER-DEBUG %s
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -DIRBUILDER -x 
c++ -emit-llvm %s -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -o 
- | FileCheck %s --check-prefixes=ALL,IRBUILDER
+// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -DIRBUILDER -x c++ 
-std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -DIRBUILDER -x c++ 
-triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions 
-debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - 
| FileCheck --check-prefixes=ALL

[clang] 023c4d4 - [analyzer][AnalysisOrderChecker] Display the CallEvent type in preCall/postCall

2020-04-09 Thread Kirstóf Umann via cfe-commits

Author: Kirstóf Umann
Date: 2020-04-09T16:41:07+02:00
New Revision: 023c4d400ef5acf3a7339dc8452ce552b15a9ae4

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

LOG: [analyzer][AnalysisOrderChecker] Display the CallEvent type in 
preCall/postCall

Exactly what it says on the tin! The included testfile demonstrates why this is
important -- for C++ dynamic memory operators, we don't always recognize custom,
or even standard-specified new/delete operators as CXXAllocatorCall or
CXXDeallocatorCall.

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

Added: 
clang/test/Analysis/cxx-dynamic-memory-analysis-order.cpp

Modified: 
clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
clang/lib/StaticAnalyzer/Core/CallEvent.cpp
clang/test/Analysis/Inputs/system-header-simulator-cxx.h
clang/test/Analysis/analyzer-config.c
clang/test/Analysis/diagnostics/explicit-suppression.cpp

Removed: 




diff  --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td 
b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
index 31e7e02c192b..4315b0984abc 100644
--- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -1275,6 +1275,30 @@ def AnalysisOrderChecker : Checker<"AnalysisOrder">,
   "false",
   Released,
   Hide>,
+CmdLineOption,
+CmdLineOption,
+CmdLineOption,
+CmdLineOption,
 CmdLineOption,
   "false",
   Released,
   Hide>,
+CmdLineOption,
 CmdLineOptiongetKind() == CE_Function;
@@ -634,13 +638,12 @@ class BlockCall : public CallEvent {
   void getInitialStackFrameContents(const StackFrameContext *CalleeCtx,
 BindingsTy &Bindings) const override;
 
-  ArrayRef parameters() const override;
+  ArrayRef parameters() const override;
 
   Kind getKind() const override { return CE_Block; }
+  virtual StringRef getKindAsString() const override { return "BlockCall"; }
 
-  static bool classof(const CallEvent *CA) {
-return CA->getKind() == CE_Block;
-  }
+  static bool classof(const CallEvent *CA) { return CA->getKind() == CE_Block; 
}
 };
 
 /// Represents a non-static C++ member function call, no matter how
@@ -712,6 +715,7 @@ class CXXMemberCall : public CXXInstanceCall {
   RuntimeDefinition getRuntimeDefinition() const override;
 
   Kind getKind() const override { return CE_CXXMember; }
+  virtual StringRef getKindAsString() const override { return "CXXMemberCall"; 
}
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXMember;
@@ -751,6 +755,9 @@ class CXXMemberOperatorCall : public CXXInstanceCall {
   const Expr *getCXXThisExpr() const override;
 
   Kind getKind() const override { return CE_CXXMemberOperator; }
+  virtual StringRef getKindAsString() const override {
+return "CXXMemberOperatorCall";
+  }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXMemberOperator;
@@ -815,6 +822,9 @@ class CXXDestructorCall : public CXXInstanceCall {
   }
 
   Kind getKind() const override { return CE_CXXDestructor; }
+  virtual StringRef getKindAsString() const override {
+return "CXXDestructorCall";
+  }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXDestructor;
@@ -887,6 +897,9 @@ class CXXConstructorCall : public AnyCXXConstructorCall {
   }
 
   Kind getKind() const override { return CE_CXXConstructor; }
+  virtual StringRef getKindAsString() const override {
+return "CXXConstructorCall";
+  }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXConstructor;
@@ -964,6 +977,9 @@ class CXXInheritedConstructorCall : public 
AnyCXXConstructorCall {
   }
 
   Kind getKind() const override { return CE_CXXInheritedConstructor; }
+  virtual StringRef getKindAsString() const override {
+return "CXXInheritedConstructorCall";
+  }
 
   static bool classof(const CallEvent *CA) {
 return CA->getKind() == CE_CXXInheritedConstructor;
@@ -1020,6 +1036,9 @@ class CXXAllocatorCall : public AnyFunctionCall {
   }
 
   Kind getKind() const override { return CE_CXXAllocator; }
+  virtual StringRef getKindAsString() const override {
+return "CXXAllocatorCall";
+  }
 
   static bool classof(const CallEvent *CE) {
 return CE->getKind() == CE_CXXAllocator;
@@ -1143,6 +1162,9 @@ class ObjCMethodCall : public CallEvent {
   ArrayRef parameters() const override;
 
   Kind getKind() const override { return CE_ObjCMessage; }
+  virtual StringRef getKindAsString() const override {

[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-04-09 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1500
+  if (cast(Name)->hasContainingCsect())
+emitLinkage(&F, Name);
+

DiggerLin wrote:
> jasonliu wrote:
> > DiggerLin wrote:
> > > jasonliu wrote:
> > > > 1. We need to rebase here, as it is called `hasRepresentedCsectSet()` 
> > > > instead of `hasContainingCsect()` now.
> > > > 2. I'm slightly worried here to rely on `hasRepresentedCsectSet()` to 
> > > > check if a linkage should be emitted. This is based on the assumption 
> > > > that we will not ever change our implementation for `.bl foo` to `.bl 
> > > > foo[PR]`. But in https://reviews.llvm.org/D77080#inline-706207, we 
> > > > discussed about this possibility. So this assumption might not be true 
> > > > in the future. However, I'm not sure if there is another way to check 
> > > > if this function have been called directly. 
> > > > So if there is another way to check, we should pursue the alternative 
> > > > instead. If there is not, then we need to add an assert here, like 
> > > > `assert(Name->getName().equals(cast(Name)->getUnqualifiedName())`
> > > >  to make sure we don't get a qualname here. 
> > > > 3. 
> > > > Have a comment here and tell people what we are doing here.
> > > > For example, 
> > > > // If there is a direct call to external function, then we need to emit 
> > > > linkage for its function entry point. 
> > > when we implement .bl foo to .bl foo[PR]
> > > the SymbolName will change from .bl[SMC] and check the 
> > > .bl[SMC]->hasRepresentedCsectSet()
> > Yes, but foo[PR]->hasRepresentedCsectSet() will always return true, because 
> > whenever we created a qualname will always have csect set. How will we know 
> > if foo() function is called directly then? 
> we only deal with extern function(we do not deal with definition function) 
> here, for extern function, it not always has MCSectionXCOFF, it only create 
> the extern function be called directly in the 
> llvm/lib/CodeGen/MachineModuleInfo.cpp line 108~116, unless we delete the 
> code later. if the code is not changed. for extern function foo , the 
> .foo[PR] -> hasRepresentedCsectSet()  when directly call. otherwise false.
Okk. I think I got what you mean. If .foo[PR] is created then it means there is 
a direct call. Otherwise, we will not have a .foo[PR], and of course that newly 
created .foo[PR] will not have a RepresentedCsect.
Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932



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


[PATCH] D73891: [RISCV] Support experimental/unratified extensions

2020-04-09 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

I've approved D65649  now, so I think this one 
can land as soon as that one does.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73891



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


[PATCH] D77806: [analyzer] Do not report CFError null dereference for nonnull params

2020-04-09 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 256306.
vsavchenko added a comment.

Add one more test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77806

Files:
  clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  clang/test/Analysis/CheckNSError.m
  clang/test/Analysis/nonnull.cpp

Index: clang/test/Analysis/nonnull.cpp
===
--- /dev/null
+++ clang/test/Analysis/nonnull.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core -verify %s
+
+void nonnull [[gnu::nonnull]] (int *q);
+
+void f1(int *p) {
+  if (p)
+return;
+  nonnull(p); //expected-warning{{nonnull}}
+}
+
+void f2(int *p) {
+  if (p)
+return;
+  auto lambda = [](int *q) __attribute__((nonnull)){};
+  lambda(p); //expected-warning{{nonnull}}
+}
+
+template 
+void variadicNonnull(ARGS... args) __attribute__((nonnull));
+
+void f3(int a, float b, int *p) {
+  if (p)
+return;
+  variadicNonnull(a, b, p); //expected-warning{{nonnull}}
+}
+
+int globalVar = 15;
+void moreParamsThanArgs [[gnu::nonnull(2, 4)]] (int a, int *p, int b = 42, int *q = &globalVar);
+
+void f4(int a, int *p) {
+  if (p)
+return;
+  moreParamsThanArgs(a, p); //expected-warning{{nonnull}}
+}
Index: clang/test/Analysis/CheckNSError.m
===
--- clang/test/Analysis/CheckNSError.m
+++ clang/test/Analysis/CheckNSError.m
@@ -62,4 +62,17 @@
   return 0;
 }
 
+int __attribute__((nonnull)) f4(CFErrorRef *error) {
+  *error = 0; // no-warning
+  return 0;
+}
 
+int __attribute__((nonnull(1))) f5(int *x, CFErrorRef *error) {
+  *error = 0; // expected-warning {{Potential null dereference}}
+  return 0;
+}
+
+int __attribute__((nonnull(2))) f6(int *x, CFErrorRef *error) {
+  *error = 0; // no-warning
+  return 0;
+}
Index: clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
@@ -14,8 +14,9 @@
 //
 //===--===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/AST/Attr.h"
+#include "clang/Analysis/AnyCall.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -28,44 +29,78 @@
 
 namespace {
 class NonNullParamChecker
-  : public Checker< check::PreCall, EventDispatcher > {
+: public Checker> {
   mutable std::unique_ptr BTAttrNonNull;
   mutable std::unique_ptr BTNullRefArg;
 
 public:
-
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
+  void checkBeginFunction(CheckerContext &C) const;
 
   std::unique_ptr
-  genReportNullAttrNonNull(const ExplodedNode *ErrorN,
-   const Expr *ArgE,
+  genReportNullAttrNonNull(const ExplodedNode *ErrorN, const Expr *ArgE,
unsigned IdxOfArg) const;
   std::unique_ptr
   genReportReferenceToNullPointer(const ExplodedNode *ErrorN,
   const Expr *ArgE) const;
 };
-} // end anonymous namespace
 
-/// \return Bitvector marking non-null attributes.
-static llvm::SmallBitVector getNonNullAttrs(const CallEvent &Call) {
+template 
+void setBitsAccordingToFunctionAttributes(const CallType &Call,
+  llvm::SmallBitVector &AttrNonNull) {
   const Decl *FD = Call.getDecl();
-  unsigned NumArgs = Call.getNumArgs();
-  llvm::SmallBitVector AttrNonNull(NumArgs);
+
   for (const auto *NonNull : FD->specific_attrs()) {
 if (!NonNull->args_size()) {
-  AttrNonNull.set(0, NumArgs);
+  // Lack of attribute parameters means that all of the parameters are
+  // implicitly marked as non-null.
+  AttrNonNull.set();
   break;
 }
+
 for (const ParamIdx &Idx : NonNull->args()) {
+  // 'nonnull' attribute's parameters are 1-based and should be adjusted to
+  // match actual AST parameter/argument indices.
   unsigned IdxAST = Idx.getASTIndex();
-  if (IdxAST >= NumArgs)
+  if (IdxAST >= AttrNonNull.size())
 continue;
   AttrNonNull.set(IdxAST);
 }
   }
+}
+
+template 
+void setBitsAccordingToParameterAttributes(const CallType &Call,
+   llvm::SmallBitVector &AttrNonNull) {
+  for (const ParmVarDecl *Parameter : Call.parameters()) {
+if (Parameter->hasAttr())
+  AttrNonNull.set(Parameter->getFunctionScopeIndex());
+  }
+}
+
+template 
+llvm::SmallBitVector getNonNullAttrsImpl(const CallType &Call,
+ unsigned ExpectedSize) {
+  llvm::SmallBitVector AttrN

[PATCH] D77728: [Driver][X86] Add an alias for -mpad-max-prefix-size

2020-04-09 Thread Kan Shengchen via Phabricator via cfe-commits
skan updated this revision to Diff 256308.
skan added a comment.

Fix the tests after rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77728

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/x86-malign-branch.c
  clang/test/Driver/x86-malign-branch.s


Index: clang/test/Driver/x86-malign-branch.s
===
--- clang/test/Driver/x86-malign-branch.s
+++ clang/test/Driver/x86-malign-branch.s
@@ -9,5 +9,7 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX
 // PREFIX: "-mllvm" "-x86-pad-max-prefix-size=5"
 
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX
+
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 
| FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/test/Driver/x86-malign-branch.c
===
--- clang/test/Driver/x86-malign-branch.c
+++ clang/test/Driver/x86-malign-branch.c
@@ -24,6 +24,9 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=15 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-15
 // PREFIX-15: "-mllvm" "-x86-pad-max-prefix-size=15"
 
+/// Test -malign-branch-prefix-size= for GCC compatibilty
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=15 %s -c -### 2>&1 | 
FileCheck %s --check-prefix=PREFIX-15
+
 /// Test -mbranches-within-32B-boundaries
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 
| FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2189,6 +2189,8 @@
   HelpText<"Specify the boundary's size to align branches">;
 def mpad_max_prefix_size_EQ : Joined<["-"], "mpad-max-prefix-size=">, 
Group, Flags<[DriverOption]>,
   HelpText<"Specify maximum number of prefixes to use for padding">;
+def malign_branch_prefix_size_EQ : Joined<["-"], 
"malign-branch-prefix-size=">, Group, Flags<[DriverOption]>, 
Alias,
+  HelpText<"Alias for -mpad-max-prefix-size">;// Alias for GCC compatibility
 def mbranches_within_32B_boundaries : Flag<["-"], 
"mbranches-within-32B-boundaries">, Flags<[DriverOption]>, Group,
   HelpText<"Align selected branches (fused, jcc, jmp) within 32-byte 
boundary">;
 def mfancy_math_387 : Flag<["-"], "mfancy-math-387">, 
Group;


Index: clang/test/Driver/x86-malign-branch.s
===
--- clang/test/Driver/x86-malign-branch.s
+++ clang/test/Driver/x86-malign-branch.s
@@ -9,5 +9,7 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX
 // PREFIX: "-mllvm" "-x86-pad-max-prefix-size=5"
 
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=5 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX
+
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/test/Driver/x86-malign-branch.c
===
--- clang/test/Driver/x86-malign-branch.c
+++ clang/test/Driver/x86-malign-branch.c
@@ -24,6 +24,9 @@
 // RUN: %clang -target x86_64 -mpad-max-prefix-size=15 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-15
 // PREFIX-15: "-mllvm" "-x86-pad-max-prefix-size=15"
 
+/// Test -malign-branch-prefix-size= for GCC compatibilty
+// RUN: %clang -target x86_64 -malign-branch-prefix-size=15 %s -c -### 2>&1 | FileCheck %s --check-prefix=PREFIX-15
+
 /// Test -mbranches-within-32B-boundaries
 // RUN: %clang -target x86_64 -mbranches-within-32B-boundaries %s -c -### 2>&1 | FileCheck %s --check-prefix=32B
 // 32B: "-mllvm" "-x86-branches-within-32B-boundaries"
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2189,6 +2189,8 @@
   HelpText<"Specify the boundary's size to align branches">;
 def mpad_max_prefix_size_EQ : Joined<["-"], "mpad-max-prefix-size=">, Group, Flags<[DriverOption]>,
   HelpText<"Specify maximum number of prefixes to use for padding">;
+def malign_branch_prefix_size_EQ : Joined<["-"], "malign-branch-prefix-size=">, Group, Flags<[DriverOption]>, Alias,
+  HelpText<"Alias for -mpad-max-prefix-size">;// Alias for GCC compatibility
 def mbranches_within_32B_boundaries : Flag<["-"], "mbranches-within-32B-boundaries">, Flags<[DriverOption]>, Group,
   HelpText<"Align selected branches (fused, jcc, jmp) within 32-byte boundary">;
 de

[PATCH] D77305: [Analyzer][VLASize] Support multi-dimensional arrays.

2020-04-09 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 256307.
balazske marked 3 inline comments as done.
balazske added a comment.

Small renamings and reformatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77305

Files:
  clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
  clang/test/Analysis/vla.c

Index: clang/test/Analysis/vla.c
===
--- clang/test/Analysis/vla.c
+++ clang/test/Analysis/vla.c
@@ -1,4 +1,8 @@
-// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-checker=debug.ExprInspection -verify %s
+
+typedef unsigned long size_t;
+size_t clang_analyzer_getExtent(void *);
+void clang_analyzer_eval(int);
 
 // Zero-sized VLAs.
 void check_zero_sized_VLA(int x) {
@@ -84,3 +88,41 @@
   if (x > 0)
 check_negative_sized_VLA_11_sub(x);
 }
+
+// Multi-dimensional arrays.
+
+void check_zero_sized_VLA_multi1(int x) {
+  if (x)
+return;
+
+  int vla[10][x]; // expected-warning{{Declared variable-length array (VLA) has zero size}}
+}
+
+void check_zero_sized_VLA_multi2(int x, int y) {
+  if (x)
+return;
+
+  int vla[y][x]; // expected-warning{{Declared variable-length array (VLA) has zero size}}
+}
+
+// Check the extent.
+
+void check_VLA_extent() {
+  int x = 3;
+
+  int vla1[x];
+  clang_analyzer_eval(clang_analyzer_getExtent(&vla1) == x * sizeof(int));
+  // expected-warning@-1{{TRUE}}
+
+  int vla2[x][2];
+  clang_analyzer_eval(clang_analyzer_getExtent(&vla2) == x * 2 * sizeof(int));
+  // expected-warning@-1{{TRUE}}
+
+  int vla2m[2][x];
+  clang_analyzer_eval(clang_analyzer_getExtent(&vla2m) == 2 * x * sizeof(int));
+  // expected-warning@-1{{TRUE}}
+
+  int vla3m[2][x][4];
+  clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) == 2 * x * 4 * sizeof(int));
+  // expected-warning@-1{{TRUE}}
+}
Index: clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/VLASizeChecker.cpp
@@ -34,6 +34,9 @@
   mutable std::unique_ptr BT;
   enum VLASize_Kind { VLA_Garbage, VLA_Zero, VLA_Tainted, VLA_Negative };
 
+  ProgramStateRef checkVLASize(CheckerContext &C, ProgramStateRef State,
+   const Expr *SizeE) const;
+
   void reportBug(VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State,
  CheckerContext &C,
  std::unique_ptr Visitor = nullptr) const;
@@ -43,6 +46,65 @@
 };
 } // end anonymous namespace
 
+ProgramStateRef VLASizeChecker::checkVLASize(CheckerContext &C,
+ ProgramStateRef State,
+ const Expr *SizeE) const {
+  SVal SizeV = C.getSVal(SizeE);
+
+  if (SizeV.isUndef()) {
+reportBug(VLA_Garbage, SizeE, State, C);
+return nullptr;
+  }
+
+  // See if the size value is known. It can't be undefined because we would have
+  // warned about that already.
+  if (SizeV.isUnknown())
+return nullptr;
+
+  // Check if the size is tainted.
+  if (isTainted(State, SizeV)) {
+reportBug(VLA_Tainted, SizeE, nullptr, C,
+  std::make_unique(SizeV));
+return nullptr;
+  }
+
+  // Check if the size is zero.
+  DefinedSVal SizeD = SizeV.castAs();
+
+  ProgramStateRef StateNotZero, StateZero;
+  std::tie(StateNotZero, StateZero) = State->assume(SizeD);
+
+  if (StateZero && !StateNotZero) {
+reportBug(VLA_Zero, SizeE, StateZero, C);
+return nullptr;
+  }
+
+  // From this point on, assume that the size is not zero.
+  State = StateNotZero;
+
+  // Check if the size is negative.
+  SValBuilder &SVB = C.getSValBuilder();
+
+  QualType SizeTy = SizeE->getType();
+  DefinedOrUnknownSVal Zero = SVB.makeZeroVal(SizeTy);
+
+  SVal LessThanZeroVal = SVB.evalBinOp(State, BO_LT, SizeD, Zero, SizeTy);
+  if (Optional LessThanZeroDVal =
+  LessThanZeroVal.getAs()) {
+ConstraintManager &CM = C.getConstraintManager();
+ProgramStateRef StatePos, StateNeg;
+
+std::tie(StateNeg, StatePos) = CM.assumeDual(State, *LessThanZeroDVal);
+if (StateNeg && !StatePos) {
+  reportBug(VLA_Negative, SizeE, State, C); // FIXME: StateNeg ?
+  return nullptr;
+}
+State = StatePos;
+  }
+
+  return State;
+}
+
 void VLASizeChecker::reportBug(
 VLASize_Kind Kind, const Expr *SizeE, ProgramStateRef State,
 CheckerContext &C, std::unique_ptr Visitor) const {
@@ -89,98 +151,72 @@
 return;
 
   ASTContext &Ctx = C.getASTContext();
+  SValBuilder &SVB = C.getSValBuilder();
+  ProgramStateRef State = C.getState();
+
   const VariableArrayType *VLA = Ctx.getAsVariableArrayType(VD->getType());
   if (!VLA)
 return;
 
-  // FIXME: Handle multi-dimensional VLAs.
-  const Expr *SE = VLA->getSizeExpr();
-  ProgramStateRef state = C.getState();
-  SVal s

[PATCH] D77721: [ASTImporter] Add support for importing fixed point literals

2020-04-09 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

Hi Vince, this looks good to me!

On the other hand I was pondering on @balazske's comment, this one:

> Or use the new flag added to every item in DefaultTestValuesForRunOptions, 
> specially if there is relevant difference in the AST for the options in 
> DefaultTestValuesForRunOptions in the code of this test (probably not).

So, the below test instantiation checks only with the "-ffixed-point" option 
passed to the frontend.

  INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
  ::testing::Values(ArgVector{"-ffixed-point"}), );

However, almost all other tests are exercised with a bunch of different options 
that are listed in `DefaultTestValuesForRunOptions`. We have this mechanism, 
because previously we had a lot of failures from windows build bots, where the 
base AST can be different. Of course it is not super relevant to a literal, but 
with structs and templates it is.

So, I think it would be really useful in the future, if we could extend 
`DefaultTestValuesForRunOptions` with an additional option. And it is okay to 
do that in a follow up patch (maybe I'll do it myself, just let me know if you 
don't have time for that). Here is what I've been thinking:

  --- a/clang/unittests/AST/ASTImporterFixtures.h
  +++ b/clang/unittests/AST/ASTImporterFixtures.h
  @@ -66,10 +66,13 @@ protected:
 }
   };
  
  -const auto DefaultTestValuesForRunOptions = ::testing::Values(
  +const auto DefaultTestArrayForRunOptions = std::array{
   ArgVector(), ArgVector{"-fdelayed-template-parsing"},
   ArgVector{"-fms-compatibility"},
  -ArgVector{"-fdelayed-template-parsing", "-fms-compatibility"});
  +ArgVector{"-fdelayed-template-parsing", "-fms-compatibility"}};
  +
  +const auto DefaultTestValuesForRunOptions =
  +::testing::ValuesIn(DefaultTestArrayForRunOptions);



  --- a/clang/unittests/AST/ASTImporterTest.cpp
  +++ b/clang/unittests/AST/ASTImporterTest.cpp
  @@ -5922,6 +5922,28 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
ImportExprOfAlignmentAttr) {
 EXPECT_TRUE(ToA);
   }
  
  +template 
  +auto ExtendWithOptions(const T& Values, const ArgVector& Args) {
  +  auto Copy = Values;
  +  for (ArgVector& ArgV : Copy) {
  +for (const std::string& Arg : Args) {
  +  ArgV.push_back(Arg);
  +}
  +  }
  +  return ::testing::ValuesIn(Copy);
  +}
  +
  +INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportFixedPointExpr,
  +ExtendWithOptions(DefaultTestArrayForRunOptions,
  +  ArgVector{"-ffixed-point"}), );

This would give us the following test instances:

  ParameterizedTests/ImportFixedPointExpr.ImportFixedPointerLiteralExpr/0, 
where GetParam() = { "-ffixed-point" }
  ParameterizedTests/ImportFixedPointExpr.ImportFixedPointerLiteralExpr/1, 
where GetParam() = { "-fdelayed-template-parsing", "-ffixed-point" }
  ParameterizedTests/ImportFixedPointExpr.ImportFixedPointerLiteralExpr/2, 
where GetParam() = { "-fms-compatibility", "-ffixed-point" }
  ParameterizedTests/ImportFixedPointExpr.ImportFixedPointerLiteralExpr/3, 
where GetParam() = { "-fdelayed-template-parsing", "-fms-compatibility", 
"-ffixed-point" }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77721



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


[PATCH] D77391: [analyzer][AnalysisOrder] Display the CallEvent type for preCall/postCall

2020-04-09 Thread Kristóf Umann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Szelethus marked an inline comment as done.
Closed by commit rG023c4d400ef5: [analyzer][AnalysisOrderChecker] Display the 
CallEvent type in preCall/postCall (authored by Szelethus).

Changed prior to commit:
  https://reviews.llvm.org/D77391?vs=254771&id=256313#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77391

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/lib/StaticAnalyzer/Checkers/AnalysisOrderChecker.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/analyzer-config.c
  clang/test/Analysis/cxx-dynamic-memory-analysis-order.cpp
  clang/test/Analysis/diagnostics/explicit-suppression.cpp

Index: clang/test/Analysis/diagnostics/explicit-suppression.cpp
===
--- clang/test/Analysis/diagnostics/explicit-suppression.cpp
+++ clang/test/Analysis/diagnostics/explicit-suppression.cpp
@@ -19,6 +19,6 @@
 void testCopyNull(C *I, C *E) {
   std::copy(I, E, (C *)0);
 #ifndef SUPPRESSED
-  // expected-warning@../Inputs/system-header-simulator-cxx.h:698 {{Called C++ object pointer is null}}
+  // expected-warning@../Inputs/system-header-simulator-cxx.h:699 {{Called C++ object pointer is null}}
 #endif
 }
Index: clang/test/Analysis/cxx-dynamic-memory-analysis-order.cpp
===
--- /dev/null
+++ clang/test/Analysis/cxx-dynamic-memory-analysis-order.cpp
@@ -0,0 +1,130 @@
+// RUN: %clang_analyze_cc1 -std=c++20 -fblocks -verify %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.AnalysisOrder \
+// RUN:   -analyzer-config debug.AnalysisOrder:PreStmtCXXNewExpr=true \
+// RUN:   -analyzer-config debug.AnalysisOrder:PostStmtCXXNewExpr=true \
+// RUN:   -analyzer-config debug.AnalysisOrder:PreStmtCXXDeleteExpr=true \
+// RUN:   -analyzer-config debug.AnalysisOrder:PostStmtCXXDeleteExpr=true \
+// RUN:   -analyzer-config debug.AnalysisOrder:PreCall=true \
+// RUN:   -analyzer-config debug.AnalysisOrder:PostCall=true \
+// RUN:   2>&1 | FileCheck %s
+
+// expected-no-diagnostics
+
+#include "Inputs/system-header-simulator-cxx.h"
+
+void f() {
+  // C++20 standard draft 17.6.1.15:
+  // Required behavior: A call to an operator delete with a size parameter may
+  // be changed to a call to the corresponding operator delete without a size
+  // parameter, without affecting memory allocation. [ Note: A conforming
+  // implementation is for operator delete(void* ptr, size_t size) to simply
+  // call operator delete(ptr). — end note ]
+  //
+  // C++20 standard draft 17.6.1.24, about nothrow operator delete:
+  //   void operator delete(void* ptr, const std::nothrow_t&) noexcept;
+  //   void operator delete(void* ptr, std::align_val_t alignment,
+  //const std::nothrow_t&) noexcept;
+  // Default behavior: Calls operator delete(ptr), or operator delete(ptr,
+  // alignment), respectively.
+
+  // FIXME: All calls to operator new should be CXXAllocatorCall.
+  // FIXME: PostStmt should be present.
+  {
+int *p = new int;
+delete p;
+// CHECK:  PreCall (operator new) [CXXAllocatorCall]
+// CHECK-NEXT: PostCall (operator new) [CXXAllocatorCall]
+// CHECK-NEXT: PreStmt
+// CHECK-NEXT: PostStmt
+// CHECK-NEXT: PreStmt
+
+p = new int;
+operator delete(p, 23542368);
+// CHECK-NEXT: PreCall (operator new) [CXXAllocatorCall]
+// CHECK-NEXT: PostCall (operator new) [CXXAllocatorCall]
+// CHECK-NEXT: PreStmt
+// CHECK-NEXT: PostStmt
+// CHECK-NEXT: PreCall (operator delete) [SimpleFunctionCall]
+// CHECK-NEXT: PostCall (operator delete) [SimpleFunctionCall]
+
+void *v = operator new(sizeof(int[2]), std::align_val_t(2));
+operator delete(v, std::align_val_t(2));
+// CHECK-NEXT: PreCall (operator new) [SimpleFunctionCall]
+// CHECK-NEXT: PostCall (operator new) [SimpleFunctionCall]
+// CHECK-NEXT: PreCall (operator delete) [SimpleFunctionCall]
+// CHECK-NEXT: PostCall (operator delete) [SimpleFunctionCall]
+
+v = operator new(sizeof(int[2]), std::align_val_t(2));
+operator delete(v, 345345, std::align_val_t(2));
+// CHECK-NEXT: PreCall (operator new) [SimpleFunctionCall]
+// CHECK-NEXT: PostCall (operator new) [SimpleFunctionCall]
+// CHECK-NEXT: PreCall (operator delete) [SimpleFunctionCall]
+// CHECK-NEXT: PostCall (operator delete) [SimpleFunctionCall]
+
+p = new (std::nothrow) int;
+operator delete(p, std::nothrow);
+// CHECK-NEXT: PreCall (operator new) [CXXAllocatorCall]
+// CHECK-NEXT: PostCall (operator new) [CXXAllocatorCall]
+// CHECK-NEXT: PreStmt
+// CHECK-NEXT: PostStmt
+// CHECK-NEXT: PreCall

[PATCH] D77229: [Analyzer][WIP] Avoid handling of LazyCompundVals in IteratorModeling

2020-04-09 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware updated this revision to Diff 256310.
baloghadamsoftware added a comment.

OK. I solved almost every problem except that `checkDeadSymbols()` removes the 
iterator position keyed by the temporary region representing the argument from 
the map before it is needed. Either I must somehow recognize that although the 
region is not "live" but the call whose argument it stores is not postchecked 
yet. I have no idea how to do this. Or, which I would prefer is to modify 
`SymbolReaper` so that `isLive()` returns true for temporary regions storing 
arguments of calls not postchecked yet. I have no idea either how to do this. 
Maybe should we take the `Expr` of `CXXTempObjectRegion`, use `ParentMap` to 
recognize whether it is a parameter for a `FunctionDecl`, but how to check 
whether the call for the function of the `FunctionDecl` is not postchecked yet? 
@NoQ, could you please, help me in this? Thx!


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

https://reviews.llvm.org/D77229

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Checkers/ContainerModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/Iterator.cpp
  clang/lib/StaticAnalyzer/Checkers/IteratorModeling.cpp
  clang/lib/StaticAnalyzer/Checkers/STLAlgorithmModeling.cpp
  clang/lib/StaticAnalyzer/Core/CallEvent.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
  clang/test/Analysis/container-modeling.cpp
  clang/test/Analysis/iterator-modeling.cpp

Index: clang/test/Analysis/iterator-modeling.cpp
===
--- clang/test/Analysis/iterator-modeling.cpp
+++ clang/test/Analysis/iterator-modeling.cpp
@@ -28,7 +28,7 @@
 void clang_analyzer_eval(bool);
 void clang_analyzer_warnIfReached();
 
-void begin(const std::vector &v) {
+/*void begin(const std::vector &v) {
   auto i = v.begin();
 
   clang_analyzer_eval(clang_analyzer_iterator_container(i) == &v); // expected-warning{{TRUE}}
@@ -945,7 +945,7 @@
   clang_analyzer_express(clang_analyzer_iterator_position(i1)); // expected-warning{{$L.end() - 1}} FIXME: should be $L.end() - 2
   clang_analyzer_express(clang_analyzer_iterator_position(i2)); // expected-warning{{$L.end()}}
   // clang_analyzer_express(clang_analyzer_iterator_position(i3)); FIXME: expect warning $L.end() - 1
-}
+}*/
 
 /// std::vector-like containers: Only the iterators before the insertion point
 ///  remain valid. The past-the-end iterator is also
@@ -965,7 +965,7 @@
   // clang_analyzer_express(clang_analyzer_iterator_position(i2)); FIXME: expect warning $V.begin() - 1
 }
 
-void vector_insert_behind_begin(std::vector &V, int n) {
+/*void vector_insert_behind_begin(std::vector &V, int n) {
   auto i0 = V.cbegin(), i1 = ++V.cbegin(), i2 = V.cend();
 
   clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
@@ -1880,3 +1880,4 @@
 // CHECK-NEXT: "i1 : Valid ; Container == SymRegion{reg_$[[#]] & V>} ; Offset == conj_$[[#]]{long, LC[[#]], S[[#]], #[[#]]}"
 // CHECK-NEXT:   ]}
 }
+*/
Index: clang/test/Analysis/container-modeling.cpp
===
--- clang/test/Analysis/container-modeling.cpp
+++ clang/test/Analysis/container-modeling.cpp
@@ -17,7 +17,7 @@
 void clang_analyzer_warnIfReached();
 
 void begin(const std::vector &V) {
-  V.begin();
+  const auto i0 = V.begin();
 
   clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
   clang_analyzer_express(clang_analyzer_container_begin(V)); // expected-warning{{$V.begin()}}
@@ -25,7 +25,7 @@
 }
 
 void end(const std::vector &V) {
-  V.end();
+  const auto i0 = V.end();
 
   clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
   clang_analyzer_express(clang_analyzer_container_end(V)); // expected-warning{{$V.end()}}
@@ -41,10 +41,10 @@
 // Move
 
 void move_assignment(std::vector &V1, std::vector &V2) {
-  V1.cbegin();
-  V1.cend();
-  V2.cbegin();
-  V2.cend();
+  const auto i0 = V1.cbegin();
+  const auto i1 = V1.cend();
+  const auto i2 = V2.cbegin();
+  const auto i3 = V2.cend();
   long B1 = clang_analyzer_container_begin(V1);
   long E1 = clang_analyzer_container_end(V1);
   long B2 = clang_analyzer_container_begin(V2);
@@ -70,8 +70,8 @@
 void clang_analyzer_dump(void*);
 
 void push_back(std::vector &V, int n) {
-  V.cbegin();
-  V.cend();
+  const auto i0 = V.cbegin();
+  const auto i1 = V.cend();
 
   clang_analyzer_denote(clang_analyzer_container_begin(V), "$V.begin()");
   clang_analyzer_denote(clang_analyzer_container_end(V), "$V.end()");
@@ -90,8 +90,8 @@
 /// past-the-end position of the container is incremented).
 
 void emplace_back(std::vector &V, int n) {
-  V.cbegin();
-  V.cend();
+  const auto i0 = V.cbegin(

[PATCH] D77731: [OPENMP]Fix capturing of global variables in OpenMP regions.

2020-04-09 Thread Alexey Bataev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG56c3b2b091bf: [OPENMP]Fix capturing of global variables in 
OpenMP regions. (authored by ABataev).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77731

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

Index: clang/test/OpenMP/parallel_codegen.cpp
===
--- clang/test/OpenMP/parallel_codegen.cpp
+++ clang/test/OpenMP/parallel_codegen.cpp
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -verify -fopenmp -x c++ -emit-llvm %s -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,CHECK
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
 // RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefixes=ALL-DEBUG,CHECK-DEBUG %s
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -x c++ -emit-llvm %s -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
-// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefixes=ALL-DEBUG,IRBUILDER-DEBUG %s
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-enable-irbuilder -DIRBUILDER -x c++ -emit-llvm %s -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -o - | FileCheck %s --check-prefixes=ALL,IRBUILDER
+// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -DIRBUILDER -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-enable-irbuilder -DIRBUILDER -x c++ -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -debug-info-kind=limited -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefixes=ALL-DEBUG,IRBUILDER-DEBUG %s
 
 // RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -emit-llvm %s -triple %itanium_abi_triple -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
@@ -45,7 +45,18 @@
 int main (int argc, char **argv) {
   int a[argc];
 #pragma omp parallel shared(global, a) default(none)
-  (void)global, foo(a[1]);
+  foo(a[1]), a[1] = global;
+#ifndef IRBUILDER
+// TODO: Support for privates in IRBuilder.
+#pragma omp parallel private(global, a) default(none)
+#pragma omp parallel shared(global, a) default(none)
+  foo(a[1]), a[1] = global;
+// FIXME: IRBuilder crashes in void llvm::OpenMPIRBuilder::finalize()
+// Assertion `Extractor.isEligible() && "Expected OpenMP outlining to be possible!"' failed.
+#pragma omp parallel shared(global, a) default(none)
+#pragma omp parallel shared(global, a) default(none)
+  foo(a[1]), a[1] = global;
+#endif // IRBUILDER
   return tmain(argv);
 }
 
@@ -53,6 +64,8 @@
 // ALL: store i32 %argc, i32* [[ARGC_ADDR:%.+]],
 // ALL: [[VLA:%.+]] = alloca i32, i{{[0-9]+}} [[VLA_SIZE:%[^,]+]],
 // CHECK:  call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 2, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i{{[0-9]+}}, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*), i{{[0-9]+}} [[VLA_SIZE]], i32* [[VLA]])
+// CHECK:  call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i64)* [[OMP_OUTLINED1:@.+]] to void (i32*, i32*, ...)*), i{{[0-9]+}} [[VLA_SIZE]])
+// CHECK:  call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 2, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i{{[0-9]+}}, i32*)* [[OMP_OUTLINED2:@.+]] to void (i32*, i32*, ...)*), i{{[0-9]+}} [[VLA_SIZE]], i32* [[VLA]])
 // IRBUILDER:   call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 1, void (i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OMP_OUTLINED:@.+]] to void (i32*, i32*, ...)*), i32* [[VLA]])
 // ALL:  [[ARGV:%.+]] = load i8**, i8*** {{%[a-z0-9.]+}}
 // ALL-NEXT:  [[RET:%.+]] = call {{[a-z\_\b]*[ ]?i32}} [[TMAIN:@.+tmain.+]](i8** [[ARGV]])
@@ -73,7 +86,7 @@
 // ALL-DEBUG:ret i32
 // ALL-DEBUG-NEXT:  }
 
-// CHECK:   define internal {{.*}}void [[OMP_OUTLINED]](i32

[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-04-09 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp:1497
+  OutContext.getOrCreateSymbol("." + Name->getName());
+  assert(FnEntryPointSym->getName().equals(
+ cast(FnEntryPointSym)->getUnqualifiedName()) &&

Based on our discussion, this assertion could be removed.
And please add a comment saying
// If there is a direct call to this extern function, we need to emit linkage 
for its function entry point symbol.



Comment at: llvm/test/CodeGen/PowerPC/aix-extern-weak.ll:11
+
+@foo_ext_weak_p = global void (...)* bitcast (void ()* @foo_ext_weak to void 
(...)*)
+

hubert.reinterpretcast wrote:
> I would prefer to test the function call and the take-address-of-function 
> cases separately here.
I think this is to test when the function is both taken address, and get called 
directly, will we emit linkage for both  function entry point and function 
descriptor symbol? The original implementation only emit one of them.
Maybe it makes sense to have a separate test case like this to test the linkage 
emit in all circumstance: 
```
void foo_called();
void foo_refed();
void foo_called_refed();

void (*foo_refed_p)() = foo_refed;
void (*foo_called_refed_p)() = foo_called_refed;

void bar(){
  foo_called();
  foo_called_refed();
}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932



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


[clang] 2b8c1ac - [OPENMP]Fix the test to pacify buildbots, NFC.

2020-04-09 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-04-09T11:28:50-04:00
New Revision: 2b8c1ac9cad6c4465e1ff79a67ab68b8e83a49d3

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

LOG: [OPENMP]Fix the test to pacify buildbots, NFC.

Added: 


Modified: 
clang/test/OpenMP/parallel_codegen.cpp

Removed: 




diff  --git a/clang/test/OpenMP/parallel_codegen.cpp 
b/clang/test/OpenMP/parallel_codegen.cpp
index b38e9ae706bd..cfcd3a401c9a 100644
--- a/clang/test/OpenMP/parallel_codegen.cpp
+++ b/clang/test/OpenMP/parallel_codegen.cpp
@@ -64,7 +64,7 @@ int main (int argc, char **argv) {
 // ALL: store i32 %argc, i32* [[ARGC_ADDR:%.+]],
 // ALL: [[VLA:%.+]] = alloca i32, i{{[0-9]+}} [[VLA_SIZE:%[^,]+]],
 // CHECK:  call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 2, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*, i{{[0-9]+}}, i32*)* [[OMP_OUTLINED:@.+]] to 
void (i32*, i32*, ...)*), i{{[0-9]+}} [[VLA_SIZE]], i32* [[VLA]])
-// CHECK:  call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 1, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*, i64)* [[OMP_OUTLINED1:@.+]] to void (i32*, 
i32*, ...)*), i{{[0-9]+}} [[VLA_SIZE]])
+// CHECK:  call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 1, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*, i{{[0-9]+}})* [[OMP_OUTLINED1:@.+]] to void 
(i32*, i32*, ...)*), i{{[0-9]+}} [[VLA_SIZE]])
 // CHECK:  call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, ...)*, 
...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 2, void (i32*, i32*, 
...)* bitcast (void (i32*, i32*, i{{[0-9]+}}, i32*)* [[OMP_OUTLINED2:@.+]] to 
void (i32*, i32*, ...)*), i{{[0-9]+}} [[VLA_SIZE]], i32* [[VLA]])
 // IRBUILDER:   call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, 
...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 1, void 
(i32*, i32*, ...)* bitcast (void (i32*, i32*, i32*)* [[OMP_OUTLINED:@.+]] to 
void (i32*, i32*, ...)*), i32* [[VLA]])
 // ALL:  [[ARGV:%.+]] = load i8**, i8*** {{%[a-z0-9.]+}}
@@ -121,13 +121,13 @@ int main (int argc, char **argv) {
 // ALL-DEBUG-DAG: define linkonce_odr void [[FOO]](i32 %argc)
 
 // CHECK:   define internal {{.*}}void [[OMP_OUTLINED1]](i32* noalias 
%{{.+}}, i32* noalias %{{.+}}, i{{[0-9]+}}{{.*}} [[VLA_SIZE:%.+]])
-// CHECK:   call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, 
...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 3, void 
(i32*, i32*, ...)* bitcast (void (i32*, i32*, i64, i32*, i32*)* 
[[OMP_OUTLINED11:@.+]] to void (i32*, i32*, ...)*), i64 %{{.+}}, i32* %{{.+}}, 
i32* %{{.+}})
+// CHECK:   call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, 
...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 3, void 
(i32*, i32*, ...)* bitcast (void (i32*, i32*, i{{[0-9]+}}, i32*, i32*)* 
[[OMP_OUTLINED11:@.+]] to void (i32*, i32*, ...)*), i{{[0-9]+}} %{{.+}}, i32* 
%{{.+}}, i32* %{{.+}})
 
 // CHECK:   define internal {{.*}}void [[OMP_OUTLINED11]](i32* noalias 
%{{.+}}, i32* noalias %{{.+}}, i{{[0-9]+}}{{.*}} [[VLA_SIZE:%.+]], i32* {{.+}} 
[[VLA_ADDR:%[^)]+]], i32* {{.+}} %{{.+}})
 // CHECK-NOT:   load i32, i32* @
 
 // CHECK:   define internal {{.*}}void [[OMP_OUTLINED2]](i32* noalias 
%{{.+}}, i32* noalias %{{.+}}, i{{[0-9]+}}{{.*}} [[VLA_SIZE:%.+]], i32* {{.+}} 
[[VLA_ADDR:%[^)]+]])
-// CHECK:   call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, 
...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 2, void 
(i32*, i32*, ...)* bitcast (void (i32*, i32*, i64, i32*)* 
[[OMP_OUTLINED21:@.+]] to void (i32*, i32*, ...)*), i64 %{{.+}}, i32* %{{.+}})
+// CHECK:   call {{.*}}void (%struct.ident_t*, i32, void (i32*, i32*, 
...)*, ...) @__kmpc_fork_call(%struct.ident_t* [[DEF_LOC_2]], i32 2, void 
(i32*, i32*, ...)* bitcast (void (i32*, i32*, i{{[0-9]+}}, i32*)* 
[[OMP_OUTLINED21:@.+]] to void (i32*, i32*, ...)*), i{{[0-9]+}} %{{.+}}, i32* 
%{{.+}})
 
 
 // CHECK:   define internal {{.*}}void [[OMP_OUTLINED21]](i32* noalias 
%{{.+}}, i32* noalias %{{.+}}, i{{[0-9]+}}{{.*}} [[VLA_SIZE:%.+]], i32* {{.+}} 
[[VLA_ADDR:%[^)]+]])



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


[PATCH] D76932: [AIX] emit .extern and .weak directive linkage

2020-04-09 Thread Jason Liu via Phabricator via cfe-commits
jasonliu added inline comments.



Comment at: llvm/test/CodeGen/PowerPC/aix-extern.ll:14
+
+; Function Attrs: noinline nounwind optnone
+define void @foo() #0 {

nit: Function Attrs and `#0` could be removed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76932



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


[PATCH] D76078: [AArch64][SVE] Add a pass for SVE intrinsic optimisations

2020-04-09 Thread Kerry McLaughlin via Phabricator via cfe-commits
kmclaughlin added a comment.

Ping :)


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

https://reviews.llvm.org/D76078



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


[PATCH] D75851: [Analyzer][StreamChecker] Added evaluation of fseek.

2020-04-09 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 256317.
balazske added a comment.

Addressed review comments (reformat and rename).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75851

Files:
  clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  clang/test/Analysis/stream-error.c

Index: clang/test/Analysis/stream-error.c
===
--- clang/test/Analysis/stream-error.c
+++ clang/test/Analysis/stream-error.c
@@ -52,3 +52,34 @@
   clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
   fclose(F);
 }
+
+void error_fseek() {
+  FILE *F = fopen("file", "r");
+  if (!F)
+return;
+  int rc = fseek(F, 0, SEEK_SET);
+  if (rc) {
+int IsFEof = feof(F), IsFError = ferror(F);
+// Get feof or ferror or no error.
+clang_analyzer_eval(IsFEof || IsFError);
+// expected-warning@-1 {{FALSE}}
+// expected-warning@-2 {{TRUE}}
+clang_analyzer_eval(IsFEof && IsFError); // expected-warning {{FALSE}}
+// Error flags should not change.
+if (IsFEof)
+  clang_analyzer_eval(feof(F)); // expected-warning {{TRUE}}
+else
+  clang_analyzer_eval(feof(F)); // expected-warning {{FALSE}}
+if (IsFError)
+  clang_analyzer_eval(ferror(F)); // expected-warning {{TRUE}}
+else
+  clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  } else {
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+// Error flags should not change.
+clang_analyzer_eval(feof(F));   // expected-warning {{FALSE}}
+clang_analyzer_eval(ferror(F)); // expected-warning {{FALSE}}
+  }
+  fclose(F);
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -25,8 +25,13 @@
 
 namespace {
 
+struct FnDescription;
+
 /// Full state information about a stream pointer.
 struct StreamState {
+  /// The last file operation called in the stream.
+  const FnDescription *LastOperation;
+
   /// State of a stream symbol.
   /// FIXME: We need maybe an "escaped" state later.
   enum KindTy {
@@ -45,6 +50,9 @@
 FEof,
 /// Other generic (non-EOF) error (`ferror` is true).
 FError,
+/// Unknown error flag is set (or none), the meaning depends on the last
+/// operation.
+Unknown
   } ErrorState = NoError;
 
   bool isOpened() const { return State == Opened; }
@@ -63,28 +71,47 @@
 assert(State == Opened && "Error undefined for closed stream.");
 return ErrorState == FError;
   }
+  bool isUnknown() const {
+assert(State == Opened && "Error undefined for closed stream.");
+return ErrorState == Unknown;
+  }
 
   bool operator==(const StreamState &X) const {
 // In not opened state error should always NoError.
-return State == X.State && ErrorState == X.ErrorState;
+return LastOperation == X.LastOperation && State == X.State &&
+   ErrorState == X.ErrorState;
   }
 
-  static StreamState getOpened() { return StreamState{Opened}; }
-  static StreamState getClosed() { return StreamState{Closed}; }
-  static StreamState getOpenFailed() { return StreamState{OpenFailed}; }
-  static StreamState getOpenedWithFEof() { return StreamState{Opened, FEof}; }
-  static StreamState getOpenedWithFError() {
-return StreamState{Opened, FError};
+  static StreamState getOpened(const FnDescription *L) {
+return StreamState{L, Opened};
+  }
+  static StreamState getOpened(const FnDescription *L, ErrorKindTy E) {
+return StreamState{L, Opened, E};
+  }
+  static StreamState getClosed(const FnDescription *L) {
+return StreamState{L, Closed};
   }
+  static StreamState getOpenFailed(const FnDescription *L) {
+return StreamState{L, OpenFailed};
+  }
+
+  /// Return if the specified error kind is possible on the stream in the
+  /// current state.
+  /// This depends on the stored `LastOperation` value.
+  /// If the error is not possible returns empty value.
+  /// If the error is possible returns the remaining possible error type
+  /// (after taking out `ErrorKind`). If a single error is possible it will
+  /// return that value, otherwise unknown error.
+  Optional getRemainingPossibleError(ErrorKindTy ErrorKind) const;
 
   void Profile(llvm::FoldingSetNodeID &ID) const {
+ID.AddPointer(LastOperation);
 ID.AddInteger(State);
 ID.AddInteger(ErrorState);
   }
 };
 
 class StreamChecker;
-struct FnDescription;
 using FnCheck = std::function;
 
@@ -95,8 +122,28 @@
   FnCheck PreFn;
   FnCheck EvalFn;
   ArgNoTy StreamArgNo;
+  // What errors are possible after this operation.
+  // Used only if this operation resulted in Unknown state
+  // (otherwise there is a known single error).
+  // Must contain 2 or 3 elements, or zero.
+  llvm

[PATCH] D77806: [analyzer] Do not report CFError null dereference for nonnull params

2020-04-09 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko updated this revision to Diff 256318.
vsavchenko added a comment.

Add forgotten hunk


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77806

Files:
  clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
  clang/test/Analysis/CheckNSError.m
  clang/test/Analysis/nonnull.cpp

Index: clang/test/Analysis/nonnull.cpp
===
--- /dev/null
+++ clang/test/Analysis/nonnull.cpp
@@ -0,0 +1,34 @@
+// RUN: %clang_analyze_cc1 -std=c++11 -analyzer-checker=core -verify %s
+
+void nonnull [[gnu::nonnull]] (int *q);
+
+void f1(int *p) {
+  if (p)
+return;
+  nonnull(p); //expected-warning{{nonnull}}
+}
+
+void f2(int *p) {
+  if (p)
+return;
+  auto lambda = [](int *q) __attribute__((nonnull)){};
+  lambda(p); //expected-warning{{nonnull}}
+}
+
+template 
+void variadicNonnull(ARGS... args) __attribute__((nonnull));
+
+void f3(int a, float b, int *p) {
+  if (p)
+return;
+  variadicNonnull(a, b, p); //expected-warning{{nonnull}}
+}
+
+int globalVar = 15;
+void moreParamsThanArgs [[gnu::nonnull(2, 4)]] (int a, int *p, int b = 42, int *q = &globalVar);
+
+void f4(int a, int *p) {
+  if (p)
+return;
+  moreParamsThanArgs(a, p); //expected-warning{{nonnull}}
+}
Index: clang/test/Analysis/CheckNSError.m
===
--- clang/test/Analysis/CheckNSError.m
+++ clang/test/Analysis/CheckNSError.m
@@ -62,4 +62,17 @@
   return 0;
 }
 
+int __attribute__((nonnull)) f4(CFErrorRef *error) {
+  *error = 0; // no-warning
+  return 0;
+}
 
+int __attribute__((nonnull(1))) f5(int *x, CFErrorRef *error) {
+  *error = 0; // expected-warning {{Potential null dereference}}
+  return 0;
+}
+
+int __attribute__((nonnull(2))) f6(int *x, CFErrorRef *error) {
+  *error = 0; // no-warning
+  return 0;
+}
Index: clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/NonNullParamChecker.cpp
@@ -14,8 +14,9 @@
 //
 //===--===//
 
-#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/AST/Attr.h"
+#include "clang/Analysis/AnyCall.h"
+#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
@@ -28,44 +29,78 @@
 
 namespace {
 class NonNullParamChecker
-  : public Checker< check::PreCall, EventDispatcher > {
+: public Checker> {
   mutable std::unique_ptr BTAttrNonNull;
   mutable std::unique_ptr BTNullRefArg;
 
 public:
-
   void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
+  void checkBeginFunction(CheckerContext &C) const;
 
   std::unique_ptr
-  genReportNullAttrNonNull(const ExplodedNode *ErrorN,
-   const Expr *ArgE,
+  genReportNullAttrNonNull(const ExplodedNode *ErrorN, const Expr *ArgE,
unsigned IdxOfArg) const;
   std::unique_ptr
   genReportReferenceToNullPointer(const ExplodedNode *ErrorN,
   const Expr *ArgE) const;
 };
-} // end anonymous namespace
 
-/// \return Bitvector marking non-null attributes.
-static llvm::SmallBitVector getNonNullAttrs(const CallEvent &Call) {
+template 
+void setBitsAccordingToFunctionAttributes(const CallType &Call,
+  llvm::SmallBitVector &AttrNonNull) {
   const Decl *FD = Call.getDecl();
-  unsigned NumArgs = Call.getNumArgs();
-  llvm::SmallBitVector AttrNonNull(NumArgs);
+
   for (const auto *NonNull : FD->specific_attrs()) {
 if (!NonNull->args_size()) {
-  AttrNonNull.set(0, NumArgs);
+  // Lack of attribute parameters means that all of the parameters are
+  // implicitly marked as non-null.
+  AttrNonNull.set();
   break;
 }
+
 for (const ParamIdx &Idx : NonNull->args()) {
+  // 'nonnull' attribute's parameters are 1-based and should be adjusted to
+  // match actual AST parameter/argument indices.
   unsigned IdxAST = Idx.getASTIndex();
-  if (IdxAST >= NumArgs)
+  if (IdxAST >= AttrNonNull.size())
 continue;
   AttrNonNull.set(IdxAST);
 }
   }
+}
+
+template 
+void setBitsAccordingToParameterAttributes(const CallType &Call,
+   llvm::SmallBitVector &AttrNonNull) {
+  for (const ParmVarDecl *Parameter : Call.parameters()) {
+if (Parameter->hasAttr())
+  AttrNonNull.set(Parameter->getFunctionScopeIndex());
+  }
+}
+
+template 
+llvm::SmallBitVector getNonNullAttrsImpl(const CallType &Call,
+ unsigned ExpectedSize) {
+  llvm::SmallBitVector Attr

[PATCH] D77066: [analyzer] ApiModeling: Add buffer size arg constraint

2020-04-09 Thread Gabor Marton via Phabricator via cfe-commits
martong marked an inline comment as done.
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp:253
+
+  // FIXME Implement a generic negate for all BO values.
+  assert(Tmp.Op == BO_LE && "Op should be <=");

Use BinaryOperator::negateComparisonOp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77066



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


Build czar switchover

2020-04-09 Thread Akira Hatanaka via cfe-commits
Hi Volodymyr and Azhar,

Here is the current status of the bots:

1. Automerger
Automerger has almost caught up. [apple/master -> internal/master] has just 13 
unmerged commits and no conflicts.

2. BlueDragon
There are a few clang-1200 bots that are failing.

- The following bot is failing because it can’t find libLTO:
  
https://smooshbase.apple.com/ci/view/BuildCzar/job/apple-clang-ios-san/job/internal%252Fclang%252F1200/
 

  I’ve filed a radar for it (rdar://problem/61485027 ).

- I expect this one to turn green soon:
  
https://smooshbase.apple.com/ci/view/BuildCzar/job/apple-clang-ios-stage2-RLTO/

  I’ve already fixed the failing tests by requiring support for matrix-type 
when -fenable-matrix is passed on the command line.

- This one is failing because three opt pipeline tests are failing:
  
https://smooshbase.apple.com/ci/view/BuildCzar/job/apple-clang-xcode-stage1-RA/job/internal%252Fclang%252F1200/

  The following commit might have to be cherry picked to 1200 to fix the tests. 
I’ll file a radar and ask Florian to take a look.

 Author: Florian Hahn 
 Date:   Tue Apr 7 14:44:19 2020 +0100

 [Matrix] Preserve LI in TileBuilder.

3. GreenDragon
A few ASAN tests have been failing on the expensive check bot 
(http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-expensive/). I’ll 
file a radar and take a look at it today. 

The ASAN bot (http://lab.llvm.org:8080/green/job/clang-stage2-cmake-RgSan/) 
started failing this morning. I haven’t investigated why it’s failing.___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D77792: [analyzer] Extend constraint manager to be able to compare simple SymSymExprs

2020-04-09 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

I like it, nice work!




Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:774
 
+Optional RangeConstraintManager::tryAssumeSymSymOp(
+ProgramStateRef State, BinaryOperator::Opcode Op, SymbolRef LHSSym,

Is it possible to ever return with `None`? Other `assume` functions usually 
just return with `nullptr` on infeasible state as you do. What would be the 
meaning if `None` is returned, is that another kind of infeasibility?



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:797
+
+  switch (Op) {
+  case BO_LT:

Perhaps this hunk could be greatly simplified if `CompareResult` was actually 
`BinaryOperator::Opcode`.

Maybe (?):
```
if (Res == Op)
  return State;
return InfeasibleState;
```



Comment at: clang/test/Analysis/constraint-manager-sym-sym.c:70
+
+// [2,5] and [5,10]
+void test_range6(int l, int r) {

How is it different than `// [0,5] and [5,10]`?



Comment at: clang/test/Analysis/constraint-manager-sym-sym.c:172
+}
+

I think we could benefit from tests for cases like this: 
```
{[0,1],[5,6]} < {[9,9],[11,42],[44,44]}
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77792



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


[PATCH] D77777: [nvptx] Add `nvvm.texsurf.handle` internalizer.

2020-04-09 Thread Michael Liao via Phabricator via cfe-commits
hliao updated this revision to Diff 256321.
hliao added a comment.

Rebase to trunk.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D7

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGenCUDA/surface.cu
  clang/test/CodeGenCUDA/texture.cu
  llvm/lib/Target/NVPTX/CMakeLists.txt
  llvm/lib/Target/NVPTX/NVPTX.h
  llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
  llvm/lib/Target/NVPTX/NVPTXTexSurfHandleInternalizer.cpp
  llvm/test/CodeGen/NVPTX/tex-read-cuda.ll

Index: llvm/test/CodeGen/NVPTX/tex-read-cuda.ll
===
--- llvm/test/CodeGen/NVPTX/tex-read-cuda.ll
+++ llvm/test/CodeGen/NVPTX/tex-read-cuda.ll
@@ -6,6 +6,7 @@
 
 declare { float, float, float, float } @llvm.nvvm.tex.unified.1d.v4f32.s32(i64, i32)
 declare i64 @llvm.nvvm.texsurf.handle.internal.p1i64(i64 addrspace(1)*)
+declare i64 @llvm.nvvm.texsurf.handle.p1i64(metadata, i64 addrspace(1)*)
 
 ; SM20-LABEL: .entry foo
 ; SM30-LABEL: .entry foo
@@ -28,7 +29,7 @@
 ; SM20-LABEL: .entry bar
 ; SM30-LABEL: .entry bar
 define void @bar(float* %red, i32 %idx) {
-; SM30: mov.u64 %rd[[TEXHANDLE:[0-9]+]], tex0 
+; SM30: mov.u64 %rd[[TEXHANDLE:[0-9]+]], tex0
   %texHandle = tail call i64 @llvm.nvvm.texsurf.handle.internal.p1i64(i64 addrspace(1)* @tex0)
 ; SM20: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [tex0, {%r{{[0-9]+}}}]
 ; SM30: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [%rd[[TEXHANDLE]], {%r{{[0-9]+}}}]
@@ -40,7 +41,24 @@
   ret void
 }
 
-!nvvm.annotations = !{!1, !2, !3}
+; SM20-LABEL: .entry bax
+; SM30-LABEL: .entry bax
+define void @bax(float* %red, i32 %idx) {
+; SM30: mov.u64 %rd[[TEXHANDLE:[0-9]+]], tex0
+  %texHandle = tail call i64 @llvm.nvvm.texsurf.handle.p1i64(metadata !5, i64 addrspace(1)* @tex0)
+; SM20: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [tex0, {%r{{[0-9]+}}}]
+; SM30: tex.1d.v4.f32.s32 {%f[[RED:[0-9]+]], %f[[GREEN:[0-9]+]], %f[[BLUE:[0-9]+]], %f[[ALPHA:[0-9]+]]}, [%rd[[TEXHANDLE]], {%r{{[0-9]+}}}]
+  %val = tail call { float, float, float, float } @llvm.nvvm.tex.unified.1d.v4f32.s32(i64 %texHandle, i32 %idx)
+  %ret = extractvalue { float, float, float, float } %val, 0
+; SM20: st.global.f32 [%r{{[0-9]+}}], %f[[RED]]
+; SM30: st.global.f32 [%r{{[0-9]+}}], %f[[RED]]
+  store float %ret, float* %red
+  ret void
+}
+
+!nvvm.annotations = !{!1, !2, !3, !4}
 !1 = !{void (i64, float*, i32)* @foo, !"kernel", i32 1}
 !2 = !{void (float*, i32)* @bar, !"kernel", i32 1}
-!3 = !{i64 addrspace(1)* @tex0, !"texture", i32 1}
+!3 = !{void (float*, i32)* @bax, !"kernel", i32 1}
+!4 = !{i64 addrspace(1)* @tex0, !"texture", i32 1}
+!5 = !{i64 addrspace(1)* @tex0}
Index: llvm/lib/Target/NVPTX/NVPTXTexSurfHandleInternalizer.cpp
===
--- /dev/null
+++ llvm/lib/Target/NVPTX/NVPTXTexSurfHandleInternalizer.cpp
@@ -0,0 +1,81 @@
+//===- NVPTXLowerAggrCopies.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
+//
+//===--===//
+//
+// \file
+// Replace `nvvm.texsurf.handle` intrinsics with their internal version, i.e.
+// `nvvm.texsurf.handle.internal`.
+//
+//===--===//
+
+#include "NVPTX.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/IntrinsicsNVPTX.h"
+#include "llvm/Pass.h"
+
+using namespace llvm;
+
+#define DEBUG_TYPE "nvptx-texsurf-handle-internalizer"
+
+namespace llvm {
+void initializeTexSurfHandleInternalizerPass(PassRegistry &);
+}
+
+namespace {
+
+class TexSurfHandleInternalizer : public FunctionPass {
+public:
+  static char ID;
+
+  TexSurfHandleInternalizer() : FunctionPass(ID) {
+initializeTexSurfHandleInternalizerPass(*PassRegistry::getPassRegistry());
+  }
+
+  StringRef getPassName() const override {
+return "Internalize `nvvm.texsurf.handle` intrinsics";
+  }
+
+  void getAnalysisUsage(AnalysisUsage &AU) const override {
+AU.setPreservesCFG();
+  }
+
+  bool runOnFunction(Function &F) override {
+bool Changed = false;
+for (auto &BB : F)
+  for (auto BI = BB.begin(), BE = BB.end(); BI != BE; /*EMPTY*/) {
+IntrinsicInst *II = dyn_cast(&*BI++);
+if (!II || II->getIntrinsicID() != Intrinsic::nvvm_texsurf_handle)
+  continue;
+assert(II->getArgOperand(1) ==
+   cast(
+   cast(II->getArgOperand(0))->getMetadata())
+   ->ge

[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

2020-04-09 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: cfe-commits, ASDenysPetrov, martong, Charusso, 
gamesh411, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, 
baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: clang.

Array size expressions in typedef statements with a VLA
(variable-length array) are handled from now as in plain
(non-typedef) VLA declarations.
(Type-alias is not handled.)

I am not familiar with the CFGBuilder, the new code
only seems to work. Maybe somebody can tell how to
make a better solution (if needed) for the problem.

The fix is useful to have the values used at VLA sizes
available for the analyzer and checkers.
The code works similar as `CodeGenFunction::emitDecl`
that processes typedef and type-alias VLA size expressions
at place of the typedef or type-alias statement.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77809

Files:
  clang/lib/Analysis/CFG.cpp


Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2839,6 +2839,19 @@
 /// DeclStmts and initializers in them.
 CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) {
   assert(DS->isSingleDecl() && "Can handle single declarations only.");
+
+  if (const auto *TDD = dyn_cast(DS->getSingleDecl())) {
+// If we encounter a VLA in typedef, then process its size expressions.
+CFGBlock *LastBlock = Block;
+for (const VariableArrayType *VA =
+ FindVA(TDD->getUnderlyingType().getTypePtr());
+ VA != nullptr; VA = FindVA(VA->getElementType().getTypePtr())) {
+  if (CFGBlock *newBlock = addStmt(VA->getSizeExpr()))
+LastBlock = newBlock;
+}
+return LastBlock;
+  }
+
   VarDecl *VD = dyn_cast(DS->getSingleDecl());
 
   if (!VD) {


Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -2839,6 +2839,19 @@
 /// DeclStmts and initializers in them.
 CFGBlock *CFGBuilder::VisitDeclSubExpr(DeclStmt *DS) {
   assert(DS->isSingleDecl() && "Can handle single declarations only.");
+
+  if (const auto *TDD = dyn_cast(DS->getSingleDecl())) {
+// If we encounter a VLA in typedef, then process its size expressions.
+CFGBlock *LastBlock = Block;
+for (const VariableArrayType *VA =
+ FindVA(TDD->getUnderlyingType().getTypePtr());
+ VA != nullptr; VA = FindVA(VA->getElementType().getTypePtr())) {
+  if (CFGBlock *newBlock = addStmt(VA->getSizeExpr()))
+LastBlock = newBlock;
+}
+return LastBlock;
+  }
+
   VarDecl *VD = dyn_cast(DS->getSingleDecl());
 
   if (!VD) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: changes to matrix size check

2020-04-09 Thread Akira Hatanaka via cfe-commits
+ Volodymyr, Azhar

> On Apr 8, 2020, at 6:28 AM, Florian Hahn  wrote:
> 
> Hi Akira,
> 
>> On Apr 7, 2020, at 21:12, Akira Hatanaka > > wrote:
>> 
>> Hi Adam and Florian,
>> 
>> Just to give you a heads up, I’ve made changes to the code that checks 
>> matrix size and the corresponding test case following Sam McCall’s open 
>> source patch 
>> (https://github.com/llvm/llvm-project/commit/88fbadd0f5d50ea1d310fb63da6da15b82a9be05
>>  
>> ).
>>  If it’s not correct or if you think there are better ways to do the check, 
>> feel free to rewrite the code I committed.
>> 
>> https://stashweb.sd.apple.com/projects/DEVTOOLS/repos/llvm-project/pull-requests/1408/overview
>>  
>> 
> Thanks for the heads-up. I will take a look. I just noticed that 
> internal/master started crashing for matrix code. Might be related.
> 

I’m seeing aarch64-matrix-amx-versioning.cpp assert when I run the tests on my 
desktop machine. Is that the test you saw that was crashing? I haven’t seen 
this failure in any of our internal bots though, probably because the test is 
guarded by ‘REQUIRES: matrix-test’.

Also, there was a commit by Eli Friedman which removed SequentialType from the 
type hierarchy. I just did the minimum to resolve the merge conflict, but it 
looks like there are several places that need to be fixed to handle MatrixType. 
Could you take a look at them too?

Also, there are three failing opt pipeline tests:
https://smooshbase.apple.com/ci/view/BuildCzar/job/apple-clang-xcode-stage1-RA/job/internal%252Fclang%252F1200/238/

Should we cherry pick the following commit to clang 1200 or should we just fix 
the check strings in the tests?

Author: Florian Hahn mailto:florian_h...@apple.com>>
 Date:   Tue Apr 7 14:44:19 2020 +0100

 [Matrix] Preserve LI in TileBuilder.

> Cheers,
> Florian
> 

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


[PATCH] D75665: [analyzer] On-demand parsing capability for CTU

2020-04-09 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D75665#1971440 , @gamesh411 wrote:

> In D75665#1907914 , @martong wrote:
>
> > The warning below suggests that we parse the ctu-other.c file (and 
> > presumably every file) as a C++ file, even if it should be parsed as a C 
> > file. Perhaps the invocation of the parser is missing some setting? Also, 
> > could this be the reason why on-the-fly and pch driven ctu gives different 
> > statistics?
> >
> >   warning: treating 'c' input as 'c++' when in C++ mode, this behavior is 
> > deprecated [-Wdeprecated]
> >   
> > /mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/clang/test/Analysis/Inputs/ctu-other.c:47:26:
> >  error: 'DataType' cannot be defined in a parameter type
> >   int structInProto(struct DataType {int a;int b; } * d) {
> >^
> >   1 error generated.
> >   Error while processing 
> > /mnt/disks/ssd0/agent/workspace/amd64_debian_testing_clang8/clang/test/Analysis/Inputs/ctu-other.c.
> >  
> >
>
>
> I have investigated the issue, and the compiler flags were looked up using 
> the heuristic implemented in tooling.
>  This heuristic looks for the suitable compilation database in an upward 
> ascending fashion inside the directory tree startin from the input source 
> file.
>  By copying both the source file and the compilation database to the test 
> directory this heuristic does the right thing now. (up until now the found 
> compile_commands.json was the one used for llvm-project itself, and picked up 
> a c++ specific compilation).
>
> This issue is solved, however the ASTImporter still cannot import the inline 
> definition of the struct, and emits an error.
>  Right now I am debugging the master branch that uses the AST-dumps wheter I 
> also encounter this error inside the ASTImporter (just to see if I am 
> operating on sane assumptions).


I've been looking into this and the ASTImporter indeed does not (cannot) import 
the definition of `structInProto()`. But that's just fine, that is why we have 
a branching for the call expression (TRUE/FALSE) below in ctu-main.c . All 
other functions whose definition were imported gives only the TRUE branch.

  clang_analyzer_eval(structInProto(&d) == 0); // expected-warning{{TRUE}} 
expected-warning{{FALSE}}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D75665



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


[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

2020-04-09 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

There must be a way to dump the CFG. Perhaps you could add a test that dumps 
the CFG of a given source and then by using `FileCheck` we could see the exact 
feature that is missing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809



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


[PATCH] D71553: [RISCV] Add Clang frontend support for Bitmanip extension

2020-04-09 Thread Scott Egerton via Phabricator via cfe-commits
s.egerton accepted this revision.
s.egerton added a comment.

Looks good to me


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71553



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


[PATCH] D77743: [HIP] Emit symbols with kernel name in host binary

2020-04-09 Thread Michael Liao via Phabricator via cfe-commits
hliao requested changes to this revision.
hliao added a comment.
This revision now requires changes to proceed.

In D77743#1970304 , @tra wrote:

> In D77743#1970163 , @yaxunl wrote:
>
> > The kernel handle is a variable. Even if it has the same name as kernel, it 
> > is OK for the debugger since the debugger does not put break point on a 
> > variable.
>
>
> The patch appears to apply only to generated kernels. What happens when we 
> take address of the kernel directly?
>
>   a.hip: 
>   __global__ void kernel() {}
>  
>   auto kernel_ref() {
> return kernel;
>   }
>  
>   b.hip:
>   extern __global__ void kernel(); // access the handle var
>   something kernel_ref(); // returns the stub pointer?
>  
>   void f() {
> auto x = kernel_ref();
> auto y = kernel(); 
> hipLaunchKernel(x,...); // x is the stub pointer. 
> hipLaunchKernel(y,...);
>   }
>
>
> Will `x` and `y` contain the same value? For CUDA the answer would be yes as 
> they both would contain the address of the host-side stub with the kernel's 
> name.
>  In this case external reference will point to the handle variable, but I'm 
> not sure what would kernel_ref() return. 
>  My guess is that it will be the stub address, which may be a problem.  I may 
> be wrong. It would be good to add a test to verify that we always get 
> consistent results when we're referencing the kernel.


That's a good question. That introduces the ambiguity on the values of the same 
symbol (from the programmer point of view). To ensure we won't there's no 
ambiguity, we should always use that *alias* global variable for `__global__` 
function on the host side as it will be used in the runtime API to query the 
device-side function.


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

https://reviews.llvm.org/D77743



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


[PATCH] D77809: [Analyzer] Include typedef statements in CFG build.

2020-04-09 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

In D77809#1972232 , @martong wrote:

> There must be a way to dump the CFG. Perhaps you could add a test that dumps 
> the CFG of a given source and then by using `FileCheck` we could see the 
> exact feature that is missing.


`debug.DumpCFG` to the rescue!

  $ clang -cc1 -analyzer-checker-help-developer | grep "debug.DumpCFG"
debug.DumpCFG Display Control-Flow Graphs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D77809



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


  1   2   3   >