[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-06-24 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

Thanks @MaskRay for the quick patch!


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

https://reviews.llvm.org/D126864

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-06-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

The CPython usage is a real UB: https://github.com/python/cpython/issues/94250

In D126864#3609497 , @efriedma wrote:

> I suspect the refactoring in the latest version of the patch accidentally 
> made UBSan a bit more strict by default.

Yes, the patch accidentally dropped a -fsanitize=array-bounds workaround for 
size-1 array as the last member of a structure. I added it back in 
572b08790a69f955ae0cbb1b4a7d4a215f15dad9 



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

https://reviews.llvm.org/D126864

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


[PATCH] D128574: [clang-format] Quit analyzing solution space for large state count

2022-06-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/56043.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128574

Files:
  clang/lib/Format/UnwrappedLineFormatter.cpp


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1163,6 +1163,10 @@
 
 // While not empty, take first element and follow edges.
 while (!Queue.empty()) {
+  // Quit if we still haven't found a solution by now.
+  if (Count > 2500)
+return 0;
+
   Penalty = Queue.top().first.first;
   StateNode *Node = Queue.top().second;
   if (!Node->State.NextToken) {


Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1163,6 +1163,10 @@
 
 // While not empty, take first element and follow edges.
 while (!Queue.empty()) {
+  // Quit if we still haven't found a solution by now.
+  if (Count > 2500)
+return 0;
+
   Penalty = Queue.top().first.first;
   StateNode *Node = Queue.top().second;
   if (!Node->State.NextToken) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 262b409 - [Driver] Fix -fstrict-flex-arrays= help message after D126864

2022-06-24 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-06-24T22:20:37-07:00
New Revision: 262b4091f9724994f4675fa0bab14b4988f10308

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

LOG: [Driver] Fix -fstrict-flex-arrays= help message after D126864

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 81d1d53cea9b..5d5f886ea753 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1141,7 +1141,7 @@ def fapple_kext : Flag<["-"], "fapple-kext">, 
Group, Flags<[CC1Option]>
   HelpText<"Use Apple's kernel extensions ABI">,
   MarshallingInfoFlag>;
 def fstrict_flex_arrays_EQ : Joined<["-"], 
"fstrict-flex-arrays=">,Group,
-  MetaVarName<", Values<"1,2,3">,
+  MetaVarName<"">, Values<"0,1,2,3">,
   LangOpts<"StrictFlexArrays">,
   Flags<[CC1Option]>,
   HelpText<"Enable optimizations based on the strict definition of flexible 
arrays">,



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


[clang] 572b087 - [clang] Add back -fsanitize=array-bounds workaround for size-1 array after -fstrict-flex-arrays change

2022-06-24 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-06-24T22:15:47-07:00
New Revision: 572b08790a69f955ae0cbb1b4a7d4a215f15dad9

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

LOG: [clang] Add back -fsanitize=array-bounds workaround for size-1 array after 
-fstrict-flex-arrays change

Before C99 introduced flexible array member, common practice uses size-1 array
to emulate FAM, e.g. https://github.com/python/cpython/issues/94250
As a result, -fsanitize=array-bounds instrumentation skipped such structures
as a workaround (from 539e4a77bbabbc19f22b2bd24e04af2e432e599d).

D126864 accidentally dropped the workaround. Add it back with tests.

Added: 
clang/test/CodeGen/bounds-checking-fma.c

Modified: 
clang/lib/CodeGen/CGExpr.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index df96be70800b..0fed82d3e68c 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -931,8 +931,8 @@ static llvm::Value *getArrayIndexingBound(CodeGenFunction 
&CGF,
 
   if (const auto *CE = dyn_cast(Base)) {
 if (CE->getCastKind() == CK_ArrayToPointerDecay &&
-!CE->getSubExpr()->isFlexibleArrayMember(Context,
- StrictFlexArraysLevel)) {
+!CE->getSubExpr()->IgnoreParens()->isFlexibleArrayMember(
+Context, std::max(StrictFlexArraysLevel, 1))) {
   IndexedType = CE->getSubExpr()->getType();
   const ArrayType *AT = IndexedType->castAsArrayTypeUnsafe();
   if (const auto *CAT = dyn_cast(AT))

diff  --git a/clang/test/CodeGen/bounds-checking-fma.c 
b/clang/test/CodeGen/bounds-checking-fma.c
new file mode 100644
index ..fbc51dc7a5e1
--- /dev/null
+++ b/clang/test/CodeGen/bounds-checking-fma.c
@@ -0,0 +1,42 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=array-bounds %s -o - | 
FileCheck %s --check-prefixes=CHECK,CHECK-STRICT-0
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=array-bounds 
-fstrict-flex-arrays=1 %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-1
+// RUN: %clang_cc1 -emit-llvm -triple x86_64 -fsanitize=array-bounds 
-fstrict-flex-arrays=2 %s -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-STRICT-2
+
+// Before flexible array member was added to C99, many projects use a
+// one-element array as the last emember of a structure as an alternative.
+// E.g. https://github.com/python/cpython/issues/94250
+// Suppress such errors with -fstrict-flex-arrays=0.
+struct One {
+  int a[1];
+};
+struct Two {
+  int a[2];
+};
+struct Three {
+  int a[3];
+};
+
+// CHECK-LABEL: define {{.*}} @test_one(
+int test_one(struct One *p, int i) {
+  // CHECK-STRICT-0-NOT: @__ubsan
+  // CHECK-STRICT-1-NOT: @__ubsan
+  // CHECK-STRICT-2: call void @__ubsan_handle_out_of_bounds_abort(
+  return p->a[i] + (p->a)[i];
+}
+
+// CHECK-LABEL: define {{.*}} @test_two(
+int test_two(struct Two *p, int i) {
+  // CHECK-STRICT-0: call void @__ubsan_handle_out_of_bounds_abort(
+  // CHECK-STRICT-1: call void @__ubsan_handle_out_of_bounds_abort(
+  // CHECK-STRICT-2: call void @__ubsan_handle_out_of_bounds_abort(
+  return p->a[i] + (p->a)[i];
+}
+
+// CHECK-LABEL: define {{.*}} @test_three(
+int test_three(struct Three *p, int i) {
+  // CHECK-STRICT-0: call void @__ubsan_handle_out_of_bounds_abort(
+  // CHECK-STRICT-1: call void @__ubsan_handle_out_of_bounds_abort(
+  // CHECK-STRICT-2: call void @__ubsan_handle_out_of_bounds_abort(
+  return p->a[i] + (p->a)[i];
+}



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


[PATCH] D128328: [C++20][Modules] Improve handing of Private Module Fragment diagnostics.

2022-06-24 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai added a comment.

Sorry for changing my mind. I've thought about the errors more and especially 
about the case mentioned by Chuanqi

  export module A;
  [export] inline void func();

I'm afraid it can complicate the implementation but we can achieve some 
consistency with errors like

  export module A;
  export inline void func(); // error: no definition for exported inline 
function 'func' in module 'A'

and

  export module A;
  export inline void func(); // error: no definition for exported inline 
function 'func' in module 'A'
  //...
  module :private;
  void func() {}  // note: definition here is not reachable as it is private

I think it is useful to have connection between declaration and definition and 
to explain why the definition is no good.

Specific wording around "no definition | missing definition | definition 
required" is flexible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128328

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


[PATCH] D107082: [X86][RFC] Enable `_Float16` type support on X86 following the psABI

2022-06-24 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

I'll take care next time. Thanks @MaskRay !


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107082

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


[PATCH] D128571: [X86] Support `_Float16` on SSE2 and up

2022-06-24 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei created this revision.
pengfei added reviewers: zahiraam, rjmccall, bkramer, alexfh.
Herald added a subscriber: jsji.
Herald added a project: All.
pengfei requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This is split from D113107  to address #56204 
and 
https://discourse.llvm.org/t/how-to-build-compiler-rt-for-new-x86-half-float-abi/63366


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128571

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/lib/Basic/Targets/X86.cpp
  clang/test/CodeGen/X86/Float16-arithmetic.c
  clang/test/CodeGen/X86/Float16-complex.c
  clang/test/CodeGen/X86/avx512fp16-complex.c
  clang/test/Sema/Float16.c
  clang/test/Sema/conversion-target-dep.c
  clang/test/SemaCXX/Float16.cpp

Index: clang/test/SemaCXX/Float16.cpp
===
--- clang/test/SemaCXX/Float16.cpp
+++ clang/test/SemaCXX/Float16.cpp
@@ -1,18 +1,10 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
-// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s
 
-#ifdef HAVE
 // expected-no-diagnostics
-#endif // HAVE
 
-#ifndef HAVE
-// expected-error@+2{{_Float16 is not supported on this target}}
-#endif // !HAVE
 _Float16 f;
 
-#ifndef HAVE
-// expected-error@+2{{invalid suffix 'F16' on floating constant}}
-#endif // !HAVE
 const auto g = 1.1F16;
Index: clang/test/Sema/conversion-target-dep.c
===
--- clang/test/Sema/conversion-target-dep.c
+++ clang/test/Sema/conversion-target-dep.c
@@ -6,7 +6,7 @@
 
 long double ld;
 double d;
-_Float16 f16; // x86-error {{_Float16 is not supported on this target}}
+_Float16 f16;
 
 int main(void) {
   ld = d; // x86-warning {{implicit conversion increases floating-point precision: 'double' to 'long double'}}
Index: clang/test/Sema/Float16.c
===
--- clang/test/Sema/Float16.c
+++ clang/test/Sema/Float16.c
@@ -1,18 +1,13 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc %s
-// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc -target-feature +avx512fp16 %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s -DHAVE
-// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s -DHAVE
+// RUN: %clang_cc1 -fsyntax-only -verify -triple x86_64-linux-pc -target-feature +avx512fp16 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple spir-unknown-unknown %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple armv7a-linux-gnu %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple aarch64-linux-gnu %s
 
-#ifndef HAVE
-// expected-error@+2{{_Float16 is not supported on this target}}
-#endif // HAVE
 _Float16 f;
 
-#ifdef HAVE
 _Complex _Float16 a;
 void builtin_complex(void) {
   _Float16 a = 0;
   (void)__builtin_complex(a, a); // expected-error {{'_Complex _Float16' is invalid}}
 }
-#endif
Index: clang/test/CodeGen/X86/Float16-complex.c
===
--- clang/test/CodeGen/X86/Float16-complex.c
+++ clang/test/CodeGen/X86/Float16-complex.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -target-feature +avx512fp16 -o - | FileCheck %s --check-prefix=X86
+// RUN: %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s --check-prefix=X86
 
 _Float16 _Complex add_half_rr(_Float16 a, _Float16 b) {
   // X86-LABEL: @add_half_rr(
Index: clang/test/CodeGen/X86/Float16-arithmetic.c
===
--- /dev/null
+++ clang/test/CodeGen/X86/Float16-arithmetic.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple  x86_64-unknown-unknown \
+// RUN: -emit-llvm -o - %s  | FileCheck %s --check-prefixes=CHECK
+
+// CHECK-NOT: fpext
+// CHECK-NOT: fptrunc
+
+_Float16 add1(_Float16 a, _Float16 b) {
+  return a + b;
+}
+
+_Float16 add2(_Float16 a, _Float16 b, _Float16 c) {
+  return a + b + c;
+}
+
+_Float16 div(_Float16 a, _Float16 b) {
+  return a / b;
+}
+
+_Float16 mul(_Float16 a, _Float16 b) {
+  return a * b;
+}
+
+_Float16 add_and_mul1(_Float16 a, _Float16 b, _Float16 c, _Float16 d) {
+  return a * b + c * d;
+}
+
+_Float16 add_and_mul2(_Float16 a, _Float16 b, _Float16 c, _Float16 d) {
+  return (a - 6 * b) + c;
+}
Index: clang/lib/Basic/Targets/X86.cpp

[PATCH] D128567: [WIP][Fuchsia] Set LLVM_TOOL_LLD_BUILD to allow some extra runtimes tests to run

2022-06-24 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D128567#3609644 , @leonardchan 
wrote:

> I'm thinking `LLVM_TOOL_LLD_BUILD` might be a remnant of times before the 
> monorepo since lld doesn't exist under `llvm/tools` anymore.

Yes, that's correct. The proposed cleanup is the solution I'd prefer. I 
recently did a similar cleanup for libc++ in D126905 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128567

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


[PATCH] D128496: [clang-format] Further improve requires clause detection

2022-06-24 Thread Björn Schäpers via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
HazardyKnusperkeks marked an inline comment as done.
Closed by commit rGb3aeca3962bb: [clang-format] Further improve requires clause 
detection (authored by HazardyKnusperkeks).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128496

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/TokenAnnotatorTest.cpp


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -402,6 +402,33 @@
   EXPECT_TOKEN(Tokens[25], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[27], tok::greater, TT_TemplateCloser);
   EXPECT_TOKEN(Tokens[28], tok::greater, TT_TemplateCloser);
+
+  Tokens = annotate("auto bar() -> int requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto bar() -> void requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto bar() -> MyType requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens =
+  annotate("auto bar() -> SOME_MACRO_TYPE requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens =
+  annotate("auto bar() -> qualified::type requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresClause);
+
+  Tokens =
+  annotate("auto bar() -> Template requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3168,6 +3168,11 @@
 break;
   }
   default:
+if (PreviousNonComment->isTypeOrIdentifier()) {
+  // This is a requires clause.
+  parseRequiresClause(RequiresToken);
+  return true;
+}
 // It's an expression.
 parseRequiresExpression(RequiresToken);
 return false;


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -402,6 +402,33 @@
   EXPECT_TOKEN(Tokens[25], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[27], tok::greater, TT_TemplateCloser);
   EXPECT_TOKEN(Tokens[28], tok::greater, TT_TemplateCloser);
+
+  Tokens = annotate("auto bar() -> int requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto bar() -> void requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto bar() -> MyType requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens =
+  annotate("auto bar() -> SOME_MACRO_TYPE requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens =
+  annotate("auto bar() -> qualified::type requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresClause);
+
+  Tokens =
+  annotate("auto bar() -> Template requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3168,6 +3168,11 @@
 break;
   }
   default:
+if (PreviousNonComment->isTypeOrIdentifier()) {
+  // This is a requires clause.
+  parseRequiresClause(RequiresToken);
+  return true;
+}
 // It's an expression.
 parseRequiresExpression(RequiresToken);
 return false;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] b3aeca3 - [clang-format] Further improve requires clause detection

2022-06-24 Thread Björn Schäpers via cfe-commits

Author: Björn Schäpers
Date: 2022-06-25T04:43:38+02:00
New Revision: b3aeca3962bb39dfe110472ea033bda32044455d

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

LOG: [clang-format] Further improve requires clause detection

If there is a typeish token before the requires, it can't be a requires
expression.

Fixes https://github.com/llvm/llvm-project/issues/56176

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index 77a59d8585091..c1bfa4d573a72 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3168,6 +3168,11 @@ bool clang::format::UnwrappedLineParser::parseRequires() 
{
 break;
   }
   default:
+if (PreviousNonComment->isTypeOrIdentifier()) {
+  // This is a requires clause.
+  parseRequiresClause(RequiresToken);
+  return true;
+}
 // It's an expression.
 parseRequiresExpression(RequiresToken);
 return false;

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index aa91f389a5d2e..2dbc5da07d4db 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -402,6 +402,33 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
   EXPECT_TOKEN(Tokens[25], tok::less, TT_TemplateOpener);
   EXPECT_TOKEN(Tokens[27], tok::greater, TT_TemplateCloser);
   EXPECT_TOKEN(Tokens[28], tok::greater, TT_TemplateCloser);
+
+  Tokens = annotate("auto bar() -> int requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto bar() -> void requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto bar() -> MyType requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens =
+  annotate("auto bar() -> SOME_MACRO_TYPE requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::kw_requires, TT_RequiresClause);
+
+  Tokens =
+  annotate("auto bar() -> qualified::type requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::kw_requires, TT_RequiresClause);
+
+  Tokens =
+  annotate("auto bar() -> Template requires(is_integral_v) {}");
+  ASSERT_EQ(Tokens.size(), 19u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::kw_requires, TT_RequiresClause);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {



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


[PATCH] D113107: Support of expression granularity for _Float16.

2022-06-24 Thread Phoebe Wang via Phabricator via cfe-commits
pengfei added a comment.

@zahiraam I'm going to enable the FE support when I reland the backend patch. 
Community people report correctness issue due to the ABI issue in compiler-rt. 
See https://github.com/llvm/llvm-project/issues/56204


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

https://reviews.llvm.org/D113107

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


[PATCH] D128359: [clang][dataflow] Move logic for `createStorageLocation` from `DataflowEnvironment` to `DataflowAnalysisContext`.

2022-06-24 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:47
 
+/// Gets the set of all fields in the type.
+llvm::DenseSet getObjectFields(QualType Type);




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128359

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


[PATCH] D128569: Start support for HLSL `RWBuffer`

2022-06-24 Thread Chris Bieneman via Phabricator via cfe-commits
beanz created this revision.
beanz added reviewers: Anastasia, spyffe, kuhar, bogner, python3kgae.
Herald added a project: All.
beanz requested review of this revision.
Herald added a project: clang.

Most of the change here is fleshing out the HLSLExternalSemaSource with
builder implementations to build the builtin types. Eventually, I may
move some of this code into tablegen or a more managable declarative
file but I want to get the AST generation logic ready first.

This code adds two new types into the HLSL AST, `hlsl::Resource` and
`hlsl::RWBuffer`. The `Resource` type is just a wrapper around a handle
identifier, and is largely unused in source. It will morph a bit over
time as I work on getting the source compatability correct, but for now
it is a reasonable stand-in. The `RWBuffer` type is not ready for use.
I'm posting this change for review because it adds a lot of
infrastructure code and is testable.

There is one change to clang code outside the HLSL-specific logic here,
which addresses a behavior change introduced a long time ago in
967d438439ac. That change resulted in unintentionally breaking
situations where an incomplete template declaration was provided from
an AST source, and needed to be completed later by the external AST.
That situation doesn't happen in the normal AST importer flow, but can
happen when an AST source provides incomplete declarations of
templates. The solution is to annotate template specializations of
incomplete types with the HasExternalLexicalSource bit from the base
template.

Depends on D128012 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128569

Files:
  clang/include/clang/Basic/Builtins.def
  clang/include/clang/Sema/HLSLExternalSemaSource.h
  clang/lib/AST/DeclTemplate.cpp
  clang/lib/Sema/HLSLExternalSemaSource.cpp
  clang/test/AST/HLSL/RWBuffer-AST.hlsl
  clang/test/AST/HLSL/ResourceStruct.hlsl
  clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl

Index: clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/BuiltIns/RWBuffers.hlsl
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -x hlsl -fsyntax-only -verify %s
+
+Resource ResourceDescriptorHeap[5];
+typedef vector float3;
+
+RWBuffer Buffer;
+
+[numthreads(1,1,1)]
+void main() {
+  (void)Buffer.h; // expected-error {{'h' is a private member of 'hlsl::RWBuffer'}}
+  // expected-note@* {{implicitly declared private here}}
+}
Index: clang/test/AST/HLSL/ResourceStruct.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/ResourceStruct.hlsl
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -fsyntax-only -ast-dump %s | FileCheck %s 
+
+// CHECK: NamespaceDecl {{.*}} implicit hlsl
+// CHECK: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class Resource definition
+// CHECK-NEXT: DefinitionData pass_in_registers standard_layout trivially_copyable trivial literal
+// CHECK-NEXT: DefaultConstructor exists trivial needs_implicit
+// CHECK-NEXT: CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
+// CHECK-NEXT: MoveConstructor exists simple trivial needs_implicit
+// CHECK-NEXT: CopyAssignment simple trivial has_const_param needs_implicit implicit_has_const_param
+// CHECK-NEXT: MoveAssignment exists simple trivial needs_implicit
+// CHECK-NEXT: Destructor simple irrelevant trivial needs_implicit
+// CHECK-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  implicit h 'int'
Index: clang/test/AST/HLSL/RWBuffer-AST.hlsl
===
--- /dev/null
+++ clang/test/AST/HLSL/RWBuffer-AST.hlsl
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -fsyntax-only -ast-dump -DEMPTY %s | FileCheck -check-prefix=EMPTY %s 
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -fsyntax-only -ast-dump %s | FileCheck %s 
+
+// EMPTY: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  implicit RWBuffer
+// EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <>  class depth 0 index 0 element_type
+// EMPTY-NEXT: TemplateArgument type 'float'
+// EMPTY-NEXT: BuiltinType 0x{{[0-9A-Fa-f]+}} 'float'
+// EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class RWBuffer
+// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+
+// There should be no more occurrances of RWBuffer
+// EMPTY-NOT: RWBuffer
+
+#ifndef EMPTY
+
+RWBuffer Buffer;
+
+#endif
+
+// CHECK: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class Resource definition
+// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  implicit h 'int'
+
+// CHECK: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  implicit RWBuffer
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <>  class depth 0 i

[PATCH] D128372: [Clang-Tidy] Empty Check

2022-06-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp:55
+
+auto Methods = MemberCall->getRecordDecl()->methods();
+auto Clear = llvm::find_if(Methods, [](const CXXMethodDecl *F) {

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



Comment at: clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp:76
+
+auto Methods = Arg->getType()->getAsCXXRecordDecl()->methods();
+auto Clear = llvm::find_if(Methods, [](const CXXMethodDecl *F) {

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



Comment at: clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.h:22
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone-standalone-empty.html
+class StandaloneEmptyCheck : public ClangTidyCheck {

Please fix URL.



Comment at: clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.h:29
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+};
+

Please define `isLanguageVersionSupported()`.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst:5
+=
+
+

Excessive newline.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst:9
+
+The ``empty()`` method on several common ranges returns a boolean indicating
+whether or not the range is empty, but is often mistakenly interpreted as

Boolean.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

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


[PATCH] D128372: [Clang-Tidy] Empty Check

2022-06-24 Thread Abraham Corea Diaz via Phabricator via cfe-commits
abrahamcd updated this revision to Diff 439938.
abrahamcd marked 7 inline comments as done.
abrahamcd retitled this revision from "Clang-Tidy Empty Check" to "[Clang-Tidy] 
Empty Check".
abrahamcd added a comment.
Herald added a subscriber: xazax.hun.

Added functionality to check if member function `clear()` exists before
suggesting it as a fix, including updated tests to reflect that. Fixed
path change and rebase errors from the initial revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

Files:
  clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
  clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp
  clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/bugprone/standalone-empty.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/test/clang-tidy/checkers/bugprone-standalone-empty.cpp
  clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/standalone-empty.cpp
@@ -0,0 +1,202 @@
+// RUN: %check_clang_tidy %s bugprone-standalone-empty %t
+
+namespace std {
+template 
+struct vector {
+  bool empty();
+};
+
+template 
+struct vector_with_clear {
+  bool empty();
+  void clear();
+};
+
+template 
+struct vector_with_void_empty {
+  void empty();
+  void clear();
+};
+
+template 
+struct vector_with_int_empty {
+  int empty();
+  void clear();
+};
+
+template 
+bool empty(T &&);
+
+} // namespace std
+
+namespace absl {
+struct string {
+  bool empty();
+};
+
+struct string_with_clear {
+  bool empty();
+  void clear();
+};
+
+struct string_with_void_empty {
+  void empty();
+  void clear();
+};
+
+struct string_with_int_empty {
+  int empty();
+  void clear();
+};
+
+template 
+bool empty(T &&);
+} // namespace absl
+
+namespace test {
+template 
+void empty(T &&);
+} // namespace test
+
+int test_member_empty() {
+  std::vector s;
+
+  s.empty();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'empty()' [bugprone-standalone-empty]
+
+  std::vector_with_void_empty m;
+
+  m.empty();
+  // no-warning
+
+  std::vector_with_clear v;
+
+  v.empty();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'empty()', did you mean 'clear()'? [bugprone-standalone-empty]
+  // CHECK-FIXES: {{^  }}v.clear();{{$}}
+
+  std::vector_with_int_empty w;
+
+  w.empty();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'empty()', did you mean 'clear()'? [bugprone-standalone-empty]
+  // CHECK-FIXES: {{^  }}w.clear();{{$}}
+
+  absl::string x;
+
+  x.empty();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'empty()' [bugprone-standalone-empty]
+
+  absl::string_with_void_empty y;
+
+  y.empty();
+  // no-warning
+
+  absl::string_with_clear z;
+
+  z.empty();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'empty()', did you mean 'clear()'? [bugprone-standalone-empty]
+  // CHECK-FIXES: {{^  }}z.clear();{{$}}
+
+  absl::string_with_int_empty a;
+
+  a.empty();
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'empty()', did you mean 'clear()'? [bugprone-standalone-empty]
+  // CHECK-FIXES: {{^  }}a.clear();{{$}}
+}
+
+int test_qualified_empty() {
+  absl::string_with_clear v;
+
+  std::empty(v);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'std::empty', did you mean 'clear()'? [bugprone-standalone-empty]
+  // CHECK-FIXES: {{^  }}v.clear();{{$}}
+
+  absl::empty(v);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'absl::empty', did you mean 'clear()'? [bugprone-standalone-empty]
+  // CHECK-FIXES: {{^  }}v.clear();{{$}}
+
+  test::empty(v);
+  // no-warning
+
+  absl::string w;
+
+  std::empty(w);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'std::empty' [bugprone-standalone-empty]
+
+}
+
+int test_unqualified_empty() {
+  std::vector v;
+
+  empty(v);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'std::empty' [bugprone-standalone-empty]
+
+  std::vector_with_void_empty w;
+
+  empty(w);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'std::empty', did you mean 'clear()'? [bugprone-standalone-empty]
+  // CHECK-FIXES: {{^  }}w.clear();{{$}}
+
+  std::vector_with_clear x;
+
+  empty(x);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the result of 'std::empty', did you mean 'clear()'? [bugprone-standalone-empty]
+  // CHECK-FIXES: {{^  }}x.clear();{{$}}
+
+  std::vector_with_int_empty y;
+
+  empty(y);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: ignoring the resu

[PATCH] D128567: [WIP][Fuchsia] Set LLVM_TOOL_LLD_BUILD to allow some extra runtimes tests to run

2022-06-24 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D128567#3609635 , @leonardchan 
wrote:

> Won't be landing this until I'm sure any new tests that will be running from 
> this won't fail locally.

Or given https://reviews.llvm.org/D126936 and this could just pass magically on 
our bots, maybe we could just land this at the cost of being able to reproduce 
failures locally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128567

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


[PATCH] D128567: [WIP][Fuchsia] Set LLVM_TOOL_LLD_BUILD to allow some extra runtimes tests to run

2022-06-24 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

An alternative approach to this is update this bit of cmake in 
compiler-rt/CMakeLists.txt:

  set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/tools/lld)
  if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
set(COMPILER_RT_HAS_LLD TRUE)
  else()
set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/../lld)
if(EXISTS ${COMPILER_RT_LLD_PATH}/ AND LLVM_TOOL_LLD_BUILD)
  set(COMPILER_RT_HAS_LLD TRUE)
endif()
  endif()
  
  if(ANDROID)
set(COMPILER_RT_HAS_LLD TRUE)
set(COMPILER_RT_TEST_USE_LLD TRUE)
append_list_if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG -fuse-ld=lld 
SANITIZER_COMMON_LINK_FLAGS)
append_list_if(COMPILER_RT_HAS_LLD -fuse-ld=lld 
COMPILER_RT_UNITTEST_LINK_FLAGS)
  endif()

to something like:

  set(COMPILER_RT_LLD_PATH ${LLVM_MAIN_SRC_DIR}/../lld)
  if(EXISTS ${COMPILER_RT_LLD_PATH})
set(COMPILER_RT_HAS_LLD TRUE)
  endif()
  
  if(ANDROID)
set(COMPILER_RT_HAS_LLD TRUE)
set(COMPILER_RT_TEST_USE_LLD TRUE)
  endif()
  append_list_if(COMPILER_RT_HAS_FUSE_LD_LLD_FLAG -fuse-ld=lld 
SANITIZER_COMMON_LINK_FLAGS)
  append_list_if(COMPILER_RT_HAS_LLD -fuse-ld=lld 
COMPILER_RT_UNITTEST_LINK_FLAGS)

I'm thinking `LLVM_TOOL_LLD_BUILD` might be a remnant of times before the 
monorepo since lld doesn't exist under `llvm/tools` anymore.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128567

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


[PATCH] D128567: [WIP][Fuchsia] Set LLVM_TOOL_LLD_BUILD to allow some extra runtimes tests to run

2022-06-24 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

Won't be landing this until I'm sure any new tests that will be running from 
this won't fail locally.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128567

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


[PATCH] D128567: [WIP][Fuchsia] Set LLVM_TOOL_LLD_BUILD to allow some extra runtimes tests to run

2022-06-24 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added a reviewer: phosek.
leonardchan added a project: clang.
Herald added subscribers: abrachet, kristof.beyls, mgorny.
Herald added a project: All.
leonardchan requested review of this revision.
Herald added a subscriber: cfe-commits.

`LLVM_TOOL_LLD_BUILD` is required for `COMPILER_RT_HAS_LLD` to be set which 
impacts tests in the following ways:

- This sets `config.has_lld` in various lit files. This allows hwasan tests to 
run for arm runtimes and sets the feature `lld-available` which is required for 
a couple of tests.
- Adds an "lld variant" of test suites for various sanitizers like msan that 
essentially run a suite of msan tests, but explicitly linked with lld.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128567

Files:
  clang/cmake/caches/Fuchsia-stage2.cmake


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -134,6 +134,7 @@
 set(RUNTIMES_${target}_SANITIZER_COMMON_TEST_TARGET_CFLAGS 
"--unwindlib=libunwind -static-libgcc" CACHE STRING "")
 set(RUNTIMES_${target}_TSAN_TEST_TARGET_CFLAGS "--unwindlib=libunwind 
-static-libgcc" CACHE STRING "")
 set(RUNTIMES_${target}_LLVM_TOOLS_DIR "${CMAKE_BINARY_DIR}/bin" CACHE BOOL 
"")
+set(RUNTIMES_${target}_LLVM_TOOL_LLD_BUILD ON CACHE BOOL "")
 set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES 
"compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
 
 # Use .build-id link.


Index: clang/cmake/caches/Fuchsia-stage2.cmake
===
--- clang/cmake/caches/Fuchsia-stage2.cmake
+++ clang/cmake/caches/Fuchsia-stage2.cmake
@@ -134,6 +134,7 @@
 set(RUNTIMES_${target}_SANITIZER_COMMON_TEST_TARGET_CFLAGS "--unwindlib=libunwind -static-libgcc" CACHE STRING "")
 set(RUNTIMES_${target}_TSAN_TEST_TARGET_CFLAGS "--unwindlib=libunwind -static-libgcc" CACHE STRING "")
 set(RUNTIMES_${target}_LLVM_TOOLS_DIR "${CMAKE_BINARY_DIR}/bin" CACHE BOOL "")
+set(RUNTIMES_${target}_LLVM_TOOL_LLD_BUILD ON CACHE BOOL "")
 set(RUNTIMES_${target}_LLVM_ENABLE_RUNTIMES "compiler-rt;libcxx;libcxxabi;libunwind" CACHE STRING "")
 
 # Use .build-id link.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1355-1356
   // at all, we assume it has dynamic initializer (in other TU).
-  //
-  // FIXME: Metadata should be attched directly to the global directly instead
-  // of being added to llvm.asan.globals.
-  return G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
+  if (G->hasSanitizerMetadata() && G->getSanitizerMetadata().IsDynInit)
+return false;
+

vitalybuka wrote:
> hctim wrote:
> > vitalybuka wrote:
> > > I believe previous was like this.
> > > if you want to change that lets do another patch. 
> > refactored it slightly, it's clear to me now (and IMHO much clearer to 
> > reason about, i suck at flipping multiple conditions in my head) that it's 
> > the same code
> Before: G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
> Now:  G->hasInitializer() && !(G->hasSanitizerMetadata() && 
> G->getSanitizerMetadata().IsDynInit)
> 
> Which is fine, because previously NoMD == !IsDynInit
> 
> So logic-wise this version is LGTM
> equivalent one-liner is even cleaner:
> return G->hasInitializer() && !(G->hasSanitizerMetadata() && 
> G->getSanitizerMetadata().IsDynInit)
> Before: G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
"Before" is "Before the patch"



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

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


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka accepted this revision.
vitalybuka added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1355-1356
   // at all, we assume it has dynamic initializer (in other TU).
-  //
-  // FIXME: Metadata should be attched directly to the global directly instead
-  // of being added to llvm.asan.globals.
-  return G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
+  if (G->hasSanitizerMetadata() && G->getSanitizerMetadata().IsDynInit)
+return false;
+

hctim wrote:
> vitalybuka wrote:
> > I believe previous was like this.
> > if you want to change that lets do another patch. 
> refactored it slightly, it's clear to me now (and IMHO much clearer to reason 
> about, i suck at flipping multiple conditions in my head) that it's the same 
> code
Before: G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
Now:  G->hasInitializer() && !(G->hasSanitizerMetadata() && 
G->getSanitizerMetadata().IsDynInit)

Which is fine, because previously NoMD == !IsDynInit

So logic-wise this version is LGTM
equivalent one-liner is even cleaner:
return G->hasInitializer() && !(G->hasSanitizerMetadata() && 
G->getSanitizerMetadata().IsDynInit)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

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


[PATCH] D107082: [X86][RFC] Enable `_Float16` type support on X86 following the psABI

2022-06-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In addition, don't use `Reland "Reland "Reland "Reland ...` One `Reland` is 
sufficient.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107082

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-06-24 Thread Caroline Tice via Phabricator via cfe-commits
cmtice added a comment.

I did some testing and verified that this commit is causing some of the 
Sanitizer issues we are seeing. Is there any chance of a revert?


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

https://reviews.llvm.org/D126864

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


[PATCH] D127910: [Clang][AArch64] Add SME C intrinsics for load and store

2022-06-24 Thread Sagar Kulkarni via Phabricator via cfe-commits
sagarkulkarni19 marked 2 inline comments as done.
sagarkulkarni19 added inline comments.



Comment at: clang/lib/Basic/Targets/AArch64.cpp:342
+  if (HasSME)
+Builder.defineMacro("__ARM_FEATURE_SME", "1");
+

sdesmalen wrote:
> sagarkulkarni19 wrote:
> > sdesmalen wrote:
> > > When this macro is non-zero, it suggests that the compiler implements the 
> > > full SME ACLE. That is currently not yet the case, so until then we 
> > > should leave this macro undefined.
> > Okay makes sense. But until all SME ACLE is implemented, do we need some 
> > sort of guard in the meantime while the SME intrinsics that are implemented 
> > incrementally? 
> The tests need to have manual `-D__ARM_FEATURE_SME` in the RUN lines. Once 
> the feature is implemented and we add the definition automatically when +sme 
> is specified, we update the tests. See for example D81725 where we did this 
> for SVE.
Thanks. That makes sense, now the macro is undefined and I have updated the 
testcases accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127910

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


[PATCH] D107082: [X86][RFC] Enable `_Float16` type support on X86 following the psABI

2022-06-24 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Please include `Differential Revision: ` line for reland commits as well so 
that people know that this patch has a reland.
https://github.com/llvm/llvm-project/issues/56204 is related to 
655ba9c8a1d22075443711cc749f0b032e07adee 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D107082

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


[PATCH] D127910: [Clang][AArch64] Add SME C intrinsics for load and store

2022-06-24 Thread Sagar Kulkarni via Phabricator via cfe-commits
sagarkulkarni19 updated this revision to Diff 439919.
sagarkulkarni19 edited the summary of this revision.
sagarkulkarni19 added a comment.

Updated testcases and also added the `vnum` variant of the ld1 and st1 
intrinsics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127910

Files:
  clang/include/clang/Basic/TargetBuiltins.h
  clang/include/clang/Basic/arm_sve.td
  clang/lib/Basic/Targets/AArch64.cpp
  clang/lib/Basic/Targets/AArch64.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/lib/Headers/CMakeLists.txt
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ld1.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ld1_vnum.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_st1.c
  clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_st1_vnum.c
  clang/utils/TableGen/SveEmitter.cpp
  clang/utils/TableGen/TableGen.cpp
  clang/utils/TableGen/TableGenBackends.h

Index: clang/utils/TableGen/TableGenBackends.h
===
--- clang/utils/TableGen/TableGenBackends.h
+++ clang/utils/TableGen/TableGenBackends.h
@@ -101,6 +101,8 @@
 void EmitSveTypeFlags(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 void EmitSveRangeChecks(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 
+void EmitSmeHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
+
 void EmitMveHeader(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 void EmitMveBuiltinDef(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
 void EmitMveBuiltinSema(llvm::RecordKeeper &Records, llvm::raw_ostream &OS);
Index: clang/utils/TableGen/TableGen.cpp
===
--- clang/utils/TableGen/TableGen.cpp
+++ clang/utils/TableGen/TableGen.cpp
@@ -80,6 +80,7 @@
   GenArmSveBuiltinCG,
   GenArmSveTypeFlags,
   GenArmSveRangeChecks,
+  GenArmSmeHeader,
   GenArmCdeHeader,
   GenArmCdeBuiltinDef,
   GenArmCdeBuiltinSema,
@@ -217,6 +218,8 @@
"Generate arm_sve_typeflags.inc for clang"),
 clEnumValN(GenArmSveRangeChecks, "gen-arm-sve-sema-rangechecks",
"Generate arm_sve_sema_rangechecks.inc for clang"),
+clEnumValN(GenArmSmeHeader, "gen-arm-sme-header",
+   "Generate arm_sme.h for clang"),
 clEnumValN(GenArmMveHeader, "gen-arm-mve-header",
"Generate arm_mve.h for clang"),
 clEnumValN(GenArmMveBuiltinDef, "gen-arm-mve-builtin-def",
@@ -434,6 +437,9 @@
   case GenArmSveRangeChecks:
 EmitSveRangeChecks(Records, OS);
 break;
+  case GenArmSmeHeader:
+EmitSmeHeader(Records, OS);
+break;
   case GenArmCdeHeader:
 EmitCdeHeader(Records, OS);
 break;
Index: clang/utils/TableGen/SveEmitter.cpp
===
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -334,6 +334,9 @@
   /// Emit arm_sve.h.
   void createHeader(raw_ostream &o);
 
+  /// Emit arm_sme.h.
+  void createSMEHeader(raw_ostream &o);
+
   /// Emit all the __builtin prototypes and code needed by Sema.
   void createBuiltins(raw_ostream &o);
 
@@ -347,7 +350,9 @@
   void createTypeFlags(raw_ostream &o);
 
   /// Create intrinsic and add it to \p Out
-  void createIntrinsic(Record *R, SmallVectorImpl> &Out);
+  void createIntrinsic(Record *R,
+   SmallVectorImpl> &Out,
+   bool IsSME = false);
 };
 
 } // end anonymous namespace
@@ -757,6 +762,11 @@
 NumVectors = 0;
 Signed = true;
 break;
+  case '%':
+Pointer = true;
+Void = true;
+NumVectors = 0;
+break;
   case 'A':
 Pointer = true;
 ElementBitwidth = Bitwidth = 8;
@@ -989,7 +999,7 @@
 }
 
 void SVEEmitter::createIntrinsic(
-Record *R, SmallVectorImpl> &Out) {
+Record *R, SmallVectorImpl> &Out, bool IsSME) {
   StringRef Name = R->getValueAsString("Name");
   StringRef Proto = R->getValueAsString("Prototype");
   StringRef Types = R->getValueAsString("Types");
@@ -1005,6 +1015,9 @@
   for (auto FlagRec : FlagsList)
 Flags |= FlagRec->getValueAsInt("Value");
 
+  bool SMEFlag = Flags & getEnumValueForFlag("IsSME");
+  if (SMEFlag != IsSME)
+return;
   // Create a dummy TypeSpec for non-overloaded builtins.
   if (Types.empty()) {
 assert((Flags & getEnumValueForFlag("IsOverloadNone")) &&
@@ -1286,11 +1299,85 @@
   OS << "#endif /* __ARM_SVE_H */\n";
 }
 
+void SVEEmitter::createSMEHeader(raw_ostream &OS) {
+  OS << "/*=== arm_sme.h - ARM SME intrinsics "
+"---===\n"
+" *\n"
+" *\n"
+" * Part of the LLVM Project, under the Apache License v2.0 with LLVM "
+"Exceptions.\n"
+" * See https://llvm.org/LICENSE.txt for license information.\n"
+" * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n"
+" *\n"
+

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 439918.
hctim marked 3 inline comments as done.
hctim added a comment.

Vitaly's comments, round 2.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
  llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -357,8 +357,6 @@
  ArrayRef) {
 AddressSanitizerOptions Opts;
 if (Name == "asan-pipeline") {
-  MPM.addPass(
-  RequireAnalysisPass());
   MPM.addPass(ModuleAddressSanitizerPass(Opts));
   return true;
 }
Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
@@ -2,7 +2,7 @@
 ; Make sure asan does not instrument __sancov_gen_
 
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
-; RUN: opt < %s -passes='module(require,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 $Foo = comdat any
Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -10,13 +10,12 @@
 ; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
 ; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
-; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
+; CHECK:  @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
-; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
-; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([7 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8
+; CHECK-SAME:   x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }, section ".ASAN$GL",
+; CHECK-SAME:   comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
@@ -35,11 +34,9 @@
 
 attributes #0 = { nounwind sanitize_address uwtable }
 
-!llvm.asan.globals = !{!0}
 !llvm.module.flags = !{!2, !3}
 !llvm.ident = !{!4}
 
-!0 = !{[5 x i8]* @"??_C@_04JIHMPGLA@asdf?$AA@", !1, !"", i1 false, i1 false}
 !1 = !{!"t.cpp", i32 1, i32 31}
 !2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
Index: llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
+++ llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
@@ -2,17 +2,10 @@
 ; RUN: opt < %s -passes='asan-pipeline' -asan-mapping-scale=5 -S | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 tar

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added inline comments.



Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:67-72
+  if (FsanitizeArgument.has(SanitizerKind::Address) && !Meta.NoAddress) {
 IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
  SanitizerKind::KernelAddress,
  GV, Loc, Ty, "init");
 Meta.IsDynInit = IsDynInit;
   }

vitalybuka wrote:
> I recommend to move this change into another patch
> 
> and it should probably be:
> Meta.IsDynInit &= IsDynInit && FsanitizeArgument.has(SanitizerKind::Address) 
> && !Meta.NoAddress && !CGM.isInNoSanitizeLis;
sure, will punt to follow-up patch (leaving comment open, will close it out 
when i've added the dependency)



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:34
 #include "llvm/BinaryFormat/MachO.h"
+#include "llvm/Demangle/Demangle.h"
 #include "llvm/IR/Argument.h"

vitalybuka wrote:
> Please don't demangle in this patch, or keep as close as possible to the 
> current behaviour
> Also isn't demangling by compliler-rt is better? mangled form is shorter.
as discussed, current descriptor has the demangled name because it's provided 
by clang frontend in `llvm.asan.globals`.

to keep this migration as close to the original as possible, keeping demangle 
of names in descriptors here, but added a TODO for follow-up work to instead 
demangle in the runtime.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1355-1356
   // at all, we assume it has dynamic initializer (in other TU).
-  //
-  // FIXME: Metadata should be attched directly to the global directly instead
-  // of being added to llvm.asan.globals.
-  return G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
+  if (G->hasSanitizerMetadata() && G->getSanitizerMetadata().IsDynInit)
+return false;
+

vitalybuka wrote:
> I believe previous was like this.
> if you want to change that lets do another patch. 
refactored it slightly, it's clear to me now (and IMHO much clearer to reason 
about, i suck at flipping multiple conditions in my head) that it's the same 
code


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

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


[PATCH] D126731: [pseudo] Eliminate dependencies from clang-pseudo-gen. NFC

2022-06-24 Thread Florian Mayer via Phabricator via cfe-commits
fmayer added a comment.

FWIW this is not really NFC, I found this as the culprit in bisecting the 
Android LLVM toolchain build, causing the following error:

  FAILED: tools/clang/tools/extra/pseudo/include/CXXBNF.inc 
/usr/local/google/home/fmayer/llvm-toolchain/out/stage2/tools/clang/tools/extra/pseudo/include/CXXBNF.inc
 
  cd 
/usr/local/google/home/fmayer/llvm-toolchain/out/stage2/tools/clang/tools/extra/pseudo/include
 && /usr/local/google/home/fmayer/llvm-toolchain/out/stage2/bin/pseudo-gen 
--grammar 
/usr/local/google/home/fmayer/llvm-toolchain/out/llvm-project/clang-tools-extra/pseudo/include/../lib/cxx.bnf
 --emit-grammar-content -o 
/usr/local/google/home/fmayer/llvm-toolchain/out/stage2/tools/clang/tools/extra/pseudo/include/CXXBNF.inc
  /usr/local/google/home/fmayer/llvm-toolchain/out/stage2/bin/pseudo-gen: error 
while loading shared libraries: libc++.so.1: cannot open shared object file: No 
such file or directory
  [2437/6345] Generating nonterminal symbol file for cxx grammar...
  FAILED: tools/clang/tools/extra/pseudo/include/CXXSymbols.inc 
/usr/local/google/home/fmayer/llvm-toolchain/out/stage2/tools/clang/tools/extra/pseudo/include/CXXSymbols.inc
 
  cd 
/usr/local/google/home/fmayer/llvm-toolchain/out/stage2/tools/clang/tools/extra/pseudo/include
 && /usr/local/google/home/fmayer/llvm-toolchain/out/stage2/bin/pseudo-gen 
--grammar 
/usr/local/google/home/fmayer/llvm-toolchain/out/llvm-project/clang-tools-extra/pseudo/include/../lib/cxx.bnf
 --emit-symbol-list -o 
/usr/local/google/home/fmayer/llvm-toolchain/out/stage2/tools/clang/tools/extra/pseudo/include/CXXSymbols.inc
  /usr/local/google/home/fmayer/llvm-toolchain/out/stage2/bin/pseudo-gen: error 
while loading shared libraries: libc++.so.1: cannot open shared object file: No 
such file or directory


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126731

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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-06-24 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

I suspect the refactoring in the latest version of the patch accidentally made 
UBSan a bit more strict by default.


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

https://reviews.llvm.org/D126864

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


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

The rest is LGTM




Comment at: clang/lib/CodeGen/SanitizerMetadata.cpp:67-72
+  if (FsanitizeArgument.has(SanitizerKind::Address) && !Meta.NoAddress) {
 IsDynInit &= !CGM.isInNoSanitizeList(SanitizerKind::Address |
  SanitizerKind::KernelAddress,
  GV, Loc, Ty, "init");
 Meta.IsDynInit = IsDynInit;
   }

I recommend to move this change into another patch

and it should probably be:
Meta.IsDynInit &= IsDynInit && FsanitizeArgument.has(SanitizerKind::Address) && 
!Meta.NoAddress && !CGM.isInNoSanitizeLis;



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:34
 #include "llvm/BinaryFormat/MachO.h"
+#include "llvm/Demangle/Demangle.h"
 #include "llvm/IR/Argument.h"

Please don't demangle in this patch, or keep as close as possible to the 
current behaviour
Also isn't demangling by compliler-rt is better? mangled form is shorter.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:1355-1356
   // at all, we assume it has dynamic initializer (in other TU).
-  //
-  // FIXME: Metadata should be attched directly to the global directly instead
-  // of being added to llvm.asan.globals.
-  return G->hasInitializer() && !GlobalsMD.get(G).IsDynInit;
+  if (G->hasSanitizerMetadata() && G->getSanitizerMetadata().IsDynInit)
+return false;
+

I believe previous was like this.
if you want to change that lets do another patch. 



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2330
+ConstantInt::get(IntptrTy, Meta.IsDynInit),
+ConstantInt::get(IntptrTy, 0),
 ConstantExpr::getPointerCast(ODRIndicator, IntptrTy));

hctim wrote:
> vitalybuka wrote:
> > MD was fine, less changed lines
> done
Constant::getNullValue


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

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


[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 439912.
hctim marked 2 inline comments as done.
hctim added a comment.

Vitaly's comments - round 1.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
  llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -357,8 +357,6 @@
  ArrayRef) {
 AddressSanitizerOptions Opts;
 if (Name == "asan-pipeline") {
-  MPM.addPass(
-  RequireAnalysisPass());
   MPM.addPass(ModuleAddressSanitizerPass(Opts));
   return true;
 }
Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
@@ -2,7 +2,7 @@
 ; Make sure asan does not instrument __sancov_gen_
 
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
-; RUN: opt < %s -passes='module(require,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 $Foo = comdat any
Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -10,13 +10,12 @@
 ; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
 ; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
-; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
+; CHECK:  @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
-; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
-; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([7 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8
+; CHECK-SAME:   x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }, section ".ASAN$GL",
+; CHECK-SAME:   comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
@@ -35,11 +34,9 @@
 
 attributes #0 = { nounwind sanitize_address uwtable }
 
-!llvm.asan.globals = !{!0}
 !llvm.module.flags = !{!2, !3}
 !llvm.ident = !{!4}
 
-!0 = !{[5 x i8]* @"??_C@_04JIHMPGLA@asdf?$AA@", !1, !"", i1 false, i1 false}
 !1 = !{!"t.cpp", i32 1, i32 31}
 !2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
Index: llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
+++ llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
@@ -2,17 +2,10 @@
 ; RUN: opt < %s -passes='asan-pipeline' -asan-mapping-scale=5 -S | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 ta

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim marked 2 inline comments as done.
hctim added inline comments.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2100
+GlobalVariable *Metadata = CreateMetadataGlobal(
+M, Initializer, llvm::demangle(std::string(G->getName(;
 

vitalybuka wrote:
> was this demanded before?
removed, think this got accidentally added during a sweep of demangling names 
for the produced metadata, which is necessary now that clang doesn't produce 
the info.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2330
+ConstantInt::get(IntptrTy, Meta.IsDynInit),
+ConstantInt::get(IntptrTy, 0),
 ConstantExpr::getPointerCast(ODRIndicator, IntptrTy));

vitalybuka wrote:
> MD was fine, less changed lines
done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

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


[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-06-24 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann accepted this revision as: tahonermann.
tahonermann added a comment.
This revision is now accepted and ready to land.

> @tahonermann gentle ping (Aaron told me you might have further comments)

I'm sorry for the delay. I ran out of time to do the thorough review I would 
have liked to do, but I did scroll through everything now and did not find 
anything concerning; Aaron clearly conducted a thorough review already. It 
looks great to me, really nice work!




Comment at: clang/lib/Lex/Lexer.cpp:3255-3260
+if (!isAlphanumeric(C) && C != '_' && C != '-' && C != ' ')
+  break;
+
+if ((C < 'A' || C > 'Z') && !llvm::isDigit(C) && C != ' ' && C != '-') {
+  Invalid = true;
+}

cor3ntin wrote:
> tahonermann wrote:
> > It isn't clear to me why there are two separate `if` statements here. I 
> > would expect the following to suffice. If I'm misunderstanding something, 
> > then comments might be helpful.
> >   if (!isUppercase(C) && !isDigit(C) && C != '-' && C != ' ') {
> > Invalid = true;
> > break;
> >   }
> > 
> > I'm not sure why there is a test for '_' since that character is not 
> > present in the grammar for `n-char` in P2071.
> > 
> > Is it intentional that there is no `break` statement in the second `if` 
> > statement?
> I improved that, what it does should be more clear now. More importantly, I 
> added a diagnostic note when we detect a loose match.
> 
> We allow `_` because  Unicode does.
> We first perform a strict match - which fails as no Unicode name contains an 
> underscore, we emit a diagnostic, and then we try a loose matching which does 
> allow `_`.
> This enable us to produces better diagnostics
> 
> ```
> :2:18: error: 'GREEK_SMALL_LETTER-OMICRON' is not a valid Unicode 
> character name
> const char* \N{GREEK_SMALL_LETTER-OMICRON} = "\N{zero width no break 
> space}"; 
>  ^
> :2:20: note: characters names in Unicode escape sequences are 
> sensitive to case and whitespaces
> const char* \N{GREEK_SMALL_LETTER-OMICRON} = "\N{zero width no break 
> space}"; 
>^~
>GREEK SMALL LETTER OMICRON
> :2:54: error: 'zero width no break space' is not a valid Unicode 
> character name
> const char* \N{GREEK_SMALL_LETTER-OMICRON} = "\N{zero width no break 
> space}"; 
>  ^
> :2:54: note: characters names in Unicode escape sequences are 
> sensitive to case and whitespaces
> const char* \N{GREEK_SMALL_LETTER-OMICRON} = "\N{zero width no break 
> space}"; 
>  ^
>  ZERO WIDTH NO-BREAK 
> SPACE```
> 
That's great! Very nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-06-24 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:201
+  const FieldDecl *FD = nullptr;
+  size_t Sz = -1;
+  VarDecl *VD = nullptr;

ABataev wrote:
> What is Sz here? Better to give a better name and add a description for the 
> struct and all fields
How about use StackLevel.  Sorry use 0 instead



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1143
+break;
+  Sz--;
+}

ABataev wrote:
> Is it possible to have an overflow here?
I don't think that is possible.  when I != EndI and Stacklevel should > 0  Or 
if I == EndI and Stacklevel should be 0

I add assert to check boundary condition be ensure:
 assert((StackLevel > 0 && I != EndI) || (StackLevel == 0 && I == EndI));






Comment at: clang/lib/Sema/SemaOpenMP.cpp:1148
+for (const auto &IFD : I->ImplicitDefaultFirstprivateFDs)
+  if (IFD.FD == FD && IFD.Sz == Sz)
+return IFD.VD;

ABataev wrote:
> What if Sz == -1?
Should not be 0.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1176
+  }
+  Sz--;
+}

ABataev wrote:
> What about overflow here?
Add assert for boundary check.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:17480
 DeclRefExpr *Ref = nullptr;
-if (!VD && !CurContext->isDependentContext())
-  Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false);
-DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref);
+if (!VD && !CurContext->isDependentContext()) {
+  auto *FD = dyn_cast(D);

ABataev wrote:
> A check here not for curcontext dependent but for FD being dependent?
I can not this to work.  Since the private copy only build under only build 
non-dependent context. 




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-06-24 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 439906.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/default_firstprivate_ast_print.cpp
  clang/test/OpenMP/default_private_ast_print.cpp

Index: clang/test/OpenMP/default_private_ast_print.cpp
===
--- clang/test/OpenMP/default_private_ast_print.cpp
+++ clang/test/OpenMP/default_private_ast_print.cpp
@@ -96,4 +96,57 @@
   // DUMP-NEXT:  -DeclRefExpr {{.*}} 'a'
   // DUMP-NEXT:  -DeclRefExpr {{.*}} 'yy'
 }
+
+void zoo(int);
+struct A {
+  int z;
+  int f;
+  A();
+  ~A();
+  void foo() {
+#pragma omp parallel private(z) default(private)
+{
+  z++;
+  f++;
+  zoo(z + f);
+  f++;
+}
+  }
+  // PRINT:#pragma omp parallel private(this->z) default(private)
+  // DUMP: -OMPParallelDirective
+  // DUMP-NEXT:  -OMPPrivateClause
+  // DUMP-NEXT:-DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT:  -OMPDefaultClause
+  // DUMP-NEXT:  -OMPPrivateClause
+  // DUMP-NEXT:-DeclRefExpr {{.*}} 'f'
+  // DUMP: -CXXThisExpr {{.*}} 'A *' implicit this
+  void bar() {
+#pragma omp parallel private(z) default(private)
+{
+#pragma omp parallel private(z) default(private)
+  {
+z++;
+f++;
+zoo(z + f);
+f++;
+  }
+}
+  }
+  // PRINT:#pragma omp parallel private(this->z) default(private)
+  // PRINT:  #pragma omp parallel private(this->z) default(private)
+  // DUMP: -OMPParallelDirective
+  // DUMP-NEXT:  -OMPPrivateClause
+  // DUMP-NEXT:-DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT:  -OMPDefaultClause
+  // DUMP:   -OMPParallelDirective
+  // DUMP-NEXT:-OMPPrivateClause
+  // DUMP-NEXT:   -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT:-OMPDefaultClause
+  // DUMP-NEXT:-OMPPrivateClause {{.*}} 
+  // DUMP-NEXT:   -DeclRefExpr {{.*}} 'f'
+  // DUMP: -CXXThisExpr
+  // DUMP: -MemberExpr
+  // DUMP-NEXT:   -CXXThisExpr
+  // DUMP: -CXXThisExpr
+};
 #endif // HEADER
Index: clang/test/OpenMP/default_firstprivate_ast_print.cpp
===
--- clang/test/OpenMP/default_firstprivate_ast_print.cpp
+++ clang/test/OpenMP/default_firstprivate_ast_print.cpp
@@ -45,7 +45,8 @@
 // PRINT-NEXT:  this->targetDev++;
 // CHECK-NEXT: }
 // DUMP: -OMPParallelDirective
-// DUMP->NEXT: -OMPDefaultClause
+// DUMP-NEXT: -OMPDefaultClause
+// DUMP-NOT:   -OMPFirstprivateClause
   }
   // PRINT: template<> void apply<32U>()
   // PRINT: #pragma omp parallel default(firstprivate)
@@ -99,4 +100,60 @@
   // DUMP-NEXT: -DeclRefExpr {{.*}} 'yy'
   // DUMP-NEXT: -DeclRefExpr {{.*}} 'y'
 }
+void zoo(int);
+struct A {
+  int z;
+  int f;
+  A();
+  ~A();
+  void foo() {
+#pragma omp parallel firstprivate(z) default(firstprivate)
+{
+  z++;
+  f++;
+  zoo(z + f);
+  f++;
+}
+  }
+  // PRINT:  #pragma omp parallel firstprivate(this->z) default(firstprivate)
+  // DUMP:   -OMPParallelDirective
+  // DUMP-NEXT: -OMPFirstprivateClause
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT: -OMPDefaultClause
+  // DUMP-NEXT: -OMPFirstprivateClause {{.*}} 
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'
+  // DUMP:  -CXXThisExpr {{.*}} 'A *' implicit this
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'
+  void bar() {
+#pragma omp parallel firstprivate(z) default(firstprivate)
+{
+#pragma omp parallel private(z) default(firstprivate)
+  {
+z++;
+f++;
+zoo(z + f);
+f++;
+  }
+}
+  }
+  // PRINT:  #pragma omp parallel firstprivate(this->z) default(firstprivate)
+  // PRINT:#pragma omp parallel private(this->z) default(firstprivate)
+  // DUMP: -OMPParallelDirective
+  // DUMP-NEXT: -OMPFirstprivateClause
+  // DUMP-NEXT:  -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT:  -OMPDefaultClause
+  // DUMP:-OMPParallelDirective
+  // DUMP-NEXT:-OMPPrivateClaus
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT: -OMPDefaultClause
+  // DUMP-NEXT: -OMPFirstprivateClause {{.*}} 
+  // DUMP-NEXT:  -DeclRefExpr {{.*}} 'f'
+  // DUMP:   -CXXThisExpr {{.*}} 'A *' implicit this
+  // DUMP-NEXT:  -DeclRefExpr {{.*}} 'f'
+  // DUMP: -MemberExpr {{.*}}
+  // DUMP-NEXT:  -CXXThisExpr
+  // DUMP:   -CXXThisExpr {{.*}} 'A *' implicit this
+  // DUMP-NEXT:  -DeclRefExpr {{.*}} 'z'
+};
 #endif // HEADER
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -196,6 +196,17 @@
 llvm::DenseSet> UsedInScanDirective;
 llvm::DenseMap, UsesAllocatorsDeclKind>
 UsesAllocatorsDecls;
+struct ImplicitDefaultFDI

[PATCH] D128363: [clang][dataflow] Implement functionality for flow condition variable substitution.

2022-06-24 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:209
+  /// `Substitutions`, it will be substituted with the value it maps to.
+  BoolValue &buildAndSubstituteFlowCondition(
+  AtomicBoolValue &Token,

Could you copy the example from the commit description into the doc comment?



Comment at: 
clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp:319
+  EXPECT_TRUE(Context.equivalentBoolValues(FCWithXFalse, False));
+}
+

Could you also add a test for negations?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128363

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


[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker

2022-06-24 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:34
 /// Return whether `Var` was changed in `LoopStmt`.
 static bool isChanged(const Stmt *LoopStmt, const VarDecl *Var,
   ASTContext *Context) {

NoQ wrote:
> Ok so this whole checker does this procedure involving `ExprMutationAnalyzer` 
> trying to figure out if the variable can be changed from within the loop. I 
> wonder if our problem of whether the static variable can be changed within 
> the loop is a sub-problem of this problem and therefore could have a general 
> solution inside `ExprMutationAnalyzer`. If so, other clang-tidy checks that 
> use `ExprMutationAnalyzer` could immediately benefit from such solution. WDYT?
I think this is a good point.  I can do it after this patch.


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

https://reviews.llvm.org/D128401

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


[PATCH] D128556: Make Objective-C++ match Objective-C's behavior on implicit ivar access when `self` is shadowed

2022-06-24 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added a comment.

Please add a test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128556

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


[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker

2022-06-24 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 439903.
ziqingluo-90 added a comment.

I missed the part of coding standard about the usage of `auto`.   Now change to 
conform to it.


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

https://reviews.llvm.org/D128401

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

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
@@ -44,6 +44,27 @@
 j++;
   }
 }
+
++ (void)recursiveMethod {
+  static int i = 0;
+
+  i++;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+[I classMethod];
+  }
+
+  id x = [[I alloc] init];
+
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+[x instanceMethod];
+  }
+  while (i < 10) {
+// no warning, there is a recursive call that can mutate the static local variable
+[I recursiveMethod];
+  }
+}
 @end
 
 void testArrayCount() {
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
@@ -685,3 +685,29 @@
 0;
   }) x;
 }
+
+void test_local_static_recursion() {
+  static int i = 10;
+  int j = 0;
+
+  i--;
+  while (i >= 0)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i >= 0;)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i + j >= 0;)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i >= 0; i--)
+; // no warning, i decrements
+  while (j >= 0)
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (j) are updated in the loop body [bugprone-infinite-loop]
+test_local_static_recursion();
+
+  int (*p)(int) = 0;
+
+  while (i >= 0)
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+p = 0;
+  while (i >= 0)
+p(0); // we don't know what p points to so no warning
+}
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -11,6 +11,9 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
+#include "clang/Analysis/CallGraph.h"
+#include "llvm/ADT/SCCIterator.h"
+#include "llvm/ADT/SmallVector.h"
 
 using namespace clang::ast_matchers;
 using clang::tidy::utils::hasPtrOrReferenceInFunc;
@@ -146,6 +149,110 @@
   return false;
 }
 
+/// populates the set `Callees` with all function (and objc method) declarations
+/// called in `StmtNode` if all visited call sites have resolved call targets.
+///
+/// \return true iff all `CallExprs` visited have callees; false otherwise
+/// indicating there is an unresolved indirect call.
+static bool populateCallees(const Stmt *StmtNode,
+llvm::SmallSet &Callees) {
+  if (const auto *Call = dyn_cast(StmtNode)) {
+const Decl *Callee = Call->getDirectCallee();
+
+if (!Callee)
+  return false; // unresolved call
+Callees.insert(Callee->getCanonicalDecl());
+  }
+  if (const auto *Call = dyn_cast(StmtNode)) {
+const Decl *Callee = Call->getMethodDecl();
+
+if (!Callee)
+  return false; // unresolved call
+Callees.insert(Callee->getCanonicalDecl());
+  }
+  for (const Stmt *Child : StmtNode->children())
+if (Child && !populateCallees(Child, Callees))
+  return false;
+  return true;
+}
+
+/// returns true iff `SCC` contains `Func` and its' function set overlaps with
+/// `Callees`
+static bool overlap(ArrayRef SCC,
+const llvm::SmallSet &Callees,
+const Decl *Func) {
+  bool ContainsFunc = false, Overlap = false;
+
+  for (const CallGraphNode *GNode : SCC) {
+const Decl *CanDecl = GNode->getDecl()->getCanonicalDecl();
+
+ContainsFunc = ContainsFunc || (CanDecl == Func);
+Overlap = Overlap || Callees.contains(CanDecl);
+if (ContainsFunc && Overlap)
+  return true;
+  }
+  return Contai

[PATCH] D128521: [clang][dataflow] Implement functionality to compare if two boolean values are equivalent.

2022-06-24 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f65a3e61005: [clang][dataflow] Implement functionality to 
compare if two boolean values are… (authored by wyt, committed by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128521

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -213,4 +213,67 @@
   EXPECT_TRUE(Context.flowConditionIsTautology(FC5));
 }
 
+TEST_F(DataflowAnalysisContextTest, EquivBoolVals) {
+  auto &X = Context.createAtomicBoolValue();
+  auto &Y = Context.createAtomicBoolValue();
+  auto &Z = Context.createAtomicBoolValue();
+  auto &True = Context.getBoolLiteralValue(true);
+  auto &False = Context.getBoolLiteralValue(false);
+
+  // X == X
+  EXPECT_TRUE(Context.equivalentBoolValues(X, X));
+  // X != Y
+  EXPECT_FALSE(Context.equivalentBoolValues(X, Y));
+
+  // !X != X
+  EXPECT_FALSE(Context.equivalentBoolValues(Context.getOrCreateNegation(X), X));
+  // !(!X) = X
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateNegation(Context.getOrCreateNegation(X)), X));
+
+  // (X || X) == X
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateDisjunction(X, X), X));
+  // (X || Y) != X
+  EXPECT_FALSE(
+  Context.equivalentBoolValues(Context.getOrCreateDisjunction(X, Y), X));
+  // (X || True) == True
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateDisjunction(X, True), True));
+  // (X || False) == X
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateDisjunction(X, False), X));
+
+  // (X && X) == X
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, X), X));
+  // (X && Y) != X
+  EXPECT_FALSE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, Y), X));
+  // (X && True) == X
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, True), X));
+  // (X && False) == False
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateConjunction(X, False), False));
+
+  // (X || Y) == (Y || X)
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateDisjunction(X, Y),
+   Context.getOrCreateDisjunction(Y, X)));
+  // (X && Y) == (Y && X)
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, Y),
+   Context.getOrCreateConjunction(Y, X)));
+
+  // ((X || Y) || Z) == (X || (Y || Z))
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateDisjunction(Context.getOrCreateDisjunction(X, Y), Z),
+  Context.getOrCreateDisjunction(X, Context.getOrCreateDisjunction(Y, Z;
+  // ((X && Y) && Z) == (X && (Y && Z))
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateConjunction(Context.getOrCreateConjunction(X, Y), Z),
+  Context.getOrCreateConjunction(X, Context.getOrCreateConjunction(Y, Z;
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -137,6 +137,13 @@
   return isUnsatisfiable(std::move(Constraints));
 }
 
+bool DataflowAnalysisContext::equivalentBoolValues(BoolValue &Val1,
+   BoolValue &Val2) {
+  llvm::DenseSet Constraints = {
+  &getOrCreateNegation(getOrCreateIff(Val1, Val2))};
+  return isUnsatisfiable(Constraints);
+}
+
 void DataflowAnalysisContext::addTransitiveFlowConditionConstraints(
 AtomicBoolValue &Token, llvm::DenseSet &Constraints,
 llvm::DenseSet &VisitedTokens) {
Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -203,6 +203,11 @@
   /// identified by `Token` are always true.
   bool flowConditionIsTautology(AtomicBoolValue &Token);
 
+  /// Returns true if `Val1` is equivalent to `Val2`.
+  /// Note: This function doesn't take into account constraints on `Val1` and
+  /// `Val2` imposed by the flow condition.
+  bool equivalentBoolValues(BoolValue &Val1, BoolValue &Val2

[clang] 0f65a3e - [clang][dataflow] Implement functionality to compare if two boolean values are equivalent.

2022-06-24 Thread Dmitri Gribenko via cfe-commits

Author: Wei Yi Tee
Date: 2022-06-25T00:10:35+02:00
New Revision: 0f65a3e610051fc319372eea647fb50f60b2b21c

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

LOG: [clang][dataflow] Implement functionality to compare if two boolean values 
are equivalent.

`equivalentBoolValues` compares equivalence between two booleans. The current 
implementation does not consider constraints imposed by flow conditions on the 
booleans and its subvalues.

Depends On D128520

Reviewed By: gribozavr2, xazax.hun

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index 8a1fc9745b21..6011584f2006 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -203,6 +203,11 @@ class DataflowAnalysisContext {
   /// identified by `Token` are always true.
   bool flowConditionIsTautology(AtomicBoolValue &Token);
 
+  /// Returns true if `Val1` is equivalent to `Val2`.
+  /// Note: This function doesn't take into account constraints on `Val1` and
+  /// `Val2` imposed by the flow condition.
+  bool equivalentBoolValues(BoolValue &Val1, BoolValue &Val2);
+
 private:
   /// Adds all constraints of the flow condition identified by `Token` and all
   /// of its transitive dependencies to `Constraints`. `VisitedTokens` is used

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index 57c8750a67e6..475eeef53737 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -137,6 +137,13 @@ bool 
DataflowAnalysisContext::flowConditionIsTautology(AtomicBoolValue &Token) {
   return isUnsatisfiable(std::move(Constraints));
 }
 
+bool DataflowAnalysisContext::equivalentBoolValues(BoolValue &Val1,
+   BoolValue &Val2) {
+  llvm::DenseSet Constraints = {
+  &getOrCreateNegation(getOrCreateIff(Val1, Val2))};
+  return isUnsatisfiable(Constraints);
+}
+
 void DataflowAnalysisContext::addTransitiveFlowConditionConstraints(
 AtomicBoolValue &Token, llvm::DenseSet &Constraints,
 llvm::DenseSet &VisitedTokens) {

diff  --git 
a/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
index 1ff7cf1dce9e..1f0116cdbf2e 100644
--- a/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -213,4 +213,67 @@ TEST_F(DataflowAnalysisContextTest, 
FlowConditionTautologies) {
   EXPECT_TRUE(Context.flowConditionIsTautology(FC5));
 }
 
+TEST_F(DataflowAnalysisContextTest, EquivBoolVals) {
+  auto &X = Context.createAtomicBoolValue();
+  auto &Y = Context.createAtomicBoolValue();
+  auto &Z = Context.createAtomicBoolValue();
+  auto &True = Context.getBoolLiteralValue(true);
+  auto &False = Context.getBoolLiteralValue(false);
+
+  // X == X
+  EXPECT_TRUE(Context.equivalentBoolValues(X, X));
+  // X != Y
+  EXPECT_FALSE(Context.equivalentBoolValues(X, Y));
+
+  // !X != X
+  EXPECT_FALSE(Context.equivalentBoolValues(Context.getOrCreateNegation(X), 
X));
+  // !(!X) = X
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateNegation(Context.getOrCreateNegation(X)), X));
+
+  // (X || X) == X
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateDisjunction(X, X), X));
+  // (X || Y) != X
+  EXPECT_FALSE(
+  Context.equivalentBoolValues(Context.getOrCreateDisjunction(X, Y), X));
+  // (X || True) == True
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateDisjunction(X, True), True));
+  // (X || False) == X
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateDisjunction(X, False), X));
+
+  // (X && X) == X
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, X), X));
+  // (X && Y) != X
+  EXPECT_FALSE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, Y), X));
+  // (X && True) == X
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, True), 
X));
+  // (X && False) == False
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateConjunction(X, False), False))

