[PATCH] D80966: [codeview] Put !heapallocsite on calls to operator new

2020-06-06 Thread Douglas Yung via Phabricator via cfe-commits
dyung added a comment.

I've reverted this change in g059ba74bb6f6166ca7c1783ef81dd37a5209b758 to get 
the bots green again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80966



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


[clang] 059ba74 - Revert "[codeview] Put !heapallocsite on calls to operator new"

2020-06-06 Thread Douglas Yung via cfe-commits

Author: Douglas Yung
Date: 2020-06-06T23:30:46Z
New Revision: 059ba74bb6f6166ca7c1783ef81dd37a5209b758

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

LOG: Revert "[codeview] Put !heapallocsite on calls to operator new"

This reverts commit 672ed5386024ba5cee53e19d637b7920a4889837.

This commit is hitting an assertion failure across multiple bots in the test:
Profile- :: instrprof-gcov-multithread_fork.test

Failing bots include:
http://lab.llvm.org:8011/builders/llvm-avr-linux/builds/2205
http://lab.llvm.org:8011/builders/clang-cmake-aarch64-lld/builds/8967
http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/10789
http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux/builds/27750
http://lab.llvm.org:8011/builders/sanitizer-ppc64be-linux/builds/16751

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGen/debug-info-codeview-heapallocsite.c

Removed: 
clang/test/CodeGenCXX/debug-info-codeview-heapallocsite.cpp



diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 136782fccf40..6bde3124555b 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4951,7 +4951,7 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
,
   // Add metadata for calls to MSAllocator functions
   if (getDebugInfo() && TargetDecl &&
   TargetDecl->hasAttr())
-getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy->getPointeeType(), Loc);
+getDebugInfo()->addHeapAllocSiteMetadata(CI, RetTy, Loc);
 
   // 4. Finish the call.
 

diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 1737154d179a..cc50ec6a8c89 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2146,14 +2146,16 @@ llvm::DIType 
*CGDebugInfo::getOrCreateStandaloneType(QualType D,
   return T;
 }
 
