[clang] 62c221b - [Concepts] Profile TypeConstraints in ProfileTemplateParameterList

2020-01-23 Thread Saar Raz via cfe-commits

Author: Saar Raz
Date: 2020-01-23T09:59:51+02:00
New Revision: 62c221b5090c2e1d3ca408bcab6f69c4d9e175b7

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

LOG: [Concepts] Profile TypeConstraints in ProfileTemplateParameterList

Profile TypeConstraints in ProfileTemplateParameterList so we can distinguish
between partial specializations which differ in their TemplateParameterList
type constraints.

Recommit, now profiling the IDC so that we can deal with situations where the
TemplateArgsAsWritten are nullptr (happens when canonicalizing type 
constraints).

Added: 


Modified: 
clang/lib/AST/DeclTemplate.cpp

clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index e750bb8b6af7..9bd3b64feb4e 100755
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -488,7 +488,10 @@ static void ProfileTemplateParameterList(ASTContext &C,
 if (const auto *TTP = dyn_cast(D)) {
   ID.AddInteger(1);
   ID.AddBoolean(TTP->isParameterPack());
-  // TODO: Concepts: profile type-constraints.
+  ID.AddBoolean(TTP->hasTypeConstraint());
+  if (const TypeConstraint *TC = TTP->getTypeConstraint())
+TC->getImmediatelyDeclaredConstraint()->Profile(ID, C,
+/*Canonical=*/true);
   continue;
 }
 const auto *TTP = cast(D);

diff  --git 
a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
 
b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
index 1ea4da29ee9f..9f3c21f99174 100644
--- 
a/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
+++ 
b/clang/test/CXX/temp/temp.constr/temp.constr.constr/partial-specializations.cpp
@@ -31,6 +31,23 @@ namespace class_templates
   // expected-note@-2{{during template argument deduction for class template 
partial specialization 'B' [with T = int *]}}
   // expected-note@-3{{during template argument deduction for class template 
partial specialization 'B' [with T = int]}}
   // expected-note@-4 2{{in instantiation of template class 
'class_templates::B' requested here}}
+
+  template
+  concept same_as = is_same::value;
+
+  template T> requires A::type
+  struct B {};
+  // expected-note@-1{{previous}}
+
+  template T> requires A::type
+  struct B {};
+  // expected-error@-1{{redefinition}}
+
+  template requires A::type
+  struct B {};
+
+  template T> requires A::type
+  struct B {};
 }
 
 namespace variable_templates



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


[PATCH] D73199: [clangd] Errors in TestTU cause test failures unless suppressed with error-ok.

2020-01-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

LGTM, thanks for the cleanup!




Comment at: clang-tools-extra/clangd/unittests/TestTU.cpp:84
+  if (llvm::none_of(Files, [](const auto &KV) {
+return llvm::StringRef(KV.second).contains("error-ok");
+  })) {

should we make this more obscure, something like `// TESTTU: error-ok` ?

Even though it sounds implausible, just in case someone spells `error-ok` as 
part of the test, and silently drops the error :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73199



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


[PATCH] D73185: [AST] Add fixed-point subtraction constant evaluation.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan marked an inline comment as done.
ebevhan added inline comments.



Comment at: clang/include/clang/Basic/FixedPoint.h:82
+  unsigned IsSaturated: 1;
+  unsigned HasUnsignedPadding : 1;
 };

rjmccall wrote:
> These changes should probably be done in a separate patch.
> 
> I don't have a problem with compressing this type, but I'm curious if there 
> was a concrete motivation.
I can do it separately.

There wasn't really a strong motivation other than that it could be packed 
better than it was.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73185



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


[PATCH] D73185: [AST] Add fixed-point subtraction constant evaluation.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 239791.
ebevhan added a comment.

Move packing of FixedPointSemantics to a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73185

Files:
  clang/include/clang/Basic/FixedPoint.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/FixedPoint.cpp
  clang/test/Frontend/fixed_point_sub.c

Index: clang/test/Frontend/fixed_point_sub.c
===
--- clang/test/Frontend/fixed_point_sub.c
+++ clang/test/Frontend/fixed_point_sub.c
@@ -1,6 +1,55 @@
 // RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
 // RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
 
+// Subtraction between different fixed point types
+short _Accum sa_const = 1.0hk - 2.0hk;  // CHECK-DAG: @sa_const  = {{.*}}global i16 -128, align 2
+_Accum a_const = 1.0hk - 2.0k;  // CHECK-DAG: @a_const   = {{.*}}global i32 -32768, align 4
+long _Accum la_const = 1.0hk - 2.0lk;   // CHECK-DAG: @la_const  = {{.*}}global i64 -2147483648, align 8
+short _Accum sa_const2 = 0.5hr - 2.0hk; // CHECK-DAG: @sa_const2  = {{.*}}global i16 -192, align 2
+short _Accum sa_const3 = 0.5r - 2.0hk;  // CHECK-DAG: @sa_const3  = {{.*}}global i16 -192, align 2
+short _Accum sa_const4 = 0.5lr - 2.0hk; // CHECK-DAG: @sa_const4  = {{.*}}global i16 -192, align 2
+short _Accum sa_const5 = 2.0hk - 0.5lr; // CHECK-DAG: @sa_const5  = {{.*}}global i16 192, align 2
+
+// Unsigned subtraction
+unsigned short _Accum usa_const = 3.0uhk - 2.0uhk;
+// CHECK-SIGNED-DAG:   @usa_const = {{.*}}global i16 768, align 2
+// CHECK-UNSIGNED-DAG: @usa_const = {{.*}}global i16 384, align 2
+
+// Unsigned - signed
+short _Accum sa_const6 = 1.0uhk - 2.0hk;
+// CHECK-DAG: @sa_const6 = {{.*}}global i16 -128, align 2
+
+// Subtraction with negative number
+short _Accum sa_const7 = 0.5hr - (-2.0hk);
+// CHECK-DAG: @sa_const7 = {{.*}}global i16 320, align 2
+
+// Int subtraction
+unsigned short _Accum usa_const2 = 2 - 0.5uhk;
+// CHECK-SIGNED-DAG:   @usa_const2 = {{.*}}global i16 640, align 2
+// CHECK-UNSIGNED-DAG: @usa_const2 = {{.*}}global i16 320, align 2
+short _Accum sa_const8 = 2 - (-0.5hk);   // CHECK-DAG: @sa_const8 = {{.*}}global i16 320, align 2
+short _Accum sa_const9 = 257 - 2.0hk;// CHECK-DAG: @sa_const9 = {{.*}}global i16 32640, align 2
+long _Fract lf_const = 0.5lr - 1;// CHECK-DAG: @lf_const  = {{.*}}global i32 -1073741824, align 4
+
+// Saturated subtraction
+_Sat short _Accum sat_sa_const = (_Sat short _Accum)128.0hk - (-128.0hk);
+// CHECK-DAG: @sat_sa_const = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const = (_Sat unsigned short _Accum)128.0uhk - (-128.0uhk);
+// CHECK-SIGNED-DAG:   @sat_usa_const = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const = {{.*}}global i16 32767, align 2
+_Sat short _Accum sat_sa_const2 = (_Sat short _Accum)128.0hk - (-128);
+// CHECK-DAG: @sat_sa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const2 = (_Sat unsigned short _Accum)128.0uhk - (-128);
+// CHECK-SIGNED-DAG:   @sat_usa_const2 = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const3 = (_Sat unsigned short _Accum)0.5uhk - 2;
+// CHECK-DAG:   @sat_usa_const3 = {{.*}}global i16 0, align 2
+_Sat short _Accum sat_sa_const3 = (_Sat short _Accum)-128.0hk - 128;
+// CHECK-DAG: @sat_sa_const3 = {{.*}}global i16 -32768, align 2
+_Sat short _Accum sat_sa_const4 = (_Sat short _Accum)-150.0hk - 130.0lk;
+// CHECK-DAG: @sat_sa_const4 = {{.*}}global i16 -32768, align 2
+
+
 void SignedSubtraction() {
   // CHECK-LABEL: SignedSubtraction
   short _Accum sa;
Index: clang/lib/Basic/FixedPoint.cpp
===
--- clang/lib/Basic/FixedPoint.cpp
+++ clang/lib/Basic/FixedPoint.cpp
@@ -173,6 +173,30 @@
   return APFixedPoint(Result, CommonFXSema);
 }
 
+APFixedPoint APFixedPoint::sub(const APFixedPoint &Other,
+   bool *Overflow) const {
+  auto CommonFXSema = Sema.getCommonSemantics(Other.getSemantics());
+  APFixedPoint ConvertedThis = convert(CommonFXSema);
+  APFixedPoint ConvertedOther = Other.convert(CommonFXSema);
+  llvm::APSInt ThisVal = ConvertedThis.getValue();
+  llvm::APSInt OtherVal = ConvertedOther.getValue();
+  bool Overflowed = false;
+
+  llvm::APSInt Result;
+  if (CommonFXSema.isSaturated()) {
+Result = CommonFXSema.isSigned() ? ThisVal.ssub_sat(OtherVal)
+ : ThisVal.usub_sat(OtherVal);
+  } else {
+Result = ThisVal.isSigned() ? ThisVal.ssub_ov(OtherVal, Overflowed)
+: ThisVal.usub_ov(OtherVal, Overflowed);
+  }
+
+  if (Overflow)
+*Overfl

[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

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

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

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

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



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098



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


[PATCH] D73257: [AST] Compress the FixedPointSemantics type better.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan created this revision.
ebevhan added reviewers: rjmccall, leonardchan, bjope.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73257

Files:
  clang/include/clang/Basic/FixedPoint.h


Index: clang/include/clang/Basic/FixedPoint.h
===
--- clang/include/clang/Basic/FixedPoint.h
+++ clang/include/clang/Basic/FixedPoint.h
@@ -75,11 +75,11 @@
   }
 
 private:
-  unsigned Width;
-  unsigned Scale;
-  bool IsSigned;
-  bool IsSaturated;
-  bool HasUnsignedPadding;
+  unsigned Width  : 16;
+  unsigned Scale  : 13;
+  unsigned IsSigned   : 1;
+  unsigned IsSaturated: 1;
+  unsigned HasUnsignedPadding : 1;
 };
 
 /// The APFixedPoint class works similarly to APInt/APSInt in that it is a


Index: clang/include/clang/Basic/FixedPoint.h
===
--- clang/include/clang/Basic/FixedPoint.h
+++ clang/include/clang/Basic/FixedPoint.h
@@ -75,11 +75,11 @@
   }
 
 private:
-  unsigned Width;
-  unsigned Scale;
-  bool IsSigned;
-  bool IsSaturated;
-  bool HasUnsignedPadding;
+  unsigned Width  : 16;
+  unsigned Scale  : 13;
+  unsigned IsSigned   : 1;
+  unsigned IsSaturated: 1;
+  unsigned HasUnsignedPadding : 1;
 };
 
 /// The APFixedPoint class works similarly to APInt/APSInt in that it is a
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73257: [AST] Compress the FixedPointSemantics type better.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 239796.
ebevhan added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73257

Files:
  clang/include/clang/Basic/FixedPoint.h


Index: clang/include/clang/Basic/FixedPoint.h
===
--- clang/include/clang/Basic/FixedPoint.h
+++ clang/include/clang/Basic/FixedPoint.h
@@ -75,11 +75,11 @@
   }
 
 private:
-  unsigned Width;
-  unsigned Scale;
-  bool IsSigned;
-  bool IsSaturated;
-  bool HasUnsignedPadding;
+  unsigned Width  : 16;
+  unsigned Scale  : 13;
+  unsigned IsSigned   : 1;
+  unsigned IsSaturated: 1;
+  unsigned HasUnsignedPadding : 1;
 };
 
 /// The APFixedPoint class works similarly to APInt/APSInt in that it is a


Index: clang/include/clang/Basic/FixedPoint.h
===
--- clang/include/clang/Basic/FixedPoint.h
+++ clang/include/clang/Basic/FixedPoint.h
@@ -75,11 +75,11 @@
   }
 
 private:
-  unsigned Width;
-  unsigned Scale;
-  bool IsSigned;
-  bool IsSaturated;
-  bool HasUnsignedPadding;
+  unsigned Width  : 16;
+  unsigned Scale  : 13;
+  unsigned IsSigned   : 1;
+  unsigned IsSaturated: 1;
+  unsigned HasUnsignedPadding : 1;
 };
 
 /// The APFixedPoint class works similarly to APInt/APSInt in that it is a
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73182: [CodeGen] Emit IR for fixed-point multiplication and division.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 239793.
ebevhan added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73182

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Frontend/fixed_point_div.c
  clang/test/Frontend/fixed_point_mul.c