[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D127544#3609393 , @hctim wrote:

> I see that the clang-ppc64le-linux bot is green with the second attempt 
> (https://lab.llvm.org/buildbot/#/builders/105/builds/27200). Please let me 
> know if you have further issues.

Thanks. Will do (hopefully there won't be more issues).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

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


[PATCH] D128520: [clang][dataflow] Refactor function that queries the solver for satisfiability checking.

2022-06-24 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG42a7ddb428c9: [clang][dataflow] Refactor function that 
queries the solver for satisfiability… (authored by wyt, committed by 
gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128520

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp


Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -108,6 +108,13 @@
   return Token;
 }
 
+Solver::Result
+DataflowAnalysisContext::querySolver(llvm::DenseSet Constraints) {
+  Constraints.insert(&getBoolLiteralValue(true));
+  Constraints.insert(&getOrCreateNegation(getBoolLiteralValue(false)));
+  return S->solve(std::move(Constraints));
+}
+
 bool DataflowAnalysisContext::flowConditionImplies(AtomicBoolValue &Token,
BoolValue &Val) {
   // Returns true if and only if truth assignment of the flow condition implies
@@ -115,28 +122,19 @@
   // reducing the problem to satisfiability checking. In other words, we 
attempt
   // to show that assuming `Val` is false makes the constraints induced by the
   // flow condition unsatisfiable.
-  llvm::DenseSet Constraints = {
-  &Token,
-  &getBoolLiteralValue(true),
-  &getOrCreateNegation(getBoolLiteralValue(false)),
-  &getOrCreateNegation(Val),
-  };
+  llvm::DenseSet Constraints = {&Token, 
&getOrCreateNegation(Val)};
   llvm::DenseSet VisitedTokens;
   addTransitiveFlowConditionConstraints(Token, Constraints, VisitedTokens);
-  return S->solve(std::move(Constraints)) == Solver::Result::Unsatisfiable;
+  return isUnsatisfiable(std::move(Constraints));
 }
 
 bool DataflowAnalysisContext::flowConditionIsTautology(AtomicBoolValue &Token) 
{
   // Returns true if and only if we cannot prove that the flow condition can
   // ever be false.
-  llvm::DenseSet Constraints = {
-  &getBoolLiteralValue(true),
-  &getOrCreateNegation(getBoolLiteralValue(false)),
-  &getOrCreateNegation(Token),
-  };
+  llvm::DenseSet Constraints = {&getOrCreateNegation(Token)};
   llvm::DenseSet VisitedTokens;
   addTransitiveFlowConditionConstraints(Token, Constraints, VisitedTokens);
-  return S->solve(std::move(Constraints)) == Solver::Result::Unsatisfiable;
+  return isUnsatisfiable(std::move(Constraints));
 }
 
 void DataflowAnalysisContext::addTransitiveFlowConditionConstraints(
Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -212,6 +212,19 @@
   AtomicBoolValue &Token, llvm::DenseSet &Constraints,
   llvm::DenseSet &VisitedTokens);
 
+  /// Returns the result of satisfiability checking on `Constraints`.
+  /// Possible return values are:
+  /// - `Satisfiable`: There exists a satisfying assignment for `Constraints`.
+  /// - `Unsatisfiable`: There is no satisfying assignment for `Constraints`.
+  /// - `TimedOut`: The solver gives up on finding a satisfying assignment.
+  Solver::Result querySolver(llvm::DenseSet Constraints);
+
+  /// Returns true if the solver is able to prove that there is no satisfying
+  /// assignment for `Constraints`
+  bool isUnsatisfiable(llvm::DenseSet Constraints) {
+return querySolver(std::move(Constraints)) == 
Solver::Result::Unsatisfiable;
+  }
+
   std::unique_ptr S;
 
   // Storage for the state of a program.


Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -108,6 +108,13 @@
   return Token;
 }
 
+Solver::Result
+DataflowAnalysisContext::querySolver(llvm::DenseSet Constraints) {
+  Constraints.insert(&getBoolLiteralValue(true));
+  Constraints.insert(&getOrCreateNegation(getBoolLiteralValue(false)));
+  return S->solve(std::move(Constraints));
+}
+
 bool DataflowAnalysisContext::flowConditionImplies(AtomicBoolValue &Token,
BoolValue &Val) {
   // Returns true if and only if truth assignment of the flow condition implies
@@ -115,28 +122,19 @@
   // reducing the problem to satisfiability checking. In other words, we attempt
   // to show that assuming `Val` is false makes the constraints induced by the
   // flow condition unsatisfiable.
-  llvm::DenseSet Constraints = {
-   

[clang] 42a7ddb - [clang][dataflow] Refactor function that queries the solver for satisfiability checking.

2022-06-24 Thread Dmitri Gribenko via cfe-commits

Author: Wei Yi Tee
Date: 2022-06-25T00:05:43+02:00
New Revision: 42a7ddb428c999229491b0effbb1a4059149fba8

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

LOG: [clang][dataflow] Refactor function that queries the solver for 
satisfiability checking.

Given a set of `Constraints`, `querySolver` adds common background information 
across queries (`TrueVal` is always true and `FalseVal` is always false) and 
passes the query to the solver.

`checkUnsatisfiable` is a simple wrapper around `querySolver` for checking that 
the solver returns an unsatisfiable result.

Depends On D128519

Reviewed By: gribozavr2, xazax.hun

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index 9f89b2ff5b831..8a1fc9745b215 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -212,6 +212,19 @@ class DataflowAnalysisContext {
   AtomicBoolValue &Token, llvm::DenseSet &Constraints,
   llvm::DenseSet &VisitedTokens);
 
+  /// Returns the result of satisfiability checking on `Constraints`.
+  /// Possible return values are:
+  /// - `Satisfiable`: There exists a satisfying assignment for `Constraints`.
+  /// - `Unsatisfiable`: There is no satisfying assignment for `Constraints`.
+  /// - `TimedOut`: The solver gives up on finding a satisfying assignment.
+  Solver::Result querySolver(llvm::DenseSet Constraints);
+
+  /// Returns true if the solver is able to prove that there is no satisfying
+  /// assignment for `Constraints`
+  bool isUnsatisfiable(llvm::DenseSet Constraints) {
+return querySolver(std::move(Constraints)) == 
Solver::Result::Unsatisfiable;
+  }
+
   std::unique_ptr S;
 
   // Storage for the state of a program.

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index 10e7df394f40f..57c8750a67e66 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -108,6 +108,13 @@ 
DataflowAnalysisContext::joinFlowConditions(AtomicBoolValue &FirstToken,
   return Token;
 }
 
+Solver::Result
+DataflowAnalysisContext::querySolver(llvm::DenseSet Constraints) {
+  Constraints.insert(&getBoolLiteralValue(true));
+  Constraints.insert(&getOrCreateNegation(getBoolLiteralValue(false)));
+  return S->solve(std::move(Constraints));
+}
+
 bool DataflowAnalysisContext::flowConditionImplies(AtomicBoolValue &Token,
BoolValue &Val) {
   // Returns true if and only if truth assignment of the flow condition implies
@@ -115,28 +122,19 @@ bool 
DataflowAnalysisContext::flowConditionImplies(AtomicBoolValue &Token,
   // reducing the problem to satisfiability checking. In other words, we 
attempt
   // to show that assuming `Val` is false makes the constraints induced by the
   // flow condition unsatisfiable.
-  llvm::DenseSet Constraints = {
-  &Token,
-  &getBoolLiteralValue(true),
-  &getOrCreateNegation(getBoolLiteralValue(false)),
-  &getOrCreateNegation(Val),
-  };
+  llvm::DenseSet Constraints = {&Token, 
&getOrCreateNegation(Val)};
   llvm::DenseSet VisitedTokens;
   addTransitiveFlowConditionConstraints(Token, Constraints, VisitedTokens);
-  return S->solve(std::move(Constraints)) == Solver::Result::Unsatisfiable;
+  return isUnsatisfiable(std::move(Constraints));
 }
 
 bool DataflowAnalysisContext::flowConditionIsTautology(AtomicBoolValue &Token) 
{
   // Returns true if and only if we cannot prove that the flow condition can
   // ever be false.
-  llvm::DenseSet Constraints = {
-  &getBoolLiteralValue(true),
-  &getOrCreateNegation(getBoolLiteralValue(false)),
-  &getOrCreateNegation(Token),
-  };
+  llvm::DenseSet Constraints = {&getOrCreateNegation(Token)};
   llvm::DenseSet VisitedTokens;
   addTransitiveFlowConditionConstraints(Token, Constraints, VisitedTokens);
-  return S->solve(std::move(Constraints)) == Solver::Result::Unsatisfiable;
+  return isUnsatisfiable(std::move(Constraints));
 }
 
 void DataflowAnalysisContext::addTransitiveFlowConditionConstraints(



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


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

I see that the clang-ppc64le-linux bot is green with the second attempt 
(https://lab.llvm.org/buildbot/#/builders/105/builds/27200). Please let me know 
if you have further issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

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


[PATCH] D128521: [clang][dataflow] Implement functionality to compare if two boolean values are equivalent.

2022-06-24 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 439899.
wyt added a comment.

Propagate change from parent patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128521

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -213,4 +213,67 @@
   EXPECT_TRUE(Context.flowConditionIsTautology(FC5));
 }
 
+TEST_F(DataflowAnalysisContextTest, EquivBoolVals) {
+  auto &X = Context.createAtomicBoolValue();
+  auto &Y = Context.createAtomicBoolValue();
+  auto &Z = Context.createAtomicBoolValue();
+  auto &True = Context.getBoolLiteralValue(true);
+  auto &False = Context.getBoolLiteralValue(false);
+
+  // X == X
+  EXPECT_TRUE(Context.equivalentBoolValues(X, X));
+  // X != Y
+  EXPECT_FALSE(Context.equivalentBoolValues(X, Y));
+
+  // !X != X
+  EXPECT_FALSE(Context.equivalentBoolValues(Context.getOrCreateNegation(X), X));
+  // !(!X) = X
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateNegation(Context.getOrCreateNegation(X)), X));
+
+  // (X || X) == X
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateDisjunction(X, X), X));
+  // (X || Y) != X
+  EXPECT_FALSE(
+  Context.equivalentBoolValues(Context.getOrCreateDisjunction(X, Y), X));
+  // (X || True) == True
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateDisjunction(X, True), True));
+  // (X || False) == X
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateDisjunction(X, False), X));
+
+  // (X && X) == X
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, X), X));
+  // (X && Y) != X
+  EXPECT_FALSE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, Y), X));
+  // (X && True) == X
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, True), X));
+  // (X && False) == False
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateConjunction(X, False), False));
+
+  // (X || Y) == (Y || X)
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateDisjunction(X, Y),
+   Context.getOrCreateDisjunction(Y, X)));
+  // (X && Y) == (Y && X)
+  EXPECT_TRUE(
+  Context.equivalentBoolValues(Context.getOrCreateConjunction(X, Y),
+   Context.getOrCreateConjunction(Y, X)));
+
+  // ((X || Y) || Z) == (X || (Y || Z))
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateDisjunction(Context.getOrCreateDisjunction(X, Y), Z),
+  Context.getOrCreateDisjunction(X, Context.getOrCreateDisjunction(Y, Z;
+  // ((X && Y) && Z) == (X && (Y && Z))
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  Context.getOrCreateConjunction(Context.getOrCreateConjunction(X, Y), Z),
+  Context.getOrCreateConjunction(X, Context.getOrCreateConjunction(Y, Z;
+}
+
 } // namespace
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -137,6 +137,13 @@
   return isUnsatisfiable(std::move(Constraints));
 }
 
+bool DataflowAnalysisContext::equivalentBoolValues(BoolValue &Val1,
+   BoolValue &Val2) {
+  llvm::DenseSet Constraints = {
+  &getOrCreateNegation(getOrCreateIff(Val1, Val2))};
+  return isUnsatisfiable(Constraints);
+}
+
 void DataflowAnalysisContext::addTransitiveFlowConditionConstraints(
 AtomicBoolValue &Token, llvm::DenseSet &Constraints,
 llvm::DenseSet &VisitedTokens) {
Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -203,6 +203,11 @@
   /// identified by `Token` are always true.
   bool flowConditionIsTautology(AtomicBoolValue &Token);
 
+  /// Returns true if `Val1` is equivalent to `Val2`.
+  /// Note: This function doesn't take into account constraints on `Val1` and
+  /// `Val2` imposed by the flow condition.
+  bool equivalentBoolValues(BoolValue &Val1, BoolValue &Val2);
+
 private:
   /// Adds all constraints of the flow condition identified by `Token` and all
   /// of its transitive dependencies to `Constraints`. `VisitedTokens` is used
___

[PATCH] D128520: [clang][dataflow] Refactor function that queries the solver for satisfiability checking.

2022-06-24 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 439898.
wyt marked an inline comment as done.
wyt added a comment.

Rename `checkUnsatisfiable` to `isUnsatisfiable`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128520

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp


Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -108,6 +108,13 @@
   return Token;
 }
 
+Solver::Result
+DataflowAnalysisContext::querySolver(llvm::DenseSet Constraints) {
+  Constraints.insert(&getBoolLiteralValue(true));
+  Constraints.insert(&getOrCreateNegation(getBoolLiteralValue(false)));
+  return S->solve(std::move(Constraints));
+}
+
 bool DataflowAnalysisContext::flowConditionImplies(AtomicBoolValue &Token,
BoolValue &Val) {
   // Returns true if and only if truth assignment of the flow condition implies
@@ -115,28 +122,19 @@
   // reducing the problem to satisfiability checking. In other words, we 
attempt
   // to show that assuming `Val` is false makes the constraints induced by the
   // flow condition unsatisfiable.
-  llvm::DenseSet Constraints = {
-  &Token,
-  &getBoolLiteralValue(true),
-  &getOrCreateNegation(getBoolLiteralValue(false)),
-  &getOrCreateNegation(Val),
-  };
+  llvm::DenseSet Constraints = {&Token, 
&getOrCreateNegation(Val)};
   llvm::DenseSet VisitedTokens;
   addTransitiveFlowConditionConstraints(Token, Constraints, VisitedTokens);
-  return S->solve(std::move(Constraints)) == Solver::Result::Unsatisfiable;
+  return isUnsatisfiable(std::move(Constraints));
 }
 
 bool DataflowAnalysisContext::flowConditionIsTautology(AtomicBoolValue &Token) 
{
   // Returns true if and only if we cannot prove that the flow condition can
   // ever be false.
-  llvm::DenseSet Constraints = {
-  &getBoolLiteralValue(true),
-  &getOrCreateNegation(getBoolLiteralValue(false)),
-  &getOrCreateNegation(Token),
-  };
+  llvm::DenseSet Constraints = {&getOrCreateNegation(Token)};
   llvm::DenseSet VisitedTokens;
   addTransitiveFlowConditionConstraints(Token, Constraints, VisitedTokens);
-  return S->solve(std::move(Constraints)) == Solver::Result::Unsatisfiable;
+  return isUnsatisfiable(std::move(Constraints));
 }
 
 void DataflowAnalysisContext::addTransitiveFlowConditionConstraints(
Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -212,6 +212,19 @@
   AtomicBoolValue &Token, llvm::DenseSet &Constraints,
   llvm::DenseSet &VisitedTokens);
 
+  /// Returns the result of satisfiability checking on `Constraints`.
+  /// Possible return values are:
+  /// - `Satisfiable`: There exists a satisfying assignment for `Constraints`.
+  /// - `Unsatisfiable`: There is no satisfying assignment for `Constraints`.
+  /// - `TimedOut`: The solver gives up on finding a satisfying assignment.
+  Solver::Result querySolver(llvm::DenseSet Constraints);
+
+  /// Returns true if the solver is able to prove that there is no satisfying
+  /// assignment for `Constraints`
+  bool isUnsatisfiable(llvm::DenseSet Constraints) {
+return querySolver(std::move(Constraints)) == 
Solver::Result::Unsatisfiable;
+  }
+
   std::unique_ptr S;
 
   // Storage for the state of a program.


Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -108,6 +108,13 @@
   return Token;
 }
 
