[PATCH] D103040: Print default template argument if manually specified in typedef declaration.

2021-06-30 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/test/SemaTemplate/class-template-id.cpp:12-14
+return ptr2; // expected-error{{cannot initialize return object of type 
'A *' (aka 'A *') with an lvalue of type 'const A 
*'}}
   else {
+return ptr3; // expected-error{{cannot initialize return object of type 
'A *' (aka 'A *') with an lvalue of type 'A *'}}

FWIW, looks like this was a reduction in quality - printing the value of the 
default argument in these error messages, when omitting it was probably 
desirable?

& doesn't seem to be a necessary consequence of the patch description's goals.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103040

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


[PATCH] D105017: [analyzer] LValueToRValueBitCasts should evaluate to an r-value

2021-06-30 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D105017#2848465 , @NoQ wrote:

> So it worked out of the box? Great!

Yes, it did.


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

https://reviews.llvm.org/D105017

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


[PATCH] D103797: [clang] Use resolved path for headers in decluse diagnostics

2021-06-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

We discussed this a bit offline, and IIUC the plan is not to push this through 
at least for now. Notes:

- path to a file is more accurate/informative than spelling, since it really is 
the file rather than the name that is restricted
- however in practice the spelling probably isn't ambiguous and is more 
readable, so this is probably a regression overall for display
- our motivation here is to be able to unambiguously extract the path 
programmatically.
  - Adding a `struct { string; FileEntry*; }` as a diagnostic argument kind is 
another (somewhat intrusive) way out.
  - The (private) codebase we're experimenting on expresses most `#include`s 
relative to a single root, so we can probably just live without this at least 
for a while
- If we do this getName() is probably indeed better than tryGetRealPathName, 
resolving symlinks may have some bad effects


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103797

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


[PATCH] D104616: [analyzer] Model comparision methods of std::unique_ptr

2021-06-30 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD updated this revision to Diff 355458.
RedDocMD added a comment.

Refactored out common block


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104616

Files:
  clang/lib/StaticAnalyzer/Checkers/SmartPtr.h
  clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  clang/test/Analysis/Inputs/system-header-simulator-cxx.h
  clang/test/Analysis/smart-ptr.cpp

Index: clang/test/Analysis/smart-ptr.cpp
===
--- clang/test/Analysis/smart-ptr.cpp
+++ clang/test/Analysis/smart-ptr.cpp
@@ -457,3 +457,32 @@
 P->foo(); // expected-warning {{Dereference of null smart pointer 'P' [alpha.cplusplus.SmartPtr]}}
   }
 }
+
+// The following is a silly function,
+// but serves to test if we are picking out
+// standard comparision functions from custom ones.
+template 
+bool operator<(std::unique_ptr &x, double d);
+
+void uniquePtrComparision(std::unique_ptr unknownPtr) {
+  auto ptr = std::unique_ptr(new int(13));
+  auto nullPtr = std::unique_ptr();
+  auto otherPtr = std::unique_ptr(new int(29));
+
+  clang_analyzer_eval(ptr == ptr); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr > ptr);  // expected-warning{{FALSE}}
+  clang_analyzer_eval(ptr <= ptr); // expected-warning{{TRUE}}
+
+  clang_analyzer_eval(nullPtr <= unknownPtr); // expected-warning{{TRUE}}
+  clang_analyzer_eval(unknownPtr >= nullPtr); // expected-warning{{TRUE}}
+
+  clang_analyzer_eval(ptr != otherPtr); // expected-warning{{TRUE}}
+  clang_analyzer_eval(ptr > nullPtr);   // expected-warning{{TRUE}}
+
+  clang_analyzer_eval(ptr != nullptr);// expected-warning{{TRUE}}
+  clang_analyzer_eval(nullPtr != nullptr);// expected-warning{{FALSE}}
+  clang_analyzer_eval(nullptr <= unknownPtr); // expected-warning{{TRUE}}
+  clang_analyzer_eval(nullptr < unknownPtr);  // expected-warning{{UNKNOWN}}
+
+  clang_analyzer_eval(ptr < 2.0); // expected-warning{{UNKNOWN}}
+}
Index: clang/test/Analysis/Inputs/system-header-simulator-cxx.h
===
--- clang/test/Analysis/Inputs/system-header-simulator-cxx.h
+++ clang/test/Analysis/Inputs/system-header-simulator-cxx.h
@@ -978,6 +978,61 @@
 void swap(unique_ptr &x, unique_ptr &y) noexcept {
   x.swap(y);
 }
+
+template 
+bool operator==(const unique_ptr &x, const unique_ptr &y);
+
+template 
+bool operator!=(const unique_ptr &x, const unique_ptr &y);
+
+template 
+bool operator<(const unique_ptr &x, const unique_ptr &y);
+
+template 
+bool operator>(const unique_ptr &x, const unique_ptr &y);
+
+template 
+bool operator<=(const unique_ptr &x, const unique_ptr &y);
+
+template 
+bool operator>=(const unique_ptr &x, const unique_ptr &y);
+
+template 
+bool operator==(const unique_ptr &x, nullptr_t y);
+
+template 
+bool operator!=(const unique_ptr &x, nullptr_t y);
+
+template 
+bool operator<(const unique_ptr &x, nullptr_t y);
+
+template 
+bool operator>(const unique_ptr &x, nullptr_t y);
+
+template 
+bool operator<=(const unique_ptr &x, nullptr_t y);
+
+template 
+bool operator>=(const unique_ptr &x, nullptr_t y);
+
+template 
+bool operator==(nullptr_t x, const unique_ptr &y);
+
+template 
+bool operator!=(nullptr_t x, const unique_ptr &y);
+
+template 
+bool operator>(nullptr_t x, const unique_ptr &y);
+
+template 
+bool operator<(nullptr_t x, const unique_ptr &y);
+
+template 
+bool operator>=(nullptr_t x, const unique_ptr &y);
+
+template 
+bool operator<=(nullptr_t x, const unique_ptr &y);
+
 } // namespace std
 #endif
 
Index: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
+++ clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
@@ -29,7 +29,10 @@
 #include "clang/StaticAnalyzer/Core/PathSensitive/SVals.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymExpr.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/ErrorHandling.h"
 #include 
+#include 
 
 using namespace clang;
 using namespace ento;
@@ -68,6 +71,10 @@
   bool updateMovedSmartPointers(CheckerContext &C, const MemRegion *ThisRegion,
 const MemRegion *OtherSmartPtrRegion) const;
   void handleBoolConversion(const CallEvent &Call, CheckerContext &C) const;
+  bool handleComparisionOp(const CallEvent &Call, CheckerContext &C) const;
+  std::pair
+  retrieveOrConjureInnerPtrVal(const MemRegion *ThisRegion, const Expr *E,
+   QualType Type, CheckerContext &C) const;
 
   using SmartPtrMethodHandlerFn =
   void (SmartPtrModeling::*)(const CallEvent &Call, CheckerContext &) const;
@@ -89,18 +96,24 @@
   const auto *MethodDecl = dyn_cast_or_null(Call.getDecl());
   if (!MethodDecl || !MethodDecl->getParent())
 return false;
+  return isStdSmartPtr(Met

[PATCH] D105168: [RISCV] Unify the arch string parsing logic to to RISCVArchStringParser.

2021-06-30 Thread Kito Cheng via Phabricator via cfe-commits
kito-cheng updated this revision to Diff 355459.
kito-cheng added a comment.

Minor clean up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105168

Files:
  clang/lib/Basic/Targets/RISCV.cpp
  clang/lib/Basic/Targets/RISCV.h
  clang/lib/Driver/ToolChains/Arch/RISCV.cpp
  clang/test/Driver/riscv-arch.c
  llvm/include/llvm/Support/RISCVISAInfo.h
  llvm/lib/Support/CMakeLists.txt
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
  llvm/test/MC/RISCV/attribute-arch.s
  llvm/test/MC/RISCV/attribute-with-insts.s
  llvm/test/MC/RISCV/invalid-attribute.s

Index: llvm/test/MC/RISCV/invalid-attribute.s
===
--- llvm/test/MC/RISCV/invalid-attribute.s
+++ llvm/test/MC/RISCV/invalid-attribute.s
@@ -7,10 +7,10 @@
 # RUN: not llvm-mc %s -triple=riscv64 -filetype=asm 2>&1 | FileCheck %s
 
 .attribute arch, "foo"
-# CHECK: [[@LINE-1]]:18: error: bad arch string foo
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'foo', string must begin with rv32{i,e,g} or rv64{i,g}
 
 .attribute arch, "rv32i2p0_y2p0"
-# CHECK: [[@LINE-1]]:18: error: bad arch string y2p0
+# CHECK: [[@LINE-1]]:18: error: invalid arch name 'rv32i2p0_y2p0', invalid standard user-level extension 'y'
 
 .attribute stack_align, "16"
 # CHECK: [[@LINE-1]]:25: error: expected numeric constant
Index: llvm/test/MC/RISCV/attribute-with-insts.s
===
--- llvm/test/MC/RISCV/attribute-with-insts.s
+++ llvm/test/MC/RISCV/attribute-with-insts.s
@@ -10,7 +10,7 @@
 # RUN:   | llvm-objdump --triple=riscv64 -d -M no-aliases - \
 # RUN:   | FileCheck -check-prefix=CHECK-INST %s
 
-.attribute arch, "rv64i2p0_m2p0_a2p0_d2p0_c2p0"
+.attribute arch, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 # CHECK-INST: lr.w t0, (t1)
 lr.w t0, (t1)
Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -9,9 +9,6 @@
 .attribute arch, "rv32i2"
 # CHECK: attribute  5, "rv32i2p0"
 
-.attribute arch, "rv32i2p"
-# CHECK: attribute  5, "rv32i2p0"
-
 .attribute arch, "rv32i2p0"
 # CHECK: attribute  5, "rv32i2p0"
 
@@ -33,14 +30,14 @@
 .attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
-.attribute arch, "rv32ima2p_fdc"
+.attribute arch, "rv32ima2p0_fdc"
 # CHECK: attribute  5, "rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0"
 
 .attribute arch, "rv32ib"
 # CHECK: attribute  5, "rv32i2p0_b0p93_zba0p93_zbb0p93_zbc0p93_zbe0p93_zbf0p93_zbm0p93_zbp0p93_zbr0p93_zbs0p93_zbt0p93"
 
 .attribute arch, "rv32iv"
-# CHECK: attribute  5, "rv32i2p0_v0p10"
+# CHECK: attribute  5, "rv32i2p0_v0p10_zvamo0p10_zvlsseg0p10"
 
 .attribute arch, "rv32izba"
 # CHECK: attribute  5, "rv32i2p0_zba0p93"
Index: llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
===
--- llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -35,6 +35,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/RISCVAttributes.h"
+#include "llvm/Support/RISCVISAInfo.h"
 #include "llvm/Support/TargetRegistry.h"
 
 #include 
@@ -50,6 +51,13 @@
 STATISTIC(RISCVNumInstrsCompressed,
   "Number of RISC-V Compressed instructions emitted");
 
+namespace llvm {
+extern const llvm::SubtargetFeatureKV RISCVFeatureKV[];
+}
+
+static ArrayRef RISCVFeatureTable =
+makeArrayRef(RISCVFeatureKV, RISCV::NumSubtargetFeatures);
+
 namespace {
 struct RISCVOperand;
 
@@ -2027,113 +2035,39 @@
 
   if (Tag == RISCVAttrs::ARCH) {
 StringRef Arch = StringValue;
-if (Arch.consume_front("rv32"))
+for (auto Feature : RISCVFeatureTable) {
+  if (llvm::RISCVISAInfo::isSupportedExtension(
+  Feature.Key, /* CheckExperimental */ true)) {
+clearFeatureBits(Feature.Value, Feature.Key);
+  }
+}
+
+llvm::RISCVISAInfo ISAInfo;
+if (auto E =
+ISAInfo.parse(StringValue, /* EnableExperimentalExtension */ true,
+  /* ExperimentalExtensionVersionCheck */ false)) {
+  std::string Buffer;
+  raw_string_ostream OutputErrMsg(Buffer);
+  handleAllErrors(std::move(E), [&](llvm::StringError &ErrMsg) {
+OutputErrMsg << "invalid arch name '" << Arch << "', "
+ << ErrMsg.getMessage();
+  });
+
+  return Error(ValueExprLoc, OutputErrMsg.str());
+}
+
+for (auto Feature : RISCVFeatureTable) {
+  if (ISAInfo.hasExtension(Feature.Key)) {
+setFeatureBits(Feature.Value, Feature.Key);
+  }
+}
+
+if (ISAInfo.getXLEN() == 32)
   clearFeatureBits(RISCV::Feature64Bit, "64bit");
-else if (Arch.consume_front("rv64"))
+else 

[PATCH] D105097: [clang][AArch64][SVE] Handle PRValue under VLAT <-> VLST cast

2021-06-30 Thread JunMa via Phabricator via cfe-commits
junparser updated this revision to Diff 355460.
junparser added a comment.

address comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105097

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-call.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c

Index: clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
===
--- clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
+++ clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
@@ -22,13 +22,13 @@
 // CHECK-128-LABEL: @write_global_i64(
 // CHECK-128-NEXT:  entry:
 // CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = call <2 x i64> @llvm.experimental.vector.extract.v2i64.nxv2i64( [[V:%.*]], i64 0)
-// CHECK-128-NEXT:store <2 x i64> [[CASTFIXEDSVE]], <2 x i64>* @global_i64, align 16, [[TBAA6:!tbaa !.*]]
+// CHECK-128-NEXT:store <2 x i64> [[CASTFIXEDSVE]], <2 x i64>* @global_i64, align 16, !tbaa [[TBAA6:![0-9]+]]
 // CHECK-128-NEXT:ret void
 //
 // CHECK-512-LABEL: @write_global_i64(
 // CHECK-512-NEXT:  entry:
 // CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = call <8 x i64> @llvm.experimental.vector.extract.v8i64.nxv2i64( [[V:%.*]], i64 0)
-// CHECK-512-NEXT:store <8 x i64> [[CASTFIXEDSVE]], <8 x i64>* @global_i64, align 16, [[TBAA6:!tbaa !.*]]
+// CHECK-512-NEXT:store <8 x i64> [[CASTFIXEDSVE]], <8 x i64>* @global_i64, align 16, !tbaa [[TBAA6:![0-9]+]]
 // CHECK-512-NEXT:ret void
 //
 void write_global_i64(svint64_t v) { global_i64 = v; }
@@ -36,33 +36,33 @@
 // CHECK-128-LABEL: @write_global_bf16(
 // CHECK-128-NEXT:  entry:
 // CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = call <8 x bfloat> @llvm.experimental.vector.extract.v8bf16.nxv8bf16( [[V:%.*]], i64 0)
-// CHECK-128-NEXT:store <8 x bfloat> [[CASTFIXEDSVE]], <8 x bfloat>* @global_bf16, align 16, [[TBAA6]]
+// CHECK-128-NEXT:store <8 x bfloat> [[CASTFIXEDSVE]], <8 x bfloat>* @global_bf16, align 16, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:ret void
 //
 // CHECK-512-LABEL: @write_global_bf16(
 // CHECK-512-NEXT:  entry:
 // CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = call <32 x bfloat> @llvm.experimental.vector.extract.v32bf16.nxv8bf16( [[V:%.*]], i64 0)
-// CHECK-512-NEXT:store <32 x bfloat> [[CASTFIXEDSVE]], <32 x bfloat>* @global_bf16, align 16, [[TBAA6]]
+// CHECK-512-NEXT:store <32 x bfloat> [[CASTFIXEDSVE]], <32 x bfloat>* @global_bf16, align 16, !tbaa [[TBAA6]]
 // CHECK-512-NEXT:ret void
 //
 void write_global_bf16(svbfloat16_t v) { global_bf16 = v; }
 
 // CHECK-128-LABEL: @write_global_bool(
 // CHECK-128-NEXT:  entry:
-// CHECK-128-NEXT:[[V_ADDR:%.*]] = alloca , align 16
-// CHECK-128-NEXT:store  [[V:%.*]], * [[V_ADDR]], align 16, [[TBAA9:!tbaa !.*]]
-// CHECK-128-NEXT:[[TMP0:%.*]] = bitcast * [[V_ADDR]] to <2 x i8>*
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <2 x i8>, <2 x i8>* [[TMP0]], align 16, [[TBAA6]]
-// CHECK-128-NEXT:store <2 x i8> [[TMP1]], <2 x i8>* @global_bool, align 2, [[TBAA6]]
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca , align 16
+// CHECK-128-NEXT:store  [[V:%.*]], * [[SAVED_VALUE]], align 16, !tbaa [[TBAA9:![0-9]+]]
+// CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = bitcast * [[SAVED_VALUE]] to <2 x i8>*
+// CHECK-128-NEXT:[[TMP0:%.*]] = load <2 x i8>, <2 x i8>* [[CASTFIXEDSVE]], align 16, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:store <2 x i8> [[TMP0]], <2 x i8>* @global_bool, align 2, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:ret void
 //
 // CHECK-512-LABEL: @write_global_bool(
 // CHECK-512-NEXT:  entry:
-// CHECK-512-NEXT:[[V_ADDR:%.*]] = alloca , align 16
-// CHECK-512-NEXT:store  [[V:%.*]], * [[V_ADDR]], align 16, [[TBAA9:!tbaa !.*]]
-// CHECK-512-NEXT:[[TMP0:%.*]] = bitcast * [[V_ADDR]] to <8 x i8>*
-// CHECK-512-NEXT:[[TMP1:%.*]] = load <8 x i8>, <8 x i8>* [[TMP0]], align 16, [[TBAA6]]
-// CHECK-512-NEXT:store <8 x i8> [[TMP1]], <8 x i8>* @global_bool, align 2, [[TBAA6]]
+// CHECK-512-NEXT:[[SAVED_VALUE:%.*]] = alloca , align 16
+// CHECK-512-NEXT:store  [[V:%.*]], * [[SAVED_VALUE]], align 16, !tbaa [[TBAA9:![0-9]+]]
+// CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = bitcast * [[SAVED_VALUE]] to <8 x i8>*
+// CHECK-512-NEXT:[[TMP0:%.*]] = load <8 x i8>, <8 x i8>* [[CASTFIXEDSVE]], align 16, !tbaa [[TBAA6]]
+// CHECK-512-NEXT:store <8 x i8> [[TMP0]], <8 x i8>* @global_bool, align 2, !tbaa [[TBAA6]]
 // CHECK-512-NEXT:ret void
 //
 void write_global_bool(svbool_t v) { global_bool = v; }
@@ -73,13 +73,13 @@
 
 // CHECK-128-LABEL: @read_global_i64(
 // CHECK-128-NEXT:  entry:
-// CHECK-128-NEXT:[[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @global_i64, align 16, [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @global_i64, align 16, !tbaa [[TBAA6]]
 // 

[PATCH] D105127: Implement P1401R5

2021-06-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 355462.
cor3ntin added a comment.

Fix and add tests for the case where the condition is not convertible to bool
Simplify code.
Add reference to c++23 wording


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105127

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1296,7 +1296,7 @@
 
   Narrowing contextual conversions to bool
   https://wg21.link/P1401R5";>P1401R5
-  No
+  Clang 13
 
 
   Trimming whitespaces before line splicing
Index: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
===
--- clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++1z -verify %s
 // RUN: %clang_cc1 -std=c++1z -verify %s -DUNDEFINED
+// RUN: %clang_cc1 -std=c++2b -verify %s
+// RUN: %clang_cc1 -std=c++2b -verify %s -DUNDEFINED
 
 #ifdef UNDEFINED
 // "used but not defined" errors don't get produced if we have more interesting
@@ -38,19 +40,55 @@
 }
 #else
 namespace ccce {
+struct S {
+} s;
   void f() {
 if (5) {}
-if constexpr (5) {} // expected-error {{cannot be narrowed}}
+if constexpr (5) {
+}
   }
   template void g() {
-if constexpr (N) {} // expected-error {{cannot be narrowed}}
+if constexpr (N) {
+}
   }
-  template void g<5>(); // expected-note {{instantiation of}}
+  template void g<5>();
   void h() {
-if constexpr (4.3) {} // expected-error{{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (4.3) {
+}
 constexpr void *p = nullptr;
-if constexpr (p) {} // expected-error{{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (p) {
+}
+  }
+
+  void not_constant(int b, S s) {
+if constexpr (bool(b)) { // expected-error {{constexpr if condition is not a constant expression}}
+}
+if constexpr (b) { // expected-error {{constexpr if condition is not a constant expression}}
+}
+if constexpr (s) {
+}
+
+constexpr S constexprS;
+if constexpr (s) {
+}
   }
+
+#if __cplusplus <= 202002
+  // expected-error@47 {{cannot be narrowed}}
+  // expected-error@51 {{cannot be narrowed}}
+  // expected-note@54  {{instantiation of}}
+  // expected-error@56 {{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+  // expected-error@59 {{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+  // expected-error@68 {{value of type 'ccce::S' is not implicitly convertible to 'bool'}}
+  // expected-error@72 {{value of type 'ccce::S' is not implicitly convertible to 'bool'}}
+#else
+  // expected-error@68 {{value of type 'ccce::S' is not contextually convertible to 'bool'}}
+  // expected-error@72 {{value of type 'ccce::S' is not contextually convertible to 'bool'}}
+  // expected-warning@56 {{implicit conversion from 'double' to 'bool' changes value}}
+#endif
+  // expected-note@64 {{cannot be used in a constant expression}}
+  // expected-note@66 {{cannot be used in a constant expression}}
+  // expected-note@63 2{{declared here}}
 }
 
 namespace generic_lambda {
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -3911,7 +3911,7 @@
 
 /// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid.
 ExprResult Sema::CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr) {
-  // C++ 6.4p4:
+  // C++11 6.4p4:
   // The value of a condition that is an initialized declaration in a statement
   // other than a switch statement is the value of the declared variable
   // implicitly converted to type bool. If that conversion is ill-formed, the
@@ -3920,11 +3920,29 @@
   // expression, implicitly converted to bool.
   //
   // FIXME: Return this value to the caller so they don't need to recompute it.
-  llvm::APSInt Value(/*BitWidth*/1);
-  return (IsConstexpr && !CondExpr->isValueDependent())
- ? CheckConvertedConstantExpression(CondExpr, Context.BoolTy, Value,
-CCEK_ConstexprIf)
- : PerformContextuallyConvertToBool(CondExpr);
+
+  // C++2b 8.5.2p2
+  // If the if statement is of the form if constexpr, the value of the condition
+  // is contextually converted to bool and the converted expression shall be
+  // a constant expression
+
+  if (CondExpr->isValueDependent()

[PATCH] D104616: [analyzer] Model comparision methods of std::unique_ptr

2021-06-30 Thread Deep Majumder via Phabricator via cfe-commits
RedDocMD added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp:443-446
+  auto RetVal = C.getSValBuilder().evalBinOp(
+  State, BOK, FirstPtrVal, SecondPtrVal, Call.getResultType());
+  State = State->BindExpr(Call.getOriginExpr(), C.getLocationContext(), 
RetVal);
+  C.addTransition(State);

NoQ wrote:
> Because these operators are pure boolean functions, a state split would be 
> justified. It's pointless to call the operator unless both return values are 
> feasible. I think you should do an `assume()` and transition into both states.
> 
> It might also make sense to consult `-analyzer-config eagerly-assume=` before 
> doing it but it sounds like this option will stays true forever and we might 
> as well remove it.
> 
> The spaceship operator is obviously an exceptional case. Invocation of the 
> spaceship operator isn't a good indication that all three return values are 
> feasible, might be only two.
I think this comment has got displaced from its original location from 
subsequent updates. Could you please clarify?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104616

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


[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman, mgorny.
kuhnel requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

This is only the indexing part, it is NOT wired up to the
rest of ClandgdServer.

This is a step towards an implementation for
https://github.com/clangd/clangd/issues/618

Note: I'll pick up work on this in August, feel free to ignore this patch until 
then.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,63 @@
+//===-- StdLibIndexTests.cpp *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateIncludeHeader) {
+  auto Sli = StandardLibraryIndex();
+  auto Includes = Sli.generateIncludeHeader();
+
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+}
+
+/// test building the virtual file system
+TEST(StdLibIndexTests, buildFilesystem) {
+  auto Sli = StandardLibraryIndex();
+  auto FS = Sli.buildFilesystem(Sli.generateIncludeHeader());
+  auto Buffer =
+  FS->getBufferForFile(StandardLibraryIndex::StdLibHeaderFileName);
+  EXPECT_THAT((bool)Buffer.getError(), IsFalse());
+  EXPECT_THAT(Buffer.get()->getBuffer(), HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  auto Sli = StandardLibraryIndex();
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = Sli.indexHeaders(HeaderMock);
+  EXPECT_THAT((bool)Index, IsTrue()) << llvm::toString(Index.takeError());
+  FuzzyFindRequest Req;
+  Req.Query = "myfunc";
+  Req.AnyScope = true;
+  Req.Limit = 100;
+  std::vector Matches;
+  Index.get()->fuzzyFind(
+  Req, [&](const Symbol &Sym) { Matches.push_back(Sym.Name.str()); });
+  EXPECT_THAT(Matches.size(), Eq((size_t)1));
+  EXPECT_THAT(Matches, Contains("myfunc"));
+}
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -88,6 +88,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,42 @@
+//===--- StdLib.h *- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+class StandardLibraryIndex {
+  // TODO: do we really need a class? Or would plain functions be good enough?
+  // TODO: do we really need to make verything public just for unittesting?
+public:
+  /* virtual file name for indexing */
+  static const std::string StdLibHeaderFileName;
+
+  /* generate the index */
+  Expected>
+  indexHeaders(std::string HeaderSources);
+
+  /* generate header containing #includes for all standard library headers */
+  std::string generateIncludeHeader();
+
+  /* build a virtual filesyst

[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355466.
kuhnel added a comment.

forgot header comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,63 @@
+//===-- StdLibIndexTests.cpp *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateIncludeHeader) {
+  auto Sli = StandardLibraryIndex();
+  auto Includes = Sli.generateIncludeHeader();
+
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+}
+
+/// test building the virtual file system
+TEST(StdLibIndexTests, buildFilesystem) {
+  auto Sli = StandardLibraryIndex();
+  auto FS = Sli.buildFilesystem(Sli.generateIncludeHeader());
+  auto Buffer =
+  FS->getBufferForFile(StandardLibraryIndex::StdLibHeaderFileName);
+  EXPECT_THAT((bool)Buffer.getError(), IsFalse());
+  EXPECT_THAT(Buffer.get()->getBuffer(), HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  auto Sli = StandardLibraryIndex();
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = Sli.indexHeaders(HeaderMock);
+  EXPECT_THAT((bool)Index, IsTrue()) << llvm::toString(Index.takeError());
+  FuzzyFindRequest Req;
+  Req.Query = "myfunc";
+  Req.AnyScope = true;
+  Req.Limit = 100;
+  std::vector Matches;
+  Index.get()->fuzzyFind(
+  Req, [&](const Symbol &Sym) { Matches.push_back(Sym.Name.str()); });
+  EXPECT_THAT(Matches.size(), Eq((size_t)1));
+  EXPECT_THAT(Matches, Contains("myfunc"));
+}
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -88,6 +88,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,42 @@
+//===--- StdLib.h *- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+class StandardLibraryIndex {
+  // TODO: do we really need a class? Or would plain functions be good enough?
+  // TODO: do we really need to make verything public just for unittesting?
+public:
+  /* virtual file name for indexing */
+  static const std::string StdLibHeaderFileName;
+
+  /* generate the index */
+  Expected>
+  indexHeaders(std::string HeaderSources);
+
+  /* generate header containing #includes for all standard library headers */
+  std::string generateIncludeHeader();
+
+  /* build a virtual filesystem with the file to be indexed */
+  llvm::IntrusiveRefCntPtr
+  buildFilesystem(std::string HeaderSources);
+};
+
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
\ No newline at end of file
Index: clang-tools-extra/clangd/index/StdLib.cpp
=

[PATCH] D105145: [clang][Fuchsia] Remove relative-vtables multilibs

2021-06-30 Thread Petr Hosek via Phabricator via cfe-commits
phosek accepted this revision.
phosek 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/D105145/new/

https://reviews.llvm.org/D105145

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


[PATCH] D105120: [clang] Fix UB when string.front() is used for the empty string

2021-06-30 Thread Dmitry Polukhin via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfceaf8621179: [clang] Fix UB when string.front() is used for 
the empty string (authored by DmitryPolukhin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105120

Files:
  clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
  clang/unittests/Tooling/CompilationDatabaseTest.cpp


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto *It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@
   Argv.reserve(Cmd.CommandLine.size());
   for (auto &Arg : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;


Index: clang/unittests/Tooling/CompilationDatabaseTest.cpp
===
--- clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto *It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang
Index: clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
===
--- clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@
   Argv.reserve(Cmd.CommandLine.size());
   for (auto &Arg : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] fceaf86 - [clang] Fix UB when string.front() is used for the empty string

2021-06-30 Thread Dmitry Polukhin via cfe-commits

Author: Dmitry Polukhin
Date: 2021-06-30T01:07:47-07:00
New Revision: fceaf8621179aa758c44f3eaee02d789abfd455b

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

LOG: [clang] Fix UB when string.front() is used for the empty string

Compilation database might have empty string as a command line argument.
But ExpandResponseFilesDatabase::expand doesn't expect this and assumes
that string.front() can be used for any argument. It is undefined behaviour if
string is empty. With debug build mode it causes crash in clangd.

Test Plan: check-clang

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

Added: 


Modified: 
clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp

Removed: 




diff  --git a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp 
b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
index a825370afcf56..29787b8a88942 100644
--- a/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
+++ b/clang/lib/Tooling/ExpandResponseFilesCompilationDatabase.cpp
@@ -54,7 +54,8 @@ class ExpandResponseFilesDatabase : public 
CompilationDatabase {
   Argv.reserve(Cmd.CommandLine.size());
   for (auto &Arg : Cmd.CommandLine) {
 Argv.push_back(Arg.c_str());
-SeenRSPFile |= Arg.front() == '@';
+if (!Arg.empty())
+  SeenRSPFile |= Arg.front() == '@';
   }
   if (!SeenRSPFile)
 continue;

diff  --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 9a04de32c852d..218a352f86f06 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -700,6 +700,10 @@ class MemDBTest : public ::testing::Test {
 SmallVector Argv = {Clang, File, "-D", File};
 llvm::SplitString(Flags, Argv);
 
+// Trim double quotation from the argumnets if any.
+for (auto *It = Argv.begin(); It != Argv.end(); ++It)
+  *It = It->trim("\"");
+
 SmallString<32> Dir;
 llvm::sys::path::system_temp_directory(false, Dir);
 
@@ -962,5 +966,12 @@ TEST_F(ExpandResponseFilesTest, ExpandResponseFiles) {
   EXPECT_EQ(getCommand("bar.cpp"), "clang bar.cpp -D bar.cpp -Dflag");
 }
 
+TEST_F(ExpandResponseFilesTest, ExpandResponseFilesEmptyArgument) {
+  addFile(path(StringRef("rsp1.rsp")), "-Dflag");
+
+  add("foo.cpp", "clang", "@rsp1.rsp \"\"");
+  EXPECT_EQ(getCommand("foo.cpp"), "clang foo.cpp -D foo.cpp -Dflag ");
+}
+
 } // end namespace tooling
 } // end namespace clang



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


[PATCH] D105097: [clang][AArch64][SVE] Handle PRValue under VLAT <-> VLST cast

2021-06-30 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2103
+  if (const CallExpr *CE = dyn_cast(E))
+Ty = CE->getCallReturnType(CGF.getContext());
+

I don't think we need to call getCallReturnType() here.  A call that returns a 
reference is an lvalue, and the code here expects an rvalue.  So 
CE->getCallReturnType() is going to be the same as E->getType().


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105097

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


[PATCH] D104052: [clang] Fix CallExpr dependence bit may not respecting all its arguments.

2021-06-30 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 355469.
hokein added a comment.

refine the solution: introduce a separate method, and call it when needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104052

Files:
  clang/include/clang/AST/Expr.h
  clang/lib/AST/Expr.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/recovery-expr-type.cpp


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -139,6 +139,7 @@
 
 namespace test12 {
 // Verify we do not crash.
-void fun(int *foo = no_such_function()); // expected-error {{undeclared 
identifier}}
-void baz() { fun(); }
+int fun(int *foo = no_such_function()); // expected-error {{undeclared 
identifier}}
+void crash1() { fun(); }
+void crash2() { constexpr int s = fun(); }
 } // namespace test12
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5924,6 +5924,7 @@
   for (unsigned i = 0; i < TotalNumArgs; ++i)
 Call->setArg(i, AllArgs[i]);
 