Index: clang/test/Frontend/fixed_point_mul.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_mul.c
@@ -0,0 +1,431 @@
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+void SignedMultiplication() {
+  // CHECK-LABEL: SignedMultiplication
+  short _Accum sa;
+  _Accum a, b, c, d;
+  long _Accum la;
+  unsigned short _Accum usa;
+  unsigned _Accum ua;
+  unsigned long _Accum ula;
+
+  short _Fract sf;
+  _Fract f;
+  long _Fract lf;
+  unsigned short _Fract usf;
+  unsigned _Fract uf;
+  unsigned long _Fract ulf;
+
+  // Same type
+  // CHECK:   [[TMP0:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP1:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP2:%.*]] = call i16 @llvm.smul.fix.i16(i16 [[TMP0]], i16 [[TMP1]], i32 7)
+  // CHECK-NEXT:  store i16 [[TMP2]], i16* %sa, align 2
+  sa = sa * sa;
+
+  // To larger scale and larger width
+  // CHECK:   [[TMP3:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP4:%.*]] = load i32, i32* %a, align 4
+  // CHECK-NEXT:  [[RESIZE:%.*]] = sext i16 [[TMP3]] to i32
+  // CHECK-NEXT:  [[UPSCALE:%.*]] = shl i32 [[RESIZE]], 8
+  // CHECK-NEXT:  [[TMP5:%.*]] = call i32 @llvm.smul.fix.i32(i32 [[UPSCALE]], i32 [[TMP4]], i32 15)
+  // CHECK-NEXT:  store i32 [[TMP5]], i32* %a, align 4
+  a = sa * a;
+
+  // To same scale and smaller width
+  // CHECK:   [[TMP6:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP7:%.*]] = load i8, i8* %sf, align 1
+  // CHECK-NEXT:  [[RESIZE1:%.*]] = sext i8 [[TMP7]] to i16
+  // CHECK-NEXT:  [[TMP8:%.*]] = call i16 @llvm.smul.fix.i16(i16 [[TMP6]], i16 [[RESIZE1]], i32 7)
+  // CHECK-NEXT:  store i16 [[TMP8]], i16* %sa, align 2
+  sa = sa * sf;
+
+  // To smaller scale and same width.
+  // CHECK:   [[TMP9:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:  [[TMP10:%.*]] = load i16, i16* %f, align 2
+  // CHECK-NEXT:  [[RESIZE2:%.*]] = sext i16 [[TMP9]] to i24
+  // CHECK-NEXT:  [[UPSCALE3:%.*]] = shl i24 [[RESIZE2]], 8
+  // CHECK-NEXT:  [[RESIZE4:%.*]] = sext i16 [[TMP10]] to i24
+  // CHECK-NEXT:  [[TMP11:%.*]] = call i24 @llvm.smul.fix.i24(i24 [[UPSCALE3]], i24 [[RESIZE4]], i32 15)
+  // CHECK-NEXT:  [[DOWNSCALE:%.*]] = ashr i24 [[TMP11]], 8
+  // CHECK-NEXT:  [[RESIZE5:%.*]] = trunc i24 [[DOWNSCALE]] to i16
+  // CHECK-NEXT:  store i16 [[RESIZE5]], i16* %sa, align 2
+  sa = sa * f;
+
+  // To smaller scale and smaller width
+  // CHECK:   [[TMP12:%.*]] = load i32, i32* %a, align 4
+  // CHECK-NEXT:  [[TMP13:%.*]] = load i8, i8* %sf, align 1
+  // CHECK-NEXT:  [[RESIZE6:%.*]] = sext i8 [[TMP13]] to i32
+  // CHECK-NEXT:  [[UPSCALE7:%.*]] = shl i32 [[RESIZE6]], 8
+  // CHECK-NEXT:  [[TMP14:%.*]] = call i32 @llvm.smul.fix.i32(i32 [[TMP12]], i32 [[UPSCALE7]], i32 15)
+  // CHECK-NEXT:  store i32 [[TMP14]], i32* %a, align 4
+  a = a * sf;
+
+  // To larger scale and same width
+  // CHECK:   [[TMP15:%.*]] = load i32, i32* %a, align 4
+  // CHECK-NEXT:  [[TMP16:%.*]] = load i32, i32* %lf, align 4
+  // CHECK-NEXT:  [[RESIZE8:%.*]] = sext i32 [[TMP15]] to i48
+  // CHECK-NEXT:  [[UPSCALE9:%.*]] = shl i48 [[RESIZE8]], 16
+  // CHECK-NEXT:  [[RESIZE10:%.*]] = sext i32 [[TMP16]] to i48
+  // CHECK-NEXT:  [[TMP17:%.*]] = call i48 @llvm.smul.fix.i48(i48 [[UPSCALE9]], i48 [[RESIZE10]], i32 31)
+  // CHECK-NEXT:  [[DOWNSCALE11:%.*]] = ashr i48 [[TMP17]], 16
+  // CHECK-NEXT:  [[RESIZE12:%.*]] = trunc i48 [[DOWNSCALE11]] to i32
+  // CHECK-NEXT:  store i32 [[RESIZE12]], i32* %a, align 4
+  a = a * lf;
+
+  // With corresponding unsigned type
+  // CHECK:[[TMP18:%.*]] = load i16, i16* %sa, align 2
+  // CHECK-NEXT:   [[TMP19:%.*]] = load i16, i16* %usa, align 2
+  // SIGNED-NEXT:  [[RESIZE13:%.*]] = sext i16 [[TMP18]] to i17
+  // SIGNED-NEXT:  [[UPSCALE14:%.*]] = shl i17 [[RESIZE13]], 1
+  // SIGNED-NEXT:  [[RESIZE15:%.*]] = zext i16 [[TMP19]] to i17
+  // SIGNED-NEXT:  [[TMP20:%.*]] = call i17 @llvm.smul.fix.i17(i17 [[UPSCALE14]], i17 [[RESIZE15]], i32 8)
+  // SIGNED-NEXT:  [[DOWNSCALE16:%.*]] = ashr i17 [[TMP20]], 1
+  // SIGNED-NEXT:  [[RESIZE17:%.*]] = trunc i17 [[DOWNSCALE16]] to i16
+  // SIGNED-NEXT:  store i16 [[RESIZE17]], i16* %sa, align 2
+  // UNSIGNED-NEXT:[[TMP20:%.*]] = call i16 @llvm.smul.fix.i16(i16 [[TMP18]], i16 [[TMP19]], i32 7)
+  // UNSIGNED-NEXT:store i16 [[TMP20]], i16* %sa, align 2
+  sa = sa * usa;

[PATCH] D73184: [CodeGen] Emit IR for compound assignment with fixed-point operands.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 239795.
ebevhan added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73184

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Frontend/fixed_point_compound.c

Index: clang/test/Frontend/fixed_point_compound.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_compound.c
@@ -0,0 +1,374 @@
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+short _Fract shf;
+_Accum a;
+unsigned _Fract uf;
+unsigned long _Accum ula;
+
+_Sat short _Fract sshf;
+_Sat _Accum sa;
+_Sat unsigned _Fract suf;
+_Sat unsigned long _Accum sula;
+
+int i;
+unsigned int u;
+signed char c;
+
+
+// CHECK-LABEL: @Addition(
+void Addition() {
+// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4
+// CHECK-NEXT:[[TMP1:%.*]] = load i8, i8* @shf, align 1
+// CHECK-NEXT:[[RESIZE:%.*]] = sext i8 [[TMP1]] to i32
+// CHECK-NEXT:[[UPSCALE:%.*]] = shl i32 [[RESIZE]], 8
+// CHECK-NEXT:[[TMP2:%.*]] = add i32 [[UPSCALE]], [[TMP0]]
+// CHECK-NEXT:[[DOWNSCALE:%.*]] = ashr i32 [[TMP2]], 8
+// CHECK-NEXT:[[RESIZE1:%.*]] = trunc i32 [[DOWNSCALE]] to i8
+// CHECK-NEXT:store i8 [[RESIZE1]], i8* @shf, align 1
+  shf += a;
+
+// CHECK: [[TMP3:%.*]] = load i16, i16* @uf, align 2
+// CHECK-NEXT:[[TMP4:%.*]] = load i32, i32* @a, align 4
+// SIGNED-NEXT:   [[RESIZE2:%.*]] = sext i32 [[TMP4]] to i33
+// SIGNED-NEXT:   [[UPSCALE3:%.*]] = shl i33 [[RESIZE2]], 1
+// SIGNED-NEXT:   [[RESIZE4:%.*]] = zext i16 [[TMP3]] to i33
+// SIGNED-NEXT:   [[TMP5:%.*]] = add i33 [[UPSCALE3]], [[RESIZE4]]
+// SIGNED-NEXT:   [[DOWNSCALE5:%.*]] = ashr i33 [[TMP5]], 1
+// SIGNED-NEXT:   [[RESIZE6:%.*]] = trunc i33 [[DOWNSCALE5]] to i32
+// SIGNED-NEXT:   store i32 [[RESIZE6]], i32* @a, align 4
+// UNSIGNED-NEXT: [[RESIZE2:%.*]] = zext i16 [[TMP3]] to i32
+// UNSIGNED-NEXT: [[TMP5:%.*]] = add i32 [[TMP4]], [[RESIZE2]]
+// UNSIGNED-NEXT: store i32 [[TMP5]], i32* @a, align 4
+  a += uf;
+
+// CHECK: [[TMP6:%.*]] = load i64, i64* @ula, align 8
+// CHECK-NEXT:[[TMP7:%.*]] = load i16, i16* @uf, align 2
+// CHECK-NEXT:[[RESIZE7:%.*]] = zext i16 [[TMP7]] to i64
+// CHECK-NEXT:[[UPSCALE8:%.*]] = shl i64 [[RESIZE7]], 16
+// CHECK-NEXT:[[TMP8:%.*]] = add i64 [[UPSCALE8]], [[TMP6]]
+// CHECK-NEXT:[[DOWNSCALE9:%.*]] = lshr i64 [[TMP8]], 16
+// CHECK-NEXT:[[RESIZE10:%.*]] = trunc i64 [[DOWNSCALE9]] to i16
+// CHECK-NEXT:store i16 [[RESIZE10]], i16* @uf, align 2
+  uf += ula;
+
+// CHECK: [[TMP9:%.*]] = load i8, i8* @shf, align 1
+// CHECK-NEXT:[[TMP10:%.*]] = load i64, i64* @ula, align 8
+// SIGNED-NEXT:   [[RESIZE11:%.*]] = zext i64 [[TMP10]] to i65
+// SIGNED-NEXT:   [[RESIZE12:%.*]] = sext i8 [[TMP9]] to i65
+// SIGNED-NEXT:   [[UPSCALE13:%.*]] = shl i65 [[RESIZE12]], 25
+// SIGNED-NEXT:   [[TMP11:%.*]] = add i65 [[RESIZE11]], [[UPSCALE13]]
+// SIGNED-NEXT:   [[DOWNSCALE14:%.*]] = ashr i65 [[TMP11]], 1
+// SIGNED-NEXT:   [[RESIZE15:%.*]] = trunc i65 [[DOWNSCALE14]] to i64
+// SIGNED-NEXT:   [[UPSCALE16:%.*]] = shl i64 [[RESIZE15]], 1
+// SIGNED-NEXT:   store i64 [[UPSCALE16]], i64* @ula, align 8
+// UNSIGNED-NEXT: [[RESIZE7:%.*]] = sext i8 [[TMP9]] to i64
+// UNSIGNED-NEXT: [[UPSCALE8:%.*]] = shl i64 [[RESIZE7]], 24
+// UNSIGNED-NEXT: [[TMP11:%.*]] = add i64 [[TMP10]], [[UPSCALE8]]
+// UNSIGNED-NEXT: store i64 [[TMP11]], i64* @ula, align 8
+  ula += shf;
+
+// CHECK: [[TMP12:%.*]] = load i8, i8* @shf, align 1
+// CHECK-NEXT:[[TMP13:%.*]] = load i16, i16* @uf, align 2
+// SIGNED-NEXT:   [[RESIZE17:%.*]] = zext i16 [[TMP13]] to i17
+// SIGNED-NEXT:   [[RESIZE18:%.*]] = sext i8 [[TMP12]] to i17
+// SIGNED-NEXT:   [[UPSCALE19:%.*]] = shl i17 [[RESIZE18]], 9
+// SIGNED-NEXT:   [[TMP14:%.*]] = add i17 [[RESIZE17]], [[UPSCALE19]]
+// SIGNED-NEXT:   [[DOWNSCALE20:%.*]] = ashr i17 [[TMP14]], 1
+// SIGNED-NEXT:   [[RESIZE21:%.*]] = trunc i17 [[DOWNSCALE20]] to i16
+// SIGNED-NEXT:   [[UPSCALE22:%.*]] = shl i16 [[RESIZE21]], 1
+// SIGNED-NEXT:   store i16 [[UPSCALE22]], i16* @uf, align 2
+// UNSIGNED-NEXT: [[RESIZE9:%.*]] = sext i8 [[TMP12]] to i16
+// UNSIGNED-NEXT: [[UPSCALE10:%.*]] = shl i16 [[RESIZE9]], 8
+// UNSIGNED-NEXT: [[TMP14:%.*]] = add i16 [[TMP13]], [[UPSCALE10]]
+// UNSIGNED-NEXT: store i16 [[TMP14]], i16* @uf, align 2
+  uf += shf;
+
+// CHECK: [[TMP15:%.*]] = load i8, i8* @shf, align 1
+// CHECK-NEXT:[[TMP16:%.*]] = load i32, i32* @a, align 4
+// CHECK-NEXT:[[RESIZE23:%.*]] = sext i8 [[TMP15]] to i32
+// CHECK-NEXT:[[UPSCALE24:%.*]] = shl i32 [[RESIZE23]], 8
+// CHECK-NEXT:[[TMP17:%.*]] = add i32 [[TMP16]], [[UPSCALE24]]
+// CHECK-NEXT

[PATCH] D73187: [AST] Add fixed-point division constant evaluation.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 239798.
ebevhan added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73187

Files:
  clang/include/clang/Basic/FixedPoint.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/FixedPoint.cpp
  clang/test/Frontend/fixed_point_div.c

Index: clang/test/Frontend/fixed_point_div.c
===
--- clang/test/Frontend/fixed_point_div.c
+++ clang/test/Frontend/fixed_point_div.c
@@ -1,6 +1,70 @@
 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
 
+// Division between different fixed point types
+short _Accum sa_const = 1.0hk / 2.0hk;  // CHECK-DAG: @sa_const  = {{.*}}global i16 64, align 2
+_Accum a_const = 1.0hk / 2.0k;  // CHECK-DAG: @a_const   = {{.*}}global i32 16384, align 4
+long _Accum la_const = 1.0hk / 2.0lk;   // CHECK-DAG: @la_const  = {{.*}}global i64 1073741824, align 8
+short _Accum sa_const2 = 0.5hr / 2.0hk; // CHECK-DAG: @sa_const2  = {{.*}}global i16 32, align 2
+short _Accum sa_const3 = 0.5r / 2.0hk;  // CHECK-DAG: @sa_const3  = {{.*}}global i16 32, align 2
+short _Accum sa_const4 = 0.5lr / 2.0hk; // CHECK-DAG: @sa_const4  = {{.*}}global i16 32, align 2
+short _Accum sa_const5 = 2.0hk / 0.5lr; // CHECK-DAG: @sa_const5  = {{.*}}global i16 512, align 2
+
+// Unsigned division
+unsigned short _Accum usa_const = 3.0uhk / 2.0uhk;
+// CHECK-SIGNED-DAG:   @usa_const = {{.*}}global i16 192, align 2
+// CHECK-UNSIGNED-DAG: @usa_const = {{.*}}global i16 384, align 2
+
+// Unsigned / signed
+short _Accum sa_const6 = 1.0uhk / 2.0hk;
+// CHECK-DAG: @sa_const6 = {{.*}}global i16 64, align 2
+
+// Division with negative number
+short _Accum sa_const7 = 0.5hr / (-2.0hk);
+// CHECK-DAG: @sa_const7 = {{.*}}global i16 -32, align 2
+
+// Int division
+unsigned short _Accum usa_const2 = 2 / 0.5uhk;
+// CHECK-SIGNED-DAG:   @usa_const2 = {{.*}}global i16 512, align 2
+// CHECK-UNSIGNED-DAG: @usa_const2 = {{.*}}global i16 1024, align 2
+short _Accum sa_const8 = 2 / (-0.5hk);   // CHECK-DAG: @sa_const8 = {{.*}}global i16 -512, align 2
+short _Accum sa_const9 = 256 / 2.0hk;// CHECK-DAG: @sa_const9 = {{.*}}global i16 16384, align 2
+long _Fract lf_const = 0.5lr / -1;   // CHECK-DAG: @lf_const  = {{.*}}global i32 -1073741824, align 4
+
+// Saturated division
+_Sat short _Accum sat_sa_const = (_Sat short _Accum)128.0hk / (-0.25hk);
+// CHECK-DAG: @sat_sa_const = {{.*}}global i16 -32768, align 2
+_Sat unsigned short _Accum sat_usa_const = (_Sat unsigned short _Accum)128.0uhk / (0.25uhk);
+// CHECK-SIGNED-DAG:   @sat_usa_const = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const = {{.*}}global i16 32767, align 2
+_Sat short _Accum sat_sa_const2 = (_Sat short _Accum)-128.0hk / (-0.0125hr);
+// CHECK-DAG: @sat_sa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const2 = (_Sat unsigned short _Accum)128.0uhk / (-128);
+// CHECK-SIGNED-DAG:   @sat_usa_const2 = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const3 = (_Sat unsigned short _Accum)0.5uhk / -1;
+// CHECK-DAG:   @sat_usa_const3 = {{.*}}global i16 0, align 2
+_Sat short _Accum sat_sa_const3 = (_Sat short _Accum)-128.0hk / 128;
+// CHECK-DAG: @sat_sa_const3 = {{.*}}global i16 -128, align 2
+_Sat short _Accum sat_sa_const4 = (_Sat short _Accum)-25.7hk / 0.1lk;
+// CHECK-DAG: @sat_sa_const4 = {{.*}}global i16 -32768, align 2
+
+// Some more cases
+short _Accum sa_const10 = 255.9921875hk / 255.9921875hk;
+// CHECK-DAG: @sa_const10 = {{.*}}global i16 128, align 2
+short _Accum sat_sa_const5 = (_Sat short _Accum)(-255.0hk - 1.0hk) / 0.0078125hk;
+// CHECK-DAG: @sat_sa_const5 = {{.*}}global i16 -32768, align 2
+_Sat short _Accum sat_sa_const6 = (_Sat short _Accum)(-255.0hk - 1.0hk) / -0.0078125hk;
+// CHECK-DAG: @sat_sa_const6 = {{.*}}global i16 32767, align 2
+short _Accum sa_const12 = 255.9921875hk / -1.0hk;
+// CHECK-DAG: @sa_const12 = {{.*}}global i16 -32767, align 2
+_Sat short _Accum sat_sa_const7 = (_Sat short _Accum)(-255.0hk - 1.0hk) / -1.0hk;
+// CHECK-DAG: @sat_sa_const7 = {{.*}}global i16 32767, align 2
+short _Accum sa_const13 = 0.0234375hk / 2.0hk;
+// CHECK-DAG: @sa_const13 = {{.*}}global i16 1, align 2
+short _Accum sa_const14 = -0.0234375hk / 2.0hk;
+// CHECK-DAG: @sa_const14 = {{.*}}global i16 -2, align 2
+
 void SignedDivision() {
   // CHECK-LABEL: SignedDivision
   short _Accum sa;
Index: clang/lib/Basic/FixedPoint.cpp
===
--- clang/lib/Basic/FixedPoint.cpp
+++ clang/lib/Basic/FixedPoint.cpp
@@ -

[PATCH] D72824: [X86] Add combination for fma and fneg on X86 under strict FP.

2020-01-23 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

Add to isNegatibleForFree/getNegatedExpression as well?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72824



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


[PATCH] D73183: [CodeGen] Emit IR for fixed-point unary operators.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 239794.
ebevhan added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73183

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/Frontend/fixed_point_unary.c

Index: clang/test/Frontend/fixed_point_unary.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_unary.c
@@ -0,0 +1,264 @@
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
+// RUN: %clang_cc1 -ffixed-point -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
+
+_Accum a;
+_Fract f;
+long _Fract lf;
+unsigned _Accum ua;
+short unsigned _Accum usa;
+unsigned _Fract uf;
+
+_Sat _Accum sa;
+_Sat _Fract sf;
+_Sat long _Fract slf;
+_Sat unsigned _Accum sua;
+_Sat short unsigned _Accum susa;
+_Sat unsigned _Fract suf;
+
+// CHECK-LABEL: @Increment(
+void Increment() {
+// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4
+// CHECK-NEXT:[[TMP1:%.*]] = sub i32 [[TMP0]], -32768
+// CHECK-NEXT:store i32 [[TMP1]], i32* @a, align 4
+  a++;
+
+// CHECK: [[TMP2:%.*]] = load i16, i16* @f, align 2
+// CHECK-NEXT:[[TMP3:%.*]] = sub i16 [[TMP2]], -32768
+// CHECK-NEXT:store i16 [[TMP3]], i16* @f, align 2
+  f++;
+
+// CHECK: [[TMP4:%.*]] = load i32, i32* @lf, align 4
+// CHECK-NEXT:[[TMP5:%.*]] = sub i32 [[TMP4]], -2147483648
+// CHECK-NEXT:store i32 [[TMP5]], i32* @lf, align 4
+  lf++;
+
+// CHECK: [[TMP6:%.*]] = load i32, i32* @ua, align 4
+// SIGNED-NEXT:   [[TMP7:%.*]] = add i32 [[TMP6]], 65536
+// UNSIGNED-NEXT: [[TMP7:%.*]] = add i32 [[TMP6]], 32768
+// CHECK-NEXT:store i32 [[TMP7]], i32* @ua, align 4
+  ua++;
+
+// CHECK: [[TMP8:%.*]] = load i16, i16* @usa, align 2
+// SIGNED-NEXT:   [[TMP9:%.*]] = add i16 [[TMP8]], 256
+// UNSIGNED-NEXT: [[TMP9:%.*]] = add i16 [[TMP8]], 128
+// CHECK-NEXT:store i16 [[TMP9]], i16* @usa, align 2
+  usa++;
+
+// CHECK: [[TMP10:%.*]] = load i16, i16* @uf, align 2
+// SIGNED-NEXT:   [[TMP11:%.*]] = add i16 [[TMP10]], undef
+// UNSIGNED-NEXT: [[TMP11:%.*]] = add i16 [[TMP10]], -32768
+// CHECK-NEXT:store i16 [[TMP11]], i16* @uf, align 2
+  uf++;
+
+// CHECK: [[TMP12:%.*]] = load i32, i32* @sa, align 4
+// CHECK-NEXT:[[TMP13:%.*]] = call i32 @llvm.ssub.sat.i32(i32 [[TMP12]], i32 -32768)
+// CHECK-NEXT:store i32 [[TMP13]], i32* @sa, align 4
+  sa++;
+
+// CHECK: [[TMP14:%.*]] = load i16, i16* @sf, align 2
+// CHECK-NEXT:[[TMP15:%.*]] = call i16 @llvm.ssub.sat.i16(i16 [[TMP14]], i16 -32768)
+// CHECK-NEXT:store i16 [[TMP15]], i16* @sf, align 2
+  sf++;
+
+// CHECK: [[TMP16:%.*]] = load i32, i32* @slf, align 4
+// CHECK-NEXT:[[TMP17:%.*]] = call i32 @llvm.ssub.sat.i32(i32 [[TMP16]], i32 -2147483648)
+// CHECK-NEXT:store i32 [[TMP17]], i32* @slf, align 4
+  slf++;
+
+// CHECK: [[TMP18:%.*]] = load i32, i32* @sua, align 4
+// SIGNED-NEXT:   [[TMP19:%.*]] = call i32 @llvm.uadd.sat.i32(i32 [[TMP18]], i32 65536)
+// SIGNED-NEXT:   store i32 [[TMP19]], i32* @sua, align 4
+// UNSIGNED-NEXT: [[RESIZE:%.*]] = trunc i32 [[TMP18]] to i31
+// UNSIGNED-NEXT: [[TMP19:%.*]] = call i31 @llvm.uadd.sat.i31(i31 [[RESIZE]], i31 32768)
+// UNSIGNED-NEXT: [[RESIZE1:%.*]] = zext i31 [[TMP19]] to i32
+// UNSIGNED-NEXT: store i32 [[RESIZE1]], i32* @sua, align 4
+  sua++;
+
+// CHECK: [[TMP20:%.*]] = load i16, i16* @susa, align 2
+// SIGNED-NEXT:   [[TMP21:%.*]] = call i16 @llvm.uadd.sat.i16(i16 [[TMP20]], i16 256)
+// SIGNED-NEXT:   store i16 [[TMP21]], i16* @susa, align 2
+// UNSIGNED-NEXT: [[RESIZE2:%.*]] = trunc i16 [[TMP20]] to i15
+// UNSIGNED-NEXT: [[TMP21:%.*]] = call i15 @llvm.uadd.sat.i15(i15 [[RESIZE2]], i15 128)
+// UNSIGNED-NEXT: [[RESIZE3:%.*]] = zext i15 [[TMP21]] to i16
+// UNSIGNED-NEXT: store i16 [[RESIZE3]], i16* @susa, align 2
+  susa++;
+
+// CHECK: [[TMP22:%.*]] = load i16, i16* @suf, align 2
+// SIGNED-NEXT:   [[TMP23:%.*]] = call i16 @llvm.uadd.sat.i16(i16 [[TMP22]], i16 -1)
+// SIGNED-NEXT:   store i16 [[TMP23]], i16* @suf, align 2
+// UNSIGNED-NEXT: [[RESIZE4:%.*]] = trunc i16 [[TMP22]] to i15
+// UNSIGNED-NEXT: [[TMP23:%.*]] = call i15 @llvm.uadd.sat.i15(i15 [[RESIZE4]], i15 -1)
+// UNSIGNED-NEXT: [[RESIZE5:%.*]] = zext i15 [[TMP23]] to i16
+// UNSIGNED-NEXT: store i16 [[RESIZE5]], i16* @suf, align 2
+  suf++;
+}
+
+// CHECK-LABEL: @Decrement(
+void Decrement() {
+// CHECK: [[TMP0:%.*]] = load i32, i32* @a, align 4
+// CHECK-NEXT:[[TMP1:%.*]] = add i32 [[TMP0]], -32768
+// CHECK-NEXT:store i32 [[TMP1]], i32* @a, align 4
+  a--;
+
+// CHECK: [[TMP2:%.*]] = load i16, i16* @f, align 2
+// CHECK-NEXT:[[TMP3:%.*]] = add i16 [[TMP2]], -32768
+// CHECK-NEXT:store i16 [[TMP3]], i16* @f, align 2
+  f--;
+
+// CHECK: [[TMP4:%.*]] = load i32, 

[PATCH] D73186: [AST] Add fixed-point multiplication constant evaluation.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 239797.
ebevhan added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73186

Files:
  clang/include/clang/Basic/FixedPoint.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/FixedPoint.cpp
  clang/test/Frontend/fixed_point_mul.c

Index: clang/test/Frontend/fixed_point_mul.c
===
--- clang/test/Frontend/fixed_point_mul.c
+++ clang/test/Frontend/fixed_point_mul.c
@@ -1,6 +1,49 @@
 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
 // RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -S -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
 
+// Multiplication between different fixed point types
+short _Accum sa_const = 2.0hk * 2.0hk;  // CHECK-DAG: @sa_const  = {{.*}}global i16 512, align 2
+_Accum a_const = 3.0hk * 2.0k;  // CHECK-DAG: @a_const   = {{.*}}global i32 196608, align 4
+long _Accum la_const = 4.0hk * 2.0lk;   // CHECK-DAG: @la_const  = {{.*}}global i64 17179869184, align 8
+short _Accum sa_const2 = 0.5hr * 2.0hk; // CHECK-DAG: @sa_const2  = {{.*}}global i16 128, align 2
+short _Accum sa_const3 = 0.5r * 3.0hk;  // CHECK-DAG: @sa_const3  = {{.*}}global i16 192, align 2
+short _Accum sa_const4 = 0.5lr * 4.0hk; // CHECK-DAG: @sa_const4  = {{.*}}global i16 256, align 2
+
+// Unsigned multiplication
+unsigned short _Accum usa_const = 1.0uhk * 2.0uhk;
+// CHECK-SIGNED-DAG:   @usa_const = {{.*}}global i16 768, align 2
+// CHECK-UNSIGNED-DAG: @usa_const = {{.*}}global i16 384, align 2
+
+// Unsigned * signed
+short _Accum sa_const5 = 20.0uhk * 3.0hk;
+// CHECK-DAG: @sa_const5 = {{.*}}global i16 7680, align 2
+
+// Multiplication with negative number
+short _Accum sa_const6 = 0.5hr * (-2.0hk);
+// CHECK-DAG: @sa_const6 = {{.*}}global i16 -128, align 2
+
+// Int multiplication
+unsigned short _Accum usa_const2 = 5 * 10.5uhk;
+// CHECK-SIGNED-DAG:   @usa_const2 = {{.*}}global i16 640, align 2
+// CHECK-UNSIGNED-DAG: @usa_const2 = {{.*}}global i16 320, align 2
+short _Accum sa_const7 = 3 * (-0.5hk);   // CHECK-DAG: @sa_const7 = {{.*}}global i16 -192, align 2
+short _Accum sa_const8 = 100 * (-2.0hk); // CHECK-DAG: @sa_const8 = {{.*}}global i16 -25600, align 2
+long _Fract lf_const = -0.25lr * 3;  // CHECK-DAG: @lf_const  = {{.*}}global i32 -1610612736, align 4
+
+// Saturated multiplication
+_Sat short _Accum sat_sa_const = (_Sat short _Accum)128.0hk * 3.0hk;
+// CHECK-DAG: @sat_sa_const = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const = (_Sat unsigned short _Accum)128.0uhk * 128.0uhk;
+// CHECK-SIGNED-DAG:   @sat_usa_const = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const = {{.*}}global i16 32767, align 2
+_Sat short _Accum sat_sa_const2 = (_Sat short _Accum)128.0hk * -128;
+// CHECK-DAG: @sat_sa_const2 = {{.*}}global i16 -32768, align 2
+_Sat unsigned short _Accum sat_usa_const2 = (_Sat unsigned short _Accum)128.0uhk * 30;
+// CHECK-SIGNED-DAG:   @sat_usa_const2 = {{.*}}global i16 65535, align 2
+// CHECK-UNSIGNED-DAG: @sat_usa_const2 = {{.*}}global i16 32767, align 2
+_Sat unsigned short _Accum sat_usa_const3 = (_Sat unsigned short _Accum)0.5uhk * (-2);
+// CHECK-DAG:   @sat_usa_const3 = {{.*}}global i16 0, align 2
+
 void SignedMultiplication() {
   // CHECK-LABEL: SignedMultiplication
   short _Accum sa;
Index: clang/lib/Basic/FixedPoint.cpp
===
--- clang/lib/Basic/FixedPoint.cpp
+++ clang/lib/Basic/FixedPoint.cpp
@@ -197,6 +197,57 @@
   return APFixedPoint(Result, CommonFXSema);
 }
 
+APFixedPoint APFixedPoint::mul(const APFixedPoint &Other,
+   bool *Overflow) const {
+  auto CommonFXSema = Sema.getCommonSemantics(Other.getSemantics());
+  APFixedPoint ConvertedThis = convert(CommonFXSema);
+  APFixedPoint ConvertedOther = Other.convert(CommonFXSema);
+  llvm::APSInt ThisVal = ConvertedThis.getValue();
+  llvm::APSInt OtherVal = ConvertedOther.getValue();
+  bool Overflowed = false;
+
+  // Widen the LHS and RHS so we can perform a full multiplication.
+  unsigned Wide = CommonFXSema.getWidth() * 2;
+  if (CommonFXSema.isSigned()) {
+ThisVal = ThisVal.sextOrSelf(Wide);
+OtherVal = OtherVal.sextOrSelf(Wide);
+  } else {
+ThisVal = ThisVal.zextOrSelf(Wide);
+OtherVal = OtherVal.zextOrSelf(Wide);
+  }
+
+  // Perform the full multiplication and downscale to get the same scale.
+  llvm::APSInt Result;
+  if (CommonFXSema.isSigned())
+Result = ThisVal.smul_ov(OtherVal, Overflowed)
+.ashr(CommonFXSema.getScale());
+  else
+Result = ThisVal.umul_ov(OtherVal, Overflowed)
+.lshr(CommonFXSema.getScale());
+  assert(!Overflowed && "Full multiplication can

[PATCH] D73188: [AST] Improve overflow diagnostics for fixed-point constant evaluation.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 239799.
ebevhan added a comment.

Added tests for saturating types. Changed the warning group name for 
consistency.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73188

Files:
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/lib/AST/ExprConstant.cpp
  clang/test/Frontend/fixed_point_errors.c

Index: clang/test/Frontend/fixed_point_errors.c
===
--- clang/test/Frontend/fixed_point_errors.c
+++ clang/test/Frontend/fixed_point_errors.c
@@ -250,3 +250,17 @@
 char c_const = 256.0uk;   // expected-warning{{implicit conversion from 256.0 cannot fit within the range of values for 'char'}}
 short _Accum sa_const5 = 256; // expected-warning{{implicit conversion from 256 cannot fit within the range of values for 'short _Accum'}}
 unsigned short _Accum usa_const2 = -2;// expected-warning{{implicit conversion from -2 cannot fit within the range of values for 'unsigned short _Accum'}}
+
+short _Accum add_ovf1 = 255.0hk + 20.0hk; // expected-warning {{overflow in expression; result is -237.0 with type 'short _Accum'}}
+short _Accum add_ovf2 = 10 + 0.5hr;   // expected-warning {{overflow in expression; result is 0.5 with type 'short _Fract'}}
+short _Accum sub_ovf1 = 16.0uhk - 32.0uhk;// expected-warning {{overflow in expression; result is 240.0 with type 'unsigned short _Accum'}}
+short _Accum sub_ovf2 = -255.0hk - 20;// expected-warning {{overflow in expression; result is 237.0 with type 'short _Accum'}}
+short _Accum mul_ovf1 = 200.0uhk * 10.0uhk;   // expected-warning {{overflow in expression; result is 208.0 with type 'unsigned short _Accum'}}
+short _Accum mul_ovf2 = (-0.5hr - 0.5hr) * (-0.5hr - 0.5hr);  // expected-warning {{overflow in expression; result is -1.0 with type 'short _Fract'}}
+short _Accum div_ovf1 = 255.0hk / 0.5hk;  // expected-warning {{overflow in expression; result is -2.0 with type 'short _Accum'}}
+
+// No warnings for saturation
+short _Fract add_sat  = (_Sat short _Fract)0.5hr + 0.5hr;
+short _Accum sub_sat  = (_Sat short _Accum)-200.0hk - 80.0hk;
+short _Accum mul_sat  = (_Sat short _Accum)80.0hk * 10.0hk;
+short _Fract div_sat  = (_Sat short _Fract)0.9hr / 0.1hr;
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -12570,8 +12570,14 @@
   return false;
 bool Overflowed;
 APFixedPoint Result = Src.convert(DestFXSema, &Overflowed);
-if (Overflowed && !HandleOverflow(Info, E, Result, DestType))
-  return false;
+if (Overflowed) {
+  if (Info.checkingForUndefinedBehavior())
+Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
+ diag::warn_fixedpoint_constant_overflow)
+  << Result.toString() << E->getType();
+  else if (!HandleOverflow(Info, E, Result, E->getType()))
+return false;
+}
 return Success(Result, E);
   }
   case CK_IntegralToFixedPoint: {
@@ -12583,8 +12589,14 @@
 APFixedPoint IntResult = APFixedPoint::getFromIntValue(
 Src, Info.Ctx.getFixedPointSemantics(DestType), &Overflowed);
 
-if (Overflowed && !HandleOverflow(Info, E, IntResult, DestType))
-  return false;
+if (Overflowed) {
+  if (Info.checkingForUndefinedBehavior())
+Info.Ctx.getDiagnostics().Report(E->getExprLoc(),
+ diag::warn_fixedpoint_constant_overflow)
+  << IntResult.toString() << E->getType();
+  else if (!HandleOverflow(Info, E, IntResult, E->getType()))
+return false;
+}
 
 return Success(IntResult, E);
   }
@@ -12609,47 +12621,41 @@
   if (!EvaluateFixedPointOrInteger(RHS, RHSFX, Info))
 return false;
 
+  bool OpOverflow = false, ConversionOverflow = false;
+  APFixedPoint Result(LHSFX.getSemantics());
   switch (E->getOpcode()) {
   case BO_Add: {
-bool AddOverflow, ConversionOverflow;
-APFixedPoint Result = LHSFX.add(RHSFX, &AddOverflow)
-   .convert(ResultFXSema, &ConversionOverflow);
-if ((AddOverflow || ConversionOverflow) &&
-!HandleOverflow(Info, E, Result, E->getType()))
-  return false;
-return Success(Result, E);
+Result = LHSFX.add(RHSFX, &OpOverflow)
+  .convert(ResultFXSema, &ConversionOverflow);
+break;
   }
   case BO_Sub: {
-bool AddOverflow, ConversionOverflow;
-APFixedPoint Result = LHSFX.sub(RHSFX, &AddOverflow)
-   .convert(ResultFXSema, &ConversionOverflow);
-if ((AddOverflow || ConversionOverflow) &&
-!HandleOverflow(Info, E, Result, E->getType()))
-  return false;
-return Succ

[PATCH] D73189: [AST] Fix certain consteval assignment and comma operator issues with fixed-point types.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan updated this revision to Diff 239800.
ebevhan added a comment.

Rebased.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73189

Files:
  clang/lib/AST/ExprConstant.cpp
  clang/test/Frontend/fixed_point_crash.c


Index: clang/test/Frontend/fixed_point_crash.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_crash.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -ffixed-point %s
+
+union a {
+  _Accum x;
+  int i;
+};
+
+int fn1() {
+  union a m;
+  m.x = 5.6k;
+  return m.i;
+}
+
+int fn2() {
+  union a m;
+  m.x = 7, 5.6k; // expected-warning {{expression result unused}}
+  return m.x, m.i; // expected-warning {{expression result unused}}
+}
+
+_Accum acc = (0.5r, 6.9k); // expected-warning {{expression result unused}}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -12609,6 +12609,9 @@
 }
 
 bool FixedPointExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
+  if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma)
+return ExprEvaluatorBaseTy::VisitBinaryOperator(E);
+
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   FixedPointSemantics ResultFXSema =


Index: clang/test/Frontend/fixed_point_crash.c
===
--- /dev/null
+++ clang/test/Frontend/fixed_point_crash.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -verify -ffixed-point %s
+
+union a {
+  _Accum x;
+  int i;
+};
+
+int fn1() {
+  union a m;
+  m.x = 5.6k;
+  return m.i;
+}
+
+int fn2() {
+  union a m;
+  m.x = 7, 5.6k; // expected-warning {{expression result unused}}
+  return m.x, m.i; // expected-warning {{expression result unused}}
+}
+
+_Accum acc = (0.5r, 6.9k); // expected-warning {{expression result unused}}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -12609,6 +12609,9 @@
 }
 
 bool FixedPointExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
+  if (E->isPtrMemOp() || E->isAssignmentOp() || E->getOpcode() == BO_Comma)
+return ExprEvaluatorBaseTy::VisitBinaryOperator(E);
+
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();
   FixedPointSemantics ResultFXSema =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73099: [Alignment][NFC] Deprecate Align::None()

2020-01-23 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 239801.
gchatelet added a comment.

- Rebasing


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73099

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGObjCMac.cpp
  llvm/include/llvm/CodeGen/AsmPrinter.h
  llvm/include/llvm/CodeGen/TargetFrameLowering.h
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/Support/Alignment.h
  llvm/lib/Analysis/Loads.cpp
  llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
  llvm/lib/CodeGen/GlobalISel/CallLowering.cpp
  llvm/lib/CodeGen/MIRPrinter.cpp
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/lib/CodeGen/MachineFrameInfo.cpp
  llvm/lib/CodeGen/MachineOperand.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/ExecutionEngine/Orc/Speculation.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/lib/Target/AArch64/AArch64CompressJumpTables.cpp
  llvm/lib/Target/AMDGPU/AMDGPUFrameLowering.h
  llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp
  llvm/lib/Target/AMDGPU/R600FrameLowering.h
  llvm/lib/Target/AMDGPU/SIFrameLowering.h
  llvm/lib/Target/ARM/ARMBasicBlockInfo.cpp
  llvm/lib/Target/ARM/ARMBasicBlockInfo.h
  llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
  llvm/lib/Target/AVR/AVRFrameLowering.cpp
  llvm/lib/Target/Hexagon/HexagonBranchRelaxation.cpp
  llvm/lib/Target/Hexagon/HexagonFixupHwLoops.cpp
  llvm/lib/Target/Hexagon/HexagonFrameLowering.h
  llvm/lib/Target/Hexagon/HexagonTargetTransformInfo.cpp
  llvm/lib/Target/Mips/MipsCallLowering.cpp
  llvm/lib/Target/Mips/MipsConstantIslandPass.cpp
  llvm/lib/Target/PowerPC/PPCBranchSelector.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
  llvm/lib/Transforms/Instrumentation/Instrumentation.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/unittests/Support/AlignmentTest.cpp
  polly/lib/CodeGen/LoopGeneratorsKMP.cpp

Index: polly/lib/CodeGen/LoopGeneratorsKMP.cpp
===
--- polly/lib/CodeGen/LoopGeneratorsKMP.cpp
+++ polly/lib/CodeGen/LoopGeneratorsKMP.cpp
@@ -468,7 +468,7 @@
 // Global Variable Definitions
 GlobalVariable *StrVar = new GlobalVariable(
 *M, ArrayType, true, GlobalValue::PrivateLinkage, 0, ".str.ident");
-StrVar->setAlignment(llvm::Align::None());
+StrVar->setAlignment(llvm::Align(1));
 
 SourceLocDummy = new GlobalVariable(
 *M, IdentTy, true, GlobalValue::PrivateLinkage, nullptr, LocName);
Index: llvm/unittests/Support/AlignmentTest.cpp
===
--- llvm/unittests/Support/AlignmentTest.cpp
+++ llvm/unittests/Support/AlignmentTest.cpp
@@ -52,7 +52,6 @@
 
 TEST(AlignmentTest, AlignDefaultCTor) {
   EXPECT_EQ(Align().value(), 1ULL);
-  EXPECT_EQ(Align::None().value(), 1ULL);
 }
 
 TEST(AlignmentTest, MaybeAlignDefaultCTor) {
Index: llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
===
--- llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -177,8 +177,7 @@
   if (!isOnlyUsedInComparisonWithZero(CI))
 return false;
 
-  if (!isDereferenceableAndAlignedPointer(Str, Align::None(), APInt(64, Len),
-  DL))
+  if (!isDereferenceableAndAlignedPointer(Str, Align(1), APInt(64, Len), DL))
 return false;
 
   if (CI->getFunction()->hasFnAttribute(Attribute::SanitizeMemory))
@@ -289,7 +288,7 @@
   // We have enough information to now generate the memcpy call to do the
   // concatenation for us.  Make a memcpy to copy the nul byte with align = 1.
   B.CreateMemCpy(
-  CpyDst, Align::None(), Src, Align::None(),
+  CpyDst, Align(1), Src, Align(1),
   ConstantInt::get(DL.getIntPtrType(Src->getContext()), Len + 1));
   return Dst;
 }
@@ -562,7 +561,7 @@
   // We have enough information to now generate the memcpy call to do the
   // copy for us.  Make a memcpy to copy the nul byte with align = 1.
   CallInst *NewCI =
-  B.CreateMemCpy(Dst, Align::None(), Src, Align::None(),
+  B.CreateMemCpy(Dst, Align(1), Src, Align(1),
  ConstantInt::get(DL.getIntPtrType(CI->getContext()), Len));
   NewCI->setAttributes(CI->getAttributes());
   return Dst;
@@ -590,8 +589,7 @@
 
   // We have enough information to now generate the memcpy call to do the
   // copy for us.  Make a memcpy to copy the nul byte with align = 1.
-  CallInst *NewCI =
-  B.Crea

[PATCH] D72829: Implement -fsemantic-interposition

2020-01-23 Thread George Rimar via Phabricator via cfe-commits
grimar added inline comments.



Comment at: llvm/lib/IR/Module.cpp:558
+bool Module::getSemanticInterposition() const {
+  auto *Val =
+  cast_or_null(getModuleFlag("SemanticInterposition"));

A minor nit about style:
This probably would be nicer as

```
  if (auto *Val = cast_or_null(
  getModuleFlag("SemanticInterposition")))
return cast(Val->getValue())->getZExtValue();
  return false;
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829



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


[PATCH] D72934: [ARM,MVE] Support immediate vbicq,vorrq,vmvnq intrinsics.

2020-01-23 Thread Dave Green via Phabricator via cfe-commits
dmgreen accepted this revision.
dmgreen added a comment.
This revision is now accepted and ready to land.

Looks good, from what I can tell.

I especially like the selects. We know that we have to do more work there, but 
adding this for more instructions would go a long way towards creating more 
predicated instructions (before the ability to do this in IR comes along).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72934



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


[PATCH] D72824: [X86] Add combination for fma and fneg on X86 under strict FP.

2020-01-23 Thread Pengfei Wang via Phabricator via cfe-commits
pengfei added a comment.

In D72824#1835568 , @RKSimon wrote:

> Add to isNegatibleForFree/getNegatedExpression as well?


We don't need to add them to isNegatibleForFree/getNegatedExpression. We won't 
negate any FMA results by negative FMA instructions under strict FP, because 
fneg(FMA) has different result from FNMA under some rounding mode.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72824



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


[PATCH] D72829: Implement -fsemantic-interposition

2020-01-23 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 239809.
serge-sans-paille added a comment.

Take review into account


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/IR/GlobalValue.h
  llvm/include/llvm/IR/Module.h
  llvm/lib/IR/Globals.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/Transforms/Inline/inline-semantic-interposition.ll
  llvm/test/Verifier/module-flags-semantic-interposition.ll

Index: llvm/test/Verifier/module-flags-semantic-interposition.ll
===
--- /dev/null
+++ llvm/test/Verifier/module-flags-semantic-interposition.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = dso_local global i32 1, align 4
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"SemanticInterposition", float 1.}
+
+; CHECK: SemanticInterposition metadata requires constant integer argument
Index: llvm/test/Transforms/Inline/inline-semantic-interposition.ll
===
--- /dev/null
+++ llvm/test/Transforms/Inline/inline-semantic-interposition.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -inline  -S | FileCheck %s
+
+define internal i32 @callee1(i32 %A) {
+  ret i32 %A
+}
+define i32 @callee2(i32 %A) {
+  ret i32 %A
+}
+
+; CHECK-LABEL: @caller
+define i32 @caller(i32 %A) {
+; CHECK-NOT: call i32 @callee1(i32 %A)
+  %A1 = call i32 @callee1(i32 %A)
+; CHECK: %A2 = call i32 @callee2(i32 %A)
+  %A2 = call i32 @callee2(i32 %A)
+; CHECK: add i32 %A, %A2
+  %R = add i32 %A1, %A2
+  ret i32 %R
+}
+
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"SemanticInterposition", i32 1}
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1476,6 +1476,13 @@
"'Linker Options' named metadata no longer supported");
   }
 
+  if (ID->getString() == "SemanticInterposition") {
+ConstantInt *Value =
+mdconst::dyn_extract_or_null(Op->getOperand(2));
+Assert(Value,
+   "SemanticInterposition metadata requires constant integer argument");
+  }
+
   if (ID->getString() == "CG Profile") {
 for (const MDOperand &MDO : cast(Op->getOperand(2))->operands())
   visitModuleFlagCGProfileEntry(MDO);
Index: llvm/lib/IR/Module.cpp
===
--- llvm/lib/IR/Module.cpp
+++ llvm/lib/IR/Module.cpp
@@ -554,6 +554,20 @@
: getModuleFlag("ProfileSummary"));
 }
 
+bool Module::getSemanticInterposition() const {
+  auto *Val =
+  cast_or_null(getModuleFlag("SemanticInterposition"));
+
+  if (!Val)
+return false;
+
+  return cast(Val->getValue())->getZExtValue();
+}
+
+void Module::setSemanticInterposition(bool SI) {
+  addModuleFlag(ModFlagBehavior::Error, "SemanticInterposition", SI);
+}
+
 void Module::setOwnedMemoryBuffer(std::unique_ptr MB) {
   OwnedMemoryBuffer = std::move(MB);
 }
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -94,6 +94,13 @@
   llvm_unreachable("not a global");
 }
 
+bool GlobalValue::isInterposable() const {
+  if (isInterposableLinkage(getLinkage()))
+return true;
+  return getParent() && getParent()->getSemanticInterposition() &&
+ !isDSOLocal();
+}
+
 unsigned GlobalValue::getAlignment() const {
   if (auto *GA = dyn_cast(this)) {
 // In general we cannot compute this at the IR level, but we try.
Index: llvm/include/llvm/IR/Module.h
===
--- llvm/include/llvm/IR/Module.h
+++ llvm/include/llvm/IR/Module.h
@@ -848,6 +848,12 @@
   Metadata *getProfileSummary(bool IsCS);
   /// @}
 
+  /// Returns whether semantic interposition is to be respected.
+  bool getSemanticInterposition() const;
+
+  /// Set whether semantic interposition is to be respected.
+  void setSemanticInterposition(bool);
+
   /// Returns true if PLT should be avoided for RTLib calls.
   bool getRtLibUseGOT() const;
 
Index: llvm/include/llvm/IR/GlobalValue.h
===
--- llvm/include/llvm/IR/GlobalValue.h
+++ llvm/include/llvm/IR/GlobalValue.h
@@ -426,7 +426,7 @@
   /// *arbitrary* definition at link time.  We cannot do any IPO or inlinining
   /// across interposable call edges, since the callee can be replaced with
   /// something arbitrary at link time.
-  bool isInterposable() co

[PATCH] D73218: [clangd] Show background index status using LSP 3.15 work-done progress notifications

2020-01-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added inline comments.



Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:223
+// We've requested the client to create a progress bar.
+// Meanwhile, the state is buffered in PendingBackgraundIndexProgress.
+Creating,

s/PendingBackgraundIndexProgress/PendingBackgroundIndexProgress/



Comment at: clang-tools-extra/clangd/ClangdLSPServer.h:232
+  /// LSP extension: skip WorkDoneProgressCreate, just send progress streams.
+  bool BackgroundIndexSkipCreate;
   // Store of the current versions of the open documents.

initialize to `false`



Comment at: clang-tools-extra/clangd/Protocol.cpp:383
+
+llvm::json::Value toJSON(const WorkDoneProgressBegin &P) {
+  llvm::json::Object Result{

why not  have a single struct with that has a required `kind` field and a bunch 
of optional fields.
Later on we can assert on the existence of fields depending on the kind, I 
think it would simplify the implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73218



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


[PATCH] D73162: [test] Avoid loop-unroll.c test getting confused by fadd in git revision

2020-01-23 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop updated this revision to Diff 239808.
russell.gallop added a comment.

Update to check for start of metadata.


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

https://reviews.llvm.org/D73162

Files:
  clang/test/CodeGen/loop-unroll.c


Index: clang/test/CodeGen/loop-unroll.c
===
--- clang/test/CodeGen/loop-unroll.c
+++ clang/test/CodeGen/loop-unroll.c
@@ -37,9 +37,11 @@
 // CHECK-DISABLE-UNROLL-NOT: fmul
 // CHECK-DISABLE-UNROLL-NOT: fadd
 // CHECK-DISABLE-UNROLL-NOT: store
+// Limit scope of checking so this does not match "fadd" within git version 
string
+// CHECK-DISABLE-UNROLL: !0 =

 int printf(const char * restrict format, ...);

 void for_test() {
   double A[1000], B[1000];
   int L = 500;


Index: clang/test/CodeGen/loop-unroll.c
===
--- clang/test/CodeGen/loop-unroll.c
+++ clang/test/CodeGen/loop-unroll.c
@@ -37,9 +37,11 @@
 // CHECK-DISABLE-UNROLL-NOT: fmul
 // CHECK-DISABLE-UNROLL-NOT: fadd
 // CHECK-DISABLE-UNROLL-NOT: store
+// Limit scope of checking so this does not match "fadd" within git version string
+// CHECK-DISABLE-UNROLL: !0 =

 int printf(const char * restrict format, ...);

 void for_test() {
   double A[1000], B[1000];
   int L = 500;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73162: [test] Avoid loop-unroll.c test getting confused by fadd in git revision

2020-01-23 Thread Russell Gallop via Phabricator via cfe-commits
russell.gallop added a comment.

In D73162#1834379 , @asbirlea wrote:

> Oh, wow! Might I ask you add the same for fmul? We may get a revision like 
> that next time :).
>  Thank you!


fmul shouldn't have the same problem as git hashes are only hex characters.

In D73162#1834392 , @fhahn wrote:

> I think  we could also just add a single match for something after the 
> generated functions, to limit the scope of CHECK-NOT, e.g add something like 
> `CHECK : !0 =`


Thanks, that's cleaner.

Note that the diff here is a little confused. There are now no changes to the 
previous check lines.


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

https://reviews.llvm.org/D73162



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


[clang] 4662f6e - [test] Avoid loop-unroll.c test getting confused by fadd in git revision

2020-01-23 Thread Russell Gallop via cfe-commits

Author: Russell Gallop
Date: 2020-01-23T09:27:16Z
New Revision: 4662f6e1c7781bea5cc836948b1aa67f58b8b98d

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

LOG: [test] Avoid loop-unroll.c test getting confused by fadd in git revision

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

Added: 


Modified: 
clang/test/CodeGen/loop-unroll.c

Removed: 




diff  --git a/clang/test/CodeGen/loop-unroll.c 
b/clang/test/CodeGen/loop-unroll.c
index 601bf43d8267..7c79ed28b0e7 100644
--- a/clang/test/CodeGen/loop-unroll.c
+++ b/clang/test/CodeGen/loop-unroll.c
@@ -37,6 +37,8 @@
 // CHECK-DISABLE-UNROLL-NOT: fmul
 // CHECK-DISABLE-UNROLL-NOT: fadd
 // CHECK-DISABLE-UNROLL-NOT: store
+// Limit scope of checking so this does not match "fadd" within git version 
string
+// CHECK-DISABLE-UNROLL: !0 =
 
 int printf(const char * restrict format, ...);
 



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


[PATCH] D73162: [test] Avoid loop-unroll.c test getting confused by fadd in git revision

2020-01-23 Thread Russell Gallop via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4662f6e1c778: [test] Avoid loop-unroll.c test getting 
confused by fadd in git revision (authored by russell.gallop).

Changed prior to commit:
  https://reviews.llvm.org/D73162?vs=239808&id=239812#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73162

Files:
  clang/test/CodeGen/loop-unroll.c


Index: clang/test/CodeGen/loop-unroll.c
===
--- clang/test/CodeGen/loop-unroll.c
+++ clang/test/CodeGen/loop-unroll.c
@@ -37,6 +37,8 @@
 // CHECK-DISABLE-UNROLL-NOT: fmul
 // CHECK-DISABLE-UNROLL-NOT: fadd
 // CHECK-DISABLE-UNROLL-NOT: store
+// Limit scope of checking so this does not match "fadd" within git version 
string
+// CHECK-DISABLE-UNROLL: !0 =
 
 int printf(const char * restrict format, ...);
 


Index: clang/test/CodeGen/loop-unroll.c
===
--- clang/test/CodeGen/loop-unroll.c
+++ clang/test/CodeGen/loop-unroll.c
@@ -37,6 +37,8 @@
 // CHECK-DISABLE-UNROLL-NOT: fmul
 // CHECK-DISABLE-UNROLL-NOT: fadd
 // CHECK-DISABLE-UNROLL-NOT: store
+// Limit scope of checking so this does not match "fadd" within git version string
+// CHECK-DISABLE-UNROLL: !0 =
 
 int printf(const char * restrict format, ...);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-23 Thread Eugene Leviant via Phabricator via cfe-commits
evgeny777 added inline comments.



Comment at: llvm/lib/Transforms/IPO/GlobalSplit.cpp:116
+if (GV.hasMetadata(LLVMContext::MD_vcall_visibility))
+  SplitGV->setVCallVisibilityMetadata(GV.getVCallVisibility());
   }

I think this needs a test. Removal of this code doesn't break anything


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71907



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


[PATCH] D72829: Implement -fsemantic-interposition

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

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

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

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



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829



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


[PATCH] D73186: [AST] Add fixed-point multiplication constant evaluation.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: clang/lib/Basic/FixedPoint.cpp:242
+  } else
+Overflowed = Result < Min || Result > Max;
+

rjmccall wrote:
> If the maximum expressible value is *k*, and the fully-precise multiplication 
> yields *k+e* for some epsilon *e* that isn't representable in the result 
> semantics, is that considered an overflow?  If so, I think you need to do the 
> shift after these bound checks, since the shift destroys the difference 
> between *k* and *k+e*.  That is, unless there's a compelling mathematical 
> argument that it's not possible to overflow only in the fully-precision 
> multiplication — but while I think that's possibly true of `_Fract` (since 
> *k^2 < k*), it seems unlikely to be true of `_Accum`, although I haven't 
> looked for a counter-example.  And if there is a compelling argument, it 
> should probably be at least alluded to in a comment.
> 
> Would this algorithm be simpler if you took advantage of the fact that 
> `APFixedPointSemantics` doesn't have to correspond to a real type?  You could 
> probably just convert to a double-width common semantics, right?
> If the maximum expressible value is *k*, and the fully-precise multiplication 
> yields *k+e* for some epsilon *e* that isn't representable in the result 
> semantics, is that considered an overflow? If so, I think you need to do the 
> shift after these bound checks, since the shift destroys the difference 
> between *k* and *k+e*.

I don't think I would consider that to be overflow; that's precision loss. E-C 
considers these to be different:

> If the source value cannot be represented exactly by the fixed-point type, 
> the source value is rounded to either the closest fixed-point value greater 
> than the source value (rounded up) or to the closest fixed-point value less 
> than the source value (rounded down).
>
> When the source value does not fit within the range of the fixed-point type, 
> the conversion overflows. [...]
>
> [...]
>
> If the result type of an arithmetic operation is a fixed-point type, [...] 
> the calculated result is the mathematically exact result with overflow 
> handling and rounding performed to the full precision of the result type as 
> explained in 4.1.3. 

There is also no value of `e` that would affect saturation. Any full precision 
calculation that gives `k+e` must be `k` after downscaling, since the bits that 
represent `e` must come from the extra precision range. Even though `k+e` is 
technically larger than `k`, saturation would still just give us `k` after 
truncating out `e`, so the end result is the same.

> Would this algorithm be simpler if you took advantage of the fact that 
> APFixedPointSemantics doesn't have to correspond to a real type? You could 
> probably just convert to a double-width common semantics, right?

It's likely possible to use APFixedPoint in the calculations here, but I used 
APInt to make the behavior explicit and not accidentally be dependent on the 
behavior of APFixedPoint's conversions or operations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73186



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-23 Thread Eugene Leviant via Phabricator via cfe-commits
evgeny777 added a comment.

Looks good so far. See remaining comment in D71907 





Comment at: clang/lib/CodeGen/CGVTables.cpp:1050
 
-  if (getCodeGenOpts().LTOVisibilityPublicStd) {
-const DeclContext *DC = RD;
-while (1) {
-  auto *D = cast(DC);
-  DC = DC->getParent();
-  if (isa(DC->getRedeclContext())) {
-if (auto *ND = dyn_cast(D))
-  if (const IdentifierInfo *II = ND->getIdentifier())
-if (II->isStr("std") || II->isStr("stdext"))
-  return false;
-break;
-  }
-}
-  }
+  if (HasLTOVisibilityPublicStd(RD))
+return false;

nit: return !HasLTOVisibilityPublicStd(RD)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71913



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


[PATCH] D72824: [X86] Add combination for fma and fneg on X86 under strict FP.

2020-01-23 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added a comment.

In D72824#1835633 , @pengfei wrote:

> In D72824#1835568 , @RKSimon wrote:
>
> > Add to isNegatibleForFree/getNegatedExpression as well?
>
>
> We don't need to add them to isNegatibleForFree/getNegatedExpression. We 
> won't negate any FMA results by negative FMA instructions under strict FP, 
> because fneg(FMA) has different result from FNMA under some rounding mode.


Thanks for confirming - no more comments from me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72824



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


[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

2020-01-23 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 239825.
njames93 added a comment.

- use regex for func name matching


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
  clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-main-like.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-main-like.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-main-like.cpp
@@ -0,0 +1,63 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: readability-identifier-naming.ParameterCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.IgnoreMainLikeFunctions, value: 1} \
+// RUN:  ]}'
+
+int mainLike(int argc, char **argv);
+int mainLike(int argc, char **argv, const char **env);
+int mainLike(int argc, const char **argv);
+int mainLike(int argc, const char **argv, const char **env);
+int mainLike(int argc, char *argv[]);
+int mainLike(int argc, const char *argv[]);
+int mainLike(int argc, char *argv[], char *env[]);
+int mainLike(int argc, const char *argv[], const char *env[]);
+void notMain(int argc, char **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: invalid case style for parameter 'argv'
+void notMain(int argc, char **argv, char **env);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: invalid case style for parameter 'argv'
+// CHECK-MESSAGES: :[[@LINE-3]]:44: warning: invalid case style for parameter 'env'
+int notMain(int argc, char **argv, char **env, int Extra);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'argv'
+// CHECK-MESSAGES: :[[@LINE-3]]:43: warning: invalid case style for parameter 'env'
+int notMain(int argc, char **argv, int Extra);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'argv'
+int notMain(int argc, char *argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: invalid case style for parameter 'argv'
+int notMain(unsigned argc, char **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:35: warning: invalid case style for parameter 'argv'
+int notMain(long argc, char *argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'argv'
+int notMain(int argc, char16_t **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: invalid case style for parameter 'argv'
+int notMain(int argc, char argv[]);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:28: warning: invalid case style for parameter 'argv'
+typedef char myFunChar;
+typedef int myFunInt;
+typedef char **myFunCharPtr;
+typedef long myFunLong;
+myFunInt mainLikeTypedef(myFunInt argc, myFunChar **argv);
+int mainLikeTypedef(int argc, myFunCharPtr argv);
+int notMainTypedef(myFunLong argc, char **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:43: warning: invalid case style for parameter 'argv'
+
+// Don't flag as name contains the word main
+int myMainFunction(int argc, char *argv[]);
+
+// This is fine, named with wmain and has wchar ptr.
+int wmainLike(int argc, wchar_t *argv[]);
+
+// Flag this as has signature of main, but named as wmain.
+int wmainLike(int argc, char *argv[]);
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: invalid case style for parameter 'argv'
Index: clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
@@ -55,6 +55,7 @@
  - :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`, :option:`GlobalFunctionSuffix`
  - :option:`GlobalPointerCas

[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

2020-01-23 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 239830.
njames93 added a comment.

- Dont trim func name before regex


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
  clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-main-like.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-main-like.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-main-like.cpp
@@ -0,0 +1,63 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: readability-identifier-naming.ParameterCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.IgnoreMainLikeFunctions, value: 1} \
+// RUN:  ]}'
+
+int mainLike(int argc, char **argv);
+int mainLike(int argc, char **argv, const char **env);
+int mainLike(int argc, const char **argv);
+int mainLike(int argc, const char **argv, const char **env);
+int mainLike(int argc, char *argv[]);
+int mainLike(int argc, const char *argv[]);
+int mainLike(int argc, char *argv[], char *env[]);
+int mainLike(int argc, const char *argv[], const char *env[]);
+void notMain(int argc, char **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: invalid case style for parameter 'argv'
+void notMain(int argc, char **argv, char **env);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: invalid case style for parameter 'argv'
+// CHECK-MESSAGES: :[[@LINE-3]]:44: warning: invalid case style for parameter 'env'
+int notMain(int argc, char **argv, char **env, int Extra);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'argv'
+// CHECK-MESSAGES: :[[@LINE-3]]:43: warning: invalid case style for parameter 'env'
+int notMain(int argc, char **argv, int Extra);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'argv'
+int notMain(int argc, char *argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: invalid case style for parameter 'argv'
+int notMain(unsigned argc, char **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:35: warning: invalid case style for parameter 'argv'
+int notMain(long argc, char *argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'argv'
+int notMain(int argc, char16_t **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: invalid case style for parameter 'argv'
+int notMain(int argc, char argv[]);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:28: warning: invalid case style for parameter 'argv'
+typedef char myFunChar;
+typedef int myFunInt;
+typedef char **myFunCharPtr;
+typedef long myFunLong;
+myFunInt mainLikeTypedef(myFunInt argc, myFunChar **argv);
+int mainLikeTypedef(int argc, myFunCharPtr argv);
+int notMainTypedef(myFunLong argc, char **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:43: warning: invalid case style for parameter 'argv'
+
+// Don't flag as name contains the word main
+int myMainFunction(int argc, char *argv[]);
+
+// This is fine, named with wmain and has wchar ptr.
+int wmainLike(int argc, wchar_t *argv[]);
+
+// Flag this as has signature of main, but named as wmain.
+int wmainLike(int argc, char *argv[]);
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: invalid case style for parameter 'argv'
Index: clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
+++ clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
@@ -55,6 +55,7 @@
  - :option:`GlobalFunctionCase`, :option:`GlobalFunctionPrefix`, :option:`GlobalFunctionSuffix`
  - :option:`GlobalPointerCas

[PATCH] D73261: [dwarf5] Support DebugInfo for constexpr for C++ variables and functions

2020-01-23 Thread Awanish Pandey via Phabricator via cfe-commits
awpandey created this revision.
awpandey added reviewers: dblaikie, aprantl, probinson, jini.susan.george.
awpandey added projects: debug-info, LLVM, clang.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.

This patch adds //dw_at_const_expr// flag for the constant variable or 
functions in C++


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73261

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/test/CodeGenCXX/constExpr.cpp
  clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp
  llvm/include/llvm/IR/DIBuilder.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/Bitcode/Reader/MetadataLoader.cpp
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/IR/AsmWriter.cpp
  llvm/lib/IR/DIBuilder.cpp
  llvm/lib/IR/DebugInfo.cpp
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/IR/LLVMContextImpl.h
  llvm/unittests/CodeGen/MachineInstrTest.cpp
  llvm/unittests/IR/IRBuilderTest.cpp
  llvm/unittests/IR/MetadataTest.cpp

Index: llvm/unittests/IR/MetadataTest.cpp
===
--- llvm/unittests/IR/MetadataTest.cpp
+++ llvm/unittests/IR/MetadataTest.cpp
@@ -86,7 +86,7 @@
   DISubprogram *getSubprogram() {
 return DISubprogram::getDistinct(
 Context, nullptr, "", "", nullptr, 0, nullptr, 0, nullptr, 0, 0,
-DINode::FlagZero, DISubprogram::SPFlagZero, nullptr);
+DINode::FlagZero, DISubprogram::SPFlagZero, false, nullptr);
   }
   DIFile *getFile() {
 return DIFile::getDistinct(Context, "file.c", "/path/to/dir");
@@ -927,12 +927,12 @@
   {
 // Different function, same inlined-at.
 auto *F = getFile();
-auto *SP1 = DISubprogram::getDistinct(Context, F, "a", "a", F, 0, nullptr,
-  0, nullptr, 0, 0, DINode::FlagZero,
-  DISubprogram::SPFlagZero, nullptr);
-auto *SP2 = DISubprogram::getDistinct(Context, F, "b", "b", F, 0, nullptr,
-  0, nullptr, 0, 0, DINode::FlagZero,
-  DISubprogram::SPFlagZero, nullptr);
+auto *SP1 = DISubprogram::getDistinct(
+Context, F, "a", "a", F, 0, nullptr, 0, nullptr, 0, 0, DINode::FlagZero,
+DISubprogram::SPFlagZero, false, nullptr);
+auto *SP2 = DISubprogram::getDistinct(
+Context, F, "b", "b", F, 0, nullptr, 0, nullptr, 0, 0, DINode::FlagZero,
+DISubprogram::SPFlagZero, false, nullptr);
 
 auto *I = DILocation::get(Context, 2, 7, N);
 auto *A = DILocation::get(Context, 1, 6, SP1, I);
@@ -1168,7 +1168,7 @@
   DIType *Type = getDerivedType();
   DINode::DIFlags Flags = static_cast(7);
   auto *VlaExpr = DILocalVariable::get(Context, Scope, "vla_expr", File, 8,
-   Type, 2, Flags, 8);
+   Type, 2, Flags, 8, false);
 
   auto *N = DISubrange::get(Context, VlaExpr, 0);
   auto Count = N->getCount();
@@ -1822,7 +1822,7 @@
 
   auto *N = DISubprogram::get(
   Context, Scope, Name, LinkageName, File, Line, Type, ScopeLine,
-  ContainingType, VirtualIndex, ThisAdjustment, Flags, SPFlags, Unit,
+  ContainingType, VirtualIndex, ThisAdjustment, Flags, SPFlags, false, Unit,
   TemplateParams, Declaration, RetainedNodes, ThrownTypes);
 
   EXPECT_EQ(dwarf::DW_TAG_subprogram, N->getTag());
@@ -1848,97 +1848,98 @@
   EXPECT_EQ(ThrownTypes, N->getThrownTypes().get());
   EXPECT_EQ(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
  Type, ScopeLine, ContainingType, VirtualIndex,
- ThisAdjustment, Flags, SPFlags, Unit,
+ ThisAdjustment, Flags, SPFlags, false, Unit,
  TemplateParams, Declaration, RetainedNodes,
  ThrownTypes));
 
   EXPECT_NE(N, DISubprogram::get(Context, getCompositeType(), Name, LinkageName,
  File, Line, Type, ScopeLine, ContainingType,
  VirtualIndex, ThisAdjustment, Flags, SPFlags,
- Unit, TemplateParams, Declaration,
+ false, Unit, TemplateParams, Declaration,
  RetainedNodes, ThrownTypes));
   EXPECT_NE(N, DISubprogram::get(Context, Scope, "other", LinkageName, File,
  Line, Type, ScopeLine, ContainingType,
  VirtualIndex, ThisAdjustment, Flags, SPFlags,
- Unit, TemplateParams, Declaration,
+ false, Unit, TemplateParams, Declaration,
  RetainedNodes, ThrownTypes));
   EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, "other", File, Line,
  Type, ScopeLine, ContainingType, VirtualIndex,
-

[PATCH] D72144: Treat C# `using` as a control statement

2020-01-23 Thread Jonathan B Coe via Phabricator via cfe-commits
jbcoe updated this revision to Diff 239836.
jbcoe added a comment.

Extended tests and added some comments explaining why seeming duplicated tests 
are useful.


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

https://reviews.llvm.org/D72144

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -235,20 +235,46 @@
   Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
   verifyFormat("public void foo () {\n"
"  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using () {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
Style);
 
   Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
   verifyFormat("public void foo() {\n"
"  using(StreamWriter sw = new StreamWriter(filenameB)) {}\n"
+   "  using() {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter(filenameA)) {}\n"
+   "  using () {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+   Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using() {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
+   Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpRegions) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2869,7 +2869,8 @@
 // space between keywords and paren e.g. "using ("
 if (Right.is(tok::l_paren))
   if (Left.is(tok::kw_using))
-return spaceRequiredBeforeParens(Left);
+return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements 
||
+   spaceRequiredBeforeParens(Right);
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -235,20 +235,46 @@
   Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
   verifyFormat("public void foo () {\n"
"  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using () {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
Style);
 
   Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
   verifyFormat("public void foo() {\n"
"  using(StreamWriter sw = new StreamWriter(filenameB)) {}\n"
+   "  using() {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter(filenameA)) {}\n"
+   "  using () {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+   Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using() {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
+   Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpRegions) {
Index: clang/lib/Format/Tok

[PATCH] D72829: Implement -fsemantic-interposition

2020-01-23 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 239837.
serge-sans-paille added a comment.

Formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829

Files:
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/IR/GlobalValue.h
  llvm/include/llvm/IR/Module.h
  llvm/lib/IR/Globals.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/Transforms/Inline/inline-semantic-interposition.ll
  llvm/test/Verifier/module-flags-semantic-interposition.ll

Index: llvm/test/Verifier/module-flags-semantic-interposition.ll
===
--- /dev/null
+++ llvm/test/Verifier/module-flags-semantic-interposition.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = dso_local global i32 1, align 4
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"SemanticInterposition", float 1.}
+
+; CHECK: SemanticInterposition metadata requires constant integer argument
Index: llvm/test/Transforms/Inline/inline-semantic-interposition.ll
===
--- /dev/null
+++ llvm/test/Transforms/Inline/inline-semantic-interposition.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -inline  -S | FileCheck %s
+
+define internal i32 @callee1(i32 %A) {
+  ret i32 %A
+}
+define i32 @callee2(i32 %A) {
+  ret i32 %A
+}
+
+; CHECK-LABEL: @caller
+define i32 @caller(i32 %A) {
+; CHECK-NOT: call i32 @callee1(i32 %A)
+  %A1 = call i32 @callee1(i32 %A)
+; CHECK: %A2 = call i32 @callee2(i32 %A)
+  %A2 = call i32 @callee2(i32 %A)
+; CHECK: add i32 %A, %A2
+  %R = add i32 %A1, %A2
+  ret i32 %R
+}
+
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"SemanticInterposition", i32 1}
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1476,6 +1476,13 @@
"'Linker Options' named metadata no longer supported");
   }
 
+  if (ID->getString() == "SemanticInterposition") {
+ConstantInt *Value =
+mdconst::dyn_extract_or_null(Op->getOperand(2));
+Assert(Value,
+   "SemanticInterposition metadata requires constant integer argument");
+  }
+
   if (ID->getString() == "CG Profile") {
 for (const MDOperand &MDO : cast(Op->getOperand(2))->operands())
   visitModuleFlagCGProfileEntry(MDO);
Index: llvm/lib/IR/Module.cpp
===
--- llvm/lib/IR/Module.cpp
+++ llvm/lib/IR/Module.cpp
@@ -554,6 +554,20 @@
: getModuleFlag("ProfileSummary"));
 }
 