+Solver::Result
+DataflowAnalysisContext::querySolver(llvm::DenseSet Constraints) {
+  Constraints.insert(&getBoolLiteralValue(true));
+  Constraints.insert(&getOrCreateNegation(getBoolLiteralValue(false)));
+  return S->solve(std::move(Constraints));
+}
+
 bool DataflowAnalysisContext::flowConditionImplies(AtomicBoolValue &Token,
BoolValue &Val) {
   // Returns true if and only if truth assignment of the flow condition implies
@@ -115,28 +122,19 @@
   // reducing the problem to satisfiability checking. In other words, we attempt
   // to show that assuming `Val` is false makes the constraints induced by the
   // flow condition unsatisfiable.
-  llvm::DenseSet Constraints = {
-  &Token,
-  &getBoolLiteralValue(true),
-  &getOrCreateNegation(getBoolLiteralValue(false)),
-  &getOrCreateNegation(Val),

[clang] 243fc3d - fix-forward hwasan-globals.cpp (round 2)

2022-06-24 Thread Mitch Phillips via cfe-commits

Author: Mitch Phillips
Date: 2022-06-24T14:49:37-07:00
New Revision: 243fc3daf675ea047bb80c21c62d24a331da8b16

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

LOG: fix-forward hwasan-globals.cpp (round 2)

Just force the aarch64 target compilation (after making sure the test
only runs if that target is available).

Because global metadata isn't target-specific, just selecting a target
here is fine.

Should fix https://reviews.llvm.org/D127544#3609312

Added: 


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

Removed: 




diff  --git a/clang/test/CodeGen/hwasan-globals.cpp 
b/clang/test/CodeGen/hwasan-globals.cpp
index 9424efacb381..39460d3297b4 100644
--- a/clang/test/CodeGen/hwasan-globals.cpp
+++ b/clang/test/CodeGen/hwasan-globals.cpp
@@ -1,13 +1,14 @@
-// REQUIRES: aarch64-registered-target || x86-registered-target
+// REQUIRES: aarch64-registered-target
 
 // RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
 // RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \
-// RUN:   -fsanitize=hwaddress -emit-llvm -o - %s | FileCheck %s
+// RUN:   -fsanitize=hwaddress -emit-llvm -triple aarch64-linux-android31 -o -\
+// RUN:%s | FileCheck %s
 
 // RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
 // RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \
-// RUN:   -fsanitize=hwaddress -emit-llvm -o - %s | \
-// RUN:   FileCheck %s --check-prefix=IGNORELIST
+// RUN:   -fsanitize=hwaddress -emit-llvm -triple aarch64-linux-android31 -o -\
+// RUN:   %s | FileCheck %s --check-prefix=IGNORELIST
 
 int global;
 int __attribute__((no_sanitize("hwaddress"))) attributed_global;
@@ -31,14 +32,14 @@ void func() {
 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], 
!"extra_global", i1 false, i1 false}
 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, 
i1 false}
-// CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 12, i32 5}
+// CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 13, i32 5}
 // CHECK: ![[ATTR_GLOBAL]] = !{{{.*attributed_global.*}}, null, null, i1 