+  Call->computeDependence();
   return false;
 }
 
@@ -6836,6 +6837,7 @@
 
   TheCall->setArg(i, Arg);
 }
+TheCall->computeDependence();
   }
 
   if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl))
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1398,7 +1398,7 @@
   for (unsigned I = Args.size(); I != NumArgs; ++I)
 setArg(I, nullptr);
 
-  setDependence(computeDependence(this, PreArgs));
+  this->computeDependence();
 
   CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
   if (hasStoredFPFeatures())
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -2987,11 +2987,21 @@
   }
 
   /// setArg - Set the specified argument.
+  /// ! the dependence bits might be stale after calling this setter, it is
+  /// *caller*'s responsibility to recompute them.
   void setArg(unsigned Arg, Expr *ArgExpr) {
 assert(Arg < getNumArgs() && "Arg access out of range!");
 getArgs()[Arg] = ArgExpr;
   }
 
+  /// Compute and set dependence bits.
+  void computeDependence() {
+setDependence(clang::computeDependence(
+this, llvm::makeArrayRef(
+  reinterpret_cast(getTrailingStmts() + 
PREARGS_START),
+  getNumPreArgs(;
+  }
+
   /// Reduce the number of arguments in this call expression. This is used for
   /// example during error recovery to drop extra arguments. There is no way
   /// to perform the opposite because: 1.) We don't track how much storage


Index: clang/test/SemaCXX/recovery-expr-type.cpp
===
--- clang/test/SemaCXX/recovery-expr-type.cpp
+++ clang/test/SemaCXX/recovery-expr-type.cpp
@@ -139,6 +139,7 @@
 
 namespace test12 {
 // Verify we do not crash.
-void fun(int *foo = no_such_function()); // expected-error {{undeclared identifier}}
-void baz() { fun(); }
+int fun(int *foo = no_such_function()); // expected-error {{undeclared identifier}}
+void crash1() { fun(); }
+void crash2() { constexpr int s = fun(); }
 } // namespace test12
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5924,6 +5924,7 @@
   for (unsigned i = 0; i < TotalNumArgs; ++i)
 Call->setArg(i, AllArgs[i]);
 
+  Call->computeDependence();
   return false;
 }
 
@@ -6836,6 +6837,7 @@
 
   TheCall->setArg(i, Arg);
 }
+TheCall->computeDependence();
   }
 
   if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl))
Index: clang/lib/AST/Expr.cpp
===
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -1398,7 +1398,7 @@
   for (unsigned I = Args.size(); I != NumArgs; ++I)
 setArg(I, nullptr);
 
-  setDependence(computeDependence(this, PreArgs));
+  this->computeDependence();
 
   CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
   if (hasStoredFPFeatures())
Index: clang/include/clang/AST/Expr.h
===
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -2987,11 +2987,21 @@
   }
 
   /// setArg - Set the specified argument.
+  /// ! the dependence bits might be stale after calling this setter, it is
+  /// *caller*'s responsibility to recompute them.
   void setArg(unsigned Arg, Expr *ArgExpr) {
 assert(Arg < getNumArgs() && "Arg access out of range!");
 getArgs()[Arg] = ArgExpr;
   }
 
+  /// Compute and set dependen

[PATCH] D104052: [clang] Fix CallExpr dependence bit may not respecting all its arguments.

2021-06-30 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

sorry for the delay, I lost the track.

> I think I can also live with adding explicit recomputeDependence() calls in 
> the right places, and slapping a warning on setArg() that it might be needed.

I'm inclined with this option.

As you mentioned,  there are two major places (ConvertArgumentForCall and 
BuildResolvedCallExpr in SemaExpr)  calling `setArg`, and it is trivial to 
update them. 
There are a lot of `setArg` usage in `SemaChecking.cpp`, but I think we're not 
interested to them --  because there are invalid checks before calling `setArg` 
and we mostly care about the error-bit.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104052

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


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355470.
kuhnel added a comment.

addressed Sam's review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h

Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -162,7 +162,7 @@
 
   // handleErrors needs to be able to set the Checked flag.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // Expected needs to be able to steal the payload when constructed from an
   // error.
@@ -244,7 +244,7 @@
 
   /// Returns the dynamic class id of this error, or null if this is a success
   /// value.
-  const void* dynamicClassID() const {
+  const void *dynamicClassID() const {
 if (!getPtr())
   return nullptr;
 return getPtr()->dynamicClassID();
@@ -270,9 +270,8 @@
 
   ErrorInfoBase *getPtr() const {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-return reinterpret_cast(
- reinterpret_cast(Payload) &
- ~static_cast(0x1));
+return reinterpret_cast(
+reinterpret_cast(Payload) & ~static_cast(0x1));
 #else
 return Payload;
 #endif
@@ -280,10 +279,9 @@
 
   void setPtr(ErrorInfoBase *EI) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(EI) &
- ~static_cast(0x1)) |
-(reinterpret_cast(Payload) & 0x1));
+Payload = reinterpret_cast(
+(reinterpret_cast(EI) & ~static_cast(0x1)) |
+(reinterpret_cast(Payload) & 0x1));
 #else
 Payload = EI;
 #endif
@@ -299,10 +297,9 @@
 
   void setChecked(bool V) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(Payload) &
-  ~static_cast(0x1)) |
-  (V ? 0 : 1));
+Payload = reinterpret_cast(
+(reinterpret_cast(Payload) & ~static_cast(0x1)) |
+(V ? 0 : 1));
 #endif
   }
 
@@ -333,7 +330,7 @@
 
 /// Make a Error instance representing failure using the given error info
 /// type.