-void CGDebugInfo::addHeapAllocSiteMetadata(llvm::CallBase *CI,
-   QualType AllocatedTy,
+void CGDebugInfo::addHeapAllocSiteMetadata(llvm::Instruction *CI,
+   QualType D,
SourceLocation Loc) {
   llvm::MDNode *node;
-  if (AllocatedTy->isVoidType())
+  if (D.getTypePtr()->isVoidPointerType()) {
 node = llvm::MDNode::get(CGM.getLLVMContext(), None);
-  else
-node = getOrCreateType(AllocatedTy, getOrCreateFile(Loc));
+  } else {
+QualType PointeeTy = D.getTypePtr()->getPointeeType();
+node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
+  }
 
   CI->setMetadata("heapallocsite", node);
 }

diff  --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h
index 96ef6c7c1d27..367047e79dc9 100644
--- a/clang/lib/CodeGen/CGDebugInfo.h
+++ b/clang/lib/CodeGen/CGDebugInfo.h
@@ -509,7 +509,7 @@ class CGDebugInfo {
   llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
 
   /// Add heapallocsite metadata for MSAllocator calls.
-  void addHeapAllocSiteMetadata(llvm::CallBase *CallSite, QualType AllocatedTy,
+  void addHeapAllocSiteMetadata(llvm::Instruction *CallSite, QualType Ty,
 SourceLocation Loc);
 
   void completeType(const EnumDecl *ED);

diff  --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index dfae2bc5e47a..d0012337cdd3 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1638,13 +1638,6 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const 
CXXNewExpr *E) {
 RValue RV =
   EmitNewDeleteCall(*this, allocator, allocatorType, allocatorArgs);
 
-// Set !heapallocsite metadata on the call to operator new.
-if (getDebugInfo()) {
-  if (auto *newCall = dyn_cast(RV.getScalarVal()))
-getDebugInfo()->addHeapAllocSiteMetadata(newCall, allocType,
- E->getExprLoc());
-}
-
 // If this was a call to a global replaceable allocation function that does
 // not take an alignment argument, the allocator is known to produce
 // storage that's suitably aligned for any object that fits, up to a known

diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 612a2ecef843..b169462f535a 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2065,15 +2065,11 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
   }
 }
 
-// Update heapallocsite metadata when there is an explicit pointer cast.
-if (auto *CI = dyn_cast(Src)) {
-  if (CI->getMetadata("heapallocsite") && isa(CE)) {
-QualType 

[PATCH] D72778: [Matrix] Add __builtin_matrix_transpose to Clang.

2020-06-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/Sema/SemaChecking.cpp:15051
+
+  Expr *Arg = TheCall->getArg(0);
+  if (!Arg->getType()->isConstantMatrixType()) {

fhahn wrote:
> rjmccall wrote:
> > When a builtin has custom type-checking (`t`), you need to handle 
> > placeholders in the operands yourself, just like you would for an operator.
> I added placeholder handling and added additional tests.
Oh, I'm sorry, I gave you poor advice: you do need to handle placeholders, but 
more generally than that, you need an r-value.   Since you aren't doing any 
further conversions, you just need to call DefaultLValueConversion, which will 
also handle placeholders for you.

You will also need to store the checked argument back into the call, which you 
can only really test with an IRGen test.  This is one of the few places where 
we do actually directly mutate the AST.



Comment at: clang/lib/Sema/SemaChecking.cpp:1918
+switch (BuiltinID) {
+case Builtin::BI__builtin_matrix_transpose:
+  return SemaBuiltinMatrixTransposeOverload(TheCall, TheCallResult);

I didn't notice this before, but I think a single level of switch is fine; 
there's probably nothing common about matrix builtins that you're going to want 
to handle like this.



Comment at: clang/lib/Sema/SemaChecking.cpp:15063
+  // matrix type.
+  auto *MType = Matrix->getType()->getAs();
+  QualType ResultType = Context.getConstantMatrixType(

Please call `getAs` once and then check the result above instead of calling 
`isConstantMatrixType()` (which does most of the same work as `getAs`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72778



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


[PATCH] D81336: [clang-tidy] simplify-bool-expr ignores template instantiations

2020-06-06 Thread Nathan James via Phabricator via cfe-commits
njames93 created this revision.
njames93 added reviewers: aaron.ballman, alexfh, lebedev.ri, gribozavr2.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Ignore template instantiations in the matchers, Addresses 
readability-simplify-boolean-expr false-positive for bool from template. 



Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81336

Files:
  clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp


Index: 
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
===
--- 
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
+++ 
clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
@@ -948,3 +948,18 @@
 }
 // CHECK-MESSAGES: :[[@LINE-4]]:12: warning: {{.*}} in conditional return
 // CHECK-FIXES: S == (A)S;{{$}}
+
+template 
+void ignoreInstantiations() {
+  if (B) {
+return;
+  } else {
+return;
+  }
+}
+
+void instantiate() {
+  // Just make sure the check isn't fooled by template instantiations.
+  ignoreInstantiations();
+  ignoreInstantiations();
+}
Index: clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/SimplifyBooleanExprCheck.cpp
@@ -422,7 +422,7 @@
   bool Value,
   StringRef BooleanId) {
   Finder->addMatcher(
-  ifStmt(isExpansionInMainFile(),
+  ifStmt(unless(isInTemplateInstantiation()),
  hasCondition(cxxBoolLiteral(equals(Value)).bind(BooleanId)))
   .bind(IfStmtId),
   this);
@@ -432,7 +432,7 @@
   bool Value,
   StringRef TernaryId) {
   Finder->addMatcher(
-  conditionalOperator(isExpansionInMainFile(),
+  conditionalOperator(unless(isInTemplateInstantiation()),
   hasTrueExpression(cxxBoolLiteral(equals(Value))),
   hasFalseExpression(cxxBoolLiteral(equals(!Value
   .bind(TernaryId),
@@ -442,13 +442,13 @@
 void SimplifyBooleanExprCheck::matchIfReturnsBool(MatchFinder *Finder,
   bool Value, StringRef Id) {
   if (ChainedConditionalReturn)
-Finder->addMatcher(ifStmt(isExpansionInMainFile(),
+Finder->addMatcher(ifStmt(unless(isInTemplateInstantiation()),
   hasThen(returnsBool(Value, ThenLiteralId)),
   hasElse(returnsBool(!Value)))
.bind(Id),
this);
   else
-Finder->addMatcher(ifStmt(isExpansionInMainFile(),
+Finder->addMatcher(ifStmt(unless(isInTemplateInstantiation()),
   unless(hasParent(ifStmt())),
   hasThen(returnsBool(Value, ThenLiteralId)),
   hasElse(returnsBool(!Value)))
@@ -474,12 +474,16 @@
   auto Else = anyOf(SimpleElse, compoundStmt(statementCountIs(1),
  hasAnySubstatement(SimpleElse)));
   if (ChainedConditionalAssignment)
-Finder->addMatcher(ifStmt(hasThen(Then), hasElse(Else)).bind(Id), this);
+Finder->addMatcher(ifStmt(unless(isInTemplateInstantiation()),
+  hasThen(Then), hasElse(Else))
+   .bind(Id),
+   this);
   else
-Finder->addMatcher(
-ifStmt(unless(hasParent(ifStmt())), hasThen(Then), hasElse(Else))
-.bind(Id),
-this);
+Finder->addMatcher(ifStmt(unless(isInTemplateInstantiation()),
+  unless(hasParent(ifStmt())), hasThen(Then),
+  hasElse(Else))
+   .bind(Id),
+   this);
 }
 
 void SimplifyBooleanExprCheck::matchCompoundIfReturnsBool(MatchFinder *Finder,
@@ -487,6 +491,7 @@
   StringRef Id) {
   Finder->addMatcher(
   compoundStmt(
+  unless(isInTemplateInstantiation()),
   hasAnySubstatement(
   ifStmt(hasThen(returnsBool(Value)), unless(hasElse(stmt(),
   hasAnySubstatement(returnStmt(has(ignoringParenImpCasts(


Index: clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-simplify-bool-expr.cpp
@@ 

[PATCH] D72778: [Matrix] Add __builtin_matrix_transpose to Clang.

2020-06-06 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 269032.
fhahn marked an inline comment as done.
fhahn added a comment.

Thanks for all the comments!

Simplified code as suggested, handle placeholder expressions and add tests for 
them.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72778

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/matrix-type-builtins.c
  clang/test/CodeGenCXX/matrix-type-builtins.cpp
  clang/test/CodeGenObjC/matrix-type-builtins.m
  clang/test/Sema/matrix-type-builtins.c
  clang/test/SemaCXX/matrix-type-builtins.cpp
  clang/test/SemaObjC/matrix-type-builtins.m

Index: clang/test/SemaObjC/matrix-type-builtins.m
===
--- /dev/null
+++ clang/test/SemaObjC/matrix-type-builtins.m
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fenable-matrix %s
+
+typedef double double4x4 __attribute__((matrix_type(4, 4)));
+typedef unsigned u4x4 __attribute__((matrix_type(4, 4)));
+
+__attribute__((objc_root_class))
+@interface MatrixValue
+@property double4x4 value;
+@end
+
+void test_element_type_mismatch(u4x4 m, MatrixValue *mv) {
+  m = __builtin_matrix_transpose(mv.value);
+  // expected-error@-1 {{assigning to 'u4x4' (aka 'unsigned int __attribute__((matrix_type(4, 4)))') from incompatible type 'double __attribute__((matrix_type(4, 4)))'}}
+}
+
+typedef double double3x3 __attribute__((matrix_type(3, 3)));
+
+double test_dimension_mismatch(double3x3 m, MatrixValue *mv) {
+  m = __builtin_matrix_transpose(mv.value);
+  // expected-error@-1 {{assigning to 'double3x3' (aka 'double __attribute__((matrix_type(3, 3)))') from incompatible type 'double __attribute__((matrix_type(4, 4)))'}}
+}
Index: clang/test/SemaCXX/matrix-type-builtins.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/matrix-type-builtins.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang_cc1 %s -fenable-matrix -pedantic -std=c++11 -verify -triple=x86_64-apple-darwin9
+
+template 
+struct MyMatrix {
+  using matrix_t = EltTy __attribute__((matrix_type(Rows, Columns)));
+
+  matrix_t value;
+};
+
+template 
+typename MyMatrix::matrix_t transpose(MyMatrix ) {
+  char *v1 = __builtin_matrix_transpose(A.value);
+  // expected-error@-1 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 2)))'}}
+  // expected-error@-2 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 3)))'}}
+  // expected-error@-3 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 3)))'}}
+
+  __builtin_matrix_transpose(A);
+  // expected-error@-1 {{first argument must be a matrix}}
+  // expected-error@-2 {{first argument must be a matrix}}
+  // expected-error@-3 {{first argument must be a matrix}}
+
+  return __builtin_matrix_transpose(A.value);
+  // expected-error@-1 {{cannot initialize return object of type 'typename MyMatrix::matrix_t' (aka 'unsigned int __attribute__((matrix_type(2, 3)))') with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 2)))'}}
+  // expected-error@-2 {{cannot initialize return object of type 'typename MyMatrix::matrix_t' (aka 'unsigned int __attribute__((matrix_type(2, 3)))') with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 3)))'}}
+  // expected-error@-3 {{cannot initialize return object of type 'typename MyMatrix::matrix_t' (aka 'float __attribute__((matrix_type(3, 3)))') with an rvalue of type 'unsigned int __attribute__((matrix_type(3, 3)))'}}
+}
+
+void test_transpose_template(unsigned *Ptr1, float *Ptr2) {
+  MyMatrix Mat1;
+  MyMatrix Mat2;
+  Mat1.value = *((decltype(Mat1)::matrix_t *)Ptr1);
+  Mat1.value = transpose(Mat1);
+  // expected-note@-1 {{in instantiation of function template specialization 'transpose' requested here}}
+
+  Mat1.value = transpose(Mat2);
+  // expected-note@-1 {{in instantiation of function template specialization 'transpose' requested here}}
+
+  MyMatrix Mat3;
+  Mat3.value = transpose(Mat2);
+  // expected-note@-1 {{in instantiation of function template specialization 'transpose' requested here}}
+}
Index: clang/test/Sema/matrix-type-builtins.c
===
--- /dev/null
+++ clang/test/Sema/matrix-type-builtins.c
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -fenable-matrix -pedantic -verify -triple=x86_64-apple-darwin9
+
+typedef float sx5x10_t __attribute__((matrix_type(5, 10)));
+typedef int ix3x2_t __attribute__((matrix_type(3, 2)));
+typedef double dx3x3 __attribute__((matrix_type(3, 3)));
+typedef unsigned ix3x3 __attribute__((matrix_type(3, 3)));
+
+void 

[PATCH] D72778: [Matrix] Add __builtin_matrix_transpose to Clang.

2020-06-06 Thread Florian Hahn via Phabricator via cfe-commits
fhahn marked 3 inline comments as done.
fhahn added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1642
+  return cast(Ty.getCanonicalType());
+};
+

rjmccall wrote:
> Unnecessary semicolon.  I think it's probably clearer just to 
> `castAs()` inline in the code rather than introducing 
> this trivial wrapper for it.  We generally treat getAs/castAs as 
> idiomatically implying the result type strong enough to permit `auto`, just 
> like `dyn_cast`, so it'll probably even be more compact than this overall.
Sounds good, I dropped it and replaced it with getAs



Comment at: clang/lib/Sema/SemaChecking.cpp:15051
+
+  Expr *Arg = TheCall->getArg(0);
+  if (!Arg->getType()->isConstantMatrixType()) {

rjmccall wrote:
> When a builtin has custom type-checking (`t`), you need to handle 
> placeholders in the operands yourself, just like you would for an operator.
I added placeholder handling and added additional tests.



Comment at: clang/lib/Sema/SemaChecking.cpp:15060
+  ConstantMatrixType const *MType =
+  cast(Arg->getType().getCanonicalType());
+  QualType ResultType = Context.getConstantMatrixType(

rjmccall wrote:
> Don't canonicalize here, and you don't need to include `const` anyway.
dropped, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72778



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


[PATCH] D76794: [Matrix] Implement * binary operator for MatrixType.

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

Thanks, LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76794



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


[PATCH] D79830: Add support of __builtin_expect_with_probability

2020-06-06 Thread Zhi Zhuang via Phabricator via cfe-commits
LukeZhuang updated this revision to Diff 269028.
LukeZhuang added a reviewer: dexonsmith.
LukeZhuang added a comment.

**updated: 06/06/2020**
(1) updated llvm.expect.with.probability intrinsic document in LangRef.rst


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

https://reviews.llvm.org/D79830

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-expect-with-probability-template.cpp
  clang/test/CodeGen/builtin-expect-with-probability.c
  clang/test/Sema/builtin-expect-with-probability-avr.cpp
  clang/test/Sema/builtin-expect-with-probability.cpp
  llvm/docs/BranchWeightMetadata.rst
  llvm/docs/LangRef.rst
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
  llvm/test/Transforms/LowerExpectIntrinsic/basic.ll

Index: llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
===
--- llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
+++ llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
@@ -285,6 +285,29 @@
 
 declare i1 @llvm.expect.i1(i1, i1) nounwind readnone
 
+; CHECK-LABEL: @test11(
+define dso_local void @test11(i32 %0) noinline nounwind optnone uwtable {
+  %2 = alloca i32, align 4
+  store i32 %0, i32* %2, align 4
+  %3 = load i32, i32* %2, align 4
+  %4 = icmp sgt i32 %3, 0
+  %5 = zext i1 %4 to i32
+  %6 = sext i32 %5 to i64
+  %7 = call i64 @llvm.expect.with.probability.i64(i64 %6, i64 1, double 8.00e-01)
+  %8 = icmp ne i64 %7, 0
+  br i1 %8, label %9, label %10
+
+9:; preds = %1
+  call void (...) @ff()
+  br label %10
+
+10:   ; preds = %9, %1
+  ret void
+}
+
+declare i64 @llvm.expect.with.probability.i64(i64, i64, double) nounwind readnone willreturn
+declare dso_local void @ff(...)
+
 ; CHECK: !0 = !{!"branch_weights", i32 2000, i32 1}
 ; CHECK: !1 = !{!"misexpect", i64 0, i64 2000, i64 1}
 ; CHECK: !2 = !{!"branch_weights", i32 1, i32 2000}
@@ -292,3 +315,5 @@
 ; CHECK: !4 = !{!"branch_weights", i32 1, i32 1, i32 2000}
 ; CHECK: !5 = !{!"misexpect", i64 2, i64 2000, i64 1}
 ; CHECK: !6 = !{!"branch_weights", i32 2000, i32 1, i32 1}
+; CHECK: !7 = !{!"branch_weights", i32 1717986918, i32 429496731}
+; CHECK: !8 = !{!"misexpect", i64 0, i64 1717986918, i64 429496731}
Index: llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
===
--- llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
+++ llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
@@ -55,13 +55,32 @@
 "unlikely-branch-weight", cl::Hidden, cl::init(1),
 cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
 
+std::pair setBranchWeight(Intrinsic::ID IntrinsicID,
+  CallInst *CI, int BranchCount) {
+  if (IntrinsicID == Intrinsic::expect) {
+// __builtin_expect
+return {LikelyBranchWeight, UnlikelyBranchWeight};
+  } else {
+// __builtin_expect_with_probability
+assert(CI->getNumOperands() >= 3 &&
+   "expect with probability must have 3 arguments");
+ConstantFP *Confidence = dyn_cast(CI->getArgOperand(2));
+double TrueProb = Confidence->getValueAPF().convertToDouble();
+double FalseProb = (1.0 - TrueProb) / (BranchCount - 1);
+uint32_t LikelyBW = ceil((TrueProb * (double)(INT32_MAX - 1)) + 1.0);
+uint32_t UnlikelyBW = ceil((FalseProb * (double)(INT32_MAX - 1)) + 1.0);
+return {LikelyBW, UnlikelyBW};
+  }
+}
+
 static bool handleSwitchExpect(SwitchInst ) {
   CallInst *CI = dyn_cast(SI.getCondition());
   if (!CI)
 return false;
 
   Function *Fn = CI->getCalledFunction();
-  if (!Fn || Fn->getIntrinsicID() != Intrinsic::expect)
+  if (!Fn || (Fn->getIntrinsicID() != Intrinsic::expect &&
+  Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
 return false;
 
   Value *ArgValue = CI->getArgOperand(0);
@@ -71,15 +90,20 @@
 
   SwitchInst::CaseHandle Case = *SI.findCaseValue(ExpectedValue);
   unsigned n = SI.getNumCases(); // +1 for default case.
-  SmallVector Weights(n + 1, UnlikelyBranchWeight);
+  std::pair WeightNums =
+  setBranchWeight(Fn->getIntrinsicID(), CI, n + 1);
+  uint32_t LikelyBranchWeightVal = WeightNums.first;
+  uint32_t UnlikelyBranchWeightVal = WeightNums.second;
+
+  SmallVector Weights(n + 1, UnlikelyBranchWeightVal);
 
   uint64_t Index = (Case == *SI.case_default()) ? 0 : Case.getCaseIndex() + 1;
-  Weights[Index] = LikelyBranchWeight;
+  Weights[Index] = LikelyBranchWeightVal;
 
-  SI.setMetadata(
-  LLVMContext::MD_misexpect,
-  MDBuilder(CI->getContext())
-  .createMisExpect(Index, LikelyBranchWeight, UnlikelyBranchWeight));
+  SI.setMetadata(LLVMContext::MD_misexpect,
+ MDBuilder(CI->getContext())
+  

[PATCH] D76794: [Matrix] Implement * binary operator for MatrixType.

2020-06-06 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 269027.
fhahn marked 2 inline comments as done.
fhahn added a comment.

In D76794#2078232 , @rjmccall wrote:

> Your IRGen test cases cover a lot of ground, but please add more Sema test 
> cases that go over the basics: element types matching, column/row counts 
> matching, multiplication by inappropriate scalars, etc.  Otherwise LGTM!


Oh, of course! I think some of those might have been accidentally dropped when 
moving patches around. I've added the additional Sema tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76794

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGen/matrix-type-operators.c
  clang/test/CodeGenCXX/matrix-type-operators.cpp
  clang/test/Sema/matrix-type-operators.c
  clang/test/SemaCXX/matrix-type-operators.cpp
  llvm/include/llvm/IR/MatrixBuilder.h

Index: llvm/include/llvm/IR/MatrixBuilder.h
===
--- llvm/include/llvm/IR/MatrixBuilder.h
+++ llvm/include/llvm/IR/MatrixBuilder.h
@@ -33,6 +33,21 @@
   IRBuilderTy 
   Module *getModule() { return B.GetInsertBlock()->getParent()->getParent(); }
 
+  std::pair splatScalarOperandIfNeeded(Value *LHS,
+ Value *RHS) {
+assert((LHS->getType()->isVectorTy() || RHS->getType()->isVectorTy()) &&
+   "One of the operands must be a matrix (embedded in a vector)");
+if (LHS->getType()->isVectorTy() && !RHS->getType()->isVectorTy())
+  RHS = B.CreateVectorSplat(
+  cast(LHS->getType())->getNumElements(), RHS,
+  "scalar.splat");
+else if (!LHS->getType()->isVectorTy() && RHS->getType()->isVectorTy())
+  LHS = B.CreateVectorSplat(
+  cast(RHS->getType())->getNumElements(), LHS,
+  "scalar.splat");
+return {LHS, RHS};
+  }
+
 public:
   MatrixBuilder(IRBuilderTy ) : B(Builder) {}
 
@@ -164,15 +179,13 @@
: B.CreateSub(LHS, RHS);
   }
 
-  /// Multiply matrix \p LHS with scalar \p RHS.
+  /// Multiply matrix \p LHS with scalar \p RHS or scalar \p LHS with matrix \p
+  /// RHS.
   Value *CreateScalarMultiply(Value *LHS, Value *RHS) {
-Value *ScalarVector =
-B.CreateVectorSplat(cast(LHS->getType())->getNumElements(),
-RHS, "scalar.splat");
-if (RHS->getType()->isFloatingPointTy())
-  return B.CreateFMul(LHS, ScalarVector);
-
-return B.CreateMul(LHS, ScalarVector);
+std::tie(LHS, RHS) = splatScalarOperandIfNeeded(LHS, RHS);
+if (LHS->getType()->getScalarType()->isFloatingPointTy())
+  return B.CreateFMul(LHS, RHS);
+return B.CreateMul(LHS, RHS);
   }
 
   /// Extracts the element at (\p RowIdx, \p ColumnIdx) from \p Matrix.
Index: clang/test/SemaCXX/matrix-type-operators.cpp
===
--- clang/test/SemaCXX/matrix-type-operators.cpp
+++ clang/test/SemaCXX/matrix-type-operators.cpp
@@ -65,6 +65,45 @@
   // expected-note@-1 {{in instantiation of function template specialization 'subtract' requested here}}
 }
 
+template 
+typename MyMatrix::matrix_t multiply(MyMatrix , MyMatrix ) {
+  char *v1 = A.value * B.value;
+  // expected-error@-1 {{cannot initialize a variable of type 'char *' with an rvalue of type 'unsigned int __attribute__((matrix_type(2, 2)))'}}
+  // expected-error@-2 {{invalid operands to binary expression ('MyMatrix::matrix_t' (aka 'unsigned int __attribute__((matrix_type(3, 2)))') and 'MyMatrix::matrix_t' (aka 'unsigned int __attribute__((matrix_type(3, 3)))'))}}
+  // expected-error@-3 {{invalid operands to binary expression ('MyMatrix::matrix_t' (aka 'float __attribute__((matrix_type(2, 2)))') and 'MyMatrix::matrix_t' (aka 'unsigned int __attribute__((matrix_type(2, 2)))'))}}
+
+  MyMatrix m;
+  B.value = m.value * A.value;
+  // expected-error@-1 {{invalid operands to binary expression ('MyMatrix::matrix_t' (aka 'int __attribute__((matrix_type(5, 6)))') and 'MyMatrix::matrix_t' (aka 'unsigned int __attribute__((matrix_type(2, 2)))'))}}
+  // expected-error@-2 {{invalid operands to binary expression ('MyMatrix::matrix_t' (aka 'int __attribute__((matrix_type(5, 6)))') and 'MyMatrix::matrix_t' (aka 'unsigned int __attribute__((matrix_type(3, 2)))'))}}
+  // expected-error@-3 {{invalid operands to binary expression ('MyMatrix::matrix_t' (aka 'int __attribute__((matrix_type(5, 6)))') and 'MyMatrix::matrix_t' (aka 'float __attribute__((matrix_type(2, 2)))'))}}
+
+  return A.value * B.value;
+  // expected-error@-1 {{invalid operands to binary expression ('MyMatrix::matrix_t' (aka 'unsigned int __attribute__((matrix_type(3, 2)))') and 'MyMatrix::matrix_t' (aka 'unsigned int __attribute__((matrix_type(3, 3)))'))}}
+  // expected-error@-2 {{invalid 

[PATCH] D76794: [Matrix] Implement * binary operator for MatrixType.

2020-06-06 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added inline comments.



Comment at: clang/lib/Sema/SemaExpr.cpp:12130
+  QualType LHSType = LHS.get()->getType().getUnqualifiedType();
+  QualType RHSType = RHS.get()->getType().getUnqualifiedType();
+

rjmccall wrote:
> You never actually do anything with these that cares about having gotten the 
> unqualified type.
Ah right! I think that was still a left-over from the manual conversion code. 
Dropped!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76794



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


[PATCH] D79842: [clang][Driver] Correct tool search path priority

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



Comment at: clang/test/Driver/program-path-priority.c:15
+// "program path" for these tests
+// RUN: rm -rf %t
+// RUN: mkdir -p %t

`rm -rf %t && mkdir -p %t`
You can do this on one line



Comment at: clang/test/Driver/program-path-priority.c:17
+// RUN: mkdir -p %t
+// RUN: cp %clang %t
+

clang can be of several hundred bytes. Copying it is expensive. Use `ln -s` and 
add `UNSUPPORTED: system-windows` with a comment saying "Don't create symlinks 
on Windows" or similar



Comment at: clang/test/Driver/program-path-priority.c:19
+
+// No gccs at all, nothing is found
+// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 \

You can use `/// ` to make comments stand out from RUN and CHECK lines.



Comment at: clang/test/Driver/program-path-priority.c:20
+// No gccs at all, nothing is found
+// RUN: env "PATH=" %t/clang -### -target notreal-none-elf %s 2>&1 \
+// RUN: | FileCheck --check-prefix=NO_NOTREAL_GCC %s

Place `\` on the previous line to emphasize it has a continuation. Add two 
spaces before the continuation line to emphasize it is a continuation line.



Comment at: clang/test/Driver/program-path-priority.c:39
+// RUN: | FileCheck --check-prefix=ENV_PATH_NOTREAL_GCC %s
+// ENV_PATH_NOTREAL_GCC: env{{/|}}notreal-none-elf-gcc
+

Just use `/` since you are going to use `ln -s` `chmod +x` etc


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D79842



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


[PATCH] D72778: [Matrix] Add __builtin_matrix_transpose to Clang.

2020-06-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:1642
+  return cast(Ty.getCanonicalType());
+};
+

Unnecessary semicolon.  I think it's probably clearer just to 
`castAs()` inline in the code rather than introducing this 
trivial wrapper for it.  We generally treat getAs/castAs as idiomatically 
implying the result type strong enough to permit `auto`, just like `dyn_cast`, 
so it'll probably even be more compact than this overall.



Comment at: clang/lib/Sema/SemaChecking.cpp:1920
+  return ExprError();
+}
+

I don't think there's a need for this explicit check, since you're going to 
require the argument to have matrix type.



Comment at: clang/lib/Sema/SemaChecking.cpp:15051
+
+  Expr *Arg = TheCall->getArg(0);
+  if (!Arg->getType()->isConstantMatrixType()) {

When a builtin has custom type-checking (`t`), you need to handle placeholders 
in the operands yourself, just like you would for an operator.



Comment at: clang/lib/Sema/SemaChecking.cpp:15060
+  ConstantMatrixType const *MType =
+  cast(Arg->getType().getCanonicalType());
+  QualType ResultType = Context.getConstantMatrixType(

Don't canonicalize here, and you don't need to include `const` anyway.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72778



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


[PATCH] D76794: [Matrix] Implement * binary operator for MatrixType.

2020-06-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

Your IRGen test cases cover a lot of ground, but please add more Sema test 
cases that go over the basics: element types matching, column/row counts 
matching, multiplication by inappropriate scalars, etc.  Otherwise LGTM!




Comment at: clang/lib/Sema/SemaExpr.cpp:12130
+  QualType LHSType = LHS.get()->getType().getUnqualifiedType();
+  QualType RHSType = RHS.get()->getType().getUnqualifiedType();
+

You never actually do anything with these that cares about having gotten the 
unqualified type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D76794



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


[PATCH] D81311: [RFC] LangRef: Define inmem parameter attribute

2020-06-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D81311#2077944 , @arsenm wrote:

> In D81311#2077868 , @rjmccall wrote:
>
> > Most of the generalized optimization properties of this attribute seem to 
> > be redundant with existing attributes.  What are the properties you're 
> > trying to convey exactly?  The argument is a pointer to memory of a certain 
> > size and alignment, and that memory is known to be exclusive to this call 
> > and also constant?
>
>
> It's really just the in memory size and alignment. In this case, constantness 
> is implicit since I'll use a constant address space for the pointer (and 
> probably mark the parameter with readonly for good measure)


In principle, `readonly` has the same issues that lead to this attribute being 
necessary: it's not really a semantic contract, it's something that can be 
placed on the argument by IR.  But it's probably to separate that.

>> I don't think in practice those other attributes would ever not be preserved 
>> through IR passes, especially for kernels.  I guess they could be introduced 
>> by other analyses, and you wouldn't want this property to be confused with 
>> that?  Still, maybe it would be less redundant to just have this attribute 
>> require the existence of those other attributes (particularly 
>> `dereferenceable` and `align`) rather than providing its own structure.
> 
> I believe byval implies dereferencable already, and I was just trying to be 
> more explicit than what the others state. The alignment behavior also matches 
> what the other attributes already do. I expect in practice to always emit an 
> align attribute

It's generally best to insist on strong rules up front and then weaken them if 
there's really a use case.  There's no good reason not to carry an alignment.

>> Do you actually need any of the structure of the type beyond a size and 
>> alignment?
> 
> Not really. I just need to distinguish whether you are are using 
> sizeof(struct Foo) or a pointer sized slot in the argument buffer

Okay.  I think just carrying numbers is probably less representationally 
problematic.

My thinking here is that we can make this attribute something that we'd just 
add by default to all indirect arguments, and then the only special case 
behavior you need for kernels is that (1) there's a stable size and alignment 
that you can extract into the kernel-invocation system, which is probably not 
otherwise useful to IR beyond the existing attributes, and (2) the frontend 
needs to copy from the argument to form the mutable parameter variable.


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

https://reviews.llvm.org/D81311



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


[PATCH] D81311: [RFC] LangRef: Define inmem parameter attribute

2020-06-06 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

I wonder if `byref` would be a better name for this, as a way to say that the 
object is semantically a direct argument that's being passed by implicit 
reference.


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

https://reviews.llvm.org/D81311



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


[PATCH] D81254: [analyzer] Produce symbolic values for C-array elements

2020-06-06 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RegionStore.cpp:1709
   if (!O.getRegion())
-return UnknownVal();
+return svalBuilder.getRegionValueSymbolVal(R);
 

As soon as contents of the array change during analysis, this becomes 
incorrect: we cannot keep denoting a new value with the same old symbol.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81254



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


[PATCH] D81176: [HIP] Add default header and include path

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

In D81176#2077940 , @thakis wrote:

> One more example failure: 
> http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/16333
>
> (Note I had re-reverted your reland, see the 2 comments above your comment.)


Sorry I missed that failure. I have fixed that issue and recommitted again. I 
will monitor it and revert if necessary. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81176



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


[PATCH] D80876: [clang] Default to windows response files when running on windows

2020-06-06 Thread Martin Storsjö via Phabricator via cfe-commits
mstorsjo added a comment.

In D80876#2071997 , @sbc100 wrote:

> In D80876#2070233 , @mstorsjo wrote:
>
> > In D80876#2069970 , @sbc100 wrote:
> >
> > > Do you know how gcc handles this case when running on mingw?
> >
> >
> > It uses the gnu/unix quoting style - so that's the case for wanting clang 
> > to preserve compatibility with that behaviour.
>
>
> Is there any case where gcc on windows will use the windows quoting style?


Not that I'm aware of, no.

> If the answer is no, and I assume GNU ar is the same, then perhaps the 
> solution is revert https://reviews.llvm.org/D69665 instead and have all the 
> llvm tools except clang-cl default to the GNU style.

Hmm, that might be at least one consistent strategy. For llvm-ar, it'd default 
to posix quoting, while llvm-lib does use windows style quoting. (It probably 
doesn't need a full revert, but keeping the rsp-quoting option, just changing 
the default.)

In one sense, it feels weird to stop doing the native thing in these tools, 
just for the sake of the mingw usecase - but on the other hand, if there's no 
other predecent for using windows style quoting with those particular tools, 
and there is predecent for keeping the posix quoting, I guess it should be 
fine. That would at least be a path forward without potentially breaking the 
msys2/mingw ecosystem.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80876



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


[clang] cdd683b - [gcov] Support big-endian .gcno and simplify version handling in .gcda

2020-06-06 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2020-06-06T11:01:47-07:00
New Revision: cdd683b516d147925212724b09ec6fb792a40041

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

LOG: [gcov] Support big-endian .gcno and simplify version handling in .gcda

Added: 


Modified: 
clang/test/CodeGen/code-coverage.c
compiler-rt/lib/profile/GCDAProfiling.c
llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
llvm/test/Transforms/GCOVProfiling/function-numbering.ll
llvm/test/Transforms/GCOVProfiling/version.ll

Removed: 




diff  --git a/clang/test/CodeGen/code-coverage.c 
b/clang/test/CodeGen/code-coverage.c
index 2b3e90fac5cd..3a11cb2c7df7 100644
--- a/clang/test/CodeGen/code-coverage.c
+++ b/clang/test/CodeGen/code-coverage.c
@@ -35,13 +35,18 @@ int test2(int b) {
   return b * 2;
 }
 
-// 402: private unnamed_addr constant [5 x i8] c"*204\00"
-// 407: private unnamed_addr constant [5 x i8] c"*704\00"
-// 408: private unnamed_addr constant [5 x i8] c"*804\00"
 
 // CHECK: @__llvm_internal_gcov_emit_function_args.0 = internal unnamed_addr 
constant [2 x %0]
 // CHECK-SAME: [%0 zeroinitializer, %0 { i32 1, i32 0, i32 0 }]
 
+// CHECK: @__llvm_internal_gcov_emit_file_info = internal unnamed_addr 
constant [1 x %2]
+/// 0x3430322a '4' '0' '2' '*'
+// 402-SAME: i32 875573802
+/// 0x3430372a '4' '0' '7' '*'
+// 407-SAME: i32 875575082
+/// 0x3430382a '4' '0' '8' '*'
+// 408-SAME: i32 875575338
+
 // Check that the noredzone flag is set on the generated functions.
 
 // CHECK: void @__llvm_gcov_writeout() unnamed_addr [[NRZ:#[0-9]+]]

diff  --git a/compiler-rt/lib/profile/GCDAProfiling.c 
b/compiler-rt/lib/profile/GCDAProfiling.c
index ccbd180fff36..cea7eb8ec954 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -349,7 +349,7 @@ static void unmap_file() {
  * started at a time.
  */
 COMPILER_RT_VISIBILITY
-void llvm_gcda_start_file(const char *orig_filename, const char version[4],
+void llvm_gcda_start_file(const char *orig_filename, uint32_t version,
   uint32_t checksum) {
   const char *mode = "r+b";
   filename = mangle_filename(orig_filename);
@@ -406,20 +406,15 @@ void llvm_gcda_start_file(const char *orig_filename, 
const char version[4],
   }
 
   /* gcda file, version, stamp checksum. */
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-  gcov_version = version[3] >= 'A'
- ? (version[3] - 'A') * 100 + (version[2] - '0') * 10 +
-   version[1] - '0'
- : (version[3] - '0') * 10 + version[1] - '0';
-#else
-  gcov_version = version[0] >= 'A'
- ? (version[0] - 'A') * 100 + (version[1] - '0') * 10 +
-   version[2] - '0'
- : (version[0] - '0') * 10 + version[2] - '0';
-#endif
-
+  {
+uint8_t c3 = version >> 24;
+uint8_t c2 = (version >> 16) & 255;
+uint8_t c1 = (version >> 8) & 255;
+gcov_version = c3 >= 'A' ? (c3 - 'A') * 100 + (c2 - '0') * 10 + c1 - '0'
+ : (c3 - '0') * 10 + c1 - '0';
+  }
   write_32bit_value(GCOV_DATA_MAGIC);
-  write_bytes(version, 4);
+  write_32bit_value(version);
   write_32bit_value(checksum);
 
 #ifdef DEBUG_GCDAPROFILING

diff  --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp 
b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index 0a83155007cf..d24a6ddfbb69 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -45,10 +45,19 @@
 #include 
 #include 
 #include 
+
 using namespace llvm;
+namespace endian = llvm::support::endian;
 
 #define DEBUG_TYPE "insert-gcov-profiling"
 
+enum : uint32_t {
+  GCOV_TAG_FUNCTION = 0x0100,
+  GCOV_TAG_BLOCKS = 0x0141,
+  GCOV_TAG_ARCS = 0x0143,
+  GCOV_TAG_LINES = 0x0145,
+};
+
 static cl::opt DefaultGCOVVersion("default-gcov-version",
cl::init("408*"), cl::Hidden,
cl::ValueRequired);
@@ -73,15 +82,7 @@ class GCOVFunction;
 class GCOVProfiler {
 public:
   GCOVProfiler() : GCOVProfiler(GCOVOptions::getDefault()) {}
-  GCOVProfiler(const GCOVOptions ) : Options(Opts) {
-assert((Options.EmitNotes || Options.EmitData) &&
-   "GCOVProfiler asked to do nothing?");
-ReversedVersion[0] = Options.Version[3];
-ReversedVersion[1] = Options.Version[2];
-ReversedVersion[2] = Options.Version[1];
-ReversedVersion[3] = Options.Version[0];
-ReversedVersion[4] = '\0';
-  }
+  GCOVProfiler(const GCOVOptions ) : Options(Opts) {}
   bool
   runOnModule(Module ,
   std::function GetTLI);
@@ -120,8 +121,6 @@ class GCOVProfiler {
 
   GCOVOptions Options;
 
-  // 

[PATCH] D78717: [SystemZ] Implement -fstack-clash-protection

2020-06-06 Thread Jonas Paulsson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
jonpa marked an inline comment as done.
Closed by commit rG515bfc66eace (authored by jonpa).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D78717?vs=268419=269023#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D78717

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/SystemZ.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/stack-clash-protection.c
  clang/test/Driver/stack-clash-protection-02.c
  llvm/include/llvm/ADT/Triple.h
  llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
  llvm/lib/Target/SystemZ/SystemZFrameLowering.h
  llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
  llvm/lib/Target/SystemZ/SystemZISelLowering.h
  llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
  llvm/lib/Target/SystemZ/SystemZInstrInfo.h
  llvm/lib/Target/SystemZ/SystemZInstrInfo.td
  llvm/lib/Target/SystemZ/SystemZOperators.td
  llvm/test/CodeGen/SystemZ/stack-clash-dynamic-alloca.ll
  llvm/test/CodeGen/SystemZ/stack-clash-protection.ll

Index: llvm/test/CodeGen/SystemZ/stack-clash-protection.ll
===
--- /dev/null
+++ llvm/test/CodeGen/SystemZ/stack-clash-protection.ll
@@ -0,0 +1,242 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z14 -O3 | FileCheck %s
+;
+; Test stack clash protection probing for static allocas.
+
+; Small: one probe.
+define i32 @fun0() #0 {
+; CHECK-LABEL: fun0:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:aghi %r15, -560
+; CHECK-NEXT:.cfi_def_cfa_offset 720
+; CHECK-NEXT:cg %r0, 552(%r15)
+; CHECK-NEXT:mvhi 552(%r15), 1
+; CHECK-NEXT:l %r2, 160(%r15)
+; CHECK-NEXT:aghi %r15, 560
+; CHECK-NEXT:br %r14
+
+  %a = alloca i32, i64 100
+  %b = getelementptr inbounds i32, i32* %a, i64 98
+  store volatile i32 1, i32* %b
+  %c = load volatile i32, i32* %a
+  ret i32 %c
+}
+
+; Medium: two probes.
+define i32 @fun1() #0 {
+; CHECK-LABEL: fun1:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:aghi %r15, -4096
+; CHECK-NEXT:.cfi_def_cfa_offset 4256
+; CHECK-NEXT:cg %r0, 4088(%r15)
+; CHECK-NEXT:aghi %r15, -4080
+; CHECK-NEXT:.cfi_def_cfa_offset 8336
+; CHECK-NEXT:cg %r0, 4072(%r15)
+; CHECK-NEXT:mvhi 976(%r15), 1
+; CHECK-NEXT:l %r2, 176(%r15)
+; CHECK-NEXT:aghi %r15, 8176
+; CHECK-NEXT:br %r14
+
+  %a = alloca i32, i64 2000
+  %b = getelementptr inbounds i32, i32* %a, i64 200
+  store volatile i32 1, i32* %b
+  %c = load volatile i32, i32* %a
+  ret i32 %c
+}
+
+; Large: Use a loop to allocate and probe in steps.
+define i32 @fun2() #0 {
+; CHECK-LABEL: fun2:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:lgr %r1, %r15
+; CHECK-NEXT:.cfi_def_cfa_register %r1
+; CHECK-NEXT:agfi %r1, -69632
+; CHECK-NEXT:.cfi_def_cfa_offset 69792
+; CHECK-NEXT:  .LBB2_1: # =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:aghi %r15, -4096
+; CHECK-NEXT:cg %r0, 4088(%r15)
+; CHECK-NEXT:clgrjh %r15, %r1, .LBB2_1
+; CHECK-NEXT:  # %bb.2:
+; CHECK-NEXT:.cfi_def_cfa_register %r15
+; CHECK-NEXT:aghi %r15, -2544
+; CHECK-NEXT:.cfi_def_cfa_offset 72336
+; CHECK-NEXT:cg %r0, 2536(%r15)
+; CHECK-NEXT:lhi %r0, 1
+; CHECK-NEXT:mvhi 568(%r15), 1
+; CHECK-NEXT:sty %r0, 28968(%r15)
+; CHECK-NEXT:l %r2, 176(%r15)
+; CHECK-NEXT:agfi %r15, 72176
+; CHECK-NEXT:br %r14
+
+  %a = alloca i32, i64 18000
+  %b0 = getelementptr inbounds i32, i32* %a, i64 98
+  %b1 = getelementptr inbounds i32, i32* %a, i64 7198
+  store volatile i32 1, i32* %b0
+  store volatile i32 1, i32* %b1
+  %c = load volatile i32, i32* %a
+  ret i32 %c
+}
+
+; Ends evenly on the step so no remainder needed.
+define void @fun3() #0 {
+; CHECK-LABEL: fun3:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:lgr %r1, %r15
+; CHECK-NEXT:.cfi_def_cfa_register %r1
+; CHECK-NEXT:aghi %r1, -28672
+; CHECK-NEXT:.cfi_def_cfa_offset 28832
+; CHECK-NEXT:  .LBB3_1: # %entry
+; CHECK-NEXT:# =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:aghi %r15, -4096
+; CHECK-NEXT:cg %r0, 4088(%r15)
+; CHECK-NEXT:clgrjh %r15, %r1, .LBB3_1
+; CHECK-NEXT:  # %bb.2: # %entry
+; CHECK-NEXT:.cfi_def_cfa_register %r15
+; CHECK-NEXT:mvhi 180(%r15), 0
+; CHECK-NEXT:l %r0, 180(%r15)
+; CHECK-NEXT:aghi %r15, 28672
+; CHECK-NEXT:br %r14
+entry:
+  %stack = alloca [7122 x i32], align 4
+  %i = alloca i32, align 4
+  %0 = bitcast [7122 x i32]* %stack to i8*
+  %i.0.i.0..sroa_cast = bitcast i32* %i to i8*
+  store volatile i32 0, i32* %i, align 4
+  %i.0.i.0.6 = load volatile i32, i32* %i, align 4
+  ret void
+}
+
+; Loop with bigger step.
+define void @fun4() #0 "stack-probe-size"="8192" {
+; CHECK-LABEL: fun4:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:lgr 

[clang] 515bfc6 - [SystemZ] Implement -fstack-clash-protection

2020-06-06 Thread Jonas Paulsson via cfe-commits

Author: Jonas Paulsson
Date: 2020-06-06T18:38:36+02:00
New Revision: 515bfc66eaced830c03b2ec187bef0d8c4dc6915

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

LOG: [SystemZ] Implement -fstack-clash-protection

Probing of allocated stack space is now done when this option is passed. The
purpose is to protect against the stack clash attack (see
https://www.qualys.com/2017/06/19/stack-clash/stack-clash.txt).

Review: Ulrich Weigand

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

Added: 
clang/test/Driver/stack-clash-protection-02.c
llvm/test/CodeGen/SystemZ/stack-clash-dynamic-alloca.ll
llvm/test/CodeGen/SystemZ/stack-clash-protection.ll

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Basic/Targets/SystemZ.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/CodeGen/stack-clash-protection.c
llvm/include/llvm/ADT/Triple.h
llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
llvm/lib/Target/SystemZ/SystemZFrameLowering.h
llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
llvm/lib/Target/SystemZ/SystemZISelLowering.h
llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp
llvm/lib/Target/SystemZ/SystemZInstrInfo.h
llvm/lib/Target/SystemZ/SystemZInstrInfo.td
llvm/lib/Target/SystemZ/SystemZOperators.td

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 25ff809120de..15e6d35117b4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -94,8 +94,8 @@ New Compiler Flags
 --
 
 - -fstack-clash-protection will provide a protection against the stack clash
-  attack for x86 architecture through automatic probing of each page of
-  allocated stack.
+  attack for x86 and s390x architectures through automatic probing of each page
+  of allocated stack.
 
 - -ffp-exception-behavior={ignore,maytrap,strict} allows the user to specify
   the floating-point exception behavior. The default setting is ``ignore``.

diff  --git a/clang/lib/Basic/Targets/SystemZ.h 
b/clang/lib/Basic/Targets/SystemZ.h
index 1c8822e2bc2d..134b0313b86a 100644
--- a/clang/lib/Basic/Targets/SystemZ.h
+++ b/clang/lib/Basic/Targets/SystemZ.h
@@ -64,6 +64,10 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public 
TargetInfo {
 
   ArrayRef getGCCAddlRegNames() const override;
 
+  bool isSPRegName(StringRef RegName) const override {
+return RegName.equals("r15");
+  }
+
   bool validateAsmConstraint(const char *,
  TargetInfo::ConstraintInfo ) const override;
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index b20048768e44..513f32caad8a 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2997,7 +2997,7 @@ static void RenderSCPOptions(const ToolChain , const 
ArgList ,
   if (!EffectiveTriple.isOSLinux())
 return;
 
-  if (!EffectiveTriple.isX86())
+  if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ())
 return;
 
   if (Args.hasFlag(options::OPT_fstack_clash_protection,

diff  --git a/clang/test/CodeGen/stack-clash-protection.c 
b/clang/test/CodeGen/stack-clash-protection.c
index f970bf909cbe..eb48da8ff9e9 100644
--- a/clang/test/CodeGen/stack-clash-protection.c
+++ b/clang/test/CodeGen/stack-clash-protection.c
@@ -1,5 +1,6 @@
 // Check the correct function attributes are generated
 // RUN: %clang_cc1 -triple x86_64-linux -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
+// RUN: %clang_cc1 -triple s390x-linux-gnu -O0 -S -emit-llvm -o- %s 
-fstack-clash-protection | FileCheck %s
 
 // CHECK: define void @large_stack() #[[A:.*]] {
 void large_stack() {

diff  --git a/clang/test/Driver/stack-clash-protection-02.c 
b/clang/test/Driver/stack-clash-protection-02.c
new file mode 100644
index ..25ff3b5d6940
--- /dev/null
+++ b/clang/test/Driver/stack-clash-protection-02.c
@@ -0,0 +1,13 @@
+// RUN: %clang -target s390x-linux-gnu -fstack-clash-protection -### %s 2>&1 | 
FileCheck %s -check-prefix=SystemZ
+// SystemZ: "-fstack-clash-protection"
+// RUN: %clang -target s390x-linux-gnu -fstack-clash-protection -S -emit-llvm 
-o %t.ll %s 2>&1 | FileCheck %s -check-prefix=SystemZ-warn
+// SystemZ-warn: warning: Unable to protect inline asm that clobbers stack 
pointer against stack clash
+
+int foo(int c) {
+  int r;
+  __asm__("ag %%r15, %0"
+  :
+  : "rm"(c)
+  : "r15");
+  return r;
+}

diff  --git a/llvm/include/llvm/ADT/Triple.h b/llvm/include/llvm/ADT/Triple.h
index fa437a57520a..8e46265c7f71 100644
--- a/llvm/include/llvm/ADT/Triple.h
+++ b/llvm/include/llvm/ADT/Triple.h
@@ -739,6 +739,11 @@ class Triple {
 return getArch() == Triple::riscv32 || getArch() == Triple::riscv64;
   }
 
+  /// Tests whether the 

[PATCH] D81332: Thread safety analysis: Support deferring locks

2020-06-06 Thread Aaron Puchert via Phabricator via cfe-commits
aaronpuchert created this revision.
aaronpuchert added reviewers: aaron.ballman, delesley.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The standard std::unique_lock can be constructed to manage a lock without
initially acquiring it by passing std::defer_lock as second parameter.
It can be acquired later by calling lock().

To support this, we use the locks_excluded attribute. This might seem
like an odd choice at first, but its consistent with the other
annotations we support on scoped capability constructors. By excluding
the lock we state that it is currently not in use and the function
doesn't change that, which is exactly what the constructor does.

Along the way we slightly simplify handling of scoped capabilities.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81332

Files:
  clang/lib/Analysis/ThreadSafety.cpp
  clang/test/SemaCXX/warn-thread-safety-analysis.cpp

Index: clang/test/SemaCXX/warn-thread-safety-analysis.cpp
===
--- clang/test/SemaCXX/warn-thread-safety-analysis.cpp
+++ clang/test/SemaCXX/warn-thread-safety-analysis.cpp
@@ -2625,9 +2625,12 @@
 
 namespace RelockableScopedLock {
 
+class DeferTraits {};
+
 class SCOPED_LOCKABLE RelockableExclusiveMutexLock {
 public:
   RelockableExclusiveMutexLock(Mutex *mu) EXCLUSIVE_LOCK_FUNCTION(mu);
+  RelockableExclusiveMutexLock(Mutex *mu, DeferTraits) LOCKS_EXCLUDED(mu);
   ~RelockableExclusiveMutexLock() EXCLUSIVE_UNLOCK_FUNCTION();
 
   void Lock() EXCLUSIVE_LOCK_FUNCTION();
@@ -2639,6 +2642,7 @@
 
 class SCOPED_LOCKABLE RelockableMutexLock {
 public:
+  RelockableMutexLock(Mutex *mu, DeferTraits) LOCKS_EXCLUDED(mu);
   RelockableMutexLock(Mutex *mu, SharedTraits) SHARED_LOCK_FUNCTION(mu);
   RelockableMutexLock(Mutex *mu, ExclusiveTraits) EXCLUSIVE_LOCK_FUNCTION(mu);
   ~RelockableMutexLock() UNLOCK_FUNCTION();
@@ -2669,6 +2673,13 @@
   x = 4;
 }
 
+void deferLock() {
+  RelockableExclusiveMutexLock scope(, DeferTraits{});
+  x = 2; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+  scope.Lock();
+  x = 3;
+}
+
 void relockExclusive() {
   RelockableMutexLock scope(, SharedTraits{});
   print(x);
@@ -2703,6 +2714,14 @@
   x = 5;
 }
 
+void deferLockShared() {
+  RelockableMutexLock scope(, DeferTraits{});
+  print(x); // expected-warning {{reading variable 'x' requires holding mutex 'mu'}}
+  scope.ReaderLock();
+  print(x);
+  x = 2; // expected-warning {{writing variable 'x' requires holding mutex 'mu' exclusively}}
+}
+
 void doubleUnlock() {
   RelockableExclusiveMutexLock scope();
   scope.Unlock();
Index: clang/lib/Analysis/ThreadSafety.cpp
===
--- clang/lib/Analysis/ThreadSafety.cpp
+++ clang/lib/Analysis/ThreadSafety.cpp
@@ -905,11 +905,7 @@
   ScopedLockableFactEntry(const CapabilityExpr , SourceLocation Loc)
   : FactEntry(CE, LK_Exclusive, Loc, false) {}
 
-  void addExclusiveLock(const CapabilityExpr ) {
-UnderlyingMutexes.emplace_back(M.sexpr(), UCK_Acquired);
-  }
-
-  void addSharedLock(const CapabilityExpr ) {
+  void addLock(const CapabilityExpr ) {
 UnderlyingMutexes.emplace_back(M.sexpr(), UCK_Acquired);
   }
 
@@ -1801,7 +1797,7 @@
   SourceLocation Loc = Exp->getExprLoc();
   CapExprSet ExclusiveLocksToAdd, SharedLocksToAdd;
   CapExprSet ExclusiveLocksToRemove, SharedLocksToRemove, GenericLocksToRemove;
-  CapExprSet ScopedExclusiveReqs, ScopedSharedReqs;
+  CapExprSet ScopedReqsAndExcludes;
   StringRef CapDiagKind = "mutex";
 
   // Figure out if we're constructing an object of scoped lockable class
@@ -1892,19 +1888,20 @@
  POK_FunctionCall, ClassifyDiagnostic(A),
  Exp->getExprLoc());
   // use for adopting a lock
-  if (isScopedVar) {
-Analyzer->getMutexIDs(A->isShared() ? ScopedSharedReqs
-: ScopedExclusiveReqs,
-  A, Exp, D, VD);
-  }
+  if (isScopedVar)
+Analyzer->getMutexIDs(ScopedReqsAndExcludes, A, Exp, D, VD);
 }
 break;
   }
 
   case attr::LocksExcluded: {
 const auto *A = cast(At);
-for (auto *Arg : A->args())
+for (auto *Arg : A->args()) {
   warnIfMutexHeld(D, Exp, Arg, ClassifyDiagnostic(A));
+  // use for deferring a lock
+  if (isScopedVar)
+Analyzer->getMutexIDs(ScopedReqsAndExcludes, A, Exp, D, VD);
+}
 break;
   }
 
@@ -1944,13 +1941,11 @@
 
 auto ScopedEntry = std::make_unique(Scp, MLoc);
 for (const auto  : ExclusiveLocksToAdd)
-  ScopedEntry->addExclusiveLock(M);
-for (const auto  : ScopedExclusiveReqs)
-  ScopedEntry->addExclusiveLock(M);
+  ScopedEntry->addLock(M);
 for (const auto  : SharedLocksToAdd)
-  ScopedEntry->addSharedLock(M);
-for (const 

[PATCH] D81252: [SVE ACLE] Remove redundant bool_t typedef.

2020-06-06 Thread Paul Walker via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd6d2f78fe504: [SVE ACLE] Remove redundant bool_t typedef. 
(authored by paulwalker-arm).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81252

Files:
  clang/utils/TableGen/SveEmitter.cpp


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -437,7 +437,8 @@
   S += "x" + utostr(getNumElements());
 if (NumVectors > 1)
   S += "x" + utostr(NumVectors);
-S += "_t";
+if (!isScalarPredicate())
+  S += "_t";
   }
 
   if (Constant)
@@ -1058,7 +1059,6 @@
   OS << "typedef __fp16 float16_t;\n";
   OS << "typedef float float32_t;\n";
   OS << "typedef double float64_t;\n";
-  OS << "typedef bool bool_t;\n\n";
 
   OS << "typedef __SVInt8_t svint8_t;\n";
   OS << "typedef __SVInt16_t svint16_t;\n";


Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -437,7 +437,8 @@
   S += "x" + utostr(getNumElements());
 if (NumVectors > 1)
   S += "x" + utostr(NumVectors);
-S += "_t";
+if (!isScalarPredicate())
+  S += "_t";
   }
 
   if (Constant)
@@ -1058,7 +1059,6 @@
   OS << "typedef __fp16 float16_t;\n";
   OS << "typedef float float32_t;\n";
   OS << "typedef double float64_t;\n";
-  OS << "typedef bool bool_t;\n\n";
 
   OS << "typedef __SVInt8_t svint8_t;\n";
   OS << "typedef __SVInt16_t svint16_t;\n";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d6d2f78 - [SVE ACLE] Remove redundant bool_t typedef.

2020-06-06 Thread Paul Walker via cfe-commits

Author: Paul Walker
Date: 2020-06-06T12:31:38Z
New Revision: d6d2f78fe504fb7b749b08c10558f42180d83d73

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

LOG: [SVE ACLE] Remove redundant bool_t typedef.

Subscribers: tschuett, cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/utils/TableGen/SveEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/SveEmitter.cpp 
b/clang/utils/TableGen/SveEmitter.cpp
index 7d99e39f9d03..be0e91d8b1d5 100644
--- a/clang/utils/TableGen/SveEmitter.cpp
+++ b/clang/utils/TableGen/SveEmitter.cpp
@@ -437,7 +437,8 @@ std::string SVEType::str() const {
   S += "x" + utostr(getNumElements());
 if (NumVectors > 1)
   S += "x" + utostr(NumVectors);
-S += "_t";
+if (!isScalarPredicate())
+  S += "_t";
   }
 
   if (Constant)
@@ -1058,7 +1059,6 @@ void SVEEmitter::createHeader(raw_ostream ) {
   OS << "typedef __fp16 float16_t;\n";
   OS << "typedef float float32_t;\n";
   OS << "typedef double float64_t;\n";
-  OS << "typedef bool bool_t;\n\n";
 
   OS << "typedef __SVInt8_t svint8_t;\n";
   OS << "typedef __SVInt16_t svint16_t;\n";



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


[PATCH] D81330: [clang][Sema] SequenceChecker: C++17 sequencing rule for overloaded operators.

2020-06-06 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno created this revision.
riccibruno added a reviewer: rsmith.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.
riccibruno added a parent revision: D81003: [clang][Sema] SequenceChecker: Also 
visit default arguments..

In C++17 the operand(s) of an overloaded operator are sequenced as for the 
corresponding built-in operator when the overloaded operator is called with the 
operator notation ([over.match.oper]p2).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D81330

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/SemaCXX/warn-unsequenced.cpp

Index: clang/test/SemaCXX/warn-unsequenced.cpp
===
--- clang/test/SemaCXX/warn-unsequenced.cpp
+++ clang/test/SemaCXX/warn-unsequenced.cpp
@@ -308,6 +308,174 @@
   }
 }
 
+namespace overloaded_operators {
+  struct E {
+E =(E &);
+E operator()(E);
+E operator()(E, E);
+E operator[](E);
+  } e;
+  // Binary operators with unsequenced operands.
+  E operator+(E,E);
+  E operator-(E,E);
+  E operator*(E,E);
+  E operator/(E,E);
+  E operator%(E,E);
+  E operator^(E,E);
+  E operator&(E,E);
+  E operator|(E,E);
+
+  E operator<(E,E);
+  E operator>(E,E);
+  E operator==(E,E);
+  E operator!=(E,E);
+  E operator>=(E,E);
+  E operator<=(E,E);
+
+  // Binary operators where the RHS is sequenced before the LHS in C++17.
+  E operator+=(E,E);
+  E operator-=(E,E);
+  E operator*=(E,E);
+  E operator/=(E,E);
+  E operator%=(E,E);
+  E operator^=(E,E);
+  E operator&=(E,E);
+  E operator|=(E,E);
+  E operator<<=(E,E);
+  E operator>>=(E,E);
+
+  // Binary operators where the LHS is sequenced before the RHS in C++17.
+  E operator<<(E,E);
+  E operator>>(E,E);
+  E operator&&(E,E);
+  E operator||(E,E);
+  E operator,(E,E);
+  E operator->*(E,E);
+
+  void test() {
+int i = 0;
+// Binary operators with unsequenced operands.
+((void)i++,e) + ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) - ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) * ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) / ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) % ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) ^ ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) & ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) | ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+
+((void)i++,e) < ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) > ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) == ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) != ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) <= ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) >= ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+// cxx17-warning@-2 {{multiple unsequenced modifications to 'i'}}
+
+// Binary operators where the RHS is sequenced before the LHS in C++17.
+((void)i++,e) = ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) += ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) -= ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) *= ((void)i++,e);
+// cxx11-warning@-1 {{multiple unsequenced modifications to 'i'}}
+((void)i++,e) /= ((void)i++,e);
+// 

[PATCH] D80804: [AMDGPU] Introduce Clang builtins to be mapped to AMDGCN atomic inc/dec intrinsics

2020-06-06 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam updated this revision to Diff 269013.
saiislam added a comment.

1. Added 64 bit variants of inc/dec as well
2. Added test cases for 64 bit variants


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80804

Files:
  clang/include/clang/Basic/BuiltinsAMDGPU.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGenCXX/builtin-amdgcn-atomic-inc-dec.cpp
  clang/test/Sema/builtin-amdgcn-atomic-inc-dec-failure.cpp
  clang/test/SemaOpenCL/builtins-amdgcn-error.cl

Index: clang/test/SemaOpenCL/builtins-amdgcn-error.cl
===
--- clang/test/SemaOpenCL/builtins-amdgcn-error.cl
+++ clang/test/SemaOpenCL/builtins-amdgcn-error.cl
@@ -144,3 +144,51 @@
   __builtin_amdgcn_s_setreg(x, 0); // expected-error {{argument to '__builtin_amdgcn_s_setreg' must be a constant integer}}
   __builtin_amdgcn_s_setreg(x, y); // expected-error {{argument to '__builtin_amdgcn_s_setreg' must be a constant integer}}
 }
+
+void test_atomic_inc32() {
+  int val = 17;
+  val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_inc32(4);// expected-error {{too few arguments to function call, expected 4}}
+  val = __builtin_amdgcn_atomic_inc32(, val, 4, 4, 4, 4);// expected-error {{too many arguments to function call, expected 4}}
+  val = __builtin_amdgcn_atomic_inc32(, val, 3.14, "");  // expected-warning {{implicit conversion from 'double' to 'unsigned int' changes value from 3.14 to 3}}
+  val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_ACQUIRE, 5);   // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'}}
+  const char ptr[] = "workgroup";
+  val = __builtin_amdgcn_atomic_inc32(, val, __ATOMIC_ACQUIRE, ptr); // expected-error {{expression is not a string literal}}
+}
+
+void test_atomic_inc64() {
+  __INT64_TYPE__ val = 17;
+  val = __builtin_amdgcn_atomic_inc64(, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_inc64(, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_inc64(4);// expected-error {{too few arguments to function call, expected 4}}
+  val = __builtin_amdgcn_atomic_inc64(, val, 4, 4, 4, 4);// expected-error {{too many arguments to function call, expected 4}}
+  val = __builtin_amdgcn_atomic_inc64(, val, 3.14, "");  // expected-warning {{implicit conversion from 'double' to 'unsigned int' changes value from 3.14 to 3}}
+  val = __builtin_amdgcn_atomic_inc64(, val, __ATOMIC_ACQUIRE, 5);   // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'}}
+  const char ptr[] = "workgroup";
+  val = __builtin_amdgcn_atomic_inc64(, val, __ATOMIC_ACQUIRE, ptr); // expected-error {{expression is not a string literal}}
+}
+
+void test_atomic_dec32() {
+  int val = 17;
+  val = __builtin_amdgcn_atomic_dec32(, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_dec32(, val, __ATOMIC_ACQUIRE - 1, "workgroup"); // expected-warning {{memory order argument to atomic operation is invalid}}
+  val = __builtin_amdgcn_atomic_dec32(4);// expected-error {{too few arguments to function call, expected 4}}
+  val = __builtin_amdgcn_atomic_dec32(, val, 4, 4, 4, 4);// expected-error {{too many arguments to function call, expected 4}}
+  val = __builtin_amdgcn_atomic_dec32(, val, 3.14, "");  // expected-warning {{implicit conversion from 'double' to 'unsigned int' changes value from 3.14 to 3}}
+  val = __builtin_amdgcn_atomic_dec32(, val, __ATOMIC_ACQUIRE, 5);   // expected-warning {{incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'}}
+  const char ptr[] = "workgroup";
+  val = __builtin_amdgcn_atomic_dec32(, val, __ATOMIC_ACQUIRE, ptr); // expected-error {{expression is not a string literal}}
+}
+
+void test_atomic_dec64() {
+  __INT64_TYPE__ val = 17;
+  val = __builtin_amdgcn_atomic_dec64(, val, __ATOMIC_SEQ_CST + 1, "workgroup"); // expected-warning {{memory order argument to atomic 

[PATCH] D57660: [Sema] SequenceChecker: Handle references, members and structured bindings.

2020-06-06 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno marked an inline comment as done.
riccibruno added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:2031-2033
+  "%select{|member |static member }0%2"
+  "%select{| of %3| of struct %4| of union %4| of class %4"
+  "| of structured binding %3}1">, InGroup;

rsmith wrote:
> I wonder if we could just print out a simple access path here (eg `x.a[3]`). 
> `APValue` has support for representing and pretty-printing such things 
> already, and you could try passing arbitrary lvalue expressions to the 
> constant evaluator to try to form them rather than special-casing a few 
> things in `getMemoryLocationImpl`.
Ah yes perhaps this can work. I will take a look at that. Thanks for the 
pointer!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D57660



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


[PATCH] D80753: [clang-tidy] remove duplicate fixes of alias checkers

2020-06-06 Thread Daniel via Phabricator via cfe-commits
Daniel599 marked an inline comment as done.
Daniel599 added inline comments.



Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:777
+  "or make sure they are both configured the same. "
+  "Aliased checkers: '{0}', '{1}'",
+  ExistingError.DiagnosticName, Error.DiagnosticName)

njames93 wrote:
> You don't really need the Aliased checkers note as that is wrapped in the 
> initial diagnostic message. 
> Also if there was a check that could spew out 3 different fix-its for the 
> same diagnostic, this would result in the duplication note being made twice, 
> maybe the notes should be cleared too?
regarding your comment about 3 fix-it, as we walked before, there isn't a case 
like that (I didn't find any) as I wanted to make a test out of it.
I added the last line as it would show who are the two that conflict 
(supporting the future case of more than 2 aliased checkers),
I can remove it if it doesn't help, let me know.

> maybe the notes should be cleared too?
I am open for suggestions about how to re-write this message :)
I also think it could be better



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

https://reviews.llvm.org/D80753



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


[PATCH] D80753: [clang-tidy] remove duplicate fixes of alias checkers

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



Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:777
+  "or make sure they are both configured the same. "
+  "Aliased checkers: '{0}', '{1}'",
+  ExistingError.DiagnosticName, Error.DiagnosticName)

You don't really need the Aliased checkers note as that is wrapped in the 
initial diagnostic message. 
Also if there was a check that could spew out 3 different fix-its for the same 
diagnostic, this would result in the duplication note being made twice, maybe 
the notes should be cleared too?


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

https://reviews.llvm.org/D80753



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


[clang] 97a6709 - [ASan][Test] Fix globals test on 32-bit architectures

2020-06-06 Thread Marco Elver via cfe-commits

Author: Marco Elver
Date: 2020-06-06T11:23:16+02:00
New Revision: 97a670958c240d469c6baf2d3c601d4dea286069

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

LOG: [ASan][Test] Fix globals test on 32-bit architectures

Buildbot reports failures on e.g. armv7 and thumbv7. Fix the test by
expecting either i32 or i64 for the size-argument.

Added: 


Modified: 
clang/test/CodeGen/asan-globals.cpp

Removed: 




diff  --git a/clang/test/CodeGen/asan-globals.cpp 
b/clang/test/CodeGen/asan-globals.cpp
index f02bd173d31b..a5374caae5c4 100644
--- a/clang/test/CodeGen/asan-globals.cpp
+++ b/clang/test/CodeGen/asan-globals.cpp
@@ -23,8 +23,8 @@ void func() {
 // ASAN-NEXT: call void @__asan_version_mismatch_check
 // KASAN-NOT: call void @__asan_init
 // KASAN-NOT: call void @__asan_version_mismatch_check
-// ASAN-NEXT: call void @__asan_register_globals(i64 ptrtoint ({{.*}}, i64 6)
-// KASAN-NEXT: call void @__asan_register_globals(i64 ptrtoint ({{.*}}, i64 5)
+// ASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 6)
+// KASAN-NEXT: call void @__asan_register_globals({{.*}}, i{{32|64}} 5)
 // CHECK-NEXT: ret void
 
 // CHECK-LABEL: define internal void @asan.module_dtor



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


[PATCH] D79830: Add support of __builtin_expect_with_probability

2020-06-06 Thread Zhi Zhuang via Phabricator via cfe-commits
LukeZhuang updated this revision to Diff 269002.
LukeZhuang added a comment.
Herald added subscribers: Jim, dylanmckay.

**updated: 06/06/2020**
(1) convert argument to IEEEdouble for different target
(2) update tests, add edge cases and llvm test
(3) minor change


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

https://reviews.llvm.org/D79830

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/builtin-expect-with-probability-template.cpp
  clang/test/CodeGen/builtin-expect-with-probability.c
  clang/test/Sema/builtin-expect-with-probability-avr.cpp
  clang/test/Sema/builtin-expect-with-probability.cpp
  llvm/docs/BranchWeightMetadata.rst
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
  llvm/test/Transforms/LowerExpectIntrinsic/basic.ll

Index: llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
===
--- llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
+++ llvm/test/Transforms/LowerExpectIntrinsic/basic.ll
@@ -285,6 +285,29 @@
 
 declare i1 @llvm.expect.i1(i1, i1) nounwind readnone
 
+; CHECK-LABEL: @test11(
+define dso_local void @test11(i32 %0) noinline nounwind optnone uwtable {
+  %2 = alloca i32, align 4
+  store i32 %0, i32* %2, align 4
+  %3 = load i32, i32* %2, align 4
+  %4 = icmp sgt i32 %3, 0
+  %5 = zext i1 %4 to i32
+  %6 = sext i32 %5 to i64
+  %7 = call i64 @llvm.expect.with.probability.i64(i64 %6, i64 1, double 8.00e-01)
+  %8 = icmp ne i64 %7, 0
+  br i1 %8, label %9, label %10
+
+9:; preds = %1
+  call void (...) @ff()
+  br label %10
+
+10:   ; preds = %9, %1
+  ret void
+}
+
+declare i64 @llvm.expect.with.probability.i64(i64, i64, double) nounwind readnone willreturn
+declare dso_local void @ff(...)
+
 ; CHECK: !0 = !{!"branch_weights", i32 2000, i32 1}
 ; CHECK: !1 = !{!"misexpect", i64 0, i64 2000, i64 1}
 ; CHECK: !2 = !{!"branch_weights", i32 1, i32 2000}
@@ -292,3 +315,5 @@
 ; CHECK: !4 = !{!"branch_weights", i32 1, i32 1, i32 2000}
 ; CHECK: !5 = !{!"misexpect", i64 2, i64 2000, i64 1}
 ; CHECK: !6 = !{!"branch_weights", i32 2000, i32 1, i32 1}
+; CHECK: !7 = !{!"branch_weights", i32 1717986918, i32 429496731}
+; CHECK: !8 = !{!"misexpect", i64 0, i64 1717986918, i64 429496731}
Index: llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
===
--- llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
+++ llvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
@@ -55,13 +55,32 @@
 "unlikely-branch-weight", cl::Hidden, cl::init(1),
 cl::desc("Weight of the branch unlikely to be taken (default = 1)"));
 
+std::pair setBranchWeight(Intrinsic::ID IntrinsicID,
+  CallInst *CI, int BranchCount) {
+  if (IntrinsicID == Intrinsic::expect) {
+// __builtin_expect
+return {LikelyBranchWeight, UnlikelyBranchWeight};
+  } else {
+// __builtin_expect_with_probability
+assert(CI->getNumOperands() >= 3 &&
+   "expect with probability must have 3 arguments");
+ConstantFP *Confidence = dyn_cast(CI->getArgOperand(2));
+double TrueProb = Confidence->getValueAPF().convertToDouble();
+double FalseProb = (1.0 - TrueProb) / (BranchCount - 1);
+uint32_t LikelyBW = ceil((TrueProb * (double)(INT32_MAX - 1)) + 1.0);
+uint32_t UnlikelyBW = ceil((FalseProb * (double)(INT32_MAX - 1)) + 1.0);
+return {LikelyBW, UnlikelyBW};
+  }
+}
+
 static bool handleSwitchExpect(SwitchInst ) {
   CallInst *CI = dyn_cast(SI.getCondition());
   if (!CI)
 return false;
 
   Function *Fn = CI->getCalledFunction();
-  if (!Fn || Fn->getIntrinsicID() != Intrinsic::expect)
+  if (!Fn || (Fn->getIntrinsicID() != Intrinsic::expect &&
+  Fn->getIntrinsicID() != Intrinsic::expect_with_probability))
 return false;
 
   Value *ArgValue = CI->getArgOperand(0);
@@ -71,15 +90,20 @@
 
   SwitchInst::CaseHandle Case = *SI.findCaseValue(ExpectedValue);
   unsigned n = SI.getNumCases(); // +1 for default case.
-  SmallVector Weights(n + 1, UnlikelyBranchWeight);
+  std::pair WeightNums =
+  setBranchWeight(Fn->getIntrinsicID(), CI, n + 1);
+  uint32_t LikelyBranchWeightVal = WeightNums.first;
+  uint32_t UnlikelyBranchWeightVal = WeightNums.second;
+
+  SmallVector Weights(n + 1, UnlikelyBranchWeightVal);
 
   uint64_t Index = (Case == *SI.case_default()) ? 0 : Case.getCaseIndex() + 1;
-  Weights[Index] = LikelyBranchWeight;
+  Weights[Index] = LikelyBranchWeightVal;
 
-  SI.setMetadata(
-  LLVMContext::MD_misexpect,
-  MDBuilder(CI->getContext())
-  .createMisExpect(Index, LikelyBranchWeight, UnlikelyBranchWeight));
+  SI.setMetadata(LLVMContext::MD_misexpect,
+ 

[PATCH] D79830: Add support of __builtin_expect_with_probability

2020-06-06 Thread Zhi Zhuang via Phabricator via cfe-commits
LukeZhuang marked 12 inline comments as done.
LukeZhuang added a comment.

In D79830#2075038 , @davidxl wrote:

> Can you add some tests at the LLVM side?


added ll test case




Comment at: clang/lib/Sema/SemaChecking.cpp:1818-1819
+llvm::APFloat Probability = Eval.Val.getFloat();
+if (!(Probability >= llvm::APFloat(0.0) &&
+  Probability <= llvm::APFloat(1.0))) {
+  Diag(ProbArg->getLocStart(), diag::err_probability_out_of_range)

LukeZhuang wrote:
> rsmith wrote:
> > I think this will probably only work if the target `double` type is 
> > `IEEEdouble`. (Otherwise you'll be comparing an `IEEEdouble` `APFloat` to a 
> > different kind of `APFloat`.)
> > 
> > We do not guarantee that `double` is `IEEEdouble` for all our supported 
> > targets. In particular, for TCE and for AVR (at least under `-mdouble=32`), 
> > `double` is `IEEEsingle` instead.
> > 
> > It looks like your LLVM intrinsic expects an LLVM IR `double` (that is, an 
> > `IEEEdouble`) as its third argument, so perhaps the right thing to do would 
> > be to convert the `APFloat` to `IEEEdouble` here and in CodeGen. Please add 
> > a test for a target where `double` is not `IEEEdouble`.
> Hi, thank you for comments! I have several questions here:
> (1) I do not understand why "APFloat Probability >= APFloat(0.0)" is affected 
> by target here. Is this just a double come from C front-end and I check it 
> here? 
> (2) And also not sure in CGBuiltin, is there I convert it to llvm intrinsic? 
> How does target double type affect it?
> (3) If I convert APFloat to IEEEDouble, should I use APF.convertToDouble or 
> create a DoubleAPFloat. My original code did APFloat.convertToDouble and 
> compare, and I do not sure about the difference.
Sorry, after I test with different targets I understood your suggestion. It 
shows weird behavior in comparing for AVR target. Now I have converted to 
IEEEdouble. I also added test for AVR target and passed it.



Comment at: clang/test/Sema/builtin-expect-with-probability.cpp:18
+  bool dummy;
+  dummy = __builtin_expect_with_probability(x > 0, 1, 0.9);
+  dummy = __builtin_expect_with_probability(x > 0, 1, 1.1); // expected-error 
{{probability of __builtin_expect_with_probability is outside the range [0.0, 
1.0]}}

rsmith wrote:
> Please also test some more edge cases. such as: if the probability argument 
> is not convertible to float, or is inf or nan, negative zero, -denorm_min, or 
> 1+epsilon.
added more edge cases here and example for AVR target



Comment at: llvm/docs/BranchWeightMetadata.rst:18
 Branch weights might be fetch from the profiling file, or generated based on
-`__builtin_expect`_ instruction.
+`__builtin_expect`_ and `__builtin_expect_with_probability`_ instruction.
 

rsmith wrote:
> There are no instructions with these names. There are Clang builtin functions 
> with these names and LLVM intrinsics with similar but different names. This 
> document should be documenting the `llvm.expect` and 
> `llvm.expect.with.probability` intrinsics.
I also think I might had better add intrinsic documents in 
llvm/docs/LangRef.rst instead of here, and keep 
__builtin_exepct_with_probability here or discuss with the original author 
about this.


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

https://reviews.llvm.org/D79830



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


[PATCH] D81315: [Draft] [Prototype] warning for default constructed unique pointer dereferences

2020-06-06 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

Hi!

Please add the [analyzer] tag in front of your patches as some folks have 
automated scripts based on that tag to add themselves as subscriber/reviewer.

A small debugging/productivity tip, if you add a `printState` method to your 
checker like in 
https://github.com/llvm/llvm-project/blob/master/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp#L573
 , you will be able to see the checker state in the exploded graph dumps.

See some other comments inline.




Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:31
 namespace {
-class SmartPtrModeling : public Checker {
+struct RegionState {
+private:

I think `RegionState` is not very descriptive. I'd call it something like 
`RegionNullness`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81315



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


[PATCH] D81315: [Draft] [Prototype] warning for default constructed unique pointer dereferences

2020-06-06 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:46
+};
+} // end of anonymous namespace
+

You can merge the two anonymous namespaces, this and the one below.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:60
+private:
+  mutable std::unique_ptr BT;
+  void reportBug(CheckerContext , const CallEvent ) const;

This is how we used to do it, but we did not update all the checks yet. 
Nowadays we can just initialize bugtypes immediately, see 
https://github.com/llvm/llvm-project/blob/master/clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp#L169



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:65
+
+  // STL smart pointers which we are trying to model
+  const llvm::StringSet<> StdSmartPtrs = {

In LLVM we aim for full sentences as comments with a period at the end.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:119
+  ProgramStateRef State = C.getState();
+  const auto OC = dyn_cast();
+  if (!OC)

Here the const applies for the pointer, not the pointee. We usually do `const 
auto *OC` instead.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:134
+reportBug(C, Call);
+  }
+}

In case we did not report a bug, we could assume that the pointer is not-null 
and we could update the state accordingly. This is a common approach the 
analyzer takes. E.g. when we se a division by X, we either report a bug or add 
an assumption that X is non-zero. 



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:150
+  const CXXRecordDecl *RD = CtorDec->getParent();
+  if (isSmartPointer(RD)) {
+State =

I wonder if you wanted to add `isSmartPointer` checks below as well. In that 
case you can hoist this check and early return for non-smart-pointers.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:195
+  // Clean up dead regions from the region map.
+  TrackedRegionMapTy TrackedRegions = State->get();
+  for (auto E : TrackedRegions) {

You probably also want to clean up the `SymbolRegionMap`. It is ok to not do it 
right now, but we usually tend to add `FIXMEs` or `TODOs` early and 
aggressively to make sure we do not forget stuff. 



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:225
+  if (RecordDec->getDeclName().isIdentifier()) {
+return StdSmartPtrs.count(RecordDec->getName().lower());
+  }

This looks good for now. But we sometimes cache the pointer to identifier info 
objects so after the initial lookup we can just do pointer comparison instead 
of more expensive operations. Also add a fixme to check for the `std` namespace.

Also, this method could even be promoted to a free functions making the list of 
SmarPtrs global. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81315



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


[PATCH] D81131: [DebugInfo] Fix assertion for extern void type

2020-06-06 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song updated this revision to Diff 268995.
yonghong-song edited the summary of this revision.
yonghong-song added a comment.
Herald added subscribers: llvm-commits, hiraditya, aprantl.
Herald added a project: LLVM.

instead of skipping generating debuginfo for "extern void var_name", do 
generate debuginfo and skip emitting dwarf types for it.
cc @dblaikie


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D81131

Files:
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/DebugInfo/BPF/extern-void.ll
  llvm/test/DebugInfo/BPF/lit.local.cfg

Index: llvm/test/DebugInfo/BPF/lit.local.cfg
===
--- /dev/null
+++ llvm/test/DebugInfo/BPF/lit.local.cfg
@@ -0,0 +1,2 @@
+if not 'BPF' in config.root.targets:
+config.unsupported = True
Index: llvm/test/DebugInfo/BPF/extern-void.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/BPF/extern-void.ll
@@ -0,0 +1,81 @@
+; RUN: llc -march=bpfel -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+; RUN: llc -march=bpfeb -filetype=asm -o - %s | FileCheck -check-prefixes=CHECK %s
+;
+; Source code:
+;   extern void bla1;
+;   void *test1() {
+; void *x = 
+; return x;
+;   }
+;
+;   extern const void bla2;
+;   const void *test2() {
+; const void *x = 
+; return x;
+;   }
+; Compilation flag:
+;   clang -target bpf -O2 -g -S -emit-llvm t.c
+
+@bla1 = external dso_local global i8, align 1, !dbg !0
+@bla2 = external dso_local constant i8, align 1, !dbg !6
+
+; Function Attrs: norecurse nounwind readnone
+define dso_local nonnull i8* @test1() local_unnamed_addr #0 !dbg !13 {
+entry:
+  call void @llvm.dbg.value(metadata i8* @bla1, metadata !18, metadata !DIExpression()), !dbg !19
+  ret i8* @bla1, !dbg !20
+}
+
+; Function Attrs: norecurse nounwind readnone
+define dso_local nonnull i8* @test2() local_unnamed_addr #0 !dbg !21 {
+entry:
+  call void @llvm.dbg.value(metadata i8* @bla2, metadata !26, metadata !DIExpression()), !dbg !27
+  ret i8* @bla2, !dbg !28
+}
+
+; CHECK:.quad bla1
+; CHECK-NEXT:   DW_TAG_variable
+;
+; CHECK:.quad   bla2
+; CHECK-NEXT:   DW_TAG_const_type
+; CHECK-NEXT:   DW_TAG_subprogram
+
+; Function Attrs: nounwind readnone speculatable willreturn
+declare void @llvm.dbg.value(metadata, metadata, metadata) #1
+
+attributes #0 = { norecurse nounwind readnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
+attributes #1 = { nounwind readnone speculatable willreturn }
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!9, !10, !11}
+!llvm.ident = !{!12}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "bla1", scope: !2, file: !3, line: 1, isLocal: false, isDefinition: false)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 8a8c6913a931e8bbd119012f4badd81155a0f48a)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "t.c", directory: "/home/yhs/tmp3")
+!4 = !{}
+!5 = !{!0, !6}
+!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
+!7 = distinct !DIGlobalVariable(name: "bla2", scope: !2, file: !3, line: 7, type: !8, isLocal: false, isDefinition: false)
+!8 = !DIDerivedType(tag: DW_TAG_const_type, baseType: null)
+!9 = !{i32 7, !"Dwarf Version", i32 4}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+!11 = !{i32 1, !"wchar_size", i32 4}
+!12 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 8a8c6913a931e8bbd119012f4badd81155a0f48a)"}
+!13 = distinct !DISubprogram(name: "test1", scope: !3, file: !3, line: 2, type: !14, scopeLine: 2, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !17)
+!14 = !DISubroutineType(types: !15)
+!15 = !{!16}
+!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
+!17 = !{!18}
+!18 = !DILocalVariable(name: "x", scope: !13, file: !3, line: 3, type: !16)
+!19 = !DILocation(line: 0, scope: !13)
+!20 = !DILocation(line: 4, column: 3, scope: !13)
+!21 = distinct !DISubprogram(name: "test2", scope: !3, file: !3, line: 8, type: !22, scopeLine: 8, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !25)
+!22 = !DISubroutineType(types: !23)
+!23 = !{!24}
+!24 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !8, size: 64)