false, i1 true}
 // CHECK: ![[DISABLE_INSTR_GLOBAL]] = 
!{{{.*disable_instrumentation_global.*}}, null, null, i1 false, i1 true}
 // CHECK: ![[IGNORELISTED_GLOBAL]] = !{{{.*ignorelisted_global.*}}, null, 
null, i1 false, i1 true}
 // CHECK: ![[STATIC_VAR]] = !{{{.*}} ![[STATIC_LOC:[0-9]+]], !"static_var", i1 
false, i1 false}
-// CHECK: ![[STATIC_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 18, i32 14}
+// CHECK: ![[STATIC_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 19, i32 14}
 // CHECK: ![[LITERAL]] = !{{{.*}} ![[LITERAL_LOC:[0-9]+]], !"", i1 false, i1 false}
-// CHECK: ![[LITERAL_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 19, i32 25}
+// CHECK: ![[LITERAL_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 20, i32 25}
 
 // IGNORELIST: @{{.*}}global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, 
no_sanitize_hwaddress



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


[PATCH] D126864: [clang] Introduce -fstrict-flex-arrays= for stricter handling of flexible arrays

2022-06-24 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added subscribers: cmtice, dblaikie.
dblaikie added a comment.
Herald added a subscriber: steakhal.

Looks like this got committed in 886715af962de2c92fac4bd37104450345711e4a 
 though it 
was missing the `Differential Revision` tag to allow phab (or humans) to 
connect the commit with the review.

In any case, this seems to be causing a UBSan (`UndefinedBehaviorSanitizer: 
out-of-bounds-index third_party/python_runtime/v3_9/Objects/codeobject.c:54:34 
`) regression in Python 3.9 at Google - I don't have a readily shareable 
standalone reproduction just now - but would you consider reverting while this 
is investigated further?

(@cmtice)


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

https://reviews.llvm.org/D126864

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


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127544#3609343 , 
@hubert.reinterpretcast wrote:

> In D127544#3609335 , @hctim wrote:
>
>> Sent fadc98b06befb674fa47da4f3d8606bf61bed681 
>>  to 
>> fix-forward.
>
> I thought `*-registered-target` is true as long as the target is available, 
> not only when the target happens to be the default.
> Also, if there would be more such tests in the future, maybe a LIT feature 
> that the default target supports HWAsan makes sense?

Too right. Given the purpose of this test is to just check that the globals 
have the right IR attributes, any target is fine - as the IR attributes aren't 
target-specific.

Took another fix-forward whack-a-mole attempt, committing in a sec.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

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


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D127544#3609335 , @hctim wrote:

> Sent fadc98b06befb674fa47da4f3d8606bf61bed681 
>  to 
> fix-forward.

I thought `*-registered-target` is true as long as the target is available, not 
only when the target happens to be the default.
Also, if there would be more such tests in the future, maybe a LIT feature that 
the default target supports HWAsan makes sense?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

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


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

Sent fadc98b06befb674fa47da4f3d8606bf61bed681 
 to 
fix-forward.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

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


[clang] fadc98b - Don't run hwasan-globals.cpp test on non-x86/aarch64

2022-06-24 Thread Mitch Phillips via cfe-commits

Author: Mitch Phillips
Date: 2022-06-24T14:33:41-07:00
New Revision: fadc98b06befb674fa47da4f3d8606bf61bed681

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

LOG: Don't run hwasan-globals.cpp test on non-x86/aarch64

Fix-forward for https://reviews.llvm.org/D127544#3609312

IR pass has some target-specific inline asm lowering that check-fails
for non-x86 non-aarch64 targets.

For now, just run these tests only on those targets.

Added: 


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

Removed: 




diff  --git a/clang/test/CodeGen/hwasan-globals.cpp 
b/clang/test/CodeGen/hwasan-globals.cpp
index 7edf6e6b7e57..9424efacb381 100644
--- a/clang/test/CodeGen/hwasan-globals.cpp
+++ b/clang/test/CodeGen/hwasan-globals.cpp
@@ -1,3 +1,5 @@
+// REQUIRES: aarch64-registered-target || x86-registered-target
+
 // RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
 // RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \
 // RUN:   -fsanitize=hwaddress -emit-llvm -o - %s | FileCheck %s
@@ -29,14 +31,14 @@ void func() {
 // CHECK: ![[EXTRA_GLOBAL]] = !{{{.*}} ![[EXTRA_GLOBAL_LOC:[0-9]+]], 
!"extra_global", i1 false, i1 false}
 // CHECK: ![[EXTRA_GLOBAL_LOC]] = !{!"{{.*}}extra-source.cpp", i32 1, i32 5}
 // CHECK: ![[GLOBAL]] = !{{{.*}} ![[GLOBAL_LOC:[0-9]+]], !"global", i1 false, 
i1 false}
-// CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 10, i32 5}
+// CHECK: ![[GLOBAL_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 12, i32 5}
 // CHECK: ![[ATTR_GLOBAL]] = !{{{.*attributed_global.*}}, null, null, i1 
false, i1 true}
 // CHECK: ![[DISABLE_INSTR_GLOBAL]] = 
!{{{.*disable_instrumentation_global.*}}, null, null, i1 false, i1 true}
 // CHECK: ![[IGNORELISTED_GLOBAL]] = !{{{.*ignorelisted_global.*}}, null, 
null, i1 false, i1 true}
 // CHECK: ![[STATIC_VAR]] = !{{{.*}} ![[STATIC_LOC:[0-9]+]], !"static_var", i1 
false, i1 false}
-// CHECK: ![[STATIC_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 16, i32 14}
+// CHECK: ![[STATIC_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 18, i32 14}
 // CHECK: ![[LITERAL]] = !{{{.*}} ![[LITERAL_LOC:[0-9]+]], !"", i1 false, i1 false}
-// CHECK: ![[LITERAL_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 17, i32 25}
+// CHECK: ![[LITERAL_LOC]] = !{!"{{.*}}hwasan-globals.cpp", i32 19, i32 25}
 
 // IGNORELIST: @{{.*}}global{{.*}} ={{.*}} global {{.*}}, no_sanitize_hwaddress
 // IGNORELIST: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, 
no_sanitize_hwaddress



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


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim added a comment.

In D127544#3609312 , 
@hubert.reinterpretcast wrote:

> This is causing "unsupported architecture" errors on bots.

Looking, I see this on the sanitizer-ppc64 bots.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

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


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

From the content of this patch, it probably is 
`llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp`:

  switch (TargetTriple.getArch()) {
  case Triple::x86_64:
// The signal handler will find the data address in rdi.
Asm = InlineAsm::get(
FunctionType::get(IRB.getVoidTy(), {PtrLong->getType()}, false),
"int3\nnopl " +
itostr(0x40 + (AccessInfo & HWASanAccessInfo::RuntimeMask)) +
"(%rax)",
"{rdi}",
/*hasSideEffects=*/true);
break;
  case Triple::aarch64:
  case Triple::aarch64_be:
// The signal handler will find the data address in x0.
Asm = InlineAsm::get(
FunctionType::get(IRB.getVoidTy(), {PtrLong->getType()}, false),
"brk #" + itostr(0x900 + (AccessInfo & HWASanAccessInfo::RuntimeMask)),
"{x0}",
/*hasSideEffects=*/true);
break;
  default:
report_fatal_error("unsupported architecture");
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

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


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

This is causing "unsupported architecture" errors on bots.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

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


[PATCH] D128520: [clang][dataflow] Refactor function that queries the solver for satisfiability checking.

2022-06-24 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 accepted this revision.
gribozavr2 added inline comments.



Comment at: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h:224
+  /// assignment for `Constraints`
+  bool checkUnsatisfiable(llvm::DenseSet Constraints) {
+return querySolver(std::move(Constraints)) == 
Solver::Result::Unsatisfiable;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128520

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


[PATCH] D128519: [clang][dataflow] Move logic for creating implication and iff expressions into `DataflowAnalysisContext` from `DataflowEnvironment`.

2022-06-24 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG00e9d53453ab: [clang][dataflow] Move logic for creating 
implication and iff expressions into… (authored by wyt, committed by gribozavr).

Changed prior to commit:
  https://reviews.llvm.org/D128519?vs=439761&id=439887#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128519

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
@@ -33,18 +33,6 @@
   Environment Env;
 };
 
-TEST_F(EnvironmentTest, MakeImplicationReturnsTrueGivenSameArgs) {
-  auto &X = Env.makeAtomicBoolValue();
-  auto &XEqX = Env.makeImplication(X, X);
-  EXPECT_EQ(&XEqX, &Env.getBoolLiteralValue(true));
-}
-
-TEST_F(EnvironmentTest, MakeIffReturnsTrueGivenSameArgs) {
-  auto &X = Env.makeAtomicBoolValue();
-  auto &XEqX = Env.makeIff(X, X);
-  EXPECT_EQ(&XEqX, &Env.getBoolLiteralValue(true));
-}
-
 TEST_F(EnvironmentTest, FlowCondition) {
   EXPECT_TRUE(Env.flowConditionImplies(Env.getBoolLiteralValue(true)));
   EXPECT_FALSE(Env.flowConditionImplies(Env.getBoolLiteralValue(false)));
Index: clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -33,63 +33,108 @@
 }
 
 TEST_F(DataflowAnalysisContextTest,
-   GetOrCreateConjunctionValueReturnsSameExprGivenSameArgs) {
+   GetOrCreateConjunctionReturnsSameExprGivenSameArgs) {
   auto &X = Context.createAtomicBoolValue();
-  auto &XAndX = Context.getOrCreateConjunctionValue(X, X);
+  auto &XAndX = Context.getOrCreateConjunction(X, X);
   EXPECT_EQ(&XAndX, &X);
 }
 
 TEST_F(DataflowAnalysisContextTest,
-   GetOrCreateConjunctionValueReturnsSameExprOnSubsequentCalls) {
+   GetOrCreateConjunctionReturnsSameExprOnSubsequentCalls) {
   auto &X = Context.createAtomicBoolValue();
   auto &Y = Context.createAtomicBoolValue();
-  auto &XAndY1 = Context.getOrCreateConjunctionValue(X, Y);
-  auto &XAndY2 = Context.getOrCreateConjunctionValue(X, Y);
+  auto &XAndY1 = Context.getOrCreateConjunction(X, Y);
+  auto &XAndY2 = Context.getOrCreateConjunction(X, Y);
   EXPECT_EQ(&XAndY1, &XAndY2);
 
-  auto &YAndX = Context.getOrCreateConjunctionValue(Y, X);
+  auto &YAndX = Context.getOrCreateConjunction(Y, X);
   EXPECT_EQ(&XAndY1, &YAndX);
 
   auto &Z = Context.createAtomicBoolValue();
-  auto &XAndZ = Context.getOrCreateConjunctionValue(X, Z);
+  auto &XAndZ = Context.getOrCreateConjunction(X, Z);
   EXPECT_NE(&XAndY1, &XAndZ);
 }
 
 TEST_F(DataflowAnalysisContextTest,
-   GetOrCreateDisjunctionValueReturnsSameExprGivenSameArgs) {
+   GetOrCreateDisjunctionReturnsSameExprGivenSameArgs) {
   auto &X = Context.createAtomicBoolValue();
-  auto &XOrX = Context.getOrCreateDisjunctionValue(X, X);
+  auto &XOrX = Context.getOrCreateDisjunction(X, X);
   EXPECT_EQ(&XOrX, &X);
 }
 
 TEST_F(DataflowAnalysisContextTest,
-   GetOrCreateDisjunctionValueReturnsSameExprOnSubsequentCalls) {
+   GetOrCreateDisjunctionReturnsSameExprOnSubsequentCalls) {
   auto &X = Context.createAtomicBoolValue();
   auto &Y = Context.createAtomicBoolValue();
-  auto &XOrY1 = Context.getOrCreateDisjunctionValue(X, Y);
-  auto &XOrY2 = Context.getOrCreateDisjunctionValue(X, Y);
+  auto &XOrY1 = Context.getOrCreateDisjunction(X, Y);
+  auto &XOrY2 = Context.getOrCreateDisjunction(X, Y);
   EXPECT_EQ(&XOrY1, &XOrY2);
 
-  auto &YOrX = Context.getOrCreateDisjunctionValue(Y, X);
+  auto &YOrX = Context.getOrCreateDisjunction(Y, X);
   EXPECT_EQ(&XOrY1, &YOrX);
 
   auto &Z = Context.createAtomicBoolValue();
-  auto &XOrZ = Context.getOrCreateDisjunctionValue(X, Z);
+  auto &XOrZ = Context.getOrCreateDisjunction(X, Z);
   EXPECT_NE(&XOrY1, &XOrZ);
 }
 
 TEST_F(DataflowAnalysisContextTest,
-   GetOrCreateNegationValueReturnsSameExprOnSubsequentCalls) {
+   GetOrCreateNegationReturnsSameExprOnSubsequentCalls) {
   auto &X = Context.createAtomicBoolValue();
-  auto &NotX1 = Context.getOrCreateNegationValue(X);
-  auto &NotX2 = Context.getOrCreateNegationValue(X);
+  auto &NotX1 = Context.getOrCreateNegation(X);
+  auto &NotX2 = Context.getOrCreateNegation(X);
   EXPECT_EQ(&NotX1, &NotX2);
 
   auto &Y = Context.createAtomicBoolVa

[clang] 00e9d53 - [clang][dataflow] Move logic for creating implication and iff expressions into `DataflowAnalysisContext` from `DataflowEnvironment`.

2022-06-24 Thread Dmitri Gribenko via cfe-commits

Author: Wei Yi Tee
Date: 2022-06-24T23:16:44+02:00
New Revision: 00e9d53453abc8f2e3d69e9c7fba83dc65a74259

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

LOG: [clang][dataflow] Move logic for creating implication and iff expressions 
into `DataflowAnalysisContext` from `DataflowEnvironment`.

To keep functionality of creating boolean expressions in a consistent location.

Depends On D128357

Reviewed By: gribozavr2, sgatev, xazax.hun

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index 48d0eedc49dde..9f89b2ff5b831 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -151,17 +151,29 @@ class DataflowAnalysisContext {
   /// `RHS`. Subsequent calls with the same arguments, regardless of their
   /// order, will return the same result. If the given boolean values represent
   /// the same value, the result will be the value itself.
-  BoolValue &getOrCreateConjunctionValue(BoolValue &LHS, BoolValue &RHS);
+  BoolValue &getOrCreateConjunction(BoolValue &LHS, BoolValue &RHS);
 
   /// Returns a boolean value that represents the disjunction of `LHS` and
   /// `RHS`. Subsequent calls with the same arguments, regardless of their
   /// order, will return the same result. If the given boolean values represent
   /// the same value, the result will be the value itself.
-  BoolValue &getOrCreateDisjunctionValue(BoolValue &LHS, BoolValue &RHS);
+  BoolValue &getOrCreateDisjunction(BoolValue &LHS, BoolValue &RHS);
 
   /// Returns a boolean value that represents the negation of `Val`. Subsequent
   /// calls with the same argument will return the same result.
-  BoolValue &getOrCreateNegationValue(BoolValue &Val);
+  BoolValue &getOrCreateNegation(BoolValue &Val);
+
+  /// Returns a boolean value that represents `LHS => RHS`. Subsequent calls
+  /// with the same arguments, will return the same result. If the given 
boolean
+  /// values represent the same value, the result will be a value that
+  /// represents the true boolean literal.
+  BoolValue &getOrCreateImplication(BoolValue &LHS, BoolValue &RHS);
+
+  /// Returns a boolean value that represents `LHS <=> RHS`. Subsequent calls
+  /// with the same arguments, regardless of their order, will return the same
+  /// result. If the given boolean values represent the same value, the result
+  /// will be a value that represents the true boolean literal.
+  BoolValue &getOrCreateIff(BoolValue &LHS, BoolValue &RHS);
 
   /// Creates a fresh flow condition and returns a token that identifies it. 
The
   /// token can be used to perform various operations on the flow condition 
such

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 0a2c75f804c2a..ac49d22995c1d 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -268,7 +268,7 @@ class Environment {
   /// order, will return the same result. If the given boolean values represent
   /// the same value, the result will be the value itself.
   BoolValue &makeAnd(BoolValue &LHS, BoolValue &RHS) const {
-return DACtx->getOrCreateConjunctionValue(LHS, RHS);
+return DACtx->getOrCreateConjunction(LHS, RHS);
   }
 
   /// Returns a boolean value that represents the disjunction of `LHS` and
@@ -276,21 +276,21 @@ class Environment {
   /// order, will return the same result. If the given boolean values represent
   /// the same value, the result will be the value itself.
   BoolValue &makeOr(BoolValue &LHS, BoolValue &RHS) const {
-return DACtx->getOrCreateDisjunctionValue(LHS, RHS);
+return DACtx->getOrCreateDisjunction(LHS, RHS);
   }
 
   /// Returns a boolean value that represents the negation of `Val`. Subsequent
   /// calls with the same argument will return the same result.
   BoolValue &makeNot(BoolValue &Val) const {
-return DACtx->getOrCreateNegationValue(Val);
+return DACtx->getOrCreateNegation(Val);
   }
 
   /// Returns a boolean value represents `LHS` => `RHS`. Subsequent calls with
-  /// the same arguments, regardl

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2100
+GlobalVariable *Metadata = CreateMetadataGlobal(
+M, Initializer, llvm::demangle(std::string(G->getName(;
 

was this demanded before?



Comment at: llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp:2330
+ConstantInt::get(IntptrTy, Meta.IsDynInit),
+ConstantInt::get(IntptrTy, 0),
 ConstantExpr::getPointerCast(ODRIndicator, IntptrTy));

MD was fine, less changed lines


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

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


[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker

2022-06-24 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:160
+  if (const auto *Call = dyn_cast(StmtNode)) {
+const auto *Callee = Call->getDirectCallee();
+

Please don't use `auto` when type is not spelled explicitly or iterator.



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:187
+  for (const auto *GNode : SCC) {
+const auto *CanDecl = GNode->getDecl()->getCanonicalDecl();
+

Ditto.


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

https://reviews.llvm.org/D128401

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


[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker

2022-06-24 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 439884.
ziqingluo-90 added a comment.

trying to be consistent in that `auto` is used wherever possible


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

https://reviews.llvm.org/D128401

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

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
@@ -44,6 +44,27 @@
 j++;
   }
 }
+
++ (void)recursiveMethod {
+  static int i = 0;
+
+  i++;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+[I classMethod];
+  }
+
+  id x = [[I alloc] init];
+
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+[x instanceMethod];
+  }
+  while (i < 10) {
+// no warning, there is a recursive call that can mutate the static local variable
+[I recursiveMethod];
+  }
+}
 @end
 
 void testArrayCount() {
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
@@ -685,3 +685,29 @@
 0;
   }) x;
 }
+
+void test_local_static_recursion() {
+  static int i = 10;
+  int j = 0;
+
+  i--;
+  while (i >= 0)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i >= 0;)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i + j >= 0;)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i >= 0; i--)
+; // no warning, i decrements
+  while (j >= 0)
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (j) are updated in the loop body [bugprone-infinite-loop]
+test_local_static_recursion();
+
+  int (*p)(int) = 0;
+
+  while (i >= 0)
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+p = 0;
+  while (i >= 0)
+p(0); // we don't know what p points to so no warning
+}
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -11,6 +11,9 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
+#include "clang/Analysis/CallGraph.h"
+#include "llvm/ADT/SCCIterator.h"
+#include "llvm/ADT/SmallVector.h"
 
 using namespace clang::ast_matchers;
 using clang::tidy::utils::hasPtrOrReferenceInFunc;
@@ -146,6 +149,110 @@
   return false;
 }
 
+/// populates the set `Callees` with all function (and objc method) declarations
+/// called in `StmtNode` if all visited call sites have resolved call targets.
+///
+/// \return true iff all `CallExprs` visited have callees; false otherwise
+/// indicating there is an unresolved indirect call.
+static bool populateCallees(const Stmt *StmtNode,
+llvm::SmallSet &Callees) {
+  if (const auto *Call = dyn_cast(StmtNode)) {
+const auto *Callee = Call->getDirectCallee();
+
+if (!Callee)
+  return false; // unresolved call
+Callees.insert(Callee->getCanonicalDecl());
+  }
+  if (const auto *Call = dyn_cast(StmtNode)) {
+const auto *Callee = Call->getMethodDecl();
+
+if (!Callee)
+  return false; // unresolved call
+Callees.insert(Callee->getCanonicalDecl());
+  }
+  for (const auto *Child : StmtNode->children())
+if (Child && !populateCallees(Child, Callees))
+  return false;
+  return true;
+}
+
+/// returns true iff `SCC` contains `Func` and its' function set overlaps with
+/// `Callees`
+static bool overlap(ArrayRef SCC,
+const llvm::SmallSet &Callees,
+const Decl *Func) {
+  bool ContainsFunc = false, Overlap = false;
+
+  for (const auto *GNode : SCC) {
+const auto *CanDecl = GNode->getDecl()->getCanonicalDecl();
+
+ContainsFunc = ContainsFunc || (CanDecl == Func);
+Overlap = Overlap || Callees.contains(CanDecl);
+if (ContainsFunc && Overlap)
+  return true;
+  }
+  return ContainsFunc && Overlap;
+}
+
+/// returns tru

[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker

2022-06-24 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 439883.

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

https://reviews.llvm.org/D128401

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

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
@@ -44,6 +44,27 @@
 j++;
   }
 }
+
++ (void)recursiveMethod {
+  static int i = 0;
+
+  i++;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+[I classMethod];
+  }
+
+  id x = [[I alloc] init];
+
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+[x instanceMethod];
+  }
+  while (i < 10) {
+// no warning, there is a recursive call that can mutate the static local variable
+[I recursiveMethod];
+  }
+}
 @end
 
 void testArrayCount() {
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
@@ -685,3 +685,29 @@
 0;
   }) x;
 }