-template  Error make_error(ArgTs &&... Args) {
+template  Error make_error(ArgTs &&...Args) {
   return Error(std::make_unique(std::forward(Args)...));
 }
 
@@ -366,7 +363,7 @@
   // handleErrors needs to be able to iterate the payload list of an
   // ErrorList.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // joinErrors is implemented in terms of join.
   friend Error joinErrors(Error, Error);
@@ -436,6 +433,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(Result.takeError()) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;
@@ -462,7 +493,8 @@
   : HasError(true)
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
 // Expected is unchecked upon construction in Debug builds.
-, Unchecked(true)
+,
+Unchecked(true)
 #endif
   {
 assert(Err && "Cannot create Expected from Error success value.");
@@ -764,7 +796,7 @@
 ///   Bar &X = cantFail(foo(false));
 ///   @endcode
 template 
-T& cantFail(Expected ValOrErr, const char *Msg = nullptr) {
+T &cantFail(Expected ValOrErr, const char *Msg = nullptr) {
   if (ValOrErr)
 return *ValOrErr;
   else {
@@ -785,8 +817,8 @@
 /// ErrorInfo types.
 template 
 class ErrorHandlerTraits
-: public ErrorHandlerTraits::ty

[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355471.
kuhnel marked 2 inline comments as done.
kuhnel added a comment.

fixed variable name


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h

Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -162,7 +162,7 @@
 
   // handleErrors needs to be able to set the Checked flag.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // Expected needs to be able to steal the payload when constructed from an
   // error.
@@ -244,7 +244,7 @@
 
   /// Returns the dynamic class id of this error, or null if this is a success
   /// value.
-  const void* dynamicClassID() const {
+  const void *dynamicClassID() const {
 if (!getPtr())
   return nullptr;
 return getPtr()->dynamicClassID();
@@ -270,9 +270,8 @@
 
   ErrorInfoBase *getPtr() const {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-return reinterpret_cast(
- reinterpret_cast(Payload) &
- ~static_cast(0x1));
+return reinterpret_cast(
+reinterpret_cast(Payload) & ~static_cast(0x1));
 #else
 return Payload;
 #endif
@@ -280,10 +279,9 @@
 
   void setPtr(ErrorInfoBase *EI) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(EI) &
- ~static_cast(0x1)) |
-(reinterpret_cast(Payload) & 0x1));
+Payload = reinterpret_cast(
+(reinterpret_cast(EI) & ~static_cast(0x1)) |
+(reinterpret_cast(Payload) & 0x1));
 #else
 Payload = EI;
 #endif
@@ -299,10 +297,9 @@
 
   void setChecked(bool V) {
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
-Payload = reinterpret_cast(
-(reinterpret_cast(Payload) &
-  ~static_cast(0x1)) |
-  (V ? 0 : 1));
+Payload = reinterpret_cast(
+(reinterpret_cast(Payload) & ~static_cast(0x1)) |
+(V ? 0 : 1));
 #endif
   }
 
@@ -333,7 +330,7 @@
 
 /// Make a Error instance representing failure using the given error info
 /// type.
-template  Error make_error(ArgTs &&... Args) {
+template  Error make_error(ArgTs &&...Args) {
   return Error(std::make_unique(std::forward(Args)...));
 }
 
@@ -366,7 +363,7 @@
   // handleErrors needs to be able to iterate the payload list of an
   // ErrorList.
   template 
-  friend Error handleErrors(Error E, HandlerTs &&... Handlers);
+  friend Error handleErrors(Error E, HandlerTs &&...Handlers);
 
   // joinErrors is implemented in terms of join.
   friend Error joinErrors(Error, Error);
@@ -436,6 +433,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;
@@ -462,7 +493,8 @@
   : HasError(true)
 #if LLVM_ENABLE_ABI_BREAKING_CHECKS
 // Expected is unchecked upon construction in Debug builds.
-, Unchecked(true)
+,
+Unchecked(true)
 #endif
   {
 assert(Err && "Cannot create Expected from Error success value.");
@@ -764,7 +796,7 @@
 ///   Bar &X = cantFail(foo(false));
 ///   @endcode
 template 
-T& cantFail(Expected ValOrErr, const char *Msg = nullptr) {
+T &cantFail(Expected ValOrErr, const char *Msg = nullptr) {
   if (ValOrErr)
 return *ValOrErr;
   else {
@@ -785,8 +817,8 @@
 /// ErrorInfo types.
 template 
 class ErrorHandlerTraits
-: public ErrorHandl

[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel marked 4 inline comments as done.
kuhnel added inline comments.



Comment at: llvm/include/llvm/Support/Error.h:462
+///
+///  Unit-testing a function returning an 'Expceted':
+///   @code{.cpp}

sammccall wrote:
> This seems too intrusive/unusual to put inline to me.
> And the main thing that is non-obvious is *why* you have to structure your 
> assertions in an unusual way, and that's not explained here.
> 
> Consider instead just briefly referencing the EXPECT_THAT_EXPECTED etc macros 
> in llvm/Testing/Support/Error.h which are designed to simplify this a bit.
Makes sense.

However  EXPECT_THAT_EXPECTED could also use some better documentation :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

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


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355472.
kuhnel marked an inline comment as done.
kuhnel added a comment.

argh, again fixed autoformatter :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h


Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105017: [analyzer] LValueToRValueBitCasts should evaluate to an r-value

2021-06-30 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko accepted this revision.
vsavchenko added a comment.

Oh, wow, that's awesome! Thanks!


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

https://reviews.llvm.org/D105017

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


[PATCH] D105014: added some example code for llvm::Expected

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

Thanks!




Comment at: llvm/include/llvm/Support/Error.h:464
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }

this won't compile, you need std::move(E)



Comment at: llvm/include/llvm/Support/Error.h:467
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode

this will crash in the error case, you need to `return` after the errs() log


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

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


[PATCH] D105127: Implement P1401R5

2021-06-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 355477.
cor3ntin added a comment.

Fix formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105127

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1296,7 +1296,7 @@
 
   Narrowing contextual conversions to bool
   https://wg21.link/P1401R5";>P1401R5
-  No
+  Clang 13
 
 
   Trimming whitespaces before line splicing
Index: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
===
--- clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -std=c++1z -verify %s
 // RUN: %clang_cc1 -std=c++1z -verify %s -DUNDEFINED
+// RUN: %clang_cc1 -std=c++2b -verify %s
+// RUN: %clang_cc1 -std=c++2b -verify %s -DUNDEFINED
 
 #ifdef UNDEFINED
 // "used but not defined" errors don't get produced if we have more interesting
@@ -38,19 +40,55 @@
 }
 #else
 namespace ccce {
+struct S {
+} s;
   void f() {
 if (5) {}
-if constexpr (5) {} // expected-error {{cannot be narrowed}}
+if constexpr (5) {
+}
   }
   template void g() {
-if constexpr (N) {} // expected-error {{cannot be narrowed}}
+if constexpr (N) {
+}
   }
-  template void g<5>(); // expected-note {{instantiation of}}
+  template void g<5>();
   void h() {
-if constexpr (4.3) {} // expected-error{{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (4.3) {
+}
 constexpr void *p = nullptr;
-if constexpr (p) {} // expected-error{{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (p) {
+}
+  }
+
+  void not_constant(int b, S s) {
+if constexpr (bool(b)) { // expected-error {{constexpr if condition is not a constant expression}}
+}
+if constexpr (b) { // expected-error {{constexpr if condition is not a constant expression}}
+}
+if constexpr (s) {
+}
+
+constexpr S constexprS;
+if constexpr (s) {
+}
   }
+
+#if __cplusplus <= 202002
+  // expected-error@47 {{cannot be narrowed}}
+  // expected-error@51 {{cannot be narrowed}}
+  // expected-note@54  {{instantiation of}}
+  // expected-error@56 {{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+  // expected-error@59 {{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+  // expected-error@68 {{value of type 'ccce::S' is not implicitly convertible to 'bool'}}
+  // expected-error@72 {{value of type 'ccce::S' is not implicitly convertible to 'bool'}}
+#else
+  // expected-error@68 {{value of type 'ccce::S' is not contextually convertible to 'bool'}}
+  // expected-error@72 {{value of type 'ccce::S' is not contextually convertible to 'bool'}}
+  // expected-warning@56 {{implicit conversion from 'double' to 'bool' changes value}}
+#endif
+  // expected-note@64 {{cannot be used in a constant expression}}
+  // expected-note@66 {{cannot be used in a constant expression}}
+  // expected-note@63 2{{declared here}}
 }
 
 namespace generic_lambda {
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -3911,7 +3911,7 @@
 
 /// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid.
 ExprResult Sema::CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr) {
-  // C++ 6.4p4:
+  // C++11 6.4p4:
   // The value of a condition that is an initialized declaration in a statement
   // other than a switch statement is the value of the declared variable
   // implicitly converted to type bool. If that conversion is ill-formed, the
@@ -3920,11 +3920,29 @@
   // expression, implicitly converted to bool.
   //
   // FIXME: Return this value to the caller so they don't need to recompute it.
-  llvm::APSInt Value(/*BitWidth*/1);
-  return (IsConstexpr && !CondExpr->isValueDependent())
- ? CheckConvertedConstantExpression(CondExpr, Context.BoolTy, Value,
-CCEK_ConstexprIf)
- : PerformContextuallyConvertToBool(CondExpr);
+
+  // C++2b 8.5.2p2
+  // If the if statement is of the form if constexpr, the value of the condition
+  // is contextually converted to bool and the converted expression shall be
+  // a constant expression
+
+  if (CondExpr->isValueDependent())
+return CondExpr;
+
+  if (IsConstexpr && !LangOpts.CPlusPlus2b) {
+llvm::APSInt Value(/*BitWidth*/

[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-30 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added inline comments.



Comment at: clang/test/Headers/Inputs/include/cstdlib:29
 float fabs(float __x) { return __builtin_fabs(__x); }
+#endif
 

jdoerfert wrote:
> That seems to be fundamentally broken then, but let's see, maybe it will 
> somehow work anyway.
I thought fabs was in math, not stdlib. Not sure what this file is doing but 
the functions above are inline and fabs isn't


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D105177: [clangd] Implemented indexing of standard library

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355478.
kuhnel added a comment.

using EXPECT_THAT_EXPECTED


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105177

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/index/StdLib.cpp
  clang-tools-extra/clangd/index/StdLib.h
  clang-tools-extra/clangd/unittests/CMakeLists.txt
  clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp

Index: clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
===
--- /dev/null
+++ clang-tools-extra/clangd/unittests/StdLibIndexTests.cpp
@@ -0,0 +1,66 @@
+//===-- StdLibIndexTests.cpp *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "index/StdLib.h"
+#include "support/Logger.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+using namespace testing;
+
+namespace clang {
+namespace clangd {
+
+/// check that the generated header sources contains some usual standard library
+/// headers
+TEST(StdLibIndexTests, generateIncludeHeader) {
+  auto Sli = StandardLibraryIndex();
+  auto Includes = Sli.generateIncludeHeader();
+
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+  EXPECT_THAT(Includes, HasSubstr("#include "));
+}
+
+/// test building the virtual file system
+TEST(StdLibIndexTests, buildFilesystem) {
+  auto Sli = StandardLibraryIndex();
+  auto FS = Sli.buildFilesystem(Sli.generateIncludeHeader());
+  auto Buffer =
+  FS->getBufferForFile(StandardLibraryIndex::StdLibHeaderFileName);
+  EXPECT_THAT((bool)Buffer.getError(), IsFalse());
+  EXPECT_THAT(Buffer.get()->getBuffer(), HasSubstr("#include "));
+}
+
+/// build the index and check if it contains the right symbols
+TEST(StdLibIndexTests, buildIndex) {
+  auto Sli = StandardLibraryIndex();
+  // TODO: maybe find a way to use a local libcxx for testing if that is
+  //   available on the machine
+  std::string HeaderMock = R"CPP(
+int myfunc(int a);
+bool otherfunc(int a, int b);
+  )CPP";
+  auto Index = Sli.indexHeaders(HeaderMock);
+  EXPECT_THAT_EXPECTED(Index, llvm::Succeeded())
+  << llvm::toString(Index.takeError());
+  FuzzyFindRequest Req;
+  Req.Query = "myfunc";
+  Req.AnyScope = true;
+  Req.Limit = 100;
+  std::vector Matches;
+  Index.get()->fuzzyFind(
+  Req, [&](const Symbol &Sym) { Matches.push_back(Sym.Name.str()); });
+  EXPECT_THAT(Matches.size(), Eq((size_t)1));
+  EXPECT_THAT(Matches, Contains("myfunc"));
+}
+
+} // namespace clangd
+} // namespace clang
Index: clang-tools-extra/clangd/unittests/CMakeLists.txt
===
--- clang-tools-extra/clangd/unittests/CMakeLists.txt
+++ clang-tools-extra/clangd/unittests/CMakeLists.txt
@@ -88,6 +88,7 @@
   SemanticSelectionTests.cpp
   SerializationTests.cpp
   SourceCodeTests.cpp
+  StdLibIndexTests.cpp
   SymbolCollectorTests.cpp
   SymbolInfoTests.cpp
   SyncAPI.cpp
Index: clang-tools-extra/clangd/index/StdLib.h
===
--- /dev/null
+++ clang-tools-extra/clangd/index/StdLib.h
@@ -0,0 +1,42 @@
+//===--- StdLib.h *- C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
+
+#include "index/Index.h"
+#include "index/MemIndex.h"
+#include "support/ThreadsafeFS.h"
+#include 
+
+namespace clang {
+namespace clangd {
+
+class StandardLibraryIndex {
+  // TODO: do we really need a class? Or would plain functions be good enough?
+  // TODO: do we really need to make verything public just for unittesting?
+public:
+  /* virtual file name for indexing */
+  static const std::string StdLibHeaderFileName;
+
+  /* generate the index */
+  Expected>
+  indexHeaders(std::string HeaderSources);
+
+  /* generate header containing #includes for all standard library headers */
+  std::string generateIncludeHeader();
+
+  /* build a virtual filesystem with the file to be indexed */
+  llvm::IntrusiveRefCntPtr
+  buildFilesystem(std::string HeaderSources);
+};
+
+} // namespace clangd
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_INDEX_STDLIB_H
\ No newline at end of file

[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-30 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added inline comments.



Comment at: clang/lib/Headers/__clang_hip_cmath.h:43
+__DEVICE__ __CONSTEXPR__ long abs(long __n) { return ::labs(__n); }
+__DEVICE__ __CONSTEXPR__ float fma(float __x, float __y, float __z) {
   return ::fmaf(__x, __y, __z);

I'm pretty sure it's UB, no diagnostic req to call a non-constexpr function 
from a constexpr one. Nevertheless, it does presently seem to be working for 
nvptx clang so will probably work for amdgcn.

Strictly I think we're supposed to detect when called at compile time and call 
one implementation and otherwise call the library one, where weirdly it's ok 
for them to return different answers. I think there's a built-in we can call to 
select between the two.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355481.
kuhnel added a comment.

also added example code for EXPECT_THAT_EXPECTED.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,29 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper marcro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test the good care
+///   auto D1 = myDivide(10, 5);
+///   // ensure the Error gets consumed in case the function fails by
+///   // calling 'toString()'. This also helps in debugging failing tests.
+///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
+/// "\n";
+///   EXPECT_THAT(*D1, Eq(2));
+///
+///   // test the error case
+///   auto D2 = myDivide(10, 0);
+///   EXPECT_THAT_EXPECTED(D2, Failed());
+///   // In the error case we need to consume the error.
+///   consumeError(D2.takeError());
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) 
\
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) 
\
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,40 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// auto Result = myDivide(X,Y);
+/// if (auto E = Result.takeError()) {
+///// We must consume the error. Typically one of:
+///// - return the error to our caller
+///// - toString(), when logging
+///// - consumeError(), to silently swallow the error
+///// - handleErrors(), to distinguish error types
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,29 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper marcro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test the good care
+///   auto D1 = myDivide(10, 5);
+///   // ensure the Error gets consumed in case the function fails by
+///   // calling 'toString()'. This also helps in debugging failing tests.
+///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
+/// "\n";
+///   EXPECT_THAT(*D1, Eq(2));
+///
+///   // test the error case
+///   auto D2 = myDivide(10, 0);
+///   EXPECT_THAT_EXPECTED(D2, Failed());
+///   // In the error case we need to consume the error.
+///   consumeError(D2.takeError());
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) \
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) \
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/i

[PATCH] D105097: [clang][AArch64][SVE] Handle PRValue under VLAT <-> VLST cast

2021-06-30 Thread JunMa via Phabricator via cfe-commits
junparser added inline comments.



Comment at: clang/lib/CodeGen/CGExprScalar.cpp:2103
+  if (const CallExpr *CE = dyn_cast(E))
+Ty = CE->getCallReturnType(CGF.getContext());
+

efriedma wrote:
> I don't think we need to call getCallReturnType() here.  A call that returns 
> a reference is an lvalue, and the code here expects an rvalue.  So 
> CE->getCallReturnType() is going to be the same as E->getType().
make sense to me, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105097

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


[PATCH] D105097: [clang][AArch64][SVE] Handle PRValue under VLAT <-> VLST cast

2021-06-30 Thread JunMa via Phabricator via cfe-commits
junparser updated this revision to Diff 355484.
junparser added a comment.

address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105097

Files:
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/test/CodeGen/attr-arm-sve-vector-bits-bitcast.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-call.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-codegen.c
  clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c

Index: clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
===
--- clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
+++ clang/test/CodeGen/attr-arm-sve-vector-bits-globals.c
@@ -22,13 +22,13 @@
 // CHECK-128-LABEL: @write_global_i64(
 // CHECK-128-NEXT:  entry:
 // CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = call <2 x i64> @llvm.experimental.vector.extract.v2i64.nxv2i64( [[V:%.*]], i64 0)
-// CHECK-128-NEXT:store <2 x i64> [[CASTFIXEDSVE]], <2 x i64>* @global_i64, align 16, [[TBAA6:!tbaa !.*]]
+// CHECK-128-NEXT:store <2 x i64> [[CASTFIXEDSVE]], <2 x i64>* @global_i64, align 16, !tbaa [[TBAA6:![0-9]+]]
 // CHECK-128-NEXT:ret void
 //
 // CHECK-512-LABEL: @write_global_i64(
 // CHECK-512-NEXT:  entry:
 // CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = call <8 x i64> @llvm.experimental.vector.extract.v8i64.nxv2i64( [[V:%.*]], i64 0)
-// CHECK-512-NEXT:store <8 x i64> [[CASTFIXEDSVE]], <8 x i64>* @global_i64, align 16, [[TBAA6:!tbaa !.*]]
+// CHECK-512-NEXT:store <8 x i64> [[CASTFIXEDSVE]], <8 x i64>* @global_i64, align 16, !tbaa [[TBAA6:![0-9]+]]
 // CHECK-512-NEXT:ret void
 //
 void write_global_i64(svint64_t v) { global_i64 = v; }
@@ -36,33 +36,33 @@
 // CHECK-128-LABEL: @write_global_bf16(
 // CHECK-128-NEXT:  entry:
 // CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = call <8 x bfloat> @llvm.experimental.vector.extract.v8bf16.nxv8bf16( [[V:%.*]], i64 0)
-// CHECK-128-NEXT:store <8 x bfloat> [[CASTFIXEDSVE]], <8 x bfloat>* @global_bf16, align 16, [[TBAA6]]
+// CHECK-128-NEXT:store <8 x bfloat> [[CASTFIXEDSVE]], <8 x bfloat>* @global_bf16, align 16, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:ret void
 //
 // CHECK-512-LABEL: @write_global_bf16(
 // CHECK-512-NEXT:  entry:
 // CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = call <32 x bfloat> @llvm.experimental.vector.extract.v32bf16.nxv8bf16( [[V:%.*]], i64 0)
-// CHECK-512-NEXT:store <32 x bfloat> [[CASTFIXEDSVE]], <32 x bfloat>* @global_bf16, align 16, [[TBAA6]]
+// CHECK-512-NEXT:store <32 x bfloat> [[CASTFIXEDSVE]], <32 x bfloat>* @global_bf16, align 16, !tbaa [[TBAA6]]
 // CHECK-512-NEXT:ret void
 //
 void write_global_bf16(svbfloat16_t v) { global_bf16 = v; }
 
 // CHECK-128-LABEL: @write_global_bool(
 // CHECK-128-NEXT:  entry:
-// CHECK-128-NEXT:[[V_ADDR:%.*]] = alloca , align 16
-// CHECK-128-NEXT:store  [[V:%.*]], * [[V_ADDR]], align 16, [[TBAA9:!tbaa !.*]]
-// CHECK-128-NEXT:[[TMP0:%.*]] = bitcast * [[V_ADDR]] to <2 x i8>*
-// CHECK-128-NEXT:[[TMP1:%.*]] = load <2 x i8>, <2 x i8>* [[TMP0]], align 16, [[TBAA6]]
-// CHECK-128-NEXT:store <2 x i8> [[TMP1]], <2 x i8>* @global_bool, align 2, [[TBAA6]]
+// CHECK-128-NEXT:[[SAVED_VALUE:%.*]] = alloca , align 16
+// CHECK-128-NEXT:store  [[V:%.*]], * [[SAVED_VALUE]], align 16, !tbaa [[TBAA9:![0-9]+]]
+// CHECK-128-NEXT:[[CASTFIXEDSVE:%.*]] = bitcast * [[SAVED_VALUE]] to <2 x i8>*
+// CHECK-128-NEXT:[[TMP0:%.*]] = load <2 x i8>, <2 x i8>* [[CASTFIXEDSVE]], align 16, !tbaa [[TBAA6]]
+// CHECK-128-NEXT:store <2 x i8> [[TMP0]], <2 x i8>* @global_bool, align 2, !tbaa [[TBAA6]]
 // CHECK-128-NEXT:ret void
 //
 // CHECK-512-LABEL: @write_global_bool(
 // CHECK-512-NEXT:  entry:
-// CHECK-512-NEXT:[[V_ADDR:%.*]] = alloca , align 16
-// CHECK-512-NEXT:store  [[V:%.*]], * [[V_ADDR]], align 16, [[TBAA9:!tbaa !.*]]
-// CHECK-512-NEXT:[[TMP0:%.*]] = bitcast * [[V_ADDR]] to <8 x i8>*
-// CHECK-512-NEXT:[[TMP1:%.*]] = load <8 x i8>, <8 x i8>* [[TMP0]], align 16, [[TBAA6]]
-// CHECK-512-NEXT:store <8 x i8> [[TMP1]], <8 x i8>* @global_bool, align 2, [[TBAA6]]
+// CHECK-512-NEXT:[[SAVED_VALUE:%.*]] = alloca , align 16
+// CHECK-512-NEXT:store  [[V:%.*]], * [[SAVED_VALUE]], align 16, !tbaa [[TBAA9:![0-9]+]]
+// CHECK-512-NEXT:[[CASTFIXEDSVE:%.*]] = bitcast * [[SAVED_VALUE]] to <8 x i8>*
+// CHECK-512-NEXT:[[TMP0:%.*]] = load <8 x i8>, <8 x i8>* [[CASTFIXEDSVE]], align 16, !tbaa [[TBAA6]]
+// CHECK-512-NEXT:store <8 x i8> [[TMP0]], <8 x i8>* @global_bool, align 2, !tbaa [[TBAA6]]
 // CHECK-512-NEXT:ret void
 //
 void write_global_bool(svbool_t v) { global_bool = v; }
@@ -73,13 +73,13 @@
 
 // CHECK-128-LABEL: @read_global_i64(
 // CHECK-128-NEXT:  entry:
-// CHECK-128-NEXT:[[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @global_i64, align 16, [[TBAA6]]
+// CHECK-128-NEXT:[[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @global_i64, align 16, !tbaa [[TBAA6]]
 // C

[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355485.
kuhnel marked 2 inline comments as done.
kuhnel added a comment.

fixed compilation issues


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,29 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper marcro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test the good care
+///   auto D1 = myDivide(10, 5);
+///   // ensure the Error gets consumed in case the function fails by
+///   // calling 'toString()'. This also helps in debugging failing tests.
+///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
+/// "\n";
+///   EXPECT_THAT(*D1, Eq(2));
+///
+///   // test the error case
+///   auto D2 = myDivide(10, 0);
+///   EXPECT_THAT_EXPECTED(D2, Failed());
+///   // In the error case we need to consume the error.
+///   consumeError(D2.takeError());
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) 
\
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) 
\
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// if (auto E = Result.takeError()) {
+///   // We must consume the error. Typically one of:
+///   // - return the error to our caller
+///   // - toString(), when logging
+///   // - consumeError(), to silently swallow the error
+///   // - handleErrors(), to distinguish error types
+///   errs() << "Problem with division " << toString(std::move(E)) << "\n";
+///   return;
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,29 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper marcro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test the good care
+///   auto D1 = myDivide(10, 5);
+///   // ensure the Error gets consumed in case the function fails by
+///   // calling 'toString()'. This also helps in debugging failing tests.
+///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
+/// "\n";
+///   EXPECT_THAT(*D1, Eq(2));
+///
+///   // test the error case
+///   auto D2 = myDivide(10, 0);
+///   EXPECT_THAT_EXPECTED(D2, Failed());
+///   // In the error case we need to consume the error.
+///   consumeError(D2.takeError());
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) \
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) \
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Suppo

[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel added inline comments.



Comment at: llvm/include/llvm/Support/Error.h:464
+///errs() << "Problem with division "
+///   << toString(E) << "\n";
+/// }

sammccall wrote:
> this won't compile, you need std::move(E)
sorry, I was too lazy to run this through the compiler. Now it compiles and 
runs...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

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


[clang] c818cb9 - [analyzer][satest][NFC] Relax dependencies requirements

2021-06-30 Thread Valeriy Savchenko via cfe-commits

Author: Valeriy Savchenko
Date: 2021-06-30T12:50:21+03:00
New Revision: c818cb96ad4aa65bceadc72199677c852e8c22bd

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

LOG: [analyzer][satest][NFC] Relax dependencies requirements

Added: 


Modified: 
clang/utils/analyzer/Dockerfile

Removed: 




diff  --git a/clang/utils/analyzer/Dockerfile b/clang/utils/analyzer/Dockerfile
index f74ff8aa95c25..bb1dd60eeb9b8 100644
--- a/clang/utils/analyzer/Dockerfile
+++ b/clang/utils/analyzer/Dockerfile
@@ -13,16 +13,16 @@ RUN apt-add-repository -y 'deb 
https://apt.kitware.com/ubuntu/ bionic main'
 
 # test system dependencies
 RUN apt-get update && apt-get install -y \
-git=1:2.17.1-1ubuntu0.7 \
-gettext=0.19.8.1-6ubuntu0.3 \
+git=1:2.17.1* \
+gettext=0.19.8.1* \
 python3=3.6.7-1~18.04 \
-python3-pip=9.0.1-2.3~ubuntu1.18.04.1 \
-cmake=3.17.3-0kitware1 \
+python3-pip=9.0.1-2.3* \
+cmake=3.20.5* \
 ninja-build=1.8.2-1
 
 # box2d dependencies
 RUN apt-get install -y \
-libx11-dev=2:1.6.4-3ubuntu0.2 \
+libx11-dev=2:1.6.4-3* \
 libxrandr-dev=2:1.5.1-1 \
 libxinerama-dev=2:1.1.3-1 \
 libxcursor-dev=1:1.1.15-1 \
@@ -35,22 +35,22 @@ RUN apt-get install -y \
 
 # simbody dependencies
 RUN apt-get install -y \
-liblapack-dev=3.7.1-4ubuntu1
+liblapack-dev=3.7.1-4*
 
 # drogon dependencies
 RUN apt-get install -y \
-libjsonrpccpp-dev=0.7.0-1build2 \
-uuid-dev=2.31.1-0.4ubuntu3.6
+libjsonrpccpp-dev=0.7.0-1* \
+uuid-dev=2.31.1-0.4*
 
 # tmux dependencies
 RUN apt-get install -y \
 autotools-dev=20180224.1 \
-automake=1:1.15.1-3ubuntu2 \
-libncurses5-dev=6.1-1ubuntu1.18.04 \
-libevent-dev=2.1.8-stable-4build1 \
-pkg-config=0.29.1-0ubuntu2 \
+automake=1:1.15.1-3* \
+libncurses5-dev=6.1-1* \
+libevent-dev=2.1.8* \
+pkg-config=0.29.1-0* \
 flex=2.6.4-6 \
-bison=2:3.0.4.dfsg-1build1
+bison=2:3.0.4.*
 
 RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 1
 



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


[PATCH] D104550: [analyzer] Implement getType for SVal

2021-06-30 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

@vsavchenko One of the added tests is failing on our 32 bit Armv7 Thumb bot: 
https://lab.llvm.org/buildbot/#/builders/170/builds/61

  
/home/tcwg-buildslave/worker/clang-thumbv7-full-2stage/llvm/clang/unittests/StaticAnalyzer/SValTest.cpp:169:
 Failure
  Expected equality of these values:
Context.UnsignedLongTy
  Which is: unsigned long
A.getType(Context)
  Which is: unsigned int
  [  FAILED  ] SValTest.GetLocAsIntType (22 ms)
  [--] 1 test from SValTest (22 ms total)

A 32/64 bit issue?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104550

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


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: llvm/include/llvm/Testing/Support/Error.h:168
 
+/// Helper marcro for checking the result of an 'Expected'
+///

marcro -> macro



Comment at: llvm/include/llvm/Testing/Support/Error.h:179
+///   // calling 'toString()'. This also helps in debugging failing tests.
+///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
+/// "\n";

you shouldn't explicitly log the tostring, this should happen automatically



Comment at: llvm/include/llvm/Testing/Support/Error.h:181
+/// "\n";
+///   EXPECT_THAT(*D1, Eq(2));
+///

this is unidiomatic/incorrect, rather just `EXPECT_THAT_EXPECTED(D1, 
HasValue(2))` in one step

(Note that if you want to write `*D1`, you need to establish that `D1` 
succeeded, e.g. by using `ASSERT_` to bail out early. As it is, if there is an 
error it'll show one failure and then crash)



Comment at: llvm/include/llvm/Testing/Support/Error.h:187
+///   // In the error case we need to consume the error.
+///   consumeError(D2.takeError());
+/// }

no, you don't!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

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


[PATCH] D105127: Implement P1401R5

2021-06-30 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

Thanks!
Just some nits and some minor points on the tests.




Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:1491
+def err_constexpr_if_condition_expression_is_not_constant : Error<
+  "constexpr if condition is not a constant expression convertible to bool">;
 def err_static_assert_failed : Error<"static_assert failed%select{ %1|}0">;

Looks a bit easier to parse the english there.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:3922
   //
   // FIXME: Return this value to the caller so they don't need to recompute it.
+

This FIXME got pushed out of the thing it used to refer to.



Comment at: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp:1-4
 // RUN: %clang_cc1 -std=c++1z -verify %s
 // RUN: %clang_cc1 -std=c++1z -verify %s -DUNDEFINED
+// RUN: %clang_cc1 -std=c++2b -verify %s
+// RUN: %clang_cc1 -std=c++2b -verify %s -DUNDEFINED

I think attaching the expected diagnostics to the lines that generate them 
looks clearer and is easier to maintain.

The problem is that it seems you are having to work around that some of these 
errors are conditional on the std version, and it would indeed be quite a bite 
noisier with the preprocessor there, but there is a simple solution: with the 
suggested edit above, you can do things like:

// cxx17-error {{value of type 'ccce::S' is not implicitly convertible to 
'bool'}}
// cxx2b-error {{value of type 'ccce::S' is not contextually convertible to 
'bool'}}

But you can still do `expected-note {{cannot be used in a constant 
expression}}` in order to expect diagnostics for all versions.



Comment at: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp:43
 namespace ccce {
+struct S {
+} s;

This is not consistently indented.



Comment at: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp:71-72
+
+constexpr S constexprS;
+if constexpr (s) {
+}

Hmm what is this testing exactly? That `constexprS` is not getting confused 
with `s`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105127

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


[PATCH] D104550: [analyzer] Implement getType for SVal

2021-06-30 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko added a comment.

In D104550#2849561 , @DavidSpickett 
wrote:

> @vsavchenko One of the added tests is failing on our 32 bit Armv7 Thumb bot: 
> https://lab.llvm.org/buildbot/#/builders/170/builds/61
>
>   
> /home/tcwg-buildslave/worker/clang-thumbv7-full-2stage/llvm/clang/unittests/StaticAnalyzer/SValTest.cpp:169:
>  Failure
>   Expected equality of these values:
> Context.UnsignedLongTy
>   Which is: unsigned long
> A.getType(Context)
>   Which is: unsigned int
>   [  FAILED  ] SValTest.GetLocAsIntType (22 ms)
>   [--] 1 test from SValTest (22 ms total)
>
> A 32/64 bit issue?

Hi @DavidSpickett , thanks for looking into this!
This patch was almost instantly followed by 
https://github.com/llvm/llvm-project/commit/b2842298cebf420ecb3750bf309021a7f37870c1
 which fixed the issue.  Please, let me know, if you still see it after that 
commit!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104550

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


[PATCH] D104550: [analyzer] Implement getType for SVal

2021-06-30 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

Cool. If you see a few more emails with the same thing ignore them, the armv7 
bots are rather slow to catch up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104550

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


[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-30 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield accepted this revision.
JonChesterfield added a comment.
This revision is now accepted and ready to land.

I recommend we ship this and fix up the rough edges as we run into them. Paired 
with ocml it passes OVO libm tests which seems to be a fairly high bar for 
'does it work'. Therefore tagging green. Any objections?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D104604: [clang] NFC: add line break at the end of if expressions

2021-06-30 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

It seems you need someone to commit this patch? If so you need to share your 
name and email address. So that someone with commit access can commit it for 
you.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104604

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


[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-30 Thread Pushpinder Singh via Phabricator via cfe-commits
pdhaliwal added inline comments.



Comment at: clang/lib/Headers/__clang_hip_cmath.h:96
+__DEVICE__ __CONSTEXPR__ bool isnan(float __x) { return ::__isnanf(__x); }
+__DEVICE__ __CONSTEXPR__ bool isnan(double __x) { return ::__isnan(__x); }
 

jdoerfert wrote:
> ^ This is how OpenMP resolves the overload issue wrt. different return types.
I tried the exact same way. The lit tests compile and run fine. I could not get 
the runtime tests compile without the errors. It might be that I am not using 
match patterns correctly. I also tried some other combinations of the match 
selector but none of them worked.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D104604: [clang] NFC: add line break at the end of if expressions

2021-06-30 Thread zhouyizhou via Phabricator via cfe-commits
zhouyizhou added a comment.

In D104604#2849676 , @xgupta wrote:

> It seems you need someone to commit this patch? If so you need to share your 
> name and email address. So that someone with commit access can commit it for 
> you.

Thank you very much, I did want someone to commit this patch for me.

My name is Zhouyi Zhou
My email address is zhouzho...@gmail.com


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104604

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


[PATCH] D105127: Implement P1401R5

2021-06-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 355505.
cor3ntin marked an inline comment as done.
cor3ntin added a comment.

Improve and fix test,
Move the fixme in a more sensible place


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105127

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/Sema/SemaExprCXX.cpp
  clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1296,7 +1296,7 @@
 
   Narrowing contextual conversions to bool
   https://wg21.link/P1401R5";>P1401R5
-  No
+  Clang 13
 
 
   Trimming whitespaces before line splicing
Index: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
===
--- clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
+++ clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -std=c++1z -verify %s
-// RUN: %clang_cc1 -std=c++1z -verify %s -DUNDEFINED
+// RUN: %clang_cc1 -std=c++1z -verify=expected,cxx17 %s
+// RUN: %clang_cc1 -std=c++1z -verify=expected,cxx17 %s -DUNDEFINED
+// RUN: %clang_cc1 -std=c++2b -verify=expected,cxx2b %s
+// RUN: %clang_cc1 -std=c++2b -verify=expected,cxx2b %s -DUNDEFINED
 
 #ifdef UNDEFINED
 // "used but not defined" errors don't get produced if we have more interesting
@@ -38,18 +40,43 @@
 }
 #else
 namespace ccce {
+
+struct S {
+} s;
   void f() {
 if (5) {}
-if constexpr (5) {} // expected-error {{cannot be narrowed}}
+if constexpr (5) { // cxx17-error {{cannot be narrowed}}
+}
   }
   template void g() {
-if constexpr (N) {} // expected-error {{cannot be narrowed}}
+if constexpr (N) { // cxx17-error {{cannot be narrowed}}
+}
   }
-  template void g<5>(); // expected-note {{instantiation of}}
+  template void g<5>(); //cxx17-note  {{instantiation of}}
   void h() {
-if constexpr (4.3) {} // expected-error{{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (4.3) { //  cxx17-error {{conversion from 'double' to 'bool' is not allowed in a converted constant expression}}
+  // cxx2b-warning@-1 {{implicit conversion from 'double' to 'bool' changes value}}
+}
 constexpr void *p = nullptr;
-if constexpr (p) {} // expected-error{{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+if constexpr (p) { // cxx17-error {{conversion from 'void *const' to 'bool' is not allowed in a converted constant expression}}
+}
+  }
+
+  void not_constant(int b, S s) { //  expected-note 2{{declared here}}
+if constexpr (bool(b)) {  // expected-error {{constexpr if condition is not a constant expression}} expected-note {{cannot be used in a constant expression}}
+}
+if constexpr (b) { // expected-error {{constexpr if condition is not a constant expression}} expected-note {{cannot be used in a constant expression}}
+}
+if constexpr (s) {
+  // cxx17-error@-1 {{value of type 'ccce::S' is not implicitly convertible to 'bool'}}
+  // cxx2b-error@-2 {{value of type 'ccce::S' is not contextually convertible to 'bool'}}
+}
+
+constexpr S constexprS;
+if constexpr (constexprS) {
+  //cxx17-error@-1 {{value of type 'const ccce::S' is not implicitly convertible to 'bool'}}
+  //cxx2b-error@-2 {{value of type 'const ccce::S' is not contextually convertible to 'bool'}}
+}
   }
 }
 
Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -3911,7 +3911,7 @@
 
 /// CheckCXXBooleanCondition - Returns true if a conversion to bool is invalid.
 ExprResult Sema::CheckCXXBooleanCondition(Expr *CondExpr, bool IsConstexpr) {
-  // C++ 6.4p4:
+  // C++11 6.4p4:
   // The value of a condition that is an initialized declaration in a statement
   // other than a switch statement is the value of the declared variable
   // implicitly converted to type bool. If that conversion is ill-formed, the
@@ -3919,12 +3919,30 @@
   // The value of a condition that is an expression is the value of the
   // expression, implicitly converted to bool.
   //
+  // C++2b 8.5.2p2
+  // If the if statement is of the form if constexpr, the value of the condition
+  // is contextually converted to bool and the converted expression shall be
+  // a constant expression
+  //
   // FIXME: Return this value to the caller so they don't need to recompute it.
-  llvm::APSInt Value(/*BitWidth*/1);
-  return (IsConstexpr && !CondExpr->isValueDependent())
- ? CheckConvertedConstantExpression(CondExpr, Context.BoolTy, Value,
-CCEK_Const

[PATCH] D105127: Implement P1401R5

2021-06-30 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:1491
+def err_constexpr_if_condition_expression_is_not_constant : Error<
+  "constexpr if condition is not a constant expression convertible to bool">;
 def err_static_assert_failed : Error<"static_assert failed%select{ %1|}0">;

mizvekov wrote:
> Looks a bit easier to parse the english there.
I would rather not change that, to remain consistent with existing diagnostics 
involving `constexpr if`
But I agree it might be good to change them all



Comment at: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp:1-4
 // RUN: %clang_cc1 -std=c++1z -verify %s
 // RUN: %clang_cc1 -std=c++1z -verify %s -DUNDEFINED
+// RUN: %clang_cc1 -std=c++2b -verify %s
+// RUN: %clang_cc1 -std=c++2b -verify %s -DUNDEFINED

mizvekov wrote:
> I think attaching the expected diagnostics to the lines that generate them 
> looks clearer and is easier to maintain.
> 
> The problem is that it seems you are having to work around that some of these 
> errors are conditional on the std version, and it would indeed be quite a 
> bite noisier with the preprocessor there, but there is a simple solution: 
> with the suggested edit above, you can do things like:
> 
> // cxx17-error {{value of type 'ccce::S' is not implicitly convertible to 
> 'bool'}}
> // cxx2b-error {{value of type 'ccce::S' is not contextually convertible to 
> 'bool'}}
> 
> But you can still do `expected-note {{cannot be used in a constant 
> expression}}` in order to expect diagnostics for all versions.
Thanks, much better, I did not know it was an option



Comment at: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp:43
 namespace ccce {
+struct S {
+} s;

mizvekov wrote:
> This is not consistently indented.
Unfortunately, it was put there by clang-format, should I move it manually?



Comment at: clang/test/CXX/stmt.stmt/stmt.select/stmt.if/p2.cpp:71-72
+
+constexpr S constexprS;
+if constexpr (s) {
+}

mizvekov wrote:
> Hmm what is this testing exactly? That `constexprS` is not getting confused 
> with `s`?
Indeed, will fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105127

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


[PATCH] D105049: [NFC] Remove extra semicolons in clang/lib/APINotes/APINotesFormat.h

2021-06-30 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added a comment.

> These result in warnings while building and don't need to be there.

What are the warnings you get, I run `make clangAPINotes` didn't get any. I am 
on a7ed55f64c5fdce9af3257458779402fb9de1f8b 
 (
[AMDGPU] Simplify getReservedNumSGPRs) and using clang version 13.0.0 
(328377307ad2da961b3be0f2bbf1814a6f1f4ed3 
).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105049

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


[clang] 2fd7550 - [clang] NFC: add line break at the end of if expressions

2021-06-30 Thread via cfe-commits

Author: Zhouyi Zhou
Date: 2021-06-30T19:48:24+08:00
New Revision: 2fd75507d1855300d0a59451337d0a55b081887c

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

LOG: [clang] NFC: add line break at the end of if expressions

Hi,

In function TransformTemplateArgument,
would it be better to add line break at the end of "if" expressions?

I use clang-format to do the job for me.

Thanks a lot

Reviewed By: pengfei

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

Added: 


Modified: 
clang/lib/Sema/TreeTransform.h

Removed: 




diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 7b9f6a85260f..70ba631dbfc6 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -4322,10 +4322,10 @@ void TreeTransform::InventTemplateArgumentLoc(
   Arg, QualType(), getDerived().getBaseLocation());
 }
 
-template
+template 
 bool TreeTransform::TransformTemplateArgument(
- const TemplateArgumentLoc &Input,
- TemplateArgumentLoc &Output, bool 
Uneval) {
+const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
+bool Uneval) {
   const TemplateArgument &Arg = Input.getArgument();
   switch (Arg.getKind()) {
   case TemplateArgument::Null:
@@ -4374,7 +4374,8 @@ bool TreeTransform::TransformTemplateArgument(
   DI = InventTypeSourceInfo(Input.getArgument().getAsType());
 
 DI = getDerived().TransformType(DI);
-if (!DI) return true;
+if (!DI)
+  return true;
 
 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
 return false;
@@ -4390,9 +4391,8 @@ bool TreeTransform::TransformTemplateArgument(
 
 CXXScopeSpec SS;
 SS.Adopt(QualifierLoc);
-TemplateName Template
-  = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
-   Input.getTemplateNameLoc());
+TemplateName Template = getDerived().TransformTemplateName(
+SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
 if (Template.isNull())
   return true;
 
@@ -4414,11 +4414,13 @@ bool TreeTransform::TransformTemplateArgument(
 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
 
 Expr *InputExpr = Input.getSourceExpression();
-if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
+if (!InputExpr)
+  InputExpr = Input.getArgument().getAsExpr();
 
 ExprResult E = getDerived().TransformExpr(InputExpr);
 E = SemaRef.ActOnConstantExpression(E);
-if (E.isInvalid()) return true;
+if (E.isInvalid())
+  return true;
 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
 return false;
   }



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


[PATCH] D104604: [clang] NFC: add line break at the end of if expressions

2021-06-30 Thread Pengfei Wang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2fd75507d185: [clang] NFC: add line break at the end of if 
expressions (authored by zhouyizhou, committed by pengfei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104604

Files:
  clang/lib/Sema/TreeTransform.h


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4322,10 +4322,10 @@
   Arg, QualType(), getDerived().getBaseLocation());
 }
 
-template
+template 
 bool TreeTransform::TransformTemplateArgument(
- const TemplateArgumentLoc &Input,
- TemplateArgumentLoc &Output, bool 
Uneval) {
+const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
+bool Uneval) {
   const TemplateArgument &Arg = Input.getArgument();
   switch (Arg.getKind()) {
   case TemplateArgument::Null:
@@ -4374,7 +4374,8 @@
   DI = InventTypeSourceInfo(Input.getArgument().getAsType());
 
 DI = getDerived().TransformType(DI);
-if (!DI) return true;
+if (!DI)
+  return true;
 
 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
 return false;
@@ -4390,9 +4391,8 @@
 
 CXXScopeSpec SS;
 SS.Adopt(QualifierLoc);
-TemplateName Template
-  = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
-   Input.getTemplateNameLoc());
+TemplateName Template = getDerived().TransformTemplateName(
+SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
 if (Template.isNull())
   return true;
 
@@ -4414,11 +4414,13 @@
 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
 
 Expr *InputExpr = Input.getSourceExpression();
-if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
+if (!InputExpr)
+  InputExpr = Input.getArgument().getAsExpr();
 
 ExprResult E = getDerived().TransformExpr(InputExpr);
 E = SemaRef.ActOnConstantExpression(E);
-if (E.isInvalid()) return true;
+if (E.isInvalid())
+  return true;
 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
 return false;
   }


Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -4322,10 +4322,10 @@
   Arg, QualType(), getDerived().getBaseLocation());
 }
 
-template
+template 
 bool TreeTransform::TransformTemplateArgument(
- const TemplateArgumentLoc &Input,
- TemplateArgumentLoc &Output, bool Uneval) {
+const TemplateArgumentLoc &Input, TemplateArgumentLoc &Output,
+bool Uneval) {
   const TemplateArgument &Arg = Input.getArgument();
   switch (Arg.getKind()) {
   case TemplateArgument::Null:
@@ -4374,7 +4374,8 @@
   DI = InventTypeSourceInfo(Input.getArgument().getAsType());
 
 DI = getDerived().TransformType(DI);
-if (!DI) return true;
+if (!DI)
+  return true;
 
 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
 return false;
@@ -4390,9 +4391,8 @@
 
 CXXScopeSpec SS;
 SS.Adopt(QualifierLoc);
-TemplateName Template
-  = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
-   Input.getTemplateNameLoc());
+TemplateName Template = getDerived().TransformTemplateName(
+SS, Arg.getAsTemplate(), Input.getTemplateNameLoc());
 if (Template.isNull())
   return true;
 
@@ -4414,11 +4414,13 @@
 Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument);
 
 Expr *InputExpr = Input.getSourceExpression();
-if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
+if (!InputExpr)
+  InputExpr = Input.getArgument().getAsExpr();
 
 ExprResult E = getDerived().TransformExpr(InputExpr);
 E = SemaRef.ActOnConstantExpression(E);
-if (E.isInvalid()) return true;
+if (E.isInvalid())
+  return true;
 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
 return false;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355507.
kuhnel marked 4 inline comments as done.
kuhnel added a comment.

updated code examples based on Sam's review

Oh my, this is really simple if you know how it's supposed 
to work. However my intuition is completely off in trying to
understand the error handling. I hope the examples help
others avoid the pain.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,26 +165,24 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
-/// Helper marcro for checking the result of an 'Expected'
+/// Helper macro for checking the result of an 'Expected'
 ///
 ///   @code{.cpp}
 /// // function to be tested
 /// Expected myDivide(int A, int B);
 ///
 /// TEST(myDivideTests, GoodAndBad) {
-///   // test the good care
-///   auto D1 = myDivide(10, 5);
-///   // ensure the Error gets consumed in case the function fails by
-///   // calling 'toString()'. This also helps in debugging failing tests.
-///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
-/// "\n";
-///   EXPECT_THAT(*D1, Eq(2));
+///   // test good case
+///   // if you only care about successor failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
 ///
 ///   // test the error case
-///   auto D2 = myDivide(10, 0);
-///   EXPECT_THAT_EXPECTED(D2, Failed());
-///   // In the error case we need to consume the error.
-///   consumeError(D2.takeError());
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
 /// }
 ///   @endcode
 


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,26 +165,24 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
-/// Helper marcro for checking the result of an 'Expected'
+/// Helper macro for checking the result of an 'Expected'
 ///
 ///   @code{.cpp}
 /// // function to be tested
 /// Expected myDivide(int A, int B);
 ///
 /// TEST(myDivideTests, GoodAndBad) {
-///   // test the good care
-///   auto D1 = myDivide(10, 5);
-///   // ensure the Error gets consumed in case the function fails by
-///   // calling 'toString()'. This also helps in debugging failing tests.
-///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
-/// "\n";
-///   EXPECT_THAT(*D1, Eq(2));
+///   // test good case
+///   // if you only care about successor failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
 ///
 ///   // test the error case
-///   auto D2 = myDivide(10, 0);
-///   EXPECT_THAT_EXPECTED(D2, Failed());
-///   // In the error case we need to consume the error.
-///   consumeError(D2.takeError());
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
 /// }
 ///   @endcode
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355508.
kuhnel added a comment.

fixed typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,26 +165,24 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
-/// Helper marcro for checking the result of an 'Expected'
+/// Helper macro for checking the result of an 'Expected'
 ///
 ///   @code{.cpp}
 /// // function to be tested
 /// Expected myDivide(int A, int B);
 ///
 /// TEST(myDivideTests, GoodAndBad) {
-///   // test the good care
-///   auto D1 = myDivide(10, 5);
-///   // ensure the Error gets consumed in case the function fails by
-///   // calling 'toString()'. This also helps in debugging failing tests.
-///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
-/// "\n";
-///   EXPECT_THAT(*D1, Eq(2));
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
 ///
 ///   // test the error case
-///   auto D2 = myDivide(10, 0);
-///   EXPECT_THAT_EXPECTED(D2, Failed());
-///   // In the error case we need to consume the error.
-///   consumeError(D2.takeError());
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
 /// }
 ///   @endcode
 


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,26 +165,24 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
-/// Helper marcro for checking the result of an 'Expected'
+/// Helper macro for checking the result of an 'Expected'
 ///
 ///   @code{.cpp}
 /// // function to be tested
 /// Expected myDivide(int A, int B);
 ///
 /// TEST(myDivideTests, GoodAndBad) {
-///   // test the good care
-///   auto D1 = myDivide(10, 5);
-///   // ensure the Error gets consumed in case the function fails by
-///   // calling 'toString()'. This also helps in debugging failing tests.
-///   EXPECT_THAT_EXPECTED(D1, Succeeded()) << toString(D1.takeError()) <<
-/// "\n";
-///   EXPECT_THAT(*D1, Eq(2));
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
 ///
 ///   // test the error case
-///   auto D2 = myDivide(10, 0);
-///   EXPECT_THAT_EXPECTED(D2, Failed());
-///   // In the error case we need to consume the error.
-///   consumeError(D2.takeError());
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
 /// }
 ///   @endcode
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105014: added some example code for llvm::Expected

2021-06-30 Thread Christian Kühnel via Phabricator via cfe-commits
kuhnel updated this revision to Diff 355510.
kuhnel added a comment.

now fixing arc's way of git commits :(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105014

Files:
  llvm/include/llvm/Support/Error.h
  llvm/include/llvm/Testing/Support/Error.h


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,27 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)
\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper macro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
+///
+///   // test the error case
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) 
\
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) 
\
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() method for testing the
 /// error class type.
+///
+/// Example usage of 'Expected' as a function return type:
+///
+///   @code{.cpp}
+/// Expected myDivide(int A, int B) {
+///   if (B == 0) {
+/// // return an Error
+/// return createStringError(inconvertibleErrorCode(),
+///  "B must not be zero!");
+///   }
+///   // return an integer
+///   return A / B;
+/// }
+///   @endcode
+///
+///   Checking the results of to a function returning 'Expected':
+///   @code{.cpp}
+/// if (auto E = Result.takeError()) {
+///   // We must consume the error. Typically one of:
+///   // - return the error to our caller
+///   // - toString(), when logging
+///   // - consumeError(), to silently swallow the error
+///   // - handleErrors(), to distinguish error types
+///   errs() << "Problem with division " << toString(std::move(E)) << "\n";
+///   return;
+/// }
+/// // use the result
+/// outs() << "The answer is " << *Result << "\n";
+///   @endcode
+///
+///  For unit-testing a function returning an 'Expceted', see the
+///  'EXPECT_THAT_EXPECTED' macros in llvm/Testing/Support/Error.h
+
 template  class LLVM_NODISCARD Expected {
   template  friend class ExpectedAsOutParameter;
   template  friend class Expected;


Index: llvm/include/llvm/Testing/Support/Error.h
===
--- llvm/include/llvm/Testing/Support/Error.h
+++ llvm/include/llvm/Testing/Support/Error.h
@@ -165,6 +165,27 @@
 #define ASSERT_THAT_ERROR(Err, Matcher)\
   ASSERT_THAT(llvm::detail::TakeError(Err), Matcher)
 
+/// Helper macro for checking the result of an 'Expected'
+///
+///   @code{.cpp}
+/// // function to be tested
+/// Expected myDivide(int A, int B);
+///
+/// TEST(myDivideTests, GoodAndBad) {
+///   // test good case
+///   // if you only care about success or failure:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), Succeeded());
+///   // if you also care about the value:
+///   EXPECT_THAT_EXPECTED(myDivide(10, 5), HasValue(2));
+///
+///   // test the error case
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0), Failed());
+///   // also check the error message
+///   EXPECT_THAT_EXPECTED(myDivide(10, 0),
+///   FailedWithMessage("B must not be zero!"));
+/// }
+///   @endcode
+
 #define EXPECT_THAT_EXPECTED(Err, Matcher) \
   EXPECT_THAT(llvm::detail::TakeExpected(Err), Matcher)
 #define ASSERT_THAT_EXPECTED(Err, Matcher) \
Index: llvm/include/llvm/Support/Error.h
===
--- llvm/include/llvm/Support/Error.h
+++ llvm/include/llvm/Support/Error.h
@@ -436,6 +436,39 @@
 /// Error cannot be copied, this class replaces getError() with
 /// takeError(). It also adds an bool errorIsA() me

[PATCH] D105185: Add _AIX73 macro

2021-06-30 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan created this revision.
Herald added subscribers: kbarton, nemanjai.
Jake-Egan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105185

Files:
  clang/lib/Basic/Targets/OSTargets.h
  clang/test/Preprocessor/init-ppc.c

Index: clang/test/Preprocessor/init-ppc.c
===
--- clang/test/Preprocessor/init-ppc.c
+++ clang/test/Preprocessor/init-ppc.c
@@ -585,6 +585,20 @@
 // PPC-AIX:#define __powerpc__ 1
 // PPC-AIX:#define __ppc__ 1
 
+// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.3.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX73 %s
+//
+// PPC-AIX73:#define _AIX32 1
+// PPC-AIX73:#define _AIX41 1
+// PPC-AIX73:#define _AIX43 1
+// PPC-AIX73:#define _AIX50 1
+// PPC-AIX73:#define _AIX51 1
+// PPC-AIX73:#define _AIX52 1
+// PPC-AIX73:#define _AIX53 1
+// PPC-AIX73:#define _AIX61 1
+// PPC-AIX73:#define _AIX71 1
+// PPC-AIX73:#define _AIX72 1
+// PPC-AIX73:#define _AIX73 1
+
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.2.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX72 %s
 //
 // PPC-AIX72:#define _AIX32 1
@@ -597,6 +611,7 @@
 // PPC-AIX72:#define _AIX61 1
 // PPC-AIX72:#define _AIX71 1
 // PPC-AIX72:#define _AIX72 1
+// PPC-AIX72-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX71 %s
 //
@@ -610,6 +625,7 @@
 // PPC-AIX71:#define _AIX61 1
 // PPC-AIX71:#define _AIX71 1
 // PPC-AIX71-NOT:#define _AIX72 1
+// PPC-AIX71-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix6.1.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX61 %s
 //
@@ -623,6 +639,7 @@
 // PPC-AIX61:#define _AIX61 1
 // PPC-AIX61-NOT:#define _AIX71 1
 // PPC-AIX61-NOT:#define _AIX72 1
+// PPC-AIX61-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix5.3.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX53 %s
 // PPC-AIX53:#define _AIX32 1
@@ -635,6 +652,7 @@
 // PPC-AIX53-NOT:#define _AIX61 1
 // PPC-AIX53-NOT:#define _AIX71 1
 // PPC-AIX53-NOT:#define _AIX72 1
+// PPC-AIX53-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix5.2.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX52 %s
 // PPC-AIX52:#define _AIX32 1
@@ -647,6 +665,7 @@
 // PPC-AIX52-NOT:#define _AIX61 1
 // PPC-AIX52-NOT:#define _AIX71 1
 // PPC-AIX52-NOT:#define _AIX72 1
+// PPC-AIX52-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix5.1.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX51 %s
 // PPC-AIX51:#define _AIX32 1
@@ -659,6 +678,7 @@
 // PPC-AIX51-NOT:#define _AIX61 1
 // PPC-AIX51-NOT:#define _AIX71 1
 // PPC-AIX51-NOT:#define _AIX72 1
+// PPC-AIX51-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix5.0.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX50 %s
 // PPC-AIX50:#define _AIX32 1
@@ -671,6 +691,7 @@
 // PPC-AIX50-NOT:#define _AIX61 1
 // PPC-AIX50-NOT:#define _AIX71 1
 // PPC-AIX50-NOT:#define _AIX72 1
+// PPC-AIX50-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix4.3.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX43 %s
 // PPC-AIX43:#define _AIX32 1
@@ -683,6 +704,7 @@
 // PPC-AIX43-NOT:#define _AIX61 1
 // PPC-AIX43-NOT:#define _AIX71 1
 // PPC-AIX43-NOT:#define _AIX72 1
+// PPC-AIX43-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix4.1.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX41 %s
 // PPC-AIX41:#define _AIX32 1
@@ -695,6 +717,7 @@
 // PPC-AIX41-NOT:#define _AIX61 1
 // PPC-AIX41-NOT:#define _AIX71 1
 // PPC-AIX41-NOT:#define _AIX72 1
+// PPC-AIX41-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc-ibm-aix3.2.0.0 < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX32 %s
 // PPC-AIX32:#define _AIX32 1
@@ -707,6 +730,7 @@
 // PPC-AIX32-NOT:#define _AIX61 1
 // PPC-AIX32-NOT:#define _AIX71 1
 // PPC-AIX32-NOT:#define _AIX72 1
+// PPC-AIX32-NOT:#define _AIX73 1
 
 // RUN: %clang_cc1 -x c++ -E -dM -ffreestanding -triple=powerpc-ibm-aix7.1.0.0 -fno-signed-char < /dev/null | FileCheck -match-full-lines -check-prefix PPC-AIX-CXX %s
 //
Index: clang/lib/Basic/Targets/OSTargets.h
===
--- clang/lib/Basic/Targets/OSTargets.h
+++ clang/lib/Basic/Targets/OSTargets.h
@@ -700,6 +700,8 @@
 if (OsVersion >= std::make_pair(6, 1)) Builder.defineMacro("_AIX61");
 if (OsVersion >= std::make_pair(7, 1)) Builder.defineMacro("_AIX71");
 if (OsVersion >= std::make_pair(7, 2)) Builder.defineMacro("_AIX72");

[clang] f7ce532 - [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-30 Thread Saiyedul Islam via cfe-commits

Author: Saiyedul Islam
Date: 2021-06-30T17:55:50+05:30
New Revision: f7ce532d622dc26eddd25f87faec0ff35dc0c2e9

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

LOG: [clang-offload-bundler] Add unbundling of archives containing bundled 
object files into device specific archives

This patch adds unbundling support of an archive file. It takes an
archive file along with a set of offload targets as input.
Output is a device specific archive for each given offload target.
Input archive contains bundled code objects bundled using
clang-offload-bundler. Each generated device specific archive contains
a set of device code object files which are named as
-.

Entries in input archive can be of any binary type which is
supported by clang-offload-bundler, like *.bc. Output archives will
contain files in same type.

Example Usuage:
  clang-offload-bundler --unbundle --inputs=lib-generic.a -type=a
  -targets=openmp-amdgcn-amdhsa--gfx906,openmp-amdgcn-amdhsa--gfx908
  -outputs=devicelib-gfx906.a,deviceLib-gfx908.a

Reviewed By: jdoerfert, yaxunl

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

Added: 


Modified: 
clang/docs/ClangOffloadBundler.rst
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/clang-offload-bundler.c
clang/test/Driver/hip-rdc-device-only.hip
clang/test/Driver/hip-toolchain-rdc-separate.hip
clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Removed: 




diff  --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index 68c5116b235f4..c92d8a94cfb54 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -121,7 +121,15 @@ Where:
   = 
==
 
 **target-triple**
-  The target triple of the code object.
+The target triple of the code object:
+
+.. code::
+
+  ---
+
+It is required to have all four components present, if target-id is present.
+Components are hyphen separated. If a component is not specified then the
+empty string must be used in its place.
 
 **target-id**
   The canonical target ID of the code object. Present only if the target

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index c265e1c4e53cb..00939eae42998 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -7629,10 +7629,16 @@ void OffloadBundler::ConstructJob(Compilation &C, const 
JobAction &JA,
   });
 }
 Triples += Action::GetOffloadKindName(CurKind);
-Triples += '-';
-Triples += CurTC->getTriple().normalize();
-if (CurKind == Action::OFK_HIP && CurDep->getOffloadingArch()) {
-  Triples += '-';
+Triples += "-";
+std::string NormalizedTriple = CurTC->getTriple().normalize();
+Triples += NormalizedTriple;
+
+if (CurDep->getOffloadingArch() != nullptr) {
+  // If OffloadArch is present it can only appear as the 6th hypen
+  // sepearated field of Bundle Entry ID. So, pad required number of
+  // hyphens in Triple.
+  for (int i = 4 - StringRef(NormalizedTriple).count("-"); i > 0; i--)
+Triples += "-";
   Triples += CurDep->getOffloadingArch();
 }
   }
@@ -7702,11 +7708,17 @@ void OffloadBundler::ConstructJobMultipleOutputs(
 
 auto &Dep = DepInfo[I];
 Triples += Action::GetOffloadKindName(Dep.DependentOffloadKind);
-Triples += '-';
-Triples += Dep.DependentToolChain->getTriple().normalize();
-if (Dep.DependentOffloadKind == Action::OFK_HIP &&
-!Dep.DependentBoundArch.empty()) {
-  Triples += '-';
+Triples += "-";
+std::string NormalizedTriple =
+Dep.DependentToolChain->getTriple().normalize();
+Triples += NormalizedTriple;
+
+if (!Dep.DependentBoundArch.empty()) {
+  // If OffloadArch is present it can only appear as the 6th hypen
+  // sepearated field of Bundle Entry ID. So, pad required number of
+  // hyphens in Triple.
+  for (int i = 4 - StringRef(NormalizedTriple).count("-"); i > 0; i--)
+Triples += "-";
   Triples += Dep.DependentBoundArch;
 }
   }

diff  --git a/clang/test/Driver/clang-offload-bundler.c 
b/clang/test/Driver/clang-offload-bundler.c
index faa6c5161a8f9..e1afa19570ec3 100644
--- a/clang/test/Driver/clang-offload-bundler.c
+++ b/clang/test/Driver/clang-offload-bundler.c
@@ -46,6 +46,7 @@
 // CK-HELP: {{.*}}bc {{.*}}- llvm-bc
 // CK-HELP: {{.*}}s {{.*}}- assembler
 // CK-HELP: {{.*}}o {{.*}}- object
+// CK-HELP: {{.*}}a {{.*}}- archive of objects
 // CK-HELP: {{.*}}gch {{.*}}- precompiled-header
 // CK-HELP: {{.*}}ast {{.*}}- clang AST file
 // CK-HELP: {{.*}}-unbundle {{.*}}- Unbundle bundled file into several output 
files.
@@ -103,6 +104,9 @@

[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-30 Thread Saiyedul Islam via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf7ce532d622d: [clang-offload-bundler] Add unbundling of 
archives containing bundled object… (authored by saiislam).

Changed prior to commit:
  https://reviews.llvm.org/D93525?vs=354197&id=355514#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

Files:
  clang/docs/ClangOffloadBundler.rst
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/clang-offload-bundler.c
  clang/test/Driver/hip-rdc-device-only.hip
  clang/test/Driver/hip-toolchain-rdc-separate.hip
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -22,14 +22,18 @@
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/Object/Archive.h"
+#include "llvm/Object/ArchiveWriter.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/ObjectFile.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
@@ -82,6 +86,7 @@
"  bc  - llvm-bc\n"
"  s   - assembler\n"
"  o   - object\n"
+   "  a   - archive of objects\n"
"  gch - precompiled-header\n"
"  ast - clang AST file"),
   cl::cat(ClangOffloadBundlerCategory));
@@ -123,20 +128,49 @@
 /// Path to the current binary.
 static std::string BundlerExecutable;
 
-/// Obtain the offload kind and real machine triple out of the target
-/// information specified by the user.
-static void getOffloadKindAndTriple(StringRef Target, StringRef &OffloadKind,
-StringRef &Triple) {
-  auto KindTriplePair = Target.split('-');
-  OffloadKind = KindTriplePair.first;
-  Triple = KindTriplePair.second;
-}
-static bool hasHostKind(StringRef Target) {
+/// Obtain the offload kind, real machine triple, and an optional GPUArch
+/// out of the target information specified by the user.
+/// Bundle Entry ID (or, Offload Target String) has following components:
+///  * Offload Kind - Host, OpenMP, or HIP
+///  * Triple - Standard LLVM Triple
+///  * GPUArch (Optional) - Processor name, like gfx906 or sm_30
+/// In presence of Proc, the Triple should contain separator "-" for all
+/// standard four components, even if they are empty.
+struct OffloadTargetInfo {
   StringRef OffloadKind;
-  StringRef Triple;
-  getOffloadKindAndTriple(Target, OffloadKind, Triple);
-  return OffloadKind == "host";
-}
+  llvm::Triple Triple;
+  StringRef GPUArch;
+
+  OffloadTargetInfo(const StringRef Target) {
+SmallVector Components;
+Target.split(Components, '-', 5);
+Components.resize(6);
+this->OffloadKind = Components[0];
+this->Triple = llvm::Triple(Components[1], Components[2], Components[3],
+Components[4]);
+this->GPUArch = Components[5];
+  }
+
+  bool hasHostKind() const { return this->OffloadKind == "host"; }
+
+  bool isOffloadKindValid() const {
+return OffloadKind == "host" || OffloadKind == "openmp" ||
+   OffloadKind == "hip" || OffloadKind == "hipv4";
+  }
+
+  bool isTripleValid() const {
+return !Triple.str().empty() && Triple.getArch() != Triple::UnknownArch;
+  }
+
+  bool operator==(const OffloadTargetInfo &Target) const {
+return OffloadKind == Target.OffloadKind &&
+   Triple.isCompatibleWith(Target.Triple) && GPUArch == Target.GPUArch;
+  }
+
+  std::string str() {
+return Twine(OffloadKind + "-" + Triple.str() + "-" + GPUArch).str();
+  }
+};
 
 /// Generic file handler interface.
 class FileHandler {
@@ -163,7 +197,7 @@
   virtual Error ReadBundleEnd(MemoryBuffer &Input) = 0;
 
   /// Read the current bundle and write the result into the stream \a OS.
-  virtual Error ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) = 0;
+  virtual Error ReadBundle(raw_ostream &OS, MemoryBuffer &Input) = 0;
 
   /// Write the header of the bundled file to \a OS based on the information
   /// gathered from \a Inputs.
@@ -378,7 +412,7 @@
 return Error::success();
   }
 
