[llvm-branch-commits] [compiler-rt] 4c6350f - [compiler-rt] [test] Handle missing ld.gold gracefully

2022-09-07 Thread Tobias Hieta via llvm-branch-commits

Author: Michał Górny
Date: 2022-09-08T08:49:20+02:00
New Revision: 4c6350f4e393c1782fd479798485b55063aa90fc

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

LOG: [compiler-rt] [test] Handle missing ld.gold gracefully

Fix the is_binutils_lto_supported() function to handle missing
executables gracefully.  Currently, the function does not catch
exceptions from subprocess.Popen() and therefore causes lit to crash
if config.gold_executable does not specify a valid executable:

```
lit: /usr/lib/python3.11/site-packages/lit/TestingConfig.py:136: fatal: unable 
to parse config file '/tmp/portage/sys-libs/compiler-rt-
15.0.0/work/compiler-rt/test/lit.common.cfg.py', traceback: Traceback (most 
recent call last):
  File "/usr/lib/python3.11/site-packages/lit/TestingConfig.py", line 125, in 
load_from_path
exec(compile(data, path, 'exec'), cfg_globals, None)
  File 
"/tmp/portage/sys-libs/compiler-rt-15.0.0/work/compiler-rt/test/lit.common.cfg.py",
 line 561, in 
if is_binutils_lto_supported():
   ^^^
  File 
"/tmp/portage/sys-libs/compiler-rt-15.0.0/work/compiler-rt/test/lit.common.cfg.py",
 line 543, in is_binutils_lto_supported
ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, 
env={'LANG': 'C'})
 

  File "/usr/lib/python3.11/subprocess.py", line 1022, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1899, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 
'GOLD_EXECUTABLE-NOTFOUND'
```

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

(cherry picked from commit ea953b9d9a65c202985a79f1f95da115829baef6)

Added: 


Modified: 
compiler-rt/test/lit.common.cfg.py

Removed: 




diff  --git a/compiler-rt/test/lit.common.cfg.py 
b/compiler-rt/test/lit.common.cfg.py
index c5a8420da14ff..3dd258283e5ce 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -540,9 +540,12 @@ def is_binutils_lto_supported():
   # We require both ld.bfd and ld.gold exist and support plugins. They are in
   # the same repository 'binutils-gdb' and usually built together.
   for exe in (config.gnu_ld_executable, config.gold_executable):
-ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, 
env={'LANG': 'C'})
-ld_out = ld_cmd.stdout.read().decode()
-ld_cmd.wait()
+try:
+  ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, 
env={'LANG': 'C'})
+  ld_out = ld_cmd.stdout.read().decode()
+  ld_cmd.wait()
+except OSError:
+  return False
 if not '-plugin' in ld_out:
   return False
 



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


[llvm-branch-commits] [clang] 0595790 - [clang-format] Distinguish logical and after bracket from reference

2022-09-07 Thread Tobias Hieta via llvm-branch-commits

Author: jackh
Date: 2022-09-08T08:49:27+02:00
New Revision: 0595790461e188d61ee35c81db7789c52c88190c

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

LOG: [clang-format] Distinguish logical and after bracket from reference

Fix commit `b646f0955574` and remove redundant code.

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

(cherry picked from commit ef71383b0cfbacdbebf495015f6ead5294bf7759)

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 5991cf23d5dc7..cf6549e2a5bda 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2329,25 +2329,6 @@ class AnnotatingParser {
 !PrevToken->MatchingParen)
   return TT_PointerOrReference;
 