+
+void test_local_static_recursion() {
+  static int i = 10;
+  int j = 0;
+
+  i--;
+  while (i >= 0)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i >= 0;)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i + j >= 0;)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i >= 0; i--)
+; // no warning, i decrements
+  while (j >= 0)
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (j) are updated in the loop body [bugprone-infinite-loop]
+test_local_static_recursion();
+
+  int (*p)(int) = 0;
+
+  while (i >= 0)
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+p = 0;
+  while (i >= 0)
+p(0); // we don't know what p points to so no warning
+}
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -11,6 +11,9 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
+#include "clang/Analysis/CallGraph.h"
+#include "llvm/ADT/SCCIterator.h"
+#include "llvm/ADT/SmallVector.h"
 
 using namespace clang::ast_matchers;
 using clang::tidy::utils::hasPtrOrReferenceInFunc;
@@ -146,6 +149,110 @@
   return false;
 }
 
+/// populates the set `Callees` with all function (and objc method) declarations
+/// called in `StmtNode` if all visited call sites have resolved call targets.
+///
+/// \return true iff all `CallExprs` visited have callees; false otherwise
+/// indicating there is an unresolved indirect call.
+static bool populateCallees(const Stmt *StmtNode,
+llvm::SmallSet &Callees) {
+  if (const auto *Call = dyn_cast(StmtNode)) {
+const auto *Callee = Call->getDirectCallee();
+
+if (!Callee)
+  return false; // unresolved call
+Callees.insert(Callee->getCanonicalDecl());
+  }
+  if (const ObjCMessageExpr *Call = dyn_cast(StmtNode)) {
+const auto *Callee = Call->getMethodDecl();
+
+if (!Callee)
+  return false; // unresolved call
+Callees.insert(Callee->getCanonicalDecl());
+  }
+  for (const Stmt *Child : StmtNode->children())
+if (Child && !populateCallees(Child, Callees))
+  return false;
+  return true;
+}
+
+/// returns true iff `SCC` contains `Func` and its' function set overlaps with
+/// `Callees`
+static bool overlap(ArrayRef SCC,
+const llvm::SmallSet &Callees,
+const Decl *Func) {
+  bool ContainsFunc = false, Overlap = false;
+
+  for (CallGraphNode *GNode : SCC) {
+const auto *CanDecl = GNode->getDecl()->getCanonicalDecl();
+
+ContainsFunc = ContainsFunc || (CanDecl == Func);
+Overlap = Overlap || Callees.contains(CanDecl);
+if (ContainsFunc && Overlap)
+  return true;
+  }
+  return ContainsFunc && Overlap;
+}
+
+/// returns true iff `Cond` involves at least one static local variable.
+static bool hasStaticLoc

[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker

2022-06-24 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 439882.
ziqingluo-90 added a comment.

addressing more comments


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

https://reviews.llvm.org/D128401

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

Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.mm
@@ -44,6 +44,27 @@
 j++;
   }
 }
+
++ (void)recursiveMethod {
+  static int i = 0;
+
+  i++;
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+[I classMethod];
+  }
+
+  id x = [[I alloc] init];
+
+  while (i < 10) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+[x instanceMethod];
+  }
+  while (i < 10) {
+// no warning, there is a recursive call that can mutate the static local variable
+[I recursiveMethod];
+  }
+}
 @end
 
 void testArrayCount() {
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/infinite-loop.cpp
@@ -685,3 +685,29 @@
 0;
   }) x;
 }
+
+void test_local_static_recursion() {
+  static int i = 10;
+  int j = 0;
+
+  i--;
+  while (i >= 0)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i >= 0;)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i + j >= 0;)
+test_local_static_recursion(); // no warning, recursively decrement i
+  for (; i >= 0; i--)
+; // no warning, i decrements
+  while (j >= 0)
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (j) are updated in the loop body [bugprone-infinite-loop]
+test_local_static_recursion();
+
+  int (*p)(int) = 0;
+
+  while (i >= 0)
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: this loop is infinite; none of its condition variables (i) are updated in the loop body [bugprone-infinite-loop]
+p = 0;
+  while (i >= 0)
+p(0); // we don't know what p points to so no warning
+}
Index: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
===
--- clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -11,6 +11,9 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
+#include "clang/Analysis/CallGraph.h"
+#include "llvm/ADT/SCCIterator.h"
+#include "llvm/ADT/SmallVector.h"
 
 using namespace clang::ast_matchers;
 using clang::tidy::utils::hasPtrOrReferenceInFunc;
@@ -146,6 +149,110 @@
   return false;
 }
 
+/// populates the set `Callees` with all function (and objc method) declarations
+/// called in `StmtNode` if all visited call sites have resolved call targets.
+///
+/// \return true iff all `CallExprs` visited have callees; false otherwise
+/// indicating there is an unresolved indirect call.
+static bool populateCallees(const Stmt *StmtNode,
+llvm::SmallSet &Callees) {
+  if (const CallExpr *Call = dyn_cast(StmtNode)) {
+const auto *Callee = Call->getDirectCallee();
+
+if (!Callee)
+  return false; // unresolved call
+Callees.insert(Callee->getCanonicalDecl());
+  }
+  if (const ObjCMessageExpr *Call = dyn_cast(StmtNode)) {
+const auto *Callee = Call->getMethodDecl();
+
+if (!Callee)
+  return false; // unresolved call
+Callees.insert(Callee->getCanonicalDecl());
+  }
+  for (const Stmt *Child : StmtNode->children())
+if (Child && !populateCallees(Child, Callees))
+  return false;
+  return true;
+}
+
+/// returns true iff `SCC` contains `Func` and its' function set overlaps with
+/// `Callees`
+static bool overlap(ArrayRef SCC,
+const llvm::SmallSet &Callees,
+const Decl *Func) {
+  bool ContainsFunc = false, Overlap = false;
+
+  for (CallGraphNode *GNode : SCC) {
+const auto *CanDecl = GNode->getDecl()->getCanonicalDecl();
+
+ContainsFunc = ContainsFunc || (CanDecl == Func);
+Overlap = Overlap || Callees.contains(CanDecl);
+if (ContainsFunc && Overlap)
+  return true;
+  }
+  return ContainsFunc && Overlap;
+}
+
+/// returns true iff `Cond` involves 

[PATCH] D127911: Delete 'llvm.asan.globals' for global metadata.

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
hctim updated this revision to Diff 439880.
hctim added a comment.

Rebase on main / landed changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127911

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/test/CodeGen/asan-globals.cpp
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  clang/test/CodeGen/sanitize-init-order.cpp
  compiler-rt/test/asan/TestCases/global-location-nodebug.cpp
  compiler-rt/test/asan/TestCases/global-location.cpp
  llvm/include/llvm/Transforms/Instrumentation/AddressSanitizer.h
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
  llvm/test/Instrumentation/AddressSanitizer/global_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/global_metadata_array.ll
  llvm/test/Instrumentation/AddressSanitizer/global_with_comdat.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_global.ll
  llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
  llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
  llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -357,8 +357,6 @@
  ArrayRef) {
 AddressSanitizerOptions Opts;
 if (Name == "asan-pipeline") {
-  MPM.addPass(
-  RequireAnalysisPass());
   MPM.addPass(ModuleAddressSanitizerPass(Opts));
   return true;
 }
Index: llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
===
--- llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
+++ llvm/test/Instrumentation/SanitizerCoverage/tracing-comdat.ll
@@ -2,7 +2,7 @@
 ; Make sure asan does not instrument __sancov_gen_
 
 ; RUN: opt < %s -passes='module(sancov-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
-; RUN: opt < %s -passes='module(require,sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
+; RUN: opt < %s -passes='module(sancov-module,asan-module)' -sanitizer-coverage-level=3 -sanitizer-coverage-trace-pc-guard  -S  | FileCheck %s
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
 target triple = "x86_64-unknown-linux-gnu"
 $Foo = comdat any
Index: llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
+++ llvm/test/Instrumentation/AddressSanitizer/win-string-literal.ll
@@ -10,13 +10,12 @@
 ; CHECK-SAME: linkonce_odr dso_local constant { [5 x i8], [27 x i8] }
 ; CHECK-SAME: { [5 x i8] c"asdf\00", [27 x i8] zeroinitializer }, comdat, align 32
 
-; CHECK: @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
+; CHECK:  @"__asan_global_??_C@_04JIHMPGLA@asdf?$AA@" =
 ; CHECK-SAME: private global { i64, i64, i64, i64, i64, i64, i64, i64 }
 ; CHECK-SAME: { i64 ptrtoint ({ [5 x i8], [27 x i8] }* @"??_C@_04JIHMPGLA@asdf?$AA@" to i64),
-; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([17 x i8]* @___asan_gen_.1 to i64),
-; CHECK-SAME:   i64 ptrtoint ([8 x i8]* @___asan_gen_ to i64), i64 0,
-; CHECK-SAME:   i64 ptrtoint ({ [6 x i8]*, i32, i32 }* @___asan_gen_.3 to i64), i64 0 },
-; CHECK-SAME:   section ".ASAN$GL", comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
+; CHECK-SAME:   i64 5, i64 32, i64 ptrtoint ([7 x i8]* @___asan_gen_.1 to i64), i64 ptrtoint ([8
+; CHECK-SAME:   x i8]* @___asan_gen_ to i64), i64 0, i64 0, i64 0 }, section ".ASAN$GL",
+; CHECK-SAME:   comdat($"??_C@_04JIHMPGLA@asdf?$AA@"), align 64
 
 ; ModuleID = 't.cpp'
 source_filename = "t.cpp"
@@ -35,11 +34,9 @@
 
 attributes #0 = { nounwind sanitize_address uwtable }
 
-!llvm.asan.globals = !{!0}
 !llvm.module.flags = !{!2, !3}
 !llvm.ident = !{!4}
 
-!0 = !{[5 x i8]* @"??_C@_04JIHMPGLA@asdf?$AA@", !1, !"", i1 false, i1 false}
 !1 = !{!"t.cpp", i32 1, i32 31}
 !2 = !{i32 1, !"wchar_size", i32 2}
 !3 = !{i32 7, !"PIC Level", i32 2}
Index: llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
===
--- llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
+++ llvm/test/Instrumentation/AddressSanitizer/instrument_initializer_metadata.ll
@@ -2,17 +2,10 @@
 ; RUN: opt < %s -passes='asan-pipeline' -asan-mapping-scale=5 -S | FileCheck %s
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
 target triple = "x86_64-unknown-linux-

[PATCH] D127898: [clang][dataflow] Add API to separate analysis from diagnosis

2022-06-24 Thread Sam Estep via Phabricator via cfe-commits
samestep updated this revision to Diff 439878.
samestep added a comment.

- Merge branch 'main' into diagnose-api
- WIP


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127898

Files:
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -11,9 +11,10 @@
 #include "TestingSupport.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Analysis/FlowSensitive/SourceLocationsLattice.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
@@ -26,8 +27,7 @@
 using namespace dataflow;
 using namespace test;
 
-using ::testing::Pair;
-using ::testing::UnorderedElementsAre;
+using ::testing::ContainerEq;
 
 // FIXME: Move header definitions in separate file(s).
 static constexpr char CSDtdDefHeader[] = R"(
@@ -1180,13 +1180,6 @@
 } // namespace base
 )";
 