-  Error ReadBundle(raw_fd_ostream &OS, MemoryBuffer &Input) final {
+  Error ReadBundle(raw_ostream &OS, MemoryBuffer &Inp

[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-30 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added a comment.

@yaxunl 
this patch on its own is failing in our internal CI. I have an internal patch 
(542569) to integrate it cleanly there.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

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


[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-30 Thread George Rokos via Phabricator via cfe-commits
grokos added inline comments.



Comment at: clang/docs/ClangOffloadBundler.rst:128
+
+  ---
+

A bit of wordplay, but it's weird that a *triple* now has 4 elements...



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:147
+Target.split(Components, '-', 5);
+Components.resize(6);
+this->OffloadKind = Components[0];

Leftover? `Components` is already 6 elements long.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:1102
+/// compatible with this code object
+/// @param [in] Code Object \p CodeObject
+/// @param [out] List of all compatible targets \p CompatibleTargets among all

`CodeObject` --> `CodeObjectInfo`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

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


[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-06-30 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp:1138
+
+Ops[0] = TableSet; // The new chain is the TableSet itself
+  }

sbc100 wrote:
> I was expecting to see a TABLE_SET back to a null after the call here to 
> avoid the GC root being leaked in table slot 0 (as above).   I must be 
> missing something?
@sbc100, that's what's happening in line 583.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

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


[PATCH] D105167: [analyzer] Fix HTML report deduplication.

2021-06-30 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

AFAIK from CodeChecker's side we are fine with this change. I think we are not 
using the `stable-report-filename` analyzer config either.
Aside from these, the less //Perl// the better, I guess.




Comment at: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp:277
+
+  std::stringstream filename;
+  filename << "report-";

I don't frequently see `stringstream`s in the codebase.
Why don't you use the llvm alternative?
```
std::string s;
llvm::raw_string_ostream os(s);
```


Repository:
  rC Clang

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

https://reviews.llvm.org/D105167

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


[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-06-30 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:130
 TT.isArch64Bit()
-? "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1"
-: "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1",
+? (hasReferenceTypes(FS)
+   ? 
"e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20"

tlively wrote:
> pmatos wrote:
> > tlively wrote:
> > > `hasReferenceTypes` should also be taking the CPU into account, not just 
> > > the feature string. Normally this would be done via `getSubtargetImpl`, 
> > > but I guess we probably can't call that this early in the construction of 
> > > the `WebAssemblyTargetMachine`. Would anything break if we just 
> > > unconditionally added the reference types address spaces to the data 
> > > layout string?
> > Regarding this change, I don't quite understand why referencetypes should 
> > take the CPU into account. Are there CPU variants for the wasm backend? I 
> > haven't touched the conditional because that would mean touching the 
> > several tests that don't enable reference types and use the old data layout 
> > string. However, I would think that if that's the path we want to follow 
> > here, we could do it and change all wasm tests to use the layout string 
> > with reference types.
> > 
> Yes, there are CPU variants defined here: 
> https://github.com/llvm/llvm-project/blob/7ac0442fe59dbe0f9127e79e8786a7dd6345c537/llvm/lib/Target/WebAssembly/WebAssembly.td#L89-L100.
>  Note that the CPU may enable reference types even if the feature string does 
> not. If it doesn't break anything, then unconditionally updating the layout 
> string sounds like the best option.
Interesting - had not come accross it. Bleeding edge does not seem to include 
reference-types. What's the reason for this? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

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


[PATCH] D105142: RFC: Implementing new mechanism for hard register operands to inline asm as a constraint.

2021-06-30 Thread David Chisnall via Phabricator via cfe-commits
theraven added a comment.

The code looks fine but it would be good to see some docs along with it.  We're 
currently missing docs on inline assembly entirely and the GCC ones are 
somewhat... opaque when it comes to describing how constraints work.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105142

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


[PATCH] D105185: [AIX] Add _AIX73 version macro

2021-06-30 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta accepted this revision.
xgupta added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/lib/Basic/Targets/OSTargets.h:704
+if (OsVersion >= std::make_pair(7, 3))
+  Builder.defineMacro("_AIX73");
 

Seems this line need formatting?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105185

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


[PATCH] D105185: [AIX] Add _AIX73 version macro

2021-06-30 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:704
+if (OsVersion >= std::make_pair(7, 3))
+  Builder.defineMacro("_AIX73");
 

xgupta wrote:
> Seems this line need formatting?
I originally had it matching the format of the other _AIX macro definitions, 
but clang-format modified it to this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105185

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


[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

2021-06-30 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

+1 for note tags.




Comment at: clang/test/Analysis/stream-note.c:134
+
+void check_eof_notes_3() {
+  FILE *F;

Perhaps we could have some more explanatory test case names. I mean how _3 is 
different than _2? What is the case each of them exactly tests?



Comment at: clang/test/Analysis/stream-note.c:141
+  int RRet = fread(Buf, 1, 1, F); // expected-note {{Assuming that stream 
reaches end-of-file here}}
+  if (ferror(F)) {// expected-note {{End-of-file status is 
discovered here}} expected-note {{Taking false branch}}
+  } else {

Strictly speaking it is not necessarily and end-of-file status, `ferror` 
indicates if there was an error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104925

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


[PATCH] D105185: [AIX] Add _AIX73 version macro

2021-06-30 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:704
+if (OsVersion >= std::make_pair(7, 3))
+  Builder.defineMacro("_AIX73");
 

Jake-Egan wrote:
> xgupta wrote:
> > Seems this line need formatting?
> I originally had it matching the format of the other _AIX macro definitions, 
> but clang-format modified it to this.
I think clang-format is there to maintain consistency in the codebase. You can 
ignore it if it is doing the opposite.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105185

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


[PATCH] D105167: [analyzer] Fix HTML report deduplication.

2021-06-30 Thread Valeriy Savchenko via Phabricator via cfe-commits
vsavchenko accepted this revision.
vsavchenko added a comment.
This revision is now accepted and ready to land.

This is incredible!  Thanks for addressing it!  I've encountered this many 
times.




Comment at: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp:277
+
+  std::stringstream filename;
+  filename << "report-";

steakhal wrote:
> I don't frequently see `stringstream`s in the codebase.
> Why don't you use the llvm alternative?
> ```
> std::string s;
> llvm::raw_string_ostream os(s);
> ```
nit: whatever stream you choose, can you please start it with a capital letter? 
💅



Comment at: clang/lib/StaticAnalyzer/Core/HTMLDiagnostics.cpp:286-287
+  // but the stable report filename is still more verbose.
+  // We should rename the option ("verbose" filename?) but it will break
+  // people's workflows.
+  if (DiagOpts.ShouldWriteStableReportFilename) {

Can we make a mirror for this option and mark the other one as deprecated?


Repository:
  rC Clang

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

https://reviews.llvm.org/D105167

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


[PATCH] D105191: [Clang][OpenMP] Add support for Static Device Libraries

2021-06-30 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam created this revision.
saiislam added reviewers: jdoerfert, ABataev, JonChesterfield, grokos.
Herald added subscribers: kerbowa, guansong, yaxunl, nhaehnle, jvesely.
saiislam requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

An archive containing device code object files can be passed to
clang command line for linking. For each given offload target
it creates a device specific archives and passes it to llvm-link.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105191

Files:
  clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.h
  clang/lib/Driver/ToolChains/Cuda.cpp

Index: clang/lib/Driver/ToolChains/Cuda.cpp
===
--- clang/lib/Driver/ToolChains/Cuda.cpp
+++ clang/lib/Driver/ToolChains/Cuda.cpp
@@ -632,6 +632,9 @@
 CmdArgs.push_back(CubinF);
   }
 
+  AddStaticDeviceLibs(C, *this, JA, Inputs, Args, CmdArgs, "nvptx", GPUArch,
+  false, false);
+
   const char *Exec =
   Args.MakeArgString(getToolChain().GetProgramPath("nvlink"));
   C.addCommand(std::make_unique(
@@ -754,6 +757,8 @@
 std::string BitcodeSuffix = "nvptx-" + GpuArch.str();
 addOpenMPDeviceRTL(getDriver(), DriverArgs, CC1Args, BitcodeSuffix,
getTriple());
+AddStaticDeviceLibs(getDriver(), DriverArgs, CC1Args, "nvptx", GpuArch,
+/* bitcode SDL?*/ true, /* PostClang Link? */ true);
   }
 }
 
Index: clang/lib/Driver/ToolChains/CommonArgs.h
===
--- clang/lib/Driver/ToolChains/CommonArgs.h
+++ clang/lib/Driver/ToolChains/CommonArgs.h
@@ -49,6 +49,38 @@
 llvm::opt::ArgStringList &CmdArgs,
 const llvm::opt::ArgList &Args);
 
+void AddStaticDeviceLibs(Compilation &C, const Tool &T, const JobAction &JA,
+ const InputInfoList &Inputs,
+ const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CmdArgs, StringRef ArchName,
+ StringRef GPUArch, bool isBitCodeSDL,
+ bool postClangLink);
+void AddStaticDeviceLibs(const Driver &D, const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CmdArgs, StringRef ArchName,
+ StringRef GPUArch, bool isBitCodeSDL,
+ bool postClangLink);
+void AddStaticDeviceLibs(Compilation *C, const Tool *T, const JobAction *JA,
+ const InputInfoList *Inputs, const Driver &D,
+ const llvm::opt::ArgList &DriverArgs,
+ llvm::opt::ArgStringList &CmdArgs, StringRef ArchName,
+ StringRef GPUArch, bool isBitCodeSDL,
+ bool postClangLink);
+
+bool SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs,
+   llvm::opt::ArgStringList &CmdArgs,
+   SmallVector LibraryPaths, std::string libname,
+   StringRef ArchName, StringRef GPUArch, bool isBitCodeSDL,
+   bool postClangLink);
+
+bool GetSDLFromOffloadArchive(Compilation &C, const Driver &D, const Tool &T,
+  const JobAction &JA, const InputInfoList &Inputs,
+  const llvm::opt::ArgList &DriverArgs,
+  llvm::opt::ArgStringList &CC1Args,
+  SmallVector LibraryPaths,
+  std::string libname, StringRef ArchName,
+  StringRef GPUArch, bool isBitCodeSDL,
+  bool postClangLink);
+
 const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
const InputInfo &Input, const InputInfo &Output);
 
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1587,6 +1587,236 @@
   }
 }
 