-// For "} &&"
-if (PrevToken->is(tok::r_brace) && Tok.is(tok::ampamp)) {
-  const FormatToken *MatchingLBrace = PrevToken->MatchingParen;
-
-  // We check whether there is a TemplateCloser(">") to indicate it's a
-  // template or not. If it's not a template, "&&" is likely a reference
-  // operator.
-  //   struct {} &&ref = {};
-  if (!MatchingLBrace)
-return TT_PointerOrReference;
-  FormatToken *BeforeLBrace = MatchingLBrace->getPreviousNonComment();
-  if (!BeforeLBrace || BeforeLBrace->isNot(TT_TemplateCloser))
-return TT_PointerOrReference;
-
-  // If it is a template, "&&" is a binary operator.
-  //   enable_if<>{} && ...
-  return TT_BinaryOperator;
-}
-
 if (PrevToken->Tok.isLiteral() ||
 PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
tok::kw_false, tok::r_brace)) {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index e26cfb0ee88a0..fdc7c4a0c2fe2 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10474,6 +10474,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyFormat("class {\n"
"}&& ptr = {};",
Style);
+  verifyFormat("bool b = 3 == int{3} && true;");
 
   Style.PointerAlignment = FormatStyle::PAS_Middle;
   verifyFormat("struct {\n"

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 4b2622522e0f8..ad8ba76bdcca0 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -86,6 +86,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
   EXPECT_EQ(Tokens.size(), 5u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::amp, TT_UnaryOperator);
 
+  Tokens = annotate("bool b = 3 == int{3} && true;\n");
+  EXPECT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+
   Tokens = annotate("struct {\n"
 "} *ptr;");
   EXPECT_EQ(Tokens.size(), 7u) << Tokens;



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


[llvm-branch-commits] [llvm] 5e1ba27 - [DAG] extractShiftForRotate - replace assertion for shift opcode with an early-out

2022-09-07 Thread Tobias Hieta via llvm-branch-commits

Author: Simon Pilgrim
Date: 2022-09-08T08:49:32+02:00
New Revision: 5e1ba27b9d494d26ea05d27a0f097ee99ea38e22

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

LOG: [DAG] extractShiftForRotate - replace assertion for shift opcode with an 
early-out

We feed the result from the first extractShiftForRotate call into the second, 
and that result might no longer be a shift op (usually due to constant folding).

NOTE: We REALLY need to stop creating nodes on the fly inside 
extractShiftForRotate!

Fixes Issue #57474

(cherry picked from commit eaede4b5b7cfc13ca0e484b4cb25b2f751d86fd9)

Added: 
llvm/test/CodeGen/X86/pr57474.ll

Modified: 
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Removed: 




diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp 
b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 42a141e8876b8..a7f9382478d47 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -7163,9 +7163,8 @@ static SDValue extractShiftForRotate(SelectionDAG &DAG, 
SDValue OppShift,
  SDValue ExtractFrom, SDValue &Mask,
  const SDLoc &DL) {
   assert(OppShift && ExtractFrom && "Empty SDValue");
-  assert(
-  (OppShift.getOpcode() == ISD::SHL || OppShift.getOpcode() == ISD::SRL) &&
-  "Existing shift must be valid as a rotate half");
+  if (OppShift.getOpcode() != ISD::SHL && OppShift.getOpcode() != ISD::SRL)
+return SDValue();
 
   ExtractFrom = stripConstantMask(DAG, ExtractFrom, Mask);
 

diff  --git a/llvm/test/CodeGen/X86/pr57474.ll 
b/llvm/test/CodeGen/X86/pr57474.ll
new file mode 100644
index 0..b12b7ee475861
--- /dev/null
+++ b/llvm/test/CodeGen/X86/pr57474.ll
@@ -0,0 +1,31 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-- | FileCheck %s
+
+define void @PR57474() nounwind {
+; CHECK-LABEL: PR57474:
+; CHECK:   # %bb.0: # %BB
+; CHECK-NEXT:pushq %rbp
+; CHECK-NEXT:movq %rsp, %rbp
+; CHECK-NEXT:movq %rsp, %rax
+; CHECK-NEXT:leaq -16(%rax), %rsp
+; CHECK-NEXT:movw $-32768, -16(%rax) # imm = 0x8000
+; CHECK-NEXT:movq %rbp, %rsp
+; CHECK-NEXT:popq %rbp
+; CHECK-NEXT:retq
+BB:
+  br label %BB1
+
+BB1:  ; preds = %BB
+  %A = alloca <1 x i16>, align 2
+  %L1 = load <1 x i16>, <1 x i16>* %A, align 2
+  %I = insertelement <1 x i16> %L1, i16 -1, i16 0
+  %B6 = add <1 x i16> %I, %I
+  %B3 = srem <1 x i16> %B6, %I
+  %B1 = add <1 x i16> %B3, %B3
+  %B5 = sdiv <1 x i16> %B1, %I
+  %B4 = udiv <1 x i16> %B3, 
+  %B2 = or <1 x i16> %B4, %B5
+  %B = lshr <1 x i16> , %B2
+  store <1 x i16> %B, <1 x i16>* %A, align 2
+  ret void
+}



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


[llvm-branch-commits] [clang] 1c73596 - [clang] Skip re-building lambda expressions in parameters to consteval fns.

2022-09-07 Thread Tobias Hieta via llvm-branch-commits

Author: Utkarsh Saxena
Date: 2022-09-08T08:49:36+02:00
New Revision: 1c73596d345481de957e5ccc0bedf1fb9d9f643a

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

LOG: [clang] Skip re-building lambda expressions in parameters to consteval fns.

As discussed in this 
[comment](https://github.com/llvm/llvm-project/issues/56183#issuecomment-1224331699),
we end up building the lambda twice: once while parsing the function calls and 
then again while handling the immediate invocation.

This happens specially during removing nested immediate invocation.
Eg: When we have another consteval function as the parameter along with this 
lambda expression. Eg: `foo(bar([]{}))`, `foo(bar(), []{})`

While removing such nested immediate invocations, we should not rebuild this 
lambda. (IIUC, rebuilding a lambda would always generate a new type which will 
never match the original type from parsing)

Fixes: https://github.com/llvm/llvm-project/issues/56183
Fixes: https://github.com/llvm/llvm-project/issues/51695
Fixes: https://github.com/llvm/llvm-project/issues/50455
Fixes: https://github.com/llvm/llvm-project/issues/54872
Fixes: https://github.com/llvm/llvm-project/issues/54587

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

(cherry picked from commit e7eec38246560781e0a4020b19c7eb038a8c5655)

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5620cb3b64004..96c4120ea522d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -542,6 +542,12 @@ C++20 Feature Support
 - As per "Conditionally Trivial Special Member Functions" (P0848), it is
   now possible to overload destructors using concepts. Note that the rest
   of the paper about other special member functions is not yet implemented.
+- Skip rebuilding lambda expressions in arguments of immediate invocations.
+  This fixes `GH56183 `_,
+  `GH51695 `_,
+  `GH50455 `_,
+  `GH54872 `_,
+  `GH54587 `_.
 
 C++2b Feature Support
 ^

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 0e24237faae5b..83081bbf0aa0c 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17600,6 +17600,11 @@ static void RemoveNestedImmediateInvocation(
   DRSet.erase(E);
   return E;
 }
+ExprResult TransformLambdaExpr(LambdaExpr *E) {
+  // Do not rebuild lambdas to avoid creating a new type.
+  // Lambdas have already been processed inside their eval context.
+  return E;
+}
 bool AlwaysRebuild() { return false; }
 bool ReplacingOriginal() { return true; }
 bool AllowSkippingCXXConstructExpr() {

diff  --git a/clang/test/SemaCXX/cxx2a-consteval.cpp 
b/clang/test/SemaCXX/cxx2a-consteval.cpp
index df2a9925c0154..c6f3e27346a10 100644
--- a/clang/test/SemaCXX/cxx2a-consteval.cpp
+++ b/clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -766,3 +766,72 @@ void test() {
   static_assert(c == 8);
 }
 }
+
+// https://github.com/llvm/llvm-project/issues/51695
+namespace GH51695 {
+// Original 
+template 
+struct type_t {};
+
+template 
+struct list_t {};
+
+template 
+consteval auto pop_front(list_t) -> auto {
+  return list_t{};
+}
+
+template 
+consteval auto apply(list_t, F fn) -> auto {
+  return fn(type_t{}...);
+}
+
+void test1() {
+  constexpr auto x = apply(pop_front(list_t{}),
+[](type_t...) { return 42; });
+  static_assert(x == 42);
+}
+// Reduced 1 
+consteval bool zero() { return false; }
+
+template 
+consteval bool foo(bool, F f) {
+  return f();
+}
+
+void test2() {
+  constexpr auto x = foo(zero(), []() { return true; });
+  static_assert(x);
+}
+
+// Reduced 2 
+template 
+consteval auto bar(F f) { return f;}
+
+void test3() {
+  constexpr auto t1 = bar(bar(bar(bar([]() { return true; }();
+  static_assert(t1);
+
+  int a = 1; // expected-note {{declared here}}
+  auto t2 = bar(bar(bar(bar([=]() { return a; }(); // expected-error-re 
{{call to consteval function 'GH51695::bar<(lambda at {{.*}})>' is not a 
constant expression}}
+  // expected-note@-1 {{read of non-const variable 'a' is not allowed in a 
constant expression}}
+
+  constexpr auto t3 = bar(bar([x=bar(42)]() { return x; }))();
+  static_assert(t3==42);
+  constexpr auto t4 = bar(bar([x=bar(42)]() co