-/// Converts `L` to string.
-static std::string ConvertToString(const SourceLocationsLattice &L,
-   const ASTContext &Ctx) {
-  return L.getSourceLocations().empty() ? "safe"
-: "unsafe: " + DebugString(L, Ctx);
-}
-
 /// Replaces all occurrences of `Pattern` in `S` with `Replacement`.
 static void ReplaceAllOccurrences(std::string &S, const std::string &Pattern,
   const std::string &Replacement) {
@@ -1207,18 +1200,14 @@
 class UncheckedOptionalAccessTest
 : public ::testing::TestWithParam {
 protected:
-  template 
-  void ExpectLatticeChecksFor(std::string SourceCode,
-  LatticeChecksMatcher MatchesLatticeChecks) {
-ExpectLatticeChecksFor(SourceCode, ast_matchers::hasName("target"),
-   MatchesLatticeChecks);
+  void ExpectDiagnosticsFor(std::string SourceCode) {
+ExpectDiagnosticsFor(SourceCode, ast_matchers::hasName("target"));
   }
 
 private:
-  template 
-  void ExpectLatticeChecksFor(std::string SourceCode,
-  FuncDeclMatcher FuncMatcher,
-  LatticeChecksMatcher MatchesLatticeChecks) {
+  template 
+  void ExpectDiagnosticsFor(std::string SourceCode,
+FuncDeclMatcher FuncMatcher) {
 ReplaceAllOccurrences(SourceCode, "$ns", GetParam().NamespaceName);
 ReplaceAllOccurrences(SourceCode, "$optional", GetParam().TypeName);
 
@@ -1245,29 +1234,51 @@
 )");
 const tooling::FileContentMappings FileContents(Headers.begin(),
 Headers.end());
-llvm::Error Error = checkDataflow(
-SourceCode, FuncMatcher,
-[](ASTContext &Ctx, Environment &) {
-  return UncheckedOptionalAccessModel(
-  Ctx, UncheckedOptionalAccessModelOptions{
-   /*IgnoreSmartPointerDereference=*/true});
-},
-[&MatchesLatticeChecks](
-llvm::ArrayRef>>
-CheckToLatticeMap,
-ASTContext &Ctx) {
-  // FIXME: Consider using a matcher instead of translating
-  // `CheckToLatticeMap` to `CheckToStringifiedLatticeMap`.
-  std::vector>
-  CheckToStringifiedLatticeMap;
-  for (const auto &E : CheckToLatticeMap) {
-CheckToStringifiedLatticeMap.emplace_back(
-E.first, ConvertToString(E.second.Lattice, Ctx));
-  }
-  EXPECT_THAT(CheckToStringifiedLatticeMap, MatchesLatticeChecks);
-},
-{"-fsyntax-only", "-std=c++17", "-Wno-undefined-inline"}, FileContents);
+UncheckedOptionalAccessModelOptions Options{
+/*IgnoreSmartPointerDereference=*/true};
+llvm::Error Error =
+checkDataflowDiagnosis(
+SourceCode, FuncMatcher,
+[Options](ASTContext &Ctx, Environment &) {
+  return UncheckedOptionalAccessModel(Ctx, Options);
+},
+[Options](ASTContext &Ctx) {
+  UncheckedOptionalAccessDiagnosis Diagnosis(Ctx, Options);
+  return [Diagnosis = std::move(Diagnosis)](
+ const Stmt *Stmt,
+ const UncheckedOptionalAccessModel::Lattice &,
+ const Environment &Env) mutable {
+  

[PATCH] D128556: Make Objective-C++ match Objective-C's behavior on implicit ivar access when `self` is shadowed

2022-06-24 Thread Michael Wyman via Phabricator via cfe-commits
mwyman created this revision.
mwyman added a project: clang.
Herald added a project: All.
mwyman requested review of this revision.
Herald added a subscriber: cfe-commits.

When compiling Objective-C++, name lookup uses the C++ lookup behavior that 
skips the filtering of non-implicit-self references, and will use a shadowed 
name that matches the type. As a result implicit ivar access behavior differs 
between Objective-C and Objective-C++, which can impact local access but also 
block captures.

This addresses the issue #56193 
 as reported on Github.

Unfortunately it appears the behavior has differed for 11 years (since the 
original fix for ObjC was applied in 2011).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128556

Files:
  clang/lib/Sema/SemaLookup.cpp


Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -1313,6 +1313,9 @@
 R.setShadowed();
 continue;
   }
+} else if (NameKind == LookupObjCImplicitSelfParam &&
+   !isa(*I)) {
+  continue;
 } else {
   // We found something in this scope, we should not look at the
   // namespace scope


Index: clang/lib/Sema/SemaLookup.cpp
===
--- clang/lib/Sema/SemaLookup.cpp
+++ clang/lib/Sema/SemaLookup.cpp
@@ -1313,6 +1313,9 @@
 R.setShadowed();
 continue;
   }
+} else if (NameKind == LookupObjCImplicitSelfParam &&
+   !isa(*I)) {
+  continue;
 } else {
   // We found something in this scope, we should not look at the
   // namespace scope
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128554: [Driver][Minix] -r: imply -nostdlib like GCC

2022-06-24 Thread Brad Smith via Phabricator via cfe-commits
brad created this revision.
brad added a reviewer: MaskRay.
brad added a project: clang.
Herald added a subscriber: StephenFan.
Herald added a project: All.
brad requested review of this revision.

Similar to D116843 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128554

Files:
  clang/lib/Driver/ToolChains/Minix.cpp
  clang/test/Driver/minix.c


Index: clang/test/Driver/minix.c
===
--- /dev/null
+++ clang/test/Driver/minix.c
@@ -0,0 +1,6 @@
+// -r suppresses default -l and crt*.o like -nostdlib.
+// RUN: %clang -### %s --target=i386-unknown-minix -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
+// CHECK-RELOCATABLE: "-r"
+// CHECK-RELOCATABLE-NOT: "-l
+// CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
Index: clang/lib/Driver/ToolChains/Minix.cpp
===
--- clang/lib/Driver/ToolChains/Minix.cpp
+++ clang/lib/Driver/ToolChains/Minix.cpp
@@ -56,7 +56,8 @@
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
 
CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
 CmdArgs.push_back(
@@ -71,7 +72,8 @@
 
   getToolChain().addProfileRTLibs(Args, CmdArgs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+   options::OPT_r)) {
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
@@ -79,7 +81,8 @@
 }
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 CmdArgs.push_back("-lc");


Index: clang/test/Driver/minix.c
===
--- /dev/null
+++ clang/test/Driver/minix.c
@@ -0,0 +1,6 @@
+// -r suppresses default -l and crt*.o like -nostdlib.
+// RUN: %clang -### %s --target=i386-unknown-minix -r 2>&1 \
+// RUN:   | FileCheck %s --check-prefix=CHECK-RELOCATABLE
+// CHECK-RELOCATABLE: "-r"
+// CHECK-RELOCATABLE-NOT: "-l
+// CHECK-RELOCATABLE-NOT: /crt{{[^.]+}}.o
Index: clang/lib/Driver/ToolChains/Minix.cpp
===
--- clang/lib/Driver/ToolChains/Minix.cpp
+++ clang/lib/Driver/ToolChains/Minix.cpp
@@ -56,7 +56,8 @@
 assert(Output.isNothing() && "Invalid output.");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crt1.o")));
 CmdArgs.push_back(Args.MakeArgString(getToolChain().GetFilePath("crti.o")));
 CmdArgs.push_back(
@@ -71,7 +72,8 @@
 
   getToolChain().addProfileRTLibs(Args, CmdArgs);
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+   options::OPT_r)) {
 if (D.CCCIsCXX()) {
   if (getToolChain().ShouldLinkCXXStdlib(Args))
 getToolChain().AddCXXStdlibLibArgs(Args, CmdArgs);
@@ -79,7 +81,8 @@
 }
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
 if (Args.hasArg(options::OPT_pthread))
   CmdArgs.push_back("-lpthread");
 CmdArgs.push_back("-lc");
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D128357: [clang][dataflow] Store flow condition constraints in a single `FlowConditionConstraints` map.

2022-06-24 Thread Dmitri Gribenko via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfb88ea62602c: [clang][dataflow] Store flow condition 
constraints in a single… (authored by wyt, committed by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128357

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp

Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -66,19 +66,16 @@
 }
 
 AtomicBoolValue &DataflowAnalysisContext::makeFlowConditionToken() {
-  AtomicBoolValue &Token = createAtomicBoolValue();
-  FlowConditionRemainingConjuncts[&Token] = {};
-  FlowConditionFirstConjuncts[&Token] = &Token;
-  return Token;
+  return createAtomicBoolValue();
 }
 
 void DataflowAnalysisContext::addFlowConditionConstraint(
 AtomicBoolValue &Token, BoolValue &Constraint) {
-  FlowConditionRemainingConjuncts[&Token].insert(&getOrCreateDisjunctionValue(
-  Constraint, getOrCreateNegationValue(Token)));
-  FlowConditionFirstConjuncts[&Token] =
-  &getOrCreateDisjunctionValue(*FlowConditionFirstConjuncts[&Token],
-   getOrCreateNegationValue(Constraint));
+  auto Res = FlowConditionConstraints.try_emplace(&Token, &Constraint);
+  if (!Res.second) {
+Res.first->second =
+&getOrCreateConjunctionValue(*Res.first->second, Constraint);
+  }
 }
 
 AtomicBoolValue &
@@ -133,24 +130,30 @@
 
 void DataflowAnalysisContext::addTransitiveFlowConditionConstraints(
 AtomicBoolValue &Token, llvm::DenseSet &Constraints,
-llvm::DenseSet &VisitedTokens) const {
+llvm::DenseSet &VisitedTokens) {
   auto Res = VisitedTokens.insert(&Token);
   if (!Res.second)
 return;
 
-  auto FirstConjunctIT = FlowConditionFirstConjuncts.find(&Token);
-  if (FirstConjunctIT != FlowConditionFirstConjuncts.end())
-Constraints.insert(FirstConjunctIT->second);
-  auto RemainingConjunctsIT = FlowConditionRemainingConjuncts.find(&Token);
-  if (RemainingConjunctsIT != FlowConditionRemainingConjuncts.end())
-Constraints.insert(RemainingConjunctsIT->second.begin(),
-   RemainingConjunctsIT->second.end());
+  auto ConstraintsIT = FlowConditionConstraints.find(&Token);
+  if (ConstraintsIT == FlowConditionConstraints.end()) {
+Constraints.insert(&Token);
+  } else {
+// Bind flow condition token via `iff` to its set of constraints:
+// FC <=> (C1 ^ C2 ^ ...), where Ci are constraints
+Constraints.insert(&getOrCreateConjunctionValue(
+getOrCreateDisjunctionValue(
+Token, getOrCreateNegationValue(*ConstraintsIT->second)),
+getOrCreateDisjunctionValue(getOrCreateNegationValue(Token),
+*ConstraintsIT->second)));
+  }
 
   auto DepsIT = FlowConditionDeps.find(&Token);
   if (DepsIT != FlowConditionDeps.end()) {
-for (AtomicBoolValue *DepToken : DepsIT->second)
+for (AtomicBoolValue *DepToken : DepsIT->second) {
   addTransitiveFlowConditionConstraints(*DepToken, Constraints,
 VisitedTokens);
+}
   }
 }
 
Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -198,7 +198,7 @@
   /// calls.
   void addTransitiveFlowConditionConstraints(
   AtomicBoolValue &Token, llvm::DenseSet &Constraints,
-  llvm::DenseSet &VisitedTokens) const;
+  llvm::DenseSet &VisitedTokens);
 
   std::unique_ptr S;
 
@@ -232,21 +232,16 @@
   // defines the flow condition. Conceptually, each binding corresponds to an
   // "iff" of the form `FC <=> (C1 ^ C2 ^ ...)` where `FC` is a flow condition
   // token (an atomic boolean) and `Ci`s are the set of constraints in the flow
-  // flow condition clause. Internally, we do not record the formula directly as
-  // an "iff". Instead, a flow condition clause is encoded as conjuncts of the
-  // form `(FC v !C1 v !C2 v ...) ^ (C1 v !FC) ^ (C2 v !FC) ^ ...`. The first
-  // conjuct is stored in the `FlowConditionFirstConjuncts` map and the set of
-  // remaining conjuncts are stored in the `FlowConditionRemainingConjuncts`
-  // map, both keyed by the token of the flow condition.
+  // flow condition clause. The set of constraints (C1 ^ C2 ^ ...) are stored in
+  // the `FlowConditionConstraints` map, keyed by the token of the flow
+  // condition.
   //
   // Flow conditions depend on other flow conditions if they are created using
   // `forkFlowCondition` or `joinFlowCondition

[clang] fb88ea6 - [clang][dataflow] Store flow condition constraints in a single `FlowConditionConstraints` map.

2022-06-24 Thread Dmitri Gribenko via cfe-commits

Author: Wei Yi Tee
Date: 2022-06-24T21:52:16+02:00
New Revision: fb88ea62602c90f8f7c80560fd6a14f1c8c6d520

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

LOG: [clang][dataflow] Store flow condition constraints in a single 
`FlowConditionConstraints` map.

A flow condition is represented with an atomic boolean token, and it is bound 
to a set of constraints: `(FC <=> C1 ^ C2 ^ ...)`. \
This was internally represented as `(FC v !C1 v !C2 v ...) ^ (C1 v !FC) ^ (C2 v 
!FC) ^ ...` and tracked by 2 maps:
- `FlowConditionFirstConjunct` stores the first conjunct `(FC v !C1 v !C2 v 
...)`
- `FlowConditionRemainingConjuncts` stores the remaining conjuncts `(C1 v !FC) 
^ (C2 v !FC) ^ ...`

This patch simplifies the tracking of the constraints by using a single 
`FlowConditionConstraints` map which stores `(C1 ^ C2 ^ ...)`, eliminating the 
use of two maps.

Reviewed By: gribozavr2, sgatev, xazax.hun

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index e2820fcb55655..48d0eedc49dde 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -198,7 +198,7 @@ class DataflowAnalysisContext {
   /// calls.
   void addTransitiveFlowConditionConstraints(
   AtomicBoolValue &Token, llvm::DenseSet &Constraints,
-  llvm::DenseSet &VisitedTokens) const;
+  llvm::DenseSet &VisitedTokens);
 
   std::unique_ptr S;
 
@@ -232,21 +232,16 @@ class DataflowAnalysisContext {
   // defines the flow condition. Conceptually, each binding corresponds to an
   // "iff" of the form `FC <=> (C1 ^ C2 ^ ...)` where `FC` is a flow condition
   // token (an atomic boolean) and `Ci`s are the set of constraints in the flow
-  // flow condition clause. Internally, we do not record the formula directly 
as
-  // an "iff". Instead, a flow condition clause is encoded as conjuncts of the
-  // form `(FC v !C1 v !C2 v ...) ^ (C1 v !FC) ^ (C2 v !FC) ^ ...`. The first
-  // conjuct is stored in the `FlowConditionFirstConjuncts` map and the set of
-  // remaining conjuncts are stored in the `FlowConditionRemainingConjuncts`
-  // map, both keyed by the token of the flow condition.
+  // flow condition clause. The set of constraints (C1 ^ C2 ^ ...) are stored 
in
+  // the `FlowConditionConstraints` map, keyed by the token of the flow
+  // condition.
   //
   // Flow conditions depend on other flow conditions if they are created using
   // `forkFlowCondition` or `joinFlowConditions`. The graph of flow condition
   // dependencies is stored in the `FlowConditionDeps` map.
   llvm::DenseMap>
   FlowConditionDeps;
-  llvm::DenseMap FlowConditionFirstConjuncts;
-  llvm::DenseMap>
-  FlowConditionRemainingConjuncts;
+  llvm::DenseMap FlowConditionConstraints;
 };
 
 } // namespace dataflow

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index 81e37e6e6905a..ffd552b1fdc72 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -66,19 +66,16 @@ BoolValue 
&DataflowAnalysisContext::getOrCreateNegationValue(BoolValue &Val) {
 }
 
 AtomicBoolValue &DataflowAnalysisContext::makeFlowConditionToken() {
-  AtomicBoolValue &Token = createAtomicBoolValue();
-  FlowConditionRemainingConjuncts[&Token] = {};
-  FlowConditionFirstConjuncts[&Token] = &Token;
-  return Token;
+  return createAtomicBoolValue();
 }
 
 void DataflowAnalysisContext::addFlowConditionConstraint(
 AtomicBoolValue &Token, BoolValue &Constraint) {
-  FlowConditionRemainingConjuncts[&Token].insert(&getOrCreateDisjunctionValue(
-  Constraint, getOrCreateNegationValue(Token)));
-  FlowConditionFirstConjuncts[&Token] =
-  &getOrCreateDisjunctionValue(*FlowConditionFirstConjuncts[&Token],
-   getOrCreateNegationValue(Constraint));
+  auto Res = FlowConditionConstraints.try_emplace(&Token, &Constraint);
+  if (!Res.second) {
+Res.first->second =
+&getOrCreateConjunctionValue(*Res.first->second, Constraint);
+  }
 }
 
 AtomicBoolValue &
@@ -133,24 +130,30 @@ bool 
DataflowAnalysisContext::flowConditionIsTautology(AtomicBoolValue &Token) {
 
 void DataflowAnalysisContext::addTransitiveFlowConditionConstraints(
 AtomicBoolValue &Token, llvm::DenseSet &Constraints,
-llvm::DenseSet &VisitedTokens) 

[PATCH] D128411: [syntax] Introduce a BaseToken class.

2022-06-24 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/include/clang/Tooling/Syntax/TokenManager.h:33
+  /// The syntax-tree Leaf node holds a Key.
+  using Key = const void *;
+  /// Gets the text of token identified by the key.

ilya-biryukov wrote:
> I have just realized that we were discussing having opaque index as a key, 
> but there may also be tokens in the syntax tree that are not backed by the 
> `TokenBuffer`.
> Those can be synthesized, e.g. imagine someone wants to change `!(A && B)` to 
> `!A || !B`. They will need to synthesize at least the `||` token as it's not 
> in the source code. There is a way to do this now and it prohibits the use of 
> an index to the `TokenBuffer`.
> 
> So having the opaque pointer is probably ok for now, it should enable the 
> pseudo-parser to build syntax trees.
> We might want to add an operation to synthesize tokens into the 
> `TokenManager` at some point, but that's a discussion for another day.

> Those can be synthesized, e.g. imagine someone wants to change !(A && B) to 
> !A || !B. They will need to synthesize at least the || token as it's not in 
> the source code. There is a way to do this now and it prohibits the use of an 
> index to the TokenBuffer.

Yes, this is the exact reason why the Key is an opaque pointer, my first 
attempt was to use an index integer, but failed -- we already have some APIs 
doing this stuff (see `createLeaf` in BuildTree.h), the token can be a 
synthesized token backed up by the SourceManager...

Personally, I don't like the Key to be an opaque pointer as well, but 
considering the effort, it seems to be the best approach so far -- it enables 
the pseudoparser to build syntax trees with a different Token implementation 
while keeping the rest syntax stuff unchanged.

> We might want to add an operation to synthesize tokens into the TokenManager 
> at some point, but that's a discussion for another day.

Agree, we will encounter this in the future, but we're still far away from 
there (the layering mutation/syntax-tree is not perfect at the moment, mutation 
still depends on the TokenBuffer). And our initial application of syntax-tree 
in pseudoparser focuses on the read use-case, we should be fine now.



Comment at: clang/lib/Tooling/Syntax/Tree.cpp:271
+  // FIXME: can be fixed by adding an tok::Kind in the Leaf node.
+  // assert(cast(C).getToken()->kind() == 
L->getDelimiterTokenKind());
 }

ilya-biryukov wrote:
> Maybe add `TokenManager::getKind(Key)` right away and remove this FIXME.
> This should as simple as `cast(T)->Kind`, right? Or am I 
> missing some complications?
Yeah, the main problem is that we don't have the `TokenManager` object in the 
`syntax::Node`, we somehow need to pass it (e.g. a function parameter), which 
seems a heavy change. I'm not sure it is worth for this small assert.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128411

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


[PATCH] D128550: [OpenMP] Change OpenMP code generation for target region entries

2022-06-24 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 439853.
jhuber6 added a comment.

Update comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128550

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -791,6 +791,38 @@
   Entry->setAlignment(Align(1));
 }
 
+OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetKernel(
+const LocationDescription &Loc, Value *&Return, Value *Ident,
+Value *DeviceID, Value *NumTeams, Value *NumThreads, Value *HostPtr,
+ArrayRef KernelArgs, ArrayRef NoWaitArgs) {
+  if (!updateToLocation(Loc))
+return Loc.IP;
+
+  auto *KernelArgsPtr =
+  Builder.CreateAlloca(OpenMPIRBuilder::KernelArgs, nullptr, "kernel_args");
+  for (unsigned I = 0, Size = KernelArgs.size(); I != Size; ++I) {
+llvm::Value *Arg =
+Builder.CreateStructGEP(OpenMPIRBuilder::KernelArgs, KernelArgsPtr, I);
+Builder.CreateAlignedStore(
+KernelArgs[I], Arg,
+M.getDataLayout().getPrefTypeAlign(KernelArgs[I]->getType()));
+  }
+
+  bool HasNoWait = !NoWaitArgs.empty();
+  SmallVector OffloadingArgs{Ident,  DeviceID, NumTeams,
+  NumThreads, HostPtr,  KernelArgsPtr};
+  if (HasNoWait)
+OffloadingArgs.append(NoWaitArgs.begin(), NoWaitArgs.end());
+
+  Return = Builder.CreateCall(
+  HasNoWait
+  ? getOrCreateRuntimeFunction(M, OMPRTL___tgt_target_kernel_nowait)
+  : getOrCreateRuntimeFunction(M, OMPRTL___tgt_target_kernel),
+  OffloadingArgs);
+
+  return Builder.saveIP();
+}
+
 void OpenMPIRBuilder::emitCancelationCheckImpl(Value *CancelFlag,
omp::Directive CanceledDirective,
FinalizeCallbackTy ExitCB) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -88,6 +88,8 @@
 __OMP_STRUCT_TYPE(Ident, ident_t, Int32, Int32, Int32, Int32, Int8Ptr)
 __OMP_STRUCT_TYPE(OffloadEntry, __tgt_offload_entry, Int8Ptr, Int8Ptr, SizeTy,
   Int32, Int32)
+__OMP_STRUCT_TYPE(KernelArgs, __tgt_kernel_arguments, Int32, VoidPtrPtr,
+  VoidPtrPtr, Int64Ptr, Int64Ptr, VoidPtrPtr, VoidPtrPtr)
 __OMP_STRUCT_TYPE(AsyncInfo, __tgt_async_info, Int8Ptr)
 
 #undef __OMP_STRUCT_TYPE
@@ -412,6 +414,10 @@
 __OMP_RTL(__tgt_target_teams_nowait_mapper, false, Int32, IdentPtr, Int64,
   VoidPtr, Int32, VoidPtrPtr, VoidPtrPtr, Int64Ptr, Int64Ptr,
   VoidPtrPtr, VoidPtrPtr, Int32, Int32, Int32, VoidPtr, Int32, VoidPtr)
+__OMP_RTL(__tgt_target_kernel, false, Int32, IdentPtr, Int64, Int32, Int32,
+  VoidPtr, KernelArgsPtr)
+__OMP_RTL(__tgt_target_kernel_nowait, false, Int32, IdentPtr, Int64, Int32,
+  Int32, VoidPtr, KernelArgsPtr, Int32, VoidPtr, Int32, VoidPtr)
 __OMP_RTL(__tgt_register_requires, false, Void, Int64)
 __OMP_RTL(__tgt_target_data_begin_mapper, false, Void, IdentPtr, Int64, Int32, VoidPtrPtr,
   VoidPtrPtr, Int64Ptr, Int64Ptr, VoidPtrPtr, VoidPtrPtr)
@@ -937,6 +943,10 @@
 ParamAttrs())
 __OMP_RTL_ATTRS(__tgt_target_teams_nowait_mapper, ForkAttrs, AttributeSet(),
 ParamAttrs())
+__OMP_RTL_ATTRS(__tgt_target_kernel, ForkAttrs, AttributeSet(),
+ParamAttrs())
+__OMP_RTL_ATTRS(__tgt_target_kernel_nowait, ForkAttrs, AttributeSet(),
+ParamAttrs())
 __OMP_RTL_ATTRS(__tgt_register_requires, ForkAttrs, AttributeSet(),
 ParamAttrs())
 __OMP_RTL_ATTRS(__tgt_target_data_begin_mapper, ForkAttrs, AttributeSet(),
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -821,6 +821,23 @@
 omp::Directive CanceledDirective,
 FinalizeCallbackTy ExitCB = {});
 
+  /// Generate a target region entry call.
+  ///
+  /// \param Loc The location at which the request originated and is fulfilled.
+  /// \param Return Return value of the created function returned by reference.
+  /// \param DeviceID Identifier for the device via the 'device' clause.
+  /// \param NumTeams Numer of teams for the region via the 'num_teams' clause
+  /// or 0 if unspecified and -1 if there is no 'teams' clause.
+  /// \param NumThreads Number of threads via the 'thread_limit' cla

[PATCH] D128550: [OpenMP] Change OpenMP code generation for target region entries

2022-06-24 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 439851.
jhuber6 added a comment.

Simplify interface now that we use -1 to indicate a lack of teams.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128550

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -791,6 +791,38 @@
   Entry->setAlignment(Align(1));
 }
 
+OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetKernel(
+const LocationDescription &Loc, Value *&Return, Value *Ident,
+Value *DeviceID, Value *NumTeams, Value *NumThreads, Value *HostPtr,
+ArrayRef KernelArgs, ArrayRef NoWaitArgs) {
+  if (!updateToLocation(Loc))
+return Loc.IP;
+
+  auto *KernelArgsPtr =
+  Builder.CreateAlloca(OpenMPIRBuilder::KernelArgs, nullptr, "kernel_args");
+  for (unsigned I = 0, Size = KernelArgs.size(); I != Size; ++I) {
+llvm::Value *Arg =
+Builder.CreateStructGEP(OpenMPIRBuilder::KernelArgs, KernelArgsPtr, I);
+Builder.CreateAlignedStore(
+KernelArgs[I], Arg,
+M.getDataLayout().getPrefTypeAlign(KernelArgs[I]->getType()));
+  }
+
+  bool HasNoWait = !NoWaitArgs.empty();
+  SmallVector OffloadingArgs{Ident,  DeviceID, NumTeams,
+  NumThreads, HostPtr,  KernelArgsPtr};
+  if (HasNoWait)
+OffloadingArgs.append(NoWaitArgs.begin(), NoWaitArgs.end());
+
+  Return = Builder.CreateCall(
+  HasNoWait
+  ? getOrCreateRuntimeFunction(M, OMPRTL___tgt_target_kernel_nowait)
+  : getOrCreateRuntimeFunction(M, OMPRTL___tgt_target_kernel),
+  OffloadingArgs);
+
+  return Builder.saveIP();
+}
+
 void OpenMPIRBuilder::emitCancelationCheckImpl(Value *CancelFlag,
omp::Directive CanceledDirective,
FinalizeCallbackTy ExitCB) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -88,6 +88,8 @@
 __OMP_STRUCT_TYPE(Ident, ident_t, Int32, Int32, Int32, Int32, Int8Ptr)
 __OMP_STRUCT_TYPE(OffloadEntry, __tgt_offload_entry, Int8Ptr, Int8Ptr, SizeTy,
   Int32, Int32)
+__OMP_STRUCT_TYPE(KernelArgs, __tgt_kernel_arguments, Int32, VoidPtrPtr,
+  VoidPtrPtr, Int64Ptr, Int64Ptr, VoidPtrPtr, VoidPtrPtr)
 __OMP_STRUCT_TYPE(AsyncInfo, __tgt_async_info, Int8Ptr)
 
 #undef __OMP_STRUCT_TYPE
@@ -412,6 +414,10 @@
 __OMP_RTL(__tgt_target_teams_nowait_mapper, false, Int32, IdentPtr, Int64,
   VoidPtr, Int32, VoidPtrPtr, VoidPtrPtr, Int64Ptr, Int64Ptr,
   VoidPtrPtr, VoidPtrPtr, Int32, Int32, Int32, VoidPtr, Int32, VoidPtr)
+__OMP_RTL(__tgt_target_kernel, false, Int32, IdentPtr, Int64, Int32, Int32,
+  VoidPtr, KernelArgsPtr)
+__OMP_RTL(__tgt_target_kernel_nowait, false, Int32, IdentPtr, Int64, Int32,
+  Int32, VoidPtr, KernelArgsPtr, Int32, VoidPtr, Int32, VoidPtr)
 __OMP_RTL(__tgt_register_requires, false, Void, Int64)
 __OMP_RTL(__tgt_target_data_begin_mapper, false, Void, IdentPtr, Int64, Int32, VoidPtrPtr,
   VoidPtrPtr, Int64Ptr, Int64Ptr, VoidPtrPtr, VoidPtrPtr)
@@ -937,6 +943,10 @@
 ParamAttrs())
 __OMP_RTL_ATTRS(__tgt_target_teams_nowait_mapper, ForkAttrs, AttributeSet(),
 ParamAttrs())
+__OMP_RTL_ATTRS(__tgt_target_kernel, ForkAttrs, AttributeSet(),
+ParamAttrs())
+__OMP_RTL_ATTRS(__tgt_target_kernel_nowait, ForkAttrs, AttributeSet(),
+ParamAttrs())
 __OMP_RTL_ATTRS(__tgt_register_requires, ForkAttrs, AttributeSet(),
 ParamAttrs())
 __OMP_RTL_ATTRS(__tgt_target_data_begin_mapper, ForkAttrs, AttributeSet(),
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -821,6 +821,23 @@
 omp::Directive CanceledDirective,
 FinalizeCallbackTy ExitCB = {});
 
+  /// Generate a target region entry call.
+  ///
+  /// \param Loc The location at which the request originated and is fulfilled.
+  /// \param Return Return value of the created function returned by reference.
+  /// \param DeviceID Identifier for the device via the 'device' clause.
+  /// \param NumTeams Numer of teams for the region via the 'num_teams' clause
+  /// or 0 if unspecified and -1 if there is no 'teams' clause.
+  /// \param NumT

[PATCH] D128550: [OpenMP] Change OpenMP code generation for target region entries

2022-06-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/CodeGen/CGOpenMPRuntime.cpp:6720-6722
   } else if (DefaultNT == -1) {
-return nullptr;
+return llvm::ConstantInt::get(CGF.Int32Ty, -1);
   }

This code can be removed safely in this form


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128550

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


[PATCH] D128550: [OpenMP] Change OpenMP code generation for target region entries

2022-06-24 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added a comment.

This currently fails about 180 Clang tests. Of those about half can be 
automatically updated. I tried to manually update the other 90 but gave up, 
attempting to auto generate those tests as well would most likely result in 
over half a million new lined added to LLVM, the autogenerated tests are highly 
inefficient and will blow up a 100 line test into 40,000 lines of checks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128550

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


[PATCH] D127544: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGfaf5e0ec737a: Add no_sanitize('hwaddress') (and 
'memtag', but that's a no-op). (authored by hctim).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127544

Files:
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGen/Inputs/sanitizer-extra-source.cpp
  clang/test/CodeGen/Inputs/sanitizer-ignorelist-global.txt
  clang/test/CodeGen/Inputs/sanitizer-ignorelist-src.txt
  clang/test/CodeGen/hwasan-globals.cpp
  clang/test/CodeGen/memtag-globals.cpp
  compiler-rt/test/hwasan/TestCases/global-with-reduction.c
  compiler-rt/test/hwasan/TestCases/global.c

Index: compiler-rt/test/hwasan/TestCases/global.c
===
--- compiler-rt/test/hwasan/TestCases/global.c
+++ compiler-rt/test/hwasan/TestCases/global.c
@@ -14,9 +14,23 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
+#include 
+
+int a = 1;
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) int x = 1;
+#else // USE_NOSANITIZE
 int x = 1;
+#endif // USE_NOSANITIZE
+int b = 1;
 
 int atoi(const char *);
 
Index: compiler-rt/test/hwasan/TestCases/global-with-reduction.c
===
--- compiler-rt/test/hwasan/TestCases/global-with-reduction.c
+++ compiler-rt/test/hwasan/TestCases/global-with-reduction.c
@@ -14,20 +14,37 @@
 // RUN: %clang_hwasan -O2 %s -o %t
 // RUN: not %run %t 1 2>&1 | FileCheck --check-prefixes=CHECK,RSYM %s
 
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 0
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -O2 && %run %t 1
+// RUN: %clang_hwasan -DUSE_NOSANITIZE %s -o %t -fno-pic -O2 && %run %t 1
+
 // REQUIRES: pointer-tagging
 
-int x = 1;
+#include 
 
-int atoi(const char *);
+// GlobalOpt may replace the current GV with a new boolean-typed GV. Previously,
+// this resulted in the "nosanitize" getting dropped because while the data/code
+// references to the GV were updated, the old metadata references weren't.
+int* f() {
+#ifdef USE_NOSANITIZE
+__attribute__((no_sanitize("hwaddress"))) static int x = 1;
+#else // USE_NOSANITIZE
+  static int x = 1;
+#endif // USE_NOSANITIZE
+  if (x == 1) x = 0;
+  return &x;
+}
 
 int main(int argc, char **argv) {
   // CHECK: Cause: global-overflow
-  // RSYM: is located 0 bytes to the right of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RSYM: is located 0 bytes to the right of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // RNOSYM: is located to the right of a 4-byte global variable in
-  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
-  // LSYM: is located 4 bytes to the left of 4-byte global variable x {{.*}} in {{.*}}global.c.tmp
+  // RNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
+  // LSYM: is located 4 bytes to the left of 4-byte global variable f.x {{.*}} in {{.*}}global-with-reduction.c.tmp
   // LNOSYM: is located to the left of a 4-byte global variable in
-  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global.c.tmp+{{.*}})
+  // LNOSYM-NEXT: #0 0x{{.*}} ({{.*}}global-with-reduction.c.tmp+{{.*}})
   // CHECK-NOT: can not describe
-  (&x)[atoi(argv[1])] = 1;
+  f()[atoi(argv[1])] = 1;
 }