+/// SDLSearch: Search for Static Device Library
+bool tools::SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs,
+  llvm::opt::ArgStringList &CC1Args,
+  SmallVector LibraryPaths,
+  std::string libname, StringRef ArchName,
+  StringRef GPUArch, bool isBitCodeSDL,
+  bool postClangLink) {
+  std::string archname = ArchName.str();
+  std::string Target = GPUArch.str();
+
+  SmallVector SDL_FileNames;
+  if (isBitCodeSDL) {
+// For bitcode SDL, search for these 12 relative SDL filenames
+SDL_FileNames.push_back(std::string("/libdevice/libbc-" + libname + "-" +
+archname + "-

[clang] e773216 - [clang][patch] Add builtin __arithmetic_fence and option fprotect-parens

2021-06-30 Thread Melanie Blower via cfe-commits

Author: Melanie Blower
Date: 2021-06-30T09:58:06-04:00
New Revision: e773216f46368cd927a3c67bfa2516913acb75e7

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

LOG: [clang][patch] Add builtin __arithmetic_fence and option fprotect-parens

This patch adds a new clang builtin, __arithmetic_fence. The purpose of the
builtin is to provide the user fine control, at the expression level, over
floating point optimization when -ffast-math (-ffp-model=fast) is enabled.
The builtin prevents the optimizer from rearranging floating point expression
evaluation. The new option fprotect-parens has the same effect on
parenthesized expressions, forcing the optimizer to respect the parentheses.

Reviewed By: aaron.ballman, kpn

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

Added: 
clang/test/AST/arithmetic-fence-builtin.c
clang/test/CodeGen/arithmetic-fence-builtin.c
clang/test/Sema/arithmetic-fence-builtin.c

Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/Builtins.def
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/TargetInfo.h
clang/include/clang/Driver/Options.td
clang/include/clang/Sema/Sema.h
clang/lib/AST/ExprConstant.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/Driver/clang_f_opts.c

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 244212a1336db..9e8bac635337e 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1478,6 +1478,26 @@ Note that floating-point operations performed as part of 
constant initialization
* ``maytrap`` The compiler avoids transformations that may raise exceptions 
that would not have been raised by the original code. Constant folding 
performed by the compiler is exempt from this option.
* ``strict`` The compiler ensures that all transformations strictly 
preserve the floating point exception semantics of the original code.
 
+.. option:: -f[no-]protect-parens:
+
+   This option pertains to floating-point types, complex types with
+   floating-point components, and vectors of these types. Some arithmetic
+   expression transformations that are mathematically correct and permissible
+   according to the C and C++ language standards may be incorrect when dealing
+   with floating-point types, such as reassociation and distribution. Further,
+   the optimizer may ignore parentheses when computing arithmetic expressions
+   in circumstances where the parenthesized and unparenthesized expression
+   express the same mathematical value. For example (a+b)+c is the same
+   mathematical value as a+(b+c), but the optimizer is free to evaluate the 
+   additions in any order regardless of the parentheses. When enabled, this
+   option forces the optimizer to honor the order of operations with respect
+   to parentheses in all circumstances.
+
+   Note that floating-point contraction (option `-ffp-contract=`) is disabled
+   when `-fprotect-parens` is enabled.  Also note that in safe floating-point
+   modes, such as `-ffp-model=precise` or `-ffp-model=strict`, this option
+   has no effect because the optimizer is prohibited from making unsafe
+   transformations.
 
 .. _fp-constant-eval:
 

diff  --git a/clang/include/clang/Basic/Builtins.def 
b/clang/include/clang/Basic/Builtins.def
index 5a9d0a0018292..33d3e6dc4e7db 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -1657,6 +1657,9 @@ BUILTIN(__builtin_ms_va_start, "vc*&.", "nt")
 BUILTIN(__builtin_ms_va_end, "vc*&", "n")
 BUILTIN(__builtin_ms_va_copy, "vc*&c*&", "n")
 
+// Arithmetic Fence: to prevent FP reordering and reassociation optimizations
+LANGBUILTIN(__arithmetic_fence, "v.", "t", ALL_LANGUAGES)
+
 #undef BUILTIN
 #undef LIBBUILTIN
 #undef LANGBUILTIN

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 70a22fd2506a3..22c2a1a39ea13 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8530,6 +8530,9 @@ def err_typecheck_expect_scalar_operand : Error<
   "operand of type %0 where arithmetic or pointer type is required">;
 def err_typecheck_cond_incompatible_operands : Error<
   "incompatible operand types%
diff { ($ and $)|}0,1">;
+def err_typecheck_expect_flt_or_vector : Error<
+  "invalid operand of type %0 where floating, complex or "
+  "a vector of such types is required">;
 def err_cast_selector_expr : 

[PATCH] D100118: [clang] Add support for new builtin __arithmetic_fence to control floating point optimization, and new clang option fprotect-parens

2021-06-30 Thread Melanie Blower via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe773216f4636: [clang][patch] Add builtin __arithmetic_fence 
and option fprotect-parens (authored by mibintc).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100118

Files:
  clang/docs/UsersManual.rst
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Basic/TargetInfo.h
  clang/include/clang/Driver/Options.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Basic/TargetInfo.cpp
  clang/lib/Basic/Targets/X86.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/AST/arithmetic-fence-builtin.c
  clang/test/CodeGen/arithmetic-fence-builtin.c
  clang/test/Driver/clang_f_opts.c
  clang/test/Sema/arithmetic-fence-builtin.c

Index: clang/test/Sema/arithmetic-fence-builtin.c
===
--- /dev/null
+++ clang/test/Sema/arithmetic-fence-builtin.c
@@ -0,0 +1,48 @@
+// RUN: %clang_cc1 -triple i386-pc-linux-gnu -emit-llvm -o - -verify -x c++ %s
+// RUN: %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -verify -x c++ %s
+// RUN: not %clang_cc1 -triple ppc64le -DPPC -emit-llvm -o - -x c++ %s \
+// RUN:-fprotect-parens 2>&1 | FileCheck -check-prefix=PPC %s
+#ifndef PPC
+int v;
+template  T addT(T a, T b) {
+  T *q = __arithmetic_fence(&a);
+  // expected-error@-1 {{invalid operand of type 'float *' where floating, complex or a vector of such types is required}}
+  // expected-error@-2 {{invalid operand of type 'int *' where floating, complex or a vector of such types is required}}
+  return __arithmetic_fence(a + b);
+  // expected-error@-1 {{invalid operand of type 'int' where floating, complex or a vector of such types is required}}
+}
+int addit(int a, int b) {
+  float x, y;
+  typedef struct {
+int a, b;
+  } stype;
+  stype s;
+  s = __arithmetic_fence(s);// expected-error {{invalid operand of type 'stype' where floating, complex or a vector of such types is required}}
+  x = __arithmetic_fence(); // expected-error {{too few arguments to function call, expected 1, have 0}}
+  x = __arithmetic_fence(x, y); // expected-error {{too many arguments to function call, expected 1, have 2}}
+  // Complex is supported.
+  _Complex double cd, cd1;
+  cd = __arithmetic_fence(cd1);
+  // Vector is supported.
+  typedef float __v4hi __attribute__((__vector_size__(8)));
+  __v4hi vec1, vec2;
+  vec1 = __arithmetic_fence(vec2);
+
+  v = __arithmetic_fence(a + b); // expected-error {{invalid operand of type 'int' where floating, complex or a vector of such types is required}}
+  float f = addT(a, b);   // expected-note {{in instantiation of function template specialization 'addT' requested here}}
+  int i = addT(1, 2);   // expected-note {{in instantiation of function template specialization 'addT' requested here}}
+  constexpr float d = 1.0 + 2.0;
+  constexpr float c = __arithmetic_fence(1.0 + 2.0);
+  constexpr float e = __arithmetic_fence(d);
+  return 0;
+}
+bool func(float f1, float f2, float f3) {
+  return (f1 == f2 && f1 == f3) || f2 == f3; // Should not warn here
+}
+static_assert( __arithmetic_fence(1.0 + 2.0), "message" );
+#else
+float addit(float a, float b) {
+  return __arithmetic_fence(a+b); // expected-error {{builtin is not supported on this target}}
+}
+#endif
+//PPC: error: option '-fprotect-parens' cannot be specified on this target
Index: clang/test/Driver/clang_f_opts.c
===
--- clang/test/Driver/clang_f_opts.c
+++ clang/test/Driver/clang_f_opts.c
@@ -1,13 +1,14 @@
 // REQUIRES: clang-driver
 
 // RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon -fpascal-strings -fno-blocks -fno-builtin -fmath-errno -fno-common -fno-pascal-strings -fblocks -fbuiltin -fmath-errno -fcommon -fpascal-strings -fsplit-stack %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS1 %s
-// RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon -fpascal-strings -fno-asm -fno-blocks -fno-builtin -fmath-errno -fno-common -fno-pascal-strings -fno-show-source-location -fshort-enums %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS2 %s
+// RUN: %clang -### -S -fasm -fblocks -fbuiltin -fno-math-errno -fcommon -fpascal-strings -fno-asm -fno-blocks -fno-builtin -fmath-errno -fno-common -fno-pascal-strings -fno-show-source-location -fshort-enums -fprotect-parens %s 2>&1 | FileCheck -check-prefix=CHECK-OPTIONS2 %s
 
 // CHECK-OPTIONS1: -fsplit-stack
 // CHECK-OPTIONS1: -fgnu-keywords
 // CHECK-OPTIONS1: -fblocks
 // CHECK-OPTIONS1: -fpascal-strings
 
+// CHECK-OPTIONS2: -fprotect-parens
 // CHECK-OPTIONS2: -fmath-errno
 // C

[PATCH] D105185: [AIX] Add _AIX73 version macro

2021-06-30 Thread Jake Egan via Phabricator via cfe-commits
Jake-Egan added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:704
+if (OsVersion >= std::make_pair(7, 3))
+  Builder.defineMacro("_AIX73");
 

xgupta wrote:
> Jake-Egan wrote:
> > xgupta wrote:
> > > Seems this line need formatting?
> > I originally had it matching the format of the other _AIX macro 
> > definitions, but clang-format modified it to this.
> I think clang-format is there to maintain consistency in the codebase. You 
> can ignore it if it is doing the opposite.
Do you suggest that I revise the formatting then?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105185

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


[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

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

In D93525#2849815 , @saiislam wrote:

> @yaxunl 
> this patch on its own is failing in our internal CI. I have an internal patch 
> (542569) to integrate it cleanly there.

Fine. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

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


[PATCH] D105187: [OPENMP]Fix PR50640: OpenMP target clause implicitly scaling loop bounds to uint64_t.

2021-06-30 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 accepted this revision.
jhuber6 added a comment.
This revision is now accepted and ready to land.

LGTM, work on my end.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105187

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


[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-06-30 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff updated this revision to Diff 355539.
sepavloff added a comment.
Herald added subscribers: kbarton, nemanjai.

Addressed reviewer's notes

- Math flags are set when ISNAN node is transformed,
- They are set in calls to getNode,
- WidenVecOp_ISNAN is made similar to WidenVecOp_SETCC,
- Building ISNAN node was changed,
- Fixed error in comment,
- Removed extra shift.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/X86/strictfp_builtins.c
  clang/test/CodeGen/aarch64-strictfp-builtins.c
  clang/test/CodeGen/strictfp_builtins.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/CodeGen/ISDOpcodes.h
  llvm/include/llvm/CodeGen/TargetLowering.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
  llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
  llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/lib/CodeGen/TargetLoweringBase.cpp
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/AArch64/aarch64-fpclass.ll
  llvm/test/CodeGen/PowerPC/ppc-fpclass.ll
  llvm/test/CodeGen/X86/x86-fpclass.ll
  llvm/test/Transforms/InstSimplify/ConstProp/fpclassify.ll

Index: llvm/test/Transforms/InstSimplify/ConstProp/fpclassify.ll
===
--- /dev/null
+++ llvm/test/Transforms/InstSimplify/ConstProp/fpclassify.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define i1 @isnan_01() {
+entry:
+  %0 = tail call i1 @llvm.isnan.f32(float 0x7FF8)
+  ret i1 %0
+}
+; CHECK-LABEL: isnan_01
+; CHECK:   ret i1 true 
+
+define i1 @isnan_02() {
+entry:
+  %0 = tail call i1 @llvm.isnan.f32(float 0x7FF0)
+  ret i1 %0
+}
+; CHECK-LABEL: isnan_02
+; CHECK:   ret i1 false 
+
+define <4 x i1> @isnan_03() {
+entry:
+  %0 = tail call <4 x i1> @llvm.isnan.v4f32(<4 x float>)
+  ret <4 x i1> %0
+}
+; CHECK-LABEL: isnan_03
+; CHECK:   ret <4 x i1> 
+
+declare i1 @llvm.isnan.f32(float)
+declare <4 x i1> @llvm.isnan.v4f32(<4 x float>)
Index: llvm/test/CodeGen/X86/x86-fpclass.ll
===
--- /dev/null
+++ llvm/test/CodeGen/X86/x86-fpclass.ll
@@ -0,0 +1,655 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=i686 | FileCheck %s -check-prefix=CHECK-32
+; RUN: llc < %s -mtriple=x86_64 | FileCheck %s -check-prefix=CHECK-64
+
+define i1 @isnan_float(float %x) {
+; CHECK-32-LABEL: isnan_float:
+; CHECK-32:   # %bb.0: # %entry
+; CHECK-32-NEXT:flds {{[0-9]+}}(%esp)
+; CHECK-32-NEXT:fucomp %st(0)
+; CHECK-32-NEXT:fnstsw %ax
+; CHECK-32-NEXT:# kill: def $ah killed $ah killed $ax
+; CHECK-32-NEXT:sahf
+; CHECK-32-NEXT:setp %al
+; CHECK-32-NEXT:retl
+;
+; CHECK-64-LABEL: isnan_float:
+; CHECK-64:   # %bb.0: # %entry
+; CHECK-64-NEXT:ucomiss %xmm0, %xmm0
+; CHECK-64-NEXT:setp %al
+; CHECK-64-NEXT:retq
+; NOSSE-32-LABEL: isnan_float:
+entry:
+  %0 = tail call i1 @llvm.isnan.f32(float %x)
+  ret i1 %0
+}
+
+define i1 @isnan_double(double %x) {
+; CHECK-32-LABEL: isnan_double:
+; CHECK-32:   # %bb.0: # %entry
+; CHECK-32-NEXT:fldl {{[0-9]+}}(%esp)
+; CHECK-32-NEXT:fucomp %st(0)
+; CHECK-32-NEXT:fnstsw %ax
+; CHECK-32-NEXT:# kill: def $ah killed $ah killed $ax
+; CHECK-32-NEXT:sahf
+; CHECK-32-NEXT:setp %al
+; CHECK-32-NEXT:retl
+;
+; CHECK-64-LABEL: isnan_double:
+; CHECK-64:   # %bb.0: # %entry
+; CHECK-64-NEXT:ucomisd %xmm0, %xmm0
+; CHECK-64-NEXT:setp %al
+; CHECK-64-NEXT:retq
+entry:
+  %0 = tail call i1 @llvm.isnan.f64(double %x)
+  ret i1 %0
+}
+
+define i1 @isnan_ldouble(x86_fp80 %x) {
+; CHECK-32-LABEL: isnan_ldouble:
+; CHECK-32:   # %bb.0: # %entry
+; CHECK-32-NEXT:fldt {{[0-9]+}}(%esp)
+; CHECK-32-NEXT:fxam
+; CHECK-32-NEXT:fstp %st(0)
+; CHECK-32-NEXT:fnstsw %ax
+; CHECK-32-NEXT:andb $69, %ah
+; CHECK-32-NEXT:cmpb $1, %ah
+; CHECK-32-NEXT:sete %al
+; CHECK-32-NEXT:retl
+;
+; CHECK-64-LABEL: isnan_ldouble:
+; CHECK-64:   # %bb.0: # %entry
+; CHECK-64-NEXT:fldt {{[0-9]+}}(%rsp)
+; CHECK-64-NEXT:fxam
+; CHECK-64-NEXT:fstp %st(0)
+; CHECK-64-NEXT:fnstsw %ax
+; CHECK-64-NEXT:andb $69, %ah
+; CHECK-64-NEXT:cmpb $1, %ah
+; CHECK-64-NEXT:sete %al
+; CHECK-64-NEXT:retq
+entry:
+  %0 = tail call i1 @llvm.isnan.f80(x86_fp80 %x)
+  ret i1 %0
+}
+
+define i1 @isnan_float_strictfp(float %x) strictfp {
+; CHECK-32-LABEL: isnan_float_strictfp:
+; CHECK-32:   # %bb.0: # %entry
+; CHECK-32-NEXT:movl $2147483647, %eax 

[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-30 Thread Saiyedul Islam via Phabricator via cfe-commits
saiislam added inline comments.



Comment at: clang/docs/ClangOffloadBundler.rst:128
+
+  ---
+

grokos wrote:
> A bit of wordplay, but it's weird that a *triple* now has 4 elements...
I think llvm::Triple it is named Triple because of historical reasons. 
Otherwise, it already has these components (including the environment).
As llvm::Triple API's don't force presence of all components it is not an issue 
in most cases, but in our case of Bundle Entry ID we need a way to 
differentiate between 4th component of Triple and a GPU arch, hence this rule.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:147
+Target.split(Components, '-', 5);
+Components.resize(6);
+this->OffloadKind = Components[0];

grokos wrote:
> Leftover? `Components` is already 6 elements long.
Not necessarily. It is possible that target has less than 6 elements. For 
example all bundling/unbundling cases which do not require GPUArch field.
E.g. "openmp-powerpc64le-ibm-linux-gnu"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

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


[PATCH] D105194: [PowerPC] Add PowerPC cmpb builtin and emit target indepedent code for XL compatibility

2021-06-30 Thread Victor Huang via Phabricator via cfe-commits
NeHuang created this revision.
NeHuang added reviewers: nemanjai, stefanp, lei, PowerPC.
NeHuang added a project: LLVM.
Herald added subscribers: shchenz, kbarton.
NeHuang requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch is in a series of patches to provide builtins for compatibility
with the XL compiler. This patch add the builtin and emit target independent
code for __cmpb.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105194

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-ppc-xlcompat-compare.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat-compare.c
===
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat-compare.c
@@ -0,0 +1,56 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// RUN: %clang_cc1 -triple powerpc64-unknown-unknown \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-unknown \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr8 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc-unknown-aix \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64-unknown-aix \
+// RUN:   -emit-llvm %s -o - -target-cpu pwr7 | FileCheck %s
+
+// CHECK-LABEL: @test_builtin_ppc_cmpb(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[LLA_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:[[LLB_ADDR:%.*]] = alloca i64, align 8
+// CHECK-NEXT:store i64 [[LLA:%.*]], i64* [[LLA_ADDR]], align 8
+// CHECK-NEXT:store i64 [[LLB:%.*]], i64* [[LLB_ADDR]], align 8
+// CHECK-NEXT:[[TMP0:%.*]] = load i64, i64* [[LLA_ADDR]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load i64, i64* [[LLB_ADDR]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = xor i64 [[TMP0]], [[TMP1]]
+// CHECK-NEXT:[[TMP3:%.*]] = and i64 [[TMP2]], 255
+// CHECK-NEXT:[[TMP4:%.*]] = icmp eq i64 [[TMP3]], 0
+// CHECK-NEXT:[[TMP5:%.*]] = select i1 [[TMP4]], i64 255, i64 0
+// CHECK-NEXT:[[TMP6:%.*]] = or i64 0, [[TMP5]]
+// CHECK-NEXT:[[TMP7:%.*]] = and i64 [[TMP2]], 65280
+// CHECK-NEXT:[[TMP8:%.*]] = icmp eq i64 [[TMP7]], 0
+// CHECK-NEXT:[[TMP9:%.*]] = select i1 [[TMP8]], i64 65280, i64 0
+// CHECK-NEXT:[[TMP10:%.*]] = or i64 [[TMP6]], [[TMP9]]
+// CHECK-NEXT:[[TMP11:%.*]] = and i64 [[TMP2]], 16711680
+// CHECK-NEXT:[[TMP12:%.*]] = icmp eq i64 [[TMP11]], 0
+// CHECK-NEXT:[[TMP13:%.*]] = select i1 [[TMP12]], i64 16711680, i64 0
+// CHECK-NEXT:[[TMP14:%.*]] = or i64 [[TMP10]], [[TMP13]]
+// CHECK-NEXT:[[TMP15:%.*]] = and i64 [[TMP2]], 4278190080
+// CHECK-NEXT:[[TMP16:%.*]] = icmp eq i64 [[TMP15]], 0
+// CHECK-NEXT:[[TMP17:%.*]] = select i1 [[TMP16]], i64 4278190080, i64 0
+// CHECK-NEXT:[[TMP18:%.*]] = or i64 [[TMP14]], [[TMP17]]
+// CHECK-NEXT:[[TMP19:%.*]] = and i64 [[TMP2]], 1095216660480
+// CHECK-NEXT:[[TMP20:%.*]] = icmp eq i64 [[TMP19]], 0
+// CHECK-NEXT:[[TMP21:%.*]] = select i1 [[TMP20]], i64 1095216660480, i64 0
+// CHECK-NEXT:[[TMP22:%.*]] = or i64 [[TMP18]], [[TMP21]]
+// CHECK-NEXT:[[TMP23:%.*]] = and i64 [[TMP2]], 280375465082880
+// CHECK-NEXT:[[TMP24:%.*]] = icmp eq i64 [[TMP23]], 0
+// CHECK-NEXT:[[TMP25:%.*]] = select i1 [[TMP24]], i64 280375465082880, i64 0
+// CHECK-NEXT:[[TMP26:%.*]] = or i64 [[TMP22]], [[TMP25]]
+// CHECK-NEXT:[[TMP27:%.*]] = and i64 [[TMP2]], 71776119061217280
+// CHECK-NEXT:[[TMP28:%.*]] = icmp eq i64 [[TMP27]], 0
+// CHECK-NEXT:[[TMP29:%.*]] = select i1 [[TMP28]], i64 71776119061217280, i64 0
+// CHECK-NEXT:[[TMP30:%.*]] = or i64 [[TMP26]], [[TMP29]]
+// CHECK-NEXT:[[TMP31:%.*]] = and i64 [[TMP2]], -72057594037927936
+// CHECK-NEXT:[[TMP32:%.*]] = icmp eq i64 [[TMP31]], 0
+// CHECK-NEXT:[[TMP33:%.*]] = select i1 [[TMP32]], i64 -72057594037927936, i64 0
+// CHECK-NEXT:[[TMP34:%.*]] = or i64 [[TMP30]], [[TMP33]]
+// CHECK-NEXT:ret i64 [[TMP34]]
+//
+long long test_builtin_ppc_cmpb(long long lla, long long llb) {
+  return __builtin_ppc_cmpb(lla, llb);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -15078,6 +15078,21 @@
 Value *shift = Builder.CreateCall(F, {Ops[0], Ops[0], Ops[1]});
 return Builder.CreateAnd(shift, Ops[2]);
   }
+  case PPC::BI__builtin_ppc_cmpb: {
+llvm::Type *Ty = Ops[0]->getType();
+Value *Zero = Constant::getNullValue(Ty);
+Value *Res = Constant::getNullValue(Ty);
+Value *X = Builder.CreateXor(Ops[0], Ops[1]);
+for (int i = 0; i < 8; i++) {
+  int64_t Mask = (int64_t)0xff << i * 8;
+  Value *Cmp = Builder.CreateICmpEQ(
+  Builder.CreateAnd(X, ConstantInt::getSigned(Ty, Mask)), Zero);
+  Value *Se

[PATCH] D104854: Introduce intrinsic llvm.isnan

2021-06-30 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff added a comment.

In D104854#2841505 , @efriedma wrote:

> I'd like to see some test coverage for all the floating-point types (half, 
> bfloat16, ppc_fp128).

Tests for half are added to aarch64-fpclass.ll, new file was created to test 
ppc_fp128. As for bfloat16, tests are added to aarch64-fpclass.ll but only in 
strictfp mode. Without this attribute codegen creates unordered compare 
operation, which is not supported for bfloat16.




Comment at: llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:662
+  EVT NewResultVT = TLI.getTypeToTransformTo(*DAG.getContext(), ResultVT);
+  return DAG.getNode(N->getOpcode(), DL, NewResultVT, N->getOperand(0));
+}

craig.topper wrote:
> Don't you net to preserve the NoFPExcept flag? Same with all the other type 
> legalization functions
Yes, it is more correct way. Updated functions.



Comment at: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp:600
+
+  SDValue Res = DAG.getNode(ISD::ISNAN, DL, ResultVT, Arg);
+  // Vectors may have a different boolean contents to scalars.  Promote the

craig.topper wrote:
> If this is ResultVT then the Extend created next is always a NOP. Should this 
> be MVT::i1?
Indeed. Thank you!



Comment at: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp:4727
+
+  if (TLI.isTypeLegal(WideResultVT)) {
+SDValue WideNode = DAG.getNode(ISD::ISNAN, DL, WideResultVT, WideArg);

craig.topper wrote:
> I wonder if we should be using getSetCCResultType here like WidenVecOp_SETCC?
Rewritten the function in this way.



Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:6371
+DAG.getNode(ISD::ISNAN, sdl, DestVT, getValue(I.getArgOperand(0)));
+V->setFlags(Flags);
+// If ISD::ISNAN should be expanded, do it right now, because the expansion

craig.topper wrote:
> Why not pass flags to getNode?
Yes, it should be set via getNode.



Comment at: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:6375
+// types prior to selection.
+if (!TLI.isOperationLegalOrCustom(ISD::ISNAN, ArgVT)) {
+  SDValue Result = TLI.expandISNAN(V.getNode(), DAG);

craig.topper wrote:
> This breaks if we add constant folding for ISD::ISNAN to getNode.
Now expansion occurs before getNode.



Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:6967
+  // NaN has all exp bits set and a non zero significand. Therefore:
+  // isnan(V) == ((exp mask - (abs(V) & exp mask)) < 0)
+  unsigned BitSize = OperandVT.getScalarSizeInBits();

thopre wrote:
> I seem to have made a mistake when I wrote this.
Thank you! I updated the comment.



Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:6981
+  // V = sign bit (Sub) <=> V = (Sub < 0)
+  SDValue SignBitV = DAG.getNode(ISD::SRL, DL, IntVT, Sub,
+ DAG.getConstant(BitSize - 1, DL, IntVT));

craig.topper wrote:
> Why can't we just check < 0 here? Why do we need to shift?
It seems the shift is not needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104854

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


[PATCH] D93525: [clang-offload-bundler] Add unbundling of archives containing bundled object files into device specific archives

2021-06-30 Thread George Rokos via Phabricator via cfe-commits
grokos added inline comments.



Comment at: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp:147
+Target.split(Components, '-', 5);
+Components.resize(6);
+this->OffloadKind = Components[0];

saiislam wrote:
> grokos wrote:
> > Leftover? `Components` is already 6 elements long.
> Not necessarily. It is possible that target has less than 6 elements. For 
> example all bundling/unbundling cases which do not require GPUArch field.
> E.g. "openmp-powerpc64le-ibm-linux-gnu"
OK, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D93525

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


[PATCH] D105191: [Clang][OpenMP] Add support for Static Device Libraries

2021-06-30 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

Not a thorough review but comments to address.




Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1662
+  std::string archname = ArchName.str();
+  std::string gpuname = GPUArch.str();
+

Coding convention.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1674
+std::string(LibraryPath + "/libdevice/lib" + libname + ".a"));
+AOBFileNames.push_back(std::string(LibraryPath + "/lib" + libname + ".a"));
+

This will accumulate more and more entries in AOBFileNames, shouldn't you clear 
it at the beginning?



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1684
+
+if (FoundAOB) {
+  std::string Err;





Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1810
+  for (std::string SDL_Name : SDL_Names) {
+//  THIS IS THE ONLY CALL TO SDLSearch
+if (!(SDLSearch(D, DriverArgs, CC1Args, LibraryPaths, SDL_Name, ArchName,





Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:1818
+  }
+}
+

Lots of places you create new std::strings for no reason, use StringRef or 
const std::string & to avoid that (especially in range loops).

Please no conditional like `a != ".." && a != ".." `. Use a compile time 
set or string switch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105191

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


[PATCH] D105185: [AIX] Add _AIX73 version macro

2021-06-30 Thread Shivam Gupta via Phabricator via cfe-commits
xgupta added inline comments.



Comment at: clang/lib/Basic/Targets/OSTargets.h:704
+if (OsVersion >= std::make_pair(7, 3))
+  Builder.defineMacro("_AIX73");
 

Jake-Egan wrote:
> xgupta wrote:
> > Jake-Egan wrote:
> > > xgupta wrote:
> > > > Seems this line need formatting?
> > > I originally had it matching the format of the other _AIX macro 
> > > definitions, but clang-format modified it to this.
> > I think clang-format is there to maintain consistency in the codebase. You 
> > can ignore it if it is doing the opposite.
> Do you suggest that I revise the formatting then?
Yeah, I think so, neglect clang-format. But you can wait for other reviewer's 
comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105185

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


[PATCH] D104918: [clang-repl] Implement partial translation units and error recovery.

2021-06-30 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added a comment.

A few minor notes




Comment at: clang/include/clang/Interpreter/Interpreter.h:63
+if (auto Err = ErrOrPTU.takeError())
   return Err;
+if (ErrOrPTU->TheModule)

`ErrorOr` has different semantics and is still in use, so the name could be 
confusing. Idiomatic usage for `Expected` would rather be like:
```
auto PTU = Parse(Code);
if (!PTU)
  return PTU.takeError();
```

The patch didn't introduce it, but it might be a good chance for improvement.



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:178
+TranslationUnitDecl *PreviousTU = MostRecentTU->getPreviousDecl();
+assert(PreviousTU);
+TranslationUnitDecl *FirstTU = MostRecentTU->getFirstDecl();

Where does it point, if the very first TU fails? Maybe worth noting in the 
assert and/or adding a test case?



Comment at: clang/lib/Interpreter/IncrementalParser.cpp:263
+  if (auto Err = ErrOrPTU.takeError())
 return std::move(Err);
 

```
auto PTU = ParseOrWrapTopLevelDecl();
if (!PTU)
  return PTU.takeError();
```


Repository:
  rC Clang

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

https://reviews.llvm.org/D104918

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


[PATCH] D104052: [clang] Fix CallExpr dependence bit may not respecting all its arguments.

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



Comment at: clang/include/clang/AST/Expr.h:2991
+  /// ! the dependence bits might be stale after calling this setter, it is
+  /// *caller*'s responsibility to recompute them.
   void setArg(unsigned Arg, Expr *ArgExpr) {

by calling computeDependence()


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104052

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


[PATCH] D105142: RFC: Implementing new mechanism for hard register operands to inline asm as a constraint.

2021-06-30 Thread Anirudh Prasad via Phabricator via cfe-commits
anirudhp added a comment.

In D105142#2849835 , @theraven wrote:

> The code looks fine but it would be good to see some docs along with it.  
> We're currently missing docs on inline assembly entirely and the GCC ones are 
> somewhat... opaque when it comes to describing how constraints work.

Thank you for your feedback! By docs do you mind updating/adding some 
information to the existing LLVM docs(like the langref 
https://llvm.org/docs/LangRef.html for example), or more comments to the code?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105142

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


[PATCH] D105099: [clang-format] Add an option to put one constructor initializer per line

2021-06-30 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius added a comment.

In D105099#2848583 , @owenpan wrote:

> If we were to start this all over without the need of backward compatibility 
> and the existence of the related unit tests, an enum might be a better 
> option. Then I still think the user might have some trouble relating the 
> following to the enum.
>
>   If AlwaysOnePerLine:
> Put each on its own line.
>   Else If AllOnOneLineOrOnePerline:
> If they all fit on one line:
>   Put all of them on a single line.
> Else If AllOnNextLine:
>   Put (the rest of) them on the next line.
> Else:
>   Put each on its own line.
>   Else:
> ...

Is there anything else in the "Else:" part above? Is there an option that we 
forgot?

I'm not sure if I understand you correctly. Is your point that an enum option 
would be hard to find by the users?
But if the doc of each currently existing option pointed to this enum option it 
would be pretty easy, no?
Or does backward compatibility seem difficult to achieve? It should be a 
straightforward mapping.

Also, I find that having option that are mutually exclusive (or one that 
doesn't change anything when another is enabled) is a smell that tells us to 
use an enum.
Personally I find it harder to finder multiple options that concern the same 
aspect of the code style rather than a single option.

What I find problematic is clear and descriptive names for all options and 
possible values, but that's unrelated to whether it's a single enum option or 
several boolean options.
Having said that, I need to admit that 
`ConstructorInitializerAllOnOneLineOrOnePerLine` name makes my blood run cold 
:).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105099

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


[clang-tools-extra] bb41f85 - [clangd] Correct SelectionTree behavior around anonymous field access.

2021-06-30 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-06-30T17:34:48+02:00
New Revision: bb41f8569138f9f87baf7f4b4e26b3cdcdfd42c6

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

LOG: [clangd] Correct SelectionTree behavior around anonymous field access.

struct A { struct { int b; }; };
A().^b;

This should be considered a reference to b, but currently it's
considered a reference to the anonymous struct field.

Fixes https://github.com/clangd/clangd/issues/798

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

Added: 


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

Removed: 




diff  --git a/clang-tools-extra/clangd/Selection.cpp 
b/clang-tools-extra/clangd/Selection.cpp
index 017f4b22861b5..ad41dec9f20f8 100644
--- a/clang-tools-extra/clangd/Selection.cpp
+++ b/clang-tools-extra/clangd/Selection.cpp
@@ -57,6 +57,27 @@ void recordMetrics(const SelectionTree &S, const LangOptions 
&Lang) {
 SelectionUsedRecovery.record(0, LanguageLabel); // unused.
 }
 
+SourceRange getSourceRange(const DynTypedNode &N) {
+  // MemberExprs to implicitly access anonymous fields should not claim any
+  // tokens for themselves. Given:
+  //   struct A { struct { int b; }; };
+  // The clang AST reports the following nodes for an access to b:
+  //   A().b;
+  //   [] MemberExpr, base = A()., member = b
+  //   [] MemberExpr: base = A(), member = 
+  //   [-]CXXConstructExpr
+  // For our purposes, we don't want the second MemberExpr to own any tokens,
+  // so we reduce its range to match the CXXConstructExpr.
+  // (It's not clear that changing the clang AST would be correct in general).
+  if (const auto *ME = N.get()) {
+if (!ME->getMemberDecl()->getDeclName())
+  return ME->getBase()
+ ? getSourceRange(DynTypedNode::create(*ME->getBase()))
+ : SourceRange();
+  }
+  return N.getSourceRange();
+}
+
 // An IntervalSet maintains a set of disjoint subranges of an array.
 //
 // Initially, it contains the entire array.
@@ -608,7 +629,7 @@ class SelectionVisitor : public 
RecursiveASTVisitor {
   // An optimization for a common case: nodes outside macro expansions that
   // don't intersect the selection may be recursively skipped.
   bool canSafelySkipNode(const DynTypedNode &N) {
-SourceRange S = N.getSourceRange();
+SourceRange S = getSourceRange(N);
 if (auto *TL = N.get()) {
   // FIXME: TypeLoc::getBeginLoc()/getEndLoc() are pretty fragile
   // heuristics. We should consider only pruning critical TypeLoc nodes, to
@@ -665,7 +686,7 @@ class SelectionVisitor : public 
RecursiveASTVisitor {
   void pop() {
 Node &N = *Stack.top();
 dlog("{1}pop: {0}", printNodeToString(N.ASTNode, PrintPolicy), indent(-1));
-claimRange(N.ASTNode.getSourceRange(), N.Selected);
+claimRange(getSourceRange(N.ASTNode), N.Selected);
 if (N.Selected == NoTokens)
   N.Selected = SelectionTree::Unselected;
 if (N.Selected || !N.Children.empty()) {
@@ -868,13 +889,13 @@ const DeclContext &SelectionTree::Node::getDeclContext() 
const {
 
 const SelectionTree::Node &SelectionTree::Node::ignoreImplicit() const {
   if (Children.size() == 1 &&
-  Children.front()->ASTNode.getSourceRange() == ASTNode.getSourceRange())
+  getSourceRange(Children.front()->ASTNode) == getSourceRange(ASTNode))
 return Children.front()->ignoreImplicit();
   return *this;
 }
 
 const SelectionTree::Node &SelectionTree::Node::outerImplicit() const {
-  if (Parent && Parent->ASTNode.getSourceRange() == ASTNode.getSourceRange())
+  if (Parent && getSourceRange(Parent->ASTNode) == getSourceRange(ASTNode))
 return Parent->outerImplicit();
   return *this;
 }

diff  --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp 
b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 8c37532507d45..166e0674afea6 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -420,6 +420,18 @@ TEST(LocateSymbol, All) {
   //   $def is the definition location (if absent, symbol has no definition)
   //   unnamed range becomes both $decl and $def.
   const char *Tests[] = {
+  R"cpp(
+struct X {
+  union {
+int [[a]];
+float b;
+  };
+};
+int test(X &x) {
+  return x.^a;
+}
+  )cpp",
+
   R"cpp(// Local variable
 int main() {
   int [[bonjour]];



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


[PATCH] D104376: [clangd] Correct SelectionTree behavior around anonymous field access.

2021-06-30 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbb41f8569138: [clangd] Correct SelectionTree behavior around 
anonymous field access. (authored by sammccall).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104376

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


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -420,6 +420,18 @@
   //   $def is the definition location (if absent, symbol has no definition)
   //   unnamed range becomes both $decl and $def.
   const char *Tests[] = {
+  R"cpp(
+struct X {
+  union {
+int [[a]];
+float b;
+  };
+};
+int test(X &x) {
+  return x.^a;
+}
+  )cpp",
+
   R"cpp(// Local variable
 int main() {
   int [[bonjour]];
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -57,6 +57,27 @@
 SelectionUsedRecovery.record(0, LanguageLabel); // unused.
 }
 
+SourceRange getSourceRange(const DynTypedNode &N) {
+  // MemberExprs to implicitly access anonymous fields should not claim any
+  // tokens for themselves. Given:
+  //   struct A { struct { int b; }; };
+  // The clang AST reports the following nodes for an access to b:
+  //   A().b;
+  //   [] MemberExpr, base = A()., member = b
+  //   [] MemberExpr: base = A(), member = 
+  //   [-]CXXConstructExpr
+  // For our purposes, we don't want the second MemberExpr to own any tokens,
+  // so we reduce its range to match the CXXConstructExpr.
+  // (It's not clear that changing the clang AST would be correct in general).
+  if (const auto *ME = N.get()) {
+if (!ME->getMemberDecl()->getDeclName())
+  return ME->getBase()
+ ? getSourceRange(DynTypedNode::create(*ME->getBase()))
+ : SourceRange();
+  }
+  return N.getSourceRange();
+}
+
 // An IntervalSet maintains a set of disjoint subranges of an array.
 //
 // Initially, it contains the entire array.
@@ -608,7 +629,7 @@
   // An optimization for a common case: nodes outside macro expansions that
   // don't intersect the selection may be recursively skipped.
   bool canSafelySkipNode(const DynTypedNode &N) {
-SourceRange S = N.getSourceRange();
+SourceRange S = getSourceRange(N);
 if (auto *TL = N.get()) {
   // FIXME: TypeLoc::getBeginLoc()/getEndLoc() are pretty fragile
   // heuristics. We should consider only pruning critical TypeLoc nodes, to
@@ -665,7 +686,7 @@
   void pop() {
 Node &N = *Stack.top();
 dlog("{1}pop: {0}", printNodeToString(N.ASTNode, PrintPolicy), indent(-1));
-claimRange(N.ASTNode.getSourceRange(), N.Selected);
+claimRange(getSourceRange(N.ASTNode), N.Selected);
 if (N.Selected == NoTokens)
   N.Selected = SelectionTree::Unselected;
 if (N.Selected || !N.Children.empty()) {
@@ -868,13 +889,13 @@
 
 const SelectionTree::Node &SelectionTree::Node::ignoreImplicit() const {
   if (Children.size() == 1 &&
-  Children.front()->ASTNode.getSourceRange() == ASTNode.getSourceRange())
+  getSourceRange(Children.front()->ASTNode) == getSourceRange(ASTNode))
 return Children.front()->ignoreImplicit();
   return *this;
 }
 
 const SelectionTree::Node &SelectionTree::Node::outerImplicit() const {
-  if (Parent && Parent->ASTNode.getSourceRange() == ASTNode.getSourceRange())
+  if (Parent && getSourceRange(Parent->ASTNode) == getSourceRange(ASTNode))
 return Parent->outerImplicit();
   return *this;
 }


Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -420,6 +420,18 @@
   //   $def is the definition location (if absent, symbol has no definition)
   //   unnamed range becomes both $decl and $def.
   const char *Tests[] = {
+  R"cpp(
+struct X {
+  union {
+int [[a]];
+float b;
+  };
+};
+int test(X &x) {
+  return x.^a;
+}
+  )cpp",
+
   R"cpp(// Local variable
 int main() {
   int [[bonjour]];
Index: clang-tools-extra/clangd/Selection.cpp
===
--- clang-tools-extra/clangd/Selection.cpp
+++ clang-tools-extra/clangd/Selection.cpp
@@ -57,6 +57,27 @@
 SelectionUsedRecovery.record(0, LanguageLabel); // unused.
 }
 
+SourceRange getSourceRange(const DynTypedNode &N) {
+  // MemberExpr

[PATCH] D104898: [clang-repl] Allow passing in code as positional arguments.

2021-06-30 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz accepted this revision.
sgraenitz added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/test/Interpreter/execute.cpp:1
 // RUN: cat %s | clang-repl | FileCheck %s
+// RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \

Maybe this could move down to line 8, so it's closer to the code that it works 
with?



Comment at: clang/tools/clang-repl/ClangRepl.cpp:90
 
+  if (!OptInputs.size()) {
+llvm::LineEditor LE("clang-repl");

`OptInputs.empty()` ?


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

https://reviews.llvm.org/D104898

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


[PATCH] D100553: [clangd] Log feature configuration (linux+asan+grpc) of the clangd build

2021-06-30 Thread Sam McCall via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
sammccall marked 3 inline comments as done.
Closed by commit rG0c96a92d8666: [clangd] Log feature configuration 
(linux+asan+grpc) of the clangd build (authored by sammccall).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D100553?vs=337726&id=355570#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100553

Files:
  clang-tools-extra/clangd/CMakeLists.txt
  clang-tools-extra/clangd/ClangdLSPServer.cpp
  clang-tools-extra/clangd/ClangdLSPServer.h
  clang-tools-extra/clangd/ConfigCompile.cpp
  clang-tools-extra/clangd/Features.cpp
  clang-tools-extra/clangd/Features.h
  clang-tools-extra/clangd/Features.inc.in
  clang-tools-extra/clangd/index/remote/Client.cpp
  clang-tools-extra/clangd/index/remote/server/Server.cpp
  clang-tools-extra/clangd/tool/ClangdMain.cpp
  clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Index: clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
===
--- clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -9,7 +9,7 @@
 #include "Config.h"
 #include "ConfigFragment.h"
 #include "ConfigTesting.h"
-#include "Features.inc"
+#include "Features.h"
 #include "TestFS.h"
 #include "clang/Basic/DiagnosticSema.h"
 #include "llvm/ADT/None.h"
Index: clang-tools-extra/clangd/tool/ClangdMain.cpp
===
--- clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -10,7 +10,7 @@
 #include "CodeComplete.h"
 #include "Config.h"
 #include "ConfigProvider.h"
-#include "Features.inc"
+#include "Features.h"
 #include "PathMapping.h"
 #include "Protocol.h"
 #include "TidyProvider.h"
@@ -26,7 +26,6 @@
 #include "support/Shutdown.h"
 #include "support/ThreadsafeFS.h"
 #include "support/Trace.h"
-#include "clang/Basic/Version.h"
 #include "clang/Format/Format.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SmallString.h"
@@ -679,7 +678,8 @@
   llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
   llvm::sys::SetInterruptFunction(&requestShutdown);
   llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
-OS << clang::getClangToolFullVersion("clangd") << "\n";
+OS << versionString() << "\n"
+   << "Features: " << featureString() << "\n";
   });
   const char *FlagsEnvVar = "CLANGD_FLAGS";
   const char *Overview =
@@ -784,7 +784,8 @@
   StreamLogger Logger(llvm::errs(), LogLevel);
   LoggingSession LoggingSession(Logger);
   // Write some initial logs before we start doing any real work.
-  log("{0}", clang::getClangToolFullVersion("clangd"));
+  log("{0}", versionString());
+  log("Features: {0}", featureString());
   log("PID: {0}", llvm::sys::Process::getProcessId());
   {
 SmallString<128> CWD;
Index: clang-tools-extra/clangd/index/remote/server/Server.cpp
===
--- clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "Features.inc"
+#include "Features.h"
 #include "Index.pb.h"
 #include "MonitoringService.grpc.pb.h"
 #include "MonitoringService.pb.h"
Index: clang-tools-extra/clangd/index/remote/Client.cpp
===
--- clang-tools-extra/clangd/index/remote/Client.cpp
+++ clang-tools-extra/clangd/index/remote/Client.cpp
@@ -9,12 +9,12 @@
 #include 
 
 #include "Client.h"
+#include "Features.h"
 #include "Service.grpc.pb.h"
 #include "index/Index.h"
 #include "marshalling/Marshalling.h"
 #include "support/Logger.h"
 #include "support/Trace.h"
-#include "clang/Basic/Version.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Error.h"
@@ -72,7 +72,8 @@
 const auto RPCRequest = ProtobufMarshaller->toProtobuf(Request);
 SPAN_ATTACH(Tracer, "Request", RPCRequest.DebugString());
 grpc::ClientContext Context;
-Context.AddMetadata("version", clang::getClangToolFullVersion("clangd"));
+Context.AddMetadata("version", versionString());
+Context.AddMetadata("features", featureString());
 std::chrono::system_clock::time_point StartTime =
 std::chrono::system_clock::now();
 auto Deadline = StartTime + DeadlineWaitingTime;
Index: clang-tools-extra/clangd/Features.inc.in
===
--- clang-tools-extra/clangd/Features.inc.in
+++ clang-tools-extra/clangd/Features.inc.in
@@ -1,3 +1,4 @@
+// IWYU pragma: private, include "Features.h"
 #define CLANGD_BUILD_XPC @CLANGD_BU

[clang-tools-extra] b447445 - [clangd] Show padding following a field on field hover.

2021-06-30 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-06-30T17:50:59+02:00
New Revision: b447445eaa6f8ff826a7eab276c10bc6f133aeb0

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

LOG: [clangd] Show padding following a field on field hover.

This displays as: `Size: 4 bytes (+4 padding)`

Also stop showing (byte) offset/size for bitfields. They're not
meaningful and using them to calculate padding is dangerous!

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

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/Hover.h
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 8b14777173a0..c71a8c40ce94 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -28,6 +28,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/OperationKinds.h"
 #include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/RecordLayout.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/SourceLocation.h"
@@ -770,10 +771,30 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
 const auto *Record = FD->getParent();
 if (Record)
   Record = Record->getDefinition();
-if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
-  HI.Offset = Ctx.getFieldOffset(FD) / 8;
-  if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType()))
-HI.Size = Size->getQuantity();
+if (Record && !Record->isInvalidDecl() && !Record->isDependentType() &&
+!FD->isBitField()) {
+  const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Record);
+  HI.Offset = Layout.getFieldOffset(FD->getFieldIndex()) / 8;
+  if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType())) {
+HI.Size = FD->isZeroSize(Ctx) ? 0 : Size->getQuantity();
+unsigned EndOfField = *HI.Offset + *HI.Size;
+
+// Calculate padding following the field.
+if (!Record->isUnion() &&
+FD->getFieldIndex() + 1 < Layout.getFieldCount()) {
+  // Measure padding up to the next class field.
+  unsigned NextOffset =
+  Layout.getFieldOffset(FD->getFieldIndex() + 1) / 8;
+  if (NextOffset >= EndOfField) // next field could be a bitfield!
+HI.Padding = NextOffset - EndOfField;
+} else {
+  // Measure padding up to the end of the object.
+  HI.Padding = Layout.getSize().getQuantity() - EndOfField;
+}
+  }
+  // Offset in a union is always zero, so not really useful to report.
+  if (Record->isUnion())
+HI.Offset.reset();
 }
 return;
   }
@@ -1013,9 +1034,12 @@ markup::Document HoverInfo::present() const {
 Output.addParagraph().appendText(
 llvm::formatv("Offset: {0} byte{1}", *Offset, *Offset == 1 ? "" : "s")
 .str());
-  if (Size)
-Output.addParagraph().appendText(
+  if (Size) {
+auto &P = Output.addParagraph().appendText(
 llvm::formatv("Size: {0} byte{1}", *Size, *Size == 1 ? "" : 
"s").str());
+if (Padding && *Padding != 0)
+  P.appendText(llvm::formatv(" (+{0} padding)", *Padding).str());
+  }
 
   if (CalleeArgInfo) {
 assert(CallPassType);

diff  --git a/clang-tools-extra/clangd/Hover.h 
b/clang-tools-extra/clangd/Hover.h
index 2f2afbf6723b..44ee9b7d7979 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -77,6 +77,8 @@ struct HoverInfo {
   llvm::Optional Size;
   /// Contains the offset of fields within the enclosing class.
   llvm::Optional Offset;
+  /// Contains the padding following a field within the enclosing class.
+  llvm::Optional Padding;
   // Set when symbol is inside function call. Contains information extracted
   // from the callee definition about the argument this is passed as.
   llvm::Optional CalleeArgInfo;

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index c2645b99926c..9089a4859c14 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -68,8 +68,9 @@ TEST(Hover, Structured) {
   // Field
   {R"cpp(
   namespace ns1 { namespace ns2 {
-struct Foo {
+class Foo {
   char [[b^ar]];
+  double y[2];
 };
   }}
   )cpp",
@@ -82,6 +83,41 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Offset = 0;
  HI.Size = 1;
+ HI.Padding = 7;
+ HI.AccessSpecifier = "private";
+   }},
+  // Union field
+  {R"cpp(
+union Foo {
+  char [[b^ar]];
+

[PATCH] D98377: [clangd] Show padding following a field on field hover.

2021-06-30 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb447445eaa6f: [clangd] Show padding following a field on 
field hover. (authored by sammccall).

Changed prior to commit:
  https://reviews.llvm.org/D98377?vs=329805&id=355571#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D98377

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/Hover.h
  clang-tools-extra/clangd/unittests/HoverTests.cpp

Index: clang-tools-extra/clangd/unittests/HoverTests.cpp
===
--- clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -68,8 +68,9 @@
   // Field
   {R"cpp(
   namespace ns1 { namespace ns2 {
-struct Foo {
+class Foo {
   char [[b^ar]];
+  double y[2];
 };
   }}
   )cpp",
@@ -82,6 +83,41 @@
  HI.Type = "char";
  HI.Offset = 0;
  HI.Size = 1;
+ HI.Padding = 7;
+ HI.AccessSpecifier = "private";
+   }},
+  // Union field
+  {R"cpp(
+union Foo {
+  char [[b^ar]];
+  double y[2];
+};
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Foo::";
+ HI.Name = "bar";
+ HI.Kind = index::SymbolKind::Field;
+ HI.Definition = "char bar";
+ HI.Type = "char";
+ HI.Size = 1;
+ HI.Padding = 15;
+ HI.AccessSpecifier = "public";
+   }},
+  // Bitfield
+  {R"cpp(
+struct Foo {
+  int [[^x]] : 1;
+  int y : 1;
+};
+  )cpp",
+   [](HoverInfo &HI) {
+ HI.NamespaceScope = "";
+ HI.LocalScope = "Foo::";
+ HI.Name = "x";
+ HI.Kind = index::SymbolKind::Field;
+ HI.Definition = "int x : 1";
+ HI.Type = "int";
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -2558,13 +2594,14 @@
 HI.Definition = "def";
 HI.Size = 4;
 HI.Offset = 12;
+HI.Padding = 4;
   },
   R"(field foo
 
 Type: type
 Value = value
 Offset: 12 bytes
-Size: 4 bytes
+Size: 4 bytes (+4 padding)
 
 // In test::Bar
 def)",
Index: clang-tools-extra/clangd/Hover.h
===
--- clang-tools-extra/clangd/Hover.h
+++ clang-tools-extra/clangd/Hover.h
@@ -77,6 +77,8 @@
   llvm::Optional Size;
   /// Contains the offset of fields within the enclosing class.
   llvm::Optional Offset;
+  /// Contains the padding following a field within the enclosing class.
+  llvm::Optional Padding;
   // Set when symbol is inside function call. Contains information extracted
   // from the callee definition about the argument this is passed as.
   llvm::Optional CalleeArgInfo;
Index: clang-tools-extra/clangd/Hover.cpp
===
--- clang-tools-extra/clangd/Hover.cpp
+++ clang-tools-extra/clangd/Hover.cpp
@@ -28,6 +28,7 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/OperationKinds.h"
 #include "clang/AST/PrettyPrinter.h"
+#include "clang/AST/RecordLayout.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/SourceLocation.h"
@@ -770,10 +771,30 @@
 const auto *Record = FD->getParent();
 if (Record)
   Record = Record->getDefinition();
-if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
-  HI.Offset = Ctx.getFieldOffset(FD) / 8;
-  if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType()))
-HI.Size = Size->getQuantity();
+if (Record && !Record->isInvalidDecl() && !Record->isDependentType() &&
+!FD->isBitField()) {
+  const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Record);
+  HI.Offset = Layout.getFieldOffset(FD->getFieldIndex()) / 8;
+  if (auto Size = Ctx.getTypeSizeInCharsIfKnown(FD->getType())) {
+HI.Size = FD->isZeroSize(Ctx) ? 0 : Size->getQuantity();
+unsigned EndOfField = *HI.Offset + *HI.Size;
+
+// Calculate padding following the field.
+if (!Record->isUnion() &&
+FD->getFieldIndex() + 1 < Layout.getFieldCount()) {
+  // Measure padding up to the next class field.
+  unsigned NextOffset =
+  Layout.getFieldOffset(FD->getFieldIndex() + 1) / 8;
+  if (NextOffset >= EndOfField) // next field could be a bitfield!
+HI.Padding = NextOffset - EndOfField;
+} else {
+  // Measure padding up to the end of the object.
+  HI.Padding = Layout.getSize().getQuantity() - EndOfField;
+}
+  }
+  // Offset in a union is always zero, so not really useful to report.

[PATCH] D95807: [Coroutines] Add the newly generated SCCs back to the CGSCC work queue after CoroSplit actually happened

2021-06-30 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks accepted this revision.
aeubanks added a comment.

The CoroSplit/PassBuilder changes lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95807

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


[clang-tools-extra] 0c96a92 - [clangd] Log feature configuration (linux+asan+grpc) of the clangd build

2021-06-30 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2021-06-30T17:49:29+02:00
New Revision: 0c96a92d8666b8eb69eb1275aed572f857182d9a

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

LOG: [clangd] Log feature configuration (linux+asan+grpc) of the clangd build

Included in logs, --version, remote index queries, and LSP serverInfo.

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

Added: 
clang-tools-extra/clangd/Features.cpp
clang-tools-extra/clangd/Features.h

Modified: 
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/Features.inc.in
clang-tools-extra/clangd/index/remote/Client.cpp
clang-tools-extra/clangd/index/remote/server/Server.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/CMakeLists.txt 
b/clang-tools-extra/clangd/CMakeLists.txt
index 671e55e8622d3..b983b71cc90f4 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -64,6 +64,7 @@ add_clang_library(clangDaemon
   DumpAST.cpp
   ExpectedTypes.cpp
   FeatureModule.cpp
+  Features.cpp
   FindSymbols.cpp
   FindTarget.cpp
   FileDistance.cpp

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp 
b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f70fd0018cfdf..9214bcbe66bca 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -12,6 +12,7 @@
 #include "Diagnostics.h"
 #include "DraftStore.h"
 #include "DumpAST.h"
+#include "Features.h"
 #include "GlobalCompilationDatabase.h"
 #include "LSPBinder.h"
 #include "Protocol.h"
@@ -24,7 +25,6 @@
 #include "support/MemoryTree.h"
 #include "support/Trace.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/Basic/Version.h"
 #include "clang/Tooling/Core/Replacement.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
@@ -620,7 +620,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams 
&Params,
   llvm::json::Object Result{
   {{"serverInfo",
 llvm::json::Object{{"name", "clangd"},
-   {"version", getClangToolFullVersion("clangd")}}},
+   {"version", llvm::formatv("{0} {1}", 
versionString(),
+ featureString())}}},
{"capabilities", std::move(ServerCaps)}}};
   if (Opts.Encoding)
 Result["offsetEncoding"] = *Opts.Encoding;

diff  --git a/clang-tools-extra/clangd/ClangdLSPServer.h 
b/clang-tools-extra/clangd/ClangdLSPServer.h
index 8c43d18502875..4c195df6f893c 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -11,7 +11,6 @@
 
 #include "ClangdServer.h"
 #include "DraftStore.h"
-#include "Features.inc"
 #include "FindSymbols.h"
 #include "GlobalCompilationDatabase.h"
 #include "LSPBinder.h"

diff  --git a/clang-tools-extra/clangd/ConfigCompile.cpp 
b/clang-tools-extra/clangd/ConfigCompile.cpp
index 438dd74d866c6..4eaff343b2290 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -28,7 +28,7 @@
 #include "ConfigFragment.h"
 #include "ConfigProvider.h"
 #include "Diagnostics.h"
-#include "Features.inc"
+#include "Features.h"
 #include "TidyProvider.h"
 #include "support/Logger.h"
 #include "support/Path.h"

diff  --git a/clang-tools-extra/clangd/Features.cpp 
b/clang-tools-extra/clangd/Features.cpp
new file mode 100644
index 0..17f475fc4c22b
--- /dev/null
+++ b/clang-tools-extra/clangd/Features.cpp
@@ -0,0 +1,55 @@
+//===--- Features.cpp - Compile-time configuration 
===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "Features.h"
+#include "clang/Basic/Version.h"
+#include "llvm/Support/Compiler.h"
+
+namespace clang {
+namespace clangd {
+
+std::string versionString() { return clang::getClangToolFullVersion("clangd"); 
}
+
+std::string featureString() {
+  return
+#if defined(_WIN32)
+  "windows"
+#elif defined(__APPLE__)
+  "mac"
+#elif defined(__linux__)
+  "linux"
+#elif defined(LLVM_ON_UNIX)
+  "unix"
+#else
+  "unknown"
+#endif
+
+#ifndef NDEBUG
+  "+debug"
+#endif
+#if LLVM_ADDRESS_SANITIZER_BUILD
+  "+asan"
+#endif
+#if LLVM_THREAD_SANITIZER_BUILD
+  "+tsan"
+#endif
+#if LLVM_MEMORY_SANITIZER_BUILD
+  "+msan"
+

[PATCH] D104742: [UpdateCCTestChecks] Implement --global-value-regex

2021-06-30 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 355579.
jdenny added a comment.

Fix the new test for the race discussed at D104714#2841465 
.


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

https://reviews.llvm.org/D104742

Files:
  clang/test/utils/update_cc_test_checks/Inputs/global-value-regex.c
  clang/test/utils/update_cc_test_checks/Inputs/global-value-regex.c.expected
  clang/test/utils/update_cc_test_checks/global-value-regex.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -36,9 +36,12 @@
   help='List of regular expressions to replace matching value names')
   parser.add_argument('--prefix-filecheck-ir-name', default='',
   help='Add a prefix to FileCheck IR value names to avoid conflicts with scripted names')
+  parser.add_argument('--global-value-regex', nargs='+', default=[],
+  help='List of regular expressions that a global value declaration must match to generate a check (has no effect if checking globals is not enabled)')
   args = parser.parse_args()
-  global _verbose
+  global _verbose, _global_value_regex
   _verbose = args.verbose
+  _global_value_regex = args.global_value_regex
   return args
 
 
@@ -796,13 +799,27 @@
 if not glob_val_dict[checkprefix][nameless_value.check_prefix]:
   continue
 
-output_lines.append(comment_marker + SEPARATOR)
-
+check_lines = []
 global_vars_seen_before = [key for key in global_vars_seen.keys()]
 for line in glob_val_dict[checkprefix][nameless_value.check_prefix]:
+  if _global_value_regex:
+matched = False
+for regex in _global_value_regex:
+  if re.match('^@' + regex + ' = ', line):
+matched = True
+break
+if not matched:
+  continue
   tmp = generalize_check_lines([line], is_analyze, set(), global_vars_seen)
   check_line = '%s %s: %s' % (comment_marker, checkprefix, tmp[0])
+  check_lines.append(check_line)
+if not check_lines:
+  continue
+
+output_lines.append(comment_marker + SEPARATOR)
+for check_line in check_lines:
   output_lines.append(check_line)
+
 printed_prefixes.add((checkprefix, nameless_value.check_prefix))
 
 # Remembe new global variables we have not seen before
Index: clang/test/utils/update_cc_test_checks/global-value-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/global-value-regex.test
@@ -0,0 +1,18 @@
+RUN: rm -rf %t && mkdir %t
+
+# Check --global-value-regex.
+RUN: cp %S/Inputs/global-value-regex.c %t/test.c
+RUN: %update_cc_test_checks %t/test.c --check-globals \
+RUN:   --global-value-regex "foo\.."
+RUN: diff -u %S/Inputs/global-value-regex.c.expected %t/test.c
+
+# Check that the generated directives actually work correctly.
+RUN: cp %S/Inputs/lit.cfg.example %t/lit.cfg
+# Show lit failures while avoiding confusing FileCheck input dump nesting.
+RUN: %lit %t
+# Lit was successful.  Sanity-check the results with deterministic test order.
+RUN: rm %t/.lit_test_times.txt
+RUN: %lit %t 2>&1 | FileCheck %s
+
+CHECK: Testing: 1 tests
+CHECK: PASS: {{.*}} test.c
Index: clang/test/utils/update_cc_test_checks/Inputs/global-value-regex.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/global-value-regex.c.expected
@@ -0,0 +1,21 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --global-value-regex "foo\.."
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+//.
+// CHECK: @foo.i = internal global i32 0, align 4
+// CHECK: @foo.j = internal global i32 0, align 4
+//.
+// CHECK-LABEL: @foo(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret void
+//
+void foo() {
+  static int i, j;
+}
+// CHECK-LABEL: @bar(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret void
+//
+void bar() {
+  static int i, j;
+}
Index: clang/test/utils/update_cc_test_checks/Inputs/global-value-regex.c
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/global-value-regex.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+void foo() {
+  static int i, j;
+}
+void bar() {
+  static int i, j;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104743: [UpdateCCTestChecks] Implement --global-hex-value-regex

2021-06-30 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny updated this revision to Diff 355582.
jdenny added a comment.

Fix the new test for the race discussed at D104714#2841465 
.


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

https://reviews.llvm.org/D104743

Files:
  clang/test/utils/update_cc_test_checks/Inputs/global-hex-value-regex.c
  
clang/test/utils/update_cc_test_checks/Inputs/global-hex-value-regex.c.expected
  clang/test/utils/update_cc_test_checks/global-hex-value-regex.test
  llvm/utils/UpdateTestChecks/common.py

Index: llvm/utils/UpdateTestChecks/common.py
===
--- llvm/utils/UpdateTestChecks/common.py
+++ llvm/utils/UpdateTestChecks/common.py
@@ -38,10 +38,13 @@
   help='Add a prefix to FileCheck IR value names to avoid conflicts with scripted names')
   parser.add_argument('--global-value-regex', nargs='+', default=[],
   help='List of regular expressions that a global value declaration must match to generate a check (has no effect if checking globals is not enabled)')
+  parser.add_argument('--global-hex-value-regex', nargs='+', default=[],
+  help='List of regular expressions such that, for matching global value declarations, literal i32/i64 values should be encoded in hex in the associated FileCheck directives')
   args = parser.parse_args()
-  global _verbose, _global_value_regex
+  global _verbose, _global_value_regex, _global_hex_value_regex
   _verbose = args.verbose
   _global_value_regex = args.global_value_regex
+  _global_hex_value_regex = args.global_hex_value_regex
   return args
 
 
@@ -607,6 +610,12 @@
   for i, line in enumerate(lines):
 # An IR variable named '%.' matches the FileCheck regex string.
 line = line.replace('%.', '%dot')
+for regex in _global_hex_value_regex:
+  if re.match('^@' + regex + ' = ', line):
+line = re.sub(r'\bi(32|64) ([0-9]+)',
+lambda m : 'i' + m.group(1) + ' [[#' + hex(int(m.group(2))) + ']]',
+line)
+break
 # Ignore any comments, since the check lines will too.
 scrubbed_line = SCRUB_IR_COMMENT_RE.sub(r'', line)
 lines[i] = scrubbed_line
Index: clang/test/utils/update_cc_test_checks/global-hex-value-regex.test
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/global-hex-value-regex.test
@@ -0,0 +1,19 @@
+RUN: rm -rf %t && mkdir %t
+
+# Check --global-hex-value-regex.
+RUN: cp %S/Inputs/global-hex-value-regex.c %t/test.c
+RUN: %update_cc_test_checks %t/test.c --check-globals \
+RUN: --global-value-regex "foo\..*" "bar\..*" \
+RUN: --global-hex-value-regex ".*\.hex"
+RUN: diff -u %S/Inputs/global-hex-value-regex.c.expected %t/test.c
+
+# Check that the generated directives actually work correctly.
+RUN: cp %S/Inputs/lit.cfg.example %t/lit.cfg
+# Show lit failures while avoiding confusing FileCheck input dump nesting.
+RUN: %lit %t
+# Lit was successful.  Sanity-check the results with deterministic test order.
+RUN: rm %t/.lit_test_times.txt
+RUN: %lit %t 2>&1 | FileCheck %s
+
+CHECK: Testing: 1 tests
+CHECK: PASS: {{.*}} test.c
Index: clang/test/utils/update_cc_test_checks/Inputs/global-hex-value-regex.c.expected
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/global-hex-value-regex.c.expected
@@ -0,0 +1,25 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals --global-value-regex "foo\..*" "bar\..*" --global-hex-value-regex ".*\.hex"
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+//.
+// CHECK: @foo.hex = internal global i32 [[#0x10]], align 4
+// CHECK: @foo.dec = internal global i32 10, align 4
+// CHECK: @bar.hex = internal global i32 [[#0x20]], align 4
+// CHECK: @bar.dec = internal global i32 20, align 4
+//.
+// CHECK-LABEL: @foo(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret void
+//
+void foo() {
+  static int hex = 0x10;
+  static int dec = 10;
+}
+// CHECK-LABEL: @bar(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:ret void
+//
+void bar() {
+  static int hex = 0x20;
+  static int dec = 20;
+}
Index: clang/test/utils/update_cc_test_checks/Inputs/global-hex-value-regex.c
===
--- /dev/null
+++ clang/test/utils/update_cc_test_checks/Inputs/global-hex-value-regex.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s | FileCheck %s
+
+void foo() {
+  static int hex = 0x10;
+  static int dec = 10;
+}
+void bar() {
+  static int hex = 0x20;
+  static int dec = 20;
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104852: [AArch64][SVEIntrinsicOpts] Convect cntb/h/w/d to vscale intrinsic or constant.

2021-06-30 Thread David Sherwood via Phabricator via cfe-commits
david-arm accepted this revision.
david-arm added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks a lot for making the changes. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104852

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


[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

2021-06-30 Thread Balázs Kéri via Phabricator via cfe-commits
balazske updated this revision to Diff 355594.
balazske added a comment.

Using NoteTag.
Removed the EOF sequence number.
Renamed test functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104925

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

Index: clang/test/Analysis/stream-note.c
===
--- clang/test/Analysis/stream-note.c
+++ clang/test/Analysis/stream-note.c
@@ -88,3 +88,60 @@
   fclose(F); // expected-warning {{Stream pointer might be NULL}}
   // expected-note@-1 {{Stream pointer might be NULL}}
 }
+
+void check_eof_notes_feof_after_feof() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  }
+  fread(Buf, 1, 1, F);
+  if (feof(F)) { // expected-note {{Taking true branch}}
+clearerr(F);
+fread(Buf, 1, 1, F);   // expected-note {{Assuming that stream reaches end-of-file here}}
+if (feof(F)) { // expected-note {{Taking true branch}}
+  fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+  // expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+}
+  }
+  fclose(F);
+}
+
+void check_eof_notes_feof_after_no_feof() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) { // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  }
+  fread(Buf, 1, 1, F);
+  if (feof(F)) { // expected-note {{Taking false branch}}
+fclose(F);
+return;
+  } else if (ferror(F)) { // expected-note {{Taking false branch}}
+fclose(F);
+return;
+  }
+  fread(Buf, 1, 1, F);   // expected-note {{Assuming that stream reaches end-of-file here}}
+  if (feof(F)) { // expected-note {{Taking true branch}}
+fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+// expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+  }
+  fclose(F);
+}
+
+void check_eof_notes_feof_or_no_error() {
+  FILE *F;
+  char Buf[10];
+  F = fopen("foo1.c", "r");
+  if (F == NULL) // expected-note {{Taking false branch}} expected-note {{'F' is not equal to NULL}}
+return;
+  int RRet = fread(Buf, 1, 1, F); // expected-note {{Assuming that stream reaches end-of-file here}}
+  if (ferror(F)) {// expected-note {{Taking false branch}}
+  } else {
+fread(Buf, 1, 1, F); // expected-warning {{Read function called when stream is in EOF state. Function has no effect}}
+// expected-note@-1 {{Read function called when stream is in EOF state. Function has no effect}}
+  }
+  fclose(F);
+}
Index: clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
===
--- clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
+++ clang/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
@@ -25,8 +25,15 @@
 using namespace ento;
 using namespace std::placeholders;
 
+//===--===//
+// Definition of state data structures.
+//===--===//
+
 namespace {
 
+const char *Desc_StreamEof = "Stream already in EOF";
+const char *Desc_ResourceLeak = "Resource leak";
+
 struct FnDescription;
 
 /// State of the stream error flags.
@@ -146,6 +153,14 @@
   }
 };
 
+} // namespace
+
+//===--===//
+// StreamChecker class and utility functions.
+//===--===//
+
+namespace {
+
 class StreamChecker;
 using FnCheck = std::function;
@@ -203,8 +218,8 @@
"Stream handling error"};
   BugType BT_IllegalWhence{this, "Illegal whence argument",
"Stream handling error"};
-  BugType BT_StreamEof{this, "Stream already in EOF", "Stream handling error"};
-  BugType BT_ResourceLeak{this, "Resource leak", "Stream handling error",
+  BugType BT_StreamEof{this, Desc_StreamEof, "Stream handling error"};
+  BugType BT_ResourceLeak{this, Desc_ResourceLeak, "Stream handling error",
   /*SuppressOnSink =*/true};
 
 public:
@@ -337,7 +352,8 @@
   /// There will be always a state transition into the passed State,
   /// by the new non-fatal error node or (if failed) a normal transition,
   /// to ensure uniform handling.
-  void reportFEofWarning(CheckerContext &C, ProgramStateRef State) const;
+  void reportFEofWarning(SymbolRef StreamSym, CheckerContext &C,
+ ProgramStateRef State) const;
 
   /// Emit resource leak w

[PATCH] D104925: [Analyzer] Improve report of file read at end-of-file condition.

2021-06-30 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked an inline comment as done.
balazske added a comment.

Updated to use `NoteTag`.
Note "End-of-file status is discovered here" is removed.




Comment at: clang/test/Analysis/stream-note.c:141
+  int RRet = fread(Buf, 1, 1, F); // expected-note {{Assuming that stream 
reaches end-of-file here}}
+  if (ferror(F)) {// expected-note {{End-of-file status is 
discovered here}} expected-note {{Taking false branch}}
+  } else {

martong wrote:
> Strictly speaking it is not necessarily and end-of-file status, `ferror` 
> indicates if there was an error.
Exacly the `ferror(F)` is false here. If it is false we may have successful 
read or EOF after read. So the message about "Assuming that stream reaches 
end-of-file here" is really an assumption here (pick one from the two possible 
results). And if EOF happens and `ferror` is false the `feof` must be true, 
this is revealed when we know that `ferror` is false.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104925

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


[clang-tools-extra] 5709842 - [clangd] Fix highlighting for implicit ObjC property refs

2021-06-30 Thread David Goldman via cfe-commits

Author: David Goldman
Date: 2021-06-30T12:31:50-04:00
New Revision: 570984204f24c326699dedcc05793b77b013f068

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

LOG: [clangd] Fix highlighting for implicit ObjC property refs

Objective-C lets you use the `self.prop` syntax as sugar for both
`[self prop]` and `[self setProp:]`, but clangd previously did not
provide a semantic token for `prop`.

Now, we provide a semantic token, treating it like a normal property
except it's backed by a `ObjCMethodDecl` instead of a
`ObjCPropertyDecl`.

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

Added: 


Modified: 
clang-tools-extra/clangd/SemanticHighlighting.cpp
clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp 
b/clang-tools-extra/clangd/SemanticHighlighting.cpp
index bb192596f8c52..b49eb785f2deb 100644
--- a/clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -556,6 +556,42 @@ class CollectExtraHighlightings
 return true;
   }
 
+  // Objective-C allows you to use property syntax `self.prop` as sugar for
+  // `[self prop]` and `[self setProp:]` when there's no explicit `@property`
+  // for `prop` as well as for class properties. We treat this like a property
+  // even though semantically it's equivalent to a method expression.
+  void highlightObjCImplicitPropertyRef(const ObjCMethodDecl *OMD,
+SourceLocation Loc) {
+auto &Tok = H.addToken(Loc, HighlightingKind::Field)
+.addModifier(HighlightingModifier::ClassScope);
+if (OMD->isClassMethod())
+  Tok.addModifier(HighlightingModifier::Static);
+if (isDefaultLibrary(OMD))
+  Tok.addModifier(HighlightingModifier::DefaultLibrary);
+  }
+
+  bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *OPRE) {
+// We need to handle implicit properties here since they will appear to
+// reference `ObjCMethodDecl` via an implicit `ObjCMessageExpr`, so normal
+// highlighting will not work.
+if (!OPRE->isImplicitProperty())
+  return true;
+// A single property expr can reference both a getter and setter, but we 
can
+// only provide a single semantic token, so prefer the getter. In most 
cases
+// the end result should be the same, although it's technically possible
+// that the user defines a setter for a system SDK.
+if (OPRE->isMessagingGetter()) {
+  highlightObjCImplicitPropertyRef(OPRE->getImplicitPropertyGetter(),
+   OPRE->getLocation());
+  return true;
+}
+if (OPRE->isMessagingSetter()) {
+  highlightObjCImplicitPropertyRef(OPRE->getImplicitPropertySetter(),
+   OPRE->getLocation());
+}
+return true;
+  }
+
   bool VisitOverloadExpr(OverloadExpr *E) {
 if (!E->decls().empty())
   return true; // handled by findExplicitReferences.

diff  --git a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp 
b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
index 02ab6bef0a817..a0212856427d6 100644
--- a/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ b/clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -696,11 +696,16 @@ sizeof...($TemplateParameter[[Elements]]);
   int $Field_decl[[_someProperty]];
 }
 @property(nonatomic, assign) int $Field_decl[[someProperty]];
+@property(readonly, class) $Class[[Foo]] 
*$Field_decl_readonly_static[[sharedInstance]];
 @end
 @implementation $Class_decl[[Foo]]
 @synthesize someProperty = _someProperty;
+- (int)$Method_decl[[otherMethod]] {
+  return 0;
+}
 - (int)$Method_decl[[doSomething]] {
-  self.$Field[[someProperty]] = self.$Field[[someProperty]] + 1;
+  $Class[[Foo]].$Field_static[[sharedInstance]].$Field[[someProperty]] 
= 1;
+  self.$Field[[someProperty]] = self.$Field[[someProperty]] + 
self.$Field[[otherMethod]] + 1;
   self->$Field[[_someProperty]] = $Field[[_someProperty]] + 1;
 }
 @end



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


[PATCH] D104904: [OpenMP][AMDGCN] Initial math headers support

2021-06-30 Thread Jon Chesterfield via Phabricator via cfe-commits
JonChesterfield added a comment.

@ronlieb reports that this change means __CUDA__ is defined for openmp amdgcn 
compilation. I'm going to try to verify that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104904

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


[PATCH] D104117: [clangd] Fix highlighting for implicit ObjC property refs

2021-06-30 Thread David Goldman via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG570984204f24: [clangd] Fix highlighting for implicit ObjC 
property refs (authored by dgoldman).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104117

Files:
  clang-tools-extra/clangd/SemanticHighlighting.cpp
  clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -696,11 +696,16 @@
   int $Field_decl[[_someProperty]];
 }
 @property(nonatomic, assign) int $Field_decl[[someProperty]];
+@property(readonly, class) $Class[[Foo]] 
*$Field_decl_readonly_static[[sharedInstance]];
 @end
 @implementation $Class_decl[[Foo]]
 @synthesize someProperty = _someProperty;
+- (int)$Method_decl[[otherMethod]] {
+  return 0;
+}
 - (int)$Method_decl[[doSomething]] {
-  self.$Field[[someProperty]] = self.$Field[[someProperty]] + 1;
+  $Class[[Foo]].$Field_static[[sharedInstance]].$Field[[someProperty]] 
= 1;
+  self.$Field[[someProperty]] = self.$Field[[someProperty]] + 
self.$Field[[otherMethod]] + 1;
   self->$Field[[_someProperty]] = $Field[[_someProperty]] + 1;
 }
 @end
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
===
--- clang-tools-extra/clangd/SemanticHighlighting.cpp
+++ clang-tools-extra/clangd/SemanticHighlighting.cpp
@@ -556,6 +556,42 @@
 return true;
   }
 
+  // Objective-C allows you to use property syntax `self.prop` as sugar for
+  // `[self prop]` and `[self setProp:]` when there's no explicit `@property`
+  // for `prop` as well as for class properties. We treat this like a property
+  // even though semantically it's equivalent to a method expression.
+  void highlightObjCImplicitPropertyRef(const ObjCMethodDecl *OMD,
+SourceLocation Loc) {
+auto &Tok = H.addToken(Loc, HighlightingKind::Field)
+.addModifier(HighlightingModifier::ClassScope);
+if (OMD->isClassMethod())
+  Tok.addModifier(HighlightingModifier::Static);
+if (isDefaultLibrary(OMD))
+  Tok.addModifier(HighlightingModifier::DefaultLibrary);
+  }
+
+  bool VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *OPRE) {
+// We need to handle implicit properties here since they will appear to
+// reference `ObjCMethodDecl` via an implicit `ObjCMessageExpr`, so normal
+// highlighting will not work.
+if (!OPRE->isImplicitProperty())
+  return true;
+// A single property expr can reference both a getter and setter, but we 
can
+// only provide a single semantic token, so prefer the getter. In most 
cases
+// the end result should be the same, although it's technically possible
+// that the user defines a setter for a system SDK.
+if (OPRE->isMessagingGetter()) {
+  highlightObjCImplicitPropertyRef(OPRE->getImplicitPropertyGetter(),
+   OPRE->getLocation());
+  return true;
+}
+if (OPRE->isMessagingSetter()) {
+  highlightObjCImplicitPropertyRef(OPRE->getImplicitPropertySetter(),
+   OPRE->getLocation());
+}
+return true;
+  }
+
   bool VisitOverloadExpr(OverloadExpr *E) {
 if (!E->decls().empty())
   return true; // handled by findExplicitReferences.


Index: clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
===
--- clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
+++ clang-tools-extra/clangd/unittests/SemanticHighlightingTests.cpp
@@ -696,11 +696,16 @@
   int $Field_decl[[_someProperty]];
 }
 @property(nonatomic, assign) int $Field_decl[[someProperty]];
+@property(readonly, class) $Class[[Foo]] *$Field_decl_readonly_static[[sharedInstance]];
 @end
 @implementation $Class_decl[[Foo]]
 @synthesize someProperty = _someProperty;
+- (int)$Method_decl[[otherMethod]] {
+  return 0;
+}
 - (int)$Method_decl[[doSomething]] {
-  self.$Field[[someProperty]] = self.$Field[[someProperty]] + 1;
+  $Class[[Foo]].$Field_static[[sharedInstance]].$Field[[someProperty]] = 1;
+  self.$Field[[someProperty]] = self.$Field[[someProperty]] + self.$Field[[otherMethod]] + 1;
   self->$Field[[_someProperty]] = $Field[[_someProperty]] + 1;
 }
 @end
Index: clang-tools-extra/clangd/SemanticHighlighting.cpp
==

[PATCH] D104797: [WebAssembly] Implementation of global.get/set for reftypes in LLVM IR

2021-06-30 Thread Thomas Lively via Phabricator via cfe-commits
tlively added inline comments.



Comment at: llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp:130
 TT.isArch64Bit()
-? "e-m:e-p:64:64-i64:64-n32:64-S128-ni:1"
-: "e-m:e-p:32:32-i64:64-n32:64-S128-ni:1",
+? (hasReferenceTypes(FS)
+   ? 
"e-m:e-p:64:64-i64:64-n32:64-S128-ni:1:10:20"

pmatos wrote:
> tlively wrote:
> > pmatos wrote:
> > > tlively wrote:
> > > > `hasReferenceTypes` should also be taking the CPU into account, not 
> > > > just the feature string. Normally this would be done via 
> > > > `getSubtargetImpl`, but I guess we probably can't call that this early 
> > > > in the construction of the `WebAssemblyTargetMachine`. Would anything 
> > > > break if we just unconditionally added the reference types address 
> > > > spaces to the data layout string?
> > > Regarding this change, I don't quite understand why referencetypes should 
> > > take the CPU into account. Are there CPU variants for the wasm backend? I 
> > > haven't touched the conditional because that would mean touching the 
> > > several tests that don't enable reference types and use the old data 
> > > layout string. However, I would think that if that's the path we want to 
> > > follow here, we could do it and change all wasm tests to use the layout 
> > > string with reference types.
> > > 
> > Yes, there are CPU variants defined here: 
> > https://github.com/llvm/llvm-project/blob/7ac0442fe59dbe0f9127e79e8786a7dd6345c537/llvm/lib/Target/WebAssembly/WebAssembly.td#L89-L100.
> >  Note that the CPU may enable reference types even if the feature string 
> > does not. If it doesn't break anything, then unconditionally updating the 
> > layout string sounds like the best option.
> Interesting - had not come accross it. Bleeding edge does not seem to include 
> reference-types. What's the reason for this? 
We don't have a well-defined process for adding features to bleeding-edge, but 
I think typically they're added once they're mostly stable and usable in the 
tools.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104797

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


[PATCH] D95807: [Coroutines] Add the newly generated SCCs back to the CGSCC work queue after CoroSplit actually happened

2021-06-30 Thread Xun Li via Phabricator via cfe-commits
lxfind added inline comments.



Comment at: llvm/lib/Transforms/Coroutines/CoroSplit.cpp:2112-2114
 StringRef Value = Attr.getValueAsString();
 LLVM_DEBUG(dbgs() << "CoroSplit: Processing coroutine '" << F.getName()
   << "' state: " << Value << "\n");

ChuanqiXu wrote:
> Refactor this into:
> ```
> LLVM_DEBUG(dbgs() << "CoroSplit: Processing coroutine '" << F.getName()
>   << "' state: " << Attr.getValueAsString() << "\n");
> ```
> could erase an warning in release build.
Good catch. How did you catch this? It seems like I don't see warning on my Mac 
by default.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95807

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


[PATCH] D95807: [Coroutines] Add the newly generated SCCs back to the CGSCC work queue after CoroSplit actually happened

2021-06-30 Thread Xun Li via Phabricator via cfe-commits
lxfind updated this revision to Diff 355607.
lxfind added a comment.

fix warning


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D95807

Files:
  clang/test/CodeGenCoroutines/coro-newpm-pipeline.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/Coroutines/CoroSplit.cpp
  llvm/test/Transforms/Coroutines/ArgAddr.ll
  llvm/test/Transforms/Coroutines/coro-alloc-with-param-O0.ll
  llvm/test/Transforms/Coroutines/coro-alloc-with-param-O2.ll
  llvm/test/Transforms/Coroutines/coro-alloca-01.ll
  llvm/test/Transforms/Coroutines/coro-alloca-02.ll
  llvm/test/Transforms/Coroutines/coro-alloca-03.ll
  llvm/test/Transforms/Coroutines/coro-alloca-04.ll
  llvm/test/Transforms/Coroutines/coro-alloca-05.ll
  llvm/test/Transforms/Coroutines/coro-alloca-06.ll
  llvm/test/Transforms/Coroutines/coro-alloca-07.ll
  llvm/test/Transforms/Coroutines/coro-alloca-08.ll
  llvm/test/Transforms/Coroutines/coro-async.ll
  llvm/test/Transforms/Coroutines/coro-byval-param.ll
  llvm/test/Transforms/Coroutines/coro-catchswitch-cleanuppad.ll
  llvm/test/Transforms/Coroutines/coro-catchswitch.ll
  llvm/test/Transforms/Coroutines/coro-debug.ll
  llvm/test/Transforms/Coroutines/coro-eh-aware-edge-split-00.ll
  llvm/test/Transforms/Coroutines/coro-eh-aware-edge-split-01.ll
  llvm/test/Transforms/Coroutines/coro-eh-aware-edge-split-02.ll
  llvm/test/Transforms/Coroutines/coro-frame-arrayalloca.ll
  llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-00.ll
  llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-01.ll
  llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-02.ll
  llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-03.ll
  llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-04.ll
  llvm/test/Transforms/Coroutines/coro-frame-reuse-alloca-05.ll
  llvm/test/Transforms/Coroutines/coro-frame-unreachable.ll
  llvm/test/Transforms/Coroutines/coro-frame.ll
  llvm/test/Transforms/Coroutines/coro-materialize.ll
  llvm/test/Transforms/Coroutines/coro-padding.ll
  llvm/test/Transforms/Coroutines/coro-param-copy.ll
  llvm/test/Transforms/Coroutines/coro-retcon-alloca.ll
  llvm/test/Transforms/Coroutines/coro-retcon-frame.ll
  llvm/test/Transforms/Coroutines/coro-retcon-once-value.ll
  llvm/test/Transforms/Coroutines/coro-retcon-once-value2.ll
  llvm/test/Transforms/Coroutines/coro-retcon-resume-values.ll
  llvm/test/Transforms/Coroutines/coro-retcon-resume-values2.ll
  llvm/test/Transforms/Coroutines/coro-retcon-unreachable.ll
  llvm/test/Transforms/Coroutines/coro-retcon-value.ll
  llvm/test/Transforms/Coroutines/coro-retcon.ll
  llvm/test/Transforms/Coroutines/coro-spill-after-phi.ll
  llvm/test/Transforms/Coroutines/coro-spill-corobegin.ll
  llvm/test/Transforms/Coroutines/coro-spill-defs-before-corobegin.ll
  llvm/test/Transforms/Coroutines/coro-spill-promise.ll
  llvm/test/Transforms/Coroutines/coro-split-00.ll
  llvm/test/Transforms/Coroutines/coro-split-02.ll
  llvm/test/Transforms/Coroutines/coro-split-alloc.ll
  llvm/test/Transforms/Coroutines/coro-split-dbg.ll
  llvm/test/Transforms/Coroutines/coro-split-eh-00.ll
  llvm/test/Transforms/Coroutines/coro-split-eh-01.ll
  llvm/test/Transforms/Coroutines/coro-split-hidden.ll
  llvm/test/Transforms/Coroutines/coro-split-musttail.ll
  llvm/test/Transforms/Coroutines/coro-split-musttail1.ll
  llvm/test/Transforms/Coroutines/coro-split-musttail2.ll
  llvm/test/Transforms/Coroutines/coro-split-musttail3.ll
  llvm/test/Transforms/Coroutines/coro-split-recursive.ll
  llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-01.ll
  llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-02.ll
  llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-03.ll
  llvm/test/Transforms/Coroutines/coro-split-sink-lifetime-04.ll
  llvm/test/Transforms/Coroutines/coro-swifterror.ll
  llvm/test/Transforms/Coroutines/coro-zero-alloca.ll
  llvm/test/Transforms/Coroutines/no-suspend.ll
  llvm/test/Transforms/Coroutines/restart-trigger.ll
  llvm/test/Transforms/Coroutines/smoketest.ll

Index: llvm/test/Transforms/Coroutines/smoketest.ll
===
--- llvm/test/Transforms/Coroutines/smoketest.ll
+++ llvm/test/Transforms/Coroutines/smoketest.ll
@@ -10,12 +10,16 @@
 ; RUN: opt < %s -disable-output -passes='default' -enable-coroutines \
 ; RUN: -debug-pass-manager 2>&1 | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-OPT
 ; RUN: opt < %s -disable-output -debug-pass-manager \
-; RUN: -passes='function(coro-early),cgscc(coro-split),function(coro-elide,coro-cleanup)' 2>&1 \
+; RUN: -passes='function(coro-early),function(coro-elide),cgscc(coro-split),function(coro-cleanup)' 2>&1 \
 ; RUN: | FileCheck %s --check-prefixes=CHECK-ALL,CHECK-OPT
 
+; note that we run CoroElidePass before CoroSplitPass. This is because CoroElidePass is part of
+; function simplification pipeline, which runs before CoroSplitPass. And since @foo is not
+; a corout

[clang-tools-extra] b56e5f8 - [clangd] Unbreak mac build after 0c96a92d8666b8

2021-06-30 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2021-06-30T12:53:38-04:00
New Revision: b56e5f8a10c1ec4fd3750bdd269fbad778820326

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

LOG: [clangd] Unbreak mac build after 0c96a92d8666b8

That commit removed the include of Features.inc from ClangdLSPServer.h,
but ClangdMain.cpp relied on this include to pull in Features.inc for
the #if at the bottom of Transport.h.

Since the include is needed in Transport.h, just add it to there
directly.

Added: 


Modified: 
clang-tools-extra/clangd/Transport.h

Removed: 




diff  --git a/clang-tools-extra/clangd/Transport.h 
b/clang-tools-extra/clangd/Transport.h
index ae6da722d91b..b3db4eba85f9 100644
--- a/clang-tools-extra/clangd/Transport.h
+++ b/clang-tools-extra/clangd/Transport.h
@@ -18,6 +18,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_TRANSPORT_H_
 
+#include "Features.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/raw_ostream.h"



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


  1   2   3   >