+bool Module::getSemanticInterposition() const {
+  Metadata *MF = getModuleFlag("SemanticInterposition");
+
+  auto *Val = cast_or_null(MF);
+  if (!Val)
+return false;
+
+  return cast(Val->getValue())->getZExtValue();
+}
+
+void Module::setSemanticInterposition(bool SI) {
+  addModuleFlag(ModFlagBehavior::Error, "SemanticInterposition", SI);
+}
+
 void Module::setOwnedMemoryBuffer(std::unique_ptr MB) {
   OwnedMemoryBuffer = std::move(MB);
 }
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -94,6 +94,13 @@
   llvm_unreachable("not a global");
 }
 
+bool GlobalValue::isInterposable() const {
+  if (isInterposableLinkage(getLinkage()))
+return true;
+  return getParent() && getParent()->getSemanticInterposition() &&
+ !isDSOLocal();
+}
+
 unsigned GlobalValue::getAlignment() const {
   if (auto *GA = dyn_cast(this)) {
 // In general we cannot compute this at the IR level, but we try.
Index: llvm/include/llvm/IR/Module.h
===
--- llvm/include/llvm/IR/Module.h
+++ llvm/include/llvm/IR/Module.h
@@ -848,6 +848,12 @@
   Metadata *getProfileSummary(bool IsCS);
   /// @}
 
+  /// Returns whether semantic interposition is to be respected.
+  bool getSemanticInterposition() const;
+
+  /// Set whether semantic interposition is to be respected.
+  void setSemanticInterposition(bool);
+
   /// Returns true if PLT should be avoided for RTLib calls.
   bool getRtLibUseGOT() const;
 
Index: llvm/include/llvm/IR/GlobalValue.h
===
--- llvm/include/llvm/IR/GlobalValue.h
+++ llvm/include/llvm/IR/GlobalValue.h
@@ -426,7 +426,7 @@
   /// *arbitrary* definition at link time.  We cannot do any IPO or inlinining
   /// across interposable call edges, since the callee can be replaced with
   /// something arbitrary at link time.
-  bool isInterposable() 

[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

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

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

{icon times-circle color=red} clang-tidy: fail. clang-tidy found 0 errors and 1 
warnings 
.

{icon check-circle color=green} clang-format: pass.

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



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098



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


[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

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

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

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

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



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098



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


[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

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



Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:383
+  } else {
+static llvm::Regex Matcher("(^((W[Mm])|(wm))ain([_A-Z]|$))|([a-z0-9_]W[Mm]"
+   "ain([_A-Z]|$))|(_wmain(_|$))",

Any thoughts on whether I should detect WMain or just Wmain. WMain looks more 
pleasing but using CamelCase rules it should likely be Wmain


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098



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


[PATCH] D72144: Treat C# `using` as a control statement

2020-01-23 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir requested changes to this revision.
krasimir added a comment.
This revision now requires changes to proceed.

I looked up the C# reference 

 and all the examples are top-level, so having top-level test cases here would 
be useful, as people would expect copy-pasting an example snippet to just work.
Sorry about asking you to go back-and-forth.


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

https://reviews.llvm.org/D72144



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


[PATCH] D72144: Treat C# `using` as a control statement

2020-01-23 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir accepted this revision.
krasimir added a comment.

I'll submit this for you.


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

https://reviews.llvm.org/D72144



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


[PATCH] D72959: Relative VTables ABI on Fuchsia

2020-01-23 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

In D72959#1835368 , @rjmccall wrote:

> There's two independently-useful things here for the relocation, right?  
> First, it's useful to be able to express a relocation to a symbol that has 
> the semantics of a particular function but doesn't necessarily have its 
> address, and that concept could be used across many "physical" relocations; 
> and second, it's potentially useful to have a shifted-by-two relative address 
> relocation, at least on AArch64 where instructions (and v-table entries under 
> this ABI) are always four-byte-aligned anyway.  Is it possible to separate 
> these concerns in ELF, e.g. by having a "symbol" that can be the target of 
> any other relocation but which actually represents a function of unspecified 
> address with the semantics of another function?


It would be possible to design relocations like that, but I think it would be 
difficult to fit into existing multi-target designs, which assume that the 
relocation code alone encodes all the actions a linker needs to take 
(smart-format, dumb-linker). My understanding of the reasons behind this are:

- The linker can have millions of relocations to resolve and  having all the 
actions explicit in the code simplifies its job.
- There is a large space of available relocation codes, partitioned per target, 
but a much more limited availability of target specific symbol types and flags.
- The concerns can be separated at implementation time, for example the symbol 
lookup, encoding and calculation stages are independent and shared between the 
codes.

It is possible that there is a better trade-off in complexity, but anything 
radically different might need quite a bit of work to fit into an existing 
linker. Hope I've understood you correctly and apologies if the above isn't 
relevant.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72959



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


[PATCH] D72829: Implement -fsemantic-interposition

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

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

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

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



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829



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


[PATCH] D69868: Allow "callbr" to return non-void values

2020-01-23 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

In D69868#1832725 , @MaskRay wrote:

> In D69868#1832559 , @void wrote:
>
> > @jyknight Do you think you'll have time to review this patch this week? I'd 
> > like to get it into the 10.0 release if possible. :-)
>
>
> I volunteer as a reviewer:)


W00t! :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69868



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


[PATCH] D72934: [ARM,MVE] Support immediate vbicq,vorrq,vmvnq intrinsics.

2020-01-23 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4321c6af28e9: [ARM,MVE] Support immediate vbicq,vorrq,vmvnq 
intrinsics. (authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72934

Files:
  clang/include/clang/Basic/arm_mve.td
  clang/include/clang/Basic/arm_mve_defs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaChecking.cpp
  clang/test/CodeGen/arm-mve-intrinsics/bitwise-imm.c
  clang/test/Sema/arm-mve-immediates.c
  clang/utils/TableGen/MveEmitter.cpp
  llvm/lib/Target/ARM/ARMISelLowering.cpp
  llvm/lib/Target/ARM/ARMInstrInfo.td
  llvm/lib/Target/ARM/ARMInstrMVE.td
  llvm/lib/Target/ARM/ARMInstrNEON.td
  llvm/test/CodeGen/Thumb2/mve-intrinsics/bitwise-imm.ll

Index: llvm/test/CodeGen/Thumb2/mve-intrinsics/bitwise-imm.ll
===
--- /dev/null
+++ llvm/test/CodeGen/Thumb2/mve-intrinsics/bitwise-imm.ll
@@ -0,0 +1,365 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=thumbv8.1m.main -mattr=+mve -verify-machineinstrs -o - %s | FileCheck %s
+
+define arm_aapcs_vfpcc <8 x i16> @test_vbicq_n_u16_sh0(<8 x i16> %a) {
+; CHECK-LABEL: test_vbicq_n_u16_sh0:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i16 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <8 x i16> %a, 
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vbicq_n_u16_sh8(<8 x i16> %a) {
+; CHECK-LABEL: test_vbicq_n_u16_sh8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i16 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <8 x i16> %a, 
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_sh0(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_sh0:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i32 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_sh8(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_sh8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i32 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_sh16(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_sh16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i32 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_sh24(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_sh24:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vbic.i32 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+; The immediate in this case is legal for a VMVN but not for a VBIC,
+; so in this case we expect to see the constant being prepared in
+; another register.
+define arm_aapcs_vfpcc <4 x i32> @test_vbicq_n_u32_illegal(<4 x i32> %a) {
+; CHECK-LABEL: test_vbicq_n_u32_illegal:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vmvn.i32 q1, #0x54ff
+; CHECK-NEXT:vand q0, q0, q1
+; CHECK-NEXT:bx lr
+entry:
+  %0 = and <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vorrq_n_u16_sh0(<8 x i16> %a) {
+; CHECK-LABEL: test_vorrq_n_u16_sh0:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vorr.i16 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = or <8 x i16> %a, 
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vorrq_n_u16_sh8(<8 x i16> %a) {
+; CHECK-LABEL: test_vorrq_n_u16_sh8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vorr.i16 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = or <8 x i16> %a, 
+  ret <8 x i16> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vorrq_n_u32_sh0(<4 x i32> %a) {
+; CHECK-LABEL: test_vorrq_n_u32_sh0:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vorr.i32 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = or <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vorrq_n_u32_sh8(<4 x i32> %a) {
+; CHECK-LABEL: test_vorrq_n_u32_sh8:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vorr.i32 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = or <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vorrq_n_u32_sh16(<4 x i32> %a) {
+; CHECK-LABEL: test_vorrq_n_u32_sh16:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vorr.i32 q0, #0x64
+; CHECK-NEXT:bx lr
+entry:
+  %0 = or <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <4 x i32> @test_vorrq_n_u32_sh24(<4 x i32> %a) {
+; CHECK-LABEL: test_vorrq_n_u32_sh24:
+; CHECK:   @ %bb.0: @ %entry
+; CHECK-NEXT:vorr.i32 q0, #0x6400
+; CHECK-NEXT:bx lr
+entry:
+  %0 = or <4 x i32> %a, 
+  ret <4 x i32> %0
+}
+
+define arm_aapcs_vfpcc <8 x i16> @test_vbicq_m_n_u16_sh0(<8 x i16> %a, i16 zeroext %p) {
+

[PATCH] D71600: PowerPC 32-bit - forces 8 byte lock/lock_free decisions at compiled time

2020-01-23 Thread Alfredo Dal'Ava Júnior via Phabricator via cfe-commits
adalava updated this revision to Diff 239847.
adalava added a comment.

Updated comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71600

Files:
  clang/lib/AST/ExprConstant.cpp
  compiler-rt/lib/builtins/atomic.c


Index: compiler-rt/lib/builtins/atomic.c
===
--- compiler-rt/lib/builtins/atomic.c
+++ compiler-rt/lib/builtins/atomic.c
@@ -119,13 +119,20 @@
   return locks + (hash & SPINLOCK_MASK);
 }
 
-/// Macros for determining whether a size is lock free.  Clang can not yet
-/// codegen __atomic_is_lock_free(16), so for now we assume 16-byte values are
-/// not lock free.
+/// Macros for determining whether a size is lock free.
 #define IS_LOCK_FREE_1 __c11_atomic_is_lock_free(1)
 #define IS_LOCK_FREE_2 __c11_atomic_is_lock_free(2)
 #define IS_LOCK_FREE_4 __c11_atomic_is_lock_free(4)
+
+/// 32 bit PowerPC doesn't support 8-byte lock_free atomics
+#if !defined(__powerpc64__) && defined(__powerpc__)
+#define IS_LOCK_FREE_8 0
+#else
 #define IS_LOCK_FREE_8 __c11_atomic_is_lock_free(8)
+#endif
+
+/// Clang can not yet codegen __atomic_is_lock_free(16), so for now we assume
+/// 16-byte values are not lock free.
 #define IS_LOCK_FREE_16 0
 
 /// Macro that calls the compiler-generated lock-free versions of functions
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -11177,6 +11177,15 @@
   }
 }
 
+// Avoid emiting call for runtime decision on PowerPC 32-bit
+// The lock free possibilities on this platform are covered by the lines 
+// above and we know in advance other cases require lock.
+// This may need to be restricted to specific operating systems in the 
future,
+// as some (perhaps AIX) might provide libatomic and prefer to use it 
instead
+if (Info.Ctx.getTargetInfo().getTriple().getArch() == llvm::Triple::ppc) {
+return Success(0, E);
+}
+
 return BuiltinOp == Builtin::BI__atomic_always_lock_free ?
 Success(0, E) : Error(E);
   }


Index: compiler-rt/lib/builtins/atomic.c
===
--- compiler-rt/lib/builtins/atomic.c
+++ compiler-rt/lib/builtins/atomic.c
@@ -119,13 +119,20 @@
   return locks + (hash & SPINLOCK_MASK);
 }
 
-/// Macros for determining whether a size is lock free.  Clang can not yet
-/// codegen __atomic_is_lock_free(16), so for now we assume 16-byte values are
-/// not lock free.
+/// Macros for determining whether a size is lock free.
 #define IS_LOCK_FREE_1 __c11_atomic_is_lock_free(1)
 #define IS_LOCK_FREE_2 __c11_atomic_is_lock_free(2)
 #define IS_LOCK_FREE_4 __c11_atomic_is_lock_free(4)
+
+/// 32 bit PowerPC doesn't support 8-byte lock_free atomics
+#if !defined(__powerpc64__) && defined(__powerpc__)
+#define IS_LOCK_FREE_8 0
+#else
 #define IS_LOCK_FREE_8 __c11_atomic_is_lock_free(8)
+#endif
+
+/// Clang can not yet codegen __atomic_is_lock_free(16), so for now we assume
+/// 16-byte values are not lock free.
 #define IS_LOCK_FREE_16 0
 
 /// Macro that calls the compiler-generated lock-free versions of functions
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -11177,6 +11177,15 @@
   }
 }
 
+// Avoid emiting call for runtime decision on PowerPC 32-bit
+// The lock free possibilities on this platform are covered by the lines 
+// above and we know in advance other cases require lock.
+// This may need to be restricted to specific operating systems in the future,
+// as some (perhaps AIX) might provide libatomic and prefer to use it instead
+if (Info.Ctx.getTargetInfo().getTriple().getArch() == llvm::Triple::ppc) {
+return Success(0, E);
+}
+
 return BuiltinOp == Builtin::BI__atomic_always_lock_free ?
 Success(0, E) : Error(E);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73025: [AArch64][SVE] Add first-faulting load intrinsic

2020-01-23 Thread Kerry McLaughlin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGaa0f37e14a87: [AArch64][SVE] Add first-faulting load 
intrinsic (authored by kmclaughlin).

Changed prior to commit:
  https://reviews.llvm.org/D73025?vs=239303&id=239849#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73025

Files:
  llvm/include/llvm/IR/IntrinsicsAArch64.td
  llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
  llvm/lib/Target/AArch64/AArch64ISelLowering.h
  llvm/lib/Target/AArch64/AArch64InstrInfo.td
  llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
  llvm/lib/Target/AArch64/SVEInstrFormats.td
  llvm/test/CodeGen/AArch64/sve-intrinsics-loads-ff.ll

Index: llvm/test/CodeGen/AArch64/sve-intrinsics-loads-ff.ll
===
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sve-intrinsics-loads-ff.ll
@@ -0,0 +1,220 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sve < %s | FileCheck %s
+
+;
+; LDFF1B
+;
+
+define  @ldff1b( %pg, i8* %a) {
+; CHECK-LABEL: ldff1b:
+; CHECK: ldff1b { z0.b }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv16i8( %pg, i8* %a)
+  ret  %load
+}
+
+define  @ldff1b_h( %pg, i8* %a) {
+; CHECK-LABEL: ldff1b_h:
+; CHECK: ldff1b { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv8i8( %pg, i8* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldff1b_s( %pg, i8* %a) {
+; CHECK-LABEL: ldff1b_s:
+; CHECK: ldff1b { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv4i8( %pg, i8* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldff1b_d( %pg, i8* %a) {
+; CHECK-LABEL: ldff1b_d:
+; CHECK: ldff1b { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv2i8( %pg, i8* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+;
+; LDFF1SB
+;
+
+define  @ldff1sb_h( %pg, i8* %a) {
+; CHECK-LABEL: ldff1sb_h:
+; CHECK: ldff1sb { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv8i8( %pg, i8* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+define  @ldff1sb_s( %pg, i8* %a) {
+; CHECK-LABEL: ldff1sb_s:
+; CHECK: ldff1sb { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv4i8( %pg, i8* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+define  @ldff1sb_d( %pg, i8* %a) {
+; CHECK-LABEL: ldff1sb_d:
+; CHECK: ldff1sb { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv2i8( %pg, i8* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+;
+; LDFF1H
+;
+
+define  @ldff1h( %pg, i16* %a) {
+; CHECK-LABEL: ldff1h:
+; CHECK: ldff1h { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv8i16( %pg, i16* %a)
+  ret  %load
+}
+
+define  @ldff1h_s( %pg, i16* %a) {
+; CHECK-LABEL: ldff1h_s:
+; CHECK: ldff1h { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv4i16( %pg, i16* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldff1h_d( %pg, i16* %a) {
+; CHECK-LABEL: ldff1h_d:
+; CHECK: ldff1h { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv2i16( %pg, i16* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldff1h_f16( %pg, half* %a) {
+; CHECK-LABEL: ldff1h_f16:
+; CHECK: ldff1h { z0.h }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv8f16( %pg, half* %a)
+  ret  %load
+}
+
+;
+; LDFF1SH
+;
+
+define  @ldff1sh_s( %pg, i16* %a) {
+; CHECK-LABEL: ldff1sh_s:
+; CHECK: ldff1sh { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv4i16( %pg, i16* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+define  @ldff1sh_d( %pg, i16* %a) {
+; CHECK-LABEL: ldff1sh_d:
+; CHECK: ldff1sh { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv2i16( %pg, i16* %a)
+  %res = sext  %load to 
+  ret  %res
+}
+
+;
+; LDFF1W
+;
+
+define  @ldff1w( %pg, i32* %a) {
+; CHECK-LABEL: ldff1w:
+; CHECK: ldff1w { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv4i32( %pg, i32* %a)
+  ret  %load
+}
+
+define  @ldff1w_d( %pg, i32* %a) {
+; CHECK-LABEL: ldff1w_d:
+; CHECK: ldff1w { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv2i32( %pg, i32* %a)
+  %res = zext  %load to 
+  ret  %res
+}
+
+define  @ldff1w_f32( %pg, float* %a) {
+; CHECK-LABEL: ldff1w_f32:
+; CHECK: ldff1w { z0.s }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv4f32( %pg, float* %a)
+  ret  %load
+}
+
+define  @ldff1w_2f32( %pg, float* %a) {
+; CHECK-LABEL: ldff1w_2f32:
+; CHECK: ldff1w { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load = call  @llvm.aarch64.sve.ldff1.nxv2f32( %pg, float* %a)
+  ret  %load
+}
+
+;
+; LDFF1SW
+;
+
+define  @ldff1sw_d( %pg, i32* %a) {
+; CHECK-LABEL: ldff1sw_d:
+; CHECK: ldff1sw { z0.d }, p0/z, [x0]
+; CHECK-NEXT: ret
+  %load

[clang] 1e0174a - Treat C# `using` as a control statement

2020-01-23 Thread Krasimir Georgiev via cfe-commits

Author: Krasimir Georgiev
Date: 2020-01-23T13:19:55+01:00
New Revision: 1e0174a93cfd364bffd12abc8f0148509d0d0f75

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

LOG: Treat C# `using` as a control statement

Contributed by jbcoe!

Summary: Unless SpaceBeforeParensOptions is set to SBPO_Never, a space will be 
put between `using` and `(` in C# code.

Reviewers: klimek, MyDeveloperDay, krasimir

Reviewed By: krasimir

Subscribers: MyDeveloperDay, cfe-commits

Tags: #clang-format, #clang

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

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTestCSharp.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 7dbde9a8d6a8..05b1db2a878d 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2869,7 +2869,8 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 // space between keywords and paren e.g. "using ("
 if (Right.is(tok::l_paren))
   if (Left.is(tok::kw_using))
-return spaceRequiredBeforeParens(Left);
+return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements 
||
+   spaceRequiredBeforeParens(Right);
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;

diff  --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 95b14d0f0aa4..90d05ad679a7 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -235,20 +235,46 @@ TEST_F(FormatTestCSharp, CSharpUsing) {
   Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
   verifyFormat("public void foo () {\n"
"  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using () {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
Style);
 
   Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
   verifyFormat("public void foo() {\n"
"  using(StreamWriter sw = new StreamWriter(filenameB)) {}\n"
+   "  using() {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter(filenameA)) {}\n"
+   "  using () {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+   Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using() {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
+   Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpRegions) {



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


[PATCH] D72144: Treat C# `using` as a control statement

2020-01-23 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Revision".
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1e0174a93cfd: Treat C# `using` as a control statement 
(authored by krasimir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72144

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestCSharp.cpp


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -235,20 +235,46 @@
   Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
   verifyFormat("public void foo () {\n"
"  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using () {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
Style);
 
   Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
   verifyFormat("public void foo() {\n"
"  using(StreamWriter sw = new StreamWriter(filenameB)) {}\n"
+   "  using() {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter(filenameA)) {}\n"
+   "  using () {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+   Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using() {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
+   Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpRegions) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -2869,7 +2869,8 @@
 // space between keywords and paren e.g. "using ("
 if (Right.is(tok::l_paren))
   if (Left.is(tok::kw_using))
-return spaceRequiredBeforeParens(Left);
+return Style.SpaceBeforeParens == FormatStyle::SBPO_ControlStatements 
||
+   spaceRequiredBeforeParens(Right);
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
 if (Left.is(TT_JsFatArrow))
   return true;


Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -235,20 +235,46 @@
   Style.SpaceBeforeParens = FormatStyle::SBPO_Always;
   verifyFormat("public void foo () {\n"
"  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using () {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using (StreamWriter sw = new StreamWriter (filenameB)) {}",
Style);
 
   Style.SpaceBeforeParens = FormatStyle::SBPO_Never;
   verifyFormat("public void foo() {\n"
"  using(StreamWriter sw = new StreamWriter(filenameB)) {}\n"
+   "  using() {}\n"
"}",
Style);
 
+  // Ensure clang-format affects top-level snippets correctly.
   verifyFormat("using(StreamWriter sw = new StreamWriter(filenameB)) {}",
Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter(filenameA)) {}\n"
+   "  using () {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw = new StreamWriter(filenameB)) {}",
+   Style);
+
+  Style.SpaceBeforeParens = FormatStyle::SBPO_NonEmptyParentheses;
+  verifyFormat("public void foo() {\n"
+   "  using (StreamWriter sw = new StreamWriter (filenameA)) {}\n"
+   "  using() {}\n"
+   "}",
+   Style);
+
+  // Ensure clang-format affects top-level snippets correctly.
+  verifyFormat("using (StreamWriter sw =

[PATCH] D73265: header file warning

2020-01-23 Thread Mikhail Goncharov via Phabricator via cfe-commits
goncharov created this revision.
Herald added subscribers: cfe-commits, usaxena95, kadircet, arphaman, jkorous.
Herald added a project: clang.
goncharov removed subscribers: jkorous, arphaman, kadircet, usaxena95, 
cfe-commits.

warning in a header


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73265

Files:
  clang-tools-extra/clangd/URI.h


Index: clang-tools-extra/clangd/URI.h
===
--- clang-tools-extra/clangd/URI.h
+++ clang-tools-extra/clangd/URI.h
@@ -9,9 +9,9 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHURI_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHURI_H
 
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Error.h"
 #include "llvm/Support/Registry.h"
+#include "llvm/Support/Error.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace clang {
 namespace clangd {


Index: clang-tools-extra/clangd/URI.h
===
--- clang-tools-extra/clangd/URI.h
+++ clang-tools-extra/clangd/URI.h
@@ -9,9 +9,9 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHURI_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_PATHURI_H
 
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/Error.h"
 #include "llvm/Support/Registry.h"
+#include "llvm/Support/Error.h"
+#include "llvm/ADT/StringRef.h"
 
 namespace clang {
 namespace clangd {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72829: Implement -fsemantic-interposition

2020-01-23 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 239857.
serge-sans-paille added a comment.

Add Release note and doc. @MaskRay can you confirm current state is ok?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  llvm/include/llvm/IR/GlobalValue.h
  llvm/include/llvm/IR/Module.h
  llvm/lib/IR/Globals.cpp
  llvm/lib/IR/Module.cpp
  llvm/lib/IR/Verifier.cpp
  llvm/test/Transforms/Inline/inline-semantic-interposition.ll
  llvm/test/Verifier/module-flags-semantic-interposition.ll

Index: llvm/test/Verifier/module-flags-semantic-interposition.ll
===
--- /dev/null
+++ llvm/test/Verifier/module-flags-semantic-interposition.ll
@@ -0,0 +1,12 @@
+; RUN: not llvm-as < %s -o /dev/null 2>&1 | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+@foo = dso_local global i32 1, align 4
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"SemanticInterposition", float 1.}
+
+; CHECK: SemanticInterposition metadata requires constant integer argument
Index: llvm/test/Transforms/Inline/inline-semantic-interposition.ll
===
--- /dev/null
+++ llvm/test/Transforms/Inline/inline-semantic-interposition.ll
@@ -0,0 +1,24 @@
+; RUN: opt < %s -inline  -S | FileCheck %s
+
+define internal i32 @callee1(i32 %A) {
+  ret i32 %A
+}
+define i32 @callee2(i32 %A) {
+  ret i32 %A
+}
+
+; CHECK-LABEL: @caller
+define i32 @caller(i32 %A) {
+; CHECK-NOT: call i32 @callee1(i32 %A)
+  %A1 = call i32 @callee1(i32 %A)
+; CHECK: %A2 = call i32 @callee2(i32 %A)
+  %A2 = call i32 @callee2(i32 %A)
+; CHECK: add i32 %A, %A2
+  %R = add i32 %A1, %A2
+  ret i32 %R
+}
+
+
+!llvm.module.flags = !{!0}
+
+!0 = !{i32 1, !"SemanticInterposition", i32 1}
Index: llvm/lib/IR/Verifier.cpp
===
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -1476,6 +1476,13 @@
"'Linker Options' named metadata no longer supported");
   }
 
+  if (ID->getString() == "SemanticInterposition") {
+ConstantInt *Value =
+mdconst::dyn_extract_or_null(Op->getOperand(2));
+Assert(Value,
+   "SemanticInterposition metadata requires constant integer argument");
+  }
+
   if (ID->getString() == "CG Profile") {
 for (const MDOperand &MDO : cast(Op->getOperand(2))->operands())
   visitModuleFlagCGProfileEntry(MDO);
Index: llvm/lib/IR/Module.cpp
===
--- llvm/lib/IR/Module.cpp
+++ llvm/lib/IR/Module.cpp
@@ -554,6 +554,20 @@
: getModuleFlag("ProfileSummary"));
 }
 
+bool Module::getSemanticInterposition() const {
+  Metadata *MF = getModuleFlag("SemanticInterposition");
+
+  auto *Val = cast_or_null(MF);
+  if (!Val)
+return false;
+
+  return cast(Val->getValue())->getZExtValue();
+}
+
+void Module::setSemanticInterposition(bool SI) {
+  addModuleFlag(ModFlagBehavior::Error, "SemanticInterposition", SI);
+}
+
 void Module::setOwnedMemoryBuffer(std::unique_ptr MB) {
   OwnedMemoryBuffer = std::move(MB);
 }
Index: llvm/lib/IR/Globals.cpp
===
--- llvm/lib/IR/Globals.cpp
+++ llvm/lib/IR/Globals.cpp
@@ -94,6 +94,13 @@
   llvm_unreachable("not a global");
 }
 
+bool GlobalValue::isInterposable() const {
+  if (isInterposableLinkage(getLinkage()))
+return true;
+  return getParent() && getParent()->getSemanticInterposition() &&
+ !isDSOLocal();
+}
+
 unsigned GlobalValue::getAlignment() const {
   if (auto *GA = dyn_cast(this)) {
 // In general we cannot compute this at the IR level, but we try.
Index: llvm/include/llvm/IR/Module.h
===
--- llvm/include/llvm/IR/Module.h
+++ llvm/include/llvm/IR/Module.h
@@ -848,6 +848,12 @@
   Metadata *getProfileSummary(bool IsCS);
   /// @}
 
+  /// Returns whether semantic interposition is to be respected.
+  bool getSemanticInterposition() const;
+
+  /// Set whether semantic interposition is to be respected.
+  void setSemanticInterposition(bool);
+
   /// Returns true if PLT should be avoided for RTLib calls.
   bool getRtLibUseGOT() const;
 
Index: llvm/include/llvm/IR/GlobalValue.h
===
--- llvm/include/llvm/IR/GlobalValue.h
+++ llvm/include/llvm/IR/GlobalValue.h
@@ -426,7 +426,7 @@
   /// *arbitrary* definition at link time.  We cannot do any IPO or inlinining
   /// acr

[PATCH] D73268: [ARM,MVE] Make the MVE intrinsics work in C++!

2020-01-23 Thread Simon Tatham via Phabricator via cfe-commits
simon_tatham created this revision.
simon_tatham added reviewers: LukeGeeson, MarkMurrayARM, miyuki, dmgreen.
Herald added subscribers: cfe-commits, kristof.beyls.
Herald added a project: clang.

Apparently nobody has tried this in months of development. It turns
out that `FunctionDecl::getBuiltinID` will never consider a function
to be a builtin if it is in C++ and not extern "C". So none of the
function declarations in  are recognized as builtins when
clang is compiling in C++ mode: it just emits calls to them as
ordinary functions, which then turn out not to exist at link time.

The trivial fix is to wrap most of arm_mve.h in an extern "C".

Added a test in clang/test/CodeGen/arm-mve-intrinsics which checks
basic functioning of the MVE header file in C++ mode. I've filled it
with copies of existing test functions from other files in that
directory, including a few moderately tricky cases of overloading (in
particular one that relies on the strict-polymorphism attribute added
in D72518 ).

(I considered making //every// test in that directory compile in both
C and C++ mode and check the code generation was identical. But I
think that would increase testing time by more than the value it adds,
and also update_cc_test_checks gets confused when the output function
name varies between RUN lines.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73268

Files:
  clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp
  clang/utils/TableGen/MveEmitter.cpp

Index: clang/utils/TableGen/MveEmitter.cpp
===
--- clang/utils/TableGen/MveEmitter.cpp
+++ clang/utils/TableGen/MveEmitter.cpp
@@ -1603,6 +1603,10 @@
 "#endif\n"
 "\n"
 "#include \n"
+"\n"
+"#ifdef __cplusplus\n"
+"extern \"C\" {\n"
+"#endif\n"
 "\n";
 
   for (size_t i = 0; i < NumParts; ++i) {
@@ -1621,7 +1625,11 @@
   OS << "#endif /* " << condition << " */\n\n";
   }
 
-  OS << "#endif /* __ARM_MVE_H */\n";
+  OS << "#ifdef __cplusplus\n"
+"} /* extern \"C\" */\n"
+"#endif\n"
+"\n"
+"#endif /* __ARM_MVE_H */\n";
 }
 
 void MveEmitter::EmitBuiltinDef(raw_ostream &OS) {
Index: clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp
===
--- /dev/null
+++ clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp
@@ -0,0 +1,160 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature +mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O3 -disable-O0-optnone -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature +mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O3 -disable-O0-optnone -DPOLYMORPHIC -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @_Z16test_vbicq_n_s1617__simd128_int16_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = and <8 x i16> [[A:%.*]], 
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+int16x8_t test_vbicq_n_s16(int16x8_t a)
+{
+#ifdef POLYMORPHIC
+return vbicq(a, 0xd500);
+#else /* POLYMORPHIC */
+return vbicq_n_s16(a, 0xd500);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vbicq_n_u3218__simd128_uint32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = and <4 x i32> [[A:%.*]], 
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+uint32x4_t test_vbicq_n_u32(uint32x4_t a)
+{
+#ifdef POLYMORPHIC
+return vbicq(a, 0x2000);
+#else /* POLYMORPHIC */
+return vbicq_n_u32(a, 0x2000);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vorrq_n_s3217__simd128_int32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = or <4 x i32> [[A:%.*]], 
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+int32x4_t test_vorrq_n_s32(int32x4_t a)
+{
+#ifdef POLYMORPHIC
+return vorrq(a, 0x1);
+#else /* POLYMORPHIC */
+return vorrq_n_s32(a, 0x1);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vorrq_n_u1618__simd128_uint16_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = or <8 x i16> [[A:%.*]], 
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+uint16x8_t test_vorrq_n_u16(uint16x8_t a)
+{
+#ifdef POLYMORPHIC
+return vorrq(a, 0xf000);
+#else /* POLYMORPHIC */
+return vorrq_n_u16(a, 0xf000);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vcmpeqq_f1619__simd128_float16_tS_(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = fcmp oeq <8 x half> [[A:%.*]], [[B:%.*]]
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.arm.mve.pred.v2i.v8i1(<8 x i1> [[TMP0]]), !range !3
+// CHECK-NEXT:[[TMP2:%.*]] = trunc i32 [[TMP1]] to i16
+// CHECK-NEXT:ret i16 [[TMP2]]
+//
+mve_pred16_t test_vcmpeqq_f16(float16x8_t a, float16x8_t b)
+{
+#ifdef POLYMORPHIC
+return vcmpeqq(a, b);

[PATCH] D72829: Implement -fsemantic-interposition

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

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

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

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


//Pre-merge checks is in beta. Report issue 
.
 Please | join beta  or | 
enable it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72829



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


[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

2020-01-23 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:383
+  } else {
+static llvm::Regex Matcher("(^((W[Mm])|(wm))ain([_A-Z]|$))|([a-z0-9_]W[Mm]"
+   "ain([_A-Z]|$))|(_wmain(_|$))",

njames93 wrote:
> Any thoughts on whether I should detect WMain or just Wmain. WMain looks more 
> pleasing but using CamelCase rules it should likely be Wmain
I think this needs to be controlled by an option if we want to keep it, because 
you can still have names like `terminateMain(int exitCode, char *msgs[]);` At 
the end of the day, no matter what regex we come up with, we can probably pick 
an identifier that subverts the check. Also, the name `main` might have 
different meanings if the function is a member function or a member of a 
namespace (or, alternatively, it may actually relate to the main entrypoint). 
Ultimately, this seems too much like guessing at user intent, which is why I 
think it should be an option (and probably off by default).

That said, if we're searching for main-like names, I think we need to find 
names like wmain, Wmain, wMain, WMain optionally with a prefix or suffix 
(perhaps with underscores). I am less certain how to treat member functions, 
but suspect the reasonable thing to do is treat them as being potentially 
main-like regardless of whether they're static or not, but the function still 
needs to be publicly available rather than private or protected (those can't be 
main-like, unless someone friends main... which is another twist).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098



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


[PATCH] D71566: New checks for fortified sprintf

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

In D71566#1834472 , @serge-sans-paille 
wrote:

> In D71566#1832394 , @aaron.ballman 
> wrote:
>
> > (There are still some minor whitespace nits to resolve as well.)
>
>
> Strange, everything is passed through clang-format-diff :-/


They may have been manually inserted by accident? It's newlines in a few 
places, I added phab review comments at them.

On the whole, I think this LGTM, assuming the requested test cases don't 
discover issues.




Comment at: clang/test/Sema/warn-fortify-source.c:127
+
+void call_sprintf() {
+  char buf[6];

I'd like to see some additional tests for things like the `+` and ` ` flags, 
length modifiers like `ll`, escape characters, etc. Basically, we should be 
testing most of the conversion specifiers to verify our conservative length 
calculations.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71566



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


[PATCH] D73268: [ARM,MVE] Make the MVE intrinsics work in C++!

2020-01-23 Thread Mark Murray via Phabricator via cfe-commits
MarkMurrayARM accepted this revision.
MarkMurrayARM added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73268



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


[PATCH] D72705: [clang][checkers] Added new checker 'alpha.unix.ErrorReturn'.

2020-01-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 239874.
balazske added a comment.

Small bugfixes, added some tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72705

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/ErrorReturnChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/error-return.c

Index: clang/test/Analysis/error-return.c
===
--- /dev/null
+++ clang/test/Analysis/error-return.c
@@ -0,0 +1,342 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.unix.ErrorReturn -verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+/*
+Functions from CERT ERR33-C that should be checked for error:
+https://wiki.sei.cmu.edu/confluence/display/c/ERR33-C.+Detect+and+handle+standard+library+errors
+
+void *aligned_alloc( size_t alignment, size_t size );
+errno_t asctime_s(char *buf, rsize_t bufsz, const struct tm *time_ptr);
+int at_quick_exit( void (*func)(void) );
+int atexit( void (*func)(void) );
+void* bsearch( const void *key, const void *ptr, size_t count, size_t size,
+   int (*comp)(const void*, const void*) );
+void* bsearch_s( const void *key, const void *ptr, rsize_t count, rsize_t size,
+ int (*comp)(const void *, const void *, void *),
+ void *context );
+wint_t btowc( int c );
+size_t c16rtomb( char * restrict s, char16_t c16, mbstate_t * restrict ps );
+size_t c32rtomb( char * restrict s, char32_t c32, mbstate_t * restrict ps );
+void* calloc( size_t num, size_t size );
+clock_t clock(void);
+int cnd_broadcast( cnd_t *cond );
+int cnd_init( cnd_t* cond );
+int cnd_signal( cnd_t *cond );
+int cnd_timedwait( cnd_t* restrict cond, mtx_t* restrict mutex,
+   const struct timespec* restrict time_point );
+int cnd_wait( cnd_t* cond, mtx_t* mutex );
+errno_t ctime_s(char *buffer, rsize_t bufsz, const time_t *time);
+int fclose( FILE *stream );
+int fflush( FILE *stream );
+int fgetc( FILE *stream );
+int fgetpos( FILE *restrict stream, fpos_t *restrict pos );
+char *fgets( char *restrict str, int count, FILE *restrict stream );
+wint_t fgetwc( FILE *stream );
+FILE *fopen( const char *restrict filename, const char *restrict mode );
+errno_t fopen_s(FILE *restrict *restrict streamptr,
+const char *restrict filename,
+const char *restrict mode);
+int fprintf( FILE *restrict stream, const char *restrict format, ... );
+int fprintf_s(FILE *restrict stream, const char *restrict format, ...);
+int fputc( int ch, FILE *stream );
+int fputs( const char *restrict str, FILE *restrict stream );
+wint_t fputwc( wchar_t ch, FILE *stream );
+int fputws( const wchar_t * restrict str, FILE * restrict stream );
+size_t fread( void *restrict buffer, size_t size, size_t count,
+  FILE *restrict stream );
+FILE *freopen( const char *restrict filename, const char *restrict mode,
+   FILE *restrict stream );
+errno_t freopen_s(FILE *restrict *restrict newstreamptr,
+  const char *restrict filename, const char *restrict mode,
+  FILE *restrict stream);
+int fscanf( FILE *restrict stream, const char *restrict format, ... );
+int fscanf_s(FILE *restrict stream, const char *restrict format, ...);
+int fseek( FILE *stream, long offset, int origin );
+int fsetpos( FILE *stream, const fpos_t *pos );
+long ftell( FILE *stream );
+int fwprintf( FILE *restrict stream,
+  const wchar_t *restrict format, ... );
+int fwprintf_s( FILE *restrict stream,
+const wchar_t *restrict format, ...);
+size_t fwrite( const void *restrict buffer, size_t size, size_t count,
+   FILE *restrict stream ); // more exact error return: < count
+int fwscanf( FILE *restrict stream,
+ const wchar_t *restrict format, ... );
+int fwscanf_s( FILE *restrict stream,
+   const wchar_t *restrict format, ...);
+int getc( FILE *stream );
+int getchar(void);
+char *getenv( const char *name );
+errno_t getenv_s( size_t *restrict len, char *restrict value,
+  rsize_t valuesz, const char *restrict name );
+char *gets_s( char *str, rsize_t n );
+wint_t getwc( FILE *stream );
+wint_t getwchar(void);
+struct tm *gmtime( const time_t *time );
+struct tm *gmtime_s(const time_t *restrict time, struct tm *restrict result);
+struct tm *localtime( const time_t *time );
+struct tm *localtime_s(const time_t *restrict time, struct tm *restrict result);
+void* malloc( size_t size );
+int mblen( const char* s, size_t n );
+size_t mbrlen( const char *restrict s, size_t n, mbstate_t *restrict ps );
+size_t mbrtoc16( char16_t * restrict pc16, const char * restrict s,
+ size_t n, mbstate_t * restrict ps );
+size_t mbrtoc32( char32_t restrict * pc32, const char * res

[clang] 98ea4b3 - [ARM,MVE] Make the MVE intrinsics work in C++!

2020-01-23 Thread Simon Tatham via cfe-commits

Author: Simon Tatham
Date: 2020-01-23T14:10:27Z
New Revision: 98ea4b30c2c4e122defce039e29f7023aa2663e7

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

LOG: [ARM,MVE] Make the MVE intrinsics work in C++!

Summary:
Apparently nobody has tried this in months of development. It turns
out that `FunctionDecl::getBuiltinID` will never consider a function
to be a builtin if it is in C++ and not extern "C". So none of the
function declarations in  are recognized as builtins when
clang is compiling in C++ mode: it just emits calls to them as
ordinary functions, which then turn out not to exist at link time.

The trivial fix is to wrap most of arm_mve.h in an extern "C".

Added a test in clang/test/CodeGen/arm-mve-intrinsics which checks
basic functioning of the MVE header file in C++ mode. I've filled it
with copies of existing test functions from other files in that
directory, including a few moderately tricky cases of overloading (in
particular one that relies on the strict-polymorphism attribute added
in D72518).

(I considered making //every// test in that directory compile in both
C and C++ mode and check the code generation was identical. But I
think that would increase testing time by more than the value it adds,
and also update_cc_test_checks gets confused when the output function
name varies between RUN lines.)

Reviewers: LukeGeeson, MarkMurrayARM, miyuki, dmgreen

Reviewed By: MarkMurrayARM

Subscribers: kristof.beyls, cfe-commits

Tags: #clang

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

Added: 
clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp

Modified: 
clang/utils/TableGen/MveEmitter.cpp

Removed: 




diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp 
b/clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp
new file mode 100644
index ..47df53839d15
--- /dev/null
+++ b/clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp
@@ -0,0 +1,160 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature 
+mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O3 
-disable-O0-optnone -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature 
+mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O3 
-disable-O0-optnone -DPOLYMORPHIC -S -emit-llvm -o - %s | opt -S -mem2reg | 
FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @_Z16test_vbicq_n_s1617__simd128_int16_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = and <8 x i16> [[A:%.*]], 
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+int16x8_t test_vbicq_n_s16(int16x8_t a)
+{
+#ifdef POLYMORPHIC
+return vbicq(a, 0xd500);
+#else /* POLYMORPHIC */
+return vbicq_n_s16(a, 0xd500);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vbicq_n_u3218__simd128_uint32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = and <4 x i32> [[A:%.*]], 
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+uint32x4_t test_vbicq_n_u32(uint32x4_t a)
+{
+#ifdef POLYMORPHIC
+return vbicq(a, 0x2000);
+#else /* POLYMORPHIC */
+return vbicq_n_u32(a, 0x2000);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vorrq_n_s3217__simd128_int32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = or <4 x i32> [[A:%.*]], 
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+int32x4_t test_vorrq_n_s32(int32x4_t a)
+{
+#ifdef POLYMORPHIC
+return vorrq(a, 0x1);
+#else /* POLYMORPHIC */
+return vorrq_n_s32(a, 0x1);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vorrq_n_u1618__simd128_uint16_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = or <8 x i16> [[A:%.*]], 
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+uint16x8_t test_vorrq_n_u16(uint16x8_t a)
+{
+#ifdef POLYMORPHIC
+return vorrq(a, 0xf000);
+#else /* POLYMORPHIC */
+return vorrq_n_u16(a, 0xf000);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vcmpeqq_f1619__simd128_float16_tS_(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = fcmp oeq <8 x half> [[A:%.*]], [[B:%.*]]
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.arm.mve.pred.v2i.v8i1(<8 
x i1> [[TMP0]]), !range !3
+// CHECK-NEXT:[[TMP2:%.*]] = trunc i32 [[TMP1]] to i16
+// CHECK-NEXT:ret i16 [[TMP2]]
+//
+mve_pred16_t test_vcmpeqq_f16(float16x8_t a, float16x8_t b)
+{
+#ifdef POLYMORPHIC
+return vcmpeqq(a, b);
+#else /* POLYMORPHIC */
+return vcmpeqq_f16(a, b);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z18test_vcmpeqq_n_f1619__simd128_float16_tDh(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast float [[B_COERCE:%.*]] to i32
+// CHECK-NEXT:[[TMP_0_EXTRACT_TRUNC:%.*]] = trunc i32 [[TMP0]] to i16
+

[PATCH] D73270: [clan-tidy] Fix false positive in bugprone-infinite-loop

2020-01-23 Thread Balogh, Ádám via Phabricator via cfe-commits
baloghadamsoftware created this revision.
baloghadamsoftware added a reviewer: gribozavr2.
baloghadamsoftware added a project: clang-tools-extra.
Herald added subscribers: mgehre, gamesh411, Szelethus, rnkovacs, whisperity.
Herald added a project: clang.

The checker `bugprone-infinite-loop` does not track changes of variables in the 
initialization expression of a variable declared inside the condition of the 
`while` statement. This leads to false positives, similarly to the one in the 
bug report 44618 . This patch 
fixes this issue by enabling tracking of the variables of this expression as 
well.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D73270

Files:
  clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -8,6 +8,11 @@
 j++;
   }
 
+  while (int k = 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (k) are updated in the loop body 
[bugprone-infinite-loop]
+j--;
+  }
+
   do {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (i) are updated in the loop body 
[bugprone-infinite-loop]
 j++;
@@ -24,6 +29,11 @@
   int Limit = 10;
   while (i < Limit) {
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (i, Limit) are updated in the loop body 
[bugprone-infinite-loop]
+j--;
+  }
+
+  while (int k = Limit) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of 
its condition variables (k, Limit) are updated in the loop body 
[bugprone-infinite-loop]
 j++;
   }
 
@@ -44,6 +54,12 @@
 // Not an error since 'Limit' is updated.
 Limit--;
   }
+
+  while (int k = Limit) {
+// Not an error since 'Limit' is updated.
+Limit--;
+  }
+
   do {
 Limit--;
   } while (i < Limit);
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -129,6 +129,7 @@
 if (isAtLeastOneCondVarChanged(Func, LoopStmt, Child, Context))
   return true;
   }
+
   return false;
 }
 
@@ -149,6 +150,7 @@
   Result += ", ";
 Result += NewNames;
   }
+
   return Result;
 }
 
@@ -173,10 +175,32 @@
   if (isAtLeastOneCondVarChanged(Func, LoopStmt, Cond, Result.Context))
 return;
 
+  if (const auto *While = dyn_cast(LoopStmt)) {
+if (const auto *LoopVarDecl = While->getConditionVariable()) {
+  if (const Expr *Init = LoopVarDecl->getInit()) {
+if (isAtLeastOneCondVarChanged(Func, LoopStmt, Init,
+   Result.Context))
+  return;
+  }
+}
+  }
+
   std::string CondVarNames = getCondVarNames(Cond);
+
   if (CondVarNames.empty())
 return;
 
+  if (const auto *While = dyn_cast(LoopStmt)) {
+if (const auto *LoopVarDecl = While->getConditionVariable()) {
+  if (const Expr *Init = LoopVarDecl->getInit()) {
+std::string AdditionalVarNames = getCondVarNames(Init);
+if (!AdditionalVarNames.empty()) {
+  CondVarNames += ", " + AdditionalVarNames;
+}
+  }
+}
+  }
+
   diag(LoopStmt->getBeginLoc(),
"this loop is infinite; none of its condition variables (%0)"
" are updated in the loop body")


Index: clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone-infinite-loop.cpp
@@ -8,6 +8,11 @@
 j++;
   }
 
+  while (int k = 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (k) are updated in the loop body [bugprone-infinite-loop]
+j--;
+  }
+
   do {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
 j++;
@@ -24,6 +29,11 @@
   int Limit = 10;
   while (i < Limit) {
 // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i, Limit) are updated in the loop body [bugprone-infinite-loop]
+j--;
+  }
+
+  while (int k = Limit) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (k, Limit) are updated in the loop body [bugprone-infinite-loop]
 j++;
   }
 

[PATCH] D73268: [ARM,MVE] Make the MVE intrinsics work in C++!

2020-01-23 Thread Simon Tatham via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG98ea4b30c2c4: [ARM,MVE] Make the MVE intrinsics work in C++! 
(authored by simon_tatham).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73268

Files:
  clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp
  clang/utils/TableGen/MveEmitter.cpp

Index: clang/utils/TableGen/MveEmitter.cpp
===
--- clang/utils/TableGen/MveEmitter.cpp
+++ clang/utils/TableGen/MveEmitter.cpp
@@ -1603,6 +1603,10 @@
 "#endif\n"
 "\n"
 "#include \n"
+"\n"
+"#ifdef __cplusplus\n"
+"extern \"C\" {\n"
+"#endif\n"
 "\n";
 
   for (size_t i = 0; i < NumParts; ++i) {
@@ -1621,7 +1625,11 @@
   OS << "#endif /* " << condition << " */\n\n";
   }
 
-  OS << "#endif /* __ARM_MVE_H */\n";
+  OS << "#ifdef __cplusplus\n"
+"} /* extern \"C\" */\n"
+"#endif\n"
+"\n"
+"#endif /* __ARM_MVE_H */\n";
 }
 
 void MveEmitter::EmitBuiltinDef(raw_ostream &OS) {
Index: clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp
===
--- /dev/null
+++ clang/test/CodeGen/arm-mve-intrinsics/cplusplus.cpp
@@ -0,0 +1,160 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature +mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O3 -disable-O0-optnone -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+// RUN: %clang_cc1 -triple thumbv8.1m.main-arm-none-eabi -target-feature +mve.fp -mfloat-abi hard -fallow-half-arguments-and-returns -O3 -disable-O0-optnone -DPOLYMORPHIC -S -emit-llvm -o - %s | opt -S -mem2reg | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: @_Z16test_vbicq_n_s1617__simd128_int16_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = and <8 x i16> [[A:%.*]], 
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+int16x8_t test_vbicq_n_s16(int16x8_t a)
+{
+#ifdef POLYMORPHIC
+return vbicq(a, 0xd500);
+#else /* POLYMORPHIC */
+return vbicq_n_s16(a, 0xd500);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vbicq_n_u3218__simd128_uint32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = and <4 x i32> [[A:%.*]], 
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+uint32x4_t test_vbicq_n_u32(uint32x4_t a)
+{
+#ifdef POLYMORPHIC
+return vbicq(a, 0x2000);
+#else /* POLYMORPHIC */
+return vbicq_n_u32(a, 0x2000);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vorrq_n_s3217__simd128_int32_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = or <4 x i32> [[A:%.*]], 
+// CHECK-NEXT:ret <4 x i32> [[TMP0]]
+//
+int32x4_t test_vorrq_n_s32(int32x4_t a)
+{
+#ifdef POLYMORPHIC
+return vorrq(a, 0x1);
+#else /* POLYMORPHIC */
+return vorrq_n_s32(a, 0x1);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vorrq_n_u1618__simd128_uint16_t(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = or <8 x i16> [[A:%.*]], 
+// CHECK-NEXT:ret <8 x i16> [[TMP0]]
+//
+uint16x8_t test_vorrq_n_u16(uint16x8_t a)
+{
+#ifdef POLYMORPHIC
+return vorrq(a, 0xf000);
+#else /* POLYMORPHIC */
+return vorrq_n_u16(a, 0xf000);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z16test_vcmpeqq_f1619__simd128_float16_tS_(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = fcmp oeq <8 x half> [[A:%.*]], [[B:%.*]]
+// CHECK-NEXT:[[TMP1:%.*]] = tail call i32 @llvm.arm.mve.pred.v2i.v8i1(<8 x i1> [[TMP0]]), !range !3
+// CHECK-NEXT:[[TMP2:%.*]] = trunc i32 [[TMP1]] to i16
+// CHECK-NEXT:ret i16 [[TMP2]]
+//
+mve_pred16_t test_vcmpeqq_f16(float16x8_t a, float16x8_t b)
+{
+#ifdef POLYMORPHIC
+return vcmpeqq(a, b);
+#else /* POLYMORPHIC */
+return vcmpeqq_f16(a, b);
+#endif /* POLYMORPHIC */
+}
+
+// CHECK-LABEL: @_Z18test_vcmpeqq_n_f1619__simd128_float16_tDh(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[TMP0:%.*]] = bitcast float [[B_COERCE:%.*]] to i32
+// CHECK-NEXT:[[TMP_0_EXTRACT_TRUNC:%.*]] = trunc i32 [[TMP0]] to i16
+// CHECK-NEXT:[[TMP1:%.*]] = bitcast i16 [[TMP_0_EXTRACT_TRUNC]] to half
+// CHECK-NEXT:[[DOTSPLATINSERT:%.*]] = insertelement <8 x half> undef, half [[TMP1]], i32 0
+// CHECK-NEXT:[[DOTSPLAT:%.*]] = shufflevector <8 x half> [[DOTSPLATINSERT]], <8 x half> undef, <8 x i32> zeroinitializer
+// CHECK-NEXT:[[TMP2:%.*]] = fcmp oeq <8 x half> [[DOTSPLAT]], [[A:%.*]]
+// CHECK-NEXT:[[TMP3:%.*]] = tail call i32 @llvm.arm.mve.pred.v2i.v8i1(<8 x i1> [[TMP2]]), !range !3
+// CHECK-NEXT:[[TMP4:%.*]] = trunc i32 [[TMP3]] to i16
+// CHECK-NEXT:ret i16 [[TMP4]]
+//
+mve_pred16_t test_vcmpeqq_n_f16(float16x8_t a, float16_t b)
+{
+#ifdef POLYMORPHIC
+return vcmpeqq(a, b);
+#else /* POLYMORPHIC */
+return vcmpeqq_n_f16(a, b);
+#endif /* POLYMORPHIC

[clang] 24364cd - [clang][CodeComplete] Make completion work after initializer lists

2020-01-23 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2020-01-23T15:32:46+01:00
New Revision: 24364cd12bbfa2e58fa74bfb49d4ea85c64c0951

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

LOG: [clang][CodeComplete] Make completion work after initializer lists

Summary:
CodeCompletion was not being triggered after successfully parsed
initializer lists, e.g.

```cpp
void foo(int, bool);
void bar() {
  foo({1}^, false);
}
```

CodeCompletion would suggest the function foo as an overload candidate up until
the point marked with `^` but after that point we do not trigger signature help
since parsing succeeds.

This patch handles that case by failing in parsing expression lists whenever we
see a codecompletion token, in addition to getting an invalid subexpression.

Reviewers: sammccall

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Parse/ParseExpr.cpp
clang/test/CodeCompletion/call.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index df8388926db1..ba7525ecf527 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,16 @@ bool Parser::ParseExpressionList(SmallVectorImpl 
&Exprs,
 
 if (Tok.is(tok::ellipsis))
   Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+else if (Tok.is(tok::code_completion)) {
+  // There's nothing to suggest in here as we parsed a full expression.
+  // Instead fail and propogate the error since caller might have something
+  // the suggest, e.g. signature help in function call. Note that this is
+  // performed before pushing the \p Expr, so that signature help can 
report
+  // current argument correctly.
+  SawError = true;
+  cutOffParsing();
+  break;
+}
 if (Expr.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
   SawError = true;

diff  --git a/clang/test/CodeCompletion/call.cpp 
b/clang/test/CodeCompletion/call.cpp
index c57c339cd130..9cba6ae100b3 100644
--- a/clang/test/CodeCompletion/call.cpp
+++ b/clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@ void test() {
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2-NOT: f(Y y, int ZZ)
   // CHECK-CC2: f(int i, int j, <#int k#>)
+  f({}, 0, 0);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: OVERLOAD: [#void#]f()
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }



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


[PATCH] D73271: [clang][CodeComplete] Support for designated initializers

2020-01-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet created this revision.
kadircet added a reviewer: sammccall.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73271

Files:
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseInit.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/test/CodeCompletion/desig-init.cpp

Index: clang/test/CodeCompletion/desig-init.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/desig-init.cpp
@@ -0,0 +1,21 @@
+struct Base {
+  int t;
+};
+struct Foo : public Base {
+  int x;
+  Base b;
+  void foo();
+};
+
+void foo() {
+  Foo F{.x = 2, .b.t = 0};
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:11:10 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:11:18 %s -o - | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: b : [#Base#]b
+  // CHECK-CC1-NEXT: COMPLETION: x : [#int#]x
+  // CHECK-CC1-NOT: foo
+  // CHECK-CC1-NOT: t
+
+  // FIXME: Handle nested designators
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:11:20 %s -o - | count 0
+}
Index: clang/lib/Sema/SemaCodeComplete.cpp
===
--- clang/lib/Sema/SemaCodeComplete.cpp
+++ clang/lib/Sema/SemaCodeComplete.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/DeclBase.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
+#include "clang/AST/Expr.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/ExprObjC.h"
 #include "clang/AST/QualTypeNames.h"
@@ -23,11 +24,14 @@
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Sema/CodeCompleteConsumer.h"
+#include "clang/Sema/Designator.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Overload.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/ScopeInfo.h"
+#include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaInternal.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallBitVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -36,6 +40,7 @@
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Casting.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
@@ -4723,6 +4728,22 @@
   }
 }
 
+static RecordDecl *getAsRecordDecl(const QualType BaseType) {
+  if (const RecordType *Record = BaseType->getAs())
+return Record->getDecl();
+
+  if (const auto *ICNT = BaseType->getAs())
+return ICNT->getDecl();
+
+  if (const auto *TST = BaseType->getAs()) {
+if (const auto *TD = dyn_cast_or_null(
+TST->getTemplateName().getAsTemplateDecl()))
+  return TD->getTemplatedDecl();
+  }
+
+  return nullptr;
+}
+
 void Sema::CodeCompleteMemberReferenceExpr(Scope *S, Expr *Base,
Expr *OtherOpBase,
SourceLocation OpLoc, bool IsArrow,
@@ -4783,23 +4804,9 @@
 return false;
 }
 
-if (const RecordType *Record = BaseType->getAs()) {
+if (RecordDecl *RD = getAsRecordDecl(BaseType)) {
   AddRecordMembersCompletionResults(*this, Results, S, BaseType, BaseKind,
-Record->getDecl(),
-std::move(AccessOpFixIt));
-} else if (const auto *TST =
-   BaseType->getAs()) {
-  TemplateName TN = TST->getTemplateName();
-  if (const auto *TD =
-  dyn_cast_or_null(TN.getAsTemplateDecl())) {
-CXXRecordDecl *RD = TD->getTemplatedDecl();
-AddRecordMembersCompletionResults(*this, Results, S, BaseType, BaseKind,
-  RD, std::move(AccessOpFixIt));
-  }
-} else if (const auto *ICNT = BaseType->getAs()) {
-  if (auto *RD = ICNT->getDecl())
-AddRecordMembersCompletionResults(*this, Results, S, BaseType, BaseKind,
-  RD, std::move(AccessOpFixIt));
+RD, std::move(AccessOpFixIt));
 } else if (!IsArrow && BaseType->isObjCObjectPointerType()) {
   // Objective-C property reference.
   AddedPropertiesSet AddedProperties;
@@ -5286,6 +5293,34 @@
   return QualType();
 }
 
+void Sema::CodeCompleteDesignator(const QualType BaseType,
+  llvm::ArrayRef InitExprs,
+  const Designation &D) {
+  // FIXME: Handle nested designations, e.g. : .x.^
+  if (!D.empty())
+return;
+
+  const auto *RD = getAsRecordDecl(BaseType);
+  if (!RD || RD->fields().empty())
+return;
+
+  CodeCompletionContext CCC(CodeCompletionContext::CCC_DotMemberAccess,
+  

[PATCH] D73177: [clang][CodeComplete] Make completion work after initializer lists

2020-01-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG24364cd12bbf: [clang][CodeComplete] Make completion work 
after initializer lists (authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73177

Files:
  clang/lib/Parse/ParseExpr.cpp
  clang/test/CodeCompletion/call.cpp


Index: clang/test/CodeCompletion/call.cpp
===
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | 
FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2-NOT: f(Y y, int ZZ)
   // CHECK-CC2: f(int i, int j, <#int k#>)
+  f({}, 0, 0);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns 
-code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: OVERLOAD: [#void#]f()
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,16 @@
 
 if (Tok.is(tok::ellipsis))
   Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+else if (Tok.is(tok::code_completion)) {
+  // There's nothing to suggest in here as we parsed a full expression.
+  // Instead fail and propogate the error since caller might have something
+  // the suggest, e.g. signature help in function call. Note that this is
+  // performed before pushing the \p Expr, so that signature help can 
report
+  // current argument correctly.
+  SawError = true;
+  cutOffParsing();
+  break;
+}
 if (Expr.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
   SawError = true;


Index: clang/test/CodeCompletion/call.cpp
===
--- clang/test/CodeCompletion/call.cpp
+++ clang/test/CodeCompletion/call.cpp
@@ -25,4 +25,10 @@
   // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:19:13 %s -o - | FileCheck -check-prefix=CHECK-CC2 %s
   // CHECK-CC2-NOT: f(Y y, int ZZ)
   // CHECK-CC2: f(int i, int j, <#int k#>)
+  f({}, 0, 0);
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-patterns -code-completion-at=%s:28:7 %s -o - | FileCheck -check-prefix=CHECK-CC3 %s
+  // CHECK-CC3: OVERLOAD: [#void#]f()
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#X#>)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#int i#>, int j, int k)
+  // CHECK-CC3-NEXT: OVERLOAD: [#void#]f(<#float x#>, float y)
 }
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -3128,6 +3128,16 @@
 
 if (Tok.is(tok::ellipsis))
   Expr = Actions.ActOnPackExpansion(Expr.get(), ConsumeToken());
+else if (Tok.is(tok::code_completion)) {
+  // There's nothing to suggest in here as we parsed a full expression.
+  // Instead fail and propogate the error since caller might have something
+  // the suggest, e.g. signature help in function call. Note that this is
+  // performed before pushing the \p Expr, so that signature help can report
+  // current argument correctly.
+  SawError = true;
+  cutOffParsing();
+  break;
+}
 if (Expr.isInvalid()) {
   SkipUntil(tok::comma, tok::r_paren, StopBeforeMatch);
   SawError = true;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73270: [clang-tidy] Fix false positive in bugprone-infinite-loop

2020-01-23 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:179
+  if (const auto *While = dyn_cast(LoopStmt)) {
+if (const auto *LoopVarDecl = While->getConditionVariable()) {
+  if (const Expr *Init = LoopVarDecl->getInit()) {

Please don't use auto unless type is explicitly stated or iterator.



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:194
+  if (const auto *While = dyn_cast(LoopStmt)) {
+if (const auto *LoopVarDecl = While->getConditionVariable()) {
+  if (const Expr *Init = LoopVarDecl->getInit()) {

Please don't use auto unless type is explicitly stated or iterator.


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D73270



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


[PATCH] D72448: [clang-tidy] readability-redundant-string-init now flags redundant initialisation in Field Decls and Constructor Initialisers

2020-01-23 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 239884.
njames93 added a comment.

- Small refactor


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72448

Files:
  clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/readability-redundant-string-init.cpp
@@ -34,6 +34,12 @@
   std::string d(R"()");
   // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
   // CHECK-FIXES: std::string d;
+  std::string e{""};
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES: std::string e;
+  std::string f = {""};
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES: std::string f;
 
   std::string u = "u";
   std::string w("w");
@@ -227,3 +233,53 @@
   other::wstring e = L"";
   other::wstring f(L"");
 }
+
+class Foo {
+  std::string A = "";
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES:  std::string A;
+  std::string B;
+  std::string C;
+  std::string D;
+  std::string E = "NotEmpty";
+
+public:
+  // Check redundant constructor where Field has a redundant initializer.
+  Foo() : A("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:11: warning: redundant string initialization
+  // CHECK-FIXES:  Foo()  {}
+
+  // Check redundant constructor where Field has no initializer.
+  Foo(char) : B("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(char)  {}
+
+  // Check redundant constructor where Field has a valid initializer.
+  Foo(long) : E("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(long) : E() {}
+
+  // Check how it handles removing 1 initializer, and defaulting the other.
+  Foo(int) : B(""), E("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: redundant string initialization
+  // CHECK-MESSAGES: [[@LINE-2]]:21: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(int) :  E() {}
+
+  Foo(short) : B{""} {}
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(short)  {}
+
+  Foo(float) : A{""}, B{""} {}
+  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: redundant string initialization
+  // CHECK-MESSAGES: [[@LINE-2]]:23: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(float)  {}
+
+
+  // Check how it handles removing some redundant initializers while leaving
+  // valid initializers intact.
+  Foo(std::string Arg) : A(Arg), B(""), C("NonEmpty"), D(R"()"), E("") {}
+  // CHECK-MESSAGES: [[@LINE-1]]:34: warning: redundant string initialization
+  // CHECK-MESSAGES: [[@LINE-2]]:56: warning: redundant string initialization
+  // CHECK-MESSAGES: [[@LINE-3]]:66: warning: redundant string initialization
+  // CHECK-FIXES:  Foo(std::string Arg) : A(Arg),  C("NonEmpty"),  E() {}
+};
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -104,6 +104,11 @@
 Changes in existing checks
 ^^
 
+- Improved :doc:`readability-redundant-string-init
+  ` check now supports a
+  `StringNames` option enabling its application to custom string classes. The 
+  check now detects in class initializers and constructor initializers which 
+  are deemed to be redundant.
 
 Renamed checks
 ^^
Index: clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
===
--- clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
+++ clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
@@ -20,6 +20,46 @@
 
 const char DefaultStringNames[] = "::std::basic_string";
 
+static ast_matchers::internal::Matcher
+hasAnyNameStdString(std::vector Names) {
+  return ast_matchers::internal::Matcher(
+  new ast_matchers::internal::HasNameMatcher(std::move(Names)));
+}
+
+static std::vector
+removeNamespaces(const std::vector &Names) {
+  std::vector Result;
+  Result.reserve(Names.size());
+  for (const std::string &Name : Names) {
+std::string::size_type ColonPos = Name.rfind(':');
+Result.push_back(
+Name.substr(ColonPos == std::string::npos ? 0 : ColonPos + 1));
+  }
+  return Result;
+}
+
+static const CXXConstructExpr *
+getConstructExpr(const CXXCtorInitializer &CtorInit) {
+  const Expr *InitExpr = CtorInit.g

[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

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



Comment at: 
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp:383
+  } else {
+static llvm::Regex Matcher("(^((W[Mm])|(wm))ain([_A-Z]|$))|([a-z0-9_]W[Mm]"
+   "ain([_A-Z]|$))|(_wmain(_|$))",

aaron.ballman wrote:
> njames93 wrote:
> > Any thoughts on whether I should detect WMain or just Wmain. WMain looks 
> > more pleasing but using CamelCase rules it should likely be Wmain
> I think this needs to be controlled by an option if we want to keep it, 
> because you can still have names like `terminateMain(int exitCode, char 
> *msgs[]);` At the end of the day, no matter what regex we come up with, we 
> can probably pick an identifier that subverts the check. Also, the name 
> `main` might have different meanings if the function is a member function or 
> a member of a namespace (or, alternatively, it may actually relate to the 
> main entrypoint). Ultimately, this seems too much like guessing at user 
> intent, which is why I think it should be an option (and probably off by 
> default).
> 
> That said, if we're searching for main-like names, I think we need to find 
> names like wmain, Wmain, wMain, WMain optionally with a prefix or suffix 
> (perhaps with underscores). I am less certain how to treat member functions, 
> but suspect the reasonable thing to do is treat them as being potentially 
> main-like regardless of whether they're static or not, but the function still 
> needs to be publicly available rather than private or protected (those can't 
> be main-like, unless someone friends main... which is another twist).
Its current behaviour now is to just flag main, but there is an option 
IgnoreMainLikeFunctions(defaults to off) that if turned on will look for 
functions with the right sig that have the word main, Main, WMain, Wmain or 
wmain in there. I'll add in the public access though, that was an oversight


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098



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


[PATCH] D73271: [clang][CodeComplete] Support for designated initializers

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

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

{icon check-circle color=green} clang-tidy: pass.

{icon check-circle color=green} clang-format: pass.

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73271



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


[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson marked 2 inline comments as done.
tejohnson added inline comments.



Comment at: llvm/lib/Transforms/IPO/GlobalSplit.cpp:116
+if (GV.hasMetadata(LLVMContext::MD_vcall_visibility))
+  SplitGV->setVCallVisibilityMetadata(GV.getVCallVisibility());
   }

evgeny777 wrote:
> I think this needs a test. Removal of this code doesn't break anything
Adding some checking in a GlobalSplit test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71907



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


[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 239888.
tejohnson marked an inline comment as done.
tejohnson added a comment.

Test GlobalSplit handling of vcall_visibility metadata


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71907

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
  llvm/include/llvm/IR/GlobalObject.h
  llvm/lib/IR/Metadata.cpp
  llvm/lib/Transforms/IPO/GlobalDCE.cpp
  llvm/lib/Transforms/IPO/GlobalSplit.cpp
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-base-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-derived-pointer-call.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-novfe.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
  llvm/test/Transforms/GlobalDCE/virtual-functions.ll
  llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
  llvm/test/Transforms/GlobalSplit/basic.ll

Index: llvm/test/Transforms/GlobalSplit/basic.ll
===
--- llvm/test/Transforms/GlobalSplit/basic.ll
+++ llvm/test/Transforms/GlobalSplit/basic.ll
@@ -12,13 +12,13 @@
 ]
 
 ; CHECK-NOT: @global =
-; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+]], !type [[T2:![0-9]+]], !type [[T3:![0-9]+$]]
-; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T4:![0-9]+]], !type [[T5:![0-9]+$]]
+; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+]], !type [[T2:![0-9]+]], !type [[T3:![0-9]+]], !vcall_visibility [[VIS:![0-9]+$]]
+; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T4:![0-9]+]], !type [[T5:![0-9]+]], !vcall_visibility [[VIS$]]
 ; CHECK-NOT: @global =
 @global = internal constant { [2 x i8* ()*], [1 x i8* ()*] } {
   [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2],
   [1 x i8* ()*] [i8* ()* @f3]
-}, !type !0, !type !1, !type !2, !type !3, !type !4
+}, !type !0, !type !1, !type !2, !type !3, !type !4, !vcall_visibility !5
 
 ; CHECK: define i8* @f1()
 define i8* @f1() {
@@ -54,6 +54,7 @@
 ; CHECK: [[T1]] = !{i32 0, !"foo"}
 ; CHECK: [[T2]] = !{i32 15, !"bar"}
 ; CHECK: [[T3]] = !{i32 16, !"a"}
+; CHECK: [[VIS]] = !{i64 2}
 ; CHECK: [[T4]] = !{i32 1, !"b"}
 ; CHECK: [[T5]] = !{i32 8, !"c"}
 !0 = !{i32 0, !"foo"}
@@ -61,3 +62,4 @@
 !2 = !{i32 16, !"a"}
 !3 = !{i32 17, !"b"}
 !4 = !{i32 24, !"c"}
+!5 = !{i64 2}
Index: llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
===
--- llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
+++ llvm/test/Transforms/GlobalDCE/vtable-rtti.ll
@@ -39,9 +39,10 @@
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 @_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
 
-!llvm.module.flags = !{!3}
+!llvm.module.flags = !{!3, !4}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 2} ; translation-unit vcall visibility
 !3 = !{i32 1, !"LTOPostLink", i32 1}
+!4 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-pre-lto.ll
@@ -85,10 +85,11 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{}
+!llvm.module.flags = !{!5}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
 !2 = !{i64 0} ; public vcall visibility
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
+!5 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functions-visibility-post-lto.ll
@@ -85,7 +85,7 @@
 
 declare dso_local noalias nonnull i8* @_Znwm(i64)
 
-!llvm.module.flags = !{!5}
+!llvm.module.flags = !{!5, !6}
 
 !0 = !{i64 16, !"_ZTS1A"}
 !1 = !{i64 16, !"_ZTSM1AFvvE.virtual"}
@@ -93,3 +93,4 @@
 !3 = !{i64 1} ; linkage-unit vcall visibility
 !4 = !{i64 2} ; translation-unit vcall visibility
 !5 = !{i32 1, !"LTOPostLink", i32 1}
+!6 = !{i32 1, !"Virtual Function Elim", i32 1}
Index: llvm/test/Transforms/GlobalDCE/virtual-functions.ll
===
--- llvm/test/Transforms/GlobalDCE/virtual-functions.ll
+++ llvm/test/Transforms/GlobalDCE/virtual-functio

[PATCH] D72448: [clang-tidy] readability-redundant-string-init now flags redundant initialisation in Field Decls and Constructor Initialisers

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

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

{icon times-circle color=red} clang-tidy: fail. clang-tidy found 0 errors and 2 
warnings 
.
 0 of them are added as review comments below (why? 
).

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

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72448



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


[PATCH] D73271: [clang][CodeComplete] Support for designated initializers

2020-01-23 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

Nit: maybe mention "top-level"  in the patch?




Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4731
 
+static RecordDecl *getAsRecordDecl(const QualType BaseType) {
+  if (const RecordType *Record = BaseType->getAs())

this needs a name and/or comment to describe how it falls back to the primary 
template if the decl for the specialization isn't known.
(From the name, you can't tel how it's different from Type::getRecordDecl)



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:4735
+
+  if (const auto *ICNT = BaseType->getAs())
+return ICNT->getDecl();

this is handled by BaseType->getAsRecordDecl()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73271



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-23 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 239890.
tejohnson added a comment.

Implement suggestion


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71913

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGClass.cpp
  clang/lib/CodeGen/CGVTables.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  clang/test/CodeGenCXX/cfi-mfcall.cpp
  clang/test/CodeGenCXX/lto-visibility-inference.cpp
  clang/test/CodeGenCXX/thinlto-distributed-type-metadata.cpp
  clang/test/CodeGenCXX/type-metadata.cpp
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/devirt_vcall_vis_public.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Transforms/IPO.h
  llvm/include/llvm/Transforms/IPO/LowerTypeTests.h
  llvm/include/llvm/Transforms/IPO/WholeProgramDevirt.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOCodeGenerator.cpp
  llvm/lib/LTO/ThinLTOCodeGenerator.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
  llvm/test/ThinLTO/X86/cache-typeid-resolutions.ll
  llvm/test/ThinLTO/X86/cfi-devirt.ll
  llvm/test/ThinLTO/X86/devirt-after-icp.ll
  llvm/test/ThinLTO/X86/devirt.ll
  llvm/test/ThinLTO/X86/devirt2.ll
  llvm/test/ThinLTO/X86/devirt_alias.ll
  llvm/test/ThinLTO/X86/devirt_available_externally.ll
  llvm/test/ThinLTO/X86/devirt_external_comdat_same_guid.ll
  llvm/test/ThinLTO/X86/devirt_promote.ll
  llvm/test/ThinLTO/X86/devirt_promote_legacy.ll
  llvm/test/ThinLTO/X86/devirt_single_hybrid.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_hidden.ll
  llvm/test/ThinLTO/X86/devirt_vcall_vis_public.ll
  llvm/test/Transforms/WholeProgramDevirt/bad-read-from-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel-threshold.ll
  llvm/test/Transforms/WholeProgramDevirt/branch-funnel.ll
  llvm/test/Transforms/WholeProgramDevirt/constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl-check.ll
  llvm/test/Transforms/WholeProgramDevirt/devirt-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/expand-check.ll
  llvm/test/Transforms/WholeProgramDevirt/export-nothing.ll
  llvm/test/Transforms/WholeProgramDevirt/export-single-impl.ll
  llvm/test/Transforms/WholeProgramDevirt/export-uniform-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unique-ret-val.ll
  llvm/test/Transforms/WholeProgramDevirt/export-unsuccessful-checked.ll
  llvm/test/Transforms/WholeProgramDevirt/export-vcp.ll
  llvm/test/Transforms/WholeProgramDevirt/non-constant-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/pointer-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/soa-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/struct-vtable.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval-invoke.ll
  llvm/test/Transforms/WholeProgramDevirt/uniform-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/unique-retval.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-accesses-memory.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-decl.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-no-this.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-non-constant-arg.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-too-wide-ints.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-type-mismatch.ll
  llvm/test/Transforms/WholeProgramDevirt/vcp-uses-this.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-begin.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-check.ll
  llvm/test/Transforms/WholeProgramDevirt/virtual-const-prop-end.ll
  llvm/test/Transforms/WholeProgramDevirt/vtable-decl.ll
  llvm/test/tools/gold/X86/devirt_vcall_vis_public.ll
  llvm/tools/gold/gold-plugin.cpp
  llvm/tools/opt/opt.cpp

Index: llvm/tools/opt/opt.cpp
===
--- llvm/tools/opt/opt.cpp
+++ llvm/tools/opt/opt.cpp
@@ -54,6 +54,7 @@
 #include "llvm/Transforms/Coroutines.h"
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
+#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/Utils/Cloning.h"
 #include "llvm/Transforms/Utils/Debugify.h"
 #include 
@@ -625,6 +626,13 @@
 return 1;
   }
 
+  // Enable testing of whole program devirtualization on this module by invoking
+  // the facility for updating public visibility to linkage unit visibility when
+  // specified by an internal option. This is normally done during LTO which is
+  // not performed via opt.
+  updateVCallVisibilityInModule(*M,
+/* WholeProgramVisibilityEnabledInLTO */ false);
+
   // Figure out what stream we are supposed to write to...
   std::unique_ptr Out;
   std::unique_ptr ThinLinkOut;
Index: llvm/tools/gold/gold-plugin.cpp
===
--- llvm/tools/gold/gold-plugin.cpp
+++ llv

[PATCH] D65994: Extended FPOptions with new attributes

2020-01-23 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 239893.
sepavloff added a comment.

Rebased the patch


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65994

Files:
  clang/include/clang/AST/Stmt.h
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/TreeTransform.h

Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -9938,7 +9938,7 @@
   RHS.get() == E->getRHS())
 return E;
 
-  Sema::FPContractStateRAII FPContractState(getSema());
+  Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
   getSema().FPFeatures = E->getFPFeatures();
 
   return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
@@ -10464,7 +10464,7 @@
   (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
 return SemaRef.MaybeBindToTemporary(E);
 
-  Sema::FPContractStateRAII FPContractState(getSema());
+  Sema::FPFeaturesStateRAII FPFeaturesState(getSema());
   getSema().FPFeatures = E->getFPFeatures();
 
   return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
Index: clang/lib/Sema/SemaAttr.cpp
===
--- clang/lib/Sema/SemaAttr.cpp
+++ clang/lib/Sema/SemaAttr.cpp
@@ -940,6 +940,14 @@
   }
 }
 
+void Sema::setRoundingMode(LangOptions::FPRoundingModeKind FPR) {
+  FPFeatures.setRoundingMode(FPR);
+}
+
+void Sema::setExceptionMode(LangOptions::FPExceptionModeKind FPE) {
+  FPFeatures.setExceptionMode(FPE);
+}
+
 void Sema::ActOnPragmaFEnvAccess(LangOptions::FEnvAccessModeKind FPC) {
   switch (FPC) {
   case LangOptions::FEA_On:
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -1014,9 +1014,9 @@
 Tok.getLocation(),
 "in compound statement ('{}')");
 
-  // Record the state of the FP_CONTRACT pragma, restore on leaving the
+  // Record the state of the FPFeatures, restore on leaving the
   // compound statement.
-  Sema::FPContractStateRAII SaveFPContractState(Actions);
+  Sema::FPFeaturesStateRAII SaveFPContractState(Actions);
 
   InMessageExpressionRAIIObject InMessage(*this, false);
   BalancedDelimiterTracker T(*this, tok::l_brace);
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1295,12 +1295,12 @@
   /// should not be used elsewhere.
   void EmitCurrentDiagnostic(unsigned DiagID);
 
-  /// Records and restores the FP_CONTRACT state on entry/exit of compound
+  /// Records and restores the FPFeatures state on entry/exit of compound
   /// statements.
-  class FPContractStateRAII {
+  class FPFeaturesStateRAII {
   public:
-FPContractStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.FPFeatures) {}
-~FPContractStateRAII() { S.FPFeatures = OldFPFeaturesState; }
+FPFeaturesStateRAII(Sema &S) : S(S), OldFPFeaturesState(S.FPFeatures) {}
+~FPFeaturesStateRAII() { S.FPFeatures = OldFPFeaturesState; }
 
   private:
 Sema& S;
@@ -9385,6 +9385,12 @@
   /// \#pragma STDC FENV_ACCESS
   void ActOnPragmaFEnvAccess(LangOptions::FEnvAccessModeKind FPC);
 
+  /// Called to set rounding mode for floating point operations.
+  void setRoundingMode(LangOptions::FPRoundingModeKind);
+
+  /// Called to set exception behavior for floating point operations.
+  void setExceptionMode(LangOptions::FPExceptionModeKind);
+
   /// AddAlignmentAttributesForRecord - Adds any needed alignment attributes to
   /// a the record decl, to handle '\#pragma pack' and '\#pragma options align'.
   void AddAlignmentAttributesForRecord(RecordDecl *RD);
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h
@@ -357,17 +357,25 @@
 class FPOptions {
 public:
   FPOptions() : fp_contract(LangOptions::FPC_Off),
-fenv_access(LangOptions::FEA_Off) {}
+fenv_access(LangOptions::FEA_Off),
+rounding(LangOptions::FPR_ToNearest),
+exceptions(LangOptions::FPE_Ignore)
+{}
 
   // Used for serializing.
   explicit FPOptions(unsigned I)
   : fp_contract(static_cast(I & 3)),
-fenv_access(static_cast((I >> 2) & 1))
+fenv_access(static_cast((I >> 2) & 1)),
+rounding(static_cast((I >> 3) & 7)),
+exceptions(static_cast((I >> 6) & 3))
 {}
 
   explicit FPOptions(const LangOptions &LangOpts)
   : fp_contract(LangOpts.getDefaultFPContractMode()),
-fenv_access(LangOptions::FEA_Off) {

[PATCH] D72705: [clang][checkers] Added new checker 'alpha.unix.ErrorReturn'.

2020-01-23 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 239891.
balazske added a comment.

Added garbage collection and better problem detection.

Without preventing garbage collection it is not possible to improve the checker
(in this way).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72705

Files:
  clang/include/clang/StaticAnalyzer/Checkers/Checkers.td
  clang/lib/StaticAnalyzer/Checkers/CMakeLists.txt
  clang/lib/StaticAnalyzer/Checkers/ErrorReturnChecker.cpp
  clang/test/Analysis/Inputs/system-header-simulator.h
  clang/test/Analysis/error-return.c

Index: clang/test/Analysis/error-return.c
===
--- /dev/null
+++ clang/test/Analysis/error-return.c
@@ -0,0 +1,340 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.unix.ErrorReturn -verify %s
+
+#include "Inputs/system-header-simulator.h"
+
+/*
+Functions from CERT ERR33-C that should be checked for error:
+https://wiki.sei.cmu.edu/confluence/display/c/ERR33-C.+Detect+and+handle+standard+library+errors
+
+void *aligned_alloc( size_t alignment, size_t size );
+errno_t asctime_s(char *buf, rsize_t bufsz, const struct tm *time_ptr);
+int at_quick_exit( void (*func)(void) );
+int atexit( void (*func)(void) );
+void* bsearch( const void *key, const void *ptr, size_t count, size_t size,
+   int (*comp)(const void*, const void*) );
+void* bsearch_s( const void *key, const void *ptr, rsize_t count, rsize_t size,
+ int (*comp)(const void *, const void *, void *),
+ void *context );
+wint_t btowc( int c );
+size_t c16rtomb( char * restrict s, char16_t c16, mbstate_t * restrict ps );
+size_t c32rtomb( char * restrict s, char32_t c32, mbstate_t * restrict ps );
+void* calloc( size_t num, size_t size );
+clock_t clock(void);
+int cnd_broadcast( cnd_t *cond );
+int cnd_init( cnd_t* cond );
+int cnd_signal( cnd_t *cond );
+int cnd_timedwait( cnd_t* restrict cond, mtx_t* restrict mutex,
+   const struct timespec* restrict time_point );
+int cnd_wait( cnd_t* cond, mtx_t* mutex );
+errno_t ctime_s(char *buffer, rsize_t bufsz, const time_t *time);
+int fclose( FILE *stream );
+int fflush( FILE *stream );
+int fgetc( FILE *stream );
+int fgetpos( FILE *restrict stream, fpos_t *restrict pos );
+char *fgets( char *restrict str, int count, FILE *restrict stream );
+wint_t fgetwc( FILE *stream );
+FILE *fopen( const char *restrict filename, const char *restrict mode );
+errno_t fopen_s(FILE *restrict *restrict streamptr,
+const char *restrict filename,
+const char *restrict mode);
+int fprintf( FILE *restrict stream, const char *restrict format, ... );
+int fprintf_s(FILE *restrict stream, const char *restrict format, ...);
+int fputc( int ch, FILE *stream );
+int fputs( const char *restrict str, FILE *restrict stream );
+wint_t fputwc( wchar_t ch, FILE *stream );
+int fputws( const wchar_t * restrict str, FILE * restrict stream );
+size_t fread( void *restrict buffer, size_t size, size_t count,
+  FILE *restrict stream );
+FILE *freopen( const char *restrict filename, const char *restrict mode,
+   FILE *restrict stream );
+errno_t freopen_s(FILE *restrict *restrict newstreamptr,
+  const char *restrict filename, const char *restrict mode,
+  FILE *restrict stream);
+int fscanf( FILE *restrict stream, const char *restrict format, ... );
+int fscanf_s(FILE *restrict stream, const char *restrict format, ...);
+int fseek( FILE *stream, long offset, int origin );
+int fsetpos( FILE *stream, const fpos_t *pos );
+long ftell( FILE *stream );
+int fwprintf( FILE *restrict stream,
+  const wchar_t *restrict format, ... );
+int fwprintf_s( FILE *restrict stream,
+const wchar_t *restrict format, ...);
+size_t fwrite( const void *restrict buffer, size_t size, size_t count,
+   FILE *restrict stream ); // more exact error return: < count
+int fwscanf( FILE *restrict stream,
+ const wchar_t *restrict format, ... );
+int fwscanf_s( FILE *restrict stream,
+   const wchar_t *restrict format, ...);
+int getc( FILE *stream );
+int getchar(void);
+char *getenv( const char *name );
+errno_t getenv_s( size_t *restrict len, char *restrict value,
+  rsize_t valuesz, const char *restrict name );
+char *gets_s( char *str, rsize_t n );
+wint_t getwc( FILE *stream );
+wint_t getwchar(void);
+struct tm *gmtime( const time_t *time );
+struct tm *gmtime_s(const time_t *restrict time, struct tm *restrict result);
+struct tm *localtime( const time_t *time );
+struct tm *localtime_s(const time_t *restrict time, struct tm *restrict result);
+void* malloc( size_t size );
+int mblen( const char* s, size_t n );
+size_t mbrlen( const char *restrict s, size_t n, mbstate_t *restrict ps );
+size_t mbrtoc16( char16_t * restrict pc16, const char * restrict s

[PATCH] D72467: Remove "mask" operand from shufflevector.

2020-01-23 Thread Sanjay Patel via Phabricator via cfe-commits
spatel added inline comments.



Comment at: llvm/include/llvm/IR/Constants.h:1220
 
+  /// Assert that this is an shufflevector and return the mask. See class
+  /// ShuffleVectorInst for a description of the mask representation.

an shufflevector -> a shufflevector



Comment at: llvm/include/llvm/IR/Constants.h:1224
+
+  /// Assert that this is an shufflevector and return the mask.
+  ///

an shufflevector -> a shufflevector



Comment at: llvm/include/llvm/IR/IRBuilder.h:2544
+SmallVector IntMask;
+ShuffleVectorInst::getShuffleMask(cast(Mask), IntMask);
+return CreateShuffleVector(V1, V2, IntMask, Name);

Add an assert that Mask isa ?



Comment at: llvm/include/llvm/IR/Instructions.h:1985-1986
 ///
+/// The shuffle mask operand specifies, for each element of the result vector,
+/// which element of the two input vectors the result element gets. The
+/// shuffle mask is represented as an array of integers. Positive integers

This reads awkwardly to me (if you agree, we can update the LangRef too). 
How about:
"For each element of the result vector, the shuffle mask selects an element 
from one of the input vectors to copy to the result. Non-negative elements in 
the mask represent an index into the concatenated pair of input vectors. 
UndefMaskElem (-1) specifies that the result element is undefined."



Comment at: llvm/include/llvm/IR/Instructions.h:2015
 
-  // allocate space for exactly three operands
+  // allocate space for exactly two operands
   void *operator new(size_t s) {

This comment doesn't add value to me, so I'd just delete it. If we want to keep 
it, should fix it to be a proper sentence with a capital letter and period.



Comment at: llvm/include/llvm/IR/PatternMatch.h:1306
+
+struct m_ZeroMask {
+  bool match(ArrayRef Mask) {

IIUC, this is meant to replace the current uses of m_Zero() or m_ZeroInt() with 
shuffle pattern matching, but there's a logic difference because those matchers 
allow undefs, but this does not? Are we missing unittests to catch that case?



Comment at: llvm/include/llvm/IR/PatternMatch.h:1320
+
 /// Matches ShuffleVectorInst.
+template 

Update/add comment:
"Matches ShuffleVectorInst independently of mask value." ?



Comment at: llvm/lib/Bitcode/Writer/ValueEnumerator.cpp:937-939
+   if (auto *CE = dyn_cast(C))
+ if (CE->getOpcode() == Instruction::ShuffleVector)
+   EnumerateOperandType(CE->getShuffleMaskForBitcode());

Indentation looks off-by-1.



Comment at: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp:1937
+  ArrayRef Mask;
+  if (const ShuffleVectorInst *SVI = dyn_cast(&U))
+Mask = SVI->getShuffleMask();

if (auto *SVI = ...)



Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:3587
+  ArrayRef Mask;
+  if (const ShuffleVectorInst *SVI = dyn_cast(&I))
+Mask = SVI->getShuffleMask();

if (auto *SVI = ...)



Comment at: llvm/lib/ExecutionEngine/Interpreter/Execution.cpp:1890
   for( unsigned i=0; igetSyncScopeID() == cast(I2)->getSyncScopeID();
+  if (const ShuffleVectorInst *SVI = dyn_cast(I1))
+return SVI->getShuffleMask() == 
cast(I2)->getShuffleMask();

Would have suggested "auto *" here, but really the whole thing should be turned 
into a switch() as a preliminary cleanup?



Comment at: llvm/lib/IR/Instructions.cpp:1824-1825
+ Instruction *InsertBefore)
+: 
Instruction(VectorType::get(cast(V1->getType())->getElementType(),
+Mask.size(), V1->getType()->getVectorIsScalable()),
+  ShuffleVector,

I see this is copied, but indentation seems off.



Comment at: llvm/lib/Transforms/Scalar/GVN.cpp:304
   e.varargs.push_back(*II);
+  } else if (ShuffleVectorInst *SVI = dyn_cast(I)) {
+ArrayRef ShuffleMask = SVI->getShuffleMask();

Use "auto *" in each clause (or convert to switch).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72467



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


[PATCH] D71913: [LTO/WPD] Enable aggressive WPD under LTO option

2020-01-23 Thread Eugene Leviant via Phabricator via cfe-commits
evgeny777 accepted this revision.
evgeny777 added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71913



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


[PATCH] D71911: [ThinLTO] Summarize vcall_visibility metadata

2020-01-23 Thread Eugene Leviant via Phabricator via cfe-commits
evgeny777 accepted this revision.
evgeny777 added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71911



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


[PATCH] D71907: [WPD/VFE] Always emit vcall_visibility metadata for -fwhole-program-vtables

2020-01-23 Thread Eugene Leviant via Phabricator via cfe-commits
evgeny777 accepted this revision.
evgeny777 added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71907



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


[PATCH] D73274: [Alignment][NFC] Use Align with CreateAlignedStore

2020-01-23 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet created this revision.
gchatelet added a reviewer: courbet.
Herald added subscribers: llvm-commits, cfe-commits, kerbowa, hiraditya, 
nhaehnle, jvesely, arsenm.
Herald added a reviewer: bollu.
Herald added projects: clang, LLVM.

This is patch is part of a series to introduce an Alignment type.
See this thread for context: 
http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D73274

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/GlobalObject.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
  llvm/lib/Target/X86/X86InterleavedAccess.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/lib/Transforms/Scalar/Scalarizer.cpp
  llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  polly/lib/CodeGen/BlockGenerators.cpp
  polly/lib/CodeGen/LoopGeneratorsKMP.cpp
  polly/lib/CodeGen/RuntimeDebugBuilder.cpp

Index: polly/lib/CodeGen/RuntimeDebugBuilder.cpp
===
--- polly/lib/CodeGen/RuntimeDebugBuilder.cpp
+++ polly/lib/CodeGen/RuntimeDebugBuilder.cpp
@@ -221,7 +221,7 @@
 
 Ty = Val->getType();
 Ptr = Builder.CreatePointerBitCastOrAddrSpaceCast(Ptr, Ty->getPointerTo(5));
-Builder.CreateAlignedStore(Val, Ptr, 4);
+Builder.CreateAlignedStore(Val, Ptr, Align(4));
 
 if (Ty->isFloatingPointTy())
   str += "%f";
Index: polly/lib/CodeGen/LoopGeneratorsKMP.cpp
===
--- polly/lib/CodeGen/LoopGeneratorsKMP.cpp
+++ polly/lib/CodeGen/LoopGeneratorsKMP.cpp
@@ -176,7 +176,7 @@
   extractValuesFromStruct(Data, StructData->getAllocatedType(), UserContext,
   Map);
 
-  const int Alignment = (is64BitArch()) ? 8 : 4;
+  const auto Alignment = llvm::Align(is64BitArch() ? 8 : 4);
   Value *ID =
   Builder.CreateAlignedLoad(IDPtr, Alignment, "polly.par.global_tid");
 
Index: polly/lib/CodeGen/BlockGenerators.cpp
===
--- polly/lib/CodeGen/BlockGenerators.cpp
+++ polly/lib/CodeGen/BlockGenerators.cpp
@@ -343,7 +343,7 @@
   RuntimeDebugBuilder::createCPUPrinter(Builder, "Store to  ", NewPointer,
 ": ", ValueOperand, "\n");
 
-Builder.CreateAlignedStore(ValueOperand, NewPointer, Store->getAlignment());
+Builder.CreateAlignedStore(ValueOperand, NewPointer, Store->getAlign());
   });
 }
 
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2346,8 +2346,8 @@
   IVec, AddrParts[Part], Group->getAlign(), ShuffledMask);
 }
 else
-  NewStoreInstr = Builder.CreateAlignedStore(IVec, AddrParts[Part],
- Group->getAlignment());
+  NewStoreInstr =
+  Builder.CreateAlignedStore(IVec, AddrParts[Part], Group->getAlign());
 
 Group->addMetadata(NewStoreInstr);
   }
@@ -2452,8 +2452,7 @@
   NewSI = Builder.CreateMaskedStore(StoredVal, VecPtr, Alignment,
 BlockInMaskParts[Part]);
 else
-  NewSI =
-  Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment.value());
+  NewSI = Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment);
   }
   addMetadata(NewSI, SI);
 }
Index: llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ -129,20 +129,18 @@
 private:
   unsigned getPointerAddressSpace(Value *I);
 
-  unsigned getAlignment(LoadInst *LI) const {
-unsigned Align = LI->getAlignment();
-if (Align != 0)
-  return Align;
+  /// TODO: Remove this function once transition to Align is over.
+  unsigned getAlignment(LoadInst *LI) const { return getAlign(LI).value(); }
 
-

[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

2020-01-23 Thread Nathan James via Phabricator via cfe-commits
njames93 updated this revision to Diff 239902.
njames93 added a comment.

- Added checks for access specifiers


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098

Files:
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
  clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
  clang-tools-extra/docs/clang-tidy/checks/readability-identifier-naming.rst
  
clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-main-like.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-main-like.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/readability-identifier-naming-main-like.cpp
@@ -0,0 +1,88 @@
+// RUN: %check_clang_tidy %s readability-identifier-naming %t -- \
+// RUN:   -config='{CheckOptions: [ \
+// RUN: {key: readability-identifier-naming.ParameterCase, value: CamelCase}, \
+// RUN: {key: readability-identifier-naming.IgnoreMainLikeFunctions, value: 1} \
+// RUN:  ]}'
+
+int mainLike(int argc, char **argv);
+int mainLike(int argc, char **argv, const char **env);
+int mainLike(int argc, const char **argv);
+int mainLike(int argc, const char **argv, const char **env);
+int mainLike(int argc, char *argv[]);
+int mainLike(int argc, const char *argv[]);
+int mainLike(int argc, char *argv[], char *env[]);
+int mainLike(int argc, const char *argv[], const char *env[]);
+void notMain(int argc, char **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: invalid case style for parameter 'argv'
+void notMain(int argc, char **argv, char **env);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: invalid case style for parameter 'argv'
+// CHECK-MESSAGES: :[[@LINE-3]]:44: warning: invalid case style for parameter 'env'
+int notMain(int argc, char **argv, char **env, int Extra);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'argv'
+// CHECK-MESSAGES: :[[@LINE-3]]:43: warning: invalid case style for parameter 'env'
+int notMain(int argc, char **argv, int Extra);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'argv'
+int notMain(int argc, char *argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: invalid case style for parameter 'argv'
+int notMain(unsigned argc, char **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:35: warning: invalid case style for parameter 'argv'
+int notMain(long argc, char *argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:30: warning: invalid case style for parameter 'argv'
+int notMain(int argc, char16_t **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:34: warning: invalid case style for parameter 'argv'
+int notMain(int argc, char argv[]);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:28: warning: invalid case style for parameter 'argv'
+typedef char myFunChar;
+typedef int myFunInt;
+typedef char **myFunCharPtr;
+typedef long myFunLong;
+myFunInt mainLikeTypedef(myFunInt argc, myFunChar **argv);
+int mainLikeTypedef(int argc, myFunCharPtr argv);
+int notMainTypedef(myFunLong argc, char **argv);
+// CHECK-MESSAGES: :[[@LINE-1]]:30: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:43: warning: invalid case style for parameter 'argv'
+
+// Don't flag as name contains the word main
+int myMainFunction(int argc, char *argv[]);
+
+// This is fine, named with wmain and has wchar ptr.
+int wmainLike(int argc, wchar_t *argv[]);
+
+// Flag this as has signature of main, but named as wmain.
+int wmainLike(int argc, char *argv[]);
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: invalid case style for parameter 'argc'
+// CHECK-MESSAGES: :[[@LINE-2]]:31: warning: invalid case style for parameter 'argv'
+
+struct Foo {
+  Foo(int argc, char *argv[]) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: invalid case style for parameter 'argc'
+  // CHECK-MESSAGES: :[[@LINE-2]]:23: warning: invalid case style for parameter 'argv'
+
+  int mainPub(int argc, char *argv[]);
+  static int mainPubStatic(int argc, char *argv[]);
+
+protected:
+  int mainProt(int argc, char *argv[]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: invalid case style for par

[PATCH] D73274: [Alignment][NFC] Use Align with CreateAlignedStore

2020-01-23 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 239903.
gchatelet added a comment.

- Improving DataLayout


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73274

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/GlobalObject.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
  llvm/lib/Target/X86/X86InterleavedAccess.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/lib/Transforms/Scalar/Scalarizer.cpp
  llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  polly/lib/CodeGen/BlockGenerators.cpp
  polly/lib/CodeGen/LoopGeneratorsKMP.cpp
  polly/lib/CodeGen/RuntimeDebugBuilder.cpp

Index: polly/lib/CodeGen/RuntimeDebugBuilder.cpp
===
--- polly/lib/CodeGen/RuntimeDebugBuilder.cpp
+++ polly/lib/CodeGen/RuntimeDebugBuilder.cpp
@@ -221,7 +221,7 @@
 
 Ty = Val->getType();
 Ptr = Builder.CreatePointerBitCastOrAddrSpaceCast(Ptr, Ty->getPointerTo(5));
-Builder.CreateAlignedStore(Val, Ptr, 4);
+Builder.CreateAlignedStore(Val, Ptr, Align(4));
 
 if (Ty->isFloatingPointTy())
   str += "%f";
Index: polly/lib/CodeGen/LoopGeneratorsKMP.cpp
===
--- polly/lib/CodeGen/LoopGeneratorsKMP.cpp
+++ polly/lib/CodeGen/LoopGeneratorsKMP.cpp
@@ -176,7 +176,7 @@
   extractValuesFromStruct(Data, StructData->getAllocatedType(), UserContext,
   Map);
 
-  const int Alignment = (is64BitArch()) ? 8 : 4;
+  const auto Alignment = llvm::Align(is64BitArch() ? 8 : 4);
   Value *ID =
   Builder.CreateAlignedLoad(IDPtr, Alignment, "polly.par.global_tid");
 
Index: polly/lib/CodeGen/BlockGenerators.cpp
===
--- polly/lib/CodeGen/BlockGenerators.cpp
+++ polly/lib/CodeGen/BlockGenerators.cpp
@@ -343,7 +343,7 @@
   RuntimeDebugBuilder::createCPUPrinter(Builder, "Store to  ", NewPointer,
 ": ", ValueOperand, "\n");
 
-Builder.CreateAlignedStore(ValueOperand, NewPointer, Store->getAlignment());
+Builder.CreateAlignedStore(ValueOperand, NewPointer, Store->getAlign());
   });
 }
 
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2346,8 +2346,8 @@
   IVec, AddrParts[Part], Group->getAlign(), ShuffledMask);
 }
 else
-  NewStoreInstr = Builder.CreateAlignedStore(IVec, AddrParts[Part],
- Group->getAlignment());
+  NewStoreInstr =
+  Builder.CreateAlignedStore(IVec, AddrParts[Part], Group->getAlign());
 
 Group->addMetadata(NewStoreInstr);
   }
@@ -2452,8 +2452,7 @@
   NewSI = Builder.CreateMaskedStore(StoredVal, VecPtr, Alignment,
 BlockInMaskParts[Part]);
 else
-  NewSI =
-  Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment.value());
+  NewSI = Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment);
   }
   addMetadata(NewSI, SI);
 }
Index: llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ -129,20 +129,19 @@
 private:
   unsigned getPointerAddressSpace(Value *I);
 
-  unsigned getAlignment(LoadInst *LI) const {
-unsigned Align = LI->getAlignment();
-if (Align != 0)
-  return Align;
+  /// TODO: Remove this function once transition to Align is over.
+  unsigned getAlignment(LoadInst *LI) const { return getAlign(LI).value(); }
 
-return DL.getABITypeAlignment(LI->getType());
+  Align getAlign(LoadInst *LI) const {
+return DL.getValueOrABITypeAlignment(LI->getAlign(), LI->getType());
   }
 
-  unsigned getAlignment(StoreInst *SI) const {
-unsigned Align = SI->getAlignment();
-if (Align != 0)
-  return Align;
+  /// TODO:

[PATCH] D73098: [clang-tidy] readability-identifier-naming disregards parameters restrictions on main like functions

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

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

{icon times-circle color=red} clang-tidy: fail. clang-tidy found 0 errors and 1 
warnings 
.
 0 of them are added as review comments below (why? 
).

{icon check-circle color=green} clang-format: pass.

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73098



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


[PATCH] D73274: [Alignment][NFC] Use Align with CreateAlignedStore

2020-01-23 Thread Clement Courbet via Phabricator via cfe-commits
courbet accepted this revision.
courbet added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/include/llvm/IR/DataLayout.h:504
   /// Returns the minimum ABI-required alignment for the specified type.
+  /// TODO: Deprecate this function once migration to Align is over.
   unsigned getABITypeAlignment(Type *Ty) const;

FIXME



Comment at: llvm/include/llvm/IR/DataLayout.h:525
   /// This is always at least as good as the ABI alignment.
+  /// TODO: Deprecate this function once migration to Align is over.
   unsigned getPrefTypeAlignment(Type *Ty) const;

FIXME



Comment at: llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp:534
 
   unsigned AlignVal = cast(Alignment)->getZExtValue();
   unsigned VectorWidth = Src->getType()->getVectorNumElements();

You can use a typed variable here.



Comment at: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp:1225
+  llvm::Instruction *NS =
+  IC.Builder.CreateAlignedStore(Val, Ptr, MaybeAlign(EltAlign));
   AAMDNodes AAMD;

I don;t think you need the `MaybeAlign` here



Comment at: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp:1276
+  Instruction *NS =
+  IC.Builder.CreateAlignedStore(Val, Ptr, MaybeAlign(EltAlign));
   AAMDNodes AAMD;

ditto


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73274



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


[PATCH] D73274: [Alignment][NFC] Use Align with CreateAlignedStore

2020-01-23 Thread Guillaume Chatelet via Phabricator via cfe-commits
gchatelet updated this revision to Diff 239906.
gchatelet marked 5 inline comments as done.
gchatelet added a comment.

- Address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73274

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/GlobalObject.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
  llvm/lib/Target/X86/X86InterleavedAccess.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/lib/Transforms/Scalar/Scalarizer.cpp
  llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  polly/lib/CodeGen/BlockGenerators.cpp
  polly/lib/CodeGen/LoopGeneratorsKMP.cpp
  polly/lib/CodeGen/RuntimeDebugBuilder.cpp

Index: polly/lib/CodeGen/RuntimeDebugBuilder.cpp
===
--- polly/lib/CodeGen/RuntimeDebugBuilder.cpp
+++ polly/lib/CodeGen/RuntimeDebugBuilder.cpp
@@ -221,7 +221,7 @@
 
 Ty = Val->getType();
 Ptr = Builder.CreatePointerBitCastOrAddrSpaceCast(Ptr, Ty->getPointerTo(5));
-Builder.CreateAlignedStore(Val, Ptr, 4);
+Builder.CreateAlignedStore(Val, Ptr, Align(4));
 
 if (Ty->isFloatingPointTy())
   str += "%f";
Index: polly/lib/CodeGen/LoopGeneratorsKMP.cpp
===
--- polly/lib/CodeGen/LoopGeneratorsKMP.cpp
+++ polly/lib/CodeGen/LoopGeneratorsKMP.cpp
@@ -176,7 +176,7 @@
   extractValuesFromStruct(Data, StructData->getAllocatedType(), UserContext,
   Map);
 
-  const int Alignment = (is64BitArch()) ? 8 : 4;
+  const auto Alignment = llvm::Align(is64BitArch() ? 8 : 4);
   Value *ID =
   Builder.CreateAlignedLoad(IDPtr, Alignment, "polly.par.global_tid");
 
Index: polly/lib/CodeGen/BlockGenerators.cpp
===
--- polly/lib/CodeGen/BlockGenerators.cpp
+++ polly/lib/CodeGen/BlockGenerators.cpp
@@ -343,7 +343,7 @@
   RuntimeDebugBuilder::createCPUPrinter(Builder, "Store to  ", NewPointer,
 ": ", ValueOperand, "\n");
 
-Builder.CreateAlignedStore(ValueOperand, NewPointer, Store->getAlignment());
+Builder.CreateAlignedStore(ValueOperand, NewPointer, Store->getAlign());
   });
 }
 
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2346,8 +2346,8 @@
   IVec, AddrParts[Part], Group->getAlign(), ShuffledMask);
 }
 else
-  NewStoreInstr = Builder.CreateAlignedStore(IVec, AddrParts[Part],
- Group->getAlignment());
+  NewStoreInstr =
+  Builder.CreateAlignedStore(IVec, AddrParts[Part], Group->getAlign());
 
 Group->addMetadata(NewStoreInstr);
   }
@@ -2452,8 +2452,7 @@
   NewSI = Builder.CreateMaskedStore(StoredVal, VecPtr, Alignment,
 BlockInMaskParts[Part]);
 else
-  NewSI =
-  Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment.value());
+  NewSI = Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment);
   }
   addMetadata(NewSI, SI);
 }
Index: llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ -129,20 +129,19 @@
 private:
   unsigned getPointerAddressSpace(Value *I);
 
-  unsigned getAlignment(LoadInst *LI) const {
-unsigned Align = LI->getAlignment();
-if (Align != 0)
-  return Align;
+  /// TODO: Remove this function once transition to Align is over.
+  unsigned getAlignment(LoadInst *LI) const { return getAlign(LI).value(); }
 
-return DL.getABITypeAlignment(LI->getType());
+  Align getAlign(LoadInst *LI) const {
+return DL.getValueOrABITypeAlignment(LI->getAlign(), LI->getType());
   }
 
-  unsigned getAlignment(StoreInst *SI) const {
-unsigned Align = SI->getAlignment();
-if (Align

[clang] 49f7bc9 - [hip] Remove `-Werror=format-nonliteral`

2020-01-23 Thread Michael Liao via cfe-commits

Author: Michael Liao
Date: 2020-01-23T11:02:11-05:00
New Revision: 49f7bc9e1e50eb8f6e065f97585b3bf0bcc23d5c

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

LOG: [hip] Remove `-Werror=format-nonliteral`

Summary:
- It won't distinguish host and device code and trigger compilation
  failure on irrelevant code.

Reviewers: sameerds, yaxunl

Subscribers: cfe-commits

Tags: #clang

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

Added: 


Modified: 
clang/lib/Driver/ToolChains/HIP.cpp
clang/test/Driver/hip-printf.hip

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/HIP.cpp 
b/clang/lib/Driver/ToolChains/HIP.cpp
index 4772a6fb6b10..7039ddeabd57 100644
--- a/clang/lib/Driver/ToolChains/HIP.cpp
+++ b/clang/lib/Driver/ToolChains/HIP.cpp
@@ -425,7 +425,6 @@ Tool *HIPToolChain::buildLinker() const {
 
 void HIPToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
   HostTC.addClangWarningOptions(CC1Args);
-  CC1Args.push_back("-Werror=format-nonliteral");
 }
 
 ToolChain::CXXStdlibType

diff  --git a/clang/test/Driver/hip-printf.hip 
b/clang/test/Driver/hip-printf.hip
index 2df344f8fb2e..ada6c651ddb7 100644
--- a/clang/test/Driver/hip-printf.hip
+++ b/clang/test/Driver/hip-printf.hip
@@ -6,4 +6,4 @@
 // RUN:   %s 2>&1 | FileCheck %s
 
 // CHECK: [[CLANG:".*clang.*"]] "-cc1"
-// CHECK-SAME: "-Werror=format-nonliteral"
+// CHECK-NOT: "-Werror=format-nonliteral"



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


[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman added a comment.

In D72647#1833203 , @sammccall wrote:

> Let's make the minimal change here and land this.


Done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72647



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


[PATCH] D73224: [hip] Remove `-Werror=format-nonliteral`

2020-01-23 Thread Michael Liao via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG49f7bc9e1e50: [hip] Remove `-Werror=format-nonliteral` 
(authored by hliao).

Changed prior to commit:
  https://reviews.llvm.org/D73224?vs=239683&id=239910#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73224

Files:
  clang/lib/Driver/ToolChains/HIP.cpp
  clang/test/Driver/hip-printf.hip


Index: clang/test/Driver/hip-printf.hip
===
--- clang/test/Driver/hip-printf.hip
+++ clang/test/Driver/hip-printf.hip
@@ -6,4 +6,4 @@
 // RUN:   %s 2>&1 | FileCheck %s
 
 // CHECK: [[CLANG:".*clang.*"]] "-cc1"
-// CHECK-SAME: "-Werror=format-nonliteral"
+// CHECK-NOT: "-Werror=format-nonliteral"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -425,7 +425,6 @@
 
 void HIPToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
   HostTC.addClangWarningOptions(CC1Args);
-  CC1Args.push_back("-Werror=format-nonliteral");
 }
 
 ToolChain::CXXStdlibType


Index: clang/test/Driver/hip-printf.hip
===
--- clang/test/Driver/hip-printf.hip
+++ clang/test/Driver/hip-printf.hip
@@ -6,4 +6,4 @@
 // RUN:   %s 2>&1 | FileCheck %s
 
 // CHECK: [[CLANG:".*clang.*"]] "-cc1"
-// CHECK-SAME: "-Werror=format-nonliteral"
+// CHECK-NOT: "-Werror=format-nonliteral"
Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -425,7 +425,6 @@
 
 void HIPToolChain::addClangWarningOptions(ArgStringList &CC1Args) const {
   HostTC.addClangWarningOptions(CC1Args);
-  CC1Args.push_back("-Werror=format-nonliteral");
 }
 
 ToolChain::CXXStdlibType
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72647: [clangd] Only re-open files if their flags changed

2020-01-23 Thread David Goldman via Phabricator via cfe-commits
dgoldman updated this revision to Diff 239907.
dgoldman added a comment.

- Swap to stringset and simpler way of tracking modified files


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72647

Files:
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/test/did-change-configuration-params.test


Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -46,8 +46,6 @@
 # ERR: Updating file {{.*}}foo.c with command
 # ERR: [{{.*}}clangd-test2]
 # ERR: clang -c foo.c -Wall -Werror
-# Don't reparse the second file:
-# ERR: Skipping rebuild of the AST for {{.*}}bar.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -20,6 +20,7 @@
 #include "Transport.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringSet.h"
 #include 
 
 namespace clang {
@@ -122,10 +123,10 @@
   /// produce '->' and '::', respectively.
   bool shouldRunCompletion(const CompletionParams &Params) const;
 
-  /// Forces a reparse of all currently opened files.  As a result, this method
-  /// may be very expensive.  This method is normally called when the
-  /// compilation database is changed.
-  void reparseOpenedFiles();
+  /// Forces a reparse of all currently opened files which were modified. As a
+  /// result, this method may be very expensive. This method is normally called
+  /// when the compilation database is changed.
+  void reparseOpenedFiles(const llvm::StringSet<> &ModifiedFiles);
   void applyConfiguration(const ConfigurationSettings &Settings);
 
   /// Sends a "publishSemanticHighlighting" notification to the LSP client.
Index: clang-tools-extra/clangd/ClangdLSPServer.cpp
===
--- clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -1122,10 +1122,8 @@
 void ClangdLSPServer::applyConfiguration(
 const ConfigurationSettings &Settings) {
   // Per-file update to the compilation database.
-  bool ShouldReparseOpenFiles = false;
+  llvm::StringSet<> ModifiedFiles;
   for (auto &Entry : Settings.compilationDatabaseChanges) {
-/// The opened files need to be reparsed only when some existing
-/// entries are changed.
 PathRef File = Entry.first;
 auto Old = CDB->getCompileCommand(File);
 auto New =
@@ -1134,11 +1132,11 @@
 /*Output=*/"");
 if (Old != New) {
   CDB->setCompileCommand(File, std::move(New));
-  ShouldReparseOpenFiles = true;
+  ModifiedFiles.insert(File);
 }
   }
-  if (ShouldReparseOpenFiles)
-reparseOpenedFiles();
+
+  reparseOpenedFiles(ModifiedFiles);
 }
 
 void ClangdLSPServer::publishSemanticHighlighting(
@@ -1391,10 +1389,15 @@
   notify("textDocument/clangd.fileStatus", Status.render(File));
 }
 
-void ClangdLSPServer::reparseOpenedFiles() {
+void ClangdLSPServer::reparseOpenedFiles(
+const llvm::StringSet<> &ModifiedFiles) {
+  if (ModifiedFiles.empty())
+return;
+  // Reparse only opened files that were modified.
   for (const Path &FilePath : DraftMgr.getActiveFiles())
-Server->addDocument(FilePath, *DraftMgr.getDraft(FilePath),
-WantDiagnostics::Auto);
+if (ModifiedFiles.find(FilePath) != ModifiedFiles.end())
+  Server->addDocument(FilePath, *DraftMgr.getDraft(FilePath),
+  WantDiagnostics::Auto);
 }
 
 } // namespace clangd


Index: clang-tools-extra/clangd/test/did-change-configuration-params.test
===
--- clang-tools-extra/clangd/test/did-change-configuration-params.test
+++ clang-tools-extra/clangd/test/did-change-configuration-params.test
@@ -46,8 +46,6 @@
 # ERR: Updating file {{.*}}foo.c with command
 # ERR: [{{.*}}clangd-test2]
 # ERR: clang -c foo.c -Wall -Werror
-# Don't reparse the second file:
-# ERR: Skipping rebuild of the AST for {{.*}}bar.c
 ---
 {"jsonrpc":"2.0","id":5,"method":"shutdown"}
 ---
Index: clang-tools-extra/clangd/ClangdLSPServer.h
===
--- clang-tools-extra/clangd/ClangdLSPServer.h
+++ clang-tools-extra/clangd/ClangdLSPServer.h
@@ -20,6 +20,7 @@
 #include "Transport.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringSet.h"
 #include 
 
 namespace clang {
@@ -122,10 +123,10 @@
   /// produce '->' and '::', res

[clang] f3c508f - [OPENMP]Fix use of local allocators in allocate clauses.

2020-01-23 Thread Alexey Bataev via cfe-commits

Author: Alexey Bataev
Date: 2020-01-23T11:04:14-05:00
New Revision: f3c508fe91606c7383c812838b07ed5433a00dcf

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

LOG: [OPENMP]Fix use of local allocators in allocate clauses.

If local allocator was declared and used in the allocate clause, it was
not captured in inner region. It leads to a compiler crash, need to
capture the allocator declarator.

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/parallel_master_codegen.cpp
clang/test/OpenMP/teams_distribute_ast_print.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 72afe63749ac..64e7b9dcd2d4 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -156,6 +156,7 @@ class DSAStackTy {
 /// Reference to the taskgroup task_reduction reference expression.
 Expr *TaskgroupReductionRef = nullptr;
 llvm::DenseSet MappedClassesQualTypes;
+SmallVector InnerUsedAllocators;
 /// List of globals marked as declare target link in this target region
 /// (isOpenMPTargetExecutionDirective(Directive) == true).
 llvm::SmallVector DeclareTargetLinkVarDecls;
@@ -900,6 +901,15 @@ class DSAStackTy {
"Expected target executable directive.");
 return getTopOfStack().DeclareTargetLinkVarDecls;
   }
+
+  /// Adds list of allocators expressions.
+  void addInnerAllocatorExpr(Expr *E) {
+getTopOfStack().InnerUsedAllocators.push_back(E);
+  }
+  /// Return list of used allocators.
+  ArrayRef getInnerAllocators() const {
+return getTopOfStack().InnerUsedAllocators;
+  }
 };
 
 bool isImplicitTaskingRegion(OpenMPDirectiveKind DKind) {
@@ -3917,6 +3927,9 @@ StmtResult Sema::ActOnOpenMPRegionEnd(StmtResult S,
 else if (Clause->getClauseKind() == OMPC_linear)
   LCs.push_back(cast(Clause));
   }
+  // Capture allocator expressions if used.
+  for (Expr *E : DSAStack->getInnerAllocators())
+MarkDeclarationsReferencedInExpr(E);
   // OpenMP, 2.7.1 Loop Construct, Restrictions
   // The nonmonotonic modifier cannot be specified if an ordered clause is
   // specified.
@@ -17268,6 +17281,8 @@ OMPClause *Sema::ActOnOpenMPAllocateClause(
   if (Vars.empty())
 return nullptr;
 
+  if (Allocator)
+DSAStack->addInnerAllocatorExpr(Allocator);
   return OMPAllocateClause::Create(Context, StartLoc, LParenLoc, Allocator,
ColonLoc, EndLoc, Vars);
 }

diff  --git a/clang/test/OpenMP/parallel_master_codegen.cpp 
b/clang/test/OpenMP/parallel_master_codegen.cpp
index ad697ee8d5b6..db799f55d13f 100644
--- a/clang/test/OpenMP/parallel_master_codegen.cpp
+++ b/clang/test/OpenMP/parallel_master_codegen.cpp
@@ -433,38 +433,61 @@ int main() {
 
 #endif
 #ifdef CK9
+///==///
+// RUN: %clang_cc1 -DCK9 -verify -fopenmp -x c++ -triple 
x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | 
FileCheck %s --check-prefix CK9
+// RUN: %clang_cc1 -DCK9 -fopenmp -x c++ -std=c++11 -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -DCK9 -fopenmp -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck %s --check-prefix CK9
+
+// RUN: %clang_cc1 -DCK9 -verify -fopenmp-simd -x c++ -triple 
x86_64-unknown-unknown -emit-llvm %s -fexceptions -fcxx-exceptions -o - | 
FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -DCK9 -fopenmp-simd -x c++ -std=c++11 -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
+// RUN: %clang_cc1 -DCK9 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 // CK9-DAG: %struct.ident_t = type { i32, i32, i32, i32, i8* }
 // CK9-DAG: [[STR:@.+]] = private unnamed_addr constant [23 x i8] 
c";unknown;unknown;0;0;;\00"
 // CK9-DAG: [[DEF_LOC:@.+]] = private unnamed_addr global %struct.ident_t { 
i32 0, i32 2, i32 0, i32 0, i8* getelementptr inbounds ([23 x i8], [23 x i8]* 
[[STR]], i32 0, i32 0) }
+typedef void **omp_allocator_handle_t;
+extern const omp_allocator_handle_t omp_default_mem_alloc;
+extern const omp_allocator_handle_t omp_large_cap_mem_alloc;
+extern const omp_allocator_handle_t omp_const_mem_alloc;
+extern const omp_allocator_handle_t omp_high_bw_mem_alloc;
+extern const omp_allocator_handle_t omp_low_lat_mem_alloc;
+extern const omp_allocator_handle_t omp_cgroup_mem_alloc;
+extern const omp_allocator_handle_t omp_pteam_mem_alloc;
+extern const omp_allocator_handle_t omp_thread_mem_alloc;
 
 void p

[PATCH] D73270: [clang-tidy] Fix false positive in bugprone-infinite-loop

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



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:132
   }
+
   return false;

Don't change formatting of code this patch doesn't need to touch



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:153
   }
+
   return Result;

likewise



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:197
+std::string AdditionalVarNames = getCondVarNames(Init);
+if (!AdditionalVarNames.empty()) {
+  CondVarNames += ", " + AdditionalVarNames;

elide braces


Repository:
  rCTE Clang Tools Extra

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

https://reviews.llvm.org/D73270



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


[PATCH] D73186: [AST] Add fixed-point multiplication constant evaluation.

2020-01-23 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added inline comments.



Comment at: clang/lib/Basic/FixedPoint.cpp:242
+  } else
+Overflowed = Result < Min || Result > Max;
+

ebevhan wrote:
> rjmccall wrote:
> > If the maximum expressible value is *k*, and the fully-precise 
> > multiplication yields *k+e* for some epsilon *e* that isn't representable 
> > in the result semantics, is that considered an overflow?  If so, I think 
> > you need to do the shift after these bound checks, since the shift destroys 
> > the difference between *k* and *k+e*.  That is, unless there's a compelling 
> > mathematical argument that it's not possible to overflow only in the 
> > fully-precision multiplication — but while I think that's possibly true of 
> > `_Fract` (since *k^2 < k*), it seems unlikely to be true of `_Accum`, 
> > although I haven't looked for a counter-example.  And if there is a 
> > compelling argument, it should probably be at least alluded to in a comment.
> > 
> > Would this algorithm be simpler if you took advantage of the fact that 
> > `APFixedPointSemantics` doesn't have to correspond to a real type?  You 
> > could probably just convert to a double-width common semantics, right?
> > If the maximum expressible value is *k*, and the fully-precise 
> > multiplication yields *k+e* for some epsilon *e* that isn't representable 
> > in the result semantics, is that considered an overflow? If so, I think you 
> > need to do the shift after these bound checks, since the shift destroys the 
> > difference between *k* and *k+e*.
> 
> I don't think I would consider that to be overflow; that's precision loss. 
> E-C considers these to be different:
> 
> > If the source value cannot be represented exactly by the fixed-point type, 
> > the source value is rounded to either the closest fixed-point value greater 
> > than the source value (rounded up) or to the closest fixed-point value less 
> > than the source value (rounded down).
> >
> > When the source value does not fit within the range of the fixed-point 
> > type, the conversion overflows. [...]
> >
> > [...]
> >
> > If the result type of an arithmetic operation is a fixed-point type, [...] 
> > the calculated result is the mathematically exact result with overflow 
> > handling and rounding performed to the full precision of the result type as 
> > explained in 4.1.3. 
> 
> There is also no value of `e` that would affect saturation. Any full 
> precision calculation that gives `k+e` must be `k` after downscaling, since 
> the bits that represent `e` must come from the extra precision range. Even 
> though `k+e` is technically larger than `k`, saturation would still just give 
> us `k` after truncating out `e`, so the end result is the same.
> 
> > Would this algorithm be simpler if you took advantage of the fact that 
> > APFixedPointSemantics doesn't have to correspond to a real type? You could 
> > probably just convert to a double-width common semantics, right?
> 
> It's likely possible to use APFixedPoint in the calculations here, but I used 
> APInt to make the behavior explicit and not accidentally be dependent on the 
> behavior of APFixedPoint's conversions or operations.
Although.,. I guess I see your point in that an intermediate result of k+e 
technically "does not fit within the range of the fixed-point type"... but I 
wonder if treating such cases as overflow is particularly meaningful. I don't 
find there to be much of a distinction between such a case and the case where 
the exact result lands inbetween two representable values. We just end up with 
a less precise result.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73186



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


[PATCH] D71566: New checks for fortified sprintf

2020-01-23 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 239913.
serge-sans-paille added a comment.

Remove extra new lines.
Add more test cases.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71566

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/warn-fortify-source.c

Index: clang/test/Sema/warn-fortify-source.c
===
--- clang/test/Sema/warn-fortify-source.c
+++ clang/test/Sema/warn-fortify-source.c
@@ -11,6 +11,8 @@
 extern "C" {
 #endif
 
+extern int sprintf(char *str, const char *format, ...);
+
 #if defined(USE_PASS_OBJECT_SIZE)
 void *memcpy(void *dst, const void *src, size_t c);
 static void *memcpy(void *dst __attribute__((pass_object_size(1))), const void *src, size_t c) __attribute__((overloadable)) __asm__("merp");
@@ -96,6 +98,91 @@
   __builtin_vsnprintf(buf, 11, "merp", list); // expected-warning {{'vsnprintf' size argument is too large; destination buffer has size 10, but size argument is 11}}
 }
 
+void call_sprintf_chk(char *buf) {
+  __builtin___sprintf_chk(buf, 1, 6, "hell\n");
+  __builtin___sprintf_chk(buf, 1, 5, "hell\n"); // expected-warning {{'sprintf' will always overflow; destination buffer has size 5, but format string expands to at least 6}}
+  __builtin___sprintf_chk(buf, 1, 6, "hell\0 boy"); // expected-warning {{format string contains '\0' within the string body}}
+  __builtin___sprintf_chk(buf, 1, 2, "hell\0 boy"); // expected-warning {{format string contains '\0' within the string body}}
+  // expected-warning@-1 {{'sprintf' will always overflow; destination buffer has size 2, but format string expands to at least 5}}
+  __builtin___sprintf_chk(buf, 1, 6, "hello");
+  __builtin___sprintf_chk(buf, 1, 5, "hello"); // expected-warning {{'sprintf' will always overflow; destination buffer has size 5, but format string expands to at least 6}}
+  __builtin___sprintf_chk(buf, 1, 2, "%c", '9');
+  __builtin___sprintf_chk(buf, 1, 1, "%c", '9'); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%d", 9);
+  __builtin___sprintf_chk(buf, 1, 1, "%d", 9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%i", 9);
+  __builtin___sprintf_chk(buf, 1, 1, "%i", 9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%o", 9);
+  __builtin___sprintf_chk(buf, 1, 1, "%o", 9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%u", 9);
+  __builtin___sprintf_chk(buf, 1, 1, "%u", 9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%x", 9);
+  __builtin___sprintf_chk(buf, 1, 1, "%x", 9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%X", 9);
+  __builtin___sprintf_chk(buf, 1, 1, "%X", 9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%hhd", (char)9);
+  __builtin___sprintf_chk(buf, 1, 1, "%hhd", (char)9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%hd", (short)9);
+  __builtin___sprintf_chk(buf, 1, 1, "%hd", (short)9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%ld", 9l);
+  __builtin___sprintf_chk(buf, 1, 1, "%ld", 9l); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%lld", 9ll);
+  __builtin___sprintf_chk(buf, 1, 1, "%lld", 9ll); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 2, "%%");
+  __builtin___sprintf_chk(buf, 1, 1, "%%"); // expected-warning {{'sprintf' will always overflow; destination buffer has size 1, but format string expands to at least 2}}
+  __builtin___sprintf_chk(buf, 1, 4, "%#x", 9);
+  __builtin___sprintf_chk(buf, 1, 3, "%#x", 9); // expected-warning {{'sprintf' will always overflow; destination buffer has size 3, but format string expands to at least 4}}
+  __builtin___sprintf_chk(buf, 1, 4, "%p", (void *)9

[clang] 59f9522 - [Alignment][NFC] Use Align with CreateAlignedStore

2020-01-23 Thread Guillaume Chatelet via cfe-commits

Author: Guillaume Chatelet
Date: 2020-01-23T17:34:32+01:00
New Revision: 59f95222d4c5e997342b0514984823a99a16d44b

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

LOG: [Alignment][NFC] Use Align with CreateAlignedStore

Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: 
http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: courbet, bollu

Subscribers: arsenm, jvesely, nhaehnle, hiraditya, kerbowa, cfe-commits, 
llvm-commits

Tags: #clang, #llvm

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

Added: 


Modified: 
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBuilder.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGGPUBuiltin.cpp
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/CodeGen/TargetInfo.cpp
llvm/include/llvm/IR/DataLayout.h
llvm/include/llvm/IR/GlobalObject.h
llvm/include/llvm/IR/IRBuilder.h
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/lib/IR/DataLayout.cpp
llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
llvm/lib/Target/X86/X86InterleavedAccess.cpp
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/lib/Transforms/Scalar/Scalarizer.cpp
llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
polly/lib/CodeGen/BlockGenerators.cpp
polly/lib/CodeGen/LoopGeneratorsKMP.cpp
polly/lib/CodeGen/RuntimeDebugBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 11f54d1f7fb2..33fad77eb4da 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1449,7 +1449,8 @@ static llvm::Constant *buildGlobalBlock(CodeGenModule 
&CGM,
 llvm::IRBuilder<> b(llvm::BasicBlock::Create(CGM.getLLVMContext(), "entry",
   Init));
 b.CreateAlignedStore(CGM.getNSConcreteGlobalBlock(),
-b.CreateStructGEP(literal, 0), CGM.getPointerAlign().getQuantity());
+ b.CreateStructGEP(literal, 0),
+ CGM.getPointerAlign().getAsAlign());
 b.CreateRetVoid();
 // We can't use the normal LLVM global initialisation array, because we
 // need to specify that this runs early in library initialisation.

diff  --git a/clang/lib/CodeGen/CGBuilder.h b/clang/lib/CodeGen/CGBuilder.h
index 107c9275431c..049e1d4b7552 100644
--- a/clang/lib/CodeGen/CGBuilder.h
+++ b/clang/lib/CodeGen/CGBuilder.h
@@ -113,7 +113,7 @@ class CGBuilderTy : public CGBuilderBaseTy {
   using CGBuilderBaseTy::CreateAlignedStore;
   llvm::StoreInst *CreateAlignedStore(llvm::Value *Val, llvm::Value *Addr,
   CharUnits Align, bool IsVolatile = 
false) {
-return CreateAlignedStore(Val, Addr, Align.getQuantity(), IsVolatile);
+return CreateAlignedStore(Val, Addr, Align.getAsAlign(), IsVolatile);
   }
 
   // FIXME: these "default-aligned" APIs should be removed,

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 86a3f1e0d237..04511e892adf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3930,7 +3930,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 auto *V =
 Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(I)), SizeTy);
 Builder.CreateAlignedStore(
-V, GEP, CGM.getDataLayout().getPrefTypeAlignment(SizeTy));
+V, GEP, CGM.getDataLayout().getPrefTypeAlign(SizeTy));
   }
   return std::tie(ElemPtr, TmpSize, TmpPtr);
 };

diff  --git a/clang/lib/CodeGen/CGGPUBuiltin.cpp 
b/clang/lib/CodeGen/CGGPUBuiltin.cpp
index bccce7dd7ff4..f860623e2bc3 100644
--- a/clang/lib/CodeGen/CGGPUBuiltin.cpp
+++ b/clang/lib/CodeGen/CGGPUBuiltin.cpp
@@ -111,7 +111,7 @@ CodeGenFunction::EmitNVPTXDevicePrintfCallExpr(const 
CallExpr *E,
 for (unsigned I = 1, NumArgs = Args.size(); I < NumArgs; ++I) {
   llvm::Value *P = Builder.CreateStructGEP(AllocaTy, Alloca, I - 1);
   llvm::Value *Arg = Args[I].getRValue(*this).getScalarVal();
-  Builder.CreateAlignedStore(Arg, P, 
DL.getPrefTypeAlignment(Arg->getType()));
+  Builder.CreateAlignedStore(Arg, P, DL.getPrefTypeAlign(Arg->getType()));
 

[PATCH] D73229: [analyzer] Improve FuchsiaHandleChecker's diagnostic messages

2020-01-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ accepted this revision.
NoQ added a comment.
This revision is now accepted and ready to land.

Nice! These are indeed useful when multiple things can happen. You may also 
consider adding stack hints a-la `MallocChecker` (i.e., "Returning; handle was 
closed").




Comment at: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp:322
 
   // Function returns an open handle.
   if (hasFuchsiaAttr(FuncDecl)) {

I think this commend would have actually made a better note text. Maybe mention 
the function name as well, "Function foo() returns an open handle".



Comment at: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp:359
+llvm::raw_string_ostream OS(SBuf);
+OS << "Handle released at " << ParamDiagIdx
+   << llvm::getOrdinalSuffix(ParamDiagIdx) << " parameter.";

I think we often use "through" in this context. I.e., "Handle released through 
2nd parameter".



Comment at: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp:363
   } else
-return "";
+return std::string{};
 });

What was wrong with good old `""`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73229



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


[PATCH] D73274: [Alignment][NFC] Use Align with CreateAlignedStore

2020-01-23 Thread Guillaume Chatelet via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG59f95222d4c5: [Alignment][NFC] Use Align with 
CreateAlignedStore (authored by gchatelet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73274

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/lib/CodeGen/CGBuilder.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGGPUBuiltin.cpp
  clang/lib/CodeGen/CGObjCGNU.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  llvm/include/llvm/IR/DataLayout.h
  llvm/include/llvm/IR/GlobalObject.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/ScalarizeMaskedMemIntrin.cpp
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/Target/AMDGPU/AMDGPURewriteOutArguments.cpp
  llvm/lib/Target/X86/X86InterleavedAccess.cpp
  llvm/lib/Transforms/IPO/LowerTypeTests.cpp
  llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
  llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
  llvm/lib/Transforms/Scalar/LowerMatrixIntrinsics.cpp
  llvm/lib/Transforms/Scalar/SROA.cpp
  llvm/lib/Transforms/Scalar/Scalarizer.cpp
  llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  polly/lib/CodeGen/BlockGenerators.cpp
  polly/lib/CodeGen/LoopGeneratorsKMP.cpp
  polly/lib/CodeGen/RuntimeDebugBuilder.cpp

Index: polly/lib/CodeGen/RuntimeDebugBuilder.cpp
===
--- polly/lib/CodeGen/RuntimeDebugBuilder.cpp
+++ polly/lib/CodeGen/RuntimeDebugBuilder.cpp
@@ -221,7 +221,7 @@
 
 Ty = Val->getType();
 Ptr = Builder.CreatePointerBitCastOrAddrSpaceCast(Ptr, Ty->getPointerTo(5));
-Builder.CreateAlignedStore(Val, Ptr, 4);
+Builder.CreateAlignedStore(Val, Ptr, Align(4));
 
 if (Ty->isFloatingPointTy())
   str += "%f";
Index: polly/lib/CodeGen/LoopGeneratorsKMP.cpp
===
--- polly/lib/CodeGen/LoopGeneratorsKMP.cpp
+++ polly/lib/CodeGen/LoopGeneratorsKMP.cpp
@@ -176,7 +176,7 @@
   extractValuesFromStruct(Data, StructData->getAllocatedType(), UserContext,
   Map);
 
-  const int Alignment = (is64BitArch()) ? 8 : 4;
+  const auto Alignment = llvm::Align(is64BitArch() ? 8 : 4);
   Value *ID =
   Builder.CreateAlignedLoad(IDPtr, Alignment, "polly.par.global_tid");
 
Index: polly/lib/CodeGen/BlockGenerators.cpp
===
--- polly/lib/CodeGen/BlockGenerators.cpp
+++ polly/lib/CodeGen/BlockGenerators.cpp
@@ -343,7 +343,7 @@
   RuntimeDebugBuilder::createCPUPrinter(Builder, "Store to  ", NewPointer,
 ": ", ValueOperand, "\n");
 
-Builder.CreateAlignedStore(ValueOperand, NewPointer, Store->getAlignment());
+Builder.CreateAlignedStore(ValueOperand, NewPointer, Store->getAlign());
   });
 }
 
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2346,8 +2346,8 @@
   IVec, AddrParts[Part], Group->getAlign(), ShuffledMask);
 }
 else
-  NewStoreInstr = Builder.CreateAlignedStore(IVec, AddrParts[Part],
- Group->getAlignment());
+  NewStoreInstr =
+  Builder.CreateAlignedStore(IVec, AddrParts[Part], Group->getAlign());
 
 Group->addMetadata(NewStoreInstr);
   }
@@ -2452,8 +2452,7 @@
   NewSI = Builder.CreateMaskedStore(StoredVal, VecPtr, Alignment,
 BlockInMaskParts[Part]);
 else
-  NewSI =
-  Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment.value());
+  NewSI = Builder.CreateAlignedStore(StoredVal, VecPtr, Alignment);
   }
   addMetadata(NewSI, SI);
 }
Index: llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ -129,20 +129,19 @@
 private:
   unsigned getPointerAddressSpace(Value *I);
 
-  unsigned getAlignment(LoadInst *LI) const {
-unsigned Align = LI->getAlignment();
-if (Align != 0)
-  return Align;
+  /// TODO: Remove this function once transition to Align is over.
+  unsigned getAlignment(LoadInst *LI) const { return getAlign(LI).value(); }
 
-return DL.getABITypeAlignment(LI->getType());
+  Align getAlign(LoadInst *LI) const {
+return DL.getValueOrABITypeAlignment(LI->getAlign(), LI->getType());
   }
 
-  unsigned getAlignment(StoreInst *SI) const {
-unsigne

[PATCH] D72467: Remove "mask" operand from shufflevector.

2020-01-23 Thread Christopher Tetreault via Phabricator via cfe-commits
ctetreau added inline comments.



Comment at: llvm/include/llvm/IR/IRBuilder.h:2544
+SmallVector IntMask;
+ShuffleVectorInst::getShuffleMask(cast(Mask), IntMask);
+return CreateShuffleVector(V1, V2, IntMask, Name);

spatel wrote:
> Add an assert that Mask isa ?
cast already does this assert.



Comment at: llvm/include/llvm/IR/IRBuilder.h:2551
+SmallVector IntMask;
+IntMask.assign(Mask.begin(), Mask.end());
+return CreateShuffleVector(V1, V2, IntMask, Name);

[0 .. uint32_MAX] is wider than [0 .. int_MAX]. Assert the values are in range 
somehow?



Comment at: llvm/include/llvm/IR/Instructions.h:1985-1986
 ///
+/// The shuffle mask operand specifies, for each element of the result vector,
+/// which element of the two input vectors the result element gets. The
+/// shuffle mask is represented as an array of integers. Positive integers

spatel wrote:
> This reads awkwardly to me (if you agree, we can update the LangRef too). 
> How about:
> "For each element of the result vector, the shuffle mask selects an element 
> from one of the input vectors to copy to the result. Non-negative elements in 
> the mask represent an index into the concatenated pair of input vectors. 
> UndefMaskElem (-1) specifies that the result element is undefined."
I also found the wording of the description of shufflevector in the language 
ref confusing. Since this description seems to be related I thought it worth 
mentioning.

It's unclear to me how the values specify vector inputs. I assume for two 
vectors <4 x 18>, that the mask <3, 4, 5, 6> takes the last element of the 
first vector, and the first three elements of the second vector, but this isn't 
explicitly stated anywhere.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72467



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


[PATCH] D71566: New checks for fortified sprintf

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

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

{icon check-circle color=green} clang-tidy: pass.

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

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


//Pre-merge checks is in beta. Report issue 
.
 Please join beta  or enable 
it for your project 
.//


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71566



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


[PATCH] D73229: [analyzer] Improve FuchsiaHandleChecker's diagnostic messages

2020-01-23 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun marked an inline comment as done.
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp:363
   } else
-return "";
+return std::string{};
 });

NoQ wrote:
> What was wrong with good old `""`?
I had two returns with different types so I either need to specify the return 
type of the lambda explicitly or make the two returns return the same type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73229



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


[PATCH] D73229: [analyzer] Improve FuchsiaHandleChecker's diagnostic messages

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



Comment at: clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp:363
   } else
-return "";
+return std::string{};
 });

xazax.hun wrote:
> NoQ wrote:
> > What was wrong with good old `""`?
> I had two returns with different types so I either need to specify the return 
> type of the lambda explicitly or make the two returns return the same type.
Oh, right.

I think i specified the return type explicitly in most places but that's not a 
must.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D73229



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


[PATCH] D72222: [Driver][CodeGen] Add -fpatchable-function-entry=N[,0]

2020-01-23 Thread Peter Smith via Phabricator via cfe-commits
peter.smith added a comment.

Although this particular commit will not be at fault, it is the option that 
enables the feature which is the earliest I can bisect the fault to. There are 
3 files in linux that assert fail on the Implement the 'patchable-function 
attribute'. The files in question are kasan/quarantine.c, mm/slab_common.c and 
mm/slub.c .

I reproduced with

  make CC=/path/to/clang/install/clang ARCH=arm64 
CROSS_COMPILE=aarch64-linux-gnu- HOSTGCC=gcc allmodconfig

You can get the log files for the build, which is from clang-10
https://git.linaro.org/toolchain/ci/base-artifacts.git/log/?h=linaro-local/ci/tcwg_kernel/llvm-release-aarch64-mainline-allmodconfig
 (4: update: llvm-linux: 19676)

If the patchable functions is intended for clang-10 we'll need to make sure any 
fix is merged to clang-10.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D7



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


[PATCH] D72982: [Clang] Un-break scan-build after integrated-cc1 change

2020-01-23 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

Thank you everybody for unbreaking us! 🙏


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D72982



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


  1   2   3   >