Index: clang/test/CodeGen/memtag-globals.cpp
===
--- /dev/null
+++ clang/test/CodeGen/memtag-globals.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \
+// RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \
+// RUN:   -fsanitize=memtag-globals -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefix=IGNORELIST
+
+int global;
+int __attribute__((no_sanitize("memtag"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) disable_instrumentation_global;
+int ignorelisted_global;
+
+void func() {
+  static int static_var = 0;
+  const char *literal = "Hello, world!";
+}
+
+// CHECK: @{{.*}}extra_global{{.*}} =
+// CHECK-NOT: no_sanitize_memtag
+// CHECK: @{{.*}}glo

[clang] faf5e0e - Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

2022-06-24 Thread Mitch Phillips via cfe-commits

Author: Mitch Phillips
Date: 2022-06-24T12:04:11-07:00
New Revision: faf5e0ec737a676088649d7c13cb50f3f91a703a

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

LOG: Add no_sanitize('hwaddress') (and 'memtag', but that's a no-op).

Currently, `__attribute__((no_sanitize('hwaddress')))` is not possible. Add 
this piece of plumbing, and now that we properly support copying attributes 
between an old and a new global variable, add a regression test for the 
GlobalOpt bug that previously lost the attribute.

Reviewed By: aaron.ballman

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

Added: 
clang/test/CodeGen/Inputs/sanitizer-extra-source.cpp
clang/test/CodeGen/Inputs/sanitizer-ignorelist-global.txt
clang/test/CodeGen/Inputs/sanitizer-ignorelist-src.txt
clang/test/CodeGen/hwasan-globals.cpp
clang/test/CodeGen/memtag-globals.cpp
compiler-rt/test/hwasan/TestCases/global-with-reduction.c

Modified: 
clang/lib/Sema/SemaDeclAttr.cpp
compiler-rt/test/hwasan/TestCases/global.c

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 2563a07b4034..73a4be54861b 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -7859,6 +7859,11 @@ static bool isGlobalVar(const Decl *D) {
   return false;
 }
 
+static bool isSanitizerAttributeAllowedOnGlobals(StringRef Sanitizer) {
+  return Sanitizer == "address" || Sanitizer == "hwaddress" ||
+ Sanitizer == "memtag";
+}
+
 static void handleNoSanitizeAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   if (!AL.checkAtLeastNumArgs(S, 1))
 return;
@@ -7876,7 +7881,7 @@ static void handleNoSanitizeAttr(Sema &S, Decl *D, const 
ParsedAttr &AL) {
 SanitizerMask() &&
 SanitizerName != "coverage")
   S.Diag(LiteralLoc, diag::warn_unknown_sanitizer_ignored) << 
SanitizerName;
-else if (isGlobalVar(D) && SanitizerName != "address")
+else if (isGlobalVar(D) && 
!isSanitizerAttributeAllowedOnGlobals(SanitizerName))
   S.Diag(D->getLocation(), diag::err_attribute_wrong_decl_type)
   << AL << ExpectedFunctionOrMethod;
 Sanitizers.push_back(SanitizerName);

diff  --git a/clang/test/CodeGen/Inputs/sanitizer-extra-source.cpp 
b/clang/test/CodeGen/Inputs/sanitizer-extra-source.cpp
new file mode 100644
index ..21371d534255
--- /dev/null
+++ b/clang/test/CodeGen/Inputs/sanitizer-extra-source.cpp
@@ -0,0 +1 @@
+int extra_global;

diff  --git a/clang/test/CodeGen/Inputs/sanitizer-ignorelist-global.txt 
b/clang/test/CodeGen/Inputs/sanitizer-ignorelist-global.txt
new file mode 100644
index ..40a1d07fb895
--- /dev/null
+++ b/clang/test/CodeGen/Inputs/sanitizer-ignorelist-global.txt
@@ -0,0 +1 @@
+global:*ignorelisted_global*

diff  --git a/clang/test/CodeGen/Inputs/sanitizer-ignorelist-src.txt 
b/clang/test/CodeGen/Inputs/sanitizer-ignorelist-src.txt
new file mode 100644
index ..67e50c852606
--- /dev/null
+++ b/clang/test/CodeGen/Inputs/sanitizer-ignorelist-src.txt
@@ -0,0 +1 @@
+src:*-globals.cpp

diff  --git a/clang/test/CodeGen/hwasan-globals.cpp 
b/clang/test/CodeGen/hwasan-globals.cpp
new file mode 100644
index ..7edf6e6b7e57
--- /dev/null
+++ b/clang/test/CodeGen/hwasan-globals.cpp
@@ -0,0 +1,57 @@
+// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-global.txt \
+// RUN:   -fsanitize=hwaddress -emit-llvm -o - %s | FileCheck %s
+
+// RUN: %clang_cc1 -include %S/Inputs/sanitizer-extra-source.cpp \
+// RUN:   -fsanitize-ignorelist=%S/Inputs/sanitizer-ignorelist-src.txt \
+// RUN:   -fsanitize=hwaddress -emit-llvm -o - %s | \
+// RUN:   FileCheck %s --check-prefix=IGNORELIST
+
+int global;
+int __attribute__((no_sanitize("hwaddress"))) attributed_global;
+int __attribute__((disable_sanitizer_instrumentation)) 
disable_instrumentation_global;
+int ignorelisted_global;
+
+void func() {
+  static int static_var = 0;
+  const char *literal = "Hello, world!";
+}
+
+// CHECK: @{{.*}}attributed_global{{.*}} ={{.*}} global {{.*}}, 
no_sanitize_hwaddress
+// CHECK: @{{.*}}disable_instrumentation_global{{.*}} ={{.*}} global {{.*}}, 
no_sanitize_hwaddress
+// CHECK: @{{.*}}ignorelisted_global{{.*}} ={{.*}} global {{.*}}, 
no_sanitize_hwaddress
+// CHECK: @{{.*}}extra_global{{.*}}.hwasan{{.*}} =
+// CHECK: @{{.*}}global{{.*}}.hwasan{{.*}} =
+// CHECK: @{{.*}}static_var{{.*}}.hwasan{{.*}} =
+// CHECK: @{{.*}}.hwasan{{.*}} = {{.*}} c"Hello, world!\00"
+
+// CHECK: !llvm.asan.globals = !{![[EXTRA_GLOBAL:[0-9]+]], ![[GLOBAL:[0-9]+]], 
![[ATTR_GLOBAL:[0-9]+]], ![[DISABLE_INSTR_GLOBAL:[0-9]+]], 
![[IGNORELISTED_GLOBAL:[0-9]+]], ![[STATIC_VAR:[0-9]+]], ![[LITERAL:[0-9]+]]}
+// CHECK: ![[EXTRA_GLOBAL]] = !{

[PATCH] D128550: [OpenMP] Change OpenMP code generation for target region entries

2022-06-24 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 created this revision.
jhuber6 added reviewers: ABataev, JonChesterfield, jdoerfert, tianshilei1992.
Herald added subscribers: guansong, hiraditya, yaxunl.
Herald added a project: All.
jhuber6 requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, sstefan1.
Herald added projects: clang, LLVM.

This patch changes the code we generate to enter a target region on the
device. This is in-line with the new definition in the runtime that was
added previously. Additionally we implement this in the OpenMPIRBuilder
so that this code can be shared with Flang in the future.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128550

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -791,6 +791,38 @@
   Entry->setAlignment(Align(1));
 }
 
+OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::emitTargetKernel(
+const LocationDescription &Loc, Value *&Return, Value *Ident,
+Value *DeviceID, Value *NumTeams, Value *NumThreads, Value *HostPtr,
+ArrayRef KernelArgs, ArrayRef NoWaitArgs) {
+  if (!updateToLocation(Loc))
+return Loc.IP;
+
+  auto *KernelArgsPtr =
+  Builder.CreateAlloca(OpenMPIRBuilder::KernelArgs, nullptr, "kernel_args");
+  for (unsigned I = 0, Size = KernelArgs.size(); I != Size; ++I) {
+llvm::Value *Arg =
+Builder.CreateStructGEP(OpenMPIRBuilder::KernelArgs, KernelArgsPtr, I);
+Builder.CreateAlignedStore(
+KernelArgs[I], Arg,
+M.getDataLayout().getPrefTypeAlign(KernelArgs[I]->getType()));
+  }
+
+  bool HasNoWait = !NoWaitArgs.empty();
+  SmallVector OffloadingArgs{Ident,  DeviceID, NumTeams,
+  NumThreads, HostPtr,  KernelArgsPtr};
+  if (HasNoWait)
+OffloadingArgs.append(NoWaitArgs.begin(), NoWaitArgs.end());
+
+  Return = Builder.CreateCall(
+  HasNoWait
+  ? getOrCreateRuntimeFunction(M, OMPRTL___tgt_target_kernel_nowait)
+  : getOrCreateRuntimeFunction(M, OMPRTL___tgt_target_kernel),
+  OffloadingArgs);
+
+  return Builder.saveIP();
+}
+
 void OpenMPIRBuilder::emitCancelationCheckImpl(Value *CancelFlag,
omp::Directive CanceledDirective,
FinalizeCallbackTy ExitCB) {
Index: llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
===
--- llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
+++ llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
@@ -88,6 +88,8 @@
 __OMP_STRUCT_TYPE(Ident, ident_t, Int32, Int32, Int32, Int32, Int8Ptr)
 __OMP_STRUCT_TYPE(OffloadEntry, __tgt_offload_entry, Int8Ptr, Int8Ptr, SizeTy,
   Int32, Int32)
+__OMP_STRUCT_TYPE(KernelArgs, __tgt_kernel_arguments, Int32, VoidPtrPtr,
+  VoidPtrPtr, Int64Ptr, Int64Ptr, VoidPtrPtr, VoidPtrPtr)
 __OMP_STRUCT_TYPE(AsyncInfo, __tgt_async_info, Int8Ptr)
 
 #undef __OMP_STRUCT_TYPE
@@ -412,6 +414,10 @@
 __OMP_RTL(__tgt_target_teams_nowait_mapper, false, Int32, IdentPtr, Int64,
   VoidPtr, Int32, VoidPtrPtr, VoidPtrPtr, Int64Ptr, Int64Ptr,
   VoidPtrPtr, VoidPtrPtr, Int32, Int32, Int32, VoidPtr, Int32, VoidPtr)
+__OMP_RTL(__tgt_target_kernel, false, Int32, IdentPtr, Int64, Int32, Int32,
+  VoidPtr, KernelArgsPtr)
+__OMP_RTL(__tgt_target_kernel_nowait, false, Int32, IdentPtr, Int64, Int32,
+  Int32, VoidPtr, KernelArgsPtr, Int32, VoidPtr, Int32, VoidPtr)
 __OMP_RTL(__tgt_register_requires, false, Void, Int64)
 __OMP_RTL(__tgt_target_data_begin_mapper, false, Void, IdentPtr, Int64, Int32, VoidPtrPtr,
   VoidPtrPtr, Int64Ptr, Int64Ptr, VoidPtrPtr, VoidPtrPtr)
@@ -937,6 +943,10 @@
 ParamAttrs())
 __OMP_RTL_ATTRS(__tgt_target_teams_nowait_mapper, ForkAttrs, AttributeSet(),
 ParamAttrs())
+__OMP_RTL_ATTRS(__tgt_target_kernel, ForkAttrs, AttributeSet(),
+ParamAttrs())
+__OMP_RTL_ATTRS(__tgt_target_kernel_nowait, ForkAttrs, AttributeSet(),
+ParamAttrs())
 __OMP_RTL_ATTRS(__tgt_register_requires, ForkAttrs, AttributeSet(),
 ParamAttrs())
 __OMP_RTL_ATTRS(__tgt_target_data_begin_mapper, ForkAttrs, AttributeSet(),
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -821,6 +821,23 @@
 omp::Directive CanceledDirective,
 FinalizeCallbackTy ExitCB = {});
 
+  /// Generate a target region entry call.
+  ///
+  /// \par

[PATCH] D128501: [CodeGen] Make uninitialized Lvalue bit-field stores poison compatible

2022-06-24 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Under this scheme, is it illegal to link together object files built with 
-ffine-grained-bitfield-accesses and object files built with 
-fno-fine-grained-bitfield-accesses?

Do we want to add a temporary option to control this, to make it easier for 
people to benchmark any performance differences?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128501

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


[PATCH] D128535: [analyzer] Improve loads from reinterpret-cast fields

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

No runtime diff. No crashes.
8 disappeared:

- 4 core.CallAndMessage (1st arg is uninitialized)
- 2 alpha.deadcode.UnreachableCode (sinked before reaching it)
- 2 core.UndefinedBinaryOperatorResult

2 new reports:

- 1 core.UndefinedBinaryOperatorResult
- 1 alpha.security.ArrayBound

15k+ reports preserved.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128535

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


[PATCH] D128157: [clang-tidy] cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro

2022-06-24 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood requested changes to this revision.
LegalizeAdulthood added a comment.
This revision now requires changes to proceed.

I get a test failure when I run with your change:

-- Testing: 972 tests, 12 workers --
FAIL: Clang Tools :: clang-apply-replacements/basic.cpp (680 of 972)
 TEST 'Clang Tools :: 
clang-apply-replacements/basic.cpp' FAILED 
Script:
--
: 'RUN: at line 1';   mkdir -p 
D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic
: 'RUN: at line 2';   grep -Ev "// *[A-Z-]+:" 
D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h
 > 
D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/basic.h
: 'RUN: at line 3';   sed 
"s#\$(path)#D:/legalize/llvm/llvm-project/build/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/basic#"
 
D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/file1.yaml
 > 
D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/file1.yaml
: 'RUN: at line 4';   sed 
"s#\$(path)#D:/legalize/llvm/llvm-project/build/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/basic#"
 
D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/file2.yaml
 > 
D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/file2.yaml
: 'RUN: at line 5';   clang-apply-replacements 
D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic
: 'RUN: at line 6';   FileCheck 
-input-file=D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/basic.h
 
D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h
: 'RUN: at line 9';   ls -1 
D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic
 | FileCheck 
D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements\basic.cpp
 --check-prefix=YAML
: 'RUN: at line 12';   grep -Ev "// *[A-Z-]+:" 
D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h
 > 
D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/basic.h
: 'RUN: at line 13';   clang-apply-replacements -remove-change-desc-files 
D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic
: 'RUN: at line 14';   ls -1 
D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic
 | FileCheck 
D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements\basic.cpp
 --check-prefix=NO_YAML
--
Exit Code: 1
  
Command Output (stdout):
--
$ ":" "RUN: at line 1"
$ "mkdir" "-p" 
"D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic"
$ ":" "RUN: at line 2"
$ "grep" "-Ev" "// *[A-Z-]+:" 
"D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h"
$ ":" "RUN: at line 3"
$ "sed" 
"s#\$(path)#D:/legalize/llvm/llvm-project/build/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/basic#"
 
"D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/file1.yaml"
$ ":" "RUN: at line 4"
$ "sed" 
"s#\$(path)#D:/legalize/llvm/llvm-project/build/tools/clang/tools/extra/test/clang-apply-replacements/Output/Inputs/basic#"
 
"D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/file2.yaml"
$ ":" "RUN: at line 5"
$ "clang-apply-replacements" 
"D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic"
$ ":" "RUN: at line 6"
$ "FileCheck" 
"-input-file=D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic/basic.h"
 
"D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h"
$ ":" "RUN: at line 9"
$ "ls" "-1" 
"D:\legalize\llvm\llvm-project\build\tools\clang\tools\extra\test\clang-apply-replacements\Output/Inputs/basic"
$ "FileCheck" 
"D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements\basic.cpp"
 "--check-prefix=YAML"
$ ":" "RUN: at line 12"
$ "grep" "-Ev" "// *[A-Z-]+:" 
"D:\legalize\llvm\llvm-project\clang-tools-extra\test\clang-apply-replacements/Inputs/basic/basic.h"
$ ":" "RUN: at line 13"
$ "clang-apply-replacements" "-remove-change-desc-files" 
"D:\legalize\llvm\llvm-project\b

[PATCH] D128436: [OpenCL] Remove fast_ half geometric builtins

2022-06-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128436

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


[PATCH] D128512: [Driver][test] Add libclang_rt.profile{{.*}}.a tests for OpenBSD.

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



Comment at: clang/test/Driver/coverage-ld.c:43
+// RUN:   | FileCheck --check-prefix=CHECK-OPENBSD-X86-64 %s
+//
+// CHECK-OPENBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"

Don't add `//\n` by cargo cult. It's not a recommended style (Having blank 
lines helps `{` `}` in Vim like editors)



Comment at: clang/test/Driver/coverage-ld.c:45
+// CHECK-OPENBSD-X86-64: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-OPENBSD-X86-64: 
"{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}openbsd{{/|}}libclang_rt.profile-x86_64.a"
+//

Note: the new recommended libclang_rt* hierarchy is 
`LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on`. This matches 
LLVM_ENABLE_RUNTIMES='compiler-rt;libcxx;libcxxabi;libunwind'.

OpenBSD hasn't switched, though.

With the new hierarchy, the location may look like: 
`lib/x86_64-unknown-openbsd/libclang_rt.profile.a`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128512

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


[PATCH] D128434: [OpenCL] Remove half scalar vload/vstore builtins

2022-06-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM! Thanks


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128434

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


[PATCH] D128449: [clang] Introduce -Warray-parameter

2022-06-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/lib/Sema/SemaDecl.cpp:3220
+
+  // `type[]` is equivalent to `type *` and `type[*]`
+  if (NoSizeInfo(Old) && NoSizeInfo(New))





Comment at: clang/lib/Sema/SemaDecl.cpp:3224
+
+  // Don't try to compare VLA sizes, unless one of them has the star modifier
+  if (Old->isVariableArrayType() && New->isVariableArrayType()) {





Comment at: clang/lib/Sema/SemaDecl.cpp:3234
+
+  // Only compare size, ignore Size modifiers and CVR
+  if (Old->isConstantArrayType() && New->isConstantArrayType())





Comment at: clang/lib/Sema/SemaDecl.cpp:3274-3278
+  S.Diag(NewParam->getLocation(), diag::warn_inconsistent_array_form)
+  << NewParam->getName()
+  << NewParamOT->getCanonicalTypeInternal().getAsString();
+  S.Diag(OldParam->getLocation(), diag::note_previous_declaration_as)
+  << OldParamOT->getCanonicalTypeInternal().getAsString();

The diagnostics engine knows how to format `NamedDecl` objects as well as 
types. Can you do this instead and still get reasonable diagnostics?



Comment at: clang/test/Sema/array-parameter.c:2
+// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -Warray-parameter 
-verify %s
+
+void f0(int a[]);

aaron.ballman wrote:
> I'd like to see some additional test cases:
> ```
> void func(int *p);
> void func(int a[2]); // Diagnose this one, I presume?
> void func(int a[]); // But also diagnose this one as well, yes?
> void func(int a[2]) {} // Do we then diagnose this as well, or is this 
> matching a previous declaration and thus fine?
> 
> void other(int n, int m, int a[n]);
> void other(int n, int m, int a[m]); // Hopefully we diagnose this set!
> 
> void another(int n, int array[n]);
> void another(int n, int array[*]); // I *think* this should be warned, but 
> I'm still a bit on the fence about it
> ```
> 
> Also, if this is expected to work in C++ as well, we should probably have 
> cases like:
> ```
> template 
> void func(int i[10]);
> 
> template 
> void func(int i[N]); // Should we diagnose this before instantiation or wait 
> until we see the instantiation and only diagnose if differs?
> 
> static constexpr int Extent = 10;
> void other(int i[10]);
> void other(int i[Extent]); // Should not be diagnosed
> ```
Do you plan to add the C++ tests?


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

https://reviews.llvm.org/D128449

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


[PATCH] D127579: [clang][WIP] add option to keep types of ptr args for non-kernel functions in metadata

2022-06-24 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added a comment.

In D127579#3598308 , @nikic wrote:

> In D127579#3598306 , @Anastasia 
> wrote:
>
>> In D127579#3595461 , @nikic wrote:
>>
>>> In D127579#3588626 , @Anastasia 
>>> wrote:
>>>
 In D127579#3586092 , @nikic 
 wrote:

> @Anastasia Thanks, that does sound like a legitimate reason to include 
> the information. I want to double check though, does linking the modules 
> actually fail if the functions have signatures that differ only by 
> pointer types? At least for normal LLVM IR this would work fine, and 
> would just result in the insertion of a bitcast during linking (and then 
> typically the bitcast would get shifted from the called function to the 
> call arguments later).

 @nikic If I use `spirv-link` with two modules that have mismatching 
 pointee type in a function parameter I get an error:

   error: 0: Type mismatch on symbol "foo" between imported 
 variable/function %6 and exported variable/function %17. 

 The way I understand a bitcast instruction in SPIR-V (`OpBitcast` in 
 https://www.khronos.org/registry/SPIR-V/specs/unified1/SPIRV.html#_conversion_instructions)
  is that it can only apply to pointer types which are distinct from 
 function types. Note that I believe that function pointers are illegal, at 
 least we disallow them in OpenCL.
>>>
>>> Okay ... can we maybe turn this around then? Always emit function 
>>> parameters as `i8*` and bitcast them as needed, even if it is possible to 
>>> guess a better type based on the definition? (Let's ignore the image type 
>>> case here, which seems to have different requirements from the rest.)
>>
>> So where would bitcasts be emitted to reconstruct the function prototypes 
>> correctly?
>
> The bitcasts would be in the definition only, when the pointer arguments 
> actually get used in a typed manner. The prototype would always include `i8*` 
> arguments only.

Ok, so does it mean that all pointer parameters in function definitions 
compiled for SPIR-V targets in clang would just be cast to the typed pointer? 
Then we only have untyped pointers in the declarations of functions? Perhaps I 
am missing something but would it not just be easier to keep the pointer types 
completely as it used to be, since it is going to be present nearly everywhere 
apart from declarations?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127579

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


[PATCH] D124447: [clang-tidy] Add infrastructure support for running on project-level information

2022-06-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In general, I think this is looking pretty close to good. Whether clang-tidy 
should get this functionality in this form or not is a bit less clear to me. 
*I* think it's helpful functionality and the current approach is reasonable, 
but I think it might be worthwhile to have a community RFC to see if others 
agree. CC @alexfh in case he wants to make a code owner decision instead.




Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:321-324
+if (MultipassPhase == MultipassProjectPhase::Collect)
+  // Allow the checks to write their data at the end of execution.
+  for (auto &Check : Checks)
+Check->runPostCollect();

I'd add the braces for readability despite them not being strictly required.



Comment at: clang-tools-extra/clang-tidy/ClangTidy.cpp:347-348
+  ClangTidyCheckFactories &CheckFactories) {
+  CheckVec Checks = CheckFactories.createChecks(&Context);
+  return Checks;
+}





Comment at: clang-tools-extra/clang-tidy/ClangTidyCheck.cpp:54
+  case MultipassProjectPhase::Compact:
+llvm_unreachable("AST Matchers should not have run in compact mode.");
+  }

I'm on the fence about whether this should be an unreachable or an assert. This 
seems like it's an assertion situation (if you reach that case, the programmer 
made a mistake; it's not that you can never reach this case).



Comment at: clang-tools-extra/clang-tidy/ClangTidyCheck.h:118-119
+
+  /// Checks that performed ``collect`` should write their data to the output 
to
+  /// the file in here.
+  virtual void postCollect(StringRef OutFile) {}





Comment at: clang-tools-extra/clang-tidy/ClangTidyCheck.h:122
+
+  /// Execute the ``postCollect()`` function to the right, automatically
+  /// generated filename.

I'm not certain what "to the right" means in this context, so some extra 
clarification here would be reasonable. I think it's saying that it's a post 
order traversal?



Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:242-243
+  MultipassProjectPhase Phase = getGlobalOptions().MultipassPhase;
+  if (Phase == MultipassProjectPhase::Collect)
+llvm_unreachable("Invalid phase 'Collect' for accessing compacted data");
+

I think this would be expressed better via an `assert`.



Comment at: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:246
+  auto InsertResult = CompactedDataPaths.try_emplace(CheckName, "");
+  std::string &FilePath = InsertResult.first->second;
+  if (!InsertResult.second)

Why is this a reference?



Comment at: clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:552-553
+}
+if (!llvm::sys::fs::is_directory(MultipassDir))
+  llvm::sys::fs::create_directory(MultipassDir);
+  }

This looks like a TOCTOU issue; `create_directory()` takes an argument for 
whether you should ignore existing or not, that should suffice here, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124447

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


[PATCH] D119296: KCFI sanitizer

2022-06-24 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen planned changes to this revision.
samitolvanen added inline comments.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:6694
 
