[PATCH] D130550: [pseudo] Start rules are `_ := start-symbol EOF`, improve recovery.

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

Previously we were calling glrRecover() ad-hoc at the end of input.
Two main problems with this:

- glrRecover() on two separate code paths is inelegant
- We may have to recover several times in succession (e.g. to exit from nested 
scopes), so we need a loop at end-of-file

Having an actual shift action for an EOF terminal allows us to handle
both concerns in the main shift/recover/reduce loop.

This revealed a recovery design bug where recovery could enter a loop by
repeatedly choosing the same parent to identically recover from.
Addressed this by allowing each node to be used as a recovery base once.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130550

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
  clang-tools-extra/pseudo/lib/Forest.cpp
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/cxx/cxx.bnf
  clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
  clang-tools-extra/pseudo/test/lr-build-basic.test
  clang-tools-extra/pseudo/test/lr-build-conflicts.test
  clang-tools-extra/pseudo/unittests/ForestTest.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp

Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -509,7 +509,7 @@
   // item `expr := • IDENTIFIER`, and both have different goto states on the
   // nonterminal `expr`.
   build(R"bnf(
-_ := test
+_ := test EOF
 
 test := { expr
 test := { IDENTIFIER
@@ -548,7 +548,7 @@
   // foo should be reduced first, so that in step 2 we have completed reduces
   // for test, and form an ambiguous forest node.
   build(R"bnf(
-_ := test
+_ := test EOF
 
 test := IDENTIFIER
 test := foo
@@ -575,7 +575,7 @@
   //  - multiple possible recovery rules
   //  - recovery from outer scopes is rejected
   build(R"bnf(
-_ := block
+_ := block EOF
 
 block := { block [recover=Braces] }
 block := { numbers [recover=Braces] }
@@ -604,9 +604,42 @@
 "[  5, end) └─} := tok[5]\n");
 }
 
+TEST_F(GLRTest, RepeatedRecovery) {
+  // We require multiple steps of recovery at eof and then a reduction in order
+  // to successfully parse.
+  build(R"bnf(
+_ := function EOF
+# FIXME: this forces EOF to be in follow(signature).
+# Remove it once we use unconstrained reduction for recovery.
+_ := signature EOF
+
+function := signature body [recover=Skip]
+signature := IDENTIFIER params [recover=Skip]
+params := ( )
+body := { }
+  )bnf");
+  TestLang.Table = LRTable::buildSLR(TestLang.G);
+  llvm::errs() << TestLang.Table.dumpForTests(TestLang.G);
+  TestLang.RecoveryStrategies.try_emplace(
+  extensionID("Skip"),
+  [](Token::Index Start, const TokenStream &) { return Start; });
+  clang::LangOptions LOptions;
+  TokenStream Tokens = cook(lex("main", LOptions), LOptions);
+
+  const ForestNode &Parsed =
+  glrParse({Tokens, Arena, GSStack}, id("function"), TestLang);
+  EXPECT_EQ(Parsed.dumpRecursive(TestLang.G),
+"[  0, end) function := signature body [recover=Skip]\n"
+"[  0,   1) ├─signature := IDENTIFIER params [recover=Skip]\n"
+"[  0,   1) │ ├─IDENTIFIER := tok[0]\n"
+"[  1,   1) │ └─params := \n"
+"[  1, end) └─body := \n");
+}
+
+
 TEST_F(GLRTest, NoExplicitAccept) {
   build(R"bnf(
-_ := test
+_ := test EOF
 
 test := IDENTIFIER test
 test := IDENTIFIER
@@ -629,7 +662,7 @@
 
 TEST_F(GLRTest, GuardExtension) {
   build(R"bnf(
-_ := start
+_ := start EOF
 
 start := IDENTIFIER [guard]
   )bnf");
Index: clang-tools-extra/pseudo/unittests/ForestTest.cpp
===
--- clang-tools-extra/pseudo/unittests/ForestTest.cpp
+++ clang-tools-extra/pseudo/unittests/ForestTest.cpp
@@ -54,7 +54,7 @@
 
 TEST_F(ForestTest, DumpBasic) {
   build(R"cpp(
-_ := add-expression
+_ := add-expression EOF
 add-expression := id-expression + id-expression
 id-expression := IDENTIFIER
   )cpp");
@@ -64,7 +64,7 @@
   cook(lex("a + b", clang::LangOptions()), clang::LangOptions());
 
   auto T = Arena.createTerminals(TS);
-  ASSERT_EQ(T.size(), 3u);
+  ASSERT_EQ(T.size(), 4u);
   const auto *Left = &Arena.createSequence(
   symbol("id-expression"), ruleFor("id-expression"), {&T.front()});
   const auto *Right = &Arena.createSequence(symbol("id-expression"),
@@ -89,9 +89,9 @@
 
 TEST_F(ForestTest, DumpAmbiguousAndRefs) {
   build(R"cpp(
-_ := type
-type := class-type # rule 3
-type := enum-type # rule 4
+_ := type EOF
+type := class-typ

[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

rusyaev-roman wrote:
> ChuanqiXu wrote:
> > rusyaev-roman wrote:
> > > ChuanqiXu wrote:
> > > > rusyaev-roman wrote:
> > > > > ChuanqiXu wrote:
> > > > > > rusyaev-roman wrote:
> > > > > > > ChuanqiXu wrote:
> > > > > > > > What if NRVO contains a value already? It is possible due to 
> > > > > > > > the value of NRVO could be set by its children.
> > > > > > > Actually this is intention. If the parent has already NRVO 
> > > > > > > candidate, then it should be invalidated (or not). Let's consider 
> > > > > > > the following examples:
> > > > > > > 
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b) {
> > > > > > >X x;
> > > > > > >X y;
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > >else
> > > > > > >   return y; // when we process this return statement, the 
> > > > > > > parent has already NRVO and it will be invalidated (this is 
> > > > > > > correct behavior)
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b) {
> > > > > > >X x;
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > >
> > > > > > >X y;
> > > > > > >// when we process this return statement, the parent has 
> > > > > > > already NRVO and it WON't be invalidated
> > > > > > >//  (this is correct behavior), because a return slot will be 
> > > > > > > available for it
> > > > > > >return y;
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b) {
> > > > > > >X x;
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > > 
> > > > > > >// when we process this return statement, the parent has 
> > > > > > > already NRVO and it WON't be invalidated (this is correct 
> > > > > > > behavior)
> > > > > > >return x;
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b, X x) {
> > > > > > >X y;
> > > > > > >
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > > 
> > > > > > >// when we process this return statement, the parent contains 
> > > > > > > nullptr (invalid candidate) and it will be invalidated (this is 
> > > > > > > correct behavior)
> > > > > > >return y;
> > > > > > > }
> > > > > > > ```
> > > > > > > 
> > > > > > > ```
> > > > > > > X foo(bool b, X x) {
> > > > > > >if (b)
> > > > > > >   return x;
> > > > > > > 
> > > > > > >X y;
> > > > > > >// when we process this return statement, the parent contains 
> > > > > > > nullptr (invalid candidate) and it WON't be invalidated (this is 
> > > > > > > correct behavior)
> > > > > > >return y;
> > > > > > > }
> > > > > > > ```
> > > > > > Oh, I see. Tricky. I don't find invalid cases now. But I recommend 
> > > > > > to comment that the children would maintain the `ReturnSlots` of 
> > > > > > their parents. (This is anti-intuition)
> > > > > > 
> > > > > > Have you tested any larger projects? Like libc++, libstdc++ or 
> > > > > > something like folly. I feel we need to do such tests to avoid we 
> > > > > > get anything wrong.
> > > > > I've already added a comment at the beginning of 
> > > > > `updateNRVOCandidate` function where this point is mentioned: 
> > > > > ```
> > > > > //  ... Therefore, we need to clear return slots for other
> > > > > //  variables defined before the current return statement in the 
> > > > > current
> > > > > //  scope and in outer scopes.
> > > > > ```
> > > > > If it's not enough, please let me know.
> > > > > 
> > > > > 
> > > > > > Have you tested any larger projects?
> > > > > 
> > > > > Yes, I've built the `clang` itself and `compiler-rt` project. Then 
> > > > > I've checked them to run 'check-all' (on built clang and 
> > > > > compiler-rt). Everything  works.
> > > > Great! Clang should be large enough.
> > > Thanks a lot for the careful review!
> > > 
> > > @ChuanqiXu  , could you land this patch please?
> > > 
> > > Many thanks to @Izaron for the original implementation.
> > Sure. What's your prefer Name and Mail address?
> Thanks!
> 
> Roman Rusyaev 
Oh, I forgot you need edit the ReleaseNotes at clang/docs/ReleaseNotes.rst


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Roman Rusyaev via Phabricator via cfe-commits
rusyaev-roman added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

ChuanqiXu wrote:
> rusyaev-roman wrote:
> > ChuanqiXu wrote:
> > > rusyaev-roman wrote:
> > > > ChuanqiXu wrote:
> > > > > rusyaev-roman wrote:
> > > > > > ChuanqiXu wrote:
> > > > > > > What if NRVO contains a value already? It is possible due to the 
> > > > > > > value of NRVO could be set by its children.
> > > > > > Actually this is intention. If the parent has already NRVO 
> > > > > > candidate, then it should be invalidated (or not). Let's consider 
> > > > > > the following examples:
> > > > > > 
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b) {
> > > > > >X x;
> > > > > >X y;
> > > > > >if (b)
> > > > > >   return x;
> > > > > >else
> > > > > >   return y; // when we process this return statement, the 
> > > > > > parent has already NRVO and it will be invalidated (this is correct 
> > > > > > behavior)
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b) {
> > > > > >X x;
> > > > > >if (b)
> > > > > >   return x;
> > > > > >
> > > > > >X y;
> > > > > >// when we process this return statement, the parent has already 
> > > > > > NRVO and it WON't be invalidated
> > > > > >//  (this is correct behavior), because a return slot will be 
> > > > > > available for it
> > > > > >return y;
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b) {
> > > > > >X x;
> > > > > >if (b)
> > > > > >   return x;
> > > > > > 
> > > > > >// when we process this return statement, the parent has already 
> > > > > > NRVO and it WON't be invalidated (this is correct behavior)
> > > > > >return x;
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b, X x) {
> > > > > >X y;
> > > > > >
> > > > > >if (b)
> > > > > >   return x;
> > > > > > 
> > > > > >// when we process this return statement, the parent contains 
> > > > > > nullptr (invalid candidate) and it will be invalidated (this is 
> > > > > > correct behavior)
> > > > > >return y;
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > ```
> > > > > > X foo(bool b, X x) {
> > > > > >if (b)
> > > > > >   return x;
> > > > > > 
> > > > > >X y;
> > > > > >// when we process this return statement, the parent contains 
> > > > > > nullptr (invalid candidate) and it WON't be invalidated (this is 
> > > > > > correct behavior)
> > > > > >return y;
> > > > > > }
> > > > > > ```
> > > > > Oh, I see. Tricky. I don't find invalid cases now. But I recommend to 
> > > > > comment that the children would maintain the `ReturnSlots` of their 
> > > > > parents. (This is anti-intuition)
> > > > > 
> > > > > Have you tested any larger projects? Like libc++, libstdc++ or 
> > > > > something like folly. I feel we need to do such tests to avoid we get 
> > > > > anything wrong.
> > > > I've already added a comment at the beginning of `updateNRVOCandidate` 
> > > > function where this point is mentioned: 
> > > > ```
> > > > //  ... Therefore, we need to clear return slots for other
> > > > //  variables defined before the current return statement in the 
> > > > current
> > > > //  scope and in outer scopes.
> > > > ```
> > > > If it's not enough, please let me know.
> > > > 
> > > > 
> > > > > Have you tested any larger projects?
> > > > 
> > > > Yes, I've built the `clang` itself and `compiler-rt` project. Then I've 
> > > > checked them to run 'check-all' (on built clang and compiler-rt). 
> > > > Everything  works.
> > > Great! Clang should be large enough.
> > Thanks a lot for the careful review!
> > 
> > @ChuanqiXu  , could you land this patch please?
> > 
> > Many thanks to @Izaron for the original implementation.
> Sure. What's your prefer Name and Mail address?
Thanks!

Roman Rusyaev 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

rusyaev-roman wrote:
> ChuanqiXu wrote:
> > rusyaev-roman wrote:
> > > ChuanqiXu wrote:
> > > > rusyaev-roman wrote:
> > > > > ChuanqiXu wrote:
> > > > > > What if NRVO contains a value already? It is possible due to the 
> > > > > > value of NRVO could be set by its children.
> > > > > Actually this is intention. If the parent has already NRVO candidate, 
> > > > > then it should be invalidated (or not). Let's consider the following 
> > > > > examples:
> > > > > 
> > > > > 
> > > > > ```
> > > > > X foo(bool b) {
> > > > >X x;
> > > > >X y;
> > > > >if (b)
> > > > >   return x;
> > > > >else
> > > > >   return y; // when we process this return statement, the parent 
> > > > > has already NRVO and it will be invalidated (this is correct behavior)
> > > > > }
> > > > > ```
> > > > > 
> > > > > ```
> > > > > X foo(bool b) {
> > > > >X x;
> > > > >if (b)
> > > > >   return x;
> > > > >
> > > > >X y;
> > > > >// when we process this return statement, the parent has already 
> > > > > NRVO and it WON't be invalidated
> > > > >//  (this is correct behavior), because a return slot will be 
> > > > > available for it
> > > > >return y;
> > > > > }
> > > > > ```
> > > > > 
> > > > > ```
> > > > > X foo(bool b) {
> > > > >X x;
> > > > >if (b)
> > > > >   return x;
> > > > > 
> > > > >// when we process this return statement, the parent has already 
> > > > > NRVO and it WON't be invalidated (this is correct behavior)
> > > > >return x;
> > > > > }
> > > > > ```
> > > > > 
> > > > > ```
> > > > > X foo(bool b, X x) {
> > > > >X y;
> > > > >
> > > > >if (b)
> > > > >   return x;
> > > > > 
> > > > >// when we process this return statement, the parent contains 
> > > > > nullptr (invalid candidate) and it will be invalidated (this is 
> > > > > correct behavior)
> > > > >return y;
> > > > > }
> > > > > ```
> > > > > 
> > > > > ```
> > > > > X foo(bool b, X x) {
> > > > >if (b)
> > > > >   return x;
> > > > > 
> > > > >X y;
> > > > >// when we process this return statement, the parent contains 
> > > > > nullptr (invalid candidate) and it WON't be invalidated (this is 
> > > > > correct behavior)
> > > > >return y;
> > > > > }
> > > > > ```
> > > > Oh, I see. Tricky. I don't find invalid cases now. But I recommend to 
> > > > comment that the children would maintain the `ReturnSlots` of their 
> > > > parents. (This is anti-intuition)
> > > > 
> > > > Have you tested any larger projects? Like libc++, libstdc++ or 
> > > > something like folly. I feel we need to do such tests to avoid we get 
> > > > anything wrong.
> > > I've already added a comment at the beginning of `updateNRVOCandidate` 
> > > function where this point is mentioned: 
> > > ```
> > > //  ... Therefore, we need to clear return slots for other
> > > //  variables defined before the current return statement in the 
> > > current
> > > //  scope and in outer scopes.
> > > ```
> > > If it's not enough, please let me know.
> > > 
> > > 
> > > > Have you tested any larger projects?
> > > 
> > > Yes, I've built the `clang` itself and `compiler-rt` project. Then I've 
> > > checked them to run 'check-all' (on built clang and compiler-rt). 
> > > Everything  works.
> > Great! Clang should be large enough.
> Thanks a lot for the careful review!
> 
> @ChuanqiXu  , could you land this patch please?
> 
> Many thanks to @Izaron for the original implementation.
Sure. What's your prefer Name and Mail address?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D130522: [clang][dataflow] Fix SAT solver crashes on `X ^ X` and `X v X`

2022-07-25 Thread Stanislav Gatev via Phabricator via cfe-commits
sgatev accepted this revision.
sgatev added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:273
+
+// Visit a sub-value of `Val` (pick any, they are identical).
+  } else {

Let's visit `C->getLeftSubValue()` here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130522

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Roman Rusyaev via Phabricator via cfe-commits
rusyaev-roman added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

ChuanqiXu wrote:
> rusyaev-roman wrote:
> > ChuanqiXu wrote:
> > > rusyaev-roman wrote:
> > > > ChuanqiXu wrote:
> > > > > What if NRVO contains a value already? It is possible due to the 
> > > > > value of NRVO could be set by its children.
> > > > Actually this is intention. If the parent has already NRVO candidate, 
> > > > then it should be invalidated (or not). Let's consider the following 
> > > > examples:
> > > > 
> > > > 
> > > > ```
> > > > X foo(bool b) {
> > > >X x;
> > > >X y;
> > > >if (b)
> > > >   return x;
> > > >else
> > > >   return y; // when we process this return statement, the parent 
> > > > has already NRVO and it will be invalidated (this is correct behavior)
> > > > }
> > > > ```
> > > > 
> > > > ```
> > > > X foo(bool b) {
> > > >X x;
> > > >if (b)
> > > >   return x;
> > > >
> > > >X y;
> > > >// when we process this return statement, the parent has already 
> > > > NRVO and it WON't be invalidated
> > > >//  (this is correct behavior), because a return slot will be 
> > > > available for it
> > > >return y;
> > > > }
> > > > ```
> > > > 
> > > > ```
> > > > X foo(bool b) {
> > > >X x;
> > > >if (b)
> > > >   return x;
> > > > 
> > > >// when we process this return statement, the parent has already 
> > > > NRVO and it WON't be invalidated (this is correct behavior)
> > > >return x;
> > > > }
> > > > ```
> > > > 
> > > > ```
> > > > X foo(bool b, X x) {
> > > >X y;
> > > >
> > > >if (b)
> > > >   return x;
> > > > 
> > > >// when we process this return statement, the parent contains 
> > > > nullptr (invalid candidate) and it will be invalidated (this is correct 
> > > > behavior)
> > > >return y;
> > > > }
> > > > ```
> > > > 
> > > > ```
> > > > X foo(bool b, X x) {
> > > >if (b)
> > > >   return x;
> > > > 
> > > >X y;
> > > >// when we process this return statement, the parent contains 
> > > > nullptr (invalid candidate) and it WON't be invalidated (this is 
> > > > correct behavior)
> > > >return y;
> > > > }
> > > > ```
> > > Oh, I see. Tricky. I don't find invalid cases now. But I recommend to 
> > > comment that the children would maintain the `ReturnSlots` of their 
> > > parents. (This is anti-intuition)
> > > 
> > > Have you tested any larger projects? Like libc++, libstdc++ or something 
> > > like folly. I feel we need to do such tests to avoid we get anything 
> > > wrong.
> > I've already added a comment at the beginning of `updateNRVOCandidate` 
> > function where this point is mentioned: 
> > ```
> > //  ... Therefore, we need to clear return slots for other
> > //  variables defined before the current return statement in the current
> > //  scope and in outer scopes.
> > ```
> > If it's not enough, please let me know.
> > 
> > 
> > > Have you tested any larger projects?
> > 
> > Yes, I've built the `clang` itself and `compiler-rt` project. Then I've 
> > checked them to run 'check-all' (on built clang and compiler-rt). 
> > Everything  works.
> Great! Clang should be large enough.
Thanks a lot for the careful review!

@ChuanqiXu  , could you land this patch please?

Many thanks to @Izaron for the original implementation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

rusyaev-roman wrote:
> ChuanqiXu wrote:
> > rusyaev-roman wrote:
> > > ChuanqiXu wrote:
> > > > What if NRVO contains a value already? It is possible due to the value 
> > > > of NRVO could be set by its children.
> > > Actually this is intention. If the parent has already NRVO candidate, 
> > > then it should be invalidated (or not). Let's consider the following 
> > > examples:
> > > 
> > > 
> > > ```
> > > X foo(bool b) {
> > >X x;
> > >X y;
> > >if (b)
> > >   return x;
> > >else
> > >   return y; // when we process this return statement, the parent has 
> > > already NRVO and it will be invalidated (this is correct behavior)
> > > }
> > > ```
> > > 
> > > ```
> > > X foo(bool b) {
> > >X x;
> > >if (b)
> > >   return x;
> > >
> > >X y;
> > >// when we process this return statement, the parent has already NRVO 
> > > and it WON't be invalidated
> > >//  (this is correct behavior), because a return slot will be 
> > > available for it
> > >return y;
> > > }
> > > ```
> > > 
> > > ```
> > > X foo(bool b) {
> > >X x;
> > >if (b)
> > >   return x;
> > > 
> > >// when we process this return statement, the parent has already NRVO 
> > > and it WON't be invalidated (this is correct behavior)
> > >return x;
> > > }
> > > ```
> > > 
> > > ```
> > > X foo(bool b, X x) {
> > >X y;
> > >
> > >if (b)
> > >   return x;
> > > 
> > >// when we process this return statement, the parent contains nullptr 
> > > (invalid candidate) and it will be invalidated (this is correct behavior)
> > >return y;
> > > }
> > > ```
> > > 
> > > ```
> > > X foo(bool b, X x) {
> > >if (b)
> > >   return x;
> > > 
> > >X y;
> > >// when we process this return statement, the parent contains nullptr 
> > > (invalid candidate) and it WON't be invalidated (this is correct behavior)
> > >return y;
> > > }
> > > ```
> > Oh, I see. Tricky. I don't find invalid cases now. But I recommend to 
> > comment that the children would maintain the `ReturnSlots` of their 
> > parents. (This is anti-intuition)
> > 
> > Have you tested any larger projects? Like libc++, libstdc++ or something 
> > like folly. I feel we need to do such tests to avoid we get anything wrong.
> I've already added a comment at the beginning of `updateNRVOCandidate` 
> function where this point is mentioned: 
> ```
> //  ... Therefore, we need to clear return slots for other
> //  variables defined before the current return statement in the current
> //  scope and in outer scopes.
> ```
> If it's not enough, please let me know.
> 
> 
> > Have you tested any larger projects?
> 
> Yes, I've built the `clang` itself and `compiler-rt` project. Then I've 
> checked them to run 'check-all' (on built clang and compiler-rt). Everything  
> works.
Great! Clang should be large enough.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D130411: [clang-format] Fix a hang when formatting C# $@ string literals

2022-07-25 Thread Owen Pan 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 rG0ffb3dd33ee1: [clang-format] Fix a hang when formatting C# 
$@ string literals (authored by owenpan).

Changed prior to commit:
  https://reviews.llvm.org/D130411?vs=447041&id=447575#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130411

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

Index: clang/unittests/Format/FormatTestCSharp.cpp
===
--- clang/unittests/Format/FormatTestCSharp.cpp
+++ clang/unittests/Format/FormatTestCSharp.cpp
@@ -574,6 +574,7 @@
   verifyFormat(R"(string str = @;)", Style);
   verifyFormat(R"(string str = @"""Hello world""";)", Style);
   verifyFormat(R"(string str = $@"""Hello {friend}""";)", Style);
+  verifyFormat(R"(return $@"Foo ""/foo?f={Request.Query["f"]}""";)", Style);
 }
 
 TEST_F(FormatTestCSharp, CSharpQuotesInInterpolatedStrings) {
Index: clang/lib/Format/FormatTokenLexer.cpp
===
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -239,55 +239,6 @@
   if (Tokens.size() < 2)
 return false;
 
-  // Interpolated strings could contain { } with " characters inside.
-  // $"{x ?? "null"}"
-  // should not be split into $"{x ?? ", null, "}" but should treated as a
-  // single string-literal.
-  //
-  // We opt not to try and format expressions inside {} within a C#
-  // interpolated string. Formatting expressions within an interpolated string
-  // would require similar work as that done for JavaScript template strings
-  // in `handleTemplateStrings()`.
-  auto &CSharpInterpolatedString = *(Tokens.end() - 2);
-  if (CSharpInterpolatedString->getType() == TT_CSharpStringLiteral &&
-  (CSharpInterpolatedString->TokenText.startswith(R"($")") ||
-   CSharpInterpolatedString->TokenText.startswith(R"($@")"))) {
-int UnmatchedOpeningBraceCount = 0;
-
-auto TokenTextSize = CSharpInterpolatedString->TokenText.size();
-for (size_t Index = 0; Index < TokenTextSize; ++Index) {
-  char C = CSharpInterpolatedString->TokenText[Index];
-  if (C == '{') {
-// "{{"  inside an interpolated string is an escaped '{' so skip it.
-if (Index + 1 < TokenTextSize &&
-CSharpInterpolatedString->TokenText[Index + 1] == '{') {
-  ++Index;
-  continue;
-}
-++UnmatchedOpeningBraceCount;
-  } else if (C == '}') {
-// "}}"  inside an interpolated string is an escaped '}' so skip it.
-if (Index + 1 < TokenTextSize &&
-CSharpInterpolatedString->TokenText[Index + 1] == '}') {
-  ++Index;
-  continue;
-}
---UnmatchedOpeningBraceCount;
-  }
-}
-
-if (UnmatchedOpeningBraceCount > 0) {
-  auto &NextToken = *(Tokens.end() - 1);
-  CSharpInterpolatedString->TokenText =
-  StringRef(CSharpInterpolatedString->TokenText.begin(),
-NextToken->TokenText.end() -
-CSharpInterpolatedString->TokenText.begin());
-  CSharpInterpolatedString->ColumnWidth += NextToken->ColumnWidth;
-  Tokens.erase(Tokens.end() - 1);
-  return true;
-}
-  }
-
   // Look for @"aa" or $"aa".
   auto &String = *(Tokens.end() - 1);
   if (!String->is(tok::string_literal))
@@ -571,45 +522,105 @@
   resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset)));
 }
 
+static auto lexCSharpString(const char *Begin, const char *End, bool Verbatim,
+bool Interpolated) {
+  auto Repeated = [&Begin, End]() {
+return Begin + 1 < End && Begin[1] == Begin[0];
+  };
+
+  // Look for a terminating '"' in the current file buffer.
+  // Make no effort to format code within an interpolated or verbatim string.
+  //
+  // Interpolated strings could contain { } with " characters inside.
+  // $"{x ?? "null"}"
+  // should not be split into $"{x ?? ", null, "}" but should be treated as a
+  // single string-literal.
+  //
+  // We opt not to try and format expressions inside {} within a C#
+  // interpolated string. Formatting expressions within an interpolated string
+  // would require similar work as that done for JavaScript template strings
+  // in `handleTemplateStrings()`.
+  for (int UnmatchedOpeningBraceCount = 0; Begin < End; ++Begin) {
+switch (*Begin) {
+case '\\':
+  if (!Verbatim)
+++Begin;
+  break;
+case '{':
+  if (Interpolated) {
+// {{ inside an interpolated string is escaped, so skip it.
+if (Repeated())
+  ++Begin;
+else
+  ++UnmatchedOpeningBraceCount;
+  }
+  break;
+case '}':
+  if (Interpolated) {
+// }} inside an interpola

[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Roman Rusyaev via Phabricator via cfe-commits
rusyaev-roman added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

ChuanqiXu wrote:
> rusyaev-roman wrote:
> > ChuanqiXu wrote:
> > > What if NRVO contains a value already? It is possible due to the value of 
> > > NRVO could be set by its children.
> > Actually this is intention. If the parent has already NRVO candidate, then 
> > it should be invalidated (or not). Let's consider the following examples:
> > 
> > 
> > ```
> > X foo(bool b) {
> >X x;
> >X y;
> >if (b)
> >   return x;
> >else
> >   return y; // when we process this return statement, the parent has 
> > already NRVO and it will be invalidated (this is correct behavior)
> > }
> > ```
> > 
> > ```
> > X foo(bool b) {
> >X x;
> >if (b)
> >   return x;
> >
> >X y;
> >// when we process this return statement, the parent has already NRVO 
> > and it WON't be invalidated
> >//  (this is correct behavior), because a return slot will be available 
> > for it
> >return y;
> > }
> > ```
> > 
> > ```
> > X foo(bool b) {
> >X x;
> >if (b)
> >   return x;
> > 
> >// when we process this return statement, the parent has already NRVO 
> > and it WON't be invalidated (this is correct behavior)
> >return x;
> > }
> > ```
> > 
> > ```
> > X foo(bool b, X x) {
> >X y;
> >
> >if (b)
> >   return x;
> > 
> >// when we process this return statement, the parent contains nullptr 
> > (invalid candidate) and it will be invalidated (this is correct behavior)
> >return y;
> > }
> > ```
> > 
> > ```
> > X foo(bool b, X x) {
> >if (b)
> >   return x;
> > 
> >X y;
> >// when we process this return statement, the parent contains nullptr 
> > (invalid candidate) and it WON't be invalidated (this is correct behavior)
> >return y;
> > }
> > ```
> Oh, I see. Tricky. I don't find invalid cases now. But I recommend to comment 
> that the children would maintain the `ReturnSlots` of their parents. (This is 
> anti-intuition)
> 
> Have you tested any larger projects? Like libc++, libstdc++ or something like 
> folly. I feel we need to do such tests to avoid we get anything wrong.
I've already added a comment at the beginning of `updateNRVOCandidate` function 
where this point is mentioned: 
```
//  ... Therefore, we need to clear return slots for other
//  variables defined before the current return statement in the current
//  scope and in outer scopes.
```
If it's not enough, please let me know.


> Have you tested any larger projects?

Yes, I've built the `clang` itself and `compiler-rt` project. Then I've checked 
them to run 'check-all' (on built clang and compiler-rt). Everything  works.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D130331: [C++20] [Modules] Disable preferred_name when writing a C++20 Module interface

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

Sorry for the frequent ping since 15.x is going to be branched. @aaron.ballman 
@tahonermann I know this might not look good to you. But I want to ask if there 
is any objection? Personally, the preferred_name attribute is not so important 
and it blocks something important. I really want to get this landed. And as 
@erichkeane said in D129748 , I'll take an 
eye on this.


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

https://reviews.llvm.org/D130331

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


[clang] 0ffb3dd - [clang-format] Fix a hang when formatting C# $@ string literals

2022-07-25 Thread via cfe-commits

Author: owenca
Date: 2022-07-25T23:17:54-07:00
New Revision: 0ffb3dd33ee1a50a6ab5db80bb8caee9133e66dc

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

LOG: [clang-format] Fix a hang when formatting C# $@ string literals

Fixes #56624.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index 66f03dcb53a12..3f9b68ccbb39f 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -239,55 +239,6 @@ bool FormatTokenLexer::tryMergeCSharpStringLiteral() {
   if (Tokens.size() < 2)
 return false;
 
-  // Interpolated strings could contain { } with " characters inside.
-  // $"{x ?? "null"}"
-  // should not be split into $"{x ?? ", null, "}" but should treated as a
-  // single string-literal.
-  //
-  // We opt not to try and format expressions inside {} within a C#
-  // interpolated string. Formatting expressions within an interpolated string
-  // would require similar work as that done for JavaScript template strings
-  // in `handleTemplateStrings()`.
-  auto &CSharpInterpolatedString = *(Tokens.end() - 2);
-  if (CSharpInterpolatedString->getType() == TT_CSharpStringLiteral &&
-  (CSharpInterpolatedString->TokenText.startswith(R"($")") ||
-   CSharpInterpolatedString->TokenText.startswith(R"($@")"))) {
-int UnmatchedOpeningBraceCount = 0;
-
-auto TokenTextSize = CSharpInterpolatedString->TokenText.size();
-for (size_t Index = 0; Index < TokenTextSize; ++Index) {
-  char C = CSharpInterpolatedString->TokenText[Index];
-  if (C == '{') {
-// "{{"  inside an interpolated string is an escaped '{' so skip it.
-if (Index + 1 < TokenTextSize &&
-CSharpInterpolatedString->TokenText[Index + 1] == '{') {
-  ++Index;
-  continue;
-}
-++UnmatchedOpeningBraceCount;
-  } else if (C == '}') {
-// "}}"  inside an interpolated string is an escaped '}' so skip it.
-if (Index + 1 < TokenTextSize &&
-CSharpInterpolatedString->TokenText[Index + 1] == '}') {
-  ++Index;
-  continue;
-}
---UnmatchedOpeningBraceCount;
-  }
-}
-
-if (UnmatchedOpeningBraceCount > 0) {
-  auto &NextToken = *(Tokens.end() - 1);
-  CSharpInterpolatedString->TokenText =
-  StringRef(CSharpInterpolatedString->TokenText.begin(),
-NextToken->TokenText.end() -
-CSharpInterpolatedString->TokenText.begin());
-  CSharpInterpolatedString->ColumnWidth += NextToken->ColumnWidth;
-  Tokens.erase(Tokens.end() - 1);
-  return true;
-}
-  }
-
   // Look for @"aa" or $"aa".
   auto &String = *(Tokens.end() - 1);
   if (!String->is(tok::string_literal))
@@ -571,45 +522,105 @@ void FormatTokenLexer::tryParseJSRegexLiteral() {
   resetLexer(SourceMgr.getFileOffset(Lex->getSourceLocation(Offset)));
 }
 
+static auto lexCSharpString(const char *Begin, const char *End, bool Verbatim,
+bool Interpolated) {
+  auto Repeated = [&Begin, End]() {
+return Begin + 1 < End && Begin[1] == Begin[0];
+  };
+
+  // Look for a terminating '"' in the current file buffer.
+  // Make no effort to format code within an interpolated or verbatim string.
+  //
+  // Interpolated strings could contain { } with " characters inside.
+  // $"{x ?? "null"}"
+  // should not be split into $"{x ?? ", null, "}" but should be treated as a
+  // single string-literal.
+  //
+  // We opt not to try and format expressions inside {} within a C#
+  // interpolated string. Formatting expressions within an interpolated string
+  // would require similar work as that done for JavaScript template strings
+  // in `handleTemplateStrings()`.
+  for (int UnmatchedOpeningBraceCount = 0; Begin < End; ++Begin) {
+switch (*Begin) {
+case '\\':
+  if (!Verbatim)
+++Begin;
+  break;
+case '{':
+  if (Interpolated) {
+// {{ inside an interpolated string is escaped, so skip it.
+if (Repeated())
+  ++Begin;
+else
+  ++UnmatchedOpeningBraceCount;
+  }
+  break;
+case '}':
+  if (Interpolated) {
+// }} inside an interpolated string is escaped, so skip it.
+if (Repeated())
+  ++Begin;
+else if (UnmatchedOpeningBraceCount > 0)
+  --UnmatchedOpeningBraceCount;
+else
+  return End;
+  }
+  break;
+case '"':
+  if (UnmatchedOpeningBraceCount > 0)
+break;
+  // "" within a verbatim string is an esc

[PATCH] D130514: [CMake][Fuchsia] Enable assertions and backtraces in stage 1 build

2022-07-25 Thread Alex Brachet 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 rG0df7d8bc355d: [CMake][Fuchsia] Enable assertions and 
backtraces in stage 1 build (authored by abrachet).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130514

Files:
  clang/cmake/caches/Fuchsia.cmake


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -34,8 +34,8 @@
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES ON CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")


Index: clang/cmake/caches/Fuchsia.cmake
===
--- clang/cmake/caches/Fuchsia.cmake
+++ clang/cmake/caches/Fuchsia.cmake
@@ -34,8 +34,8 @@
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES ON CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0df7d8b - [CMake][Fuchsia] Enable assertions and backtraces in stage 1 build

2022-07-25 Thread Alex Brachet via cfe-commits

Author: Alex Brachet
Date: 2022-07-26T06:09:38Z
New Revision: 0df7d8bc355dd506bb1a330b9f73e611f0deaf9f

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

LOG: [CMake][Fuchsia] Enable assertions and backtraces in stage 1 build

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

Added: 


Modified: 
clang/cmake/caches/Fuchsia.cmake

Removed: 




diff  --git a/clang/cmake/caches/Fuchsia.cmake 
b/clang/cmake/caches/Fuchsia.cmake
index 73ef571507179..1978195c267d9 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -34,8 +34,8 @@ set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
 set(ENABLE_LINKER_BUILD_ID ON CACHE BOOL "")
 set(ENABLE_X86_RELAX_RELOCATIONS ON CACHE BOOL "")
 
-set(LLVM_ENABLE_ASSERTIONS OFF CACHE BOOL "")
-set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
+set(LLVM_ENABLE_ASSERTIONS ON CACHE BOOL "")
+set(LLVM_ENABLE_BACKTRACES ON CACHE BOOL "")
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 if(APPLE)
   set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "")



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


[clang-tools-extra] 3f3930a - Remove redundaunt virtual specifiers (NFC)

2022-07-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-07-25T23:00:59-07:00
New Revision: 3f3930a451e118e82885a6dd20e3918427b816c2

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

LOG: Remove redundaunt virtual specifiers (NFC)

Identified with tidy-modernize-use-override.

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/SharedPtrArrayMismatchCheck.h
clang-tools-extra/clangd/AST.cpp
clang-tools-extra/clangd/support/ThreadsafeFS.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
clang/lib/CodeGen/MicrosoftCXXABI.cpp
clang/lib/Sema/Sema.cpp
clang/lib/StaticAnalyzer/Checkers/InnerPointerChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/Target/Mips/MipsPreLegalizerCombiner.cpp
llvm/lib/Target/RISCV/RISCVInstrInfo.h
llvm/lib/Target/X86/X86InstrInfo.h
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
polly/include/polly/CodeGen/BlockGenerators.h
polly/include/polly/CodeGen/LoopGeneratorsGOMP.h
polly/include/polly/CodeGen/LoopGeneratorsKMP.h
polly/include/polly/ScopPass.h
polly/lib/CodeGen/CodegenCleanup.cpp
polly/lib/Support/DumpFunctionPass.cpp
polly/lib/Support/DumpModulePass.cpp
polly/lib/Transform/DeLICM.cpp
polly/lib/Transform/FlattenSchedule.cpp
polly/lib/Transform/Simplify.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/SharedPtrArrayMismatchCheck.h 
b/clang-tools-extra/clang-tidy/bugprone/SharedPtrArrayMismatchCheck.h
index bb549c5a2c695..95b8e22588a50 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SharedPtrArrayMismatchCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SharedPtrArrayMismatchCheck.h
@@ -28,7 +28,7 @@ class SharedPtrArrayMismatchCheck : public 
SmartPtrArrayMismatchCheck {
   SharedPtrArrayMismatchCheck(StringRef Name, ClangTidyContext *Context);
 
 protected:
-  virtual SmartPtrClassMatcher getSmartPointerClassMatcher() const override;
+  SmartPtrClassMatcher getSmartPointerClassMatcher() const override;
 };
 
 } // namespace bugprone

diff  --git a/clang-tools-extra/clangd/AST.cpp 
b/clang-tools-extra/clangd/AST.cpp
index 0c67c548e6c20..f7d526fab0963 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -368,7 +368,7 @@ std::string printType(const QualType QT, const DeclContext 
&CurContext,
   public:
 PrintCB(const DeclContext *CurContext) : CurContext(CurContext) {}
 virtual ~PrintCB() {}
-virtual bool isScopeVisible(const DeclContext *DC) const override {
+bool isScopeVisible(const DeclContext *DC) const override {
   return DC->Encloses(CurContext);
 }
 

diff  --git a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp 
b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
index efd7e8cc6079c..dca04762b49a6 100644
--- a/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
+++ b/clang-tools-extra/clangd/support/ThreadsafeFS.cpp
@@ -53,7 +53,7 @@ class VolatileFileSystem : public llvm::vfs::ProxyFileSystem {
   assert(this->Wrapped);
 }
 
-virtual llvm::ErrorOr>
+llvm::ErrorOr>
 getBuffer(const llvm::Twine &Name, int64_t FileSize,
   bool RequiresNullTerminator, bool /*IsVolatile*/) override {
   return Wrapped->getBuffer(Name, FileSize, RequiresNullTerminator,

diff  --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h
index ea98dcf42de65..0affa58b2f4c0 100644
--- a/clang/lib/Basic/Targets/X86.h
+++ b/clang/lib/Basic/Targets/X86.h
@@ -229,12 +229,12 @@ class LLVM_LIBRARY_VISIBILITY X86TargetInfo : public 
TargetInfo {
   bool validateInputSize(const llvm::StringMap &FeatureMap,
  StringRef Constraint, unsigned Size) const override;
 
-  virtual bool
+  bool
   checkCFProtectionReturnSupported(DiagnosticsEngine &Diags) const override {
 return true;
   };
 
-  virtual bool
+  bool
   checkCFProtectionBranchSupported(DiagnosticsEngine &Diags) const override {
 return true;
   };

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
index 1d30c5061743a..ff585efa3fce2 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.h
@@ -186,17 +186,16 @@ class CGOpenMPRuntimeGPU : public CGOpenMPRuntime {
 
   /// Emit call to void __kmpc_push_proc_bind(ident_t *loc, kmp_int32
   /// global_tid, int proc_bind) to generate code for 'proc_bind' clause.
-  virtual void emitProcBindClause(CodeGenFunction &CGF,
-  llvm::omp::ProcBindKind ProcBind,
-   

[clang] ae002f8 - Use isa instead of dyn_cast (NFC)

2022-07-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2022-07-25T23:00:58-07:00
New Revision: ae002f8bca11bf652fa4d2683c8a627fa77158a8

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

LOG: Use isa instead of dyn_cast (NFC)

Added: 


Modified: 
clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp
mlir/lib/TableGen/Pattern.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp 
b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index 08fac9fb2e698..f12a0ee1fc6db 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -908,7 +908,7 @@ void ExprEngine::VisitCXXNewExpr(const CXXNewExpr *CNE, 
ExplodedNode *Pred,
   // values are properly placed inside the required region, however if an
   // initializer list is used, this doesn't happen automatically.
   auto *Init = CNE->getInitializer();
-  bool isInitList = dyn_cast_or_null(Init);
+  bool isInitList = isa_and_nonnull(Init);
 
   QualType ObjTy =
   isInitList ? Init->getType() : CNE->getType()->getPointeeType();

diff  --git a/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp 
b/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp
index e77c82e0fad9a..c91674426bbb0 100644
--- a/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp
+++ b/llvm/tools/llvm-dwarfutil/llvm-dwarfutil.cpp
@@ -292,7 +292,7 @@ using DebugInfoBits = SmallString<1>;
 static Error addSectionsFromLinkedData(objcopy::ConfigManager &Config,
ObjectFile &InputFile,
DebugInfoBits &LinkedDebugInfoBits) {
-  if (dyn_cast>(&InputFile)) {
+  if (isa>(&InputFile)) {
 Expected> MemFile = ELFObjectFile::create(
 MemoryBufferRef(LinkedDebugInfoBits, ""));
 if (!MemFile)
@@ -300,7 +300,7 @@ static Error 
addSectionsFromLinkedData(objcopy::ConfigManager &Config,
 
 if (Error Err = setConfigToAddNewDebugSections(Config, *MemFile))
   return Err;
-  } else if (dyn_cast>(&InputFile)) {
+  } else if (isa>(&InputFile)) {
 Expected> MemFile = ELFObjectFile::create(
 MemoryBufferRef(LinkedDebugInfoBits, ""));
 if (!MemFile)
@@ -308,7 +308,7 @@ static Error 
addSectionsFromLinkedData(objcopy::ConfigManager &Config,
 
 if (Error Err = setConfigToAddNewDebugSections(Config, *MemFile))
   return Err;
-  } else if (dyn_cast>(&InputFile)) {
+  } else if (isa>(&InputFile)) {
 Expected> MemFile = ELFObjectFile::create(
 MemoryBufferRef(LinkedDebugInfoBits, ""));
 if (!MemFile)
@@ -316,7 +316,7 @@ static Error 
addSectionsFromLinkedData(objcopy::ConfigManager &Config,
 
 if (Error Err = setConfigToAddNewDebugSections(Config, *MemFile))
   return Err;
-  } else if (dyn_cast>(&InputFile)) {
+  } else if (isa>(&InputFile)) {
 Expected> MemFile = ELFObjectFile::create(
 MemoryBufferRef(LinkedDebugInfoBits, ""));
 if (!MemFile)

diff  --git a/mlir/lib/TableGen/Pattern.cpp b/mlir/lib/TableGen/Pattern.cpp
index de767d6d3a6a1..d833de5100cc3 100644
--- a/mlir/lib/TableGen/Pattern.cpp
+++ b/mlir/lib/TableGen/Pattern.cpp
@@ -33,7 +33,7 @@ using llvm::formatv;
 
//===--===//
 
 bool DagLeaf::isUnspecified() const {
-  return dyn_cast_or_null(def);
+  return isa_and_nonnull(def);
 }
 
 bool DagLeaf::isOperandMatcher() const {



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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

rusyaev-roman wrote:
> ChuanqiXu wrote:
> > What if NRVO contains a value already? It is possible due to the value of 
> > NRVO could be set by its children.
> Actually this is intention. If the parent has already NRVO candidate, then it 
> should be invalidated (or not). Let's consider the following examples:
> 
> 
> ```
> X foo(bool b) {
>X x;
>X y;
>if (b)
>   return x;
>else
>   return y; // when we process this return statement, the parent has 
> already NRVO and it will be invalidated (this is correct behavior)
> }
> ```
> 
> ```
> X foo(bool b) {
>X x;
>if (b)
>   return x;
>
>X y;
>// when we process this return statement, the parent has already NRVO and 
> it WON't be invalidated
>//  (this is correct behavior), because a return slot will be available 
> for it
>return y;
> }
> ```
> 
> ```
> X foo(bool b) {
>X x;
>if (b)
>   return x;
> 
>// when we process this return statement, the parent has already NRVO and 
> it WON't be invalidated (this is correct behavior)
>return x;
> }
> ```
> 
> ```
> X foo(bool b, X x) {
>X y;
>
>if (b)
>   return x;
> 
>// when we process this return statement, the parent contains nullptr 
> (invalid candidate) and it will be invalidated (this is correct behavior)
>return y;
> }
> ```
> 
> ```
> X foo(bool b, X x) {
>if (b)
>   return x;
> 
>X y;
>// when we process this return statement, the parent contains nullptr 
> (invalid candidate) and it WON't be invalidated (this is correct behavior)
>return y;
> }
> ```
Oh, I see. Tricky. I don't find invalid cases now. But I recommend to comment 
that the children would maintain the `ReturnSlots` of their parents. (This is 
anti-intuition)

Have you tested any larger projects? Like libc++, libstdc++ or something like 
folly. I feel we need to do such tests to avoid we get anything wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-07-25 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic added inline comments.



Comment at: clang/include/clang/Driver/Options.td:4897
 def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, 
Group, Alias;
+def fconvert_EQ : Joined<["-"], "fconvert=">, Group,
+  HelpText<"Set endian conversion of data for unformatted files">;

peixin wrote:
> Why do you move it here? Maybe it is not implemented now, clang may need this 
> option eventually. @MaskRay 
I was using the fixed line length options as a reference for how to handle 
this--based on the discussion in the review here 
(https://reviews.llvm.org/D95460) about forwarding options to gfortran, I was 
thinking that it would also be safe to handle fconvert similarly, but I'm not 
100% sure and definitely might be misunderstanding something!



Comment at: clang/lib/Driver/ToolChains/Flang.cpp:52
+options::OPT_fno_automatic,
+options::OPT_fconvert_EQ});
 }

Reading through https://reviews.llvm.org/D95460 again, I'm not sure this is the 
appropriate place to add . I am marking this as a TODO that I will revisit with 
the other feedback!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130513

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


[clang] 620ca75 - fix comment typo to cycle bots

2022-07-25 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-07-26T01:55:10-04:00
New Revision: 620ca754e3f769f2be4668feccee84071d785be3

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

LOG: fix comment typo to cycle bots

Added: 


Modified: 
clang/tools/libclang/CIndex.cpp

Removed: 




diff  --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 776761db2b1c..9356dd4a2377 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -7371,7 +7371,7 @@ AnnotateTokensWorker::PostChildrenActions
 AnnotateTokensWorker::DetermineChildActions(CXCursor Cursor) const {
   PostChildrenActions actions;
 
-  // The DeclRefExpr of CXXOperatorCallExpr refering to the custom operator is
+  // The DeclRefExpr of CXXOperatorCallExpr referring to the custom operator is
   // visited before the arguments to the operator call. For the Call and
   // Subscript operator the range of this DeclRefExpr includes the whole call
   // expression, so that all tokens in that range would be mapped to the



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


[PATCH] D130545: [cmake] Slight fix ups to make robust to the full range of GNUInstallDirs

2022-07-25 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 447569.
Ericson2314 added a comment.
Herald added a reviewer: jdoerfert.
Herald added subscribers: llvm-commits, sstefan1.
Herald added a project: LLVM.

Add another fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130545

Files:
  clang/tools/clang-linker-wrapper/CMakeLists.txt
  llvm-libgcc/lib/CMakeLists.txt
  llvm/cmake/modules/CMakeLists.txt
  openmp/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt

Index: openmp/runtime/src/CMakeLists.txt
===
--- openmp/runtime/src/CMakeLists.txt
+++ openmp/runtime/src/CMakeLists.txt
@@ -8,6 +8,8 @@
 #//===--===//
 #
 
+include(ExtendPath)
+
 # Configure omp.h, kmp_config.h and omp-tools.h if necessary
 configure_file(${LIBOMP_INC_DIR}/omp.h.var omp.h @ONLY)
 configure_file(kmp_config.h.cmake kmp_config.h @ONLY)
@@ -347,8 +349,8 @@
 add_dependencies(libomp-micro-tests libomp-test-deps)
 
 # Install rules
-# We want to install libomp in DESTDIR/CMAKE_INSTALL_PREFIX/lib
-# We want to install headers in DESTDIR/CMAKE_INSTALL_PREFIX/include
+# We want to install libomp in ${DESTDIR}/${CMAKE_INSTALL_FULL_LIBDIR}
+# We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR}
 if(${OPENMP_STANDALONE_BUILD})
   set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
 else()
@@ -362,9 +364,10 @@
   set(LIBOMP_ALIASES "libiomp5md")
   foreach(alias IN LISTS LIBOMP_ALIASES)
 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\"
-  \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\")")
+  \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${CMAKE_INSTALL_FULL_BINDIR}\")")
+extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\"
-  \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")")
+  \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${outdir}\")")
   endforeach()
 else()
 
@@ -374,9 +377,10 @@
 # Create aliases (symlinks) of the library for backwards compatibility
 set(LIBOMP_ALIASES "libgomp;libiomp5")
 foreach(alias IN LISTS LIBOMP_ALIASES)
+  extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
   install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
 \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY
-\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")")
+\"\$ENV{DESTDIR}\${outdir}\")")
 endforeach()
   endif()
 endif()
Index: openmp/CMakeLists.txt
===
--- openmp/CMakeLists.txt
+++ openmp/CMakeLists.txt
@@ -1,7 +1,12 @@
 cmake_minimum_required(VERSION 3.13.4)
 
-# Add cmake directory to search for custom cmake functions.
-set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
+set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
+
+# Add path for custom modules
+list(INSERT CMAKE_MODULE_PATH 0
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
+  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
+  )
 
 # llvm/runtimes/ will set OPENMP_STANDALONE_BUILD.
 if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
Index: llvm/cmake/modules/CMakeLists.txt
===
--- llvm/cmake/modules/CMakeLists.txt
+++ llvm/cmake/modules/CMakeLists.txt
@@ -137,6 +137,7 @@
 
 set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}")
 extend_path(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}" "${LLVM_INSTALL_PACKAGE_DIR}")
+extend_path(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}" "${LLVM_TOOLS_INSTALL_DIR}")
 
 # Generate a default location for lit
 if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
Index: llvm-libgcc/lib/CMakeLists.txt
===
--- llvm-libgcc/lib/CMakeLists.txt
+++ llvm-libgcc/lib/CMakeLists.txt
@@ -1,5 +1,6 @@
 include(CheckLibraryExists)
 include(GNUInstallDirs)
+include(ExtendPath)
 
 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
 
@@ -41,13 +42,13 @@
   c
 )
 
-get_filename_component(LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${CMAKE_INSTALL_PREFIX}/${LIBUNWIND_INSTALL_LIBRARY_DIR}" ABSOLUTE)
+extend_path(LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${CMAKE_INSTALL_PREFIX}" "${LIBUNWIND_INSTALL_LIBRARY_DIR}")
 #string(REPLACE "${CMAKE_INSTALL_FULL_LIBDIR}/" "" LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}")
 
 install(TARGETS libgcc_s
 LIBRARY DESTINATION "${LL

[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Roman Rusyaev via Phabricator via cfe-commits
rusyaev-roman added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

ChuanqiXu wrote:
> What if NRVO contains a value already? It is possible due to the value of 
> NRVO could be set by its children.
Actually this is intention. If the parent has already NRVO candidate, then it 
should be invalidated (or not). Let's consider the following examples:


```
X foo(bool b) {
   X x;
   X y;
   if (b)
  return x;
   else
  return y; // when we process this return statement, the parent has 
already NRVO and it will be invalidated (this is correct behavior)
}
```

```
X foo(bool b) {
   X x;
   if (b)
  return x;
   
   X y;
   // when we process this return statement, the parent has already NRVO and it 
WON't be invalidated
   //  (this is correct behavior), because a return slot will be available for 
it
   return y;
}
```

```
X foo(bool b) {
   X x;
   if (b)
  return x;

   // when we process this return statement, the parent has already NRVO and it 
WON't be invalidated (this is correct behavior)
   return x;
}
```

```
X foo(bool b, X x) {
   X y;
   
   if (b)
  return x;

   // when we process this return statement, the parent contains nullptr 
(invalid candidate) and it will be invalidated (this is correct behavior)
   return y;
}
```

```
X foo(bool b, X x) {
   if (b)
  return x;

   X y;
   // when we process this return statement, the parent contains nullptr 
(invalid candidate) and it WON't be invalidated (this is correct behavior)
   return y;
}
```



Comment at: clang/lib/Sema/Scope.cpp:184-185
+  //}
+  if (!getEntity())
+getParent()->NRVO = *NRVO;
 }

ChuanqiXu wrote:
> There is a similar problem. It looks not right if the NRVO of the parent owns 
> a value already.
Yes, this is intention. You can take a look at the above comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D129160: libclang.so: Make SONAME the same as LLVM version

2022-07-25 Thread Tom Stellard via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbc39d7bdd497: libclang.so: Make SONAME the same as LLVM 
version (authored by tstellar).

Changed prior to commit:
  https://reviews.llvm.org/D129160?vs=444843&id=447566#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129160

Files:
  clang/docs/ReleaseNotes.rst
  clang/tools/libclang/CMakeLists.txt
  clang/tools/libclang/libclang.exports
  clang/tools/libclang/libclang.map
  clang/tools/libclang/linker-script-to-export-list.py

Index: clang/tools/libclang/linker-script-to-export-list.py
===
--- clang/tools/libclang/linker-script-to-export-list.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import re
-import os
-import sys
-
-input_file = open(sys.argv[1])
-output_file = open(sys.argv[2], 'w')
-
-for line in input_file:
-m = re.search('^\s+(clang_[^;]+)', line)
-if m:
-output_file.write(m.group(1) + "\n")
Index: clang/tools/libclang/libclang.map
===
--- clang/tools/libclang/libclang.map
+++ /dev/null
@@ -1,413 +0,0 @@
-# If you add a symbol to this file, make sure to add it with the correct
-# version.  For example, if the LLVM main branch is LLVM 14.0.0, add new
-# symbols with the version LLVM_14.
-# On platforms where versions scripts are not used, this file will be used to
-# generate a list of exports for libclang.so
-
-LLVM_13 {
-  global:
-clang_BlockCommandComment_getArgText;
-clang_BlockCommandComment_getCommandName;
-clang_BlockCommandComment_getNumArgs;
-clang_BlockCommandComment_getParagraph;
-clang_CXCursorSet_contains;
-clang_CXCursorSet_insert;
-clang_CXIndex_getGlobalOptions;
-clang_CXIndex_setGlobalOptions;
-clang_CXIndex_setInvocationEmissionPathOption;
-clang_CXRewriter_create;
-clang_CXRewriter_dispose;
-clang_CXRewriter_insertTextBefore;
-clang_CXRewriter_overwriteChangedFiles;
-clang_CXRewriter_removeText;
-clang_CXRewriter_replaceText;
-clang_CXRewriter_writeMainFileToStdOut;
-clang_CXXConstructor_isConvertingConstructor;
-clang_CXXConstructor_isCopyConstructor;
-clang_CXXConstructor_isDefaultConstructor;
-clang_CXXConstructor_isMoveConstructor;
-clang_CXXField_isMutable;
-clang_CXXMethod_isConst;
-clang_CXXMethod_isDefaulted;
-clang_CXXMethod_isPureVirtual;
-clang_CXXMethod_isStatic;
-clang_CXXMethod_isVirtual;
-clang_CXXRecord_isAbstract;
-clang_Comment_getChild;
-clang_Comment_getKind;
-clang_Comment_getNumChildren;
-clang_Comment_isWhitespace;
-clang_CompilationDatabase_dispose;
-clang_CompilationDatabase_fromDirectory;
-clang_CompilationDatabase_getAllCompileCommands;
-clang_CompilationDatabase_getCompileCommands;
-clang_CompileCommand_getArg;
-clang_CompileCommand_getDirectory;
-clang_CompileCommand_getFilename;
-clang_CompileCommand_getMappedSourceContent;
-clang_CompileCommand_getMappedSourcePath;
-clang_CompileCommand_getNumArgs;
-clang_CompileCommand_getNumMappedSources;
-clang_CompileCommands_dispose;
-clang_CompileCommands_getCommand;
-clang_CompileCommands_getSize;
-clang_Cursor_Evaluate;
-clang_Cursor_getArgument;
-clang_Cursor_getBriefCommentText;
-clang_Cursor_getCXXManglings;
-clang_Cursor_getCommentRange;
-clang_Cursor_getMangling;
-clang_Cursor_getModule;
-clang_Cursor_getNumArguments;
-clang_Cursor_getNumTemplateArguments;
-clang_Cursor_getObjCDeclQualifiers;
-clang_Cursor_getObjCManglings;
-clang_Cursor_getObjCPropertyAttributes;
-clang_Cursor_getObjCPropertyGetterName;
-clang_Cursor_getObjCPropertySetterName;
-clang_Cursor_getObjCSelectorIndex;
-clang_Cursor_getOffsetOfField;
-clang_Cursor_getParsedComment;
-clang_Cursor_getRawCommentText;
-clang_Cursor_getReceiverType;
-clang_Cursor_getSpellingNameRange;
-clang_Cursor_getStorageClass;
-clang_Cursor_getTemplateArgumentKind;
-clang_Cursor_getTemplateArgumentType;
-clang_Cursor_getTemplateArgumentUnsignedValue;
-clang_Cursor_getTemplateArgumentValue;
-clang_Cursor_getTranslationUnit;
-clang_Cursor_getVarDeclInitializer;
-clang_Cursor_hasAttrs;
-clang_Cursor_hasVarDeclExternalStorage;
-clang_Cursor_hasVarDeclGlobalStorage;
-clang_Cursor_isAnonymous;
-clang_Cursor_isAnonymousRecordDecl;
-clang_Cursor_isBitField;
-clang_Cursor_isDynamicCall;
-clang_Cursor_isExternalSymbol;
-clang_Cursor_isFunctionInlined;
-clang_Cursor_isInlineNamespace;
-clang_Cursor_isMacroBuiltin;
-clang_Cursor_isMacroFunctionLike;
-clang_Cursor_isNull;
-clang_Cursor_isObjCOptional;
-clang_Cursor_isVariadic;
-clang_EnumDecl_isScoped;
-clang_EvalResult_dispose;
-clang_EvalResult_getAsDou

[clang] bc39d7b - libclang.so: Make SONAME the same as LLVM version

2022-07-25 Thread Tom Stellard via cfe-commits

Author: Tom Stellard
Date: 2022-07-25T22:03:34-07:00
New Revision: bc39d7bdd4977a953b2e102f8f7eb479ad78984e

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

LOG: libclang.so: Make SONAME the same as LLVM version

This partially reverts c7b3a91017d26266d7556b1ac7c49b06f0109b91.  Having
libclang.so with a different SONAME than the other LLVM libraries was
causing a lot of confusion for users.  Also, this change did not really
acheive it's purpose of allowing apps to use newer versions of
libclang.so without rebuilding, because a new version of libclang.so
requires a new version of libLLVM.so, which does not have a stable ABI.

Reviewed By: MaskRay

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

Added: 
clang/tools/libclang/libclang.exports

Modified: 
clang/docs/ReleaseNotes.rst
clang/tools/libclang/CMakeLists.txt

Removed: 
clang/tools/libclang/libclang.map
clang/tools/libclang/linker-script-to-export-list.py



diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1dc66ac0364e4..5331dd2c38468 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -670,7 +670,8 @@ clang-extdef-mapping
 libclang
 
 
-- ...
+- The soversion for libclang will now change for each new LLVM major release.  
This matches
+  the behavior of clang <= 13.
 
 Static Analyzer
 ---

diff  --git a/clang/tools/libclang/CMakeLists.txt 
b/clang/tools/libclang/CMakeLists.txt
index 4e0647971ab46..8d95d0900e8c4 100644
--- a/clang/tools/libclang/CMakeLists.txt
+++ b/clang/tools/libclang/CMakeLists.txt
@@ -1,9 +1,3 @@
-# The SOVERSION should be updated only if a change is made to the libclang
-# ABI, and when it is updated, it should be updated to the current
-# LLVM_VERSION_MAJOR.
-# Please also see clang/tools/libclang/libclang.map
-set(CLANG_SONAME 13)
-
 set(SOURCES
   ARCMigrate.cpp
   BuildSystem.cpp
@@ -70,8 +64,7 @@ endif ()
 option(LIBCLANG_BUILD_STATIC
   "Build libclang as a static library (in addition to a shared one)" OFF)
 
-set(LLVM_EXPORTED_SYMBOL_FILE 
${CMAKE_CURRENT_BINARY_DIR}/libclang-generic.exports)
-set(LIBCLANG_VERSION_SCRIPT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)
+set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.exports)
 
 if(MSVC)
   # Avoid LNK4197 by not specifying libclang.exports here.
@@ -80,20 +73,6 @@ if(MSVC)
   set(LLVM_EXPORTED_SYMBOL_FILE)
 endif()
 
-if (UNIX AND NOT APPLE)
-  set(LLVM_EXPORTED_SYMBOL_FILE)
-  set(USE_VERSION_SCRIPT ${LLVM_HAVE_LINK_VERSION_SCRIPT})
-endif()
-
-if (LLVM_EXPORTED_SYMBOL_FILE)
-  add_custom_command(OUTPUT ${LLVM_EXPORTED_SYMBOL_FILE}
- COMMAND "${Python3_EXECUTABLE}"
-   ARGS 
${CMAKE_CURRENT_SOURCE_DIR}/linker-script-to-export-list.py
-${LIBCLANG_VERSION_SCRIPT_FILE}
-${LLVM_EXPORTED_SYMBOL_FILE}
- DEPENDS ${LIBCLANG_VERSION_SCRIPT_FILE})
-endif()
-
 if(LLVM_ENABLE_PIC OR (WIN32 AND NOT LIBCLANG_BUILD_STATIC))
   set(ENABLE_SHARED SHARED)
 endif()
@@ -166,21 +145,6 @@ if(ENABLE_SHARED)
 )
 endif()
   endif()
-  if (USE_VERSION_SCRIPT)
-target_link_options(libclang PRIVATE 
"-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
-# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
-# but requires a special option to enable it.
-if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
-  target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
-endif()
-# Ensure that libclang.so gets rebuilt when the linker script changes.
-set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY
- OBJECT_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libclang.map)
-
-set_target_properties(libclang PROPERTIES
-  VERSION 
${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX}
-  SOVERSION ${CLANG_SONAME})
-  endif()
 endif()
 
 if(INTERNAL_INSTALL_PREFIX)

diff  --git a/clang/tools/libclang/libclang.exports 
b/clang/tools/libclang/libclang.exports
new file mode 100644
index 0..639d13d21d6d3
--- /dev/null
+++ b/clang/tools/libclang/libclang.exports
@@ -0,0 +1,395 @@
+clang_BlockCommandComment_getArgText
+clang_BlockCommandComment_getCommandName
+clang_BlockCommandComment_getNumArgs
+clang_BlockCommandComment_getParagraph
+clang_CXCursorSet_contains
+clang_CXCursorSet_insert
+clang_CXIndex_getGlobalOptions
+clang_CXIndex_setGlobalOptions
+clang_CXIndex_setInvocationEmissionPathOption
+clang_CXRewriter_create
+clang_CXRewriter_dispose
+clang_CXRewriter_insertTextBefore
+clang_CXRewriter_overwriteChangedFiles
+clang_CXRewriter_removeText
+clang_CXRewriter_replaceText
+clang_CXRew

[PATCH] D129160: libclang.so: Make SONAME the same as LLVM version

2022-07-25 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

In D129160#3678441 , @h-vetinari 
wrote:

> In D129160#3678431 , @tstellar 
> wrote:
>
>> @h-vetinari Does the release note look OK?
>
> Basically yes, thank you! I'd still be more precise and say "soversion" 
> rather than "soname", but otherwise OK.

OK, I'll fix that when I commit it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129160

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


[PATCH] D129160: libclang.so: Make SONAME the same as LLVM version

2022-07-25 Thread H. Vetinari via Phabricator via cfe-commits
h-vetinari added a comment.

In D129160#3678431 , @tstellar wrote:

> @h-vetinari Does the release note look OK?

Basically yes, thank you! I'd still be more precise and say "soversion" rather 
than "soname", but otherwise OK.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129160

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


[PATCH] D129160: libclang.so: Make SONAME the same as LLVM version

2022-07-25 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

@h-vetinari Does the release note look OK?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129160

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


[PATCH] D130420: [CodeGen] Consider MangleCtx when move lazy emission States

2022-07-25 Thread Jun Zhang 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 rG58c94808450d: [CodeGen] Consider MangleCtx when move lazy 
emission States (authored by junaire).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130420

Files:
  clang/lib/CodeGen/CGCXXABI.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/execute.cpp


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -5,6 +5,7 @@
 // UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7000,4 +7000,6 @@
  "Still have (unmerged) EmittedDeferredDecls deferred decls");
 
   NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
+
+  NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }
Index: clang/lib/CodeGen/CGCXXABI.h
===
--- clang/lib/CodeGen/CGCXXABI.h
+++ clang/lib/CodeGen/CGCXXABI.h
@@ -41,6 +41,8 @@
 
 /// Implements C++ ABI-specific code generation functions.
 class CGCXXABI {
+  friend class CodeGenModule;
+
 protected:
   CodeGenModule &CGM;
   std::unique_ptr MangleCtx;


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -5,6 +5,7 @@
 // UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7000,4 +7000,6 @@
  "Still have (unmerged) EmittedDeferredDecls deferred decls");
 
   NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
+
+  NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }
Index: clang/lib/CodeGen/CGCXXABI.h
===
--- clang/lib/CodeGen/CGCXXABI.h
+++ clang/lib/CodeGen/CGCXXABI.h
@@ -41,6 +41,8 @@
 
 /// Implements C++ ABI-specific code generation functions.
 class CGCXXABI {
+  friend class CodeGenModule;
+
 protected:
   CodeGenModule &CGM;
   std::unique_ptr MangleCtx;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 58c9480 - [CodeGen] Consider MangleCtx when move lazy emission States

2022-07-25 Thread Jun Zhang via cfe-commits

Author: Jun Zhang
Date: 2022-07-26T12:34:03+08:00
New Revision: 58c94808450d0ec73bed38d1661314c1a3d56e2f

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

LOG: [CodeGen] Consider MangleCtx when move lazy emission States

Also move MangleCtx when moving some lazy emission states in
CodeGenModule. Without this patch clang-repl hits an invalid address
access when passing `-Xcc -O2` flag.

Signed-off-by: Jun Zhang 

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

Added: 


Modified: 
clang/lib/CodeGen/CGCXXABI.h
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/Interpreter/execute.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCXXABI.h b/clang/lib/CodeGen/CGCXXABI.h
index a46f7f37141f0..0768e6581acb8 100644
--- a/clang/lib/CodeGen/CGCXXABI.h
+++ b/clang/lib/CodeGen/CGCXXABI.h
@@ -41,6 +41,8 @@ struct CatchTypeInfo;
 
 /// Implements C++ ABI-specific code generation functions.
 class CGCXXABI {
+  friend class CodeGenModule;
+
 protected:
   CodeGenModule &CGM;
   std::unique_ptr MangleCtx;

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 101080b6fe132..29713a5d2b3b3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -7000,4 +7000,6 @@ void CodeGenModule::moveLazyEmissionStates(CodeGenModule 
*NewBuilder) {
  "Still have (unmerged) EmittedDeferredDecls deferred decls");
 
   NewBuilder->EmittedDeferredDecls = std::move(EmittedDeferredDecls);
+
+  NewBuilder->ABI->MangleCtx = std::move(ABI->MangleCtx);
 }

diff  --git a/clang/test/Interpreter/execute.cpp 
b/clang/test/Interpreter/execute.cpp
index f5c70c21ac507..0396ad82e9b36 100644
--- a/clang/test/Interpreter/execute.cpp
+++ b/clang/test/Interpreter/execute.cpp
@@ -5,6 +5,7 @@
 // UNSUPPORTED: system-aix
 // CHECK-DRIVER: i = 10
 // RUN: cat %s | clang-repl | FileCheck %s
+// RUN: cat %s | clang-repl -Xcc -O2 | FileCheck %s
 extern "C" int printf(const char *, ...);
 int i = 42;
 auto r1 = printf("i = %d\n", i);



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


[PATCH] D130545: [cmake] Slight fix ups to make robust to the full range of GNUInstallDirs

2022-07-25 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 created this revision.
Ericson2314 added reviewers: sebastian-ne, beanz, phosek, sterni, lebedev.ri.
Herald added a subscriber: mgorny.
Herald added a project: All.
Ericson2314 requested review of this revision.
Herald added projects: clang, OpenMP.
Herald added subscribers: openmp-commits, cfe-commits.

See 
https://cmake.org/cmake/help/v3.14/module/GNUInstallDirs.html#result-variables 
for `CMAKE_INSTALL_FULL_*`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130545

Files:
  clang/tools/clang-linker-wrapper/CMakeLists.txt
  llvm-libgcc/lib/CMakeLists.txt
  openmp/CMakeLists.txt
  openmp/runtime/src/CMakeLists.txt

Index: openmp/runtime/src/CMakeLists.txt
===
--- openmp/runtime/src/CMakeLists.txt
+++ openmp/runtime/src/CMakeLists.txt
@@ -8,6 +8,8 @@
 #//===--===//
 #
 
+include(ExtendPath)
+
 # Configure omp.h, kmp_config.h and omp-tools.h if necessary
 configure_file(${LIBOMP_INC_DIR}/omp.h.var omp.h @ONLY)
 configure_file(kmp_config.h.cmake kmp_config.h @ONLY)
@@ -347,8 +349,8 @@
 add_dependencies(libomp-micro-tests libomp-test-deps)
 
 # Install rules
-# We want to install libomp in DESTDIR/CMAKE_INSTALL_PREFIX/lib
-# We want to install headers in DESTDIR/CMAKE_INSTALL_PREFIX/include
+# We want to install libomp in ${DESTDIR}/${CMAKE_INSTALL_FULL_LIBDIR}
+# We want to install headers in ${DESTDIR}/${CMAKE_INSTALL_FULL_INCLUDEDIR}
 if(${OPENMP_STANDALONE_BUILD})
   set(LIBOMP_HEADERS_INSTALL_PATH "${CMAKE_INSTALL_INCLUDEDIR}")
 else()
@@ -362,9 +364,10 @@
   set(LIBOMP_ALIASES "libiomp5md")
   foreach(alias IN LISTS LIBOMP_ALIASES)
 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_LIB_FILE}\"
-  \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}\")")
+  \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${CMAKE_INSTALL_FULL_BINDIR}\")")
+extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
 install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E copy \"${LIBOMP_IMP_LIB_FILE}\"
-  \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")")
+  \"${alias}${CMAKE_STATIC_LIBRARY_SUFFIX}\" WORKING_DIRECTORY \"${outdir}\")")
   endforeach()
 else()
 
@@ -374,9 +377,10 @@
 # Create aliases (symlinks) of the library for backwards compatibility
 set(LIBOMP_ALIASES "libgomp;libiomp5")
 foreach(alias IN LISTS LIBOMP_ALIASES)
+  extend_path(outdir "${CMAKE_INSTALL_PREFIX}" "${OPENMP_INSTALL_LIBDIR}")
   install(CODE "execute_process(COMMAND \"\${CMAKE_COMMAND}\" -E create_symlink \"${LIBOMP_LIB_FILE}\"
 \"${alias}${LIBOMP_LIBRARY_SUFFIX}\" WORKING_DIRECTORY
-\"\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${OPENMP_INSTALL_LIBDIR}\")")
+\"\$ENV{DESTDIR}\${outdir}\")")
 endforeach()
   endif()
 endif()
Index: openmp/CMakeLists.txt
===
--- openmp/CMakeLists.txt
+++ openmp/CMakeLists.txt
@@ -1,7 +1,12 @@
 cmake_minimum_required(VERSION 3.13.4)
 
-# Add cmake directory to search for custom cmake functions.
-set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
+set(LLVM_COMMON_CMAKE_UTILS ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
+
+# Add path for custom modules
+list(INSERT CMAKE_MODULE_PATH 0
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
+  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
+  )
 
 # llvm/runtimes/ will set OPENMP_STANDALONE_BUILD.
 if (OPENMP_STANDALONE_BUILD OR "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
Index: llvm-libgcc/lib/CMakeLists.txt
===
--- llvm-libgcc/lib/CMakeLists.txt
+++ llvm-libgcc/lib/CMakeLists.txt
@@ -1,5 +1,6 @@
 include(CheckLibraryExists)
 include(GNUInstallDirs)
+include(ExtendPath)
 
 string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
 
@@ -41,13 +42,13 @@
   c
 )
 
-get_filename_component(LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${CMAKE_INSTALL_PREFIX}/${LIBUNWIND_INSTALL_LIBRARY_DIR}" ABSOLUTE)
+extend_path(LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${CMAKE_INSTALL_PREFIX}" "${LIBUNWIND_INSTALL_LIBRARY_DIR}")
 #string(REPLACE "${CMAKE_INSTALL_FULL_LIBDIR}/" "" LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}")
 
 install(TARGETS libgcc_s
 LIBRARY DESTINATION "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}" COMPONENT unwind
 ARCHIVE DESTINATION "${LLVM_LIBGCC_LIBUNWIND_STATIC_ROOT}" COMPONENT unwind
-RUNTIME DESTINATION bin COMPONENT unwind)
+RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT unwind)
 
 get_compiler_rt_install_dir(${LLVM_LIBGCC_TARGET_ARCH} install_dir_builtins)
 string(REGEX REPLACE "^lib/" "" install_dir_builtins "${install_dir_builtins}")
In

[PATCH] D129872: [clang][OpenMP] Fix runtime crash in the call to __kmp_alloc.

2022-07-25 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:16379
+// UnsignedPointerDiffType avoid truncate.
+AllocatorHT = Context.getUnsignedPointerDiffType();
+  Allocator = PerformImplicitConversion(Allocator.get(), AllocatorHT,

jyu2 wrote:
> ABataev wrote:
> > jyu2 wrote:
> > > ABataev wrote:
> > > > jyu2 wrote:
> > > > > ABataev wrote:
> > > > > > jyu2 wrote:
> > > > > > > ABataev wrote:
> > > > > > > > It must be int type, no?
> > > > > > > unsigned int?
> > > > > > Check the standard, IIRC it says just int.
> > > > > I see that is enum type.
> > > > > 
> > > > > Runtime library definitions: The enum types for 
> > > > > omp_allocator_handle_t:
> > > > > 
> > > > > The type omp_allocator_handle_t, which must be an 
> > > > > implementation-defined (for C++
> > > > > possibly scoped) enum type with at least the omp_null_allocator 
> > > > > enumerator with the
> > > > > value zero and an enumerator for each predefined memory allocator in 
> > > > > Table 2.10;
> > > > IIRC, in C enums are always int-based.
> > > That is right.  But not for C++.
> > For C++ need to get the base int type.
> For C++ enum type is unsigned int:  
> since following is defined inside the omp_allocator_handle_t.
>  KMP_ALLOCATOR_MAX_HANDLE = (18446744073709551615UL)  
> 
> But for C it is int.  
> 
> ```
> -EnumDecl 0x11b31d88  line:18:14 omp_allocator_handle_t
> | |-EnumConstantDecl 0x11b31e90  col:3 referenced 
> omp_null_allocator 'omp_allocator_handle_t'
> | | `-ImplicitCastExpr 0x11b4b770  'unsigned long' 
> | |   `-ConstantExpr 0x11b31e70  'int'
> | | |-value: Int 0
> ```
> 
> 
I wouldn't rely on this, this is just implementation specific. Instead, need to 
find corresponding EnumDwcl and extract underlying integer type 
(getIntegerType). If it is null - the underlying type is int, otherwise use 
returned type.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129872

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


[PATCH] D101070: [llvm][cmake] Make `install_symlink` workflow work with absolute install dirs

2022-07-25 Thread John Ericson 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 rG7f9e6f6fa654: [llvm][cmake] Make `install_symlink` workflow 
work with absolute install dirs (authored by Ericson2314).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/LLVMInstallSymlink.cmake


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -6,17 +6,20 @@
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  if(NOT IS_ABSOLUTE "${outdir}")
+set(outdir "${CMAKE_INSTALL_PREFIX}/${outdir}")
+  endif()
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1953,7 +1953,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" 
"PARAMS;DEPENDS;ARGS" ${ARGN})
-
+
 if (NOT ARG_FOLDER)
   set(ARG_FOLDER "Test Subdirectories")
 endif()
@@ -2009,11 +2009,11 @@
 
   set(output_dir lib${LLVM_LIBDIR_SUFFIX})
   if(WIN32 AND "${type}" STREQUAL "SHARED")
-set(output_dir bin)
+set(output_dir "${CMAKE_INSTALL_BINDIR}")
   endif()
 
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
 endfunction()
@@ -2048,8 +2048,10 @@
 set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
   endif()
 
+  set(output_dir "${${project}_TOOLS_INSTALL_DIR}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} 
${${project}_TOOLS_INSTALL_DIR})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
   if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -6,17 +6,20 @@
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  if(NOT IS_ABSOLUTE "${outdir}")
+set(outdir "${CMAKE_INSTALL_PREFIX}/${outdir}")
+  endif()
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1953,7 +1953,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" "PARAMS;DEPENDS;ARGS" ${ARGN})
-
+
 if (NOT ARG_FOLDER)
   set(ARG_FOLDER "Test Subdirectories")
 endif()
@@ -2009,11 +2009,11 @@
 
   set(output_dir lib${LLVM_LIBDIR_SUFFIX})
   if(WIN32 AND "${type}" STREQUAL "SHARED")
-set(output_dir bin)
+set(output_dir "${CMAKE_INSTALL_BINDIR}")
   endif()
 
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\")"
   COMPONENT ${component})
 
 endfunction()
@@ -2048,8 +2048,10 @@
 set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
   endif()
 
+  set(output_dir "${${project}_TOOLS_INSTALL_DIR}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_d

[PATCH] D129824: [RISCV] Set triple based on -march flag which can be deduced in more generic way

2022-07-25 Thread Jessica Clarke via Phabricator via cfe-commits
jrtc27 added a comment.

If you still want to pursue this, discussion belongs at 
https://github.com/riscv-non-isa/riscv-toolchain-conventions, not here, since 
it's an interface shared by Clang and GCC and the two should be consistent


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

https://reviews.llvm.org/D129824

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added inline comments.



Comment at: clang/lib/Sema/Scope.cpp:152-154
+  // Consider the variable as NRVO candidate if the return slot is available
+  // for it in the current scope, or if it can be available in outer scopes.
+  NRVO = CanBePutInReturnSlot ? VD : nullptr;

What if NRVO contains a value already? It is possible due to the value of NRVO 
could be set by its children.



Comment at: clang/lib/Sema/Scope.cpp:184-185
+  //}
+  if (!getEntity())
+getParent()->NRVO = *NRVO;
 }

There is a similar problem. It looks not right if the NRVO of the parent owns a 
value already.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D129824: [RISCV] Set triple based on -march flag which can be deduced in more generic way

2022-07-25 Thread Zixuan Wu via Phabricator via cfe-commits
zixuan-wu added a comment.

In D129824#3670586 , @reames wrote:

> This was very briefly discussed at today's sync up call.  We were running 
> short on time, so we didn't get a chance to talk through it, but there did 
> seem to be a consensus that discussion on the interface implications was 
> needed.  This should hopefully be on the agenda when we talk again in two 
> weeks.

Okay. Anybody else please more comments here before next sync-up call if you 
have.


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

https://reviews.llvm.org/D129824

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-07-25 Thread Peixin Qiao via Phabricator via cfe-commits
peixin added inline comments.



Comment at: clang/include/clang/Driver/Options.td:4897
 def ffixed_line_length_VALUE : Joined<["-"], "ffixed-line-length-">, 
Group, Alias;
+def fconvert_EQ : Joined<["-"], "fconvert=">, Group,
+  HelpText<"Set endian conversion of data for unformatted files">;

Why do you move it here? Maybe it is not implemented now, clang may need this 
option eventually. @MaskRay 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130513

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


[PATCH] D129873: [clang-offload-bundler] Library-ize ClangOffloadBundler

2022-07-25 Thread Jacob Lambert via Phabricator via cfe-commits
lamb-j updated this revision to Diff 447531.
lamb-j added a comment.

Removing trailing whitespace


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129873

Files:
  clang/include/clang/Driver/OffloadBundler.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/OffloadBundler.cpp
  clang/tools/clang-offload-bundler/CMakeLists.txt
  clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp

Index: clang/tools/clang-offload-bundler/CMakeLists.txt
===
--- clang/tools/clang-offload-bundler/CMakeLists.txt
+++ clang/tools/clang-offload-bundler/CMakeLists.txt
@@ -2,15 +2,16 @@
 
 add_clang_tool(clang-offload-bundler
   ClangOffloadBundler.cpp
-  
+
   DEPENDS
   intrinsics_gen
   )
 
 set(CLANG_OFFLOAD_BUNDLER_LIB_DEPS
   clangBasic
+  clangDriver
   )
-  
+
 add_dependencies(clang clang-offload-bundler)
 
 clang_target_link_libraries(clang-offload-bundler
Index: clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
===
--- clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
+++ clang/tools/clang-offload-bundler/ClangOffloadBundler.cpp
@@ -7,15 +7,14 @@
 //===--===//
 ///
 /// \file
-/// This file implements a clang-offload-bundler that bundles different
-/// files that relate with the same source code but different targets into a
-/// single one. Also the implements the opposite functionality, i.e. unbundle
-/// files previous created by this tool.
+/// This file implements a stand-alone clang-offload-bundler tool using the
+/// OffloadBundler API.
 ///
 //===--===//
 
 #include "clang/Basic/Cuda.h"
 #include "clang/Basic/Version.h"
+#include "clang/Driver/OffloadBundler.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
@@ -55,38 +54,45 @@
 
 using namespace llvm;
 using namespace llvm::object;
+using namespace clang;
 
-static cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
+static void PrintVersion(raw_ostream &OS) {
+  OS << clang::getClangToolFullVersion("clang-offload-bundler") << '\n';
+}
+
+int main(int argc, const char **argv) {
+
+  cl::opt Help("h", cl::desc("Alias for -help"), cl::Hidden);
 
-// Mark all our options with this category, everything else (except for -version
-// and -help) will be hidden.
-static cl::OptionCategory
+  // Mark all our options with this category, everything else (except for
+  // -version and -help) will be hidden.
+  cl::OptionCategory
 ClangOffloadBundlerCategory("clang-offload-bundler options");
-static cl::list
+  cl::list
 InputFileNames("input",
cl::desc("Input file."
 " Can be specified multiple times "
 "for multiple input files."),
cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 InputFileNamesDeprecatedOpt("inputs", cl::CommaSeparated,
 cl::desc("[,...] (deprecated)"),
 cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 OutputFileNames("output",
 cl::desc("Output file."
  " Can be specified multiple times "
  "for multiple output files."),
 cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 OutputFileNamesDeprecatedOpt("outputs", cl::CommaSeparated,
  cl::desc("[,...] (deprecated)"),
  cl::cat(ClangOffloadBundlerCategory));
-static cl::list
+  cl::list
 TargetNames("targets", cl::CommaSeparated,
 cl::desc("[-,...]"),
 cl::cat(ClangOffloadBundlerCategory));
-static cl::opt
+  cl::opt
 FilesType("type", cl::Required,
   cl::desc("Type of the files to be bundled/unbundled.\n"
"Current supported types are:\n"
@@ -102,1265 +108,34 @@
"  gch - precompiled-header\n"
"  ast - clang AST file"),
   cl::cat(ClangOffloadBundlerCategory));
-static cl::opt
+  cl::opt
 Unbundle("unbundle",
  cl::desc("Unbundle bundled file into several output files.\n"),
  cl::init(false), cl::cat(ClangOffloadBundlerCategory));
-
-static cl::opt
+  cl::opt
 ListBundleIDs("list", cl::desc("List bundle IDs in the bundled file.\n"),
   cl::init(false), cl::cat(ClangOffloadBundlerCategory));
-
-static cl::opt PrintExternalCommands(
+  cl::opt PrintExternalCommands(
 "###",
 cl::desc("Print any external commands that are to be executed "
  "instead of actually executing them - for testing purp

[PATCH] D130255: [Clang][LoongArch] Add initial LoongArch target and driver support

2022-07-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2226
 
+  static const char *const LoongArch64LibDirs[] = {"/lib64", "/lib"};
+  static const char *const LoongArch64Triples[] = {

xry111 wrote:
> SixWeining wrote:
> > xry111 wrote:
> > > SixWeining wrote:
> > > > MaskRay wrote:
> > > > > I don't know which of /lib64, /lib has been used. For purity, I'd 
> > > > > hope that we just have /lib, no multilib style /lib64
> > > > I also don't know the actual usage of /lib64 but I just tried and it 
> > > > works fine if I remove /lib64.
> > > I don't like `lib64` too.  But for LoongArch LP64D, the path to ELF 
> > > interpreter is hard coded `/lib64/ld-linux-loongarch-lp64d.so.1` and it 
> > > seems too late to change it.  And LoongArch GCC installs libstdc++ etc. 
> > > for LP64D into $PREFIX/lib64 by default (like x86_64).
> > > 
> > > As a distro (LFS) maintainer: we are already hacking GCC code to get rid 
> > > of `/usr/lib64`.
> > Thanks for the quick reply. So I should keep the /lib64 here?
> I think you should keep it.  A multilib distro may have `/usr/lib64`, 
> `/usr/lib32`, and `/usr/lib32sf` (`sf` for soft float or whatever) and make 
> `/usr/lib` a symlink.  A "mostly 32-bit distro" may have symlink `/usr/lib` 
> -> `/usr/lib32`, but still capable to build & run LA64 programs with 
> libraries in `/usr/lib64`.  Removing `lib64` will break clang on such distros 
> with `-mabi=64`.
> 
> Personally, I don't like `lib64`.  But we can't really predict what the 
> distro maintainers will do (unless you say something explicitly like "a LP64D 
> capable distro SHALL have LP64D libraries in `/usr/lib`" in a spec).
Dynamic loader selection is orthogonal to the LibDirs variable here. You can 
use /lib64/ld-linux-loongarch-lp64d.so.1 while the library paths are from /lib .

If anything, riscv multilib support is quite broken at this point so probably 
don't use it as a reference.
If there is ever a 32-bit distro which wants to do 64-bit compilation, you can 
leverage multiarch, which is less broken. 
https://maskray.me/blog/2021-03-28-compiler-driver-and-cross-compilation


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130255

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


[PATCH] D130531: [IR] Use Min behavior for module flag "PIC Level"

2022-07-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: davide, tejohnson.
Herald added subscribers: StephenFan, okura, kuter, hiraditya.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: sstefan1.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Using Max for both "PIC Level" and "PIE Level" is inconsistent. PIC imposes less
restriction while PIE imposes more restriction. The result generally
picks the more restrictive behavior: Min for PIC.

This choice matches `ld -r`: a non-pic object and a pic object merge into a
result which should be treated as non-pic.

To allow linking "PIC Level" using Error/Max from old bitcode files, upgrade
Error/Max to Min.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130531

Files:
  clang/test/CodeGen/piclevels.c
  llvm/lib/IR/AutoUpgrade.cpp
  llvm/lib/IR/Module.cpp
  llvm/test/Bitcode/upgrade-module-flag.ll
  llvm/test/Linker/Inputs/module-flags-pic-2-b.ll
  llvm/test/Linker/module-flags-pic-1-a.ll
  llvm/test/Linker/module-flags-pic-2-a.ll
  llvm/test/Transforms/Attributor/value-simplify-dbg.ll
  llvm/test/Transforms/Attributor/value-simplify-local-remote.ll
  llvm/test/Transforms/OpenMP/spmdization.ll
  llvm/test/Transforms/OpenMP/spmdization_assumes.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding.ll
  llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll

Index: llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll
===
--- llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll
+++ llvm/test/Transforms/OpenMP/spmdization_guarding_two_reaching_kernels.ll
@@ -265,7 +265,7 @@
 !4 = !{i32 1, !"wchar_size", i32 4}
 !5 = !{i32 7, !"openmp", i32 50}
 !6 = !{i32 7, !"openmp-device", i32 50}
-!7 = !{i32 7, !"PIC Level", i32 2}
+!7 = !{i32 8, !"PIC Level", i32 2}
 !8 = !{i32 7, !"frame-pointer", i32 2}
 !9 = !{!"clang version 14.0.0"}
 ;.
Index: llvm/test/Transforms/OpenMP/spmdization_guarding.ll
===
--- llvm/test/Transforms/OpenMP/spmdization_guarding.ll
+++ llvm/test/Transforms/OpenMP/spmdization_guarding.ll
@@ -381,7 +381,7 @@
 !2 = !{i32 1, !"wchar_size", i32 4}
 !3 = !{i32 7, !"openmp", i32 50}
 !4 = !{i32 7, !"openmp-device", i32 50}
-!5 = !{i32 7, !"PIC Level", i32 2}
+!5 = !{i32 8, !"PIC Level", i32 2}
 !6 = !{i32 7, !"frame-pointer", i32 2}
 !7 = !{!"clang version 14.0.0"}
 !8 = !{!9}
Index: llvm/test/Transforms/OpenMP/spmdization_assumes.ll
===
--- llvm/test/Transforms/OpenMP/spmdization_assumes.ll
+++ llvm/test/Transforms/OpenMP/spmdization_assumes.ll
@@ -137,7 +137,7 @@
 !2 = !{i32 1, !"wchar_size", i32 4}
 !3 = !{i32 7, !"openmp", i32 50}
 !4 = !{i32 7, !"openmp-device", i32 50}
-!5 = !{i32 7, !"PIC Level", i32 2}
+!5 = !{i32 8, !"PIC Level", i32 2}
 !6 = !{i32 7, !"frame-pointer", i32 2}
 !7 = !{!"clang version 14.0.0"}
 !8 = !{!9, !9, i64 0}
@@ -159,7 +159,7 @@
 ; CHECK: [[META2:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
 ; CHECK: [[META3:![0-9]+]] = !{i32 7, !"openmp", i32 50}
 ; CHECK: [[META4:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
-; CHECK: [[META5:![0-9]+]] = !{i32 7, !"PIC Level", i32 2}
+; CHECK: [[META5:![0-9]+]] = !{i32 8, !"PIC Level", i32 2}
 ; CHECK: [[META6:![0-9]+]] = !{i32 7, !"frame-pointer", i32 2}
 ; CHECK: [[META7:![0-9]+]] = !{!"clang version 14.0.0"}
 ; CHECK: [[TBAA8]] = !{!9, !9, i64 0}
Index: llvm/test/Transforms/OpenMP/spmdization.ll
===
--- llvm/test/Transforms/OpenMP/spmdization.ll
+++ llvm/test/Transforms/OpenMP/spmdization.ll
@@ -2395,7 +2395,7 @@
 !12 = !{i32 1, !"wchar_size", i32 4}
 !13 = !{i32 7, !"openmp", i32 50}
 !14 = !{i32 7, !"openmp-device", i32 50}
-!15 = !{i32 7, !"PIC Level", i32 2}
+!15 = !{i32 8, !"PIC Level", i32 2}
 !16 = !{i32 7, !"frame-pointer", i32 2}
 !17 = !{!"clang version 14.0.0"}
 !18 = !{!19, !19, i64 0}
@@ -2481,7 +2481,7 @@
 ; AMDGPU: [[META12:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
 ; AMDGPU: [[META13:![0-9]+]] = !{i32 7, !"openmp", i32 50}
 ; AMDGPU: [[META14:![0-9]+]] = !{i32 7, !"openmp-device", i32 50}
-; AMDGPU: [[META15:![0-9]+]] = !{i32 7, !"PIC Level", i32 2}
+; AMDGPU: [[META15:![0-9]+]] = !{i32 8, !"PIC Level", i32 2}
 ; AMDGPU: [[META16:![0-9]+]] = !{i32 7, !"frame-pointer", i32 2}
 ; AMDGPU: [[META17:![0-9]+]] = !{!"clang version 14.0.0"}
 ; AMDGPU: [[TBAA18]] = !{!19, !19, i64 0}
Index: llvm/test/Transforms/Attributor/value-simplify-local-remote.ll
===
--- llvm/test/Transforms/Attributor/value-simplify-local-remote.ll
+++ llvm/test/Transforms/Attributor/value-simplify-local-remote.ll
@@ -769,7 +769,7 @@
 !1 = !{i32 1, !"wchar_size", i32 4}
 !2 = !{i32 7, !"openmp", 

[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-07-25 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic added a comment.

Thank you for taking a look at this and thank you for the feedback!

I'm not sure if I am entirely following/I think I am confusing myself on some 
of the specifics. My understanding of your suggestion is that, rather than add 
and create a call to a fconvert-specific runtime function (`ConvertOption`) I 
should look towards implementing and calling a runtime function/API that 
(conceptually) looks something like `SetRuntimeDefaults(FORT_CONVERT="SWAP", 
[...])` to set whatever was specified on the command line.

I think where I'm getting confused is when you mention default environment 
variable settings or translating the command-line options into the equivalent 
environment settings and passing them as defaults: is the idea to set the 
actual (in this case) `FORT_CONVERT` environment variable if it hasn't already 
been defined in the environment, with the goal of letting the existing 
`FORT_CONVERT` handling deal with everything? Or, is directly setting the 
`executionEnvironment.conversion` value like I tried to do in `ConvertOption` 
ok, but I need to rethink the `ConvertOption` API itself? If the goal is to set 
`FORT_CONVERT`, I'm getting a bit hung up on `FORT_CONVERT` currently being 
handled as part of the "hardcoded" main in Fort_main.c.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130513

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


[PATCH] D128142: [MemProf] Memprof profile matching and annotation

2022-07-25 Thread Snehasish Kumar via Phabricator via cfe-commits
snehasish added inline comments.
Herald added a subscriber: mingmingl.



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1249
+void addCallStack(CallStackTrie &AllocTrie, const AllocationInfo *AllocInfo) {
+  auto AllocType = getAllocType(AllocInfo->Info.getMaxAccessCount(),
+AllocInfo->Info.getMinSize(),

Prefer moving this code after the loop, close to where AllocType is used.



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1252
+AllocInfo->Info.getMinLifetime());
+  SmallVector StackIds;
+  std::set StackHashSet;

I think if you use an llvm::SetVector here instead then you don't need the 
StackHashSet std::set below. CallstackTrie::addCallstack already accepts an 
ArrayRef so it won't need to change if we use a SetVector.



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1253
+  SmallVector StackIds;
+  std::set StackHashSet;
+  for (auto StackFrame : AllocInfo->CallStack) {

nit: It doesn't look like we #include  in this file so we are probably 
relying on having it transitively being included from somewhere.



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1276
+  if (Error E = MemProfResult.takeError()) {
+handleAllErrors(std::move(E), [&](const InstrProfError &IPE) {
+  auto Err = IPE.get();

Consider defining the lambda outside above the condition to reduce indentation. 
IMO it will be  a little easier to follow if it wasn't inlined into the if 
statement itself.



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1297
+
+  std::string Msg = IPE.message() + std::string(" ") + F.getName().str() +
+std::string(" Hash = ") +

Is an llvm::Twine a better choice here instead of std::string? I guess it 
doesn't matter much in error handling code.  



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1313
+  std::map *, unsigned>>>
+  LocHashToCallSites;
+  const auto MemProfRec = std::move(MemProfResult.get());

LocHashToCallSiteFrame to indicate the value in the map corresponds to an 
individual frame?



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1319
+// of call stack frames.
+auto StackId = computeStackId(AI.CallStack[0]);
+LocHashToAllocInfo[StackId].insert(&AI);

Not using auto over here would be helpful to know that we are indexing into the 
map below using an uint64_t. Same below.



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1330
+  // Once we find this function, we can stop recording.
+  if (StackFrame.Function == FuncGUID)
+break;

Should we assert that it was actually found?



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1360
+  // If leaf was found in a map, iterators pointing to its location in both
+  // of the maps (it may only exist in one).
+  std::map>::iterator

Can you add an assert for this?



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1365
+unsigned>>>::iterator 
CallSitesIter;
+  for (const DILocation *DIL = I.getDebugLoc(); DIL;
+   DIL = DIL->getInlinedAt()) {

`DIL != nullptr` is a little easier to follow.



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1397
+  // be non-zero.
+  auto StackFrameIncludesInlinedCallStack =
+  [&InlinedCallStack](ArrayRef ProfileCallStack,

Prefer moving this to a static helper method to reduce the size of the loop 
body, reduce indentation for this logic and make it more readable overall. 
Probably creating an functor object on the stack for each instruction that we 
process is not efficient either.



Comment at: llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp:1414
+
+  // First add !memprof metadata from allocation info, if we found the
+  // instruction's leaf location in that map, and if the rest of the

"First add !memprof metadata  ..." -- the ordering of the if-else condition 
isn't necessary though since only one of the iters can be non-null? We could 
rewrite the else condition first to reduce the complexity here a bit. Eg --

```
if (CallSitesIter != LocHashToCallSites.end()) {
  ...
  continue
}

// Flip the conditions here
if (!isNewLikeFn() || AllocInfoIter == LocHashToAllocInfo.end()) {
   continue
}

CallStackTrie AllocTrie;
...
```



Comment at: llvm/test/Transforms/PGOProfile/memprof.ll:82
+;; memprof.cc -o pgo.exe -fprofile-ge

[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an EnumDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-25 Thread Shafik Yaghmour 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 rGaea82d455113: [Clang] Fix how we set the NumPositiveBits on 
an EnumDecl to cover the case of… (authored by shafik).
Herald added projects: clang, Sanitizers.
Herald added a subscriber: Sanitizers.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130301

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/pr12251.cpp
  compiler-rt/test/ubsan/TestCases/Misc/enum.cpp

Index: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
===
--- compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
+++ compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
@@ -1,21 +1,33 @@
-// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PLAIN
-// RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E" %s -O3 -o %t && %run %t
-// RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E : bool" %s -O3 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-BOOL
+// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
 
 // FIXME: UBSan fails to add the correct instrumentation code for some reason on
 // Windows.
 // XFAIL: windows-msvc
 
-enum E { a = 1 } e;
-#undef E
+enum E { a = 1 };
+enum class EClass { a = 1 };
+enum class EBool : bool { a = 1 } e3;
+enum EEmpty {};
+enum EMinus { em = -1 };
 
 int main(int argc, char **argv) {
-  // memset(&e, 0xff, sizeof(e));
-  for (unsigned char *p = (unsigned char*)&e; p != (unsigned char*)(&e + 1); ++p)
+  E e1 = static_cast(0x);
+  EClass e2 = static_cast(0x);
+  EEmpty e4 = static_cast(1);
+  EEmpty e5 = static_cast(2);
+  EMinus e6 = static_cast(1);
+  EMinus e7 = static_cast(2);
+
+  for (unsigned char *p = (unsigned char *)&e3; p != (unsigned char *)(&e3 + 1);
+   ++p)
 *p = 0xff;
 
-  // CHECK-PLAIN: error: load of value 4294967295, which is not a valid value for type 'enum E'
-  // FIXME: Support marshalling and display of enum class values.
-  // CHECK-BOOL: error: load of value , which is not a valid value for type 'enum E'
-  return (int)e != -1;
+  return ((int)e1 != -1) & ((int)e2 != -1) &
+ // CHECK: error: load of value 4294967295, which is not a valid value for type 'E'
+ ((int)e3 != -1) & ((int)e4 == 1) &
+ // CHECK: error: load of value , which is not a valid value for type 'enum EBool'
+ ((int)e5 == 2) & ((int)e6 == 1) &
+ // CHECK: error: load of value 2, which is not a valid value for type 'EEmpty'
+ ((int)e7 == 2);
+  // CHECK: error: load of value 2, which is not a valid value for type 'EMinus'
 }
Index: clang/test/CodeGenCXX/pr12251.cpp
===
--- clang/test/CodeGenCXX/pr12251.cpp
+++ clang/test/CodeGenCXX/pr12251.cpp
@@ -18,14 +18,14 @@
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g1P2e1
-// CHECK: ret i32 0
+// CHECK: ret i32 %0
 
 enum e2 { e2_a = 0 };
 e2 g2(e2 *x) {
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g2P2e2
-// CHECK: ret i32 0
+// CHECK: ret i32 %0
 
 enum e3 { e3_a = 16 };
 e3 g3(e3 *x) {
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -18899,14 +18899,24 @@
 const llvm::APSInt &InitVal = ECD->getInitVal();
 
 // Keep track of the size of positive and negative values.
-if (InitVal.isUnsigned() || InitVal.isNonNegative())
-  NumPositiveBits = std::max(NumPositiveBits,
- (unsigned)InitVal.getActiveBits());
-else
+if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
+  // If the enumerator is zero that should still be counted as a positive
+  // bit since we need a bit to store the value zero.
+  unsigned ActiveBits = InitVal.getActiveBits();
+  NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
+} else {
   NumNegativeBits = std::max(NumNegativeBits,
  (unsigned)InitVal.getMinSignedBits());
+}
   }
 
+  // If we have have an empty set of enumerators we still need one bit.
+  // From [dcl.enum]p8
+  // If the enumerator-list is empty, the values of the enumeration are as if
+  // the enumeration had a single enumerator with value 0
+  if (!NumPositiveBits && !NumNegativeBits)
+NumPositiveBits = 1;
+
   // Figure out the type that should be used for this enum.
   QualType BestType;
   unsigned BestWidth;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,6 +198,10 @@
   constant folded. Fixes `Issue 55638 

[clang] aea82d4 - [Clang] Fix how we set the NumPositiveBits on an EnumDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-25 Thread Shafik Yaghmour via cfe-commits

Author: Shafik Yaghmour
Date: 2022-07-25T16:01:01-07:00
New Revision: aea82d4551139ded0290afab739f0b367d055628

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

LOG: [Clang] Fix how we set the NumPositiveBits on an EnumDecl to cover the 
case of single enumerator with value zero or an empty enum

Currently in Sema::ActOnEnumBody(...) when calculating NumPositiveBits we miss
the case where there is only a single enumerator with value zero and the case of
an empty enum. In both cases we end up with zero positive bits when in fact we
need one bit to store the value zero.

This PR updates the calculation to account for these cases.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaDecl.cpp
clang/test/CodeGenCXX/pr12251.cpp
compiler-rt/test/ubsan/TestCases/Misc/enum.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ab2f6387492b7..1dc66ac0364e4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -198,6 +198,10 @@ Bug Fixes
   constant folded. Fixes `Issue 55638 
`_.
 - Fixed incompatibility of Clang's  with MSVC .
   Fixes `MSVC STL Issue 2862 `_.
+- Empty enums and enums with a single enumerator with value zero will be
+  considered to have one positive bit in order to represent the underlying
+  value. This effects whether we consider the store of the value one to be well
+  defined.
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 8d2fc5331a0df..1c793eb3320e1 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -18899,14 +18899,24 @@ void Sema::ActOnEnumBody(SourceLocation EnumLoc, 
SourceRange BraceRange,
 const llvm::APSInt &InitVal = ECD->getInitVal();
 
 // Keep track of the size of positive and negative values.
-if (InitVal.isUnsigned() || InitVal.isNonNegative())
-  NumPositiveBits = std::max(NumPositiveBits,
- (unsigned)InitVal.getActiveBits());
-else
+if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
+  // If the enumerator is zero that should still be counted as a positive
+  // bit since we need a bit to store the value zero.
+  unsigned ActiveBits = InitVal.getActiveBits();
+  NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
+} else {
   NumNegativeBits = std::max(NumNegativeBits,
  (unsigned)InitVal.getMinSignedBits());
+}
   }
 
+  // If we have have an empty set of enumerators we still need one bit.
+  // From [dcl.enum]p8
+  // If the enumerator-list is empty, the values of the enumeration are as if
+  // the enumeration had a single enumerator with value 0
+  if (!NumPositiveBits && !NumNegativeBits)
+NumPositiveBits = 1;
+
   // Figure out the type that should be used for this enum.
   QualType BestType;
   unsigned BestWidth;

diff  --git a/clang/test/CodeGenCXX/pr12251.cpp 
b/clang/test/CodeGenCXX/pr12251.cpp
index 88f3cbea9202a..2615bc7260e95 100644
--- a/clang/test/CodeGenCXX/pr12251.cpp
+++ b/clang/test/CodeGenCXX/pr12251.cpp
@@ -18,14 +18,14 @@ e1 g1(e1 *x) {
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g1P2e1
-// CHECK: ret i32 0
+// CHECK: ret i32 %0
 
 enum e2 { e2_a = 0 };
 e2 g2(e2 *x) {
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g2P2e2
-// CHECK: ret i32 0
+// CHECK: ret i32 %0
 
 enum e3 { e3_a = 16 };
 e3 g3(e3 *x) {

diff  --git a/compiler-rt/test/ubsan/TestCases/Misc/enum.cpp 
b/compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
index 8e95f8b403a93..569fb638526da 100644
--- a/compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
+++ b/compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
@@ -1,21 +1,33 @@
-// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s 
--check-prefix=CHECK-PLAIN
-// RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E" %s -O3 -o %t && %run 
%t
-// RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E : bool" %s -O3 -o %t 
&& not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-BOOL
+// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s 
--check-prefix=CHECK
 
 // FIXME: UBSan fails to add the correct instrumentation code for some reason 
on
 // Windows.
 // XFAIL: windows-msvc
 
-enum E { a = 1 } e;
-#undef E
+enum E { a = 1 };
+enum class EClass { a = 1 };
+enum class EBool : bool { a = 1 } e3;
+enum EEmpty {};
+enum EMinus { em = -1 };
 
 int main(int argc, char **argv) {
-  // memset(&e, 0xff, sizeof(e));
-  for (unsigned char *p = (unsigned cha

[PATCH] D130411: [clang-format] Fix a hang when formatting C# $@ string literals

2022-07-25 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/lib/Format/FormatTokenLexer.cpp:536
+  // $"{x ?? "null"}"
+  // should not be split into $"{x ?? ", null, "}" but should treated as a
+  // single string-literal.

curdeius wrote:
> 
I left the original comments alone but will insert it before landing.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130411

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


[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an EnumDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp:27
+  return ((int)e1 != -1) & ((int)e2 != -1) &
+ // CHECK: error: load of value , which is not a valid value 
for type 'enum EBool'
+ ((int)e3 != -1) & ((int)e4 == 1) &

aaron.ballman wrote:
> shafik wrote:
> > aaron.ballman wrote:
> > > erichkeane wrote:
> > > > What does THIS come from?  What value is unknown?  Shouldn't the -1 be 
> > > > fine?
> > > +1, I'm surprised by the `` there, but also... neither `e1` nor 
> > > `e2` are of type `enum EBool`!
> > So it looks like clang knows that the only valid values for a bool enum is 
> > 0 or 1 and it will mask the value accordingly see godbolt for example using 
> > `argc` : https://godbolt.org/z/ceb9hPno9
> > 
> > So that would explain why the original test used a `unsigned char*` in 
> > order to prompt the diagnostic. 
> > 
> > Looking into the ubsan diagnostic it looks like it treats bool as an 
> > unknown value, separate from integer and float. It is not clear to me why 
> > it does this but fixing that feels outside the scope of this change since 
> > this was part of the original test.
> Thanks for looking into it! I agree that fixing the ubsan diagnostic behavior 
> is out of scope. That said, can you move the CHECK lines so that they come 
> *after* the line of code being checked? I think that's what threw me for a 
> loop regarding the `EBool` confusion I had.
Fixed, I did it like that to keep with the style of the original test but I see 
how it can be confusing.


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

https://reviews.llvm.org/D130301

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


[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 447500.
shafik marked 5 inline comments as done.
shafik added a comment.

- Adding release note
- Fixing comments
- Removing top level const on local variable
- Adjusting test so checks go after the line they are checking


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

https://reviews.llvm.org/D130301

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaDecl.cpp
  clang/test/CodeGenCXX/pr12251.cpp
  compiler-rt/test/ubsan/TestCases/Misc/enum.cpp

Index: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
===
--- compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
+++ compiler-rt/test/ubsan/TestCases/Misc/enum.cpp
@@ -1,21 +1,33 @@
-// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-PLAIN
-// RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E" %s -O3 -o %t && %run %t
-// RUN: %clangxx -fsanitize=enum -std=c++11 -DE="class E : bool" %s -O3 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-BOOL
+// RUN: %clangxx -fsanitize=enum %s -O3 -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
 
 // FIXME: UBSan fails to add the correct instrumentation code for some reason on
 // Windows.
 // XFAIL: windows-msvc
 
-enum E { a = 1 } e;
-#undef E
+enum E { a = 1 };
+enum class EClass { a = 1 };
+enum class EBool : bool { a = 1 } e3;
+enum EEmpty {};
+enum EMinus { em = -1 };
 
 int main(int argc, char **argv) {
-  // memset(&e, 0xff, sizeof(e));
-  for (unsigned char *p = (unsigned char*)&e; p != (unsigned char*)(&e + 1); ++p)
+  E e1 = static_cast(0x);
+  EClass e2 = static_cast(0x);
+  EEmpty e4 = static_cast(1);
+  EEmpty e5 = static_cast(2);
+  EMinus e6 = static_cast(1);
+  EMinus e7 = static_cast(2);
+
+  for (unsigned char *p = (unsigned char *)&e3; p != (unsigned char *)(&e3 + 1);
+   ++p)
 *p = 0xff;
 
-  // CHECK-PLAIN: error: load of value 4294967295, which is not a valid value for type 'enum E'
-  // FIXME: Support marshalling and display of enum class values.
-  // CHECK-BOOL: error: load of value , which is not a valid value for type 'enum E'
-  return (int)e != -1;
+  return ((int)e1 != -1) & ((int)e2 != -1) &
+ // CHECK: error: load of value 4294967295, which is not a valid value for type 'E'
+ ((int)e3 != -1) & ((int)e4 == 1) &
+ // CHECK: error: load of value , which is not a valid value for type 'enum EBool'
+ ((int)e5 == 2) & ((int)e6 == 1) &
+ // CHECK: error: load of value 2, which is not a valid value for type 'EEmpty'
+ ((int)e7 == 2);
+  // CHECK: error: load of value 2, which is not a valid value for type 'EMinus'
 }
Index: clang/test/CodeGenCXX/pr12251.cpp
===
--- clang/test/CodeGenCXX/pr12251.cpp
+++ clang/test/CodeGenCXX/pr12251.cpp
@@ -18,14 +18,14 @@
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g1P2e1
-// CHECK: ret i32 0
+// CHECK: ret i32 %0
 
 enum e2 { e2_a = 0 };
 e2 g2(e2 *x) {
   return *x;
 }
 // CHECK-LABEL: define{{.*}} i32 @_Z2g2P2e2
-// CHECK: ret i32 0
+// CHECK: ret i32 %0
 
 enum e3 { e3_a = 16 };
 e3 g3(e3 *x) {
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -18899,14 +18899,24 @@
 const llvm::APSInt &InitVal = ECD->getInitVal();
 
 // Keep track of the size of positive and negative values.
-if (InitVal.isUnsigned() || InitVal.isNonNegative())
-  NumPositiveBits = std::max(NumPositiveBits,
- (unsigned)InitVal.getActiveBits());
-else
+if (InitVal.isUnsigned() || InitVal.isNonNegative()) {
+  // If the enumerator is zero that should still be counted as a positive
+  // bit since we need a bit to store the value zero.
+  unsigned ActiveBits = InitVal.getActiveBits();
+  NumPositiveBits = std::max({NumPositiveBits, ActiveBits, 1u});
+} else {
   NumNegativeBits = std::max(NumNegativeBits,
  (unsigned)InitVal.getMinSignedBits());
+}
   }
 
+  // If we have have an empty set of enumerators we still need one bit.
+  // From [dcl.enum]p8
+  // If the enumerator-list is empty, the values of the enumeration are as if
+  // the enumeration had a single enumerator with value 0
+  if (!NumPositiveBits && !NumNegativeBits)
+NumPositiveBits = 1;
+
   // Figure out the type that should be used for this enum.
   QualType BestType;
   unsigned BestWidth;
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,6 +198,10 @@
   constant folded. Fixes `Issue 55638 `_.
 - Fixed incompatibility of Clang's  with MSVC .
   Fixes `MSVC STL Issue 2862 

[PATCH] D130526: [Driver][PowerPC] Support -mtune=

2022-07-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: PowerPC, nemanjai, jsji.
Herald added subscribers: luke957, StephenFan, s.egerton, shchenz, simoncook, 
kbarton.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130526

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Arch/PPC.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/ppc-cpus.c


Index: clang/test/Driver/ppc-cpus.c
===
--- clang/test/Driver/ppc-cpus.c
+++ clang/test/Driver/ppc-cpus.c
@@ -19,3 +19,6 @@
 // RUN: %clang -### -c -target powerpc64 %s -mcpu=pwr8 2>&1 | FileCheck %s 
--check-prefix=NO_PPC64
 
 // NO_PPC64-NOT: "-target-cpu" "ppc64"
+
+// RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | 
FileCheck %s --check-prefix=TUNE
+// TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2083,6 +2083,14 @@
 
 void Clang::AddPPCTargetArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
+
   // Select the ABI to use.
   const char *ABIName = nullptr;
   const llvm::Triple &T = getToolChain().getTriple();
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -107,10 +107,6 @@
 void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
-  // TODO Handle -mtune=. Suppress -Wunused-command-line-argument as a
-  // longstanding behavior.
-  (void)Args.getLastArg(options::OPT_mtune_EQ);
-
   if (Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
 Features.push_back("+spe");
 
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3982,7 +3982,7 @@
   HelpText<"Provide information about a particular module file">;
 def mthumb : Flag<["-"], "mthumb">, Group;
 def mtune_EQ : Joined<["-"], "mtune=">, Group,
-  HelpText<"Only supported on X86, RISC-V and SystemZ. Otherwise accepted for 
compatibility with GCC.">;
+  HelpText<"Only supported on AArch64, PowerPC, RISC-V, SystemZ, and X86">;
 def multi__module : Flag<["-"], "multi_module">;
 def multiply__defined__unused : Separate<["-"], "multiply_defined_unused">;
 def multiply__defined : Separate<["-"], "multiply_defined">;


Index: clang/test/Driver/ppc-cpus.c
===
--- clang/test/Driver/ppc-cpus.c
+++ clang/test/Driver/ppc-cpus.c
@@ -19,3 +19,6 @@
 // RUN: %clang -### -c -target powerpc64 %s -mcpu=pwr8 2>&1 | FileCheck %s --check-prefix=NO_PPC64
 
 // NO_PPC64-NOT: "-target-cpu" "ppc64"
+
+// RUN: %clang -### -c --target=powerpc64 %s -mcpu=generic -mtune=pwr9 2>&1 | FileCheck %s --check-prefix=TUNE
+// TUNE: "-target-cpu" "ppc64" "-tune-cpu" "pwr9"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -2083,6 +2083,14 @@
 
 void Clang::AddPPCTargetArgs(const ArgList &Args,
  ArgStringList &CmdArgs) const {
+  if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
+CmdArgs.push_back("-tune-cpu");
+if (strcmp(A->getValue(), "native") == 0)
+  CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
+else
+  CmdArgs.push_back(A->getValue());
+  }
+
   // Select the ABI to use.
   const char *ABIName = nullptr;
   const llvm::Triple &T = getToolChain().getTriple();
Index: clang/lib/Driver/ToolChains/Arch/PPC.cpp
===
--- clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -107,10 +107,6 @@
 void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
-  // TODO Handle -mtune=. Suppress -Wunused-command-line-argument as a
-  // longstanding behavior.
-  (void)Args.getLastArg(options::OPT_mtune_EQ);
-
   if (Tri

[PATCH] D124063: [LegacyPM] Rename and deprecate populateModulePassManager

2022-07-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

So nobody has managed to fix all the in-tree usage. I think having this for the 
upcoming release/15.x will be nice...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124063

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


[PATCH] D130519: [clang][dataflow] Add explicit "AST" nodes for implications and iff

2022-07-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:332
+
+  if (LeftSubVar == RightSubVar) {
+// `X <=> (A <=> A)` is equvalent to `X` which is already in

gribozavr2 wrote:
> xazax.hun wrote:
> > xazax.hun wrote:
> > > I wonder why this simplification is done here only for 
> > > `BiconditionalValue`. Other operations seem to not do these sorts of 
> > > simplifications. Also, when would we take this branch? `getOrCreateIff` 
> > > has a special case when both operands are the same. 
> > Oh, looking at the other patch I see it mentioning desugaring. So can 
> > desugaring also introduce `Biconditional`s?
> It is also necessary in the other cases due to the precondition of 
> `addClause()`, I'm adding that special handling in a separate patch: 
> https://reviews.llvm.org/D130522
> 
> We would take this branch when someone avoids using the DataflowContext API. 
> So not extremely likely at the moment, but it is a latent bug that can be 
> exposed by some future refactoring.
I see, thanks! 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130519

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


[PATCH] D130516: [Support] compression classes

2022-07-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/Serialization/ASTWriter.cpp:2003-2004
   // consumers will not want its contents.
+  llvm::compression::CompressionAlgorithm CompressionScheme =
+  llvm::compression::ZlibCompressionAlgorithm();
+

ckissane wrote:
> dblaikie wrote:
> > Doesn't this cause slicing & end up with the base implementation?
> > 
> > (also the base class `CompressionAlgorithm` has no virtual functions, so 
> > I'm not sure how this is meant to work - does this code all work? Then I 
> > must be missing some things - how does this work?)
> You are correct to observe that this patch does not fully pass around 
> pointers to instances of the classes, however, because I don't pass pointers 
> and the currently repetitive nature of the compression classes, this still 
> functions correctly.
> In short, a follow-up patch (which I will shortly upload) will convert this 
> to using class instances and passing those around.
> Including reworking functions throughout llvm-project to take advantage of 
> this.
> I am aiming to take this 2 step process to cut down on making an already 
> large pass larger.
> Let me know if you have any concerns or ideas.
But I'm not sure how this patch works correctly - wouldn't the line below 
(`CompressionScheme.supported()`) call `CompressionAlgorithm::supported()` 
which always returns false?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

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


[PATCH] D130519: [clang][dataflow] Add explicit "AST" nodes for implications and iff

2022-07-25 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr2 added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:332
+
+  if (LeftSubVar == RightSubVar) {
+// `X <=> (A <=> A)` is equvalent to `X` which is already in

xazax.hun wrote:
> xazax.hun wrote:
> > I wonder why this simplification is done here only for 
> > `BiconditionalValue`. Other operations seem to not do these sorts of 
> > simplifications. Also, when would we take this branch? `getOrCreateIff` has 
> > a special case when both operands are the same. 
> Oh, looking at the other patch I see it mentioning desugaring. So can 
> desugaring also introduce `Biconditional`s?
It is also necessary in the other cases due to the precondition of 
`addClause()`, I'm adding that special handling in a separate patch: 
https://reviews.llvm.org/D130522

We would take this branch when someone avoids using the DataflowContext API. So 
not extremely likely at the moment, but it is a latent bug that can be exposed 
by some future refactoring.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130519

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


[PATCH] D123319: Change how we handle auto return types for lambda operator() to be consistent with gcc

2022-07-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123319

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


[PATCH] D119051: Extend the C++03 definition of POD to include defaulted functions

2022-07-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119051

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


[PATCH] D130055: Clang extensions yolo, woot & kaboom

2022-07-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Any chance this could be a generalization of 
https://clang.llvm.org/doxygen/Consumed_8cpp_source.html ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130055

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


[PATCH] D130519: [clang][dataflow] Add explicit "AST" nodes for implications and iff

2022-07-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:332
+
+  if (LeftSubVar == RightSubVar) {
+// `X <=> (A <=> A)` is equvalent to `X` which is already in

xazax.hun wrote:
> I wonder why this simplification is done here only for `BiconditionalValue`. 
> Other operations seem to not do these sorts of simplifications. Also, when 
> would we take this branch? `getOrCreateIff` has a special case when both 
> operands are the same. 
Oh, looking at the other patch I see it mentioning desugaring. So can 
desugaring also introduce `Biconditional`s?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130519

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


[PATCH] D130519: [clang][dataflow] Add explicit "AST" nodes for implications and iff

2022-07-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp:332
+
+  if (LeftSubVar == RightSubVar) {
+// `X <=> (A <=> A)` is equvalent to `X` which is already in

I wonder why this simplification is done here only for `BiconditionalValue`. 
Other operations seem to not do these sorts of simplifications. Also, when 
would we take this branch? `getOrCreateIff` has a special case when both 
operands are the same. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130519

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


[clang] 1d23f6c - [Driver] Ignore unimplemented -mtune= for ARM/PowerPC

2022-07-25 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2022-07-25T15:05:38-07:00
New Revision: 1d23f6c5a4f6ebb101c282f8f506588fe4d9e92f

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

LOG: [Driver] Ignore unimplemented -mtune= for ARM/PowerPC

This compensates for 8f0c901c1a172313a32bc06a1fcface76cd1220f which enabled
-Wunused-command-line-argument for unimplemented -mtune= in the generic code.
Ignoring -mtune= appears to be longstanding and the error-free behavior in the
presence of -Werror is unfortunately relied on by the Linux kernel's arm and
powerpc ports. Ignore the warnings for the upcoming 15.0.0 branch and will
implement functionality to fill the test gap soon.

Link: https://github.com/ClangBuiltLinux/linux/issues/1674

Added: 


Modified: 
clang/lib/Driver/ToolChains/Arch/ARM.cpp
clang/lib/Driver/ToolChains/Arch/PPC.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Arch/ARM.cpp 
b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
index 5c49db2f08379..a64909d9a6e77 100644
--- a/clang/lib/Driver/ToolChains/Arch/ARM.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/ARM.cpp
@@ -548,6 +548,11 @@ void arm::getARMTargetFeatures(const Driver &D, const 
llvm::Triple &Triple,
   if (CPUArg)
 checkARMCPUName(D, CPUArg, Args, CPUName, ArchName, ExtensionFeatures,
 Triple, CPUArgFPUID);
+
+  // TODO Handle -mtune=. Suppress -Wunused-command-line-argument as a
+  // longstanding behavior.
+  (void)Args.getLastArg(options::OPT_mtune_EQ);
+
   // Honor -mfpu=. ClangAs gives preference to -Wa,-mfpu=.
   unsigned FPUID = llvm::ARM::FK_INVALID;
   const Arg *FPUArg = Args.getLastArg(options::OPT_mfpu_EQ);

diff  --git a/clang/lib/Driver/ToolChains/Arch/PPC.cpp 
b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
index bcaecf4b2d980..7817ec595ceb3 100644
--- a/clang/lib/Driver/ToolChains/Arch/PPC.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/PPC.cpp
@@ -107,6 +107,10 @@ const char *ppc::getPPCAsmModeForCPU(StringRef Name) {
 void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
const ArgList &Args,
std::vector &Features) {
+  // TODO Handle -mtune=. Suppress -Wunused-command-line-argument as a
+  // longstanding behavior.
+  (void)Args.getLastArg(options::OPT_mtune_EQ);
+
   if (Triple.getSubArch() == llvm::Triple::PPCSubArch_spe)
 Features.push_back("+spe");
 



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


[PATCH] D130523: [pseudo] Perform unconstrained recovery prior to completion.

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Apart from this patch, the main other things we need to allow missing brackets 
to be inferred:

- allow recovery to trigger subsequent recovery, even at EOF. (Simplest way is 
to address the FIXME at 660, it's pretty involved)
- allow opaque nodes to represent terminals

I have a prototype of all this working together locally, it seems to work...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130523

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


[PATCH] D130516: [Support] compression classes

2022-07-25 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added inline comments.



Comment at: clang/lib/Serialization/ASTWriter.cpp:2003-2004
   // consumers will not want its contents.
+  llvm::compression::CompressionAlgorithm CompressionScheme =
+  llvm::compression::ZlibCompressionAlgorithm();
+

dblaikie wrote:
> Doesn't this cause slicing & end up with the base implementation?
> 
> (also the base class `CompressionAlgorithm` has no virtual functions, so I'm 
> not sure how this is meant to work - does this code all work? Then I must be 
> missing some things - how does this work?)
You are correct to observe that this patch does not fully pass around pointers 
to instances of the classes, however, because I don't pass pointers and the 
currently repetitive nature of the compression classes, this still functions 
correctly.
In short, a follow-up patch (which I will shortly upload) will convert this to 
using class instances and passing those around.
Including reworking functions throughout llvm-project to take advantage of this.
I am aiming to take this 2 step process to cut down on making an already large 
pass larger.
Let me know if you have any concerns or ideas.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

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


[PATCH] D130523: [pseudo] Perform unconstrained recovery prior to completion.

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall updated this revision to Diff 447487.
sammccall added a comment.

restore removed debug


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130523

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp


Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -604,6 +604,33 @@
 "[  5, end) └─} := tok[5]\n");
 }
 
+TEST_F(GLRTest, RecoverUnrestrictedReduce) {
+  // Here, ! is not in any rule and therefore not in the follow set of `word`.
+  // We would not normally reduce `word := IDENTIFIER`, but do so for recovery.
+
+  build(R"bnf(
+_ := sentence
+
+word := IDENTIFIER
+sentence := word word [recover=AcceptAnyTokenInstead]
+  )bnf");
+
+  clang::LangOptions LOptions;
+  const TokenStream &Tokens = cook(lex("id !", LOptions), LOptions);
+  TestLang.Table = LRTable::buildSLR(TestLang.G);
+  TestLang.RecoveryStrategies.try_emplace(
+  extensionID("AcceptAnyTokenInstead"),
+  [](Token::Index Start, const TokenStream &Stream) { return Start + 1; });
+
+  const ForestNode &Parsed =
+  glrParse({Tokens, Arena, GSStack}, id("sentence"), TestLang);
+  EXPECT_EQ(Parsed.dumpRecursive(TestLang.G),
+"[  0, end) sentence := word word 
[recover=AcceptAnyTokenInstead]\n"
+"[  0,   1) ├─word := IDENTIFIER\n"
+"[  0,   1) │ └─IDENTIFIER := tok[0]\n"
+"[  1, end) └─word := \n");
+}
+
 TEST_F(GLRTest, NoExplicitAccept) {
   build(R"bnf(
 _ := test
Index: clang-tools-extra/pseudo/lib/GLR.cpp
===
--- clang-tools-extra/pseudo/lib/GLR.cpp
+++ clang-tools-extra/pseudo/lib/GLR.cpp
@@ -597,6 +597,10 @@
   std::vector Heads = {GSS.addNode(/*State=*/StartState,
   /*ForestNode=*/nullptr,
   {})};
+  // Invariant: Heads is partitioned by source: {shifted | reduced}.
+  // HeadsPartition is the index of the first head formed by reduction.
+  // We use this to discard and recreate the reduced heads during recovery.
+  unsigned HeadsPartition = 0;
   std::vector NextHeads;
   auto MaybeGC = [&, Roots(std::vector{}), I(0u)]() mutable 
{
 assert(NextHeads.empty() && "Running GC at the wrong time!");
@@ -619,8 +623,17 @@
 // If we weren't able to consume the token, try to skip over some tokens
 // so we can keep parsing.
 if (NextHeads.empty()) {
-  // FIXME: Heads may not be fully reduced, because our reductions were
-  // constrained by lookahead (but lookahead is meaningless to recovery).
+  // The reduction in the previous round was constrained by lookahead.
+  // On valid code this only rejects dead ends, but on broken code we 
should
+  // consider all possibilities.
+  //
+  // We discard all heads formed by reduction, and recreate them without
+  // this constraint. This may duplicate some nodes, but it's rare.
+  LLVM_DEBUG(llvm::dbgs() << "Shift failed, will attempt recovery. "
+ "Re-reducing without lookahead.");
+  Heads.resize(HeadsPartition);
+  Reduce(Heads, /*allow all reductions*/ tokenSymbol(tok::unknown));
+
   glrRecover(Heads, I, Params, Lang, NextHeads);
   if (NextHeads.empty())
 // FIXME: Ensure the `_ := start-symbol` rules have a fallback
@@ -632,6 +645,7 @@
 // Form nonterminals containing the token we just consumed.
 SymbolID Lookahead =
 I == Terminals.size() ? tokenSymbol(tok::eof) : Terminals[I].symbol();
+HeadsPartition = NextHeads.size();
 Reduce(NextHeads, Lookahead);
 // Prepare for the next token.
 std::swap(Heads, NextHeads);
Index: clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
===
--- clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
+++ clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
@@ -105,7 +105,11 @@
   bool canFollow(SymbolID Nonterminal, SymbolID Terminal) const {
 assert(isToken(Terminal));
 assert(isNonterminal(Nonterminal));
-return FollowSets.test(tok::NUM_TOKENS * Nonterminal +
+// tok::unknown is a sentinel value used in recovery: can follow anything.
+if (tok::unknown)
+  return true;
+return Terminal == tokenSymbol(tok::unknown) ||
+   FollowSets.test(tok::NUM_TOKENS * Nonterminal +
symbolToToken(Terminal));
   }
 


Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo

[PATCH] D130523: [pseudo] Perform unconstrained recovery prior to completion.

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: hokein.
Herald added a project: All.
sammccall requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

Our GLR uses lookahead: only perform reductions that might be consumed by the
shift immediately following. However when shift fails and so reduce is followed
by recovery instead, this restriction is incorrect and leads to missing heads.

In turn this means certain recovery strategies can't be made to work. e.g.

  ns := NAMESPACE { namespace-body } [recover=Skip]
  ns-body := namespace_opt

When `namespace { namespace {` is parsed, we can recover the inner `ns` (using
the `Skip` strategy to ignore the missing `}`). However this `namespace` will
not be reduced to a `namespace-body` as EOF is not in the follow-set, and so we
are unable to recover the outer `ns`.

This patch fixes this by tracking which heads were produced by constrained
reduce, and discarding and rebuilding them before performing recovery.

This is a prerequisite for the `Skip` strategy mentioned above, though there are
some other limitations we need to address too.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130523

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp

Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -604,6 +604,33 @@
 "[  5, end) └─} := tok[5]\n");
 }
 
+TEST_F(GLRTest, RecoverUnrestrictedReduce) {
+  // Here, ! is not in any rule and therefore not in the follow set of `word`.
+  // We would not normally reduce `word := IDENTIFIER`, but do so for recovery.
+
+  build(R"bnf(
+_ := sentence
+
+word := IDENTIFIER
+sentence := word word [recover=AcceptAnyTokenInstead]
+  )bnf");
+
+  clang::LangOptions LOptions;
+  const TokenStream &Tokens = cook(lex("id !", LOptions), LOptions);
+  TestLang.Table = LRTable::buildSLR(TestLang.G);
+  TestLang.RecoveryStrategies.try_emplace(
+  extensionID("AcceptAnyTokenInstead"),
+  [](Token::Index Start, const TokenStream &Stream) { return Start + 1; });
+
+  const ForestNode &Parsed =
+  glrParse({Tokens, Arena, GSStack}, id("sentence"), TestLang);
+  EXPECT_EQ(Parsed.dumpRecursive(TestLang.G),
+"[  0, end) sentence := word word [recover=AcceptAnyTokenInstead]\n"
+"[  0,   1) ├─word := IDENTIFIER\n"
+"[  0,   1) │ └─IDENTIFIER := tok[0]\n"
+"[  1, end) └─word := \n");
+}
+
 TEST_F(GLRTest, NoExplicitAccept) {
   build(R"bnf(
 _ := test
Index: clang-tools-extra/pseudo/lib/GLR.cpp
===
--- clang-tools-extra/pseudo/lib/GLR.cpp
+++ clang-tools-extra/pseudo/lib/GLR.cpp
@@ -43,7 +43,6 @@
 unsigned &TokenIndex, const ParseParams &Params,
 const Language &Lang,
 std::vector &NewHeads) {
-  LLVM_DEBUG(llvm::dbgs() << "Recovery at token " << TokenIndex << "...\n");
   // Describes a possibility to recover by forcibly interpreting a range of
   // tokens around the cursor as a nonterminal that we expected to see.
   struct PlaceholderRecovery {
@@ -597,6 +596,10 @@
   std::vector Heads = {GSS.addNode(/*State=*/StartState,
   /*ForestNode=*/nullptr,
   {})};
+  // Invariant: Heads is partitioned by source: {shifted | reduced}.
+  // HeadsPartition is the index of the first head formed by reduction.
+  // We use this to discard and recreate the reduced heads during recovery.
+  unsigned HeadsPartition = 0;
   std::vector NextHeads;
   auto MaybeGC = [&, Roots(std::vector{}), I(0u)]() mutable {
 assert(NextHeads.empty() && "Running GC at the wrong time!");
@@ -619,8 +622,17 @@
 // If we weren't able to consume the token, try to skip over some tokens
 // so we can keep parsing.
 if (NextHeads.empty()) {
-  // FIXME: Heads may not be fully reduced, because our reductions were
-  // constrained by lookahead (but lookahead is meaningless to recovery).
+  // The reduction in the previous round was constrained by lookahead.
+  // On valid code this only rejects dead ends, but on broken code we should
+  // consider all possibilities.
+  //
+  // We discard all heads formed by reduction, and recreate them without
+  // this constraint. This may duplicate some nodes, but it's rare.
+  LLVM_DEBUG(llvm::dbgs() << "Shift failed, will attempt recovery. "
+ "Re-reducing without lookahead.");
+  Heads.resize(HeadsPartition);
+  Reduce(Heads, /*allow all reductions*/ tokenSym

[PATCH] D130519: [clang][dataflow] Add explicit "AST" nodes for implications and iff

2022-07-25 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr updated this revision to Diff 447484.
gribozavr added a comment.

Normalized more comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130519

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -251,12 +251,16 @@
 
   // Creates a boolean implication value.
   BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-return disj(neg(LeftSubVal), RightSubVal);
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
   }
 
   // Creates a boolean biconditional value.
   BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
   }
 
 private:
Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -188,6 +188,19 @@
   expectUnsatisfiable(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}));
 }
 
+TEST(SolverTest, IffIsEquivalentToDNF) {
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto Y = Ctx.atom();
+  auto NotX = Ctx.neg(X);
+  auto NotY = Ctx.neg(Y);
+  auto XIffY = Ctx.iff(X, Y);
+  auto XIffYDNF = Ctx.disj(Ctx.conj(X, Y), Ctx.conj(NotX, NotY));
+  auto NotEquivalent = Ctx.neg(Ctx.iff(XIffY, XIffYDNF));
+
+  expectUnsatisfiable(solve({NotEquivalent}));
+}
+
 TEST(SolverTest, IffSameVars) {
   ConstraintContext Ctx;
   auto X = Ctx.atom();
@@ -279,6 +292,17 @@
   expectUnsatisfiable(solve({XEqY, X, NotY}));
 }
 
+TEST(SolverTest, ImplicationIsEquivalentToDNF) {
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto Y = Ctx.atom();
+  auto XImpliesY = Ctx.impl(X, Y);
+  auto XImpliesYDNF = Ctx.disj(Ctx.neg(X), Y);
+  auto NotEquivalent = Ctx.neg(Ctx.iff(XImpliesY, XImpliesYDNF));
+
+  expectUnsatisfiable(solve({NotEquivalent}));
+}
+
 TEST(SolverTest, ImplicationConflict) {
   ConstraintContext Ctx;
   auto X = Ctx.atom();
Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -64,33 +64,24 @@
 }
 
 TEST(BoolValueDebugStringTest, Implication) {
-  // B0 => B1, implemented as !B0 v B1
+  // B0 => B1
   ConstraintContext Ctx;
-  auto B = Ctx.disj(Ctx.neg(Ctx.atom()), Ctx.atom());
+  auto B = Ctx.impl(Ctx.atom(), Ctx.atom());
 
-  auto Expected = R"((or
-(not
-B0)
+  auto Expected = R"((=>
+B0
 B1))";
   EXPECT_THAT(debugString(*B), StrEq(Expected));
 }
 
 TEST(BoolValueDebugStringTest, Iff) {
-  // B0 <=> B1, implemented as (!B0 v B1) ^ (B0 v !B1)
+  // B0 <=> B1
   ConstraintContext Ctx;
-  auto B0 = Ctx.atom();
-  auto B1 = Ctx.atom();
-  auto B = Ctx.conj(Ctx.disj(Ctx.neg(B0), B1), Ctx.disj(B0, Ctx.neg(B1)));
+  auto B = Ctx.iff(Ctx.atom(), Ctx.atom());
 
-  auto Expected = R"((and
-(or
-(not
-B0)
-B1)
-(or
-B0
-(not
-B1";
+  auto Expected = R"((=
+B0
+B1))";
   EXPECT_THAT(debugString(*B), StrEq(Expected));
 }
 
Index: clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -304,7 +304,7 @@
 }
 #endif
 
-TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionsAtomicFC) {
+TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionContainingAtomic) {
   auto &X = Context.createAtomicBoolValue();
   auto &True = Context.getBoolLiteralValue(true);
   auto &False = Context.getBoolLiteralValue(false);
@@ -313,18 +313,18 @@
   auto &FC = Context.makeFlowConditionToken();
   Context.addFlowConditionConstraint(FC, X);
 
-  // If X is true in FC, FC = X must be true
+  // If X is true, FC 

[PATCH] D130522: [clang][dataflow] Fix SAT solver crashes on `X ^ X` and `X v X`

2022-07-25 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: martong, tschuett, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
gribozavr requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

BooleanFormula::addClause has an invariant that a clause has no duplicated
literals. When the solver was desugaring a formula into CNF clauses, it
could construct a clause with such duplicated literals in two cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130522

Files:
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -120,7 +120,7 @@
   expectUnsatisfiable(solve({NotXAndY, XAndY}));
 }
 
-TEST(SolverTest, DisjunctionSameVars) {
+TEST(SolverTest, DisjunctionSameVarWithNegation) {
   ConstraintContext Ctx;
   auto X = Ctx.atom();
   auto NotX = Ctx.neg(X);
@@ -130,6 +130,15 @@
   expectSatisfiable(solve({XOrNotX}), _);
 }
 
+TEST(SolverTest, DisjunctionSameVar) {
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto XOrX = Ctx.disj(X, X);
+
+  // X v X
+  expectSatisfiable(solve({XOrX}), _);
+}
+
 TEST(SolverTest, ConjunctionSameVarsConflict) {
   ConstraintContext Ctx;
   auto X = Ctx.atom();
@@ -140,6 +149,15 @@
   expectUnsatisfiable(solve({XAndNotX}));
 }
 
+TEST(SolverTest, ConjunctionSameVar) {
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto XAndX = Ctx.conj(X, X);
+
+  // X ^ X
+  expectSatisfiable(solve({XAndX}), _);
+}
+
 TEST(SolverTest, PureVar) {
   ConstraintContext Ctx;
   auto X = Ctx.atom();
Index: clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
===
--- clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
+++ clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
@@ -263,30 +263,51 @@
   const Variable LeftSubVar = GetVar(&C->getLeftSubValue());
   const Variable RightSubVar = GetVar(&C->getRightSubValue());
 
-  // `X <=> (A ^ B)` is equivalent to `(!X v A) ^ (!X v B) ^ (X v !A v !B)`
-  // which is already in conjunctive normal form. Below we add each of the
-  // conjuncts of the latter expression to the result.
-  Formula.addClause(negLit(Var), posLit(LeftSubVar));
-  Formula.addClause(negLit(Var), posLit(RightSubVar));
-  Formula.addClause(posLit(Var), negLit(LeftSubVar), negLit(RightSubVar));
-
-  // Visit the sub-values of `Val`.
-  UnprocessedSubVals.push(&C->getLeftSubValue());
-  UnprocessedSubVals.push(&C->getRightSubValue());
+  if (LeftSubVar == RightSubVar) {
+// `X <=> (A ^ A)` is equivalent to `(!X v A) ^ (X v !A)` which is
+// already in conjunctive normal form. Below we add each of the
+// conjuncts of the latter expression to the result.
+Formula.addClause(negLit(Var), posLit(LeftSubVar));
+Formula.addClause(posLit(Var), negLit(LeftSubVar));
+
+// Visit a sub-value of `Val` (pick any, they are identical).
+  } else {
+// `X <=> (A ^ B)` is equivalent to `(!X v A) ^ (!X v B) ^ (X v !A v !B)`
+// which is already in conjunctive normal form. Below we add each of the
+// conjuncts of the latter expression to the result.
+Formula.addClause(negLit(Var), posLit(LeftSubVar));
+Formula.addClause(negLit(Var), posLit(RightSubVar));
+Formula.addClause(posLit(Var), negLit(LeftSubVar), negLit(RightSubVar));
+
+// Visit the sub-values of `Val`.
+UnprocessedSubVals.push(&C->getLeftSubValue());
+UnprocessedSubVals.push(&C->getRightSubValue());
+  }
 } else if (auto *D = dyn_cast(Val)) {
   const Variable LeftSubVar = GetVar(&D->getLeftSubValue());
   const Variable RightSubVar = GetVar(&D->getRightSubValue());
 
-  // `X <=> (A v B)` is equivalent to `(!X v A v B) ^ (X v !A) ^ (X v !B)`
-  // which is already in conjunctive normal form. Below we add each of the
-  // conjuncts of the latter expression to the result.
-  Formula.addClause(negLit(Var), posLit(LeftSubVar), posLit(RightSubVar));
-  Formula.addClause(posLit(Var), negLit(LeftSubVar));
-  Formula.addClause(posLit(Var), negLit(RightSubVar));
+  if (LeftSubVar == RightSubVar) {
+// `X <=> (A v A)` is equivalent to `(!X v A) ^ (X v !A)` which is
+// already in conjunctive normal form. Below we add each of the
+// conjuncts of the latter expression to the result.
+Formula.addClause(negLit(Var), posLit(LeftSubVar));
+Formula.addClause(posLit(Var), negLit(LeftSubVar));
 
-  // Visit the sub-values of `Val`.
-  UnprocessedSubVals.push(&D->getLeftSubValue());
-  UnprocessedSubVals.

[PATCH] D130516: [Support] compression classes

2022-07-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

Thanks for experimenting the refactoring. My gut feeling is that

- for inheritance `llvm/lib/Support/Compression.cpp` introduces quite a bit of 
complexity.
- BestSpeedCompression/DefaultCompression/BestSizeCompression may be kinda 
weird. Not all algorithms may need all of three.
- this new interface does not make parallel compression/decompression easier.

I mentioned this on 
https://groups.google.com/g/generic-abi/c/satyPkuMisk/m/xRqMj8M3AwAJ

> I know the paradox of choice:) Certainly that we should not add a plethora of 
> bzip2, xz, lzo, brotli, etc to generic-abi. I don't think users are so fond 
> of using a different format for a slight different read/write/compression 
> ratio/memory usage need. They want to pick one format which performs well 
> across a wide variety of workloads. (Adding a new format also introduces 
> complexity on their build system side. They need to teach DWARF consumers 
> they use. It's not a small undertaking.)

I think for a long time llvm/lib/Support/Compression.cpp will stay with just 
zlib and zstd. There is a possibility if a llvm-project use case needs an 
alternative (it needs very strong arguments not using zstd), it has the other 
approach that not using llvm/Support/Compression.h


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

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


[PATCH] D119296: KCFI sanitizer

2022-07-25 Thread Sami Tolvanen via Phabricator via cfe-commits
samitolvanen added a comment.

In D119296#3673297 , @MaskRay wrote:

> It seems that we can miss the branch to have more time mature the feature and 
> have it for 16.0.

Sure, that sounds reasonable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119296

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


[PATCH] D130516: [Support] compression classes

2022-07-25 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/Serialization/ASTWriter.cpp:2003-2004
   // consumers will not want its contents.
+  llvm::compression::CompressionAlgorithm CompressionScheme =
+  llvm::compression::ZlibCompressionAlgorithm();
+

Doesn't this cause slicing & end up with the base implementation?

(also the base class `CompressionAlgorithm` has no virtual functions, so I'm 
not sure how this is meant to work - does this code all work? Then I must be 
missing some things - how does this work?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

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


[PATCH] D130519: [clang][dataflow] Add explicit "AST" nodes for implications and iff

2022-07-25 Thread Dmitri Gribenko via Phabricator via cfe-commits
gribozavr created this revision.
Herald added subscribers: martong, tschuett, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
gribozavr requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Previously we used to desugar implications and biconditionals into
equivalent CNF/DNF as soon as possible. However, this desugaring makes
debug output (Environment::dump()) less readable than it could be.
Therefore, it makes sense to keep the sugared representation of a
boolean formula, and desugar it in the solver.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130519

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
  clang/include/clang/Analysis/FlowSensitive/Value.h
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
  clang/lib/Analysis/FlowSensitive/WatchedLiteralsSolver.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
  clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
  clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
  clang/unittests/Analysis/FlowSensitive/TestingSupport.h

Index: clang/unittests/Analysis/FlowSensitive/TestingSupport.h
===
--- clang/unittests/Analysis/FlowSensitive/TestingSupport.h
+++ clang/unittests/Analysis/FlowSensitive/TestingSupport.h
@@ -251,12 +251,16 @@
 
   // Creates a boolean implication value.
   BoolValue *impl(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-return disj(neg(LeftSubVal), RightSubVal);
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
   }
 
   // Creates a boolean biconditional value.
   BoolValue *iff(BoolValue *LeftSubVal, BoolValue *RightSubVal) {
-return conj(impl(LeftSubVal, RightSubVal), impl(RightSubVal, LeftSubVal));
+Vals.push_back(
+std::make_unique(*LeftSubVal, *RightSubVal));
+return Vals.back().get();
   }
 
 private:
Index: clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SolverTest.cpp
@@ -188,6 +188,19 @@
   expectUnsatisfiable(solve({XOrY, NotXOrY, NotXOrNotY, XOrNotY}));
 }
 
+TEST(SolverTest, IffIsEquivalentToDNF) {
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto Y = Ctx.atom();
+  auto NotX = Ctx.neg(X);
+  auto NotY = Ctx.neg(Y);
+  auto XIffY = Ctx.iff(X, Y);
+  auto XIffYDNF = Ctx.disj(Ctx.conj(X, Y), Ctx.conj(NotX, NotY));
+  auto NotEquivalent = Ctx.neg(Ctx.iff(XIffY, XIffYDNF));
+
+  expectUnsatisfiable(solve({NotEquivalent}));
+}
+
 TEST(SolverTest, IffSameVars) {
   ConstraintContext Ctx;
   auto X = Ctx.atom();
@@ -279,6 +292,17 @@
   expectUnsatisfiable(solve({XEqY, X, NotY}));
 }
 
+TEST(SolverTest, ImplicationIsEquivalentToDNF) {
+  ConstraintContext Ctx;
+  auto X = Ctx.atom();
+  auto Y = Ctx.atom();
+  auto XImpliesY = Ctx.impl(X, Y);
+  auto XImpliesYDNF = Ctx.disj(Ctx.neg(X), Y);
+  auto NotEquivalent = Ctx.neg(Ctx.iff(XImpliesY, XImpliesYDNF));
+
+  expectUnsatisfiable(solve({NotEquivalent}));
+}
+
 TEST(SolverTest, ImplicationConflict) {
   ConstraintContext Ctx;
   auto X = Ctx.atom();
Index: clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DebugSupportTest.cpp
@@ -64,33 +64,24 @@
 }
 
 TEST(BoolValueDebugStringTest, Implication) {
-  // B0 => B1, implemented as !B0 v B1
+  // B0 => B1
   ConstraintContext Ctx;
-  auto B = Ctx.disj(Ctx.neg(Ctx.atom()), Ctx.atom());
+  auto B = Ctx.impl(Ctx.atom(), Ctx.atom());
 
-  auto Expected = R"((or
-(not
-B0)
+  auto Expected = R"((=>
+B0
 B1))";
   EXPECT_THAT(debugString(*B), StrEq(Expected));
 }
 
 TEST(BoolValueDebugStringTest, Iff) {
-  // B0 <=> B1, implemented as (!B0 v B1) ^ (B0 v !B1)
+  // B0 <=> B1
   ConstraintContext Ctx;
-  auto B0 = Ctx.atom();
-  auto B1 = Ctx.atom();
-  auto B = Ctx.conj(Ctx.disj(Ctx.neg(B0), B1), Ctx.disj(B0, Ctx.neg(B1)));
+  auto B = Ctx.iff(Ctx.atom(), Ctx.atom());
 
-  auto Expected = R"((and
-(or
-(not
-B0)
-B1)
-(or
-B0
-(not
-B1";
+  auto Expected = R"((=
+B0
+B1))";
   EXPECT_THAT(debugString(*B), StrEq(Expected));
 }
 
Index: clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/DataflowAnalysisContextTest.cpp
@@ -304,7 +304,7 @@
 }
 #endif
 
-TEST_F(DataflowAnalysisContextTest, SubstituteFlowConditionsAtomicFC) {
+T

[PATCH] D130516: [Support] compression classes

2022-07-25 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 447469.
ckissane added a comment.

- format
- merge fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130516

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  lld/ELF/Driver.cpp
  lld/ELF/InputSection.cpp
  llvm/include/llvm/Object/Decompressor.h
  llvm/include/llvm/Support/Compression.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  llvm/lib/Object/Decompressor.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/Compression.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/ProfileData/InstrProfTest.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -22,31 +22,43 @@
 
 namespace {
 
-#if LLVM_ENABLE_ZLIB
-static void testZlibCompression(StringRef Input, int Level) {
+static void testCompressionAlgorithm(
+StringRef Input, int Level,
+compression::CompressionAlgorithm CompressionScheme,
+std::string ExpectedDestinationBufferTooSmallErrorMessage) {
   SmallVector Compressed;
   SmallVector Uncompressed;
-  zlib::compress(arrayRefFromStringRef(Input), Compressed, Level);
+  CompressionScheme.compress(arrayRefFromStringRef(Input), Compressed, Level);
 
   // Check that uncompressed buffer is the same as original.
-  Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
+  Error E =
+  CompressionScheme.decompress(Compressed, Uncompressed, Input.size());
   consumeError(std::move(E));
 
   EXPECT_EQ(Input, toStringRef(Uncompressed));
   if (Input.size() > 0) {
 // Uncompression fails if expected length is too short.
-E = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
-EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
+E = CompressionScheme.decompress(Compressed, Uncompressed,
+ Input.size() - 1);
+EXPECT_EQ(ExpectedDestinationBufferTooSmallErrorMessage,
+  llvm::toString(std::move(E)));
   }
 }
 
+#if LLVM_ENABLE_ZLIB
+static void testZlibCompression(StringRef Input, int Level) {
+  testCompressionAlgorithm(Input, Level, ZlibCompressionAlgorithm(),
+   "zlib error: Z_BUF_ERROR");
+}
+
 TEST(CompressionTest, Zlib) {
-  testZlibCompression("", zlib::DefaultCompression);
+  compression::CompressionAlgorithm CompressionScheme =
+  compression::ZlibCompressionAlgorithm();
+  testZlibCompression("", CompressionScheme.DefaultCompression);
 
-  testZlibCompression("hello, world!", zlib::NoCompression);
-  testZlibCompression("hello, world!", zlib::BestSizeCompression);
-  testZlibCompression("hello, world!", zlib::BestSpeedCompression);
-  testZlibCompression("hello, world!", zlib::DefaultCompression);
+  testZlibCompression("hello, world!", CompressionScheme.BestSizeCompression);
+  testZlibCompression("hello, world!", CompressionScheme.BestSpeedCompression);
+  testZlibCompression("hello, world!", CompressionScheme.DefaultCompression);
 
   const size_t kSize = 1024;
   char BinaryData[kSize];
@@ -54,38 +66,27 @@
 BinaryData[i] = i & 255;
   StringRef BinaryDataStr(BinaryData, kSize);
 
-  testZlibCompression(BinaryDataStr, zlib::NoCompression);
-  testZlibCompression(BinaryDataStr, zlib::BestSizeCompression);
-  testZlibCompression(BinaryDataStr, zlib::BestSpeedCompression);
-  testZlibCompression(BinaryDataStr, zlib::DefaultCompression);
+  testZlibCompression(BinaryDataStr, CompressionScheme.BestSizeCompression);
+  testZlibCompression(BinaryDataStr, CompressionScheme.BestSpeedCompression);
+  testZlibCompression(BinaryDataStr, CompressionScheme.DefaultCompression);
 }
 #endif
 
 #if LLVM_ENABLE_ZSTD
-static void testZstdCompression(StringRef Input, int Level) {
-  SmallVector Compressed;
-  SmallVector Uncompressed;
-  zstd::compress(arrayRefFromStringRef(Input), Compressed, Level);
 
-  // Check that uncompressed buffer is the same as original.
-  Error E = zstd::uncompress(Compressed, Uncompressed, Input.size());
-  consumeError(std::move(E));
-
-  EXPECT_EQ(Input, toStringRef(Uncompressed));
-  if (Input.size() > 0) {
-// Uncompression fails if expected length is too short.
-E = zstd::uncompress(Compressed, Uncompressed, Input.size() - 1);
-EXPECT_EQ("Destination buffer is too small", llvm::toString(std::move(E)));
-  }
+static void te

[PATCH] D130516: [Support] compression classes

2022-07-25 Thread Cole Kissane via Phabricator via cfe-commits
ckissane created this revision.
ckissane added a reviewer: dblaikie.
Herald added subscribers: wenlei, usaxena95, kadircet, arphaman, hiraditya, 
arichardson, emaste.
Herald added a reviewer: alexander-shaposhnikov.
Herald added a reviewer: rupprecht.
Herald added a reviewer: jhenderson.
Herald added a reviewer: MaskRay.
Herald added a project: All.
ckissane requested review of this revision.
Herald added subscribers: cfe-commits, llvm-commits, StephenFan.
Herald added projects: clang, LLVM, clang-tools-extra.

compression algorithm base class, two (or three, if it's useful to have a 
default implementation for "None") derived classes, singleton instances of each 
and a function that takes the algorithm type and returns the handler - which 
can then be queried for "is available" and provides compress/decompress 
actions. That'd mean having only one switch instead of three, but the three are 
now so close together that it's not hugely painful to maintain (though having a 
class hierarchy would ensure the APIs were actually identical, whereas 
currently they're only identical by convention).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130516

Files:
  clang-tools-extra/clangd/index/Serialization.cpp
  clang-tools-extra/clangd/unittests/SerializationTests.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  lld/ELF/Driver.cpp
  lld/ELF/InputSection.cpp
  llvm/include/llvm/Object/Decompressor.h
  llvm/include/llvm/Support/Compression.h
  llvm/lib/MC/ELFObjectWriter.cpp
  llvm/lib/ObjCopy/ELF/ELFObject.cpp
  llvm/lib/Object/Decompressor.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingReader.cpp
  llvm/lib/ProfileData/Coverage/CoverageMappingWriter.cpp
  llvm/lib/ProfileData/InstrProf.cpp
  llvm/lib/ProfileData/SampleProfReader.cpp
  llvm/lib/ProfileData/SampleProfWriter.cpp
  llvm/lib/Support/Compression.cpp
  llvm/tools/llvm-mc/llvm-mc.cpp
  llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
  llvm/unittests/ProfileData/InstrProfTest.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -22,31 +22,43 @@
 
 namespace {
 
-#if LLVM_ENABLE_ZLIB
-static void testZlibCompression(StringRef Input, int Level) {
+static void testCompressionAlgorithm(
+StringRef Input, int Level,
+compression::CompressionAlgorithm CompressionScheme,
+std::string ExpectedDestinationBufferTooSmallErrorMessage) {
   SmallVector Compressed;
   SmallVector Uncompressed;
-  zlib::compress(arrayRefFromStringRef(Input), Compressed, Level);
+  CompressionScheme.compress(arrayRefFromStringRef(Input), Compressed, Level);
 
   // Check that uncompressed buffer is the same as original.
-  Error E = zlib::uncompress(Compressed, Uncompressed, Input.size());
+  Error E =
+  CompressionScheme.decompress(Compressed, Uncompressed, Input.size());
   consumeError(std::move(E));
 
   EXPECT_EQ(Input, toStringRef(Uncompressed));
   if (Input.size() > 0) {
 // Uncompression fails if expected length is too short.
-E = zlib::uncompress(Compressed, Uncompressed, Input.size() - 1);
-EXPECT_EQ("zlib error: Z_BUF_ERROR", llvm::toString(std::move(E)));
+E = CompressionScheme.decompress(Compressed, Uncompressed,
+ Input.size() - 1);
+EXPECT_EQ(ExpectedDestinationBufferTooSmallErrorMessage,
+  llvm::toString(std::move(E)));
   }
 }
 
+#if LLVM_ENABLE_ZLIB
+static void testZlibCompression(StringRef Input, int Level) {
+  testCompressionAlgorithm(Input, Level, ZlibCompressionAlgorithm(),
+   "zlib error: Z_BUF_ERROR");
+}
+
 TEST(CompressionTest, Zlib) {
-  testZlibCompression("", zlib::DefaultCompression);
+  compression::CompressionAlgorithm CompressionScheme =
+  compression::ZlibCompressionAlgorithm();
+  testZlibCompression("", CompressionScheme.DefaultCompression);
 
-  testZlibCompression("hello, world!", zlib::NoCompression);
-  testZlibCompression("hello, world!", zlib::BestSizeCompression);
-  testZlibCompression("hello, world!", zlib::BestSpeedCompression);
-  testZlibCompression("hello, world!", zlib::DefaultCompression);
+  testZlibCompression("hello, world!", CompressionScheme.BestSizeCompression);
+  testZlibCompression("hello, world!", CompressionScheme.BestSpeedCompression);
+  testZlibCompression("hello, world!", CompressionScheme.DefaultCompression);
 
   const size_t kSize = 1024;
   char BinaryData[kSize];
@@ -54,38 +66,27 @@
 BinaryData[i] = i & 255;
   StringRef BinaryDataStr(BinaryData, kSize);
 
-  testZlibCompression(BinaryDataStr, zlib::NoCompression);
-  testZlibCompression(BinaryDataStr, zlib::BestSizeCompression);
-  testZlibCompression(BinaryDataStr, zlib::BestSpeedCompression);
-  testZlibCompression(BinaryDataStr, zlib::DefaultC

[PATCH] D101070: [llvm][cmake] Make `install_symlink` workflow work with absolute install dirs

2022-07-25 Thread John Ericson via Phabricator via cfe-commits
Ericson2314 updated this revision to Diff 447465.
Ericson2314 added a comment.

Avoid extend_path


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/LLVMInstallSymlink.cmake


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -6,17 +6,20 @@
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  if(NOT IS_ABSOLUTE "${outdir}")
+set(outdir "${CMAKE_INSTALL_PREFIX}/${outdir}")
+  endif()
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1953,7 +1953,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" 
"PARAMS;DEPENDS;ARGS" ${ARGN})
-
+
 if (NOT ARG_FOLDER)
   set(ARG_FOLDER "Test Subdirectories")
 endif()
@@ -2009,11 +2009,11 @@
 
   set(output_dir lib${LLVM_LIBDIR_SUFFIX})
   if(WIN32 AND "${type}" STREQUAL "SHARED")
-set(output_dir bin)
+set(output_dir "${CMAKE_INSTALL_BINDIR}")
   endif()
 
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
 endfunction()
@@ -2048,8 +2048,10 @@
 set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
   endif()
 
+  set(output_dir "${${project}_TOOLS_INSTALL_DIR}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} 
${${project}_TOOLS_INSTALL_DIR})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
   if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -6,17 +6,20 @@
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  if(NOT IS_ABSOLUTE "${outdir}")
+set(outdir "${CMAKE_INSTALL_PREFIX}/${outdir}")
+  endif()
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1953,7 +1953,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" "PARAMS;DEPENDS;ARGS" ${ARGN})
-
+
 if (NOT ARG_FOLDER)
   set(ARG_FOLDER "Test Subdirectories")
 endif()
@@ -2009,11 +2009,11 @@
 
   set(output_dir lib${LLVM_LIBDIR_SUFFIX})
   if(WIN32 AND "${type}" STREQUAL "SHARED")
-set(output_dir bin)
+set(output_dir "${CMAKE_INSTALL_BINDIR}")
   endif()
 
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\")"
   COMPONENT ${component})
 
 endfunction()
@@ -2048,8 +2048,10 @@
 set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
   endif()
 
+  set(output_dir "${${project}_TOOLS_INSTALL_DIR}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} ${${project}_TOOLS_INSTALL_DIR})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" \"${output_dir}\")"
   COMPONENT ${component})
 
   if (

[PATCH] D101070: [llvm][cmake] Make `install_symlink` workflow work with absolute install dirs

2022-07-25 Thread John Ericson 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 rG5acd376438a5: [llvm][cmake] Make `install_symlink` workflow 
work with absolute install dirs (authored by Ericson2314).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

Files:
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/LLVMInstallSymlink.cmake


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -1,22 +1,26 @@
 # We need to execute this script at installation time because the
 # DESTDIR environment variable may be unset at configuration time.
 # See PR8397.
+#
+# `outdir` must be an absolute path. This module gets a very reduced
+# `CMAKE_MODULE_PATH` so it is easier to make the caller the responsible
+# for this.
 
 include(GNUInstallDirs)
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1,4 +1,5 @@
 include(GNUInstallDirs)
+include(ExtendPath)
 include(LLVMDistributionSupport)
 include(LLVMProcessSources)
 include(LLVM-Config)
@@ -1953,7 +1954,7 @@
 function(add_lit_testsuites project directory)
   if (NOT LLVM_ENABLE_IDE)
 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "FOLDER" 
"PARAMS;DEPENDS;ARGS" ${ARGN})
-
+
 if (NOT ARG_FOLDER)
   set(ARG_FOLDER "Test Subdirectories")
 endif()
@@ -2009,11 +2010,14 @@
 
   set(output_dir lib${LLVM_LIBDIR_SUFFIX})
   if(WIN32 AND "${type}" STREQUAL "SHARED")
-set(output_dir bin)
+set(output_dir "${CMAKE_INSTALL_BINDIR}")
   endif()
 
+  # `install_symlink` needs an absoute path.
+  extend_path(output_dir "${CMAKE_INSTALL_PREFIX}" "${output_dir}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} ${output_dir})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
 endfunction()
@@ -2048,8 +2052,11 @@
 set(full_dest llvm${CMAKE_EXECUTABLE_SUFFIX})
   endif()
 
+  # `install_symlink` needs an absoute path.
+  extend_path(output_dir "${CMAKE_INSTALL_PREFIX}" 
"${${project}_TOOLS_INSTALL_DIR}")
+
   install(SCRIPT ${INSTALL_SYMLINK}
-  CODE "install_symlink(${full_name} ${full_dest} 
${${project}_TOOLS_INSTALL_DIR})"
+  CODE "install_symlink(\"${full_name}\" \"${full_dest}\" 
\"${output_dir}\")"
   COMPONENT ${component})
 
   if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE)


Index: llvm/cmake/modules/LLVMInstallSymlink.cmake
===
--- llvm/cmake/modules/LLVMInstallSymlink.cmake
+++ llvm/cmake/modules/LLVMInstallSymlink.cmake
@@ -1,22 +1,26 @@
 # We need to execute this script at installation time because the
 # DESTDIR environment variable may be unset at configuration time.
 # See PR8397.
+#
+# `outdir` must be an absolute path. This module gets a very reduced
+# `CMAKE_MODULE_PATH` so it is easier to make the caller the responsible
+# for this.
 
 include(GNUInstallDirs)
 
 function(install_symlink name target outdir)
   set(DESTDIR $ENV{DESTDIR})
-  set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}")
+  set(outdir "${DESTDIR}${outdir}")
 
   message(STATUS "Creating ${name}")
 
   execute_process(
 COMMAND "${CMAKE_COMMAND}" -E create_symlink "${target}" "${name}"
-WORKING_DIRECTORY "${bindir}" ERROR_VARIABLE has_err)
+WORKING_DIRECTORY "${outdir}" ERROR_VARIABLE has_err)
   if(CMAKE_HOST_WIN32 AND has_err)
 execute_process(
   COMMAND "${CMAKE_COMMAND}" -E copy "${target}" "${name}"
-  WORKING_DIRECTORY "${bindir}")
+  WORKING_DIRECTORY "${outdir}")
   endif()
 
 endfunction()
Index: llvm/cmake/modules/AddLLVM.cmake
===
--- llvm/cmake/modules/AddLLVM.cmake
+++ llvm/cmake/modules/AddLLVM.cmake
@@ -1,4 +1,5 @@
 include(GNUInstallDirs)
+include(ExtendPath)
 include(LLVMDistributionSupport)
 include(LLVMProcessSources)
 include(LLVM-Config)
@

[PATCH] D129884: [clang][deps] Include canonical invocation in ContextHash

2022-07-25 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

Would it make sense for this to replace the existing strict context hash 
implementation?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129884

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


[PATCH] D117973: [cmake] Support custom package install paths

2022-07-25 Thread John Ericson via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Ericson2314 marked 2 inline comments as done.
Closed by commit rGac0d1d5c7b7e: [cmake] Support custom package install paths 
(authored by Ericson2314).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D117973

Files:
  clang/cmake/modules/CMakeLists.txt
  cmake/Modules/FindPrefixFromConfig.cmake
  cmake/Modules/GNUInstallPackageDir.cmake
  flang/cmake/modules/CMakeLists.txt
  lld/cmake/modules/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/CMakeLists.txt
  mlir/cmake/modules/CMakeLists.txt
  polly/cmake/CMakeLists.txt

Index: polly/cmake/CMakeLists.txt
===
--- polly/cmake/CMakeLists.txt
+++ polly/cmake/CMakeLists.txt
@@ -1,10 +1,19 @@
 # Keep this in sync with llvm/cmake/CMakeLists.txt!
 
+include(GNUInstallPackageDir)
 include(ExtendPath)
 include(FindPrefixFromConfig)
 
-set(LLVM_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
-set(POLLY_INSTALL_PACKAGE_DIR "lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
+set(POLLY_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/polly" CACHE STRING
+  "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')")
+# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
+set(polly_cmake_builddir "${POLLY_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/polly")
+
+set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
+  "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
+# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
+set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
+
 if (CMAKE_CONFIGURATION_TYPES)
   set(POLLY_EXPORTS_FILE_NAME "PollyExports-$>.cmake")
 else()
@@ -28,9 +37,6 @@
   set(POLLY_CONFIG_TARGET_${tgt}_TYPE ${tgt_type})
 endforeach()
 
-set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
-set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
-
 # generate the import code for bundled/undbundled libisl versions
 if (NOT POLLY_BUNDLED_ISL)
   get_property(incl TARGET ISL PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
@@ -50,7 +56,8 @@
 
 # Generate PollyConfig.cmake for the build tree.
 set(POLLY_CONFIG_CODE "")
-set(POLLY_CONFIG_CMAKE_DIR "${CMAKE_BINARY_DIR}/${POLLY_INSTALL_PACKAGE_DIR}")
+set(POLLY_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
+set(POLLY_CONFIG_CMAKE_DIR "${polly_cmake_builddir}")
 set(POLLY_CONFIG_INCLUDE_DIRS
   ${POLLY_SOURCE_DIR}/include
   ${ISL_INCLUDE_DIRS}
@@ -73,11 +80,11 @@
 # the imported locations
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/PollyConfig.cmake.in
-  ${POLLY_CONFIG_CMAKE_DIR}/PollyConfig.cmake
+  ${polly_cmake_builddir}/PollyConfig.cmake
   @ONLY)
 
 file(GENERATE
-  OUTPUT ${POLLY_CONFIG_CMAKE_DIR}/${POLLY_EXPORTS_FILE_NAME}
+  OUTPUT ${polly_cmake_builddir}/${POLLY_EXPORTS_FILE_NAME}
   CONTENT "${POLLY_EXPORTS}")
 
 
Index: mlir/cmake/modules/CMakeLists.txt
===
--- mlir/cmake/modules/CMakeLists.txt
+++ mlir/cmake/modules/CMakeLists.txt
@@ -1,3 +1,4 @@
+include(GNUInstallPackageDir)
 include(ExtendPath)
 include(LLVMDistributionSupport)
 include(FindPrefixFromConfig)
@@ -5,12 +6,16 @@
 # Generate a list of CMake library targets so that other CMake projects can
 # link against them. LLVM calls its version of this file LLVMExports.cmake, but
 # the usual CMake convention seems to be ${Project}Targets.cmake.
-set(MLIR_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir)
-set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/${MLIR_INSTALL_PACKAGE_DIR}")
+set(MLIR_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/mlir" CACHE STRING
+  "Path for CMake subdirectory for Polly (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/polly')")
+# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
+set(mlir_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/mlir")
 
 # Keep this in sync with llvm/cmake/CMakeLists.txt!
-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
-set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
+set(LLVM_INSTALL_PACKAGE_DIR "${CMAKE_INSTALL_PACKAGEDIR}/llvm" CACHE STRING
+  "Path for CMake subdirectory for LLVM (defaults to '${CMAKE_INSTALL_PACKAGEDIR}/llvm')")
+# CMAKE_INSTALL_PACKAGEDIR might be absolute, so don't reuse below.
+set(llvm_cmake_builddir "${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
 
 get_property(MLIR_EXPORTS GLOBAL PROPERTY MLIR_EXPORTS)
 export(TARGETS ${MLIR_EXPORTS} FILE ${mlir_cmake_builddir}/MLIRTargets.cmake)
@@ -54,8 +59,8 @@
 
 # Generate MLIRConfig.cmake for the install tree.
 find_prefix_from_config(MLIR_CONFIG_CODE MLIR_INSTALL_PREFIX "${MLIR_INSTALL_PACKAGE_DIR}")
-set(MLIR_CONFI

[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Roman Rusyaev via Phabricator via cfe-commits
rusyaev-roman added a comment.

@ChuanqiXu , I've added additional comments. Could you check again please?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D130511: [pseudo][wip] Eliminate simple-type-specifier ambiguities.

2022-07-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

My main concern here is that this might reject valid code (and if it doesn't, 
it's not obvious why).

It does look like C++ forbids the cases I can come up with (e.g. trying to 
provide a definition for `::Foo` is rejected by clang with "definition or 
redeclaration of Foo cannot name the global scope).
But I'd be way more comfortable if we could connect the specific guard rules 
here with spec language.

If we can't do this rigorously and merely are trying to encourage the *common* 
parse, then we should do it in soft disambig.

I'd like to think about this some more, do you know what part of the spec says 
that `x ::y` is invalid if x is e.g. a typedef for `int`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130511

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


[PATCH] D119792: [Clang] [P2025] Analyze only potential scopes for NRVO

2022-07-25 Thread Roman Rusyaev via Phabricator via cfe-commits
rusyaev-roman added inline comments.



Comment at: clang/include/clang/Sema/Scope.h:213-215
+  /// A single NRVO candidate variable in this scope, or nullptr if the
+  /// candidate is not available/allowed in this scope.
+  Optional NRVO;

ChuanqiXu wrote:
> Now NRVO has three states, None, nullptr and non-null value.But it doesn't 
> show in comments and implementations.
Actually it's used. I'll add additional comments for clarification.



Comment at: clang/lib/Sema/Scope.cpp:151
+void Scope::applyNRVOAndMergeItIntoParent() {
+  if (!NRVO.hasValue())
+// There is no NRVO candidate in the current scope.

ChuanqiXu wrote:
> 
nullptr should be considered below. I'll add a comment to demonstrate why it is.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D119792

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


[PATCH] D130510: Missing tautological compare warnings due to unary operators

2022-07-25 Thread Muhammad Usman Shahid via Phabricator via cfe-commits
Codesbyusman updated this revision to Diff 447453.
Codesbyusman added a comment.

also updating for the Xor bitwise operator


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130510

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/SemaCXX/warn-unreachable.cpp


Index: clang/test/SemaCXX/warn-unreachable.cpp
===
--- clang/test/SemaCXX/warn-unreachable.cpp
+++ clang/test/SemaCXX/warn-unreachable.cpp
@@ -399,13 +399,13 @@
   // TODO: Extend warning to the following code:
   if (x < -1)
 calledFun();
-  if (x == -1)
-calledFun();
+  if (x == -1)   // expected-note {{silence}}
+calledFun(); // expected-warning {{will never be executed}}
 
-  if (x != -1)
+  if (x != -1)   // expected-note {{silence}}
 calledFun();
   else
-calledFun();
+calledFun(); // expected-warning {{will never be executed}}
   if (-1 > x)
 calledFun();
   else
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -964,42 +964,51 @@
 const Expr *LHSExpr = B->getLHS()->IgnoreParens();
 const Expr *RHSExpr = B->getRHS()->IgnoreParens();
 
-const IntegerLiteral *IntLiteral = dyn_cast(LHSExpr);
-const Expr *BoolExpr = RHSExpr;
+const Expr *BoolExpr = nullptr; // To store the expression.
+Expr::EvalResult IntExprResult; // If integer literal then will save value.
 
-if (!IntLiteral) {
-  IntLiteral = dyn_cast(RHSExpr);
+if (LHSExpr->EvaluateAsInt(IntExprResult, *Context)) {
+   // Evaluating value.
+  BoolExpr = RHSExpr;
+}
+else if (RHSExpr->EvaluateAsInt(IntExprResult, *Context)) {
   BoolExpr = LHSExpr;
 }
-
-if (!IntLiteral)
+else
+{
   return TryResult();
+}
 
 const BinaryOperator *BitOp = dyn_cast(BoolExpr);
 if (BitOp && (BitOp->getOpcode() == BO_And ||
-  BitOp->getOpcode() == BO_Or)) {
+  BitOp->getOpcode() == BO_Or  || 
+  BitOp->getOpcode() == BO_Xor)) {
   const Expr *LHSExpr2 = BitOp->getLHS()->IgnoreParens();
   const Expr *RHSExpr2 = BitOp->getRHS()->IgnoreParens();
+  
+  // If integer literal in expression identified then will save value.
+  Expr::EvalResult IntExprResult2; 
 
-  const IntegerLiteral *IntLiteral2 = dyn_cast(LHSExpr2);
-
-  if (!IntLiteral2)
-IntLiteral2 = dyn_cast(RHSExpr2);
-
-  if (!IntLiteral2)
+  
+  if (LHSExpr2->EvaluateAsInt(IntExprResult2, *Context));
+  else if ( RHSExpr2->EvaluateAsInt(IntExprResult2, *Context));
+  else
 return TryResult();
 
-  llvm::APInt L1 = IntLiteral->getValue();
-  llvm::APInt L2 = IntLiteral2->getValue();
+  // Getting the values as integer from the evaluation expression to use 
for comparision.
+  llvm::APInt L1 = IntExprResult.Val.getInt(); 
+  llvm::APInt L2 = IntExprResult2.Val.getInt();
+
   if ((BitOp->getOpcode() == BO_And && (L2 & L1) != L1) ||
-  (BitOp->getOpcode() == BO_Or  && (L2 | L1) != L1)) {
+  (BitOp->getOpcode() == BO_Or  && (L2 | L1) != L1) || 
+  (BitOp->getOpcode() == BO_Xor && (L2 ^ L1) != L1) ) {
 if (BuildOpts.Observer)
   BuildOpts.Observer->compareBitwiseEquality(B,
  B->getOpcode() != BO_EQ);
 TryResult(B->getOpcode() != BO_EQ);
   }
 } else if (BoolExpr->isKnownToHaveBooleanValue()) {
-  llvm::APInt IntValue = IntLiteral->getValue();
+  llvm::APInt IntValue = IntExprResult.Val.getInt(); // Getting the value.
   if ((IntValue == 1) || (IntValue == 0)) {
 return TryResult();
   }


Index: clang/test/SemaCXX/warn-unreachable.cpp
===
--- clang/test/SemaCXX/warn-unreachable.cpp
+++ clang/test/SemaCXX/warn-unreachable.cpp
@@ -399,13 +399,13 @@
   // TODO: Extend warning to the following code:
   if (x < -1)
 calledFun();
-  if (x == -1)
-calledFun();
+  if (x == -1)   // expected-note {{silence}}
+calledFun(); // expected-warning {{will never be executed}}
 
-  if (x != -1)
+  if (x != -1)   // expected-note {{silence}}
 calledFun();
   else
-calledFun();
+calledFun(); // expected-warning {{will never be executed}}
   if (-1 > x)
 calledFun();
   else
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -964,42 +964,51 @@
 const Expr *LHSExpr = B->getLHS()->IgnoreParens();
 const Expr *RHSExpr = B->getRHS()->IgnoreParens();
 
-const IntegerLiteral *IntLiteral = dyn_cast(LHSExpr);
-const Expr *BoolExpr = RHSExpr;
+const Expr *BoolExpr = nullptr; // To store the expression.
+Expr::EvalResult IntEx

[PATCH] D130095: [clangd] Improve XRefs support for ObjCMethodDecl

2022-07-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, lgtm!




Comment at: clang-tools-extra/clangd/XRefs.cpp:89
+  return MD;
+auto *DeclCtx = cast(MD->getDeclContext());
+if (DeclCtx->isInvalidDecl())

can you have a comment here saying "Look for method definition inside the 
implementation decl"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130095

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-07-25 Thread Peter Klausler via Phabricator via cfe-commits
klausler added inline comments.



Comment at: flang/runtime/main.cpp:51
+  if (Fortran::runtime::executionEnvironment.conversion !=
+  Fortran::runtime::Convert::Unknown)
+return;

We always use braces on if/for/while/&c. constructs in the runtime.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130513

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-07-25 Thread Peter Klausler via Phabricator via cfe-commits
klausler added a comment.

Instead of adding new custom APIs that let command-line options control 
behavior is a way that is redundant with the runtime environment, I suggest 
that you try a more general runtime library API by which the main program can 
specify a default environment variable setting, or a set of them.  Then turn 
the command-line options into the equivalent environment settings and pass them 
as default settings that could be overridden by the actual environment.

This would not be any more work, it would lead to a cleaner implementation in 
the runtime than this one, and it would make the next option of this kind much 
easier to implement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130513

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


[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-07-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

In D129973#3673094 , @SimplyDanny 
wrote:

> Thank you for the review! Before I push the change into main I may add an 
> entry to `clang/docs/ReleaseNotes.rst`, right?

Yes, please add an entry in the release notes.

> And do you agree that the test failures are unrelated to my change? It looks 
> like they are all located in `libomptarget` caused by a linker error.

They don't look related but as always you should be ready to revert if any of 
the builds break in a way that you can't fix quickly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129973

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-07-25 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic added a comment.

I do have a few related lingering questions as well:

1. While this implementation mimics gfortran's behavior, there are still 
differences with other compilers (please see the comment here: 
https://github.com/llvm/llvm-project/issues/55961#issuecomment-1175677659). Is 
there a good place to document this (if worthwhile)?
2. There are a few differences in how gfortran and this implementation 
prioritize the convert command line option, environment variable, and CONVERT= 
specifier (please see comment here 
https://github.com/llvm/llvm-project/issues/55961#issuecomment-1172547132). 
Would this be worthwhile to change to match gfortran as well? If not, is there 
maybe a good place to document this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130513

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-07-25 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic created this revision.
jpenix-quic added reviewers: schweitz, klausler, peixin, awarzynski.
jpenix-quic added a project: Flang.
Herald added subscribers: mehdi_amini, jdoerfert, mgorny.
Herald added a reviewer: sscalpone.
Herald added a project: All.
jpenix-quic requested review of this revision.
Herald added subscribers: cfe-commits, sstefan1, MaskRay.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.

This follows gfortran's approach of generating a runtime call to set
the conversion state for the entire program and takes effect only if
the fconvert option is used on the main program (as the runtime call
is inserted into _QQmain).

Resolves issue: https://github.com/llvm/llvm-project/issues/55961


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130513

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/FrontendOptions.h
  flang/include/flang/Lower/Bridge.h
  flang/include/flang/Optimizer/Builder/Runtime/Convert.h
  flang/include/flang/Runtime/convert.h
  flang/include/flang/Runtime/main.h
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/FrontendActions.cpp
  flang/lib/Lower/Bridge.cpp
  flang/lib/Optimizer/Builder/CMakeLists.txt
  flang/lib/Optimizer/Builder/Runtime/Convert.cpp
  flang/runtime/environment.cpp
  flang/runtime/environment.h
  flang/runtime/main.cpp
  flang/test/Driver/convert.f90
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/frontend-forwarding.f90
  flang/tools/bbc/bbc.cpp
  flang/unittests/Runtime/ExternalIOTest.cpp

Index: flang/unittests/Runtime/ExternalIOTest.cpp
===
--- flang/unittests/Runtime/ExternalIOTest.cpp
+++ flang/unittests/Runtime/ExternalIOTest.cpp
@@ -149,6 +149,67 @@
   << "EndIoStatement() for Close";
 }
 
+TEST(ExternalIOTests, TestDirectUnformattedSwappedConvert) {
+  // OPEN(NEWUNIT=unit,ACCESS='DIRECT',ACTION='READWRITE',&
+  //   FORM='UNFORMATTED',RECL=8,STATUS='SCRATCH',CONVERT='NATIVE')
+  auto *io{IONAME(BeginOpenNewUnit)(__FILE__, __LINE__)};
+  ASSERT_TRUE(IONAME(SetAccess)(io, "DIRECT", 6)) << "SetAccess(DIRECT)";
+  ASSERT_TRUE(IONAME(SetAction)(io, "READWRITE", 9)) << "SetAction(READWRITE)";
+  ASSERT_TRUE(IONAME(SetForm)(io, "UNFORMATTED", 11)) << "SetForm(UNFORMATTED)";
+  ASSERT_TRUE(IONAME(SetConvert)(io, "NATIVE", 6)) << "SetConvert(NATIVE)";
+
+  std::int64_t buffer;
+  static constexpr std::size_t recl{sizeof buffer};
+  ASSERT_TRUE(IONAME(SetRecl)(io, recl)) << "SetRecl()";
+  ASSERT_TRUE(IONAME(SetStatus)(io, "SCRATCH", 7)) << "SetStatus(SCRATCH)";
+
+  int unit{-1};
+  ASSERT_TRUE(IONAME(GetNewUnit)(io, unit)) << "GetNewUnit()";
+  ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
+  << "EndIoStatement() for OpenNewUnit";
+
+  static constexpr int records{10};
+  for (int j{1}; j <= records; ++j) {
+// WRITE(UNIT=unit,REC=j) j
+io = IONAME(BeginUnformattedOutput)(unit, __FILE__, __LINE__);
+ASSERT_TRUE(IONAME(SetRec)(io, j)) << "SetRec(" << j << ')';
+buffer = j;
+ASSERT_TRUE(IONAME(OutputUnformattedBlock)(
+io, reinterpret_cast(&buffer), recl, recl))
+<< "OutputUnformattedBlock()";
+ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
+<< "EndIoStatement() for OutputUnformattedBlock";
+  }
+
+  // Set unformatted conversion to SWAP
+  RTNAME(ConvertOption)(4);
+  // OPEN(UNIT=unit,STATUS='OLD')
+  io = IONAME(BeginOpenUnit)(unit, __FILE__, __LINE__);
+  ASSERT_TRUE(IONAME(SetStatus)(io, "OLD", 3)) << "SetStatus(OLD)";
+  ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
+  << "EndIoStatement() for OpenUnit";
+
+  for (int j{records}; j >= 1; --j) {
+// READ(UNIT=unit,REC=j) n
+io = IONAME(BeginUnformattedInput)(unit, __FILE__, __LINE__);
+ASSERT_TRUE(IONAME(SetRec)(io, j)) << "SetRec(" << j << ')';
+ASSERT_TRUE(IONAME(InputUnformattedBlock)(
+io, reinterpret_cast(&buffer), recl, recl))
+<< "InputUnformattedBlock()";
+ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
+<< "EndIoStatement() for InputUnformattedBlock";
+ASSERT_EQ(buffer >> 56, j)
+<< "Read back " << (buffer >> 56) << " from direct unformatted record "
+<< j << ", expected " << j << '\n';
+  }
+
+  // CLOSE(UNIT=unit,STATUS='DELETE')
+  io = IONAME(BeginClose)(unit, __FILE__, __LINE__);
+  ASSERT_TRUE(IONAME(SetStatus)(io, "DELETE", 6)) << "SetStatus(DELETE)";
+  ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
+  << "EndIoStatement() for Close";
+}
+
 TEST(ExternalIOTests, TestSequentialFixedUnformatted) {
   // OPEN(NEWUNIT=unit,ACCESS='SEQUENTIAL',ACTION='READWRITE',&
   //   FORM='UNFORMATTED',RECL=8,STATUS='SCRATCH')
Index: flang/tools/bbc/bbc.cpp
===
--- flang/tools/bbc/bbc.cpp
+++ flang/tools/bbc/bbc.cpp
@@ -33,6 +33,7 @@
 #include "flang/Parser/parsing.h"
 #

[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D130224#3677224 , @aaron.ballman 
wrote:

> However, what I think I'm hearing from this thread is that there are 
> alternative approaches that have been thought about but not tried, we're not 
> certain how feasible those approaches are in practice, but we expect them to 
> be materially worse than what's proposed here. So it's not "this was the path 
> of least resistance", but "this is the correct design." Do others agree with 
> that assessment?

I think this is just the least bad on the menu of available options. I don't 
like it, but it at least provides documentation about this special behavior.

I think the only other plausible option is to assert this is still undefined 
behavior and force users to update their (newly declared invalid) code. We 
could at least partially re-optimize to uninitialized values in the backend 
(although this is apparently difficult in some situations)


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

https://reviews.llvm.org/D130224

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


[PATCH] D130511: [pseudo][wip] Eliminate simple-type-specifier ambiguities.

2022-07-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a project: All.
hokein requested review of this revision.
Herald added a subscriber: alextsao1999.
Herald added a project: clang-tools-extra.

The solution is to favor the longest possible nest-name-specifier, and
drop other alternatives by using the guard.

This is my attempt, this might not be a right approach, looking for initial
thoughts.

Motivated cases:

  Foo::Foo() {};
  // the constructor can be parsed as:
  //  - Foo ::Foo(); // where the first Foo is return-type, and ::Foo is the 
function declarator
  //  + Foo::Foo(); // where Foo::Foo is the function declarator



  void test() {
  
  // a very slow parsing case when there are many qualifers!
  X::Y::Z;
  // The statement can be parsed as:
  //  - X ::Y::Z; // ::Y::Z is the declarator
  //  - X::Y ::Z; // ::Z is the declarator
  //  + X::Y::Z;  // a declaration without declarator (X::Y::Z is 
decl-specifier-seq)
  //  + X::Y::Z;  // a qualifed-id expression
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130511

Files:
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/cxx/cxx.bnf


Index: clang-tools-extra/pseudo/lib/cxx/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx/cxx.bnf
@@ -370,11 +370,11 @@
 defining-type-specifier := enum-specifier
 defining-type-specifier-seq := defining-type-specifier
 defining-type-specifier-seq := defining-type-specifier 
defining-type-specifier-seq [guard]
-simple-type-specifier := nested-name-specifier_opt type-name
+simple-type-specifier := nested-name-specifier_opt type-name [guard]
 simple-type-specifier := nested-name-specifier TEMPLATE simple-template-id
 simple-type-specifier := decltype-specifier
 simple-type-specifier := placeholder-type-specifier
-simple-type-specifier := nested-name-specifier_opt template-name
+simple-type-specifier := nested-name-specifier_opt template-name [guard]
 simple-type-specifier := builtin-type
 builtin-type := CHAR
 builtin-type := CHAR8_T
Index: clang-tools-extra/pseudo/lib/cxx/CXX.cpp
===
--- clang-tools-extra/pseudo/lib/cxx/CXX.cpp
+++ clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -162,6 +162,10 @@
   return symbolToToken(P.Lookahead) != tok::kw_else;
 }
 
+bool guardNextTokenNotColCol(const GuardParams &P) {
+  return symbolToToken(P.Lookahead) != tok::coloncolon;
+}
+
 // Whether this e.g. decl-specifier contains an "exclusive" type such as a 
class
 // name, and thus can't combine with a second exclusive type.
 //
@@ -308,6 +312,16 @@

selection_statement_0if_1constexpr_2l_paren_3condition_4r_paren_5statement,
guardNextTokenNotElse},
 
+  {(RuleID)Rule::simple_type_specifier_0nested_name_specifier_1type_name,
+   guardNextTokenNotColCol},
+  
{(RuleID)Rule::simple_type_specifier_0nested_name_specifier_1template_name,
+   guardNextTokenNotColCol},
+  {(RuleID)Rule::simple_type_specifier_0type_name,
+   guardNextTokenNotColCol},
+  {(RuleID)Rule::simple_type_specifier_0template_name,
+   guardNextTokenNotColCol
+  },
+
   // The grammar distinguishes (only) user-defined vs plain string 
literals,
   // where the clang lexer distinguishes (only) encoding types.
   {(RuleID)Rule::user_defined_string_literal_chunk_0string_literal,


Index: clang-tools-extra/pseudo/lib/cxx/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx/cxx.bnf
@@ -370,11 +370,11 @@
 defining-type-specifier := enum-specifier
 defining-type-specifier-seq := defining-type-specifier
 defining-type-specifier-seq := defining-type-specifier defining-type-specifier-seq [guard]
-simple-type-specifier := nested-name-specifier_opt type-name
+simple-type-specifier := nested-name-specifier_opt type-name [guard]
 simple-type-specifier := nested-name-specifier TEMPLATE simple-template-id
 simple-type-specifier := decltype-specifier
 simple-type-specifier := placeholder-type-specifier
-simple-type-specifier := nested-name-specifier_opt template-name
+simple-type-specifier := nested-name-specifier_opt template-name [guard]
 simple-type-specifier := builtin-type
 builtin-type := CHAR
 builtin-type := CHAR8_T
Index: clang-tools-extra/pseudo/lib/cxx/CXX.cpp
===
--- clang-tools-extra/pseudo/lib/cxx/CXX.cpp
+++ clang-tools-extra/pseudo/lib/cxx/CXX.cpp
@@ -162,6 +162,10 @@
   return symbolToToken(P.Lookahead) != tok::kw_else;
 }
 
+bool guardNextTokenNotColCol(const GuardParams &P) {
+  return symbolToToken(P.Lookahead) != tok::coloncolon;
+}
+
 // Whether this e.g. decl-specifier contains an "exclusive" type such as a class
 // name, and thus can't combine with a second exclusive type.
 //
@@ -308,

[PATCH] D129973: [clang] Pass FoundDecl to DeclRefExpr creator for operator overloads

2022-07-25 Thread Danny Mösch via Phabricator via cfe-commits
SimplyDanny added a comment.

In D129973#3673094 , @SimplyDanny 
wrote:

> Thank you for the review! Before I push the change into main I may add an 
> entry to `clang/docs/ReleaseNotes.rst`, right?
>
> And do you agree that the test failures are unrelated to my change? It looks 
> like they are all located in `libomptarget` caused by a linker error.

@shafik: Could you give one last feedback on this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129973

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


[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

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

LGTM (aside from some small nits that you can fix when landing).




Comment at: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp:27
+  return ((int)e1 != -1) & ((int)e2 != -1) &
+ // CHECK: error: load of value , which is not a valid value 
for type 'enum EBool'
+ ((int)e3 != -1) & ((int)e4 == 1) &

shafik wrote:
> aaron.ballman wrote:
> > erichkeane wrote:
> > > What does THIS come from?  What value is unknown?  Shouldn't the -1 be 
> > > fine?
> > +1, I'm surprised by the `` there, but also... neither `e1` nor 
> > `e2` are of type `enum EBool`!
> So it looks like clang knows that the only valid values for a bool enum is 0 
> or 1 and it will mask the value accordingly see godbolt for example using 
> `argc` : https://godbolt.org/z/ceb9hPno9
> 
> So that would explain why the original test used a `unsigned char*` in order 
> to prompt the diagnostic. 
> 
> Looking into the ubsan diagnostic it looks like it treats bool as an unknown 
> value, separate from integer and float. It is not clear to me why it does 
> this but fixing that feels outside the scope of this change since this was 
> part of the original test.
Thanks for looking into it! I agree that fixing the ubsan diagnostic behavior 
is out of scope. That said, can you move the CHECK lines so that they come 
*after* the line of code being checked? I think that's what threw me for a loop 
regarding the `EBool` confusion I had.


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

https://reviews.llvm.org/D130301

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


[PATCH] D101070: [llvm][cmake] Make `install_symlink` workflow work with absolute install dirs

2022-07-25 Thread Sebastian Neubauer via Phabricator via cfe-commits
sebastian-ne accepted this revision.
sebastian-ne added a comment.
This revision is now accepted and ready to land.

No problem, thanks for the fixes!
LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D101070

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


[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D130224#3677144 , @arsenm wrote:

> In D130224#3668243 , @aaron.ballman 
> wrote:
>
>> I'm still not seeing the issue fully. My understanding of the situation 
>> (which may be wrong) is that Clang lowers to LLVM IR and adds `noundef` 
>> markings at call sites that this patch attempts to let the user then undo. 
>> However, why can Clang's CodeGen not notice the special builtin and walk up 
>> the call chain to mark all the wrapper functions to ensure everything is 
>> marked appropriately? There might be a small perf loss (if there are 
>> wrappers around wrappers around wrappers kind of situation), but this means 
>> we don't have to expose this problem to users.
>
> This requires maintaining logic in clang to specially recognize these N 
> wrapper functions, and there would be no indication in the source that this 
> magic is occurring. It's less maintainable because it requires tight, magic 
> coupling between these functions in the source and special handling in clang 
> to be maintained if anything were to change

I was thinking of something more general than that where Clang only has to 
specially recognize the builtins and which arguments to the builtin should be 
tracked to make maybeundef when walking up the call chain. However, you're not 
wrong about this being a bit magical in terms of behavior. I don't know that we 
have anything else which behaves this way.

In D130224#3677167 , @jdoerfert wrote:

>> I still think that a solution which doesn't require the user to make such 
>> dangerous decisions on their own is a better design if we can accomplish it.
>
> This is a valid opinion but I don't see how this matches what we do (or has 
> been done) in the past. I mean, there are plenty of command line options and 
> attributes that do exactly this, let the user "define", or better "refine", 
> semantics.
> The entire "initialize with 0" stuff comes to mind, making new things UB with 
> -ffast-math and friends, overloadable, etc.

Thanks, this is a good question to be asking!

We are adding attributes in a way which doesn't scale well; many attributes 
interact with one another and we have basically no test coverage for those 
situations and very little thought put into diagnostic behavior. Now that we've 
got over 400 attributes in the tree, I'm realizing I probably should have been 
saying "no" more to attributes that don't carry enough weight to be worth the 
maintenance burden, but oh well, I can't unring that bell. I have *no issue* 
with attributes that are going to be things we expect users to use themselves. 
Stuff like "initialize with 0", overloadable, etc are all things that enable 
users to do something they couldn't previously do. However, in recent history, 
we've been adding more attributes that are for compiler glue code rather than 
users. On the one hand, attributes are a great use for such a thing. On the 
other hand, there's no way to control who uses the attribute (unless we put in 
special logic to only allow it to be written in a system header, or something 
like that). So glue code attributes are a different "thing" to me than 
user-facing attributes, and I'm worried at how many we're adding without any 
real design thought put behind them other than "we need it to solve this one 
case". If we could come up with some tablegen marking to say "this attribute is 
for glue code use only" that we could use to generate diagnostics on "misuse", 
generate documentation differently from, etc, that would go a long ways towards 
alleviating the concerns about user confusion with glue code attributes and 
"real" attributes (for lack of a better term).

Of course, these are high-level worries and not necessarily specific to this 
review or anything I expect someone here to take action on. Take this as 
background information rather than a code owner mandate or anything like that. 
Specific to this review, my concern is that this is an attribute that controls 
undefined behavior in LLVM rather directly (as opposed to things like 
"initialize to 0" which impact UB, but aren't as tightly tied to the LLVM 
backend architecture). That's a worry for two reasons: the tight coupling to 
LLVM IR attribute semantics (basically, this means LLVM's "freeze" instruction 
can't change meaning  because it will potentially break user code) and misuse 
due to misunderstanding the purpose of the attribute ("this makes my code more 
secure!"). Special compiler magic alleviates both of those concerns because it 
means we aren't exposing the tight coupling and users aren't given a chance to 
misuse the attribute.

However, what I think I'm hearing from this thread is that there are 
alternative approaches that have been thought about but not tried, we're not 
certain how feasible those approaches are in practice, but we expect them to be 
materiall

[PATCH] D130510: Missing tautological compare warnings due to unary operators

2022-07-25 Thread Muhammad Usman Shahid via Phabricator via cfe-commits
Codesbyusman updated this revision to Diff 447440.
Codesbyusman edited the summary of this revision.
Codesbyusman added a comment.

updating to more efficient


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130510

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/SemaCXX/warn-unreachable.cpp


Index: clang/test/SemaCXX/warn-unreachable.cpp
===
--- clang/test/SemaCXX/warn-unreachable.cpp
+++ clang/test/SemaCXX/warn-unreachable.cpp
@@ -399,13 +399,13 @@
   // TODO: Extend warning to the following code:
   if (x < -1)
 calledFun();
-  if (x == -1)
-calledFun();
+  if (x == -1)   // expected-note {{silence}}
+calledFun(); // expected-warning {{will never be executed}}
 
-  if (x != -1)
+  if (x != -1)   // expected-note {{silence}}
 calledFun();
   else
-calledFun();
+calledFun(); // expected-warning {{will never be executed}}
   if (-1 > x)
 calledFun();
   else
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -964,33 +964,40 @@
 const Expr *LHSExpr = B->getLHS()->IgnoreParens();
 const Expr *RHSExpr = B->getRHS()->IgnoreParens();
 
-const IntegerLiteral *IntLiteral = dyn_cast(LHSExpr);
-const Expr *BoolExpr = RHSExpr;
+const Expr *BoolExpr = nullptr; // To store the expression.
+Expr::EvalResult IntExprResult; // If integer literal then will save value.
 
-if (!IntLiteral) {
-  IntLiteral = dyn_cast(RHSExpr);
+if (LHSExpr->EvaluateAsInt(IntExprResult, *Context)) {
+   // Evaluating value.
+  BoolExpr = RHSExpr;
+}
+else if (RHSExpr->EvaluateAsInt(IntExprResult, *Context)) {
   BoolExpr = LHSExpr;
 }
-
-if (!IntLiteral)
+else
+{
   return TryResult();
+}
 
 const BinaryOperator *BitOp = dyn_cast(BoolExpr);
 if (BitOp && (BitOp->getOpcode() == BO_And ||
   BitOp->getOpcode() == BO_Or)) {
   const Expr *LHSExpr2 = BitOp->getLHS()->IgnoreParens();
   const Expr *RHSExpr2 = BitOp->getRHS()->IgnoreParens();
+  
+  // If integer literal in expression identified then will save value.
+  Expr::EvalResult IntExprResult2; 
 
-  const IntegerLiteral *IntLiteral2 = dyn_cast(LHSExpr2);
-
-  if (!IntLiteral2)
-IntLiteral2 = dyn_cast(RHSExpr2);
-
-  if (!IntLiteral2)
+  
+  if (LHSExpr2->EvaluateAsInt(IntExprResult2, *Context));
+  else if ( RHSExpr2->EvaluateAsInt(IntExprResult2, *Context));
+  else
 return TryResult();
 
-  llvm::APInt L1 = IntLiteral->getValue();
-  llvm::APInt L2 = IntLiteral2->getValue();
+  // Getting the values as integer from the evaluation expression to use 
for comparision.
+  llvm::APInt L1 = IntExprResult.Val.getInt(); 
+  llvm::APInt L2 = IntExprResult2.Val.getInt();
+
   if ((BitOp->getOpcode() == BO_And && (L2 & L1) != L1) ||
   (BitOp->getOpcode() == BO_Or  && (L2 | L1) != L1)) {
 if (BuildOpts.Observer)
@@ -999,7 +1006,7 @@
 TryResult(B->getOpcode() != BO_EQ);
   }
 } else if (BoolExpr->isKnownToHaveBooleanValue()) {
-  llvm::APInt IntValue = IntLiteral->getValue();
+  llvm::APInt IntValue = IntExprResult.Val.getInt(); // Getting the value.
   if ((IntValue == 1) || (IntValue == 0)) {
 return TryResult();
   }


Index: clang/test/SemaCXX/warn-unreachable.cpp
===
--- clang/test/SemaCXX/warn-unreachable.cpp
+++ clang/test/SemaCXX/warn-unreachable.cpp
@@ -399,13 +399,13 @@
   // TODO: Extend warning to the following code:
   if (x < -1)
 calledFun();
-  if (x == -1)
-calledFun();
+  if (x == -1)   // expected-note {{silence}}
+calledFun(); // expected-warning {{will never be executed}}
 
-  if (x != -1)
+  if (x != -1)   // expected-note {{silence}}
 calledFun();
   else
-calledFun();
+calledFun(); // expected-warning {{will never be executed}}
   if (-1 > x)
 calledFun();
   else
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -964,33 +964,40 @@
 const Expr *LHSExpr = B->getLHS()->IgnoreParens();
 const Expr *RHSExpr = B->getRHS()->IgnoreParens();
 
-const IntegerLiteral *IntLiteral = dyn_cast(LHSExpr);
-const Expr *BoolExpr = RHSExpr;
+const Expr *BoolExpr = nullptr; // To store the expression.
+Expr::EvalResult IntExprResult; // If integer literal then will save value.
 
-if (!IntLiteral) {
-  IntLiteral = dyn_cast(RHSExpr);
+if (LHSExpr->EvaluateAsInt(IntExprResult, *Context)) {
+   // Evaluating value.
+  BoolExpr = RHSExpr;
+}
+else if (RHSExpr->EvaluateAsInt(IntExprResult, *Context)) {
   Bo

[PATCH] D130510: updating the function for the tautological warnings for the unary operators

2022-07-25 Thread Muhammad Usman Shahid via Phabricator via cfe-commits
Codesbyusman created this revision.
Codesbyusman added reviewers: aaron.ballman, erichkeane, xgupta.
Herald added a reviewer: NoQ.
Herald added a project: All.
Codesbyusman requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130510

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/SemaCXX/warn-unreachable.cpp


Index: clang/test/SemaCXX/warn-unreachable.cpp
===
--- clang/test/SemaCXX/warn-unreachable.cpp
+++ clang/test/SemaCXX/warn-unreachable.cpp
@@ -399,13 +399,13 @@
   // TODO: Extend warning to the following code:
   if (x < -1)
 calledFun();
-  if (x == -1)
-calledFun();
+  if (x == -1)   // expected-note {{silence}}
+calledFun(); // expected-warning {{will never be executed}}
 
-  if (x != -1)
+  if (x != -1)   // expected-note {{silence}}
 calledFun();
   else
-calledFun();
+calledFun(); // expected-warning {{will never be executed}}
   if (-1 > x)
 calledFun();
   else
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -964,33 +964,43 @@
 const Expr *LHSExpr = B->getLHS()->IgnoreParens();
 const Expr *RHSExpr = B->getRHS()->IgnoreParens();
 
-const IntegerLiteral *IntLiteral = dyn_cast(LHSExpr);
-const Expr *BoolExpr = RHSExpr;
+const Expr *BoolExpr = nullptr; // To store the expression.
+Expr::EvalResult IntExprResult; // If integer literal then will save value.
 
-if (!IntLiteral) {
-  IntLiteral = dyn_cast(RHSExpr);
+if (IsIntegerLiteralConstantExpr(LHSExpr)) {
+  LHSExpr->EvaluateAsInt(IntExprResult, *Context); // Evaluating value.
+  BoolExpr = RHSExpr;
+}
+else if (IsIntegerLiteralConstantExpr(RHSExpr)) {
+  RHSExpr->EvaluateAsInt(IntExprResult, *Context); // Evaluating value.
   BoolExpr = LHSExpr;
 }
-
-if (!IntLiteral)
+else
+{
   return TryResult();
+}
 
 const BinaryOperator *BitOp = dyn_cast(BoolExpr);
 if (BitOp && (BitOp->getOpcode() == BO_And ||
   BitOp->getOpcode() == BO_Or)) {
   const Expr *LHSExpr2 = BitOp->getLHS()->IgnoreParens();
   const Expr *RHSExpr2 = BitOp->getRHS()->IgnoreParens();
-
-  const IntegerLiteral *IntLiteral2 = dyn_cast(LHSExpr2);
-
-  if (!IntLiteral2)
-IntLiteral2 = dyn_cast(RHSExpr2);
-
-  if (!IntLiteral2)
+  
+  // If integer literal in expression identified then will save value.
+  Expr::EvalResult IntExprResult2; 
+
+  
+  if (IsIntegerLiteralConstantExpr(LHSExpr2))
+LHSExpr2->EvaluateAsInt(IntExprResult2, *Context); // Evaluating value.
+  else if (IsIntegerLiteralConstantExpr(RHSExpr2))
+RHSExpr2->EvaluateAsInt(IntExprResult2, *Context); // Evaluating value.
+  else
 return TryResult();
 
-  llvm::APInt L1 = IntLiteral->getValue();
-  llvm::APInt L2 = IntLiteral2->getValue();
+  // Getting the values as integer from the evaluation expression to use 
for comparision.
+  llvm::APInt L1 = IntExprResult.Val.getInt(); 
+  llvm::APInt L2 = IntExprResult2.Val.getInt();
+
   if ((BitOp->getOpcode() == BO_And && (L2 & L1) != L1) ||
   (BitOp->getOpcode() == BO_Or  && (L2 | L1) != L1)) {
 if (BuildOpts.Observer)
@@ -999,7 +1009,7 @@
 TryResult(B->getOpcode() != BO_EQ);
   }
 } else if (BoolExpr->isKnownToHaveBooleanValue()) {
-  llvm::APInt IntValue = IntLiteral->getValue();
+  llvm::APInt IntValue = IntExprResult.Val.getInt(); // Getting the value.
   if ((IntValue == 1) || (IntValue == 0)) {
 return TryResult();
   }


Index: clang/test/SemaCXX/warn-unreachable.cpp
===
--- clang/test/SemaCXX/warn-unreachable.cpp
+++ clang/test/SemaCXX/warn-unreachable.cpp
@@ -399,13 +399,13 @@
   // TODO: Extend warning to the following code:
   if (x < -1)
 calledFun();
-  if (x == -1)
-calledFun();
+  if (x == -1)   // expected-note {{silence}}
+calledFun(); // expected-warning {{will never be executed}}
 
-  if (x != -1)
+  if (x != -1)   // expected-note {{silence}}
 calledFun();
   else
-calledFun();
+calledFun(); // expected-warning {{will never be executed}}
   if (-1 > x)
 calledFun();
   else
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -964,33 +964,43 @@
 const Expr *LHSExpr = B->getLHS()->IgnoreParens();
 const Expr *RHSExpr = B->getRHS()->IgnoreParens();
 
-const IntegerLiteral *IntLiteral = dyn_cast(LHSExpr);
-const Expr *BoolExpr = RHSExpr;
+const Expr *BoolExpr = nullptr; // To store the expression.
+Expr::EvalResult IntExprResult; // If inte

[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-25 Thread Johannes Doerfert via Phabricator via cfe-commits
jdoerfert added a comment.

> I'm still not seeing the issue fully. My understanding of the situation 
> (which may be wrong) is that Clang lowers to LLVM IR and adds noundef 
> markings at call sites that this patch attempts to let the user then undo. 
> However, why can Clang's CodeGen not notice the special builtin and walk up 
> the call chain to mark all the wrapper functions to ensure everything is 
> marked appropriately? There might be a small perf loss (if there are wrappers 
> around wrappers around wrappers kind of situation), but this means we don't 
> have to expose this problem to users.

I think you are right, we could identify shuffles and go up the call chain in 
clang (codegen) if we wanted.

> I still think that a solution which doesn't require the user to make such 
> dangerous decisions on their own is a better design if we can accomplish it.

This is a valid opinion but I don't see how this matches what we do (or has 
been done) in the past. I mean, there are plenty of command line options and 
attributes that do exactly this, let the user "define", or better "refine", 
semantics.
The entire "initialize with 0" stuff comes to mind, making new things UB with 
-ffast-math and friends, overloadable, etc.

---

All that said, I'm generally more in favor of explicit annotations in the 
source than implicit compiler magic to implement a special case.
Others should chime in.


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

https://reviews.llvm.org/D130224

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


[PATCH] D130374: [Passes] add a tail-call-elim pass near the end of the opt pipeline

2022-07-25 Thread Sanjay Patel 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 rGbfb9b8e075ee: [Passes] add a tail-call-elim pass near the 
end of the opt pipeline (authored by spatel).
Herald added subscribers: cfe-commits, pmatos, asb, arphaman, aheejin, sbc100.
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D130374?vs=447156&id=447431#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130374

Files:
  clang/test/CodeGen/aarch64-ls64-inline-asm.c
  clang/test/CodeGen/aarch64-neon-vcmla.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.c
  clang/test/CodeGen/aarch64-sve-acle-__ARM_FEATURE_SVE_VECTOR_OPERATORS.cpp
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_abd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_abs.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_acle.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_aclt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_add.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adda.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_addv.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrh.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_adrw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_and.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_andv.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_asr.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_asrd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfdot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmlalt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bfmmla.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_bic.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brka.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkn.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkpa.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_brkpb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cadd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clasta-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clasta.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clastb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cls.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_clz.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmla.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpeq.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpge.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpgt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmple.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmplt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpne.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cmpuo.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnt-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cntb.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cntd.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cnth.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cntp.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cntw.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_compact.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create2-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create2.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create3-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create3.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create4-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_create4.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cvt-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cvt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_cvtnt.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_div.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_divr.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dot.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dup.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq-bfloat.c
  clang/test/CodeGen/aarch64-sve-intrinsics/acle_sve_dupq.c
  clang/test/CodeGen/aarch64-sve-intrinsics/ac

[PATCH] D129872: [clang][OpenMP] Fix runtime crash in the call to __kmp_alloc.

2022-07-25 Thread Jennifer Yu via Phabricator via cfe-commits
jyu2 added inline comments.



Comment at: clang/lib/Sema/SemaOpenMP.cpp:16379
+// UnsignedPointerDiffType avoid truncate.
+AllocatorHT = Context.getUnsignedPointerDiffType();
+  Allocator = PerformImplicitConversion(Allocator.get(), AllocatorHT,

ABataev wrote:
> jyu2 wrote:
> > ABataev wrote:
> > > jyu2 wrote:
> > > > ABataev wrote:
> > > > > jyu2 wrote:
> > > > > > ABataev wrote:
> > > > > > > It must be int type, no?
> > > > > > unsigned int?
> > > > > Check the standard, IIRC it says just int.
> > > > I see that is enum type.
> > > > 
> > > > Runtime library definitions: The enum types for omp_allocator_handle_t:
> > > > 
> > > > The type omp_allocator_handle_t, which must be an 
> > > > implementation-defined (for C++
> > > > possibly scoped) enum type with at least the omp_null_allocator 
> > > > enumerator with the
> > > > value zero and an enumerator for each predefined memory allocator in 
> > > > Table 2.10;
> > > IIRC, in C enums are always int-based.
> > That is right.  But not for C++.
> For C++ need to get the base int type.
For C++ enum type is unsigned int:  
since following is defined inside the omp_allocator_handle_t.
 KMP_ALLOCATOR_MAX_HANDLE = (18446744073709551615UL)  

But for C it is int.  

```
-EnumDecl 0x11b31d88  line:18:14 omp_allocator_handle_t
| |-EnumConstantDecl 0x11b31e90  col:3 referenced 
omp_null_allocator 'omp_allocator_handle_t'
| | `-ImplicitCastExpr 0x11b4b770  'unsigned long' 
| |   `-ConstantExpr 0x11b31e70  'int'
| | |-value: Int 0
```




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129872

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


[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-25 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added a comment.

In D130224#3668243 , @aaron.ballman 
wrote:

> I'm still not seeing the issue fully. My understanding of the situation 
> (which may be wrong) is that Clang lowers to LLVM IR and adds `noundef` 
> markings at call sites that this patch attempts to let the user then undo. 
> However, why can Clang's CodeGen not notice the special builtin and walk up 
> the call chain to mark all the wrapper functions to ensure everything is 
> marked appropriately? There might be a small perf loss (if there are wrappers 
> around wrappers around wrappers kind of situation), but this means we don't 
> have to expose this problem to users.

This requires maintaining logic in clang to specially recognize these N wrapper 
functions, and there would be no indication in the source that this magic is 
occurring. It's less maintainable because it requires tight, magic coupling 
between these functions in the source and special handling in clang to be 
maintained if anything were to change


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

https://reviews.llvm.org/D130224

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


[PATCH] D130493: Disable stack-sizes section by default for PS4.

2022-07-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:5883
   if (Args.hasFlag(options::OPT_fstack_size_section,
-   options::OPT_fno_stack_size_section, RawTriple.isPS4()))
+   options::OPT_fno_stack_size_section, false))
 CmdArgs.push_back("-fstack-size-section");

Switch to `Args.addOptInFlag`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130493

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


[PATCH] D130301: [Clang] Fix how we set the NumPositiveBits on an E numDecl to cover the case of single enumerator with value zero or an empty enum

2022-07-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: compiler-rt/test/ubsan/TestCases/Misc/enum.cpp:27
+  return ((int)e1 != -1) & ((int)e2 != -1) &
+ // CHECK: error: load of value , which is not a valid value 
for type 'enum EBool'
+ ((int)e3 != -1) & ((int)e4 == 1) &

aaron.ballman wrote:
> erichkeane wrote:
> > What does THIS come from?  What value is unknown?  Shouldn't the -1 be fine?
> +1, I'm surprised by the `` there, but also... neither `e1` nor `e2` 
> are of type `enum EBool`!
So it looks like clang knows that the only valid values for a bool enum is 0 or 
1 and it will mask the value accordingly see godbolt for example using `argc` : 
https://godbolt.org/z/ceb9hPno9

So that would explain why the original test used a `unsigned char*` in order to 
prompt the diagnostic. 

Looking into the ubsan diagnostic it looks like it treats bool as an unknown 
value, separate from integer and float. It is not clear to me why it does this 
but fixing that feels outside the scope of this change since this was part of 
the original test.


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

https://reviews.llvm.org/D130301

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


[PATCH] D128619: [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)

2022-07-25 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added a comment.

@erichkeane @cor3ntin

If you have time for review right now, I think it's reasonably ready and I 
would still like to merge it this week so it can land in Clang15.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128619

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


[PATCH] D128619: [Clang] Implement P0848 (Conditionally Trivial Special Member Functions)

2022-07-25 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 447425.
royjacobson marked an inline comment as done.
royjacobson added a comment.

Rebase on main and slightly update docs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128619

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/DeclCXX.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/AST/conditionally-trivial-smfs.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/SemaCXX/constrained-special-member-functions.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -927,7 +927,7 @@
   

 https://wg21.link/p0848r3";>P0848R3
-No
+Clang 15
   
   
 https://wg21.link/p1616r1";>P1616R1
Index: clang/test/SemaCXX/constrained-special-member-functions.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/constrained-special-member-functions.cpp
@@ -0,0 +1,210 @@
+// RUN: %clang_cc1 -verify -std=c++20 %s
+
+template 
+concept C0 = (N == 0);
+template 
+concept C1 = (N == 1);
+template 
+concept C2 = (N == 2);
+
+// Checks are indexed by:
+// Definition:
+//  1. Explicitly defaulted definition
+//  2. Deleted definition
+//  3. User provided definition
+// We have a less constrained user provided method that should not disable
+// the (copyable) triviality of the type.
+
+// Note that because Clang does not implement DRs 1496 and 1734, we say some
+// classes are trivial when the SMFs are deleted.
+
+template 
+struct DefaultConstructorChecker {
+DefaultConstructorChecker() requires C0 = default;
+DefaultConstructorChecker() requires C1 = delete;
+DefaultConstructorChecker() requires C2;
+DefaultConstructorChecker();
+};
+static_assert(__is_trivially_copyable(DefaultConstructorChecker<0>));
+static_assert(__is_trivially_copyable(DefaultConstructorChecker<1>));
+static_assert(__is_trivially_copyable(DefaultConstructorChecker<2>));
+static_assert(__is_trivially_copyable(DefaultConstructorChecker<3>));
+static_assert(__is_trivial(DefaultConstructorChecker<0>));
+// FIXME: DR1496
+static_assert(__is_trivial(DefaultConstructorChecker<1>));
+static_assert(!__is_trivial(DefaultConstructorChecker<2>));
+static_assert(!__is_trivial(DefaultConstructorChecker<3>));
+
+template 
+struct CopyConstructorChecker {
+CopyConstructorChecker(const CopyConstructorChecker&) requires C0 = default;
+CopyConstructorChecker(const CopyConstructorChecker&) requires C1 = delete;
+CopyConstructorChecker(const CopyConstructorChecker&) requires C2;
+CopyConstructorChecker(const CopyConstructorChecker&);
+};
+
+static_assert(__is_trivially_copyable(CopyConstructorChecker<0>));
+// FIXME: DR1734
+static_assert(__is_trivially_copyable(CopyConstructorChecker<1>));
+static_assert(!__is_trivially_copyable(CopyConstructorChecker<2>));
+static_assert(!__is_trivially_copyable(CopyConstructorChecker<3>));
+static_assert(!__is_trivial(CopyConstructorChecker<0>));
+static_assert(!__is_trivial(CopyConstructorChecker<1>));
+static_assert(!__is_trivial(CopyConstructorChecker<2>));
+static_assert(!__is_trivial(CopyConstructorChecker<3>));
+
+template 
+struct MoveConstructorChecker {
+MoveConstructorChecker(MoveConstructorChecker&&) requires C0 = default;
+MoveConstructorChecker(MoveConstructorChecker&&) requires C1 = delete;
+MoveConstructorChecker(MoveConstructorChecker&&) requires C2;
+MoveConstructorChecker(MoveConstructorChecker&&);
+};
+
+static_assert(__is_trivially_copyable(MoveConstructorChecker<0>));
+// FIXME: DR1734
+static_assert(__is_trivially_copyable(MoveConstructorChecker<1>));
+static_assert(!__is_trivially_copyable(MoveConstructorChecker<2>));
+static_assert(!__is_trivially_copyable(MoveConstructorChecker<3>));
+static_assert(!__is_trivial(MoveConstructorChecker<0>));
+static_assert(!__is_trivial(MoveConstructorChecker<1>));
+static_assert(!__is_trivial(MoveConstructorChecker<2>));
+static_assert(!__is_trivial(MoveConstructorChecker<3>));
+
+template 
+struct MoveAssignmentChecker {
+MoveAssignmentChecker& operator=(MoveAssignmentChecker&&) requires C0 = default;
+MoveAssignmentChecker& operator=(MoveAssignmentChecker&&) requires C1 = delete;
+MoveAssignmentChecker& operator=(MoveAssignmentChecker&&) requires C2;
+MoveAssignmentChecker& operator=(MoveAssignmentChecker&&);
+};
+
+static_assert(__is_trivially_copyable(MoveAssignmentChecker<0>));
+// FIXME: DR1734.
+static_assert(__is_trivially_copyable(MoveAssignmentChecker<1>));
+static_assert(!__is_trivially_copyable(MoveAssignmentChecker<2>));
+static_assert(!__is_trivially_copyable(MoveAssignmentChecker<3>));
+static_assert(__is_trivia

[PATCH] D130224: [Clang][Attribute] Introduce maybe_undef attribute for function arguments which accepts undef values

2022-07-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D130224#3668267 , @arsenm wrote:

> In D130224#3668243 , @aaron.ballman 
> wrote:
>
>> In D130224#3668240 , @arsenm wrote:
>>
>>> In D130224#3668225 , 
>>> @aaron.ballman wrote:
>>>
 It sounds like there's an extremely specific use case in mind for this 
 attribute; is there a reason why this needs to be the user's problem 
 instead of something the compiler can infer or handle on the backend?
>>>
>>> The intended user is a handful of header wrapper functions around 
>>> intrinsics, not general users
>>
>> Great, then it sounds like we don't need to expose this as an attribute 
>> because we know which intrinsics need special behavior, so we can handle 
>> them specially at codegen time or within the backend?
>
> The problem is the wrappers. We originally talked about specifically handling 
> the builtins, but that falls apart given the real users come from wrapper 
> functions which look like ordinary code

I'm still not seeing the issue fully. My understanding of the situation (which 
may be wrong) is that Clang lowers to LLVM IR and adds `noundef` markings at 
call sites that this patch attempts to let the user then undo. However, why can 
Clang's CodeGen not notice the special builtin and walk up the call chain to 
mark all the wrapper functions to ensure everything is marked appropriately? 
There might be a small perf loss (if there are wrappers around wrappers around 
wrappers kind of situation), but this means we don't have to expose this 
problem to users.

In D130224#3672338 , @nhaehnle wrote:

> In D130224#3668225 , @aaron.ballman 
> wrote:
>
>> I'm in C standards meetings this week and don't have a lot of ability to 
>> thoroughly review this yet, but the most immediate concern which springs to 
>> mind for me is that this is exposing LLVM implementation details to users. 
>> Users should not have to think about things in terms of LLVM IR markings 
>> like poison and undef, and I worry that this is an expert-only feature that 
>> will be easy to misuse and introduce security issues.
>
> Here's how I would tentatively describe the attribute in terms that mesh 
> better with how I understand C and C++:
>
>> As an exception to the rule that loading from an unitialized variable is 
>> undefined behavior, if the loaded value is used immediately as an 
>> `__attribute__((maybe_undef))` argument in a function call, the loaded value 
>> is implementation-defined. It may vary between multiple runs of the program, 
>> and it may vary between multiple uses of the uninitialized variable.
>
> This requires no thinking about LLVM IR and undef/poison.

Thanks, this helps somewhat (though I would argue that the loaded value is 
*not* implementation-defined but is instead unspecified, because that matches 
the semantics you mention about not needing to pick the same loaded value every 
time). However, this design is basically asking the user to decide when 
something should or should not be undefined behavior, which means this 
attribute will almost certainly be abused under the guise of "this makes my 
program safer because it removes UB". I still think that a solution which 
doesn't require the user to make such dangerous decisions on their own is a 
better design if we can accomplish it.


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

https://reviews.llvm.org/D130224

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


[PATCH] D130420: [CodeGen] Consider MangleCtx when move lazy emission States

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

I think this seems reasonable.  I suspect we'll need to do more plumbing here 
if we need to support snapshotting / resetting to a snapshot, but this probably 
isn't the only place, and the moves we're doing aren't set up for that either.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130420

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


[PATCH] D130423: [clang][dataflow] Rename iterators from IT to It

2022-07-25 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 rGc0c9d717dfd2: [clang][dataflow] Rename iterators from IT to 
It (authored by gribozavr).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130423

Files:
  clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp

Index: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
===
--- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -47,9 +47,9 @@
   : CFCtx(CFCtx), BlockToState(BlockToState) {}
 
   const Environment *getEnvironment(const Stmt &S) const override {
-auto BlockIT = CFCtx.getStmtToBlock().find(&ignoreCFGOmittedNodes(S));
-assert(BlockIT != CFCtx.getStmtToBlock().end());
-const auto &State = BlockToState[BlockIT->getSecond()->getBlockID()];
+auto BlockIt = CFCtx.getStmtToBlock().find(&ignoreCFGOmittedNodes(S));
+assert(BlockIt != CFCtx.getStmtToBlock().end());
+const auto &State = BlockToState[BlockIt->getSecond()->getBlockID()];
 assert(State);
 return &State.value().Env;
   }
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -564,11 +564,11 @@
 Env.setValue(Loc, *Val);
 
 if (Type->isStructureOrClassType()) {
-  for (auto IT : llvm::zip(Type->getAsRecordDecl()->fields(), S->inits())) {
-const FieldDecl *Field = std::get<0>(IT);
+  for (auto It : llvm::zip(Type->getAsRecordDecl()->fields(), S->inits())) {
+const FieldDecl *Field = std::get<0>(It);
 assert(Field != nullptr);
 
-const Expr *Init = std::get<1>(IT);
+const Expr *Init = std::get<1>(It);
 assert(Init != nullptr);
 
 if (Value *InitVal = Env.getValue(*Init, SkipPast::None))
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -352,16 +352,16 @@
 }
   }
 
-  auto IT = MemberLocToStruct.find(&Loc);
-  if (IT != MemberLocToStruct.end()) {
+  auto It = MemberLocToStruct.find(&Loc);
+  if (It != MemberLocToStruct.end()) {
 // `Loc` is the location of a struct member so we need to also update the
 // value of the member in the corresponding `StructValue`.
 
-assert(IT->second.first != nullptr);
-StructValue &StructVal = *IT->second.first;
+assert(It->second.first != nullptr);
+StructValue &StructVal = *It->second.first;
 
-assert(IT->second.second != nullptr);
-const ValueDecl &Member = *IT->second.second;
+assert(It->second.second != nullptr);
+const ValueDecl &Member = *It->second.second;
 
 StructVal.setChild(Member, Val);
   }
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -199,18 +199,18 @@
   if (!Res.second)
 return;
 
-  auto ConstraintsIT = FlowConditionConstraints.find(&Token);
-  if (ConstraintsIT == FlowConditionConstraints.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(&getOrCreateIff(Token, *ConstraintsIT->second));
+Constraints.insert(&getOrCreateIff(Token, *ConstraintsIt->second));
   }
 
-  auto DepsIT = FlowConditionDeps.find(&Token);
-  if (DepsIT != FlowConditionDeps.end()) {
-for (AtomicBoolValue *DepToken : DepsIT->second) {
+  auto DepsIt = FlowConditionDeps.find(&Token);
+  if (DepsIt != FlowConditionDeps.end()) {
+for (AtomicBoolValue *DepToken : DepsIt->second) {
   addTransitiveFlowConditionConstraints(*DepToken, Constraints,
 VisitedTokens);
 }
@@ -220,10 +220,10 @@
 BoolValue &DataflowAnalysisContext::substituteBoolValue(
 BoolValue &Val,
 llvm::DenseMap &SubstitutionsCache) {
-  auto IT = SubstitutionsCache.find(&Val);
-  if (IT != SubstitutionsCache.end()) {
+  auto It = SubstitutionsCache.find(&Val);
+  if (It != SubstitutionsCache.end()) {
 // Return memoi

  1   2   3   >