-  if (isExternallyVisible(T->getLinkage())) {
+  if (isExternallyVisible(T->getLinkage()) || !OnlyExternal) {
 std::string OutName;

pcc wrote:
> It would be better to have a separate function for computing the KCFI type 
> ids than to try and reuse this one, since you don't need the MDStrings (i.e. 
> unnecessary string uniquing) in your new caller. It also isn't appropriate to 
> pass MetadataIdMap in your new caller because you'll end up with inconsistent 
> values added to MetadataIdMap if we end up calling the other caller (e.g. if 
> both CFI and KCFI are enabled), but that's moot if you avoid it.
The code in SanitizerArgs.cpp doesn't allow both CFI and KCFI to be enabled at 
the same time, but you're right, it's probably better to just split this into a 
separate function for KCFI. I'll do that in the next version.



Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:2453
+  // additional machine instructions being emitted between the check and
+  // the call. This means we don't have to worry about expanding BLR_BTI
+  // and TCRETURNri* pseudos.

pcc wrote:
> For PAuth ABI the motivation for avoiding the gap between check and call was 
> around avoiding spilling the verified pointer, is this not possible with KCFI?
I don't believe that's a concern here. We might emit instructions for setting 
up call arguments between the check and the call, but nothing should spill the 
pointer or change the target register anymore. The main reason to avoid 
bundling the check and the call is to avoid further complications with 
expanding the remaining pseudo instructions.



Comment at: llvm/lib/Target/X86/X86AsmPrinter.cpp:119
+  MCSymbol *FnSym = OutContext.getOrCreateSymbol("__cfi_" + MF.getName());
+  // Use the same linkage as the parent function.
+  emitLinkage(&MF.getFunction(), FnSym);

pcc wrote:
> If this is just about satisfying objtool do these symbols need to be exported 
> or can they just be STB_LOCAL?
They don't have to be exported, but we ran into some objtool confusion when the 
parent function was weak, so it's easier to just use the same linkage for the 
preamble symbol.



Comment at: llvm/lib/Target/X86/X86ISelLowering.h:83
+KCFI_NT_CALL,
+KCFI_TC_RETURN,
+

pcc wrote:
> samitolvanen wrote:
> > joaomoreira wrote:
> > > samitolvanen wrote:
> > > > joaomoreira wrote:
> > > > > I did not revise the entire patch yet. With this said, IMHO, this 
> > > > > looks like an overcomplication of a simple problem. Is there a reason 
> > > > > why you really need specific KCFI_ nodes instead of only embedding 
> > > > > the hash information into an attribute at the Machine Instruction? 
> > > > > Then, if hash == 0, it just means it is a call that doesn't need 
> > > > > instrumentation.
> > > > > 
> > > > > This latter approach will require less code and should be easier to 
> > > > > maintain compatible with other CFI approaches. If the reason is 
> > > > > because you don't want to have a useless attribute for non-call 
> > > > > instructions, then you could possibly have a map where you bind the 
> > > > > call instruction with a respective hash.
> > > > > 
> > > > > Unless there is a strong reason for these, I would much better prefer 
> > > > > the slim approach suggested. Either way, if there is a reason for 
> > > > > this, I would also suggest that you at least don't name these as 
> > > > > "KCFI_something", as in the future others might want to reuse the 
> > > > > same structure for other CFI approaches.
> > > > > Is there a reason why you really need specific KCFI_ nodes instead of 
> > > > > only embedding the hash information into an attribute at the Machine 
> > > > > Instruction?
> > > > 
> > > > This implementation is similar to `CALL_RVMARKER`, `CALL_BTI` and 
> > > > basically all other pseudo call instructions in LLVM. Is adding an 
> > > > attribute to `MachineInstr` the preferred approach instead?
> > > > 
> > > > > I would also suggest that you at least don't name these as 
> > > > > "KCFI_something", as in the future others might want to reuse the 
> > > > > same structure for other CFI approaches.
> > > > 
> > > > Always happy to hear suggestions for alternative naming. Did you have 
> > > > something in mind?
> > > > This implementation is similar to `CALL_RVMARKER`, `CALL_BTI` and 
> > > > basically all other pseudo call instructions in LLVM. Is adding an 
> > > > attribute to `MachineInstr` the preferred approach instead?
> > > 
> > > My understanding is that if, every time a new mitigation or optimization 
> > > comes in, you create a new opcode for it, it will eventually bloat to 
> > > non-feasibility.
> > > 
> > > Imagine you have some mitigation like [[ 
> > > https://www.cs.columbia.

[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-06-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:201
+  const FieldDecl *FD = nullptr;
+  size_t Sz = -1;
+  VarDecl *VD = nullptr;

What is Sz here? Better to give a better name and add a description for the 
struct and all fields



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1143
+break;
+  Sz--;
+}

Is it possible to have an overflow here?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1148
+for (const auto &IFD : I->ImplicitDefaultFirstprivateFDs)
+  if (IFD.FD == FD && IFD.Sz == Sz)
+return IFD.VD;

What if Sz == -1?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:1176
+  }
+  Sz--;
+}

What about overflow here?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:17480
 DeclRefExpr *Ref = nullptr;
-if (!VD && !CurContext->isDependentContext())
-  Ref = buildCapture(*this, D, SimpleRefExpr, /*WithInit=*/false);
-DSAStack->addDSA(D, RefExpr->IgnoreParens(), OMPC_private, Ref);
+if (!VD && !CurContext->isDependentContext()) {
+  auto *FD = dyn_cast(D);

A check here not for curcontext dependent but for FD being dependent?



Comment at: clang/lib/Sema/SemaOpenMP.cpp:17759
 DeclRefExpr *Ref = nullptr;
 if (!VD && !CurContext->isDependentContext()) {
   if (TopDVar.CKind == OMPC_lastprivate) {

Adjust this check for dependent context with non-dependent FD?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-06-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:11071-11073
+  if (!getDerived().AlwaysRebuild() && !getSema().getLangOpts().OpenMP &&
+  Base.get() == E->getBase() && QualifierLoc == E->getQualifierLoc() &&
+  Member == E->getMemberDecl() && FoundDecl == E->getFoundDecl() &&

jyu2 wrote:
> ABataev wrote:
> > jyu2 wrote:
> > > ABataev wrote:
> > > > jyu2 wrote:
> > > > > ABataev wrote:
> > > > > > Why do we need this check here?
> > > > > Without, the field is not getting rebuild during the template 
> > > > > instantiation.  That cause the field is not getting captured and 
> > > > > implicit firstprivate clause is not getting generate.  The test  is 
> > > > > added in default_firstprivate_ast_print.cpp
> > > > > where I add check for it on line 58:
> > > > > // DUMP-NEXT:  -OMPFirstprivateClause
> > > > > // DUMP-NEXT:-DeclRefExpr {{.*}} 'targetDev'
> > > > This should work without changes. Do we need clause in the template 
> > > > function?
> > > Do you mean, we don't need generate clause for instantiation's template 
> > > function?
> > > 
> > > apply<32>
> > > without this change the dump like:
> > > 
> > > ```
> > > | | `-CXXMethodDecl 0x1617ab8  line:38:8 imported 
> > > used apply 'void ()'
> > > | |   |-TemplateArgument integral 32
> > > | |   `-CompoundStmt 0x161c3a0 
> > > | | `-OMPParallelDirective 0x161c350 
> > > | |   |-OMPDefaultClause 0x161bf30 
> > > | |   `-CapturedStmt 0x161c310 
> > > 
> > > With this change
> > > | | `-CXXMethodDecl 0x110cab8  line:38:8 imported 
> > > used apply 'void ()'
> > > | |   |-TemplateArgument integral 32
> > > | |   `-CompoundStmt 0x860 
> > > | | `-OMPParallelDirective 0x808 
> > > | |   |-OMPDefaultClause 0x1110f30 
> > > | |   |-OMPFirstprivateClause 0x7c8 <> 
> > > | |   | `-DeclRefExpr 0x790  'int' lvalue 
> > > OMPCapturedExpr 0x320 'targetDev' 'int &'
> > > | |   `-CapturedStmt 0x590 
> > > ```
> > > 
> > It should work without this change correctly. If not, need to adjust sema 
> > analysis for such templated functions/fields.
> Okay, I remove that change.  Will deal that later.  
> It seems I need to set AlwaysRebuild to true.  But I don't know how that 
> works at this moment.  Will submit other patch for this.
> 
> Thanks.
> 
No, need to tweak the function that builds implicit clauses to build such 
clauses for non-templated decls, even in the template context


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-06-24 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/Sema/TreeTransform.h:11071-11073
+  if (!getDerived().AlwaysRebuild() && !getSema().getLangOpts().OpenMP &&
+  Base.get() == E->getBase() && QualifierLoc == E->getQualifierLoc() &&
+  Member == E->getMemberDecl() && FoundDecl == E->getFoundDecl() &&

ABataev wrote:
> jyu2 wrote:
> > ABataev wrote:
> > > jyu2 wrote:
> > > > ABataev wrote:
> > > > > Why do we need this check here?
> > > > Without, the field is not getting rebuild during the template 
> > > > instantiation.  That cause the field is not getting captured and 
> > > > implicit firstprivate clause is not getting generate.  The test  is 
> > > > added in default_firstprivate_ast_print.cpp
> > > > where I add check for it on line 58:
> > > > // DUMP-NEXT:  -OMPFirstprivateClause
> > > > // DUMP-NEXT:-DeclRefExpr {{.*}} 'targetDev'
> > > This should work without changes. Do we need clause in the template 
> > > function?
> > Do you mean, we don't need generate clause for instantiation's template 
> > function?
> > 
> > apply<32>
> > without this change the dump like:
> > 
> > ```
> > | | `-CXXMethodDecl 0x1617ab8  line:38:8 imported 
> > used apply 'void ()'
> > | |   |-TemplateArgument integral 32
> > | |   `-CompoundStmt 0x161c3a0 
> > | | `-OMPParallelDirective 0x161c350 
> > | |   |-OMPDefaultClause 0x161bf30 
> > | |   `-CapturedStmt 0x161c310 
> > 
> > With this change
> > | | `-CXXMethodDecl 0x110cab8  line:38:8 imported 
> > used apply 'void ()'
> > | |   |-TemplateArgument integral 32
> > | |   `-CompoundStmt 0x860 
> > | | `-OMPParallelDirective 0x808 
> > | |   |-OMPDefaultClause 0x1110f30 
> > | |   |-OMPFirstprivateClause 0x7c8 <> 
> > | |   | `-DeclRefExpr 0x790  'int' lvalue 
> > OMPCapturedExpr 0x320 'targetDev' 'int &'
> > | |   `-CapturedStmt 0x590 
> > ```
> > 
> It should work without this change correctly. If not, need to adjust sema 
> analysis for such templated functions/fields.
Okay, I remove that change.  Will deal that later.  
It seems I need to set AlwaysRebuild to true.  But I don't know how that works 
at this moment.  Will submit other patch for this.

Thanks.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

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


[PATCH] D127803: Generate the capture for field when the field is used in openmp region with implicit default in the member function.

2022-06-24 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 updated this revision to Diff 439812.
jyu2 added a comment.

Remove change in TreeTransform.h.  Will deal that in other patch.  Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127803

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/default_firstprivate_ast_print.cpp
  clang/test/OpenMP/default_private_ast_print.cpp

Index: clang/test/OpenMP/default_private_ast_print.cpp
===
--- clang/test/OpenMP/default_private_ast_print.cpp
+++ clang/test/OpenMP/default_private_ast_print.cpp
@@ -96,4 +96,57 @@
   // DUMP-NEXT:  -DeclRefExpr {{.*}} 'a'
   // DUMP-NEXT:  -DeclRefExpr {{.*}} 'yy'
 }
+
+void zoo(int);
+struct A {
+  int z;
+  int f;
+  A();
+  ~A();
+  void foo() {
+#pragma omp parallel private(z) default(private)
+{
+  z++;
+  f++;
+  zoo(z + f);
+  f++;
+}
+  }
+  // PRINT:#pragma omp parallel private(this->z) default(private)
+  // DUMP: -OMPParallelDirective
+  // DUMP-NEXT:  -OMPPrivateClause
+  // DUMP-NEXT:-DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT:  -OMPDefaultClause
+  // DUMP-NEXT:  -OMPPrivateClause
+  // DUMP-NEXT:-DeclRefExpr {{.*}} 'f'
+  // DUMP: -CXXThisExpr {{.*}} 'A *' implicit this
+  void bar() {
+#pragma omp parallel private(z) default(private)
+{
+#pragma omp parallel private(z) default(private)
+  {
+z++;
+f++;
+zoo(z + f);
+f++;
+  }
+}
+  }
+  // PRINT:#pragma omp parallel private(this->z) default(private)
+  // PRINT:  #pragma omp parallel private(this->z) default(private)
+  // DUMP: -OMPParallelDirective
+  // DUMP-NEXT:  -OMPPrivateClause
+  // DUMP-NEXT:-DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT:  -OMPDefaultClause
+  // DUMP:   -OMPParallelDirective
+  // DUMP-NEXT:-OMPPrivateClause
+  // DUMP-NEXT:   -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT:-OMPDefaultClause
+  // DUMP-NEXT:-OMPPrivateClause {{.*}} 
+  // DUMP-NEXT:   -DeclRefExpr {{.*}} 'f'
+  // DUMP: -CXXThisExpr
+  // DUMP: -MemberExpr
+  // DUMP-NEXT:   -CXXThisExpr
+  // DUMP: -CXXThisExpr
+};
 #endif // HEADER
Index: clang/test/OpenMP/default_firstprivate_ast_print.cpp
===
--- clang/test/OpenMP/default_firstprivate_ast_print.cpp
+++ clang/test/OpenMP/default_firstprivate_ast_print.cpp
@@ -45,7 +45,8 @@
 // PRINT-NEXT:  this->targetDev++;
 // CHECK-NEXT: }
 // DUMP: -OMPParallelDirective
-// DUMP->NEXT: -OMPDefaultClause
+// DUMP-NEXT: -OMPDefaultClause
+// DUMP-NOT:   -OMPFirstprivateClause
   }
   // PRINT: template<> void apply<32U>()
   // PRINT: #pragma omp parallel default(firstprivate)
@@ -99,4 +100,60 @@
   // DUMP-NEXT: -DeclRefExpr {{.*}} 'yy'
   // DUMP-NEXT: -DeclRefExpr {{.*}} 'y'
 }
+void zoo(int);
+struct A {
+  int z;
+  int f;
+  A();
+  ~A();
+  void foo() {
+#pragma omp parallel firstprivate(z) default(firstprivate)
+{
+  z++;
+  f++;
+  zoo(z + f);
+  f++;
+}
+  }
+  // PRINT:  #pragma omp parallel firstprivate(this->z) default(firstprivate)
+  // DUMP:   -OMPParallelDirective
+  // DUMP-NEXT: -OMPFirstprivateClause
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT: -OMPDefaultClause
+  // DUMP-NEXT: -OMPFirstprivateClause {{.*}} 
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'
+  // DUMP:  -CXXThisExpr {{.*}} 'A *' implicit this
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'f'
+  void bar() {
+#pragma omp parallel firstprivate(z) default(firstprivate)
+{
+#pragma omp parallel private(z) default(firstprivate)
+  {
+z++;
+f++;
+zoo(z + f);
+f++;
+  }
+}
+  }
+  // PRINT:  #pragma omp parallel firstprivate(this->z) default(firstprivate)
+  // PRINT:#pragma omp parallel private(this->z) default(firstprivate)
+  // DUMP: -OMPParallelDirective
+  // DUMP-NEXT: -OMPFirstprivateClause
+  // DUMP-NEXT:  -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT:  -OMPDefaultClause
+  // DUMP:-OMPParallelDirective
+  // DUMP-NEXT:-OMPPrivateClaus
+  // DUMP-NEXT: -DeclRefExpr {{.*}} 'z'
+  // DUMP-NEXT: -OMPDefaultClause
+  // DUMP-NEXT: -OMPFirstprivateClause {{.*}} 
+  // DUMP-NEXT:  -DeclRefExpr {{.*}} 'f'
+  // DUMP:   -CXXThisExpr {{.*}} 'A *' implicit this
+  // DUMP-NEXT:  -DeclRefExpr {{.*}} 'f'
+  // DUMP: -MemberExpr {{.*}}
+  // DUMP-NEXT:  -CXXThisExpr
+  // DUMP:   -CXXThisExpr {{.*}} 'A *' implicit this
+  // DUMP-NEXT:  -DeclRefExpr {{.*}} 'z'
+};
 #endif // HEADER
Index: clang/lib/Sema/SemaOpenMP.cpp
===
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -196,6 +196,16 @@
 llvm::DenseSet> UsedInScanDirective;
 l

[clang] 4821508 - Revert "DebugInfo: Fully integrate ctor type homing into 'limited' debug info"

2022-06-24 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-06-24T17:07:47Z
New Revision: 4821508d4db75a535d02b8938f81fac6de66cc26

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

LOG: Revert "DebugInfo: Fully integrate ctor type homing into 'limited' debug 
info"

Reverting to simplify some Google-internal rollout issues. Will recommit
in a week or two.

This reverts commit 517bbc64dbe493644eff8d55fd9566435e930520.

Added: 
clang/test/CodeGenCXX/debug-info-ctor-homing-flag.cpp

Modified: 
clang/docs/UsersManual.rst
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Basic/DebugInfoOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/attr-cpuspecific-renaming.cpp
clang/test/CodeGen/pr52782-stdcall-func-decl.cpp
clang/test/CodeGenCXX/debug-info-class.cpp
clang/test/CodeGenCXX/debug-info-limited-ctor.cpp
clang/test/CodeGenCXX/debug-info-template-explicit-specialization.cpp
clang/test/CodeGenCXX/debug-lambda-this.cpp
clang/test/CodeGenCXX/ibm128-declarations.cpp
clang/test/CodeGenCXX/standalone-debug-attribute.cpp
clang/test/Driver/cl-options.c
clang/test/Driver/clang-g-opts.c
clang/test/Driver/cuda-dwarf-2.cu
clang/test/Driver/debug-options-as.c
clang/test/Driver/debug-options.c
clang/test/Driver/integrated-as.s
clang/test/Driver/myriad-toolchain.c
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/split-debug.c
clang/test/OpenMP/debug_private.c
clang/test/OpenMP/debug_task_shared.c
clang/test/OpenMP/debug_threadprivate_copyin.c

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index ccb5fed1cb370..e12dc72407b13 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2672,6 +2672,19 @@ below. If multiple flags are present, the last one is 
used.
**-fno-standalone-debug** option can be used to get to turn on the
vtable-based optimization described above.
 
+.. option:: -fuse-ctor-homing
+
+   This optimization is similar to the optimizations that are enabled as part
+   of -fno-standalone-debug. Here, Clang only emits type info for a
+   non-trivial, non-aggregate C++ class in the modules that contain a
+   definition of one of its constructors. This relies on the additional
+   assumption that all classes that are not trivially constructible have a
+   non-trivial constructor that is used somewhere. The negation,
+   -fno-use-ctor-homing, ensures that constructor homing is not used.
+
+   This flag is not enabled by default, and needs to be used with -cc1 or
+   -Xclang.
+
 .. option:: -g
 
   Generate complete debug info.

diff  --git a/clang/include/clang/Basic/CodeGenOptions.h 
b/clang/include/clang/Basic/CodeGenOptions.h
index 5f5218c87a605..23d76c308d847 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -468,7 +468,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
 
   /// Check if type and variable info should be emitted.
   bool hasReducedDebugInfo() const {
-return getDebugInfo() >= codegenoptions::LimitedDebugInfo;
+return getDebugInfo() >= codegenoptions::DebugInfoConstructor;
   }
 
   /// Check if maybe unused type info should be emitted.

diff  --git a/clang/include/clang/Basic/DebugInfoOptions.h 
b/clang/include/clang/Basic/DebugInfoOptions.h
index 98210cc3cfa13..a99a2b5903d7e 100644
--- a/clang/include/clang/Basic/DebugInfoOptions.h
+++ b/clang/include/clang/Basic/DebugInfoOptions.h
@@ -34,6 +34,12 @@ enum DebugInfoKind {
   /// (-gline-tables-only).
   DebugLineTablesOnly,
 
+  /// Limit generated debug info for classes to reduce size. This emits class
+  /// type info only where the constructor is emitted, if it is a class that
+  /// has a constructor.
+  /// FIXME: Consider combining this with LimitedDebugInfo.
+  DebugInfoConstructor,
+
   /// Limit generated debug info to reduce size (-fno-standalone-debug). This
   /// emits forward decls for types that could be replaced with forward decls 
in
   /// the source code. For dynamic C++ classes type info is only emitted into

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index e998612d32e2e..81d1d53cea9b1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5246,6 +5246,11 @@ def mrelocation_model : Separate<["-"], 
"mrelocation-model">,
 def fno_math_builtin : Flag<["-"], "fno-math-builtin">,
   HelpText<"Disable implicit builtin knowledge of math functions">,
   MarshallingInfoFlag>;
+def fno_use_ctor_homing: Flag<["-"], "fno-use-ctor-homing">,
+HelpText<"Don't u

[PATCH] D128363: [clang][dataflow] Implement functionality for flow condition variable substitution.

2022-06-24 Thread weiyi via Phabricator via cfe-commits
wyt updated this revision to Diff 439810.
wyt marked 2 inline comments as done.
wyt added a comment.

Address comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128363

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -276,4 +276,132 @@
   Context.getOrCreateConjunction(X, Context.getOrCreateConjunction(Y, Z;
 }
 
+TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionsDisjunctiveFC) {
+  auto &X = Context.createAtomicBoolValue();
+  auto &Y = Context.createAtomicBoolValue();
+  auto &True = Context.getBoolLiteralValue(true);
+  auto &False = Context.getBoolLiteralValue(false);
+
+  // FC = X || Y
+  auto &FC = Context.makeFlowConditionToken();
+  Context.addFlowConditionConstraint(FC, Context.getOrCreateDisjunction(X, Y));
+
+  // If X is true in FC, FC = X || Y must be true
+  auto &FCWithXTrue =
+  Context.buildAndSubstituteFlowCondition(FC, {{&X, &True}});
+  EXPECT_TRUE(Context.equivalentBoolValues(FCWithXTrue, True));
+
+  // If X is false in FC, FC = X || Y is equivalent to evaluating Y
+  auto &FC1WithXFalse =
+  Context.buildAndSubstituteFlowCondition(FC, {{&X, &False}});
+  EXPECT_TRUE(Context.equivalentBoolValues(FC1WithXFalse, Y));
+}
+
+TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionsConjunctiveFC) {
+  auto &X = Context.createAtomicBoolValue();
+  auto &Y = Context.createAtomicBoolValue();
+  auto &True = Context.getBoolLiteralValue(true);
+  auto &False = Context.getBoolLiteralValue(false);
+
+  // FC = X && Y
+  auto &FC = Context.makeFlowConditionToken();
+  Context.addFlowConditionConstraint(FC, Context.getOrCreateConjunction(X, Y));
+
+  // If X is true in FC, FC = X && Y is equivalent to evaluating Y
+  auto &FCWithXTrue =
+  Context.buildAndSubstituteFlowCondition(FC, {{&X, &True}});
+  EXPECT_TRUE(Context.equivalentBoolValues(FCWithXTrue, Y));
+
+  // If X is false in FC, FC = X && Y must be false
+  auto &FCWithXFalse =
+  Context.buildAndSubstituteFlowCondition(FC, {{&X, &False}});
+  EXPECT_TRUE(Context.equivalentBoolValues(FCWithXFalse, False));
+}
+
+TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionsForkedFC) {
+  auto &X = Context.createAtomicBoolValue();
+  auto &Y = Context.createAtomicBoolValue();
+  auto &Z = Context.createAtomicBoolValue();
+  auto &True = Context.getBoolLiteralValue(true);
+  auto &False = Context.getBoolLiteralValue(false);
+
+  // FC = X && Y
+  auto &FC = Context.makeFlowConditionToken();
+  Context.addFlowConditionConstraint(FC, Context.getOrCreateConjunction(X, Y));
+  // ForkedFC = FC && Z = X && Y && Z
+  auto &ForkedFC = Context.forkFlowCondition(FC);
+  Context.addFlowConditionConstraint(ForkedFC, Z);
+
+  // If any of X,Y,Z is true in ForkedFC, ForkedFC = X && Y && Z is equivalent
+  // to evaluating the conjunction of the remaining values
+  auto &ForkedFCWithZTrue =
+  Context.buildAndSubstituteFlowCondition(ForkedFC, {{&Z, &True}});
+  EXPECT_TRUE(Context.equivalentBoolValues(
+  ForkedFCWithZTrue, Context.getOrCreateConjunction(X, Y)));
+  auto &ForkedFCWithYAndZTrue = Context.buildAndSubstituteFlowCondition(
+  ForkedFC, {{&Y, &True}, {&Z, &True}});
+  EXPECT_TRUE(Context.equivalentBoolValues(ForkedFCWithYAndZTrue, X));
+
+  // If any of X,Y,Z is false in ForkedFC, ForkedFC = X && Y && Z must be false
+  auto &ForkedFCWithXFalse =
+  Context.buildAndSubstituteFlowCondition(ForkedFC, {{&X, &False}});
+  auto &ForkedFCWithYFalse =
+  Context.buildAndSubstituteFlowCondition(ForkedFC, {{&Y, &False}});
+  auto &ForkedFCWithZFalse =
+  Context.buildAndSubstituteFlowCondition(ForkedFC, {{&Z, &False}});
+  EXPECT_TRUE(Context.equivalentBoolValues(ForkedFCWithXFalse, False));
+  EXPECT_TRUE(Context.equivalentBoolValues(ForkedFCWithYFalse, False));
+  EXPECT_TRUE(Context.equivalentBoolValues(ForkedFCWithZFalse, False));
+}
+
+TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionsJoinedFC) {
+  auto &X = Context.createAtomicBoolValue();
+  auto &Y = Context.createAtomicBoolValue();
+  auto &Z = Context.createAtomicBoolValue();
+  auto &True = Context.getBoolLiteralValue(true);
+  auto &False = Context.getBoolLiteralValue(false);
+
+  // FC1 = X
+  auto &FC1 = Context.makeFlowConditionToken();
+  Context.addFlowConditionConstraint(FC1, X);
+  // FC2 = Y
+  auto &FC2 = Context.makeFlowConditionToken();
+  Context.addFlowConditionConstraint(FC2, Y);
+  // JoinedFC = (FC1 || FC2) && Z = (X || Y) && Z
+  auto &JoinedFC = Context.j

[PATCH] D128482: [clang codegen] Add dso_local/hidden/etc. markings to VTT declarations

2022-06-24 Thread Eli Friedman via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe11bf8de729a: [clang codegen] Add dso_local/hidden/etc. 
markings to VTT declarations (authored by efriedma).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128482

Files:
  clang/lib/CodeGen/CGVTT.cpp
  clang/test/CodeGenCXX/visibility.cpp


Index: clang/test/CodeGenCXX/visibility.cpp
===
--- clang/test/CodeGenCXX/visibility.cpp
+++ clang/test/CodeGenCXX/visibility.cpp
@@ -118,6 +118,8 @@
 // CHECK-HIDDEN: @_ZN6Test143varE = external global
 // CHECK: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
 // CHECK-HIDDEN: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x 
i8]
+// CHECK: @_ZTVN6test701BE = external hidden unnamed_addr constant { [5 x ptr] 
}, align 8
+// CHECK: @_ZTTN6test701BE = external hidden unnamed_addr constant [2 x ptr], 
align 8
 
 namespace test27 {
   template
@@ -1317,3 +1319,16 @@
   // CHECK-LABEL: define void @_ZN6test693foo1fEv
   // CHECK-HIDDEN-LABEL: define hidden void @_ZN6test693foo1fEv
 }
+
+namespace test70 {
+  // Make sure both the vtable and VTT declarations are marked "hidden"
+  class HIDDEN A {
+virtual void a();
+  };
+  class HIDDEN B : virtual A {
+void a() override;
+~B();
+  };
+  B::~B() {}
+  // Check lines at top of file.
+}
Index: clang/lib/CodeGen/CGVTT.cpp
===
--- clang/lib/CodeGen/CGVTT.cpp
+++ clang/lib/CodeGen/CGVTT.cpp
@@ -96,9 +96,6 @@
 
   if (CGM.supportsCOMDAT() && VTT->isWeakForLinker())
 VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));
-
-  // Set the right visibility.
-  CGM.setGVProperties(VTT, RD);
 }
 
 llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) {
@@ -122,6 +119,7 @@
   llvm::GlobalVariable *GV = CGM.CreateOrReplaceCXXRuntimeVariable(
   Name, ArrayType, llvm::GlobalValue::ExternalLinkage, Align);
   GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+  CGM.setGVProperties(GV, RD);
   return GV;
 }
 


Index: clang/test/CodeGenCXX/visibility.cpp
===
--- clang/test/CodeGenCXX/visibility.cpp
+++ clang/test/CodeGenCXX/visibility.cpp
@@ -118,6 +118,8 @@
 // CHECK-HIDDEN: @_ZN6Test143varE = external global
 // CHECK: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
 // CHECK-HIDDEN: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
+// CHECK: @_ZTVN6test701BE = external hidden unnamed_addr constant { [5 x ptr] }, align 8
+// CHECK: @_ZTTN6test701BE = external hidden unnamed_addr constant [2 x ptr], align 8
 
 namespace test27 {
   template
@@ -1317,3 +1319,16 @@
   // CHECK-LABEL: define void @_ZN6test693foo1fEv
   // CHECK-HIDDEN-LABEL: define hidden void @_ZN6test693foo1fEv
 }
+
+namespace test70 {
+  // Make sure both the vtable and VTT declarations are marked "hidden"
+  class HIDDEN A {
+virtual void a();
+  };
+  class HIDDEN B : virtual A {
+void a() override;
+~B();
+  };
+  B::~B() {}
+  // Check lines at top of file.
+}
Index: clang/lib/CodeGen/CGVTT.cpp
===
--- clang/lib/CodeGen/CGVTT.cpp
+++ clang/lib/CodeGen/CGVTT.cpp
@@ -96,9 +96,6 @@
 
   if (CGM.supportsCOMDAT() && VTT->isWeakForLinker())
 VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));
-
-  // Set the right visibility.
-  CGM.setGVProperties(VTT, RD);
 }
 
 llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) {
@@ -122,6 +119,7 @@
   llvm::GlobalVariable *GV = CGM.CreateOrReplaceCXXRuntimeVariable(
   Name, ArrayType, llvm::GlobalValue::ExternalLinkage, Align);
   GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+  CGM.setGVProperties(GV, RD);
   return GV;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e11bf8d - [clang codegen] Add dso_local/hidden/etc. markings to VTT declarations

2022-06-24 Thread Eli Friedman via cfe-commits

Author: Eli Friedman
Date: 2022-06-24T09:58:31-07:00
New Revision: e11bf8de729a4d6eb0d3b5cf154f900cddc522d3

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

LOG: [clang codegen] Add dso_local/hidden/etc. markings to VTT declarations

We were marking definitions, but not declarations. Marking declarations
makes computing the address more efficient.

Fixes issue reported at https://discourse.llvm.org/t/63090

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

Added: 


Modified: 
clang/lib/CodeGen/CGVTT.cpp
clang/test/CodeGenCXX/visibility.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index 564d9f354e646..ebac9196df025 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -96,9 +96,6 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
 
   if (CGM.supportsCOMDAT() && VTT->isWeakForLinker())
 VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));
-
-  // Set the right visibility.
-  CGM.setGVProperties(VTT, RD);
 }
 
 llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) {
@@ -122,6 +119,7 @@ llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const 
CXXRecordDecl *RD) {
   llvm::GlobalVariable *GV = CGM.CreateOrReplaceCXXRuntimeVariable(
   Name, ArrayType, llvm::GlobalValue::ExternalLinkage, Align);
   GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+  CGM.setGVProperties(GV, RD);
   return GV;
 }
 

diff  --git a/clang/test/CodeGenCXX/visibility.cpp 
b/clang/test/CodeGenCXX/visibility.cpp
index aff6554282caf..d54aa2da033ac 100644
--- a/clang/test/CodeGenCXX/visibility.cpp
+++ b/clang/test/CodeGenCXX/visibility.cpp
@@ -118,6 +118,8 @@ namespace test48 {
 // CHECK-HIDDEN: @_ZN6Test143varE = external global
 // CHECK: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x i8]
 // CHECK-HIDDEN: @_ZN6Test154TempINS_1AEE5Inner6bufferE = external global [0 x 
i8]
+// CHECK: @_ZTVN6test701BE = external hidden unnamed_addr constant { [5 x ptr] 
}, align 8
+// CHECK: @_ZTTN6test701BE = external hidden unnamed_addr constant [2 x ptr], 
align 8
 
 namespace test27 {
   template
@@ -1317,3 +1319,16 @@ namespace test69 {
   // CHECK-LABEL: define void @_ZN6test693foo1fEv
   // CHECK-HIDDEN-LABEL: define hidden void @_ZN6test693foo1fEv
 }
+
+namespace test70 {
+  // Make sure both the vtable and VTT declarations are marked "hidden"
+  class HIDDEN A {
+virtual void a();
+  };
+  class HIDDEN B : virtual A {
+void a() override;
+~B();
+  };
+  B::~B() {}
+  // Check lines at top of file.
+}



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


[PATCH] D128157: [clang-tidy] cppcoreguidelines-virtual-class-destructor: Fix crash when "virtual" keyword is expanded from a macro

2022-06-24 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.

In D128157#3605829 , @jspam wrote:

> I see :) Yes, looks like Git's rename detection did its job.
>
> Thanks for the review. Could you or someone else please merge this for me? 
> Author: Joachim Priesner 

I can submit, yes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128157

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


[PATCH] D128401: [clang-tidy] Fixing a bug raising false alarms on static local variables in the Infinite Loop Checker

2022-06-24 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added inline comments.



Comment at: clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp:190
+
+containsFunc |= (CanDecl == Func);
+overlap |= Callees.contains(CanDecl);

Personally I'm not a fan of using bitwise operators with booleans.  It involves 
implicit casts of bool to int and int to bool and doesn't use the usual 
short-circuiting logic of `||` and `&&`.  It also means this code won't be 
analyzed by clang-tidy as "performing operations on booleans" for things like 
`readability-simplify-boolean-expr`.


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

https://reviews.llvm.org/D128401

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


  1   2   >