[PATCH] D127363: [Lex] Fix for char32_t literal truncation on 16 bit architectures

2022-06-09 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

This sounds correct to me, though I don't feel like an expert here.
Upstream in non-experimental IntWidth == Char32Width except on AVR, so it won't 
actually break anything.

Regarding testing, it seems like this should change the diagnostic emitted for 
`long x = 'abc'` from "Character constant too long for its type" to 
"Multi-character character constant" when the target is AVR?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127363

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


[PATCH] D127217: [include-cleaner] Fix build error in unit test

2022-06-09 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

Can you please merge it? I don't have the rights.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127217

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


[PATCH] D127217: [include-cleaner] Fix build error in unit test

2022-06-09 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd3520171844a: [include-cleaner] Fix build error in unit test 
(authored by ckandeler, committed by nridge).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127217

Files:
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt


Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -23,5 +23,6 @@
   PRIVATE
   clangIncludeCleaner
   clangTesting
+  LLVMTestingSupport
   )
 


Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -23,5 +23,6 @@
   PRIVATE
   clangIncludeCleaner
   clangTesting
+  LLVMTestingSupport
   )
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] d352017 - [include-cleaner] Fix build error in unit test

2022-06-09 Thread Nathan Ridge via cfe-commits

Author: Christian Kandeler
Date: 2022-06-09T03:38:13-04:00
New Revision: d3520171844a80ff37ede19a14d45a94012d1a15

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

LOG: [include-cleaner] Fix build error in unit test

Reviewed By: nridge

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt 
b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
index 0cbbefcdd611e..8786f6d38e35f 100644
--- a/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ b/clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -23,5 +23,6 @@ target_link_libraries(ClangIncludeCleanerTests
   PRIVATE
   clangIncludeCleaner
   clangTesting
+  LLVMTestingSupport
   )
 



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


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-09 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: llvm/cmake/modules/AddLLVM.cmake:890
+configure_file(
+  ${LLVM_MAIN_SRC_DIR}/cmake/driver-template.cpp.in
+  ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp)

chapuni wrote:
> Do you have a plan to export the template?
Unsurprisingly, this breaks standalone builds. However, I think that the 
multicall tool is fundamentally incompatible with standalone builds, in the 
sense that all tools included in it must be part of the initial build 
configuration -- you can't first build the LLVM multicall tool and then add 
clang to it afterwards.

So I think we just need to guard this code by LLVM_TOOL_LLVM_DRIVER_BUILD, so 
we don't try to read a non-exported driver-template.cpp.in file even if we're 
not actually building the multicall tool.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

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


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-09 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: llvm/cmake/modules/AddLLVM.cmake:890
+configure_file(
+  ${LLVM_MAIN_SRC_DIR}/cmake/driver-template.cpp.in
+  ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp)

nikic wrote:
> chapuni wrote:
> > Do you have a plan to export the template?
> Unsurprisingly, this breaks standalone builds. However, I think that the 
> multicall tool is fundamentally incompatible with standalone builds, in the 
> sense that all tools included in it must be part of the initial build 
> configuration -- you can't first build the LLVM multicall tool and then add 
> clang to it afterwards.
> 
> So I think we just need to guard this code by LLVM_TOOL_LLVM_DRIVER_BUILD, so 
> we don't try to read a non-exported driver-template.cpp.in file even if we're 
> not actually building the multicall tool.
Ah, I misunderstood how this works. Generating the driver file is necessary for 
//normal// usage, not for the mutlicall tool, so it's not possible to just 
guard this code. We do need to export driver-template.cpp.in as part of the 
LLVM cmake installation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

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


[PATCH] D125349: [Sema] Fix crash for C11 atomic in gnu++ mode

2022-06-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 435448.
jansvoboda11 added a comment.

Handle volatile _Atomic as well


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125349

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
  clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp

Index: clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/atomic-builtin-compound-assignment-overload.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=gnu++98 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+_Atomic unsigned an_atomic_uint;
+
+enum { an_enum_value = 1 };
+
+void enum1() { an_atomic_uint += an_enum_value; }
+
+void enum2() { an_atomic_uint |= an_enum_value; }
+
+volatile _Atomic unsigned an_volatile_atomic_uint;
+
+void enum3() { an_volatile_atomic_uint += an_enum_value; }
+
+void enum4() { an_volatile_atomic_uint |= an_enum_value; }
Index: clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/atomic-builtin-compound-assignment-overload.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -std=gnu++11 -emit-llvm -triple=x86_64-linux-gnu -o - %s | FileCheck %s
+
+_Atomic unsigned an_atomic_uint;
+
+enum { an_enum_value = 1 };
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum1v()
+void enum1() {
+  an_atomic_uint += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum2v()
+void enum2() {
+  an_atomic_uint |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum3RU7_Atomicj({{.*}})
+void enum3(_Atomic unsigned &an_atomic_uint_param) {
+  an_atomic_uint_param += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum4RU7_Atomicj({{.*}})
+void enum4(_Atomic unsigned &an_atomic_uint_param) {
+  an_atomic_uint_param |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
+
+volatile _Atomic unsigned an_volatile_atomic_uint;
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum5v()
+void enum5() {
+  an_volatile_atomic_uint += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum6v()
+void enum6() {
+  an_volatile_atomic_uint |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum7RVU7_Atomicj({{.*}})
+void enum7(volatile _Atomic unsigned &an_volatile_atomic_uint_param) {
+  an_volatile_atomic_uint_param += an_enum_value;
+  // CHECK: atomicrmw add ptr
+}
+
+// CHECK-LABEL: define {{.*}}void @_Z5enum8RVU7_Atomicj({{.*}})
+void enum8(volatile _Atomic unsigned &an_volatile_atomic_uint_param) {
+  an_volatile_atomic_uint_param |= an_enum_value;
+  // CHECK: atomicrmw or ptr
+}
Index: clang/lib/Sema/SemaOverload.cpp
===
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -8202,6 +8202,7 @@
   Sema &S;
   ArrayRef Args;
   Qualifiers VisibleTypeConversionsQuals;
+  bool VisibleTypeIsAtomic;
   bool HasArithmeticOrEnumeralCandidateType;
   SmallVectorImpl &CandidateTypes;
   OverloadCandidateSet &CandidateSet;
@@ -8326,11 +8327,13 @@
   BuiltinOperatorOverloadBuilder(
 Sema &S, ArrayRef Args,
 Qualifiers VisibleTypeConversionsQuals,
+bool VisibleTypeIsAtomic,
 bool HasArithmeticOrEnumeralCandidateType,
 SmallVectorImpl &CandidateTypes,
 OverloadCandidateSet &CandidateSet)
 : S(S), Args(Args),
   VisibleTypeConversionsQuals(VisibleTypeConversionsQuals),
+  VisibleTypeIsAtomic(VisibleTypeIsAtomic),
   HasArithmeticOrEnumeralCandidateType(
 HasArithmeticOrEnumeralCandidateType),
   CandidateTypes(CandidateTypes),
@@ -8951,12 +8954,27 @@
 S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet,
   /*IsAssignmentOperator=*/isEqualOp);
 
+if (VisibleTypeIsAtomic) {
+  ParamTypes[0] = S.Context.getAtomicType(LeftBaseTy);
+  ParamTypes[0] = S.Context.getLValueReferenceType(ParamTypes[0]);
+  S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet,
+/*IsAssignmentOperator=*/isEqualOp);
+}
+
 // Add this built-in operator as a candidate (VQ is 'volatile').
 if (VisibleTypeConversionsQuals.hasVolatile()) {
   ParamTypes[0] = S.Context.getVolatileType(LeftBaseTy);
   ParamTypes[0] = S.Context.getLValueReferenceType(ParamTypes[0]);
   S.AddBuiltinCandidate(ParamTypes, Args, CandidateSet,
 /*IsAssignmentOperator=*/isEqualOp);
+
+  if (VisibleTypeIsAtomic) {
+ParamTypes[0] = S.Context.getAtomicType(LeftBaseTy);
+ParamTypes[0] = S.Conte

[PATCH] D125349: [Sema] Fix crash for C11 atomic in gnu++ mode

2022-06-09 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 added a comment.

> It doesn't look like the patch handles `volatile _Atomic` correctly, though.

That should be fixed in the new revision.

> I know we do a lot of candidate prefiltering, and that that can be difficult 
> because of uesr-defined conversions.  How do those things interact with 
> qualifiers?

I don't know.

> Like, I notice the existing code is adding both `(T &, T)` and `(volatile T 
> &, T)` when the LHS is `volatile`; is there a reason that's necessary?

Looking at Git history, that was always the case. I don't see any particular 
reason we do that eagerly.

> Because we can't actually convert the LHS to remove those qualifiers, and 
> adding combinatoric candidates could get very expensive if we start doing it 
> for arbitrary extended qualifiers, which it feels like we ought to.  (You 
> could certainly have e.g. a `volatile _Atomic __myaddrspace` l-value.)  If 
> this is only necessary when the LHS has a user-defined conversion, then maybe 
> we could at least not do it in the normal case just because the RHS is an 
> overloaded type.

Yup, seems like we could be more lazy/minimal about that. I can look into that 
as a follow-up.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125349

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


[PATCH] D109977: LLVM Driver Multicall tool

2022-06-09 Thread Nikita Popov via Phabricator via cfe-commits
nikic added inline comments.



Comment at: llvm/cmake/modules/AddLLVM.cmake:890
+configure_file(
+  ${LLVM_MAIN_SRC_DIR}/cmake/driver-template.cpp.in
+  ${CMAKE_CURRENT_BINARY_DIR}/${name}-driver.cpp)

nikic wrote:
> nikic wrote:
> > chapuni wrote:
> > > Do you have a plan to export the template?
> > Unsurprisingly, this breaks standalone builds. However, I think that the 
> > multicall tool is fundamentally incompatible with standalone builds, in the 
> > sense that all tools included in it must be part of the initial build 
> > configuration -- you can't first build the LLVM multicall tool and then add 
> > clang to it afterwards.
> > 
> > So I think we just need to guard this code by LLVM_TOOL_LLVM_DRIVER_BUILD, 
> > so we don't try to read a non-exported driver-template.cpp.in file even if 
> > we're not actually building the multicall tool.
> Ah, I misunderstood how this works. Generating the driver file is necessary 
> for //normal// usage, not for the mutlicall tool, so it's not possible to 
> just guard this code. We do need to export driver-template.cpp.in as part of 
> the LLVM cmake installation.
I've put up https://reviews.llvm.org/D127384 to fix this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109977

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


[PATCH] D126461: [RISCV] Extract and store new vl of vleff iff destination isn't null

2022-06-09 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead updated this revision to Diff 435454.
pcwang-thead edited the summary of this revision.
pcwang-thead added a comment.

Add null pointer checking for vlsegff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126461

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics/vleff-optimized.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vleff.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlsegff-optimized.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlsegff.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlsegff_mask.c

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


[PATCH] D126308: cmake: use llvm dir variables for clang/utils/hmaptool

2022-06-09 Thread Nikita Popov via Phabricator via cfe-commits
nikic added a comment.

In D126308#3568696 , @mizvekov wrote:

> @nikic ping, can you confirm this current patch works for you?

Sorry, missed the update. Just tried this in a local build and it seems to work 
fine!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126308

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


[PATCH] D127357: [pseudo] wip/prototype: use LR0 instead of SLR1 table

2022-06-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks for experimenting this!

> the size of the LR table is much smaller (In this patch we go from 340kB => 
> 120kB, and the encoding isn't efficient)

This is interesting. I'd expect we now add more reduce actions into the 
LRTable, thus the table size should grow (I guess the saving is because we 
don't need to store different token kinds, instead just a single `eod` token)?

> we explore more dead-ends due to lack of lookahead, and parser runs slower
> with this patch, the LR0 table parses ~1/3 slower than the SLR1. (LR0 allows 
> code simplifications so we may win some of this back)

(I also did some hack experiment yesterday, got similar results)
1/3 performance downgrade seems a lot... It is ok for error-recovery, but for 
correct code, it is an expensive and unnecessary pay.

Since this is a large change, before moving forward, maybe we should consider 
some alternatives:

1. use a hybrid solution (this also depends on how many interesting states we 
have)
  - for interesting states (where it has the sequence-element rule like `stmt 
:= expression `), we build LR(0) for these states (like this patch);
  - for other non-interesting states, we keep building the SLR;
2. as we discussed yesterday, we find all available reduce actions during the 
error recovery by iterating all tokens. This is slower (but only on the 
error-recovery path), but I think there are ways to speed that up, e.g. using 
separate storage in the LRTable


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127357

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


[PATCH] D125862: [clang][driver] Add gcc-toolset/devtoolset 12 to prefixes

2022-06-09 Thread Bevin Hansson via Phabricator via cfe-commits
ebevhan added a comment.

Hi! This test is failing in some of our downstream builds.




Comment at: clang/unittests/Driver/ToolChainTest.cpp:647
+std::unique_ptr C(
+TheDriver.BuildCompilation({"--gcc-toolchain="}));
+ASSERT_TRUE(C);

There's a binary name missing here:

```
{"clang", "--gcc-toolchain="}
```

Driver strips the first argument, so the behavior of this test becomes 
dependent on GCC_INSTALL_PREFIX which can cause it to fail in some cases.



Comment at: clang/unittests/Driver/ToolChainTest.cpp:687
+std::unique_ptr C(
+TheDriver.BuildCompilation({"--gcc-toolchain="}));
+ASSERT_TRUE(C);

Here too.


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

https://reviews.llvm.org/D125862

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


[clang-tools-extra] 075449d - [pseudo] Fix a sign-compare warning in debug build, NFC.

2022-06-09 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-09T11:18:03+02:00
New Revision: 075449da80d37bcf3e40ee584753ae0d7ae5afa5

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

LOG: [pseudo] Fix a sign-compare warning in debug build, NFC.

Added: 


Modified: 
clang-tools-extra/pseudo/lib/grammar/LRTable.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/grammar/LRTable.cpp 
b/clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
index 16c4029eec08b..28e2bf5b136ac 100644
--- a/clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
+++ b/clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
@@ -91,7 +91,7 @@ LRTable::StateID LRTable::getGoToState(StateID State,
 }
 
 llvm::ArrayRef LRTable::find(StateID Src, SymbolID ID) const {
-  assert(Src + 1 < StateOffset.size());
+  assert(Src + 1u < StateOffset.size());
   std::pair Range =
   std::make_pair(StateOffset[Src], StateOffset[Src + 1]);
   auto SymbolRange = llvm::makeArrayRef(Symbols.data() + Range.first,



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


[PATCH] D125677: [pseudo] Remove the explicit Accept actions.

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



Comment at: clang-tools-extra/pseudo/lib/GLR.cpp:86
+  const ForestNode *Result = nullptr;
+  StateID AcceptState = Params.Table.getGoToState(StartState, StartSymbol);
+  glrReduce(PendingReduce, Params, [&](const GSS::Node *NewHead) {

sammccall wrote:
> hokein wrote:
> > sammccall wrote:
> > > this line introduces a requirement that the start symbol be a nonterminal 
> > > - if this is new, can we doc it?
> > this is not a new requirement, it is rather implicit previously (we use 
> > `G.findNonterminal` to pass the start-symbol argument of the `glrParse`). I 
> > added an assertion in the glrParse.
> > 
> > It would be nice to diagnose it in the bnf grammar parsing time (will add a 
> > followup patch).
> FWIW I think an assertion (and possibly a comment) is the right tradeoff 
> here, maintaining diagnostics for all this stuff seems like overkill
Fair enough. I underestimated the effort of doing this stuff (we need to adjust 
a few existing tests in GrammarTests as well).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125677

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


[clang-tools-extra] 7a05942 - [pseudo] Remove the explicit Accept actions.

2022-06-09 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-09T11:19:07+02:00
New Revision: 7a05942dd0c548cf4a0cf52d8d3f97b0a11a6509

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

LOG: [pseudo] Remove the explicit Accept actions.

As pointed out in the previous review section, having a dedicated accept
action doesn't seem to be necessary. This patch implements the the same behavior
without accept acction, which will save some code complexity.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
clang-tools-extra/pseudo/lib/GLR.cpp
clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
clang-tools-extra/pseudo/test/lr-build-basic.test
clang-tools-extra/pseudo/test/lr-build-conflicts.test
clang-tools-extra/pseudo/unittests/GLRTest.cpp
clang-tools-extra/pseudo/unittests/LRTableTest.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
index 3cff9aec8c5eb..52f29b7d1c0ba 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
@@ -19,8 +19,7 @@
 //  Typically, based on the category of the grammar symbol, the LRTable is
 //  broken into two logically separate tables:
 //- ACTION table with terminals as columns -- e.g. ACTION[S, a] specifies
-//  next action (shift/reduce/accept/error) on state S under a lookahead
-//  terminal a
+//  next action (shift/reduce) on state S under a lookahead terminal a
 //- GOTO table with nonterminals as columns -- e.g. GOTO[S, X] specifies
 //  the state which we transist to from the state S with the nonterminal X
 //
@@ -76,8 +75,12 @@ class LRTable {
   Shift,
   // Reduce by a rule: pop the state stack.
   Reduce,
-  // Signals that we have parsed the input successfully.
-  Accept,
+
+  // NOTE: there are no typical accept actions in the LRtable, accept
+  // actions are handled specifically in the parser -- if the parser
+  // reaches to a target state (which is goto(StartState, StartSymbol)) at
+  // the EOF token after a reduce, this indicates the input has been parsed
+  // as the StartSymbol successfully.
 
   // Nonterminal actions, corresponding to entry of GOTO table.
 
@@ -86,7 +89,6 @@ class LRTable {
   GoTo,
 };
 
-static Action accept(RuleID RID) { return Action(Accept, RID); }
 static Action goTo(StateID S) { return Action(GoTo, S); }
 static Action shift(StateID S) { return Action(Shift, S); }
 static Action reduce(RuleID RID) { return Action(Reduce, RID); }

diff  --git a/clang-tools-extra/pseudo/lib/GLR.cpp 
b/clang-tools-extra/pseudo/lib/GLR.cpp
index 1031e3dd2007c..0938d8846fe06 100644
--- a/clang-tools-extra/pseudo/lib/GLR.cpp
+++ b/clang-tools-extra/pseudo/lib/GLR.cpp
@@ -39,13 +39,14 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, const 
GSS::Node &N) {
 
 const ForestNode &glrParse(const TokenStream &Tokens, const ParseParams 
&Params,
SymbolID StartSymbol) {
+  assert(isNonterminal(StartSymbol) && "Start symbol must be a nonterminal");
   llvm::ArrayRef Terminals = Params.Forest.createTerminals(Tokens);
   auto &G = Params.G;
   (void)G;
   auto &GSS = Params.GSStack;
 
-  // Lists of active shift, reduce, accept actions.
-  std::vector PendingShift, PendingReduce, PendingAccept;
+  // Lists of active shift, reduce actions.
+  std::vector PendingShift, PendingReduce;
   auto AddSteps = [&](const GSS::Node *Head, SymbolID NextTok) {
 for (const auto &Action : Params.Table.getActions(Head->State, NextTok)) {
   switch (Action.kind()) {
@@ -55,20 +56,18 @@ const ForestNode &glrParse(const TokenStream &Tokens, const 
ParseParams &Params,
   case LRTable::Action::Reduce:
 PendingReduce.push_back({Head, Action});
 break;
-  case LRTable::Action::Accept:
-PendingAccept.push_back({Head, Action});
-break;
   default:
 llvm_unreachable("unexpected action kind!");
   }
 }
   };
+  StateID StartState = Params.Table.getStartState(StartSymbol);
   std::vector NewHeads = {
-  GSS.addNode(/*State=*/Params.Table.getStartState(StartSymbol),
+  GSS.addNode(/*State=*/StartState,
   /*ForestNode=*/nullptr, {})};
   auto MaybeGC = [&, Roots(std::vector{}), I(0u)]() mutable 
{
 assert(PendingShift.empty() && PendingReduce.empty() &&
-   PendingAccept.empty() && "Running GC at the wrong time!");
+   "Running GC at the wrong time!");
 
 if (++I != 20) // Run periodically to balance CPU and 

[PATCH] D125677: [pseudo] Remove the explicit Accept actions.

2022-06-09 Thread Haojian Wu 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 rG7a05942dd0c5: [pseudo] Remove the explicit Accept actions. 
(authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D125677?vs=435309&id=435459#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125677

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
  clang-tools-extra/pseudo/test/lr-build-basic.test
  clang-tools-extra/pseudo/test/lr-build-conflicts.test
  clang-tools-extra/pseudo/unittests/GLRTest.cpp
  clang-tools-extra/pseudo/unittests/LRTableTest.cpp

Index: clang-tools-extra/pseudo/unittests/LRTableTest.cpp
===
--- clang-tools-extra/pseudo/unittests/LRTableTest.cpp
+++ clang-tools-extra/pseudo/unittests/LRTableTest.cpp
@@ -33,7 +33,7 @@
   std::vector Entries = {
   {/* State */ 0, tokenSymbol(tok::semi), Action::shift(0)},
   {/* State */ 0, tokenSymbol(tok::semi), Action::reduce(0)},
-  {/* State */ 1, tokenSymbol(tok::eof), Action::accept(2)},
+  {/* State */ 1, tokenSymbol(tok::eof), Action::reduce(2)},
   {/* State */ 2, tokenSymbol(tok::semi), Action::reduce(1)}};
   GrammarTable GT;
   LRTable T = LRTable::buildForTests(GT, Entries);
@@ -41,7 +41,7 @@
   EXPECT_THAT(T.find(0, tokenSymbol(tok::semi)),
   UnorderedElementsAre(Action::shift(0), Action::reduce(0)));
   EXPECT_THAT(T.find(1, tokenSymbol(tok::eof)),
-  UnorderedElementsAre(Action::accept(2)));
+  UnorderedElementsAre(Action::reduce(2)));
   EXPECT_THAT(T.find(1, tokenSymbol(tok::semi)), IsEmpty());
   EXPECT_THAT(T.find(2, tokenSymbol(tok::semi)),
   UnorderedElementsAre(Action::reduce(1)));
Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -393,6 +393,29 @@
 "[  0, end) └─IDENTIFIER := tok[0]\n");
 }
 
+TEST_F(GLRTest, NoExplicitAccept) {
+  build(R"bnf(
+_ := test
+
+test := IDENTIFIER test
+test := IDENTIFIER
+  )bnf");
+  clang::LangOptions LOptions;
+  // Given the following input, and the grammar above, we perform two reductions
+  // of the nonterminal `test` when the next token is `eof`, verify that the
+  // parser stops at the right state.
+  const TokenStream &Tokens = cook(lex("id id", LOptions), LOptions);
+  auto LRTable = LRTable::buildSLR(*G);
+
+  const ForestNode &Parsed =
+  glrParse(Tokens, {*G, LRTable, Arena, GSStack}, id("test"));
+  EXPECT_EQ(Parsed.dumpRecursive(*G),
+"[  0, end) test := IDENTIFIER test\n"
+"[  0,   1) ├─IDENTIFIER := tok[0]\n"
+"[  1, end) └─test := IDENTIFIER\n"
+"[  1, end)   └─IDENTIFIER := tok[1]\n");
+}
+
 TEST(GSSTest, GC) {
   //  ┌-A-┬-AB
   //  ├-B-┘
Index: clang-tools-extra/pseudo/test/lr-build-conflicts.test
===
--- clang-tools-extra/pseudo/test/lr-build-conflicts.test
+++ clang-tools-extra/pseudo/test/lr-build-conflicts.test
@@ -33,7 +33,6 @@
 # TABLE-NEXT: 'IDENTIFIER': shift state 2
 # TABLE-NEXT: 'expr': go to state 1
 # TABLE-NEXT: State 1
-# TABLE-NEXT: 'EOF': accept
 # TABLE-NEXT: '-': shift state 3
 # TABLE-NEXT: State 2
 # TABLE-NEXT: 'EOF': reduce by rule 1 'expr := IDENTIFIER'
Index: clang-tools-extra/pseudo/test/lr-build-basic.test
===
--- clang-tools-extra/pseudo/test/lr-build-basic.test
+++ clang-tools-extra/pseudo/test/lr-build-basic.test
@@ -22,7 +22,6 @@
 # TABLE-NEXT: 'expr': go to state 1
 # TABLE-NEXT: 'id': go to state 2
 # TABLE-NEXT: State 1
-# TABLE-NEXT: 'EOF': accept
 # TABLE-NEXT: State 2
 # TABLE-NEXT: 'EOF': reduce by rule 1 'expr := id'
 # TABLE-NEXT: State 3
Index: clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
+++ clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
@@ -117,11 +117,11 @@
   auto FollowSets = followSets(G);
   for (StateID SID = 0; SID < Graph.states().size(); ++SID) {
 for (const Item &I : Graph.states()[SID].Items) {
-  // If we've just parsed the start symbol, we can accept the input.
-  if (G.lookupRule(I.rule()).Target == G.underscore() && !I.hasNext()) {
-Build.insert({SID, tokenSymbol(tok::eof), Action::accept(I.rule())});
+  // If we've just parsed the start symbol, this means we succes

[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-09 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 435460.
junaire added a comment.

OK, then we'd better to roll the condition back.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

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


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,7 +134,14 @@
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+
+  std::unique_ptr OldBuilder = std::move(Builder);
+
   Initialize(*Ctx);
+
+  if (OldBuilder)
+OldBuilder->moveLazyEmissionStates(Builder.get());
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,31 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  /// Move some lazily-emitted states to the NewBuilder. This is especially
+  /// essential for the incremental parsing environment like Clang Interpreter,
+  /// because we'll lose all important information after each repl.
+  void moveLazyEmissionStates(CodeGenModule *NewBuilder) {
+assert(DeferredDeclsToEmit.empty() &&
+   "Should have emitted all decls deferred to emit.");
+assert(NewBuilder->DeferredDecls.empty() &&
+   "Newly created module should not have deferred decls");
+NewBuilder->DeferredDecls = std::move(DeferredDecls);
+
+assert(NewBuilder->DeferredVTables.empty() &&
+   "Newly created module should not have deferred vtables");
+NewBuilder->DeferredVTables = std::move(DeferredVTables);
+
+assert(NewBuilder->MangledDeclNames.empty() &&
+   "Newly created module should not have mangled decl names");
+assert(NewBuilder->Manglings.empty() &&
+   "Newly created module should not have manglings");
+NewBuilder->Manglings = std::move(Manglings);
+
+assert(WeakRefReferences.empty() &&
+   "Not all WeakRefRefs have been applied");
+NewBuilder->TBAA = std::move(TBAA);
+  }
+
 private:
   llvm::Constant *GetOrCreateLLVMFunction(
   StringRef MangledName, llvm::Type *Ty, GlobalDecl D, bool ForVTable,


Index: clang/test/Interpreter/execute.cpp
===
--- clang/test/Interpreter/execute.cpp
+++ clang/test/Interpreter/execute.cpp
@@ -13,4 +13,8 @@
 
 auto r2 = printf("S[f=%f, m=0x%llx]\n", s.f, reinterpret_cast(s.m));
 // CHECK-NEXT: S[f=1.00, m=0x0]
+
+inline int foo() { return 42; }
+int r3 = foo();
+
 quit
Index: clang/lib/CodeGen/ModuleBuilder.cpp
===
--- clang/lib/CodeGen/ModuleBuilder.cpp
+++ clang/lib/CodeGen/ModuleBuilder.cpp
@@ -134,7 +134,14 @@
   llvm::LLVMContext &C) {
   assert(!M && "Replacing existing Module?");
   M.reset(new llvm::Module(ExpandModuleName(ModuleName, CodeGenOpts), C));
+
+  std::unique_ptr OldBuilder = std::move(Builder);
+
   Initialize(*Ctx);
+
+  if (OldBuilder)
+OldBuilder->moveLazyEmissionStates(Builder.get());
+
   return M.get();
 }
 
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -1477,6 +1477,31 @@
   void printPostfixForExternalizedDecl(llvm::raw_ostream &OS,
const Decl *D) const;
 
+  /// Move some lazily-emitted states to the NewBuilder. This is especially
+  /// essential for the incremental parsing environment like Clang Interpreter,
+  /// because we'll lose all important information after each repl.
+  void moveLazyEmissionStates(CodeGenModule *NewBuilder) {
+assert(DeferredDeclsToEmit.empty() &&
+   "Should have emitted all decls deferred to emit.");
+assert(NewBuilder->DeferredDecls.empty() &&
+   "Newly created module should not have deferred decls");
+NewBuilder->DeferredDecls = std::move(DeferredDecls);
+
+assert(NewBuilder->DeferredVTables.empty() &&
+   "Newly created module should not have d

[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable

2022-06-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 435461.
ChuanqiXu added a comment.

Handle function local thread locals.


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

https://reviews.llvm.org/D125291

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-instantiated.cpp
  clang/test/CodeGenCXX/pr18635.cpp
  clang/test/CodeGenCXX/threadlocal_address.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/test/Transforms/PreISelIntrinsicLowering/threadlocal_address.ll

Index: llvm/test/Transforms/PreISelIntrinsicLowering/threadlocal_address.ll
===
--- /dev/null
+++ llvm/test/Transforms/PreISelIntrinsicLowering/threadlocal_address.ll
@@ -0,0 +1,25 @@
+; RUN: opt -pre-isel-intrinsic-lowering -opaque-pointers -S -o - < %s | FileCheck %s
+
+@i = thread_local global i32 0, align 4
+
+define dso_local noundef i32 @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr @i, align 4
+; CHECK-NEXT:[[INC:%.*]] = add nsw i32 [[TMP0]], 1
+; CHECK-NEXT:store i32 [[INC]], ptr @i, align 4
+; CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr @i, align 4
+; CHECK-NEXT:ret i32 [[TMP1]]
+;
+; CHECK-NOT: call{{.*}}@llvm.threadlocal.address(
+entry:
+  %0 = call ptr @llvm.threadlocal.address(ptr @i)
+  %1 = load i32, ptr %0, align 4
+  %inc = add nsw i32 %1, 1
+  store i32 %inc, ptr %0, align 4
+  %2 = call ptr @llvm.threadlocal.address(ptr @i)
+  %3 = load i32, ptr %2, align 4
+  ret i32 %3
+}
+
+declare ptr @llvm.threadlocal.address(ptr) nounwind readnone willreturn
Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -499,6 +499,13 @@
   return createCallHelper(TheFn, Ops, this);
 }
 
+CallInst *IRBuilderBase::CreateThreadLocalAddress(Value *Ptr) {
+  assert(isa(Ptr) && cast(Ptr)->isThreadLocal() &&
+ "threadlocal_address only applies to thread local variables.");
+  return CreateIntrinsic(llvm::Intrinsic::threadlocal_address, llvm::None,
+ {Ptr});
+}
+
 CallInst *
 IRBuilderBase::CreateAssumption(Value *Cond,
 ArrayRef OpBundles) {
Index: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
===
--- llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 //
-// This pass implements IR lowering for the llvm.load.relative and llvm.objc.*
-// intrinsics.
+// This pass implements IR lowering for the llvm.threadlocal_address,
+// llvm.load.relative and llvm.objc.* intrinsics.
 //
 //===--===//
 
@@ -128,6 +128,19 @@
   return true;
 }
 
+static bool lowerThreadLocalIntrinsics(Function &F) {
+  if (F.use_empty())
+return false;
+
+  for (Use &U : llvm::make_early_inc_range(F.uses())) {
+auto *CB = cast(U.getUser());
+CB->replaceAllUsesWith(CB->getOperand(0));
+CB->eraseFromParent();
+  }
+
+  return true;
+}
+
 static bool lowerIntrinsics(Module &M) {
   bool Changed = false;
   for (Function &F : M) {
@@ -213,6 +226,9 @@
 case Intrinsic::objc_sync_exit:
   Changed |= lowerObjCCall(F, "objc_sync_exit");
   break;
+case Intrinsic::threadlocal_address:
+  Changed |= lowerThreadLocalIntrinsics(F);
+  break;
 }
   }
   return Changed;
Index: llvm/include/llvm/IR/Intrinsics.td
===
--- llvm/include/llvm/IR/Intrinsics.td
+++ llvm/include/llvm/IR/Intrinsics.td
@@ -1390,6 +1390,9 @@
 def int_ptrmask: DefaultAttrsIntrinsic<[llvm_anyptr_ty], [LLVMMatchType<0>, llvm_anyint_ty],
[IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
 
+def int_threadlocal_address : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty],
+[IntrNoMem, IntrWillReturn]>;
+
 def int_experimental_stepvector : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
 [], [IntrNoMem]>;
 
Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -743,6 +743,9 @@
   /// If the pointer isn't i8* it will be converted.
   CallInst *CreateInvariantStart(Value *Ptr, ConstantInt *Size = nullptr);
 
+  /// Create a call to llvm.threadlocal.address intrinsic.
+  CallInst *CreateThreadLocalAddress(Value *Ptr);
+
   /// Create a call to Masked Load intrinsic
  

[clang] 40a5d79 - [clang-format][NFC] Format lib/Format and unittests/Format in clang

2022-06-09 Thread via cfe-commits

Author: owenca
Date: 2022-06-09T02:25:06-07:00
New Revision: 40a5d79a5cb4edc7343349f17e59377eb9362c4a

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

LOG: [clang-format][NFC] Format lib/Format and unittests/Format in clang

Reformat these directories with InsertBraces and RemoveBracesLLVM.

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

Added: 


Modified: 
clang/lib/Format/BreakableToken.cpp
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/BreakableToken.cpp 
b/clang/lib/Format/BreakableToken.cpp
index 6ae112b86ebb6..db82018a4c83c 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -705,11 +705,9 @@ void BreakableBlockComment::adaptStartOfLine(
   // contain a trailing whitespace.
   Prefix = Prefix.substr(0, 1);
 }
-  } else {
-if (ContentColumn[LineIndex] == 1) {
-  // This line starts immediately after the decorating *.
-  Prefix = Prefix.substr(0, 1);
-}
+  } else if (ContentColumn[LineIndex] == 1) {
+// This line starts immediately after the decorating *.
+Prefix = Prefix.substr(0, 1);
   }
   // This is the offset of the end of the last line relative to the start of 
the
   // token text in the token.

diff  --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index fe43981e27d00..6ec788ad23c66 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -230,12 +230,10 @@ void WhitespaceManager::calculateLineBreakInformation() {
 if (Change.Tok->is(tok::comment)) {
   if (Change.Tok->is(TT_LineComment) || !Change.IsInsideToken) {
 LastBlockComment = &Change;
-  } else {
-if ((Change.StartOfBlockComment = LastBlockComment)) {
-  Change.IndentationOffset =
-  Change.StartOfTokenColumn -
-  Change.StartOfBlockComment->StartOfTokenColumn;
-}
+  } else if ((Change.StartOfBlockComment = LastBlockComment)) {
+Change.IndentationOffset =
+Change.StartOfTokenColumn -
+Change.StartOfBlockComment->StartOfTokenColumn;
   }
 } else {
   LastBlockComment = nullptr;

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index ffc7e941398a1..14b169ebe5869 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25439,8 +25439,7 @@ TEST_F(FormatTest, RemoveBraces) {
   verifyFormat("do {\n"
"  ++I;\n"
"} while (hasMore() && Filter(*I));",
-   "do { ++I; } while (hasMore() && Filter(*I));",
-   Style);
+   "do { ++I; } while (hasMore() && Filter(*I));", Style);
 
   verifyFormat("if (a)\n"
"  if (b)\n"



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


[PATCH] D127366: [clang-format][NFC] Format lib/Format and unittests/Format in clang

2022-06-09 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 rG40a5d79a5cb4: [clang-format][NFC] Format lib/Format and 
unittests/Format in clang (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127366

Files:
  clang/lib/Format/BreakableToken.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25439,8 +25439,7 @@
   verifyFormat("do {\n"
"  ++I;\n"
"} while (hasMore() && Filter(*I));",
-   "do { ++I; } while (hasMore() && Filter(*I));",
-   Style);
+   "do { ++I; } while (hasMore() && Filter(*I));", Style);
 
   verifyFormat("if (a)\n"
"  if (b)\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -230,12 +230,10 @@
 if (Change.Tok->is(tok::comment)) {
   if (Change.Tok->is(TT_LineComment) || !Change.IsInsideToken) {
 LastBlockComment = &Change;
-  } else {
-if ((Change.StartOfBlockComment = LastBlockComment)) {
-  Change.IndentationOffset =
-  Change.StartOfTokenColumn -
-  Change.StartOfBlockComment->StartOfTokenColumn;
-}
+  } else if ((Change.StartOfBlockComment = LastBlockComment)) {
+Change.IndentationOffset =
+Change.StartOfTokenColumn -
+Change.StartOfBlockComment->StartOfTokenColumn;
   }
 } else {
   LastBlockComment = nullptr;
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -705,11 +705,9 @@
   // contain a trailing whitespace.
   Prefix = Prefix.substr(0, 1);
 }
-  } else {
-if (ContentColumn[LineIndex] == 1) {
-  // This line starts immediately after the decorating *.
-  Prefix = Prefix.substr(0, 1);
-}
+  } else if (ContentColumn[LineIndex] == 1) {
+// This line starts immediately after the decorating *.
+Prefix = Prefix.substr(0, 1);
   }
   // This is the offset of the end of the last line relative to the start of 
the
   // token text in the token.


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25439,8 +25439,7 @@
   verifyFormat("do {\n"
"  ++I;\n"
"} while (hasMore() && Filter(*I));",
-   "do { ++I; } while (hasMore() && Filter(*I));",
-   Style);
+   "do { ++I; } while (hasMore() && Filter(*I));", Style);
 
   verifyFormat("if (a)\n"
"  if (b)\n"
Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -230,12 +230,10 @@
 if (Change.Tok->is(tok::comment)) {
   if (Change.Tok->is(TT_LineComment) || !Change.IsInsideToken) {
 LastBlockComment = &Change;
-  } else {
-if ((Change.StartOfBlockComment = LastBlockComment)) {
-  Change.IndentationOffset =
-  Change.StartOfTokenColumn -
-  Change.StartOfBlockComment->StartOfTokenColumn;
-}
+  } else if ((Change.StartOfBlockComment = LastBlockComment)) {
+Change.IndentationOffset =
+Change.StartOfTokenColumn -
+Change.StartOfBlockComment->StartOfTokenColumn;
   }
 } else {
   LastBlockComment = nullptr;
Index: clang/lib/Format/BreakableToken.cpp
===
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -705,11 +705,9 @@
   // contain a trailing whitespace.
   Prefix = Prefix.substr(0, 1);
 }
-  } else {
-if (ContentColumn[LineIndex] == 1) {
-  // This line starts immediately after the decorating *.
-  Prefix = Prefix.substr(0, 1);
-}
+  } else if (ContentColumn[LineIndex] == 1) {
+// This line starts immediately after the decorating *.
+Prefix = Prefix.substr(0, 1);
   }
   // This is the offset of the end of the last line relative to the start of the
   // token text in the token.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127283: [pseudo] Simplify the glrReduce implementation.

2022-06-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 435463.
hokein marked 3 inline comments as done.
hokein added a comment.

address comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127283

Files:
  clang-tools-extra/pseudo/lib/GLR.cpp


Index: clang-tools-extra/pseudo/lib/GLR.cpp
===
--- clang-tools-extra/pseudo/lib/GLR.cpp
+++ clang-tools-extra/pseudo/lib/GLR.cpp
@@ -273,18 +273,16 @@
 }
   };
 
-  // The base nodes are the heads after popping the GSS nodes we are reducing.
-  // We don't care which rule yielded each base. If Family.Symbol is S, the
-  // base includes an item X := ... • S ... and since the grammar is
-  // context-free, *all* parses of S are valid here.
-  // FIXME: reuse the queues across calls instead of reallocating.
-  KeyedQueue Bases;
-
   // A sequence is the ForestNode payloads of the GSS nodes we are reducing.
   // These are the RHS of the rule, the RuleID is stored in the Family.
   // They specify a sequence ForestNode we may build (but we dedup first).
   using Sequence = llvm::SmallVector;
-  KeyedQueue Sequences;
+  struct PushSpec {
+// A base node is the head after popping the GSS nodes we are reducing.
+const GSS::Node* Base = nullptr;
+Sequence Seq;
+  };
+  KeyedQueue Sequences;
 
   Sequence TempSequence;
   // Pop walks up the parent chain(s) for a reduction from Head by to Rule.
@@ -297,9 +295,8 @@
 auto DFS = [&](const GSS::Node *N, unsigned I, auto &DFS) {
   if (I == Rule.Size) {
 F.Start = TempSequence.front()->startTokenIndex();
-Bases.emplace(F, N);
 LLVM_DEBUG(llvm::dbgs() << "--> base at S" << N->State << "\n");
-Sequences.emplace(F, TempSequence);
+Sequences.emplace(F, PushSpec{N, TempSequence});
 return;
   }
   TempSequence[Rule.Size - 1 - I] = N->Payload;
@@ -325,20 +322,26 @@
   //  - process one family at a time, forming a forest node
   //  - produces new GSS heads which may enable more pops
   PopPending();
-  while (!Bases.empty()) {
-// We should always have bases and sequences for the same families.
-Family F = Bases.top().first;
-assert(!Sequences.empty());
-assert(Sequences.top().first == F);
+  while (!Sequences.empty()) {
+Family F = Sequences.top().first;
 
 LLVM_DEBUG(llvm::dbgs() << "  Push " << Params.G.symbolName(F.Symbol)
 << " from token " << F.Start << "\n");
 
-// Grab the sequences for this family.
+// Grab the sequences and bases for this family.
+// We don't care which rule yielded each base. If Family.Symbol is S, the
+// base includes an item X := ... • S ... and since the grammar is
+// context-free, *all* parses of S are valid here.
 FamilySequences.clear();
+FamilyBases.clear();
 do {
   FamilySequences.emplace_back(Sequences.top().first.Rule,
-   Sequences.top().second);
+   Sequences.top().second.Seq);
+  FamilyBases.emplace_back(
+  Params.Table.getGoToState(Sequences.top().second.Base->State,
+F.Symbol),
+  Sequences.top().second.Base);
+
   Sequences.pop();
 } while (!Sequences.empty() && Sequences.top().first == F);
 // Build a forest node for each unique sequence.
@@ -355,15 +358,7 @@
 : &Params.Forest.createAmbiguous(F.Symbol, SequenceNodes);
 LLVM_DEBUG(llvm::dbgs() << "--> " << Parsed->dump(Params.G) << "\n");
 
-// Grab the bases for this family.
-// As well as deduplicating them, we'll group by the goto state.
-FamilyBases.clear();
-do {
-  FamilyBases.emplace_back(
-  Params.Table.getGoToState(Bases.top().second->State, F.Symbol),
-  Bases.top().second);
-  Bases.pop();
-} while (!Bases.empty() && Bases.top().first == F);
+// Bases for this family, deduplicate them, and group by the goTo State.
 sortAndUnique(FamilyBases);
 // Create a GSS node for each unique goto state.
 llvm::ArrayRef BasesLeft = FamilyBases;


Index: clang-tools-extra/pseudo/lib/GLR.cpp
===
--- clang-tools-extra/pseudo/lib/GLR.cpp
+++ clang-tools-extra/pseudo/lib/GLR.cpp
@@ -273,18 +273,16 @@
 }
   };
 
-  // The base nodes are the heads after popping the GSS nodes we are reducing.
-  // We don't care which rule yielded each base. If Family.Symbol is S, the
-  // base includes an item X := ... • S ... and since the grammar is
-  // context-free, *all* parses of S are valid here.
-  // FIXME: reuse the queues across calls instead of reallocating.
-  KeyedQueue Bases;
-
   // A sequence is the ForestNode payloads of the GSS nodes we are reducing.
   // These are the RHS of the rule, the RuleID is stored in the Family.
   // They specify a sequence ForestNod

[clang-tools-extra] 74e4d5f - [pseudo] Simplify the glrReduce implementation.

2022-06-09 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-09T11:28:52+02:00
New Revision: 74e4d5f256fab1a9a72ef60c1d672441696c52e9

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

LOG: [pseudo] Simplify the glrReduce implementation.

glrReduce maintains two priority queues (one for bases, and the other
for Sequence), these queues are in parallel with each other, corresponding to a
single family. They can be folded into one.

This patch removes the bases priority queue, which improves the glrParse by
10%.

ASTReader.cpp: 2.03M/s (before) vs 2.26M/s (after)

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

Added: 


Modified: 
clang-tools-extra/pseudo/lib/GLR.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/GLR.cpp 
b/clang-tools-extra/pseudo/lib/GLR.cpp
index 0938d8846fe0..0a81556ef052 100644
--- a/clang-tools-extra/pseudo/lib/GLR.cpp
+++ b/clang-tools-extra/pseudo/lib/GLR.cpp
@@ -279,18 +279,16 @@ void glrReduce(std::vector &PendingReduce, 
const ParseParams &Params,
 }
   };
 
-  // The base nodes are the heads after popping the GSS nodes we are reducing.
-  // We don't care which rule yielded each base. If Family.Symbol is S, the
-  // base includes an item X := ... • S ... and since the grammar is
-  // context-free, *all* parses of S are valid here.
-  // FIXME: reuse the queues across calls instead of reallocating.
-  KeyedQueue Bases;
-
   // A sequence is the ForestNode payloads of the GSS nodes we are reducing.
   // These are the RHS of the rule, the RuleID is stored in the Family.
   // They specify a sequence ForestNode we may build (but we dedup first).
   using Sequence = llvm::SmallVector;
-  KeyedQueue Sequences;
+  struct PushSpec {
+// A base node is the head after popping the GSS nodes we are reducing.
+const GSS::Node* Base = nullptr;
+Sequence Seq;
+  };
+  KeyedQueue Sequences;
 
   Sequence TempSequence;
   // Pop walks up the parent chain(s) for a reduction from Head by to Rule.
@@ -303,9 +301,8 @@ void glrReduce(std::vector &PendingReduce, const 
ParseParams &Params,
 auto DFS = [&](const GSS::Node *N, unsigned I, auto &DFS) {
   if (I == Rule.Size) {
 F.Start = TempSequence.front()->startTokenIndex();
-Bases.emplace(F, N);
 LLVM_DEBUG(llvm::dbgs() << "--> base at S" << N->State << "\n");
-Sequences.emplace(F, TempSequence);
+Sequences.emplace(F, PushSpec{N, TempSequence});
 return;
   }
   TempSequence[Rule.Size - 1 - I] = N->Payload;
@@ -331,20 +328,26 @@ void glrReduce(std::vector &PendingReduce, 
const ParseParams &Params,
   //  - process one family at a time, forming a forest node
   //  - produces new GSS heads which may enable more pops
   PopPending();
-  while (!Bases.empty()) {
-// We should always have bases and sequences for the same families.
-Family F = Bases.top().first;
-assert(!Sequences.empty());
-assert(Sequences.top().first == F);
+  while (!Sequences.empty()) {
+Family F = Sequences.top().first;
 
 LLVM_DEBUG(llvm::dbgs() << "  Push " << Params.G.symbolName(F.Symbol)
 << " from token " << F.Start << "\n");
 
-// Grab the sequences for this family.
+// Grab the sequences and bases for this family.
+// We don't care which rule yielded each base. If Family.Symbol is S, the
+// base includes an item X := ... • S ... and since the grammar is
+// context-free, *all* parses of S are valid here.
 FamilySequences.clear();
+FamilyBases.clear();
 do {
   FamilySequences.emplace_back(Sequences.top().first.Rule,
-   Sequences.top().second);
+   Sequences.top().second.Seq);
+  FamilyBases.emplace_back(
+  Params.Table.getGoToState(Sequences.top().second.Base->State,
+F.Symbol),
+  Sequences.top().second.Base);
+
   Sequences.pop();
 } while (!Sequences.empty() && Sequences.top().first == F);
 // Build a forest node for each unique sequence.
@@ -361,15 +364,7 @@ void glrReduce(std::vector &PendingReduce, 
const ParseParams &Params,
 : &Params.Forest.createAmbiguous(F.Symbol, SequenceNodes);
 LLVM_DEBUG(llvm::dbgs() << "--> " << Parsed->dump(Params.G) << "\n");
 
-// Grab the bases for this family.
-// As well as deduplicating them, we'll group by the goto state.
-FamilyBases.clear();
-do {
-  FamilyBases.emplace_back(
-  Params.Table.getGoToState(Bases.top().second->State, F.Symbol),
-  Bases.top().second);
-  Bases.pop();
-} while (!Bases.empty() && Bases.top().first == F);
+// Bases for this family, deduplicate them, and group by the goTo State.
 sortAndUnique(FamilyBases);
 

[PATCH] D127283: [pseudo] Simplify the glrReduce implementation.

2022-06-09 Thread Haojian Wu 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 rG74e4d5f256fa: [pseudo] Simplify the glrReduce 
implementation. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127283

Files:
  clang-tools-extra/pseudo/lib/GLR.cpp


Index: clang-tools-extra/pseudo/lib/GLR.cpp
===
--- clang-tools-extra/pseudo/lib/GLR.cpp
+++ clang-tools-extra/pseudo/lib/GLR.cpp
@@ -279,18 +279,16 @@
 }
   };
 
-  // The base nodes are the heads after popping the GSS nodes we are reducing.
-  // We don't care which rule yielded each base. If Family.Symbol is S, the
-  // base includes an item X := ... • S ... and since the grammar is
-  // context-free, *all* parses of S are valid here.
-  // FIXME: reuse the queues across calls instead of reallocating.
-  KeyedQueue Bases;
-
   // A sequence is the ForestNode payloads of the GSS nodes we are reducing.
   // These are the RHS of the rule, the RuleID is stored in the Family.
   // They specify a sequence ForestNode we may build (but we dedup first).
   using Sequence = llvm::SmallVector;
-  KeyedQueue Sequences;
+  struct PushSpec {
+// A base node is the head after popping the GSS nodes we are reducing.
+const GSS::Node* Base = nullptr;
+Sequence Seq;
+  };
+  KeyedQueue Sequences;
 
   Sequence TempSequence;
   // Pop walks up the parent chain(s) for a reduction from Head by to Rule.
@@ -303,9 +301,8 @@
 auto DFS = [&](const GSS::Node *N, unsigned I, auto &DFS) {
   if (I == Rule.Size) {
 F.Start = TempSequence.front()->startTokenIndex();
-Bases.emplace(F, N);
 LLVM_DEBUG(llvm::dbgs() << "--> base at S" << N->State << "\n");
-Sequences.emplace(F, TempSequence);
+Sequences.emplace(F, PushSpec{N, TempSequence});
 return;
   }
   TempSequence[Rule.Size - 1 - I] = N->Payload;
@@ -331,20 +328,26 @@
   //  - process one family at a time, forming a forest node
   //  - produces new GSS heads which may enable more pops
   PopPending();
-  while (!Bases.empty()) {
-// We should always have bases and sequences for the same families.
-Family F = Bases.top().first;
-assert(!Sequences.empty());
-assert(Sequences.top().first == F);
+  while (!Sequences.empty()) {
+Family F = Sequences.top().first;
 
 LLVM_DEBUG(llvm::dbgs() << "  Push " << Params.G.symbolName(F.Symbol)
 << " from token " << F.Start << "\n");
 
-// Grab the sequences for this family.
+// Grab the sequences and bases for this family.
+// We don't care which rule yielded each base. If Family.Symbol is S, the
+// base includes an item X := ... • S ... and since the grammar is
+// context-free, *all* parses of S are valid here.
 FamilySequences.clear();
+FamilyBases.clear();
 do {
   FamilySequences.emplace_back(Sequences.top().first.Rule,
-   Sequences.top().second);
+   Sequences.top().second.Seq);
+  FamilyBases.emplace_back(
+  Params.Table.getGoToState(Sequences.top().second.Base->State,
+F.Symbol),
+  Sequences.top().second.Base);
+
   Sequences.pop();
 } while (!Sequences.empty() && Sequences.top().first == F);
 // Build a forest node for each unique sequence.
@@ -361,15 +364,7 @@
 : &Params.Forest.createAmbiguous(F.Symbol, SequenceNodes);
 LLVM_DEBUG(llvm::dbgs() << "--> " << Parsed->dump(Params.G) << "\n");
 
-// Grab the bases for this family.
-// As well as deduplicating them, we'll group by the goto state.
-FamilyBases.clear();
-do {
-  FamilyBases.emplace_back(
-  Params.Table.getGoToState(Bases.top().second->State, F.Symbol),
-  Bases.top().second);
-  Bases.pop();
-} while (!Bases.empty() && Bases.top().first == F);
+// Bases for this family, deduplicate them, and group by the goTo State.
 sortAndUnique(FamilyBases);
 // Create a GSS node for each unique goto state.
 llvm::ArrayRef BasesLeft = FamilyBases;


Index: clang-tools-extra/pseudo/lib/GLR.cpp
===
--- clang-tools-extra/pseudo/lib/GLR.cpp
+++ clang-tools-extra/pseudo/lib/GLR.cpp
@@ -279,18 +279,16 @@
 }
   };
 
-  // The base nodes are the heads after popping the GSS nodes we are reducing.
-  // We don't care which rule yielded each base. If Family.Symbol is S, the
-  // base includes an item X := ... • S ... and since the grammar is
-  // context-free, *all* parses of S are valid here.
-  // FIXME: reuse the queues across calls instead of reallocating.
-  KeyedQueue Bases;
-
   // A sequence is the ForestNode payloads of the GSS nodes we are reducing.
   // T

[PATCH] D126461: [RISCV] Extract and store new vl of vleff/vlsegff iff destination isn't null

2022-06-09 Thread Wang Pengcheng via Phabricator via cfe-commits
pcwang-thead updated this revision to Diff 435466.
pcwang-thead added a comment.

Update test `rvv-intrinsics-overloaded/vlsegff.c`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126461

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-overloaded/vlsegff.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vleff-optimized.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vleff.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlsegff-optimized.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlsegff.c
  clang/test/CodeGen/RISCV/rvv-intrinsics/vlsegff_mask.c

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


[PATCH] D126291: [flang][Driver] Update link job on windows

2022-06-09 Thread Markus Mützel via Phabricator via cfe-commits
mmuetzel added a comment.

Should this be conditional on the command line flag `-flang-experimental-exec` 
for the time being (like for the GNU toolchain)?
See D122008 




Comment at: clang/lib/Driver/ToolChains/MSVC.cpp:133
 
+  if (C.getDriver().IsFlangMode()) {
+tools::addFortranRuntimeLibraryPath(TC, Args, CmdArgs);

The GNU toolchain has this conditional on 
`Args.hasArg(options::OPT_flang_experimental_exec)`.
Should this require that command line flag on MSVC, too?

Same for the MinGW toolchain file.


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

https://reviews.llvm.org/D126291

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


[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-06-09 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 435474.
carlosgalvezp marked 2 inline comments as done.
carlosgalvezp added a comment.

Address review comments.
Rebase on latest main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126880

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
@@ -0,0 +1,152 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-const-or-ref-data-members %t
+namespace std {
+template 
+struct reference_wrapper {};
+} // namespace std
+
+namespace gsl {
+template 
+struct not_null {};
+} // namespace gsl
+
+struct Ok {
+  int i;
+  int *p;
+  const int *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember {
+  const int c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct LvalueRefMember {
+  int &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+};
+
+struct ConstRefMember {
+  const int &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+};
+
+struct RvalueRefMember {
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstAndRefMembers {
+  int const c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  int &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+  const int &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct Foo {};
+
+struct Ok2 {
+  Foo i;
+  Foo *p;
+  const Foo *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct LvalueRefMember2 {
+  Foo &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+};
+
+struct ConstRefMember2 {
+  const Foo &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+};
+
+struct RvalueRefMember2 {
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstAndRefMembers2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  Foo &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+  const Foo &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+using ConstType = const int;
+using RefType = int &;
+using ConstRefType = const int &;
+using RefRefType = int &&;
+
+struct WithAlias {
+  ConstType c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  RefType lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: member 'lr' is a reference
+  ConstRefType cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: member 'cr' is a reference
+  RefRefType rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+using Array = int[N];
+
+struct ConstArrayMember {
+  const Array<1> c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: member 'c' is const qualified
+};
+
+struct LvalueRefArrayMember {
+  Array<2> &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'lr' is a reference
+};
+
+struct ConstLvalueRefArrayMember {
+  Array<3> const &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: member 'cr' is a reference
+};
+
+struct RvalueRefArrayMember {
+  Array<4> &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+struct TemplatedOk {
+  T t;
+};
+
+template 
+struct TemplatedConst {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is const qualified
+};
+
+template 
+struct TemplatedRef {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is a reference
+};
+
+TemplatedOk t1{};
+TemplatedConst t2{123};
+T

[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-06-09 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp added inline comments.



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

Eugene.Zelenko wrote:
> Please add `isLanguageVersionSupported`.
Done. I generated this check via `add_new_check.py` - should we add this there 
as well to avoid similar issues in the future (separate commit)?

I see some checks implement this function and some others don't, so it's not 
totally clear to me when is needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126880

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


[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable

2022-06-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu updated this revision to Diff 435475.
ChuanqiXu added a comment.

Address inline comments.


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

https://reviews.llvm.org/D125291

Files:
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/cxx11-thread-local-instantiated.cpp
  clang/test/CodeGenCXX/pr18635.cpp
  clang/test/CodeGenCXX/threadlocal_address.cpp
  llvm/docs/LangRef.rst
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/include/llvm/IR/IRBuilder.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
  llvm/lib/IR/IRBuilder.cpp
  llvm/test/Transforms/PreISelIntrinsicLowering/threadlocal_address.ll

Index: llvm/test/Transforms/PreISelIntrinsicLowering/threadlocal_address.ll
===
--- /dev/null
+++ llvm/test/Transforms/PreISelIntrinsicLowering/threadlocal_address.ll
@@ -0,0 +1,25 @@
+; RUN: opt -pre-isel-intrinsic-lowering -opaque-pointers -S -o - < %s | FileCheck %s
+
+@i = thread_local global i32 0, align 4
+
+define dso_local noundef i32 @foo() {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:[[TMP0:%.*]] = load i32, ptr @i, align 4
+; CHECK-NEXT:[[INC:%.*]] = add nsw i32 [[TMP0]], 1
+; CHECK-NEXT:store i32 [[INC]], ptr @i, align 4
+; CHECK-NEXT:[[TMP1:%.*]] = load i32, ptr @i, align 4
+; CHECK-NEXT:ret i32 [[TMP1]]
+;
+; CHECK-NOT: call{{.*}}@llvm.threadlocal.address(
+entry:
+  %0 = call ptr @llvm.threadlocal.address(ptr @i)
+  %1 = load i32, ptr %0, align 4
+  %inc = add nsw i32 %1, 1
+  store i32 %inc, ptr %0, align 4
+  %2 = call ptr @llvm.threadlocal.address(ptr @i)
+  %3 = load i32, ptr %2, align 4
+  ret i32 %3
+}
+
+declare ptr @llvm.threadlocal.address(ptr) nounwind readnone willreturn
Index: llvm/lib/IR/IRBuilder.cpp
===
--- llvm/lib/IR/IRBuilder.cpp
+++ llvm/lib/IR/IRBuilder.cpp
@@ -499,6 +499,13 @@
   return createCallHelper(TheFn, Ops, this);
 }
 
+CallInst *IRBuilderBase::CreateThreadLocalAddress(Value *Ptr) {
+  assert(isa(Ptr) && cast(Ptr)->isThreadLocal() &&
+ "threadlocal_address only applies to thread local variables.");
+  return CreateIntrinsic(llvm::Intrinsic::threadlocal_address, llvm::None,
+ {Ptr});
+}
+
 CallInst *
 IRBuilderBase::CreateAssumption(Value *Cond,
 ArrayRef OpBundles) {
Index: llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
===
--- llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 //
-// This pass implements IR lowering for the llvm.load.relative and llvm.objc.*
-// intrinsics.
+// This pass implements IR lowering for the llvm.threadlocal_address,
+// llvm.load.relative and llvm.objc.* intrinsics.
 //
 //===--===//
 
@@ -128,6 +128,19 @@
   return true;
 }
 
+static bool lowerThreadLocalIntrinsics(Function &F) {
+  if (F.use_empty())
+return false;
+
+  for (Use &U : llvm::make_early_inc_range(F.uses())) {
+auto *CB = cast(U.getUser());
+CB->replaceAllUsesWith(CB->getOperand(0));
+CB->eraseFromParent();
+  }
+
+  return true;
+}
+
 static bool lowerIntrinsics(Module &M) {
   bool Changed = false;
   for (Function &F : M) {
@@ -213,6 +226,9 @@
 case Intrinsic::objc_sync_exit:
   Changed |= lowerObjCCall(F, "objc_sync_exit");
   break;
+case Intrinsic::threadlocal_address:
+  Changed |= lowerThreadLocalIntrinsics(F);
+  break;
 }
   }
   return Changed;
Index: llvm/include/llvm/IR/Intrinsics.td
===
--- llvm/include/llvm/IR/Intrinsics.td
+++ llvm/include/llvm/IR/Intrinsics.td
@@ -1390,6 +1390,10 @@
 def int_ptrmask: DefaultAttrsIntrinsic<[llvm_anyptr_ty], [LLVMMatchType<0>, llvm_anyint_ty],
[IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
 
+// Intrinsic to wrap a thread local variable.
+def int_threadlocal_address : DefaultAttrsIntrinsic<[llvm_ptr_ty], [llvm_ptr_ty],
+   [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
+
 def int_experimental_stepvector : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
 [], [IntrNoMem]>;
 
Index: llvm/include/llvm/IR/IRBuilder.h
===
--- llvm/include/llvm/IR/IRBuilder.h
+++ llvm/include/llvm/IR/IRBuilder.h
@@ -743,6 +743,9 @@
   /// If the pointer isn't i8* it will be converted.
   CallInst *CreateInvariantStart(Value *Ptr, ConstantInt *Size = nullptr);
 
+  /// Create a call to llvm.threadlocal.address intrinsic.
+  CallInst *CreateThreadLocalAddress(Value *Ptr

[PATCH] D126880: [clang-tidy] Add cppcoreguidelines-avoid-const-or-ref-data-members check

2022-06-09 Thread Carlos Galvez via Phabricator via cfe-commits
carlosgalvezp updated this revision to Diff 435476.
carlosgalvezp added a comment.

Remove copy-paste comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126880

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
  
clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.h
  clang-tools-extra/clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tools-extra/clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/cppcoreguidelines-avoid-const-or-ref-data-members.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines-avoid-const-or-ref-data-members.cpp
@@ -0,0 +1,152 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-avoid-const-or-ref-data-members %t
+namespace std {
+template 
+struct reference_wrapper {};
+} // namespace std
+
+namespace gsl {
+template 
+struct not_null {};
+} // namespace gsl
+
+struct Ok {
+  int i;
+  int *p;
+  const int *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember {
+  const int c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified [cppcoreguidelines-avoid-const-or-ref-data-members]
+};
+
+struct LvalueRefMember {
+  int &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+};
+
+struct ConstRefMember {
+  const int &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+};
+
+struct RvalueRefMember {
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstAndRefMembers {
+  int const c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  int &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+  const int &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+  int &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct Foo {};
+
+struct Ok2 {
+  Foo i;
+  Foo *p;
+  const Foo *pc;
+  std::reference_wrapper r;
+  gsl::not_null n;
+};
+
+struct ConstMember2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+};
+
+struct LvalueRefMember2 {
+  Foo &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+};
+
+struct ConstRefMember2 {
+  const Foo &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+};
+
+struct RvalueRefMember2 {
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+struct ConstAndRefMembers2 {
+  const Foo c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  Foo &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: member 'lr' is a reference
+  const Foo &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'cr' is a reference
+  Foo &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: member 'rr' is a reference
+};
+
+using ConstType = const int;
+using RefType = int &;
+using ConstRefType = const int &;
+using RefRefType = int &&;
+
+struct WithAlias {
+  ConstType c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'c' is const qualified
+  RefType lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: member 'lr' is a reference
+  ConstRefType cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: member 'cr' is a reference
+  RefRefType rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+using Array = int[N];
+
+struct ConstArrayMember {
+  const Array<1> c;
+  // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: member 'c' is const qualified
+};
+
+struct LvalueRefArrayMember {
+  Array<2> &lr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: member 'lr' is a reference
+};
+
+struct ConstLvalueRefArrayMember {
+  Array<3> const &cr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: member 'cr' is a reference
+};
+
+struct RvalueRefArrayMember {
+  Array<4> &&rr;
+  // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: member 'rr' is a reference
+};
+
+template 
+struct TemplatedOk {
+  T t;
+};
+
+template 
+struct TemplatedConst {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is const qualified
+};
+
+template 
+struct TemplatedRef {
+  T t;
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: member 't' is a reference
+};
+
+TemplatedOk t1{};
+TemplatedConst t2{123};
+TemplatedRef t3{123};
+TemplatedRef t4{123};
+TemplatedRef t5{t1.t};
Index: clang-tools-extra/docs/clang-tidy/checks/list.r

[PATCH] D127366: [clang-format][NFC] Format lib/Format and unittests/Format in clang

2022-06-09 Thread Owen Pan via Phabricator via cfe-commits
owenpan added inline comments.



Comment at: clang/unittests/Format/FormatTest.cpp:25442
"} while (hasMore() && Filter(*I));",
-   "do { ++I; } while (hasMore() && Filter(*I));",
-   Style);
+   "do { ++I; } while (hasMore() && Filter(*I));", Style);
 

curdeius wrote:
> This line was just left unformatted, right? Or there was a recent change in 
> the behaviour?
It was unformatted. I must have forgotten to run git-clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127366

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


[PATCH] D126536: [pseudo] Add grammar annotations support.

2022-06-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein marked an inline comment as done.
hokein added inline comments.



Comment at: clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h:219
+  // ExtensionID is the index of the table.
+  std::vector AttributeValues;
 };

sammccall wrote:
> looking at this again, ExtensionNames seems clearer as ExtensionNames[ExtID] 
> seems more obvious that the kinds agree. But up to you
I considered extensionNames, but decided to use AttributeValues. 
`AttributeValues` corresponds to the syntactic grammar `[key=value]` where we 
call value as the attribute value, while using `ExtensionNames` is less 
clearer.  And yeah `AttributeValues[ExtID]` is somehow confusing, but I think 
it is fine, as it is just print code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126536

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


[PATCH] D125291: Introduce @llvm.threadlocal.address intrinsic to access TLS variable

2022-06-09 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu marked 4 inline comments as done.
ChuanqiXu added a comment.

It looks like there are two problems now:
(1) The use of TLS variable in the dynamic initializer and the use of generated 
TLS variable (`__tls_guard`)  doesn't get wrapped in 
@llvm.threadlocal_address() intrinsics. From my perspective, it is fine since 
the initializers should never be coroutines. (I meant to fix the coroutines 
bugs at the very start).
(2) The IR upgrader problem. It is fine to me too since we won't block the use 
of TLS variable directly after the patch landed (maybe we would in the longer 
future). So the higher version of LLVM will be able to compile the IR from 
older version after the patch landed. So it is not a problem to me. (It looks 
like the backward compatibility is not emphasized. This is the first time I saw 
the problem in the community)




Comment at: clang/lib/CodeGen/CGExpr.cpp:2609-2610
+  if (VD->getTLSKind() != VarDecl::TLS_None &&
+  // We only use @llvm.threadlocal.address if opaque pointers enabled.
+  // Otherwise, we need to pay for many unnecessary bitcasts.
+  //

jyknight wrote:
> This should be handled by using an overloaded intrinsic, so you get the 
> entire family llvm.threadlocal.address.* with any pointer-type as the 
> argument and the same type as the return value (that'll happen when you 
> switch the intrinsic to use llvm_anyptr_ty).
Yeah, it could be handled by an overloaded intrinsic. But given the process of 
opaque pointers goes well really, I feel like it is redundant to support non 
opaque pointer mode. It shouldn't affect users since opaque pointers is enabled 
by default as far as I know.


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

https://reviews.llvm.org/D125291

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


[clang-tools-extra] f1ac00c - [pseudo] Add grammar annotations support.

2022-06-09 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-09T12:06:22+02:00
New Revision: f1ac00c9b0d17e48f464709fc554ebf73f165158

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

LOG: [pseudo] Add grammar annotations support.

Add annotation handling ([key=value]) in the BNF grammar parser, which
will be used in the conditional reduction, and error recovery.

Reviewed By: sammccall

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

Added: 


Modified: 
clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
clang-tools-extra/pseudo/unittests/GrammarTest.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
index df757c61a1ed..fff96e9771c8 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
@@ -19,6 +19,22 @@
 //  production rules. A rule is of BNF form (AAA := BBB CCC). A symbol is 
either
 //  nonterminal or terminal, identified by a SymbolID.
 //
+//  Annotations are supported in a syntax form of [key=value]. They specify
+//  attributes which are associated with either a grammar symbol (on the
+//  right-hand side of the symbol) or a grammar rule (at the end of the rule
+//  body).
+//  Attributes provide a way to inject custom code into the GLR parser. Each
+//  unique attribute value creates an extension point (identified by 
ExtensionID
+//  ), and an extension point corresponds to a piece of native code. For
+//  example, C++ grammar has a rule:
+//
+//contextual-override := IDENTIFIER [guard=Override]
+//
+//  GLR parser only conducts the reduction of the rule if the IDENTIFIER
+//  content is `override`. This Override guard is implemented in CXX.cpp by
+//  binding the ExtensionID for the `Override` value to a specific C++ function
+//  that performs the check.
+//
 //  Notions about the BNF grammar:
 //  - "_" is the start symbol of the augmented grammar;
 //  - single-line comment is supported, starting with a #
@@ -69,6 +85,11 @@ inline SymbolID tokenSymbol(tok::TokenKind TK) {
   return TokenFlag | static_cast(TK);
 }
 
+// An extension is a piece of native code specific to a grammar that modifies
+// the behavior of annotated rules. One ExtensionID is assigned for each unique
+// attribute value (all attributes share a namespace).
+using ExtensionID = uint16_t;
+
 // A RuleID uniquely identifies a production rule in a grammar.
 // It is an index into a table of rules.
 using RuleID = uint16_t;
@@ -96,11 +117,17 @@ struct Rule {
   uint8_t Size : SizeBits; // Size of the Sequence
   SymbolID Sequence[MaxElements];
 
+  // A guard extension controls whether a reduction of a rule will be conducted
+  // by the GLR parser.
+  // 0 is sentinel unset extension ID, indicating there is no guard extension
+  // being set for this rule.
+  ExtensionID Guard = 0;
+
   llvm::ArrayRef seq() const {
 return llvm::ArrayRef(Sequence, Size);
   }
   friend bool operator==(const Rule &L, const Rule &R) {
-return L.Target == R.Target && L.seq() == R.seq();
+return L.Target == R.Target && L.seq() == R.seq() && L.Guard == R.Guard;
   }
 };
 
@@ -186,6 +213,9 @@ struct GrammarTable {
   // A table of nonterminals, sorted by name.
   // SymbolID is the index of the table.
   std::vector Nonterminals;
+  // A table of attribute values, sorted by name.
+  // ExtensionID is the index of the table.
+  std::vector AttributeValues;
 };
 
 } // namespace pseudo

diff  --git a/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp 
b/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
index 2be34f8bec68..17634632baf0 100644
--- a/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
+++ b/clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
@@ -61,6 +61,8 @@ std::string Grammar::dumpRule(RuleID RID) const {
   OS << symbolName(R.Target) << " :=";
   for (SymbolID SID : R.seq())
 OS << " " << symbolName(SID);
+  if (R.Guard)
+OS << " [guard=" << T->AttributeValues[R.Guard] << "]";
   return Result;
 }
 

diff  --git a/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp 
b/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
index f581adb3932e..82daf47af610 100644
--- a/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
+++ b/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
@@ -47,6 +47,9 @@ class GrammarBuilder {
 // Assemble the name->ID and ID->nonterminal name maps.
 llvm::DenseSet UniqueNonterminals;
 llvm::DenseMap SymbolIds;
+
+llvm::DenseSet UniqueAttributeValues;
+
 for (uint16_t I = 0; I < NumTerminals; ++I)
   SymbolIds.try_emplace(T->Terminals[I], tokenSymbol(tok::TokenKind(I)));
 au

[PATCH] D126536: [pseudo] Add grammar annotations support.

2022-06-09 Thread Haojian Wu 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 rGf1ac00c9b0d1: [pseudo] Add grammar annotations support. 
(authored by hokein).

Changed prior to commit:
  https://reviews.llvm.org/D126536?vs=434906&id=435478#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126536

Files:
  clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
  clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
  clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
  clang-tools-extra/pseudo/unittests/GrammarTest.cpp

Index: clang-tools-extra/pseudo/unittests/GrammarTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GrammarTest.cpp
+++ clang-tools-extra/pseudo/unittests/GrammarTest.cpp
@@ -99,6 +99,22 @@
   EXPECT_LT(ruleFor("x"), ruleFor("_"));
 }
 
+TEST_F(GrammarTest, Annotation) {
+  build(R"bnf(
+_ := x
+
+x := y [guard=value]
+y := IDENTIFIER [guard=final]
+
+  )bnf");
+  ASSERT_TRUE(Diags.empty());
+  EXPECT_EQ(G->lookupRule(ruleFor("_")).Guard, 0);
+  EXPECT_GT(G->lookupRule(ruleFor("x")).Guard, 0);
+  EXPECT_GT(G->lookupRule(ruleFor("y")).Guard, 0);
+  EXPECT_NE(G->lookupRule(ruleFor("x")).Guard,
+G->lookupRule(ruleFor("y")).Guard);
+}
+
 TEST_F(GrammarTest, Diagnostics) {
   build(R"cpp(
 _ := ,_opt
@@ -110,6 +126,8 @@
 # cycle
 a := b
 b := a
+
+_ := IDENTIFIER [unknown=value]
   )cpp");
 
   EXPECT_EQ(G->underscore(), id("_"));
@@ -120,7 +138,8 @@
  "Failed to parse 'invalid': no separator :=",
  "Token-like name IDENFIFIE is used as a nonterminal",
  "No rules for nonterminal: IDENFIFIE",
- "The grammar contains a cycle involving symbol a"));
+ "The grammar contains a cycle involving symbol a",
+ "Unknown attribute 'unknown'"));
 }
 
 TEST_F(GrammarTest, FirstAndFollowSets) {
Index: clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
+++ clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
@@ -47,6 +47,9 @@
 // Assemble the name->ID and ID->nonterminal name maps.
 llvm::DenseSet UniqueNonterminals;
 llvm::DenseMap SymbolIds;
+
+llvm::DenseSet UniqueAttributeValues;
+
 for (uint16_t I = 0; I < NumTerminals; ++I)
   SymbolIds.try_emplace(T->Terminals[I], tokenSymbol(tok::TokenKind(I)));
 auto Consider = [&](llvm::StringRef Name) {
@@ -55,8 +58,11 @@
 };
 for (const auto &Spec : Specs) {
   Consider(Spec.Target);
-  for (const RuleSpec::Element &Elt : Spec.Sequence)
+  for (const RuleSpec::Element &Elt : Spec.Sequence) {
 Consider(Elt.Symbol);
+for (const auto& KV : Elt.Attributes)
+   UniqueAttributeValues.insert(KV.second);
+  }
 }
 llvm::for_each(UniqueNonterminals, [&T](llvm::StringRef Name) {
   T->Nonterminals.emplace_back();
@@ -68,6 +74,15 @@
const GrammarTable::Nonterminal &R) {
   return L.Name < R.Name;
 });
+// Add an empty string for the corresponding sentinel unset attribute.
+T->AttributeValues.push_back("");
+llvm::for_each(UniqueAttributeValues, [&T](llvm::StringRef Name) {
+  T->AttributeValues.emplace_back();
+  T->AttributeValues.back() = Name.str();
+});
+llvm::sort(T->AttributeValues);
+assert(T->AttributeValues.front() == "");
+
 // Build name -> ID maps for nonterminals.
 for (SymbolID SID = 0; SID < T->Nonterminals.size(); ++SID)
   SymbolIds.try_emplace(T->Nonterminals[SID].Name, SID);
@@ -86,7 +101,9 @@
   for (const RuleSpec::Element &Elt : Spec.Sequence)
 Symbols.push_back(Lookup(Elt.Symbol));
   T->Rules.push_back(Rule(Lookup(Spec.Target), Symbols));
+  applyAttributes(Spec, *T, T->Rules.back());
 }
+
 assert(T->Rules.size() < (1 << RuleBits) &&
"Too many rules to fit in RuleID bits!");
 const auto &SymbolOrder = getTopologicalOrder(T.get());
@@ -164,6 +181,9 @@
 llvm::StringRef Target;
 struct Element {
   llvm::StringRef Symbol; // Name of the symbol
+  // Attributes that are associated to the sequence symbol or rule.
+  std::vector>
+  Attributes;
 };
 std::vector Sequence;
 
@@ -204,11 +224,46 @@
   Chunk = Chunk.trim();
   if (Chunk.empty())
 continue; // skip empty
+  if (Chunk.startswith("[") && Chunk.endswith("]")) {
+if (Out.Sequence.empty())
+  continue;
+
+parseAttributes(Chunk, Out.Sequence.back().Attributes);
+continue;
+  }
 
   Out.Sequence.push_back({Chunk});
 }
 return true;
-  };
+  }
+
+  bool parseAttributes(

[PATCH] D125400: [clang][Analyzer] Add errno state to standard functions modeling.

2022-06-09 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/test/Analysis/errno-stdlibraryfunctions-notes.c:11
+
+int access(const char *path, int amode);
+

Do you plan to extend the test file for other standard functions as well?



Comment at: clang/test/Analysis/errno-stdlibraryfunctions.c:14-15
+typedef size_t ssize_t;
+ssize_t send(int sockfd, const void *buf, size_t len, int flags);
+off_t lseek(int fildes, off_t offset, int whence);
+

Do you plan to extend the test file for other standard functions as well?



Comment at: clang/test/Analysis/errno-stdlibraryfunctions.c:43-44
+  return 1;
+}
+  }
+  if (result == offset) {

This should be reachable as well, isn't it?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125400

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


[PATCH] D127388: [pseudo] Move grammar-related headers to a separate dir, NFC.

2022-06-09 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.

We did that for .cpp, but forgot the headers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127388

Files:
  clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
  clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
  clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h
  clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRGraph.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
  clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
  clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp
  clang-tools-extra/pseudo/unittests/GrammarTest.cpp
  clang-tools-extra/pseudo/unittests/LRTableTest.cpp

Index: clang-tools-extra/pseudo/unittests/LRTableTest.cpp
===
--- clang-tools-extra/pseudo/unittests/LRTableTest.cpp
+++ clang-tools-extra/pseudo/unittests/LRTableTest.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#include "clang-pseudo/LRTable.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "clang/Basic/TokenKinds.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
Index: clang-tools-extra/pseudo/unittests/GrammarTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GrammarTest.cpp
+++ clang-tools-extra/pseudo/unittests/GrammarTest.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -7,7 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/GLR.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "clang-pseudo/Token.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/TokenKinds.h"
Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -9,10 +9,10 @@
 #include "clang-pseudo/Bracket.h"
 #include "clang-pseudo/DirectiveTree.h"
 #include "clang-pseudo/GLR.h"
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRGraph.h"
-#include "clang-pseudo/LRTable.h"
 #include "clang-pseudo/Token.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRGraph.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
Index: clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
+++ clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
@@ -6,9 +6,9 @@
 //
 //===--===//
 
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRGraph.h"
-#include "clang-pseudo/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRGraph.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "clang/Basic/TokenKinds.h"
 #include 
 
Index: clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
+++ clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#include "clang-pseudo/LRTable.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/ErrorHandling.h"
Index: clang-tools-extra/pseudo/lib/grammar/LRGraph.c

[clang-tools-extra] afbe3ae - [clangd] Minor refactor of CanonicalIncludes::addSystemHeadersMapping.

2022-06-09 Thread Ilya Biryukov via cfe-commits

Author: Paul Pluzhnikov
Date: 2022-06-09T12:18:39+02:00
New Revision: afbe3aed4986300ee2cdbb5c0303bee172c2731b

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

LOG: [clangd] Minor refactor of CanonicalIncludes::addSystemHeadersMapping.

Before commit b3a991df3cd6a SystemHeaderMap used to be a vector.

Commit b3a991df3cd6a changed it into a map, but neglected to remove
duplicate keys (e.g. "bits/typesizes.h", "include/stdint.h", etc.).

To prevent confusion, remove all duplicates, build HeaderMapping
one pair at a time and assert() that no duplicates are found.

Change by Paul Pluzhnikov (ppluzhnikov)!

Reviewed By: ilya-biryukov

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

Added: 


Modified: 
clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp 
b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
index 3d40219616eca..145d98d57ca83 100644
--- a/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ b/clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -18,6 +18,655 @@ namespace clang {
 namespace clangd {
 namespace {
 const char IWYUPragma[] = "// IWYU pragma: private, include ";
+
+const std::pair IncludeMappings[] = {
+{"include/__stddef_max_align_t.h", ""},
+{"include/__wmmintrin_aes.h", ""},
+{"include/__wmmintrin_pclmul.h", ""},
+{"include/adxintrin.h", ""},
+{"include/ammintrin.h", ""},
+{"include/avx2intrin.h", ""},
+{"include/avx512bwintrin.h", ""},
+{"include/avx512cdintrin.h", ""},
+{"include/avx512dqintrin.h", ""},
+{"include/avx512erintrin.h", ""},
+{"include/avx512fintrin.h", ""},
+{"include/avx512ifmaintrin.h", ""},
+{"include/avx512ifmavlintrin.h", ""},
+{"include/avx512pfintrin.h", ""},
+{"include/avx512vbmiintrin.h", ""},
+{"include/avx512vbmivlintrin.h", ""},
+{"include/avx512vlbwintrin.h", ""},
+{"include/avx512vlcdintrin.h", ""},
+{"include/avx512vldqintrin.h", ""},
+{"include/avx512vlintrin.h", ""},
+{"include/avxintrin.h", ""},
+{"include/bmi2intrin.h", ""},
+{"include/bmiintrin.h", ""},
+{"include/emmintrin.h", ""},
+{"include/f16cintrin.h", ""},
+{"include/float.h", ""},
+{"include/fma4intrin.h", ""},
+{"include/fmaintrin.h", ""},
+{"include/fxsrintrin.h", ""},
+{"include/ia32intrin.h", ""},
+{"include/immintrin.h", ""},
+{"include/inttypes.h", ""},
+{"include/limits.h", ""},
+{"include/lzcntintrin.h", ""},
+{"include/mm3dnow.h", ""},
+{"include/mm_malloc.h", ""},
+{"include/mmintrin.h", ""},
+{"include/mwaitxintrin.h", ""},
+{"include/pkuintrin.h", ""},
+{"include/pmmintrin.h", ""},
+{"include/popcntintrin.h", ""},
+{"include/prfchwintrin.h", ""},
+{"include/rdseedintrin.h", ""},
+{"include/rtmintrin.h", ""},
+{"include/shaintrin.h", ""},
+{"include/smmintrin.h", ""},
+{"include/stdalign.h", ""},
+{"include/stdarg.h", ""},
+{"include/stdbool.h", ""},
+{"include/stddef.h", ""},
+{"include/stdint.h", ""},
+{"include/tbmintrin.h", ""},
+{"include/tmmintrin.h", ""},
+{"include/wmmintrin.h", ""},
+{"include/x86intrin.h", ""},
+{"include/xmmintrin.h", ""},
+{"include/xopintrin.h", ""},
+{"include/xsavecintrin.h", ""},
+{"include/xsaveintrin.h", ""},
+{"include/xsaveoptintrin.h", ""},
+{"include/xsavesintrin.h", ""},
+{"include/xtestintrin.h", ""},
+{"include/_G_config.h", ""},
+{"include/assert.h", ""},
+{"algorithm", ""},
+{"valarray", ""},
+{"array", ""},
+{"atomic", ""},
+{"backward/auto_ptr.h", ""},
+{"backward/binders.h", ""},
+{"bits/algorithmfwd.h", ""},
+{"bits/alloc_traits.h", ""},
+{"bits/allocated_ptr.h", ""},
+{"bits/allocator.h", ""},
+{"bits/atomic_base.h", ""},
+{"bits/atomic_lockfree_defines.h", ""},
+{"bits/atomic_futex.h", ""},
+{"bits/basic_ios.h", ""},
+{"bits/basic_ios.tcc", ""},
+{"bits/basic_string.h", ""},
+{"bits/basic_string.tcc", ""},
+{"bits/char_traits.h", ""},
+{"bits/codecvt.h", ""},
+{"bits/concept_check.h", ""},
+{"bits/cpp_type_traits.h", ""},
+{"bits/cxxabi_forced.h", ""},
+{"bits/deque.tcc", ""},
+{"bits/exception.h", ""},
+{"bits/exception_defines.h", ""},
+{"bits/exception_ptr.h", ""},
+{"bits/forward_list.h", ""},
+{"bits/forward_list.tcc", ""},
+{"bits/fstream.tcc", ""},
+{"bits/functexcept.h", ""},
+{"bits/functional_hash.h", ""},
+{"bits/gslice.h", ""},
+{"bits/gslice_array.h", ""},
+{"bits/hash_bytes.h", ""},
+{"bits/hashtable.h", ""},
+{"bits/hashtable_policy.h", ""},
+{"bits/indirect_array.h", ""},
+{"bits/invo

[PATCH] D125742: Minor refactor of CanonicalIncludes::addSystemHeadersMapping.

2022-06-09 Thread Ilya Biryukov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGafbe3aed4986: [clangd] Minor refactor of 
CanonicalIncludes::addSystemHeadersMapping. (authored by ppluzhnikov, committed 
by ilya-biryukov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125742

Files:
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp

Index: clang-tools-extra/clangd/index/CanonicalIncludes.cpp
===
--- clang-tools-extra/clangd/index/CanonicalIncludes.cpp
+++ clang-tools-extra/clangd/index/CanonicalIncludes.cpp
@@ -18,6 +18,655 @@
 namespace clangd {
 namespace {
 const char IWYUPragma[] = "// IWYU pragma: private, include ";
+
+const std::pair IncludeMappings[] = {
+{"include/__stddef_max_align_t.h", ""},
+{"include/__wmmintrin_aes.h", ""},
+{"include/__wmmintrin_pclmul.h", ""},
+{"include/adxintrin.h", ""},
+{"include/ammintrin.h", ""},
+{"include/avx2intrin.h", ""},
+{"include/avx512bwintrin.h", ""},
+{"include/avx512cdintrin.h", ""},
+{"include/avx512dqintrin.h", ""},
+{"include/avx512erintrin.h", ""},
+{"include/avx512fintrin.h", ""},
+{"include/avx512ifmaintrin.h", ""},
+{"include/avx512ifmavlintrin.h", ""},
+{"include/avx512pfintrin.h", ""},
+{"include/avx512vbmiintrin.h", ""},
+{"include/avx512vbmivlintrin.h", ""},
+{"include/avx512vlbwintrin.h", ""},
+{"include/avx512vlcdintrin.h", ""},
+{"include/avx512vldqintrin.h", ""},
+{"include/avx512vlintrin.h", ""},
+{"include/avxintrin.h", ""},
+{"include/bmi2intrin.h", ""},
+{"include/bmiintrin.h", ""},
+{"include/emmintrin.h", ""},
+{"include/f16cintrin.h", ""},
+{"include/float.h", ""},
+{"include/fma4intrin.h", ""},
+{"include/fmaintrin.h", ""},
+{"include/fxsrintrin.h", ""},
+{"include/ia32intrin.h", ""},
+{"include/immintrin.h", ""},
+{"include/inttypes.h", ""},
+{"include/limits.h", ""},
+{"include/lzcntintrin.h", ""},
+{"include/mm3dnow.h", ""},
+{"include/mm_malloc.h", ""},
+{"include/mmintrin.h", ""},
+{"include/mwaitxintrin.h", ""},
+{"include/pkuintrin.h", ""},
+{"include/pmmintrin.h", ""},
+{"include/popcntintrin.h", ""},
+{"include/prfchwintrin.h", ""},
+{"include/rdseedintrin.h", ""},
+{"include/rtmintrin.h", ""},
+{"include/shaintrin.h", ""},
+{"include/smmintrin.h", ""},
+{"include/stdalign.h", ""},
+{"include/stdarg.h", ""},
+{"include/stdbool.h", ""},
+{"include/stddef.h", ""},
+{"include/stdint.h", ""},
+{"include/tbmintrin.h", ""},
+{"include/tmmintrin.h", ""},
+{"include/wmmintrin.h", ""},
+{"include/x86intrin.h", ""},
+{"include/xmmintrin.h", ""},
+{"include/xopintrin.h", ""},
+{"include/xsavecintrin.h", ""},
+{"include/xsaveintrin.h", ""},
+{"include/xsaveoptintrin.h", ""},
+{"include/xsavesintrin.h", ""},
+{"include/xtestintrin.h", ""},
+{"include/_G_config.h", ""},
+{"include/assert.h", ""},
+{"algorithm", ""},
+{"valarray", ""},
+{"array", ""},
+{"atomic", ""},
+{"backward/auto_ptr.h", ""},
+{"backward/binders.h", ""},
+{"bits/algorithmfwd.h", ""},
+{"bits/alloc_traits.h", ""},
+{"bits/allocated_ptr.h", ""},
+{"bits/allocator.h", ""},
+{"bits/atomic_base.h", ""},
+{"bits/atomic_lockfree_defines.h", ""},
+{"bits/atomic_futex.h", ""},
+{"bits/basic_ios.h", ""},
+{"bits/basic_ios.tcc", ""},
+{"bits/basic_string.h", ""},
+{"bits/basic_string.tcc", ""},
+{"bits/char_traits.h", ""},
+{"bits/codecvt.h", ""},
+{"bits/concept_check.h", ""},
+{"bits/cpp_type_traits.h", ""},
+{"bits/cxxabi_forced.h", ""},
+{"bits/deque.tcc", ""},
+{"bits/exception.h", ""},
+{"bits/exception_defines.h", ""},
+{"bits/exception_ptr.h", ""},
+{"bits/forward_list.h", ""},
+{"bits/forward_list.tcc", ""},
+{"bits/fstream.tcc", ""},
+{"bits/functexcept.h", ""},
+{"bits/functional_hash.h", ""},
+{"bits/gslice.h", ""},
+{"bits/gslice_array.h", ""},
+{"bits/hash_bytes.h", ""},
+{"bits/hashtable.h", ""},
+{"bits/hashtable_policy.h", ""},
+{"bits/indirect_array.h", ""},
+{"bits/invoke.h", ""},
+{"bits/ios_base.h", ""},
+{"bits/istream.tcc", ""},
+{"bits/list.tcc", ""},
+{"bits/locale_classes.h", ""},
+{"bits/locale_classes.tcc", ""},
+{"bits/locale_conv.h", ""},
+{"bits/locale_facets.h", ""},
+{"bits/locale_facets.tcc", ""},
+{"bits/locale_facets_nonio.h", ""},
+{"bits/locale_facets_nonio.tcc", ""},
+{"bits/localefwd.h", ""},
+{"bits/mask_array.h", ""},
+{"bits/memoryfwd.h", ""},
+{"bits/move.h", ""},
+{"bits/nested_exception.h", ""},
+{"bits/ostream.tcc", ""},
+{"bits/ostream_insert.h", ""},
+{"bits/parse_numbers.h", ""},
+{"bits/po

[PATCH] D125742: Minor refactor of CanonicalIncludes::addSystemHeadersMapping.

2022-06-09 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

In D125742#3563855 , @ppluzhnikov 
wrote:

> Could you commit this?

Sure! Done.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125742

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


[PATCH] D127388: [pseudo] Move grammar-related headers to a separate dir, NFC.

2022-06-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 435483.
hokein added a comment.

update missing files.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127388

Files:
  clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
  clang-tools-extra/pseudo/gen/Main.cpp
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
  clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
  clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h
  clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
  clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRGraph.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
  clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
  clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp
  clang-tools-extra/pseudo/unittests/GrammarTest.cpp
  clang-tools-extra/pseudo/unittests/LRTableTest.cpp

Index: clang-tools-extra/pseudo/unittests/LRTableTest.cpp
===
--- clang-tools-extra/pseudo/unittests/LRTableTest.cpp
+++ clang-tools-extra/pseudo/unittests/LRTableTest.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#include "clang-pseudo/LRTable.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "clang/Basic/TokenKinds.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
Index: clang-tools-extra/pseudo/unittests/GrammarTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GrammarTest.cpp
+++ clang-tools-extra/pseudo/unittests/GrammarTest.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -7,7 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/GLR.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "clang-pseudo/Token.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/TokenKinds.h"
Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -9,10 +9,10 @@
 #include "clang-pseudo/Bracket.h"
 #include "clang-pseudo/DirectiveTree.h"
 #include "clang-pseudo/GLR.h"
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRGraph.h"
-#include "clang-pseudo/LRTable.h"
 #include "clang-pseudo/Token.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRGraph.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
Index: clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
+++ clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
@@ -6,9 +6,9 @@
 //
 //===--===//
 
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRGraph.h"
-#include "clang-pseudo/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRGraph.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "clang/Basic/TokenKinds.h"
 #include 
 
Index: clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
+++ clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#include "clang-pseudo/LRTable.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/ErrorHandling.h"
Index: clang-tools-ex

[PATCH] D127389: [analyzer] Print the offending function at EndAnalysis crash

2022-06-09 Thread Balázs Benics via Phabricator via cfe-commits
steakhal created this revision.
steakhal added reviewers: NoQ, martong.
Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, 
mikhail.ramalho, a.sidorin, rnkovacs, szepet, baloghadamsoftware, xazax.hun.
Herald added a reviewer: Szelethus.
Herald added a project: All.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

I've faced crashes in the past multiple times when some
`check::EndAnalysis` callback caused some crash.
It's really anoying that it doesn't tell which function triggered this
callback.

This patch adds the well-known trace for that situation as well.
Example:

1.  parser at end of file
2. While analyzing stack: #0 Calling test11

Note that this does not have tests.
I've considered `unittests` for this purpose, by using the
`ASSERT_DEATH()` similarly how we check double eval called functions in
`ConflictingEvalCallsTest.cpp`, however, that the testsuite won't invoke
the custom handlers. Only the message of the `llvm_unreachable()` will
be printed. Consequently, it's not applicable for us testing this
feature.

I've also considered using an end-to-end LIT test for this.
For that, we would need to somehow overload the `clang_analyzer_crash()`
`ExprInspection` handler, to get triggered by other events than the
`EvalCall`. I'm not saying that we could not come up with a generic way
of causing crash in a specific checker callback, but I'm not sure if
that would worth the effort.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127389

Files:
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp


Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -613,6 +613,7 @@
 }
 
 void ExprEngine::processEndWorklist() {
+  PrettyStackTraceLocationContext CrashInfo(getRootLocationContext());
   getCheckerManager().runCheckersForEndAnalysis(G, BR, *this);
 }
 
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -228,6 +228,11 @@
 
   const Stmt *getStmt() const;
 
+  const LocationContext *getRootLocationContext() const {
+assert(G.roots_begin() != G.roots_end());
+return (*G.roots_begin())->getLocation().getLocationContext();
+  }
+
   void GenerateAutoTransition(ExplodedNode *N);
   void enqueueEndOfPath(ExplodedNodeSet &S);
   void GenerateCallExitNode(ExplodedNode *N);


Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -613,6 +613,7 @@
 }
 
 void ExprEngine::processEndWorklist() {
+  PrettyStackTraceLocationContext CrashInfo(getRootLocationContext());
   getCheckerManager().runCheckersForEndAnalysis(G, BR, *this);
 }
 
Index: clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
===
--- clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
+++ clang/include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
@@ -228,6 +228,11 @@
 
   const Stmt *getStmt() const;
 
+  const LocationContext *getRootLocationContext() const {
+assert(G.roots_begin() != G.roots_end());
+return (*G.roots_begin())->getLocation().getLocationContext();
+  }
+
   void GenerateAutoTransition(ExplodedNode *N);
   void enqueueEndOfPath(ExplodedNodeSet &S);
   void GenerateCallExitNode(ExplodedNode *N);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D122150: [clang][analyzer] Add checker for bad use of 'errno'.

2022-06-09 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/docs/analyzer/checkers.rst:2553-2555
+The supported functions are the same that are modeled by checker
+:doc:`alpha.unix.StdCLibraryFunctionArgs` (and affect value of ``errno``),
+including effect of the ``ModelPOSIX`` option of that checker.

This sentence is a bit hard to follow, I'd split this up.



Comment at: clang/docs/analyzer/checkers.rst:2559-2560
+
+The ``AllowUnconditionalErrnoRead`` option allows reads of the errno value all
+times if the value is not used as a condition (at the first read). For example
+``errno`` can be stored into a variable without getting a warning from the

"all times" and "the first read" seems to be in contradiction to each other. 
Could you please rephrase? Use a standalone sentence that explains the "(at the 
first read)" part.



Comment at: clang/docs/analyzer/checkers.rst:2560
+The ``AllowUnconditionalErrnoRead`` option allows reads of the errno value all
+times if the value is not used as a condition (at the first read). For example
+``errno`` can be stored into a variable without getting a warning from the

?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122150

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


[clang] 5160851 - cmake: use llvm dir variables for clang/utils/hmaptool

2022-06-09 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-06-09T12:25:38+02:00
New Revision: 51608515faa74c87ae09877be24eeb6a8226ff7e

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

LOG: cmake: use llvm dir variables for clang/utils/hmaptool

Copy hmaptool using the paths for CURRENT_TOOLS_DIR, so
everything goes in the right place in case llvm is included
from a top level CMakeLists.txt.

Signed-off-by: Matheus Izvekov 

Reviewed By: stephenneuendorffer

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

Added: 


Modified: 
clang/utils/hmaptool/CMakeLists.txt

Removed: 




diff  --git a/clang/utils/hmaptool/CMakeLists.txt 
b/clang/utils/hmaptool/CMakeLists.txt
index f0d9866782b88..1b77727fa791b 100644
--- a/clang/utils/hmaptool/CMakeLists.txt
+++ b/clang/utils/hmaptool/CMakeLists.txt
@@ -1,19 +1,14 @@
-set(CLANG_HMAPTOOL hmaptool)
+# FIXME: ideally we would just provide CURRENT_TOOLS_DIR globally instead of
+#computing it just for function(configure_lit_site_cfg)
+set_llvm_build_mode()
+string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" CURRENT_TOOLS_DIR 
"${LLVM_RUNTIME_OUTPUT_INTDIR}")
 
-add_custom_command(OUTPUT 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}
-   COMMAND ${CMAKE_COMMAND} -E make_directory
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin
-   COMMAND ${CMAKE_COMMAND} -E copy
- ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/
-   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL})
+add_custom_command(OUTPUT "${CURRENT_TOOLS_DIR}/hmaptool"
+   COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${CURRENT_TOOLS_DIR}"
+   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-list(APPEND Depends 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
-install(PROGRAMS ${CLANG_HMAPTOOL}
-DESTINATION "${CMAKE_INSTALL_BINDIR}"
-COMPONENT hmaptool)
-
-add_custom_target(hmaptool ALL DEPENDS ${Depends})
+install(PROGRAMS hmaptool DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" COMPONENT 
hmaptool)
+add_custom_target(hmaptool ALL DEPENDS "${CURRENT_TOOLS_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
 if(NOT LLVM_ENABLE_IDE)



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


[PATCH] D126308: cmake: use llvm dir variables for clang/utils/hmaptool

2022-06-09 Thread Matheus Izvekov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG51608515faa7: cmake: use llvm dir variables for 
clang/utils/hmaptool (authored by mizvekov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126308

Files:
  clang/utils/hmaptool/CMakeLists.txt


Index: clang/utils/hmaptool/CMakeLists.txt
===
--- clang/utils/hmaptool/CMakeLists.txt
+++ clang/utils/hmaptool/CMakeLists.txt
@@ -1,19 +1,14 @@
-set(CLANG_HMAPTOOL hmaptool)
+# FIXME: ideally we would just provide CURRENT_TOOLS_DIR globally instead of
+#computing it just for function(configure_lit_site_cfg)
+set_llvm_build_mode()
+string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" CURRENT_TOOLS_DIR 
"${LLVM_RUNTIME_OUTPUT_INTDIR}")
 
-add_custom_command(OUTPUT 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}
-   COMMAND ${CMAKE_COMMAND} -E make_directory
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin
-   COMMAND ${CMAKE_COMMAND} -E copy
- ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/
-   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL})
+add_custom_command(OUTPUT "${CURRENT_TOOLS_DIR}/hmaptool"
+   COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${CURRENT_TOOLS_DIR}"
+   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-list(APPEND Depends 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
-install(PROGRAMS ${CLANG_HMAPTOOL}
-DESTINATION "${CMAKE_INSTALL_BINDIR}"
-COMPONENT hmaptool)
-
-add_custom_target(hmaptool ALL DEPENDS ${Depends})
+install(PROGRAMS hmaptool DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" COMPONENT 
hmaptool)
+add_custom_target(hmaptool ALL DEPENDS "${CURRENT_TOOLS_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
 if(NOT LLVM_ENABLE_IDE)


Index: clang/utils/hmaptool/CMakeLists.txt
===
--- clang/utils/hmaptool/CMakeLists.txt
+++ clang/utils/hmaptool/CMakeLists.txt
@@ -1,19 +1,14 @@
-set(CLANG_HMAPTOOL hmaptool)
+# FIXME: ideally we would just provide CURRENT_TOOLS_DIR globally instead of
+#computing it just for function(configure_lit_site_cfg)
+set_llvm_build_mode()
+string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" CURRENT_TOOLS_DIR "${LLVM_RUNTIME_OUTPUT_INTDIR}")
 
-add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}
-   COMMAND ${CMAKE_COMMAND} -E make_directory
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin
-   COMMAND ${CMAKE_COMMAND} -E copy
- ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/
-   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL})
+add_custom_command(OUTPUT "${CURRENT_TOOLS_DIR}/hmaptool"
+   COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${CURRENT_TOOLS_DIR}"
+   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
-install(PROGRAMS ${CLANG_HMAPTOOL}
-DESTINATION "${CMAKE_INSTALL_BINDIR}"
-COMPONENT hmaptool)
-
-add_custom_target(hmaptool ALL DEPENDS ${Depends})
+install(PROGRAMS hmaptool DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" COMPONENT hmaptool)
+add_custom_target(hmaptool ALL DEPENDS "${CURRENT_TOOLS_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
 if(NOT LLVM_ENABLE_IDE)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126308: cmake: use llvm dir variables for clang/utils/hmaptool

2022-06-09 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D126308#3569379 , @nikic wrote:

> Sorry, missed the update. Just tried this in a local build and it seems to 
> work fine!

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126308

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


[PATCH] D127065: [docs] Update supported language standards list for C++

2022-06-09 Thread Jose Manuel Monsalve Diaz via Phabricator via cfe-commits
josemonsalve2 added a comment.

Changes are fine. I am not familiar with the progress in C++20 and 23, but I 
trust your judgement here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127065

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


[PATCH] D127389: [analyzer] Print the offending function at EndAnalysis crash

2022-06-09 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:616
 void ExprEngine::processEndWorklist() {
+  PrettyStackTraceLocationContext CrashInfo(getRootLocationContext());
   getCheckerManager().runCheckersForEndAnalysis(G, BR, *this);

Okay, so, at least we will get the name of the top-level function, right? Some 
comments might be useful here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127389

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


[PATCH] D127390: [clang-format][NFC] Remove unused FormatStyle members

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127390

Files:
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -395,11 +395,6 @@
   /// \version 9
   bool AllowAllArgumentsOnNextLine;
 
-  /// This option is **deprecated**. See ``NextLine`` of
-  /// ``PackConstructorInitializers``.
-  /// \version 9
-  bool AllowAllConstructorInitializersOnNextLine;
-
   /// If the function declaration doesn't fit on a line,
   /// allow putting all parameters of a function declaration onto
   /// the next line even if ``BinPackParameters`` is ``false``.
@@ -1883,11 +1878,6 @@
   /// \version 5
   bool CompactNamespaces;
 
-  /// This option is **deprecated**. See ``CurrentLine`` of
-  /// ``PackConstructorInitializers``.
-  /// \version 3.7
-  bool ConstructorInitializerAllOnOneLineOrOnePerLine;
-
   /// The number of characters to use for indentation of constructor
   /// initializer lists as well as inheritance lists.
   /// \version 3.7


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -395,11 +395,6 @@
   /// \version 9
   bool AllowAllArgumentsOnNextLine;
 
-  /// This option is **deprecated**. See ``NextLine`` of
-  /// ``PackConstructorInitializers``.
-  /// \version 9
-  bool AllowAllConstructorInitializersOnNextLine;
-
   /// If the function declaration doesn't fit on a line,
   /// allow putting all parameters of a function declaration onto
   /// the next line even if ``BinPackParameters`` is ``false``.
@@ -1883,11 +1878,6 @@
   /// \version 5
   bool CompactNamespaces;
 
-  /// This option is **deprecated**. See ``CurrentLine`` of
-  /// ``PackConstructorInitializers``.
-  /// \version 3.7
-  bool ConstructorInitializerAllOnOneLineOrOnePerLine;
-
   /// The number of characters to use for indentation of constructor
   /// initializer lists as well as inheritance lists.
   /// \version 3.7
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127393: [Driver] Don't add -lresolv on FreeBSD

2022-06-09 Thread Andrew Turner via Phabricator via cfe-commits
andrew created this revision.
andrew added reviewers: kda, vitalybuka, eugenis, MaskRay.
Herald added subscribers: StephenFan, krytarowski, arichardson, emaste.
Herald added a project: All.
andrew requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

There is no libresolv on FreeBSD. This fixes the sanitizers on
FreeBSD after https://reviews.llvm.org/D127145


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127393

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/sanitizer-ld.c


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -107,7 +107,6 @@
 // CHECK-ASAN-FREEBSD: "--export-dynamic"
 // CHECK-ASAN-FREEBSD: "-lpthread"
 // CHECK-ASAN-FREEBSD: "-lrt"
-// CHECK-ASAN-FREEBSD: "-lresolv"
 
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=i386-unknown-freebsd -fuse-ld=ld -fsanitize=address \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -839,7 +839,7 @@
   TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-lexecinfo");
   // There is no libresolv on Android.
-  if (!TC.getTriple().isAndroid())
+  if (!TC.getTriple().isAndroid() && !TC.getTriple().isOSFreeBSD())
 CmdArgs.push_back("-lresolv");
 }
 


Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -107,7 +107,6 @@
 // CHECK-ASAN-FREEBSD: "--export-dynamic"
 // CHECK-ASAN-FREEBSD: "-lpthread"
 // CHECK-ASAN-FREEBSD: "-lrt"
-// CHECK-ASAN-FREEBSD: "-lresolv"
 
 // RUN: %clang -### %s 2>&1 \
 // RUN: --target=i386-unknown-freebsd -fuse-ld=ld -fsanitize=address \
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -839,7 +839,7 @@
   TC.getTriple().isOSOpenBSD())
 CmdArgs.push_back("-lexecinfo");
   // There is no libresolv on Android.
-  if (!TC.getTriple().isAndroid())
+  if (!TC.getTriple().isAndroid() && !TC.getTriple().isOSFreeBSD())
 CmdArgs.push_back("-lresolv");
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127390: [clang-format][NFC] Remove unused FormatStyle members

2022-06-09 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

Good finding!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127390

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


[clang] 65b34b7 - [clang][pr55896]:co_yield/co_await thread-safety

2022-06-09 Thread Nathan Sidwell via cfe-commits

Author: Nathan Sidwell
Date: 2022-06-09T04:42:10-07:00
New Revision: 65b34b78f8dafbfd97836af3165e73c5b316c6b5

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

LOG: [clang][pr55896]:co_yield/co_await thread-safety

co_await and co_yield are represented by (classes derived from)
CoroutineSuspendExpr.  That has a number of child nodes, not all of
which are used for code-generation.  In particular the operand is
represented multiple times, and, like the problem with co_return
(55406) it must only be emitted in the CFG exactly once.  The operand
also appears inside OpaqueValueExprs, but that's ok.

This adds a visitor for SuspendExprs to emit the required children in
the correct order.  Note that this CFG is pre-coro xform.  We don't
have initial or final suspend points.

Reviewed By: bruno

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

Added: 


Modified: 
clang/lib/Analysis/CFG.cpp
clang/test/SemaCXX/thread-safety-coro.cpp

Removed: 




diff  --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index 1417b95aad93..8379e108fa27 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -597,6 +597,8 @@ class CFGBuilder {
   CFGBlock *VisitObjCMessageExpr(ObjCMessageExpr *E, AddStmtChoice asc);
   CFGBlock *VisitPseudoObjectExpr(PseudoObjectExpr *E);
   CFGBlock *VisitReturnStmt(Stmt *S);
+  CFGBlock *VisitCoroutineSuspendExpr(CoroutineSuspendExpr *S,
+  AddStmtChoice asc);
   CFGBlock *VisitSEHExceptStmt(SEHExceptStmt *S);
   CFGBlock *VisitSEHFinallyStmt(SEHFinallyStmt *S);
   CFGBlock *VisitSEHLeaveStmt(SEHLeaveStmt *S);
@@ -2297,6 +2299,10 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc,
 case Stmt::CoreturnStmtClass:
   return VisitReturnStmt(S);
 
+case Stmt::CoyieldExprClass:
+case Stmt::CoawaitExprClass:
+  return VisitCoroutineSuspendExpr(cast(S), asc);
+
 case Stmt::SEHExceptStmtClass:
   return VisitSEHExceptStmt(cast(S));
 
@@ -3152,6 +3158,27 @@ CFGBlock *CFGBuilder::VisitReturnStmt(Stmt *S) {
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E,
+AddStmtChoice asc) {
+  // We're modelling the pre-coro-xform CFG. Thus just evalate the various
+  // active components of the co_await or co_yield. Note we do not model the
+  // edge from the builtin_suspend to the exit node.
+  if (asc.alwaysAdd(*this, E)) {
+autoCreateBlock();
+appendStmt(Block, E);
+  }
+  CFGBlock *B = Block;
+  if (auto *R = Visit(E->getResumeExpr()))
+B = R;
+  if (auto *R = Visit(E->getSuspendExpr()))
+B = R;
+  if (auto *R = Visit(E->getReadyExpr()))
+B = R;
+  if (auto *R = Visit(E->getCommonExpr()))
+B = R;
+  return B;
+}
+
 CFGBlock *CFGBuilder::VisitSEHExceptStmt(SEHExceptStmt *ES) {
   // SEHExceptStmt are treated like labels, so they are the first statement in 
a
   // block.

diff  --git a/clang/test/SemaCXX/thread-safety-coro.cpp 
b/clang/test/SemaCXX/thread-safety-coro.cpp
index a500ad5435e4..9d40c3bf492a 100644
--- a/clang/test/SemaCXX/thread-safety-coro.cpp
+++ b/clang/test/SemaCXX/thread-safety-coro.cpp
@@ -38,10 +38,14 @@ class Task {
 Task get_return_object() noexcept;
 void unhandled_exception() noexcept;
 void return_value(int value) noexcept;
+
+std::suspend_always yield_value(int value) noexcept;
   };
 };
 
 Task Foo() noexcept {
   // ICE'd
+  co_yield({ int frame = 0; 0; });
+  co_await({ int frame = 0; std::suspend_always(); });
   co_return({ int frame = 0; 0; });
 }



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


[PATCH] D127236: [clang][pr55896]:co_yield/co_await thread-safety

2022-06-09 Thread Nathan Sidwell via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
urnathan marked an inline comment as done.
Closed by commit rG65b34b78f8da: [clang][pr55896]:co_yield/co_await 
thread-safety (authored by urnathan).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D127236?vs=434887&id=435501#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127236

Files:
  clang/lib/Analysis/CFG.cpp
  clang/test/SemaCXX/thread-safety-coro.cpp


Index: clang/test/SemaCXX/thread-safety-coro.cpp
===
--- clang/test/SemaCXX/thread-safety-coro.cpp
+++ clang/test/SemaCXX/thread-safety-coro.cpp
@@ -38,10 +38,14 @@
 Task get_return_object() noexcept;
 void unhandled_exception() noexcept;
 void return_value(int value) noexcept;
+
+std::suspend_always yield_value(int value) noexcept;
   };
 };
 
 Task Foo() noexcept {
   // ICE'd
+  co_yield({ int frame = 0; 0; });
+  co_await({ int frame = 0; std::suspend_always(); });
   co_return({ int frame = 0; 0; });
 }
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -597,6 +597,8 @@
   CFGBlock *VisitObjCMessageExpr(ObjCMessageExpr *E, AddStmtChoice asc);
   CFGBlock *VisitPseudoObjectExpr(PseudoObjectExpr *E);
   CFGBlock *VisitReturnStmt(Stmt *S);
+  CFGBlock *VisitCoroutineSuspendExpr(CoroutineSuspendExpr *S,
+  AddStmtChoice asc);
   CFGBlock *VisitSEHExceptStmt(SEHExceptStmt *S);
   CFGBlock *VisitSEHFinallyStmt(SEHFinallyStmt *S);
   CFGBlock *VisitSEHLeaveStmt(SEHLeaveStmt *S);
@@ -2297,6 +2299,10 @@
 case Stmt::CoreturnStmtClass:
   return VisitReturnStmt(S);
 
+case Stmt::CoyieldExprClass:
+case Stmt::CoawaitExprClass:
+  return VisitCoroutineSuspendExpr(cast(S), asc);
+
 case Stmt::SEHExceptStmtClass:
   return VisitSEHExceptStmt(cast(S));
 
@@ -3152,6 +3158,27 @@
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E,
+AddStmtChoice asc) {
+  // We're modelling the pre-coro-xform CFG. Thus just evalate the various
+  // active components of the co_await or co_yield. Note we do not model the
+  // edge from the builtin_suspend to the exit node.
+  if (asc.alwaysAdd(*this, E)) {
+autoCreateBlock();
+appendStmt(Block, E);
+  }
+  CFGBlock *B = Block;
+  if (auto *R = Visit(E->getResumeExpr()))
+B = R;
+  if (auto *R = Visit(E->getSuspendExpr()))
+B = R;
+  if (auto *R = Visit(E->getReadyExpr()))
+B = R;
+  if (auto *R = Visit(E->getCommonExpr()))
+B = R;
+  return B;
+}
+
 CFGBlock *CFGBuilder::VisitSEHExceptStmt(SEHExceptStmt *ES) {
   // SEHExceptStmt are treated like labels, so they are the first statement in 
a
   // block.


Index: clang/test/SemaCXX/thread-safety-coro.cpp
===
--- clang/test/SemaCXX/thread-safety-coro.cpp
+++ clang/test/SemaCXX/thread-safety-coro.cpp
@@ -38,10 +38,14 @@
 Task get_return_object() noexcept;
 void unhandled_exception() noexcept;
 void return_value(int value) noexcept;
+
+std::suspend_always yield_value(int value) noexcept;
   };
 };
 
 Task Foo() noexcept {
   // ICE'd
+  co_yield({ int frame = 0; 0; });
+  co_await({ int frame = 0; std::suspend_always(); });
   co_return({ int frame = 0; 0; });
 }
Index: clang/lib/Analysis/CFG.cpp
===
--- clang/lib/Analysis/CFG.cpp
+++ clang/lib/Analysis/CFG.cpp
@@ -597,6 +597,8 @@
   CFGBlock *VisitObjCMessageExpr(ObjCMessageExpr *E, AddStmtChoice asc);
   CFGBlock *VisitPseudoObjectExpr(PseudoObjectExpr *E);
   CFGBlock *VisitReturnStmt(Stmt *S);
+  CFGBlock *VisitCoroutineSuspendExpr(CoroutineSuspendExpr *S,
+  AddStmtChoice asc);
   CFGBlock *VisitSEHExceptStmt(SEHExceptStmt *S);
   CFGBlock *VisitSEHFinallyStmt(SEHFinallyStmt *S);
   CFGBlock *VisitSEHLeaveStmt(SEHLeaveStmt *S);
@@ -2297,6 +2299,10 @@
 case Stmt::CoreturnStmtClass:
   return VisitReturnStmt(S);
 
+case Stmt::CoyieldExprClass:
+case Stmt::CoawaitExprClass:
+  return VisitCoroutineSuspendExpr(cast(S), asc);
+
 case Stmt::SEHExceptStmtClass:
   return VisitSEHExceptStmt(cast(S));
 
@@ -3152,6 +3158,27 @@
   return B;
 }
 
+CFGBlock *CFGBuilder::VisitCoroutineSuspendExpr(CoroutineSuspendExpr *E,
+AddStmtChoice asc) {
+  // We're modelling the pre-coro-xform CFG. Thus just evalate the various
+  // active components of the co_await or co_yield. Note we do not model the
+  // edge from the builtin_suspend to the exit node.
+  if (asc.alwaysAdd(*this, E)) {
+autoCr

[PATCH] D126536: [pseudo] Add grammar annotations support.

2022-06-09 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added inline comments.



Comment at: clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp:235
 
   Out.Sequence.push_back({Chunk});
 }

I get a warning/error on this line with this commit:
```
13:31:17 ../../clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp:235:36: 
error: missing field 'Attributes' initializer 
[-Werror,-Wmissing-field-initializers]
13:31:17   Out.Sequence.push_back({Chunk});
13:31:17^
13:31:17 1 error generated.
```
I see the warning when compiling with clang 8.0.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126536

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


[PATCH] D127396: [clang][ASTImporter] Fix import of function with auto return type.

2022-06-09 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, martong, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fix a case of importing a function with auto return type
that is resolved with a type template argument that is declared
inside the function.
This is a fix for issue #55500 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127396

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -6319,6 +6319,61 @@
 
 struct ImportAutoFunctions : ASTImporterOptionSpecificTestBase {};
 
+TEST_P(ImportAutoFunctions, ReturnWithTemplateWithStructDeclaredInside1) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template struct Tmpl {};
+  auto foo() {
+struct X {};
+return Tmpl();
+  }
+  )",
+  Lang_CXX14, "input0.cc");
+  FunctionDecl *From = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("foo")));
+
+  FunctionDecl *To = Import(From, Lang_CXX14);
+  EXPECT_TRUE(To);
+  EXPECT_TRUE(isa(To->getReturnType()));
+}
+
+TEST_P(ImportAutoFunctions, ReturnWithTemplateWithStructDeclaredInside2) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template struct Tmpl {};
+  auto foo() {
+struct X {};
+return Tmpl>();
+  }
+  )",
+  Lang_CXX14, "input0.cc");
+  FunctionDecl *From = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("foo")));
+
+  FunctionDecl *To = Import(From, Lang_CXX14);
+  EXPECT_TRUE(To);
+  EXPECT_TRUE(isa(To->getReturnType()));
+}
+
+TEST_P(ImportAutoFunctions, ReturnWithTemplateWithTypedefDeclaredInside) {
+  Decl *FromTU = getTuDecl(
+  R"(
+  template struct Tmpl {};
+  auto foo() {
+struct X {};
+using x_type = X;
+return Tmpl();
+  }
+  )",
+  Lang_CXX14, "input0.cc");
+  FunctionDecl *From = FirstDeclMatcher().match(
+  FromTU, functionDecl(hasName("foo")));
+
+  FunctionDecl *To = Import(From, Lang_CXX14);
+  EXPECT_TRUE(To);
+  EXPECT_TRUE(isa(To->getReturnType()));
+}
+
 TEST_P(ImportAutoFunctions, ReturnWithTypedefDeclaredInside) {
   Decl *FromTU = getTuDecl(
   R"(
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -3227,23 +3227,32 @@
   return false;
 }
 
+static bool hasTypeDeclaredInsideFunction(QualType T, const FunctionDecl *FD) {
+  if (T.isNull())
+return false;
+  if (const auto *RecordT = T->getAs()) {
+const RecordDecl *RD = RecordT->getDecl();
+assert(RD);
+if (isAncestorDeclContextOf(FD, RD)) {
+  assert(RD->getLexicalDeclContext() == RD->getDeclContext());
+  return true;
+}
+if (const auto *RDTempl = dyn_cast(RD))
+  return llvm::count_if(RDTempl->getTemplateArgs().asArray(),
+[FD](const TemplateArgument &Arg) {
+  return hasTypeDeclaredInsideFunction(
+  Arg.getAsType(), FD);
+});
+  }
+  return false;
+}
+
 bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) {
   QualType FromTy = D->getType();
   const auto *FromFPT = FromTy->getAs();
   assert(FromFPT && "Must be called on FunctionProtoType");
-  if (const AutoType *AutoT =
-  FromFPT->getReturnType()->getContainedAutoType()) {
-QualType DeducedT = AutoT->getDeducedType();
-if (const auto *RecordT =
-!DeducedT.isNull() ? DeducedT->getAs() : nullptr) {
-  const RecordDecl *RD = RecordT->getDecl();
-  assert(RD);
-  if (isAncestorDeclContextOf(D, RD)) {
-assert(RD->getLexicalDeclContext() == RD->getDeclContext());
-return true;
-  }
-}
-  }
+  if (const AutoType *AutoT = FromFPT->getReturnType()->getContainedAutoType())
+return hasTypeDeclaredInsideFunction(AutoT->getDeducedType(), D);
   if (const auto *TypedefT = FromFPT->getReturnType()->getAs()) {
 const TypedefNameDecl *TD = TypedefT->getDecl();
 assert(TD);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127397: [pseudo] Fix unit test build

2022-06-09 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler created this revision.
ckandeler added a reviewer: hokein.
Herald added a subscriber: mgorny.
Herald added a project: All.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, alextsao1999.
Herald added a project: clang-tools-extra.

Analogous to 632545e8ce846ccaeca8df15a3dc5e36d01a1275 
.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127397

Files:
  clang-tools-extra/pseudo/unittests/CMakeLists.txt


Index: clang-tools-extra/pseudo/unittests/CMakeLists.txt
===
--- clang-tools-extra/pseudo/unittests/CMakeLists.txt
+++ clang-tools-extra/pseudo/unittests/CMakeLists.txt
@@ -1,6 +1,5 @@
 set(LLVM_LINK_COMPONENTS
   Support
-  TestingSupport
   )
 
 add_custom_target(ClangPseudoUnitTests)
@@ -24,4 +23,5 @@
   PRIVATE
   clangPseudo
   clangPseudoGrammar
+  LLVMTestingSupport
   )


Index: clang-tools-extra/pseudo/unittests/CMakeLists.txt
===
--- clang-tools-extra/pseudo/unittests/CMakeLists.txt
+++ clang-tools-extra/pseudo/unittests/CMakeLists.txt
@@ -1,6 +1,5 @@
 set(LLVM_LINK_COMPONENTS
   Support
-  TestingSupport
   )
 
 add_custom_target(ClangPseudoUnitTests)
@@ -24,4 +23,5 @@
   PRIVATE
   clangPseudo
   clangPseudoGrammar
+  LLVMTestingSupport
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D126495: [clang-tidy] Organize test docs into subdirectories by module (NFC)

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

In D126495#3569029 , @njames93 wrote:

> In D126495#3568998 , 
> @LegalizeAdulthood wrote:
>
>> Gentle ping
>
> My previous point about the links in the header files not being updated 
> hasn't been addressed.

Ah yes, I got distracted and forgot about that.  I will update the diff.

> It would also be nice if there was a redirect that would dynamically 
> translate the old links to new links.

You can do that with `.htaccess`, but I don't know if that's considered 
acceptable in clang documentation.

Leaving `.rst` pages in place for all the old locations just recreates the 
clutter instead of getting rid of it.


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

https://reviews.llvm.org/D126495

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


[PATCH] D118711: [hack] Build a tree of preprocessing directives

2022-06-09 Thread Richard via Phabricator via cfe-commits
LegalizeAdulthood added a comment.
Herald added a project: All.

I'm discarding this review, as it was just for comment purposes, until I have a 
proper implementation to discuss.


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

https://reviews.llvm.org/D118711

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


[PATCH] D32199: [TySan] A Type Sanitizer (Clang)

2022-06-09 Thread Florian Hahn via Phabricator via cfe-commits
fhahn updated this revision to Diff 435508.
fhahn added a comment.

Add TySan library when building on Darwin.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D32199

Files:
  clang/include/clang/Basic/Features.def
  clang/include/clang/Basic/Sanitizers.def
  clang/include/clang/Driver/SanitizerArgs.h
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenTBAA.cpp
  clang/lib/CodeGen/SanitizerMetadata.cpp
  clang/lib/CodeGen/SanitizerMetadata.h
  clang/lib/Driver/SanitizerArgs.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Driver/ToolChains/Linux.cpp
  clang/test/CodeGen/sanitize-type-attr.cpp
  clang/test/Driver/sanitizer-ld.c

Index: clang/test/Driver/sanitizer-ld.c
===
--- clang/test/Driver/sanitizer-ld.c
+++ clang/test/Driver/sanitizer-ld.c
@@ -261,6 +261,28 @@
 // CHECK-ASAN-MYRIAD-NOT: "-lc"
 // CHECK-ASAN-MYRIAD: libclang_rt.asan-sparcel.a"
 
+// RUN: %clangxx %s -### -o %t.o 2>&1 \
+// RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
+// RUN: -fsanitize=type \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TYSAN-LINUX-CXX %s
+//
+// CHECK-TYSAN-LINUX-CXX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-TYSAN-LINUX-CXX-NOT: stdc++
+// CHECK-TYSAN-LINUX-CXX: "--whole-archive" "{{.*}}libclang_rt.tysan{{[^.]*}}.a" "--no-whole-archive"
+// CHECK-TYSAN-LINUX-CXX: stdc++
+
+// RUN: %clangxx -fsanitize=type -### %s 2>&1 \
+// RUN: -mmacosx-version-min=10.6 \
+// RUN: --target=x86_64-apple-darwin13.4.0 -fuse-ld=ld -stdlib=platform \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-TYSAN-DARWIN-CXX %s
+// CHECK-TYSAN-DARWIN-CXX: "{{.*}}ld{{(.exe)?}}"
+// CHECK-TYSAN-DARWIN-CXX: libclang_rt.tysan_osx_dynamic.dylib
+// CHECK-TYSAN-DARWIN-CXX-NOT: -lc++abi
+
 // RUN: %clangxx -### %s 2>&1 \
 // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \
 // RUN: -fsanitize=thread \
Index: clang/test/CodeGen/sanitize-type-attr.cpp
===
--- /dev/null
+++ clang/test/CodeGen/sanitize-type-attr.cpp
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type | FileCheck -check-prefix=TYSAN %s
+// RUN: echo "src:%s" | sed -e 's/\\//g' > %t
+// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm -o - %s -fsanitize=type -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %s
+
+// The sanitize_type attribute should be attached to functions
+// when TypeSanitizer is enabled, unless no_sanitize("type") attribute
+// is present.
+
+// WITHOUT:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN1{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type"))) int NoTYSAN1(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN2{{.*}}) [[NOATTR]]
+// BL:  NoTYSAN2{{.*}}) [[NOATTR]]
+// TYSAN:  NoTYSAN2{{.*}}) [[NOATTR]]
+__attribute__((no_sanitize("type"))) int NoTYSAN2(int *a);
+int NoTYSAN2(int *a) { return *a; }
+
+// WITHOUT:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// BL:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+// TYSAN:  NoTYSAN3{{.*}}) [[NOATTR:#[0-9]+]]
+__attribute__((no_sanitize("type"))) int NoTYSAN3(int *a) { return *a; }
+
+// WITHOUT:  TYSANOk{{.*}}) [[NOATTR]]
+// BL:  TYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TYSANOk{{.*}}) [[WITH:#[0-9]+]]
+int TYSANOk(int *a) { return *a; }
+
+// WITHOUT:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// BL:  TemplateTYSANOk{{.*}}) [[NOATTR]]
+// TYSAN: TemplateTYSANOk{{.*}}) [[WITH]]
+template 
+int TemplateTYSANOk() { return i; }
+
+// WITHOUT:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// BL:  TemplateNoTYSAN{{.*}}) [[NOATTR]]
+// TYSAN: TemplateNoTYSAN{{.*}}) [[NOATTR]]
+template 
+__attribute__((no_sanitize("type"))) int TemplateNoTYSAN() { return i; }
+
+int force_instance = TemplateTYSANOk<42>() + TemplateNoTYSAN<42>();
+
+// Check that __cxx_global_var_init* get the sanitize_type attribute.
+int global1 = 0;
+int global2 = *(int *)((char *)&global1 + 1);
+// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// BL: @__cxx_global_var_init{{.*}}[[NOATTR:#[0-9]+]]
+// TYSAN: @__cxx_global_var_init{{.*}}[[WITH:#[0-9]+]]
+
+// Make sure that we don't add globals to the list for which we don't have a
+// specific type description.
+struct SX {
+  int a, b;
+};
+SX sx;
+
+// WITHOUT: attributes [[NOATTR]] = { noinline nounwind{{.*}} }
+
+// BL: att

[PATCH] D125788: [flang][driver] Rename `flang-new` as `flang`

2022-06-09 Thread Andrzej Warzynski via Phabricator via cfe-commits
awarzynski added a comment.

In the call yesterday it was proposed that we add a CMake option that will 
control the name of the driver. I suggest adding `FLANG_USE_LEGACY_NAME`:

- when set to `ON`, the driver binary will be called `flang-new`,
- when set to `OFF`, the driver binary will be called `flang`.

With this approach, everyone will be able to select the preferred driver name. 
Note that:

- this will affect both the build and installation targets,
- LLVM's testing infrastructure will automatically choose between `flang` and 
`flang-new` (based on `FLANG_USE_LEGACY_NAME`),
- you won't be required to perform any extra steps (in fact, you will be able 
to continue with your current workflows).

It was requested that the default value is set to `ON` (i.e. the default name 
for the driver executable in LLVM Flang will remain `flang-new`).

Later today I will upload a new version of this patch that implements the 
above. As for changing the default to `flang` (i.e. setting the default for 
`FLANG_USE_LEGACY_NAME` to `OFF`), the following remains a blocker:

In D125788#3535199 , @sscalpone wrote:

> My proposal is:
>
> If the compiler compiles it, it ought to run.
> If the compiler can't compile it, it ought to clearly say why.
>
> 1. All tests of legal Fortran that compile & link must also execute correctly 
> (which excludes tests that expect to catch a problem at runtime)
> 2. For all tests with unsupported features, the compiler must issues an error 
> message and the message references the source-location of the unsupported 
> feature
>
> My preference is to use the NAG test suite.   It is not freely available.

We did discuss replacing NAG with e.g. SNAP + SPEC, but we run out of time and 
haven't concluded that part.

As always, please comment if I missed or misread anything!

**Next steps**
I will update this patch by introducing `FLANG_USE_LEGACY_NAME` CMake option - 
it will control the name of the generated driver executable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125788

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


[PATCH] D127388: [pseudo] Move grammar-related headers to a separate dir, NFC.

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



Comment at: clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h:52
 
 #ifndef CLANG_PSEUDO_GRAMMAR_H
 #define CLANG_PSEUDO_GRAMMAR_H

header guards should really be updated :-(


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127388

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


[clang-tools-extra] 9ce232f - [pseudo] Fix the missing-field-initializers warning from f1ac00c9b0d1, NFC

2022-06-09 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-09T14:10:36+02:00
New Revision: 9ce232fba99c47c3246f06fcbe37c24b9d90585f

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

LOG: [pseudo] Fix the missing-field-initializers warning from f1ac00c9b0d1, NFC

Added: 


Modified: 
clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp

Removed: 




diff  --git a/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp 
b/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
index 82daf47af610..91e0d3956518 100644
--- a/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
+++ b/clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
@@ -232,7 +232,7 @@ class GrammarBuilder {
 continue;
   }
 
-  Out.Sequence.push_back({Chunk});
+  Out.Sequence.push_back({Chunk, /*Attributes=*/{}});
 }
 return true;
   }



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


[PATCH] D126536: [pseudo] Add grammar annotations support.

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



Comment at: clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp:235
 
   Out.Sequence.push_back({Chunk});
 }

uabelho wrote:
> I get a warning/error on this line with this commit:
> ```
> 13:31:17 ../../clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp:235:36: 
> error: missing field 'Attributes' initializer 
> [-Werror,-Wmissing-field-initializers]
> 13:31:17   Out.Sequence.push_back({Chunk});
> 13:31:17^
> 13:31:17 1 error generated.
> ```
> I see the warning when compiling with clang 8.0.
sorry (I don't this warning enabled), should be fixed in 
9ce232fba99c47c3246f06fcbe37c24b9d90585f.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126536

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


[PATCH] D127400: [pseudo] Add xfail tests for a simple-declaration/function-definition ambiguity

2022-06-09 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.

I expect to eliminate this ambiguity at the grammar level by use of guards,
because it interferes with brace-based error recvoery.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127400

Files:
  clang-tools-extra/pseudo/test/cxx/declarator-function.cpp
  clang-tools-extra/pseudo/test/cxx/declarator-var.cpp


Index: clang-tools-extra/pseudo/test/cxx/declarator-var.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/declarator-var.cpp
@@ -0,0 +1,12 @@
+// The standard grammar allows an function-body to use any declarator, 
including
+// a non-function declarator. This creates an ambiguity where a
+// simple-declaration is misparsed as a function-definition.
+// FIXME: eliminate this false parse.
+// XFAIL: *
+
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest |
+// FileCheck %s
+void (*s)(){};
+// CHECK-NOT:  function-definition
+// CHECK:  init-declarator := declarator initializer
+// CHECK-NOT:  function-definition
Index: clang-tools-extra/pseudo/test/cxx/declarator-function.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/declarator-function.cpp
@@ -0,0 +1,12 @@
+// The standard grammar allows an init-list with any declarator, including
+// a function declarator. This creates an ambiguity where a function-definition
+// is misparsed as a simple-declaration.
+// FIXME: eliminate this false parse.
+// XFAIL: *
+
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest |
+// FileCheck %s
+void s(){};
+// CHECK-NOT:  simple-declaration
+// CHECK:  function-definition := decl-specifier-seq declarator
+// function-body CHECK-NOT:  simple-declaration


Index: clang-tools-extra/pseudo/test/cxx/declarator-var.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/declarator-var.cpp
@@ -0,0 +1,12 @@
+// The standard grammar allows an function-body to use any declarator, including
+// a non-function declarator. This creates an ambiguity where a
+// simple-declaration is misparsed as a function-definition.
+// FIXME: eliminate this false parse.
+// XFAIL: *
+
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest |
+// FileCheck %s
+void (*s)(){};
+// CHECK-NOT:  function-definition
+// CHECK:  init-declarator := declarator initializer
+// CHECK-NOT:  function-definition
Index: clang-tools-extra/pseudo/test/cxx/declarator-function.cpp
===
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/declarator-function.cpp
@@ -0,0 +1,12 @@
+// The standard grammar allows an init-list with any declarator, including
+// a function declarator. This creates an ambiguity where a function-definition
+// is misparsed as a simple-declaration.
+// FIXME: eliminate this false parse.
+// XFAIL: *
+
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest |
+// FileCheck %s
+void s(){};
+// CHECK-NOT:  simple-declaration
+// CHECK:  function-definition := decl-specifier-seq declarator
+// function-body CHECK-NOT:  simple-declaration
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 18f0b70 - [pseudo] Don't clang-format test inputs. NFC

2022-06-09 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-06-09T14:18:30+02:00
New Revision: 18f0b7092db5b8554415e872d02c4628a5ae7296

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

LOG: [pseudo] Don't clang-format test inputs. NFC

Added: 
clang-tools-extra/pseudo/test/.clang-format

Modified: 


Removed: 




diff  --git a/clang-tools-extra/pseudo/test/.clang-format 
b/clang-tools-extra/pseudo/test/.clang-format
new file mode 100644
index ..e3845288a2ae
--- /dev/null
+++ b/clang-tools-extra/pseudo/test/.clang-format
@@ -0,0 +1 @@
+DisableFormat: true



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


[PATCH] D127397: [pseudo] Fix unit test build

2022-06-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127397

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


[PATCH] D127397: [pseudo] Fix unit test build

2022-06-09 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler added a comment.

Can you please merge it? I don't have the rights.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127397

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


[PATCH] D125919: Drop qualifiers from return types in C (DR423)

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

In D125919#3560523 , @aaron.ballman 
wrote:

> All that said, I think you can see why I'm hoping to get an answer from WG14 
> as to what to do. Reasonable folks are disagreeing on what the standard 
> requires here.

The discussion on the WG14 reflector seems to be settling down to a consensus 
position that the `_Atomic` qualifier is only syntactically a qualifier and its 
use designates an entirely new type. When the standard says "unqualified type", 
the `_Atomic` is not considered a qualification. So we should *not* be 
stripping the `_Atomic` as I was doing in this patch. (SC22WG14.22200 has most 
of the details spelled out nicely, if you have access to the reflectors.)

I had asked other questions in related areas that also got answers.

`const void func(volatile void);` -- the return type is adjusted to `void`; the 
parameter type is UB (by lack of specification) and we can do what we want 
here. We currently diagnose the parameter as being invalid: 
https://godbolt.org/z/9c8bTrerY. Our behavior with the parameter is consistent 
with GCC and EDG.

`const int main(void)` -- this is valid and equivalent to `int main(void)`, so 
it should be accepted; we currently reject: https://godbolt.org/z/v43h596ev

`const int func(void); int func(void) { }` -- this is DR423. It is valid, the 
composite type is `int(void)`; we give a conflicting types error: 
https://godbolt.org/z/Yb841r7Ex


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125919

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


[PATCH] D126536: [pseudo] Add grammar annotations support.

2022-06-09 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added inline comments.



Comment at: clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp:235
 
   Out.Sequence.push_back({Chunk});
 }

hokein wrote:
> uabelho wrote:
> > I get a warning/error on this line with this commit:
> > ```
> > 13:31:17 ../../clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp:235:36: 
> > error: missing field 'Attributes' initializer 
> > [-Werror,-Wmissing-field-initializers]
> > 13:31:17   Out.Sequence.push_back({Chunk});
> > 13:31:17^
> > 13:31:17 1 error generated.
> > ```
> > I see the warning when compiling with clang 8.0.
> sorry (I don't this warning enabled), should be fixed in 
> 9ce232fba99c47c3246f06fcbe37c24b9d90585f.
Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126536

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


[clang-tools-extra] bf83062 - [pseudo] Fix unit test build

2022-06-09 Thread Haojian Wu via cfe-commits

Author: Christian Kandeler
Date: 2022-06-09T14:42:47+02:00
New Revision: bf830623b063af1c620f369b6bf1808c30d5f0fb

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

LOG: [pseudo] Fix unit test build

Analogous to 632545e8ce846ccaeca8df15a3dc5e36d01a1275.

Reviewed By: hokein

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

Added: 


Modified: 
clang-tools-extra/pseudo/unittests/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/pseudo/unittests/CMakeLists.txt 
b/clang-tools-extra/pseudo/unittests/CMakeLists.txt
index 2185e4e4c146b..70796195d9bed 100644
--- a/clang-tools-extra/pseudo/unittests/CMakeLists.txt
+++ b/clang-tools-extra/pseudo/unittests/CMakeLists.txt
@@ -1,6 +1,5 @@
 set(LLVM_LINK_COMPONENTS
   Support
-  TestingSupport
   )
 
 add_custom_target(ClangPseudoUnitTests)
@@ -24,4 +23,5 @@ target_link_libraries(ClangPseudoTests
   PRIVATE
   clangPseudo
   clangPseudoGrammar
+  LLVMTestingSupport
   )



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


[PATCH] D127397: [pseudo] Fix unit test build

2022-06-09 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGbf830623b063: [pseudo] Fix unit test build (authored by 
ckandeler, committed by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127397

Files:
  clang-tools-extra/pseudo/unittests/CMakeLists.txt


Index: clang-tools-extra/pseudo/unittests/CMakeLists.txt
===
--- clang-tools-extra/pseudo/unittests/CMakeLists.txt
+++ clang-tools-extra/pseudo/unittests/CMakeLists.txt
@@ -1,6 +1,5 @@
 set(LLVM_LINK_COMPONENTS
   Support
-  TestingSupport
   )
 
 add_custom_target(ClangPseudoUnitTests)
@@ -24,4 +23,5 @@
   PRIVATE
   clangPseudo
   clangPseudoGrammar
+  LLVMTestingSupport
   )


Index: clang-tools-extra/pseudo/unittests/CMakeLists.txt
===
--- clang-tools-extra/pseudo/unittests/CMakeLists.txt
+++ clang-tools-extra/pseudo/unittests/CMakeLists.txt
@@ -1,6 +1,5 @@
 set(LLVM_LINK_COMPONENTS
   Support
-  TestingSupport
   )
 
 add_custom_target(ClangPseudoUnitTests)
@@ -24,4 +23,5 @@
   PRIVATE
   clangPseudo
   clangPseudoGrammar
+  LLVMTestingSupport
   )
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D127397: [pseudo] Fix unit test build

2022-06-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In D127397#3569925 , @ckandeler wrote:

> Can you please merge it? I don't have the rights.

sure, committed in bf830623b063af1c620f369b6bf1808c30d5f0fb 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127397

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


[PATCH] D127396: [clang][ASTImporter] Fix import of function with auto return type.

2022-06-09 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: rnkovacs.

Thanks, nice work!

> This is a fix for issue #55500 .

I think github will NOT automatically close the issue, unless you have a more 
specific format in the commit message. E.g. "Fixes #555000". See the docs here: 
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue




Comment at: clang/lib/AST/ASTImporter.cpp:3250
+
 bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside(FunctionDecl *D) {
   QualType FromTy = D->getType();

It's a good idea to extend this function!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127396

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


[PATCH] D127400: [pseudo] Add xfail tests for a simple-declaration/function-definition ambiguity

2022-06-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added inline comments.
This revision is now accepted and ready to land.



Comment at: clang-tools-extra/pseudo/test/cxx/declarator-function.cpp:12
+// CHECK:  function-definition := decl-specifier-seq declarator
+// function-body CHECK-NOT:  simple-declaration

nit: the line seems to be broken by the clang-format.



Comment at: clang-tools-extra/pseudo/test/cxx/declarator-var.cpp:10
+void (*s)(){};
+// CHECK-NOT:  function-definition
+// CHECK:  init-declarator := declarator initializer

why we need two lines for `function-definition`?
because of the undeterministic order of the ambiguous results (we don't know 
whether function-def comes first or the var-decl comes first)? 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127400

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


[clang] 8e1a29e - Use HTTPS links instead of HTTP ones in the C DR status page

2022-06-09 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-06-09T08:52:30-04:00
New Revision: 8e1a29ecab4e35de72232fc9fd9706ed1cc64f9b

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

LOG: Use HTTPS links instead of HTTP ones in the C DR status page

Added: 


Modified: 
clang/www/c_dr_status.html

Removed: 




diff  --git a/clang/www/c_dr_status.html b/clang/www/c_dr_status.html
index ff3387b7caf7e..75709d418a837 100644
--- a/clang/www/c_dr_status.html
+++ b/clang/www/c_dr_status.html
@@ -1,5 +1,5 @@
 http://www.w3.org/TR/html4/strict.dtd";>
+  "https://www.w3.org/TR/html4/strict.dtd";>
 
 
   
@@ -49,211 +49,211 @@ C defect report implementation status
 Available in Clang?
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_001.html";>1
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_001.html";>1
 C89
 Do functions return values by copying?
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_002.html";>2
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_002.html";>2
 NAD
 Subclause 6.8.3.2: Semantics of #
 Unknown
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_003.html";>3
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_003.html";>3
 NAD
 Subclause 6.1.8: Preprocessing numbers
 Unknown
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_004.html";>4
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_004.html";>4
 NAD
 Are multiple definitions of unused identifiers with external linkage 
permitted?
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_005.html";>5
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_005.html";>5
 NAD
 May a conforming implementation define and recognize a pragma which 
would change the semantics of the language?
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_006.html";>6
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_006.html";>6
 C89
 It is unclear how the strtoul function behaves when presented with a 
subject sequence that begins with a minus sign
 N/A
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_007.html";>7
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_007.html";>7
 NAD
 Are declarations of the form struct-or-union identifier ; permitted 
after the identifier tag has already been declared?
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_008.html";>8
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_008.html";>8
 NAD
 Can a conforming C compiler to perform dead-store elimination?
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_009.html";>9
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_009.html";>9
 C89
 Use of typedef names in parameter declarations
 No
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_010.html";>10
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_010.html";>10
 NAD
 Is a typedef to an incomplete type legal?
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_011.html";>11
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_011.html";>11
 C89
 Merging of declarations for linked identifier
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_012.html";>12
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_012.html";>12
 NAD
 Is it valid to take the address of a dereferenced void pointer?
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_013.html";>13
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_013.html";>13
 C89
 Compatible and composite function types
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_014.html";>14
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_014.html";>14
 C89
 Issues with setjmp and fscanf descriptions
 N/A
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_015.html";>15
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_015.html";>15
 NAD
 What is the promoted type of a plain int bit-field?
 Yes
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_016.html";>16
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_016.html";>16
 C89
 What does static storage duration do when zero for the type is not all 
zero bits?
 Unknown
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_017.html";>17
+https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_017.html";>17
 C89
 39 unrelated questions about C89
 Unknown
   
   
-http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_018.html";>18
+https://www.open-std.org/jtc1/sc2

[PATCH] D127388: [pseudo] Move grammar-related headers to a separate dir, NFC.

2022-06-09 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 435516.
hokein added a comment.

update header guards.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127388

Files:
  clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
  clang-tools-extra/pseudo/gen/Main.cpp
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
  clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
  clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h
  clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
  clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRGraph.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
  clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
  clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp
  clang-tools-extra/pseudo/unittests/GrammarTest.cpp
  clang-tools-extra/pseudo/unittests/LRTableTest.cpp

Index: clang-tools-extra/pseudo/unittests/LRTableTest.cpp
===
--- clang-tools-extra/pseudo/unittests/LRTableTest.cpp
+++ clang-tools-extra/pseudo/unittests/LRTableTest.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#include "clang-pseudo/LRTable.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "clang/Basic/TokenKinds.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
Index: clang-tools-extra/pseudo/unittests/GrammarTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GrammarTest.cpp
+++ clang-tools-extra/pseudo/unittests/GrammarTest.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -7,7 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/GLR.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "clang-pseudo/Token.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/TokenKinds.h"
Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -9,10 +9,10 @@
 #include "clang-pseudo/Bracket.h"
 #include "clang-pseudo/DirectiveTree.h"
 #include "clang-pseudo/GLR.h"
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRGraph.h"
-#include "clang-pseudo/LRTable.h"
 #include "clang-pseudo/Token.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRGraph.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
Index: clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
+++ clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
@@ -6,9 +6,9 @@
 //
 //===--===//
 
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRGraph.h"
-#include "clang-pseudo/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRGraph.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "clang/Basic/TokenKinds.h"
 #include 
 
Index: clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
+++ clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#include "clang-pseudo/LRTable.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/ErrorHandling.h"
Index: clang-tools-ex

[PATCH] D127388: [pseudo] Move grammar-related headers to a separate dir, NFC.

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



Comment at: clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h:52
 
 #ifndef CLANG_PSEUDO_GRAMMAR_H
 #define CLANG_PSEUDO_GRAMMAR_H

sammccall wrote:
> header guards should really be updated :-(
oops, forgot these. Updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127388

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


[clang-tools-extra] c70aeaa - [pseudo] Move grammar-related headers to a separate dir, NFC.

2022-06-09 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-06-09T14:58:05+02:00
New Revision: c70aeaad2b23b0b30baf6e4580a1995547f9ba41

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

LOG: [pseudo] Move grammar-related headers to a separate dir, NFC.

We did that for .cpp, but forgot the headers.

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

Added: 
clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRGraph.h
clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h

Modified: 
clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
clang-tools-extra/pseudo/gen/Main.cpp
clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
clang-tools-extra/pseudo/lib/GLR.cpp
clang-tools-extra/pseudo/lib/cxx/CXX.cpp
clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
clang-tools-extra/pseudo/tool/ClangPseudo.cpp
clang-tools-extra/pseudo/unittests/GLRTest.cpp
clang-tools-extra/pseudo/unittests/GrammarTest.cpp
clang-tools-extra/pseudo/unittests/LRTableTest.cpp

Removed: 
clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h
clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h



diff  --git a/clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp 
b/clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
index 7b59eec30dbdf..58367837813ff 100644
--- a/clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
+++ b/clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
@@ -9,9 +9,9 @@
 #include "clang-pseudo/DirectiveTree.h"
 #include "clang-pseudo/Forest.h"
 #include "clang-pseudo/GLR.h"
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRTable.h"
 #include "clang-pseudo/Token.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/MemoryBuffer.h"

diff  --git a/clang-tools-extra/pseudo/gen/Main.cpp 
b/clang-tools-extra/pseudo/gen/Main.cpp
index 47ba7f2e71b54..38cb7f48e2b66 100644
--- a/clang-tools-extra/pseudo/gen/Main.cpp
+++ b/clang-tools-extra/pseudo/gen/Main.cpp
@@ -12,7 +12,7 @@
 //
 
//===--===//
 
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"

diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
index c699c4c217dff..29bcac98a64f8 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
@@ -20,8 +20,8 @@
 #ifndef CLANG_PSEUDO_FOREST_H
 #define CLANG_PSEUDO_FOREST_H
 
-#include "clang-pseudo/Grammar.h"
 #include "clang-pseudo/Token.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Allocator.h"

diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
index fc5ebeda1f279..8783872fa3556 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
@@ -30,8 +30,8 @@
 #define CLANG_PSEUDO_GLR_H
 
 #include "clang-pseudo/Forest.h"
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "llvm/Support/Allocator.h"
 #include 
 

diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
index edeeb636d83ed..4acad01588124 100644
--- a/clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
+++ b/clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
@@ -23,7 +23,7 @@
 #ifndef CLANG_PSEUDO_CXX_CXX_H
 #define CLANG_PSEUDO_CXX_CXX_H
 
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 
 namespace clang {
 namespace pseudo {

diff  --git a/clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h 
b/clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
similarity index 98%
rename from clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
rename to clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
index fff96e9771c8a..8137734bd74fb 100644
--- a/clang-to

[PATCH] D127388: [pseudo] Move grammar-related headers to a separate dir, NFC.

2022-06-09 Thread Haojian Wu 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 rGc70aeaad2b23: [pseudo] Move grammar-related headers to a 
separate dir, NFC. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127388

Files:
  clang-tools-extra/pseudo/fuzzer/Fuzzer.cpp
  clang-tools-extra/pseudo/gen/Main.cpp
  clang-tools-extra/pseudo/include/clang-pseudo/Forest.h
  clang-tools-extra/pseudo/include/clang-pseudo/GLR.h
  clang-tools-extra/pseudo/include/clang-pseudo/Grammar.h
  clang-tools-extra/pseudo/include/clang-pseudo/LRGraph.h
  clang-tools-extra/pseudo/include/clang-pseudo/LRTable.h
  clang-tools-extra/pseudo/include/clang-pseudo/cxx/CXX.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/Grammar.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRGraph.h
  clang-tools-extra/pseudo/include/clang-pseudo/grammar/LRTable.h
  clang-tools-extra/pseudo/lib/GLR.cpp
  clang-tools-extra/pseudo/lib/cxx/CXX.cpp
  clang-tools-extra/pseudo/lib/grammar/Grammar.cpp
  clang-tools-extra/pseudo/lib/grammar/GrammarBNF.cpp
  clang-tools-extra/pseudo/lib/grammar/LRGraph.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
  clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
  clang-tools-extra/pseudo/tool/ClangPseudo.cpp
  clang-tools-extra/pseudo/unittests/GLRTest.cpp
  clang-tools-extra/pseudo/unittests/GrammarTest.cpp
  clang-tools-extra/pseudo/unittests/LRTableTest.cpp

Index: clang-tools-extra/pseudo/unittests/LRTableTest.cpp
===
--- clang-tools-extra/pseudo/unittests/LRTableTest.cpp
+++ clang-tools-extra/pseudo/unittests/LRTableTest.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#include "clang-pseudo/LRTable.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "clang/Basic/TokenKinds.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
Index: clang-tools-extra/pseudo/unittests/GrammarTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GrammarTest.cpp
+++ clang-tools-extra/pseudo/unittests/GrammarTest.cpp
@@ -6,7 +6,7 @@
 //
 //===--===//
 
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
Index: clang-tools-extra/pseudo/unittests/GLRTest.cpp
===
--- clang-tools-extra/pseudo/unittests/GLRTest.cpp
+++ clang-tools-extra/pseudo/unittests/GLRTest.cpp
@@ -7,7 +7,7 @@
 //===--===//
 
 #include "clang-pseudo/GLR.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/Grammar.h"
 #include "clang-pseudo/Token.h"
 #include "clang/Basic/LangOptions.h"
 #include "clang/Basic/TokenKinds.h"
Index: clang-tools-extra/pseudo/tool/ClangPseudo.cpp
===
--- clang-tools-extra/pseudo/tool/ClangPseudo.cpp
+++ clang-tools-extra/pseudo/tool/ClangPseudo.cpp
@@ -9,10 +9,10 @@
 #include "clang-pseudo/Bracket.h"
 #include "clang-pseudo/DirectiveTree.h"
 #include "clang-pseudo/GLR.h"
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRGraph.h"
-#include "clang-pseudo/LRTable.h"
 #include "clang-pseudo/Token.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRGraph.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "clang/Basic/LangOptions.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/CommandLine.h"
Index: clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
+++ clang-tools-extra/pseudo/lib/grammar/LRTableBuild.cpp
@@ -6,9 +6,9 @@
 //
 //===--===//
 
-#include "clang-pseudo/Grammar.h"
-#include "clang-pseudo/LRGraph.h"
-#include "clang-pseudo/LRTable.h"
+#include "clang-pseudo/grammar/Grammar.h"
+#include "clang-pseudo/grammar/LRGraph.h"
+#include "clang-pseudo/grammar/LRTable.h"
 #include "clang/Basic/TokenKinds.h"
 #include 
 
Index: clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
===
--- clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
+++ clang-tools-extra/pseudo/lib/grammar/LRTable.cpp
@@ -6,8 +6,8 @@
 //
 //===--===//
 
-#include "clang-pseudo/LRTable.h"
-#include "clang-pseudo/Grammar.h"
+#include "clang-pseudo/grammar/LRTable.h"
+#include "clan

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

2022-06-09 Thread serge via Phabricator via cfe-commits
serge-sans-paille updated this revision to Diff 435520.
serge-sans-paille added a comment.
Herald added a subscriber: martong.

Take into account @efriedma and @kees review, plus adding a bunch of extra test 
case


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

https://reviews.llvm.org/D126864

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/LangOptions.def
  clang/include/clang/Driver/Options.td
  clang/include/clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/CodeGen/object-size-flex-array.c
  clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp

Index: clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/array-bounds-strict-flex-arrays.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -verify -fstrict-flex-arrays %s
+
+// We cannot know for sure the size of a flexible array.
+void test() {
+  struct {
+int f;
+int a[];
+  } s2;
+  s2.a[2] = 0; // no-warning
+}
+
+// Under -fstrict-flex-arrays `a` is not a flexible array.
+void test1() {
+  struct {
+int f;
+int a[1]; // expected-note {{declared here}}
+  } s2;
+  s2.a[2] = 0; // expected-warning 1 {{array index 2 is past the end of the array (which contains 1 element)}}
+}
Index: clang/test/CodeGen/object-size-flex-array.c
===
--- /dev/null
+++ clang/test/CodeGen/object-size-flex-array.c
@@ -0,0 +1,101 @@
+// RUN: %clang -fstrict-flex-arrays-target x86_64-apple-darwin -S -emit-llvm %s -o - 2>&1 | FileCheck --check-prefix CHECK-STRICT %s
+// RUN: %clang -fno-strict-flex-arrays -target x86_64-apple-darwin -S -emit-llvm %s -o - 2>&1 | FileCheck %s
+
+#ifndef DYNAMIC
+#define OBJECT_SIZE_BUILTIN __builtin_object_size
+#else
+#define OBJECT_SIZE_BUILTIN __builtin_dynamic_object_size
+#endif
+
+typedef struct {
+  float f;
+  double c[];
+} foo_t;
+
+typedef struct {
+  float f;
+  double c[0];
+} foo0_t;
+
+typedef struct {
+  float f;
+  double c[1];
+} foo1_t;
+
+typedef struct {
+  float f;
+  double c[2];
+} foo2_t;
+
+// CHECK-LABEL: @bar
+// CHECK-STRICT-LABEL: @bar
+unsigned bar(foo_t *f) {
+  // CHECK: ret i32 %
+  // CHECK-STRICT: ret i32 %
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
+
+// CHECK-LABEL: @bar0
+// CHECK-STRICT-LABEL: @bar0
+unsigned bar0(foo0_t *f) {
+  // CHECK: ret i32 %
+  // CHECK-STRICT: ret i32 0
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
+
+// CHECK-LABEL: @bar1
+// CHECK-STRICT-LABEL: @bar1
+unsigned bar1(foo1_t *f) {
+  // CHECK: ret i32 %
+  // CHECK-STRICT: ret i32 8
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
+
+// CHECK-LABEL: @bar2
+// CHECK-STRICT-LABEL: @bar2
+unsigned bar2(foo2_t *f) {
+  // CHECK: ret i32 %
+  // CHECK-STRICT: ret i32 16
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
+
+// Also checks for non-trailing flex-array like members
+
+typedef struct {
+  double c[0];
+  float f;
+} foofoo0_t;
+
+typedef struct {
+  double c[1];
+  float f;
+} foofoo1_t;
+
+typedef struct {
+  double c[2];
+  float f;
+} foofoo2_t;
+
+// CHECK-LABEL: @babar0
+// CHECK-STRICT-LABEL: @babar0
+unsigned babar0(foofoo0_t *f) {
+  // CHECK: ret i32 0
+  // CHECK-STRICT: ret i32 0
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
+
+// CHECK-LABEL: @babar1
+// CHECK-STRICT-LABEL: @babar1
+unsigned babar1(foofoo1_t *f) {
+  // CHECK: ret i32 8
+  // CHECK-STRICT: ret i32 8
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
+
+// CHECK-LABEL: @babar2
+// CHECK-STRICT-LABEL: @babar2
+unsigned babar2(foofoo2_t *f) {
+  // CHECK: ret i32 16
+  // CHECK-STRICT: ret i32 16
+  return OBJECT_SIZE_BUILTIN(f->c, 1);
+}
Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -789,6 +789,9 @@
   if (isa(AT))
 return true;
 
+  if (getContext().getLangOpts().StrictFlexArrays)
+return false;
+
   if (const auto *CAT = dyn_cast(AT)) {
 const llvm::APInt &Size = CAT->getSize();
 if (Size.isZero())
Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -15722,6 +15722,9 @@
 /// commonly used to emulate flexible arrays in C89 code.
 static bool IsTailPaddedMemberArray(Sema &S, const llvm::APInt &Size,
 const NamedDecl *ND) {
+  if (S.getLangOpts().StrictFlexArrays)
+return false;
+
   if (Size != 1 || !ND) return false;
 
   const FieldDecl *FD = dyn_cast(ND);
Index: clang/lib/Driver/ToolChains/Clang.cpp
==

[clang] 8feb92a - [clang][tests] Add missing compiler name

2022-06-09 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2022-06-09T15:11:40+02:00
New Revision: 8feb92add88adbb53729dd10f12667bb326e021e

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

LOG: [clang][tests] Add missing compiler name

The driver stripts the first argument. Without the compiler name, the
test depends on whether GCC_INSTALL_PREFIX is set or not.

See https://reviews.llvm.org/D125862

Added: 


Modified: 
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index 3f59fd4b94616..33389a52c6bb8 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -595,7 +595,7 @@ TEST(ToolChainTest, Toolsets) {
 Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
  "clang LLVM compiler", InMemoryFileSystem);
 std::unique_ptr C(
-TheDriver.BuildCompilation({"--gcc-toolchain="}));
+TheDriver.BuildCompilation({"clang", "--gcc-toolchain="}));
 ASSERT_TRUE(C);
 std::string S;
 {
@@ -635,7 +635,7 @@ TEST(ToolChainTest, Toolsets) {
 Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
  "clang LLVM compiler", InMemoryFileSystem);
 std::unique_ptr C(
-TheDriver.BuildCompilation({"--gcc-toolchain="}));
+TheDriver.BuildCompilation({"clang", "--gcc-toolchain="}));
 ASSERT_TRUE(C);
 std::string S;
 {



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


[clang] cedfb54 - [docs] Update supported language standards list for C++

2022-06-09 Thread Yuki Okushi via cfe-commits

Author: Yuki Okushi
Date: 2022-06-09T22:14:08+09:00
New Revision: cedfb5462cd86b9790a887e4e566a85cfe4f2313

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

LOG: [docs] Update supported language standards list for C++

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

Added: 


Modified: 
clang/docs/CommandGuide/clang.rst

Removed: 




diff  --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 658a30458043e..af2b0df98d3dc 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -185,13 +185,21 @@ Language Selection and Mode Options
 
ISO C++ 2017 with amendments and GNU extensions
 
-  | ``c++2a``
+  | ``c++20``
 
-   Working draft for ISO C++ 2020
+   ISO C++ 2020 with amendments
 
-  | ``gnu++2a``
+  | ``gnu++20``
 
-   Working draft for ISO C++ 2020 with GNU extensions
+   ISO C++ 2020 with amendments and GNU extensions
+
+  | ``c++2b``
+
+   Working draft for ISO C++ 2023
+
+  | ``gnu++2b``
+
+   Working draft for ISO C++ 2023 with GNU extensions
 
  The default C++ language standard is ``gnu++14``.
 



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


[PATCH] D127065: [docs] Update supported language standards list for C++

2022-06-09 Thread Yuki Okushi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcedfb5462cd8: [docs] Update supported language standards 
list for C++ (authored by JohnTitor).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127065

Files:
  clang/docs/CommandGuide/clang.rst


Index: clang/docs/CommandGuide/clang.rst
===
--- clang/docs/CommandGuide/clang.rst
+++ clang/docs/CommandGuide/clang.rst
@@ -185,13 +185,21 @@
 
ISO C++ 2017 with amendments and GNU extensions
 
-  | ``c++2a``
+  | ``c++20``
 
-   Working draft for ISO C++ 2020
+   ISO C++ 2020 with amendments
 
-  | ``gnu++2a``
+  | ``gnu++20``
 
-   Working draft for ISO C++ 2020 with GNU extensions
+   ISO C++ 2020 with amendments and GNU extensions
+
+  | ``c++2b``
+
+   Working draft for ISO C++ 2023
+
+  | ``gnu++2b``
+
+   Working draft for ISO C++ 2023 with GNU extensions
 
  The default C++ language standard is ``gnu++14``.
 


Index: clang/docs/CommandGuide/clang.rst
===
--- clang/docs/CommandGuide/clang.rst
+++ clang/docs/CommandGuide/clang.rst
@@ -185,13 +185,21 @@
 
ISO C++ 2017 with amendments and GNU extensions
 
-  | ``c++2a``
+  | ``c++20``
 
-   Working draft for ISO C++ 2020
+   ISO C++ 2020 with amendments
 
-  | ``gnu++2a``
+  | ``gnu++20``
 
-   Working draft for ISO C++ 2020 with GNU extensions
+   ISO C++ 2020 with amendments and GNU extensions
+
+  | ``c++2b``
+
+   Working draft for ISO C++ 2023
+
+  | ``gnu++2b``
+
+   Working draft for ISO C++ 2023 with GNU extensions
 
  The default C++ language standard is ``gnu++14``.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D125862: [clang][driver] Add gcc-toolset/devtoolset 12 to prefixes

2022-06-09 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked 2 inline comments as done.
tbaeder added inline comments.



Comment at: clang/unittests/Driver/ToolChainTest.cpp:647
+std::unique_ptr C(
+TheDriver.BuildCompilation({"--gcc-toolchain="}));
+ASSERT_TRUE(C);

ebevhan wrote:
> There's a binary name missing here:
> 
> ```
> {"clang", "--gcc-toolchain="}
> ```
> 
> Driver strips the first argument, so the behavior of this test becomes 
> dependent on GCC_INSTALL_PREFIX which can cause it to fail in some cases.
Thanks, I pushed a commit adding the driver name.


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

https://reviews.llvm.org/D125862

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


[PATCH] D111548: [Clang] Add the `annotate_type` attribute

2022-06-09 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 435524.
mboehme added a comment.

Rebased to a newer base revision.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D111548

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/TypePrinter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/SemaAttr.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/AST/attr-annotate-type.c
  clang/test/CodeGenCXX/annotate-type.cpp
  clang/test/Sema/annotate-type.c
  clang/test/SemaCXX/annotate-type.cpp
  clang/unittests/AST/AttrTest.cpp

Index: clang/unittests/AST/AttrTest.cpp
===
--- clang/unittests/AST/AttrTest.cpp
+++ clang/unittests/AST/AttrTest.cpp
@@ -7,7 +7,10 @@
 //===--===//
 
 #include "clang/AST/Attr.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/Basic/AttrKinds.h"
+#include "clang/Tooling/Tooling.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -15,10 +18,154 @@
 
 namespace {
 
+using clang::ast_matchers::constantExpr;
+using clang::ast_matchers::equals;
+using clang::ast_matchers::functionDecl;
+using clang::ast_matchers::has;
+using clang::ast_matchers::hasDescendant;
+using clang::ast_matchers::hasName;
+using clang::ast_matchers::integerLiteral;
+using clang::ast_matchers::match;
+using clang::ast_matchers::selectFirst;
+using clang::ast_matchers::stringLiteral;
+using clang::ast_matchers::varDecl;
+using clang::tooling::buildASTFromCode;
+using clang::tooling::buildASTFromCodeWithArgs;
+
 TEST(Attr, Doc) {
   EXPECT_THAT(Attr::getDocumentation(attr::Used).str(),
   testing::HasSubstr("The compiler must emit the definition even "
  "if it appears to be unused"));
 }
 
+const FunctionDecl *getFunctionNode(ASTUnit *AST, const std::string &Name) {
+  auto Result =
+  match(functionDecl(hasName(Name)).bind("fn"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("fn");
+}
+
+const VarDecl *getVariableNode(ASTUnit *AST, const std::string &Name) {
+  auto Result = match(varDecl(hasName(Name)).bind("var"), AST->getASTContext());
+  EXPECT_EQ(Result.size(), 1u);
+  return Result[0].getNodeAs("var");
+}
+
+template 
+void AssertAnnotatedAs(TypeLoc TL, llvm::StringRef annotation,
+   ModifiedTypeLoc &ModifiedTL,
+   const AnnotateTypeAttr **AnnotateOut = nullptr) {
+  const auto AttributedTL = TL.getAs();
+  ASSERT_FALSE(AttributedTL.isNull());
+  ModifiedTL = AttributedTL.getModifiedLoc().getAs();
+  ASSERT_TRUE(ModifiedTL);
+
+  ASSERT_NE(AttributedTL.getAttr(), nullptr);
+  const auto *Annotate = dyn_cast(AttributedTL.getAttr());
+  ASSERT_NE(Annotate, nullptr);
+  EXPECT_EQ(Annotate->getAnnotation(), annotation);
+  if (AnnotateOut) {
+*AnnotateOut = Annotate;
+  }
+}
+
+TEST(Attr, AnnotateType) {
+
+  // Test that the AnnotateType attribute shows up in the right places and that
+  // it stores its arguments correctly.
+
+  auto AST = buildASTFromCode(R"cpp(
+void f(int* [[clang::annotate_type("foo", "arg1", 2)]] *,
+   int [[clang::annotate_type("bar")]]);
+
+int [[clang::annotate_type("int")]] * [[clang::annotate_type("ptr")]]
+  array[10] [[clang::annotate_type("arr")]];
+
+void (* [[clang::annotate_type("funcptr")]] fp)(void);
+
+struct S { int mem; };
+int [[clang::annotate_type("int")]]
+S::* [[clang::annotate_type("ptr_to_mem")]] ptr_to_member = &S::mem;
+  )cpp");
+
+  {
+const FunctionDecl *Func = getFunctionNode(AST.get(), "f");
+
+// First parameter.
+const auto PointerTL = Func->getParamDecl(0)
+   ->getTypeSourceInfo()
+   ->getTypeLoc()
+   .getAs();
+ASSERT_FALSE(PointerTL.isNull());
+PointerTypeLoc PointerPointerTL;
+const AnnotateTypeAttr *Annotate;
+AssertAnnotatedAs(PointerTL.getPointeeLoc(), "foo", PointerPointerTL,
+  &Annotate);
+
+EXPECT_EQ(Annotate->args_size(), 2);
+const auto *StringLit = selectFirst(
+"str", match(constantExpr(hasDescendant(stringLiteral().bind("str"))),
+ *Annotate->args_begin()[0], AST->getASTContext()));
+ASSERT_NE(StringLit, nullptr);
+EXPECT_EQ(StringLit->getString(), "arg1");
+EXPECT_EQ(match(constantExpr(has(integerLiteral(equals(2)).bind("int"))),
+*Annotate->args_begin()[1], AST->getASTContext())
+  .size(),
+  1);
+
+// Second parameter.
+BuiltinTypeLoc IntTL;
+AssertAnnotatedAs(Func->getParamDecl(1)->getTypeSourceInfo()->getTypeLoc(),
+

[PATCH] D125400: [clang][Analyzer] Add errno state to standard functions modeling.

2022-06-09 Thread Balázs Kéri via Phabricator via cfe-commits
balazske marked 2 inline comments as done.
balazske added inline comments.



Comment at: clang/test/Analysis/errno-stdlibraryfunctions-notes.c:11
+
+int access(const char *path, int amode);
+

martong wrote:
> Do you plan to extend the test file for other standard functions as well?
It was not planned. I am not sure if it is better to have some more functions 
but not all. If there is a test for all of the functions it should be generated 
somehow (test every function for success and failure case, arguments passed to 
the functions are probably not easy to generate).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125400

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


[PATCH] D124932: [clang][dataflow] Track `optional` contents in `optional` model.

2022-06-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 435528.
ymandel added a comment.

rebase and merge


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124932

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

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2154,7 +2154,6 @@
   ExpectLatticeChecksFor(
   R"(
 #include "unchecked_optional_access_test.h"
-
 $ns::$optional MakeOpt();
 
 void target() {
@@ -2165,7 +2164,6 @@
 }
   )",
   UnorderedElementsAre(Pair("check-1", "unsafe: input.cc:9:7")));
-
   ExpectLatticeChecksFor(
   R"(
 #include "unchecked_optional_access_test.h"
@@ -2231,8 +2229,95 @@
   UnorderedElementsAre(Pair("check", "unsafe: input.cc:8:7")));
 }
 
+TEST_P(UncheckedOptionalAccessTest, OptionalValueOptional) {
+  // Basic test that nested values are populated.  We nest an optional because
+  // its easy to use in a test, but the type of the nested value shouldn't
+  // matter.
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+using Foo = $ns::$optional;
+
+void target($ns::$optional foo) {
+  if (foo && *foo) {
+foo->value();
+/*[[access]]*/
+  }
+}
+  )",
+  UnorderedElementsAre(Pair("access", "safe")));
+
+  // Mutation is supported for nested values.
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+using Foo = $ns::$optional;
+
+void target($ns::$optional foo) {
+  if (foo && *foo) {
+foo->reset();
+foo->value();
+/*[[reset]]*/
+  }
+}
+  )",
+  UnorderedElementsAre(Pair("reset", "unsafe: input.cc:9:9")));
+}
+
+// Tests that structs can be nested. We use an optional field because its easy
+// to use in a test, but the type of the field shouldn't matter.
+TEST_P(UncheckedOptionalAccessTest, OptionalValueStruct) {
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+struct Foo {
+  $ns::$optional opt;
+};
+
+void target($ns::$optional foo) {
+  if (foo && foo->opt) {
+foo->opt.value();
+/*[[access]]*/
+  }
+}
+  )",
+  UnorderedElementsAre(Pair("access", "safe")));
+}
+
+TEST_P(UncheckedOptionalAccessTest, OptionalValueInitialization) {
+  // FIXME: Fix when to initialize `value`. All unwrapping should be safe in
+  // this example, but `value` initialization is done multiple times during the
+  // fixpoint iterations and joining the environment won't correctly merge them.
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+using Foo = $ns::$optional;
+
+void target($ns::$optional foo, bool b) {
+  if (!foo.has_value()) return;
+  if (b) {
+if (!foo->has_value()) return;
+// We have created `foo.value()`.
+foo->value();
+  } else {
+if (!foo->has_value()) return;
+// We have created `foo.value()` again, in a different environment.
+foo->value();
+  }
+  // Now we merge the two values. UncheckedOptionalAccessModel::merge() will
+  // throw away the "value" property.
+  foo->value();
+  /*[[merge]]*/
+}
+  )",
+  UnorderedElementsAre(Pair("merge", "unsafe: input.cc:19:7")));
+}
+
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
 // - invalidation (passing optional by non-const reference/pointer)
-// - nested `optional` values
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -179,9 +179,15 @@
 
 /// Returns the symbolic value that represents the "has_value" property of the
 /// optional value `OptionalVal`. Returns null if `OptionalVal` is null.
-BoolValue *getHasValue(Value *OptionalVal) {
-  if (OptionalVal) {
-return cast(OptionalVal->getProperty("has_value"));
+BoolValue *getHasValue(Environment &Env, Value *OptionalVal) {
+  if (OptionalVal != nullptr) {
+auto *HasValueVal =
+cast_or_null(OptionalVal->getProperty("has_value"));
+if (HasValueVal == nullptr) {
+  HasValueVal = &Env.makeAtomicBoolValue();
+  OptionalVal->setProperty("has_value", *HasValueVal);
+}
+return HasValueVal;
   }
   return nullptr;
 }
@@ -218,6 +224,50 @@
  .getDesugaredType(ASTCtx));
 }
 
+

[PATCH] D126907: Deferred Concept Instantiation Implementation Take 2

2022-06-09 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D126907#3568943 , @ChuanqiXu wrote:

> In D126907#3566633 , @erichkeane 
> wrote:
>
>> All of the comments from @ChuanqiXu done, thank you so much!
>>
>> As far as the crash you're seeing: That is typically a 'depth mismatch' 
>> kinda thing.  They sadly only show up when the types of the template 
>> arguments are different (that is, pack vs integral vs type), but I thought I 
>> got all of them with examples.
>>
>> I'll keep hunting for more during the day today, but any amount of 
>> reproducer you can provide (even if not minimized) would be incredibly 
>> helpful!
>
> Oh, if a not minimized reproducer is desired, you could find it at: 
> https://github.com/alibaba/async_simple. It should crash when we run 'make' 
> in build directory. (The version of libstdc++ is 10.2 in my environment)
>
> I would try to make a reduced example in the next week if we don't go on 
> smoothly.

I was able to reproduce it, but my time today is pretty limited (I have an EWG 
meeting to chair today + prep + stuff after), so I'm not sure what progress 
I'll make today.  So if you make any progress on it, it would be greatly 
appreciated too!


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

https://reviews.llvm.org/D126907

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


[PATCH] D126061: [clang] Reject non-declaration C++11 attributes on declarations

2022-06-09 Thread Martin Böhme via Phabricator via cfe-commits
mboehme marked an inline comment as done.
mboehme added inline comments.



Comment at: clang/lib/Sema/ParsedAttr.cpp:228
+  switch (getParsedKind()) {
+  case AT_AddressSpace:
+  case AT_OpenCLPrivateAddressSpace:

rsmith wrote:
> I don't think this one really slides today, in the syntactic sense, prior to 
> this patch (and I guess the same is true for most of these). Given:
> 
> ```
> [[clang::address_space(5)]] int x;
> int [[clang::address_space(5)]] y;
> ```
> 
> ... we accept `x` and reject `y`, making it look like this is simply a 
> declaration attribute. Hm, but we accept:
> 
> ```
> int *[[clang::address_space(5)]] *z;
> ```
> 
> ... so it really *does* seem to behave like a type attribute sometimes?
> 
> OK, so this patch is doing two things:
> 
> 1) It's permitting the use of these attributes as type attributes, where they 
> were not consistently permitted previously.
> 2) It's deprecating / warning on uses of them as declaration attributes.
> 
> That means there's no way to write code that is compatible with both old and 
> new Clang and produces no warnings, but it's easy enough to turn the warning 
> flag off I suppose. The new behavior does seem much better than the old.
> I don't think this one really slides today, in the syntactic sense, prior to 
> this patch (and I guess the same is true for most of these). Given:
> 
> ```
> [[clang::address_space(5)]] int x;
> int [[clang::address_space(5)]] y;
> ```
> 
> ... we accept `x` and reject `y`, making it look like this is simply a 
> declaration attribute.

Yes, and we get the same behavior for all C++11 attributes.

This is because, today, Clang flat-out rejects _all_ C++11 attributes that are 
placed after a decl-specifier-seq:

From `ParseDeclarationSpecifiers()`:

```
// Reject C++11 attributes that appertain to decl specifiers as
// we don't support any C++11 attributes that appertain to decl
// specifiers. This also conforms to what g++ 4.8 is doing.
ProhibitCXX11Attributes(attrs, diag::err_attribute_not_type_attr);
```

https://github.com/llvm/llvm-project/blob/main/clang/lib/Parse/ParseDecl.cpp#L3182

So really what the "slides" terminology means is "is treated as appertaining to 
the decl-specifier-seq instead of the declaration".

> Hm, but we accept:
> 
> ```
> int *[[clang::address_space(5)]] *z;
> ```
> 
> ... so it really *does* seem to behave like a type attribute sometimes?

Yes, because Clang does allow C++11 attributes (including `address_space` in 
particular) on declarator chunks today -- it just doesn't allow them on the 
decl-specifier-seq. As an aside, this makes the error message we get when 
putting the attribute on the decl-specifier-seq today ("'address_space' 
attribute cannot be applied to types") pretty misleading.

> OK, so this patch is doing two things:
> 
> 1) It's permitting the use of these attributes as type attributes, where they 
> were not consistently permitted previously.
> 2) It's deprecating / warning on uses of them as declaration attributes.

Actually, 1) happens in https://reviews.llvm.org/D111548, which this change is 
based on.

I did things this way because

  - I want to introduce `annotate_type` first, so that this change can use it 
in tests as an example of a type attribute that doesn't "slide"
  - I wanted tests in https://reviews.llvm.org/D111548 to be able to use 
`annotate_type` in all places that it's intended for, including on the 
decl-specifier-seq, so I needed to open up that usage. (Actually, when I first 
authored https://reviews.llvm.org/D111548, I didn't even realize that this 
followup change would be coming.)

Is this confusing? I could instead do the following:

  - Move the change that allows C++11 attributes on the decl-specifier-seq from 
https://reviews.llvm.org/D111548 to here.
  - Move tests that use `annotate_type` on the decl-specifier-seq from 
https://reviews.llvm.org/D111548 to here.

Do you think that would be preferable?

> That means there's no way to write code that is compatible with both old and 
> new Clang and produces no warnings, but it's easy enough to turn the warning 
> flag off I suppose.

That's true -- and I think it's the best we can do. The behavior that Clang 
exhibits today is of course set in stone (error out if the attribute is placed 
on the decl-specifier-seq), and at the same time it seems obvious that we want 
to nudge people away from putting the attribute on the declaration, as it's 
really a type attribute. (Just repeating your analysis here essentially; I 
think we agree, and there's nothing to do here.)

I do think this makes an argument that the new diagnostic we're introducing 
should be a warning initially, not an error. Otherwise, there would be no way 
to use the C++11 spelling in a way that compiles (albeit maybe with warnings) 
both before and after this patch.

> The new behavior does seem much better than the old.





Comment at: clang/lib/S

[PATCH] D127306: [analyzer] Treat system globals as mutable if they are not const

2022-06-09 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D127306#3566984 , @steakhal wrote:

> In D127306#3566761 , @martong wrote:
>
>>> In theory, the engine should propagate taint in default eval call. If that 
>>> would be the case, we would still have this report.
>>
>> How complex would it be to add the taint propagation to the engine/evalCall? 
>> Do you see that feasible as a parent patch of this?
>
> I see your point, but I don't think we should delay D124244 
>  because of that. By landing this, we could 
> also land that. And the change you propose might take significantly longer to 
> make and verify.
> I could make some prototypes, but I'm not making promises.

Ok.

One concern. Can we decide for a global **const system** variable if that it is 
a //system// variable? Consider `my_const_system_global`, it will be in 
`GlobalImmutableSpaceRegion`, however, it is also a //system// variable. Would 
it make sense to have a GlobalImmutable**System**SpaceRegion?




Comment at: clang/lib/StaticAnalyzer/Core/MemRegion.cpp:979-980
+if (Ty.isConstQualified() && Ty->isArithmeticType()) {
   // TODO: We could walk the complex types here and see if everything is
   // constified.
+  sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);

Is this comment still meaningful? I don't think so because if the type is 
const, then it does not matter what sub-types it has.



Comment at: clang/test/Analysis/globals-are-not-always-immutable.c:14
+void test_errno() {
+  errno = 2;
+  clang_analyzer_eval(errno == 2); // expected-warning {{TRUE}}

I am wondering if we should have another test for `assert(errno == 2);`. 
Because here we add a binding to the store, however, with the `assert` we add a 
constraint to the range based constraint manager and these are very much 
different cases.

The same applies to the below tests as well.



Comment at: clang/test/Analysis/globals-are-not-always-immutable.c:55
+  invalidate_globals();
+  clang_analyzer_eval(my_mutable_system_global == 2); // expected-warning 
{{UNKNOWN}} It was previously TRUE.
+}

Please highlight that this is the essence of the change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127306

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


[PATCH] D127389: [analyzer] Print the offending function at EndAnalysis crash

2022-06-09 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127389

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


[PATCH] D127285: [analyzer] Fix assertion failure after getKnownValue call

2022-06-09 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

In D127285#3566032 , @steakhal wrote:

> LGTM
> Schedule a measurement to see what changes. Let's hope it won't introduce 
> more crashes.
> If everything checks out, it gets approved.

Results are good. No new assertion failures, neither crashes. Runtime is the 
same (in the margin of error). `Redis` has been added to the set of analyzed 
projects this time. F23373861: stats.html 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127285

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


[PATCH] D125349: [Sema] Fix crash for C11 atomic in gnu++ mode

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



Comment at: clang/lib/Sema/SemaOverload.cpp:8982
 
 // Extension: Add the binary operators =, +=, -=, *=, /= for vector types.
 for (QualType Vec1Ty : CandidateTypes[0].vector_types())

Do we need to handle atomic vector types?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125349

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


[clang] bc2c759 - [analyzer] Fix assertion failure after getKnownValue call

2022-06-09 Thread Gabor Marton via cfe-commits

Author: Gabor Marton
Date: 2022-06-09T16:13:57+02:00
New Revision: bc2c759aeee7d1560840a24365ce18b8e8b63ded

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

LOG: [analyzer] Fix assertion failure after getKnownValue call

Depends on D126560. `getKnownValue` has been changed by the parent patch
in a way that simplification was removed. This is not correct when the
function is called by the Checkers. Thus, a new internal function is
introduced, `getConstValue`, which simply queries the constraint manager.
This `getConstValue` is used internally in the `SimpleSValBuilder` when a
binop is evaluated, this way we avoid the recursion into the `Simplifier`.

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

Added: 
clang/test/Analysis/svalbuilder-simplify-no-crash.c

Modified: 
clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 392251109e7da..785039a186486 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -22,6 +22,13 @@ using namespace ento;
 namespace {
 class SimpleSValBuilder : public SValBuilder {
 
+  // Query the constraint manager whether the SVal has only one possible
+  // (integer) value. If that is the case, the value is returned. Otherwise,
+  // returns NULL.
+  // This is an implementation detail. Checkers should use `getKnownValue()`
+  // instead.
+  const llvm::APSInt *getConstValue(ProgramStateRef state, SVal V);
+
   // With one `simplifySValOnce` call, a compound symbols might collapse to
   // simpler symbol tree that is still possible to further simplify. Thus, we
   // do the simplification on a new symbol tree until we reach the simplest
@@ -45,7 +52,7 @@ class SimpleSValBuilder : public SValBuilder {
   SVal simplifyUntilFixpoint(ProgramStateRef State, SVal Val);
 
   // Recursively descends into symbolic expressions and replaces symbols
-  // with their known values (in the sense of the getKnownValue() method).
+  // with their known values (in the sense of the getConstValue() method).
   // We traverse the symbol tree and query the constraint values for the
   // sub-trees and if a value is a constant we do the constant folding.
   SVal simplifySValOnce(ProgramStateRef State, SVal V);
@@ -65,8 +72,9 @@ class SimpleSValBuilder : public SValBuilder {
   SVal evalBinOpLN(ProgramStateRef state, BinaryOperator::Opcode op,
Loc lhs, NonLoc rhs, QualType resultTy) override;
 
-  /// getKnownValue - evaluates a given SVal. If the SVal has only one possible
-  ///  (integer) value, that value is returned. Otherwise, returns NULL.
+  /// Evaluates a given SVal by recursively evaluating and
+  /// simplifying the children SVals. If the SVal has only one possible
+  /// (integer) value, that value is returned. Otherwise, returns NULL.
   const llvm::APSInt *getKnownValue(ProgramStateRef state, SVal V) override;
 
   SVal simplifySVal(ProgramStateRef State, SVal V) override;
@@ -532,7 +540,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
   llvm::APSInt LHSValue = lhs.castAs().getValue();
 
   // If we're dealing with two known constants, just perform the operation.
-  if (const llvm::APSInt *KnownRHSValue = getKnownValue(state, rhs)) {
+  if (const llvm::APSInt *KnownRHSValue = getConstValue(state, rhs)) {
 llvm::APSInt RHSValue = *KnownRHSValue;
 if (BinaryOperator::isComparisonOp(op)) {
   // We're looking for a type big enough to compare the two values.
@@ -652,7 +660,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
 }
 
 // For now, only handle expressions whose RHS is a constant.
-if (const llvm::APSInt *RHSValue = getKnownValue(state, rhs)) {
+if (const llvm::APSInt *RHSValue = getConstValue(state, rhs)) {
   // If both the LHS and the current expression are additive,
   // fold their constants and try again.
   if (BinaryOperator::isAdditiveOp(op)) {
@@ -699,7 +707,7 @@ SVal SimpleSValBuilder::evalBinOpNN(ProgramStateRef state,
   }
 
   // Is the RHS a constant?
-  if (const llvm::APSInt *RHSValue = getKnownValue(state, rhs))
+  if (const llvm::APSInt *RHSValue = getConstValue(state, rhs))
 return MakeSymIntVal(Sym, op, *RHSValue, resultTy);
 
   if (Optional V = tryRearrange(state, op, lhs, rhs, resultTy))
@@ -1187,8 +1195,8 @@ SVal SimpleSValBuilder::evalBinOpLN(ProgramStateRef state,
   return UnknownVal();
 }
 
-const llvm::APSInt *SimpleSValBuilder::getKnownValue(ProgramStateRef state,
-   SVal V) {
+const llvm::APSInt

[PATCH] D127285: [analyzer] Fix assertion failure after getKnownValue call

2022-06-09 Thread Gabor Marton 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 rGbc2c759aeee7: [analyzer] Fix assertion failure after 
getKnownValue call (authored by martong).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127285

Files:
  clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  clang/test/Analysis/svalbuilder-simplify-no-crash.c

Index: clang/test/Analysis/svalbuilder-simplify-no-crash.c
===
--- /dev/null
+++ clang/test/Analysis/svalbuilder-simplify-no-crash.c
@@ -0,0 +1,13 @@
+// RUN: %clang_analyze_cc1 %s \
+// RUN:   -analyzer-checker=core \
+// RUN:   -analyzer-checker=debug.ExprInspection \
+// RUN:   -verify
+
+// Here, we test that svalbuilder simplification does not produce any
+// assertion failure.
+
+void crashing(long a, _Bool b) {
+  (void)(a & 1 && 0);
+  b = a & 1;
+  (void)(b << 1); // expected-warning{{core.UndefinedBinaryOperatorResult}}
+}
Index: clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
===
--- clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -22,6 +22,13 @@
 namespace {
 class SimpleSValBuilder : public SValBuilder {
 
+  // Query the constraint manager whether the SVal has only one possible
+  // (integer) value. If that is the case, the value is returned. Otherwise,
+  // returns NULL.
+  // This is an implementation detail. Checkers should use `getKnownValue()`
+  // instead.
+  const llvm::APSInt *getConstValue(ProgramStateRef state, SVal V);
+
   // With one `simplifySValOnce` call, a compound symbols might collapse to
   // simpler symbol tree that is still possible to further simplify. Thus, we
   // do the simplification on a new symbol tree until we reach the simplest
@@ -45,7 +52,7 @@
   SVal simplifyUntilFixpoint(ProgramStateRef State, SVal Val);
 
   // Recursively descends into symbolic expressions and replaces symbols
-  // with their known values (in the sense of the getKnownValue() method).
+  // with their known values (in the sense of the getConstValue() method).
   // We traverse the symbol tree and query the constraint values for the
   // sub-trees and if a value is a constant we do the constant folding.
   SVal simplifySValOnce(ProgramStateRef State, SVal V);
@@ -65,8 +72,9 @@
   SVal evalBinOpLN(ProgramStateRef state, BinaryOperator::Opcode op,
Loc lhs, NonLoc rhs, QualType resultTy) override;
 
-  /// getKnownValue - evaluates a given SVal. If the SVal has only one possible
-  ///  (integer) value, that value is returned. Otherwise, returns NULL.
+  /// Evaluates a given SVal by recursively evaluating and
+  /// simplifying the children SVals. If the SVal has only one possible
+  /// (integer) value, that value is returned. Otherwise, returns NULL.
   const llvm::APSInt *getKnownValue(ProgramStateRef state, SVal V) override;
 
   SVal simplifySVal(ProgramStateRef State, SVal V) override;
@@ -532,7 +540,7 @@
   llvm::APSInt LHSValue = lhs.castAs().getValue();
 
   // If we're dealing with two known constants, just perform the operation.
-  if (const llvm::APSInt *KnownRHSValue = getKnownValue(state, rhs)) {
+  if (const llvm::APSInt *KnownRHSValue = getConstValue(state, rhs)) {
 llvm::APSInt RHSValue = *KnownRHSValue;
 if (BinaryOperator::isComparisonOp(op)) {
   // We're looking for a type big enough to compare the two values.
@@ -652,7 +660,7 @@
 }
 
 // For now, only handle expressions whose RHS is a constant.
-if (const llvm::APSInt *RHSValue = getKnownValue(state, rhs)) {
+if (const llvm::APSInt *RHSValue = getConstValue(state, rhs)) {
   // If both the LHS and the current expression are additive,
   // fold their constants and try again.
   if (BinaryOperator::isAdditiveOp(op)) {
@@ -699,7 +707,7 @@
   }
 
   // Is the RHS a constant?
-  if (const llvm::APSInt *RHSValue = getKnownValue(state, rhs))
+  if (const llvm::APSInt *RHSValue = getConstValue(state, rhs))
 return MakeSymIntVal(Sym, op, *RHSValue, resultTy);
 
   if (Optional V = tryRearrange(state, op, lhs, rhs, resultTy))
@@ -1187,8 +1195,8 @@
   return UnknownVal();
 }
 
-const llvm::APSInt *SimpleSValBuilder::getKnownValue(ProgramStateRef state,
-   SVal V) {
+const llvm::APSInt *SimpleSValBuilder::getConstValue(ProgramStateRef state,
+ SVal V) {
   if (V.isUnknownOrUndef())
 return nullptr;
 
@@ -1204,6 +1212,11 @@
   return nullptr;
 }
 
+const llvm::APSInt *SimpleSValBuilder::getKnownValue(ProgramStateRef state,
+ SVal V) {
+  return get

[PATCH] D124932: [clang][dataflow] Track `optional` contents in `optional` model.

2022-06-09 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel updated this revision to Diff 435537.
ymandel added a comment.

add missing blank line to test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124932

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

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2165,7 +2165,6 @@
 }
   )",
   UnorderedElementsAre(Pair("check-1", "unsafe: input.cc:9:7")));
-
   ExpectLatticeChecksFor(
   R"(
 #include "unchecked_optional_access_test.h"
@@ -2231,8 +2230,95 @@
   UnorderedElementsAre(Pair("check", "unsafe: input.cc:8:7")));
 }
 
+TEST_P(UncheckedOptionalAccessTest, OptionalValueOptional) {
+  // Basic test that nested values are populated.  We nest an optional because
+  // its easy to use in a test, but the type of the nested value shouldn't
+  // matter.
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+using Foo = $ns::$optional;
+
+void target($ns::$optional foo) {
+  if (foo && *foo) {
+foo->value();
+/*[[access]]*/
+  }
+}
+  )",
+  UnorderedElementsAre(Pair("access", "safe")));
+
+  // Mutation is supported for nested values.
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+using Foo = $ns::$optional;
+
+void target($ns::$optional foo) {
+  if (foo && *foo) {
+foo->reset();
+foo->value();
+/*[[reset]]*/
+  }
+}
+  )",
+  UnorderedElementsAre(Pair("reset", "unsafe: input.cc:9:9")));
+}
+
+// Tests that structs can be nested. We use an optional field because its easy
+// to use in a test, but the type of the field shouldn't matter.
+TEST_P(UncheckedOptionalAccessTest, OptionalValueStruct) {
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+struct Foo {
+  $ns::$optional opt;
+};
+
+void target($ns::$optional foo) {
+  if (foo && foo->opt) {
+foo->opt.value();
+/*[[access]]*/
+  }
+}
+  )",
+  UnorderedElementsAre(Pair("access", "safe")));
+}
+
+TEST_P(UncheckedOptionalAccessTest, OptionalValueInitialization) {
+  // FIXME: Fix when to initialize `value`. All unwrapping should be safe in
+  // this example, but `value` initialization is done multiple times during the
+  // fixpoint iterations and joining the environment won't correctly merge them.
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+using Foo = $ns::$optional;
+
+void target($ns::$optional foo, bool b) {
+  if (!foo.has_value()) return;
+  if (b) {
+if (!foo->has_value()) return;
+// We have created `foo.value()`.
+foo->value();
+  } else {
+if (!foo->has_value()) return;
+// We have created `foo.value()` again, in a different environment.
+foo->value();
+  }
+  // Now we merge the two values. UncheckedOptionalAccessModel::merge() will
+  // throw away the "value" property.
+  foo->value();
+  /*[[merge]]*/
+}
+  )",
+  UnorderedElementsAre(Pair("merge", "unsafe: input.cc:19:7")));
+}
+
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
 // - invalidation (passing optional by non-const reference/pointer)
-// - nested `optional` values
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -179,9 +179,15 @@
 
 /// Returns the symbolic value that represents the "has_value" property of the
 /// optional value `OptionalVal`. Returns null if `OptionalVal` is null.
-BoolValue *getHasValue(Value *OptionalVal) {
-  if (OptionalVal) {
-return cast(OptionalVal->getProperty("has_value"));
+BoolValue *getHasValue(Environment &Env, Value *OptionalVal) {
+  if (OptionalVal != nullptr) {
+auto *HasValueVal =
+cast_or_null(OptionalVal->getProperty("has_value"));
+if (HasValueVal == nullptr) {
+  HasValueVal = &Env.makeAtomicBoolValue();
+  OptionalVal->setProperty("has_value", *HasValueVal);
+}
+return HasValueVal;
   }
   return nullptr;
 }
@@ -218,6 +224,50 @@
  .getDesugaredType(ASTCtx));
 }
 
+/// Tries to initialize the `optional`'s value (that is, contents), and return
+/// its location. Returns nullptr if the value can't be represented.
+S

[clang] dd38caf - [clang][dataflow] Track `optional` contents in `optional` model.

2022-06-09 Thread Yitzhak Mandelbaum via cfe-commits

Author: Yitzhak Mandelbaum
Date: 2022-06-09T14:17:39Z
New Revision: dd38caf3b5b724c1f84998c1ae105f709c3ed405

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

LOG: [clang][dataflow] Track `optional` contents in `optional` model.

This patch adds partial support for tracking (i.e. modeling) the contents of an
optional value. Specifically, it supports tracking the value after it is
accessed. We leave tracking constructed/assigned contents to a future patch.

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index cf93a07f832df..00d22fbe8bb80 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -179,9 +179,15 @@ StructValue &createOptionalValue(Environment &Env, 
BoolValue &HasValueVal) {
 
 /// Returns the symbolic value that represents the "has_value" property of the
 /// optional value `OptionalVal`. Returns null if `OptionalVal` is null.
-BoolValue *getHasValue(Value *OptionalVal) {
-  if (OptionalVal) {
-return cast(OptionalVal->getProperty("has_value"));
+BoolValue *getHasValue(Environment &Env, Value *OptionalVal) {
+  if (OptionalVal != nullptr) {
+auto *HasValueVal =
+cast_or_null(OptionalVal->getProperty("has_value"));
+if (HasValueVal == nullptr) {
+  HasValueVal = &Env.makeAtomicBoolValue();
+  OptionalVal->setProperty("has_value", *HasValueVal);
+}
+return HasValueVal;
   }
   return nullptr;
 }
@@ -218,6 +224,50 @@ int countOptionalWrappers(const ASTContext &ASTCtx, 
QualType Type) {
  .getDesugaredType(ASTCtx));
 }
 
+/// Tries to initialize the `optional`'s value (that is, contents), and return
+/// its location. Returns nullptr if the value can't be represented.
+StorageLocation *maybeInitializeOptionalValueMember(QualType Q,
+Value &OptionalVal,
+Environment &Env) {
+  // The "value" property represents a synthetic field. As such, it needs
+  // `StorageLocation`, like normal fields (and other variables). So, we model
+  // it with a `ReferenceValue`, since that includes a storage location.  Once
+  // the property is set, it will be shared by all environments that access the
+  // `Value` representing the optional (here, `OptionalVal`).
+  if (auto *ValueProp = OptionalVal.getProperty("value")) {
+auto *ValueRef = clang::cast(ValueProp);
+auto &ValueLoc = ValueRef->getPointeeLoc();
+if (Env.getValue(ValueLoc) == nullptr) {
+  // The property was previously set, but the value has been lost. This can
+  // happen, for example, because of an environment merge (where the two
+  // environments mapped the property to 
diff erent values, which resulted in
+  // them both being discarded), or when two blocks in the CFG, with 
neither
+  // a dominator of the other, visit the same optional value, or even when 
a
+  // block is revisited during testing to collect per-statement state.
+  // FIXME: This situation means that the optional contents are not shared
+  // between branches and the like. Practically, this lack of sharing
+  // reduces the precision of the model when the contents are relevant to
+  // the check, like another optional or a boolean that influences control
+  // flow.
+  auto *ValueVal = Env.createValue(ValueLoc.getType());
+  if (ValueVal == nullptr)
+return nullptr;
+  Env.setValue(ValueLoc, *ValueVal);
+}
+return &ValueLoc;
+  }
+
+  auto Ty = stripReference(Q);
+  auto *ValueVal = Env.createValue(Ty);
+  if (ValueVal == nullptr)
+return nullptr;
+  auto &ValueLoc = Env.createStorageLocation(Ty);
+  Env.setValue(ValueLoc, *ValueVal);
+  auto ValueRef = std::make_unique(ValueLoc);
+  OptionalVal.setProperty("value", Env.takeOwnership(std::move(ValueRef)));
+  return &ValueLoc;
+}
+
 void initializeOptionalReference(const Expr *OptionalExpr,
  const MatchFinder::MatchResult &,
  LatticeTransferState &State) {
@@ -233,11 +283,16 @@ void transferUnwrapCall(const Expr *UnwrapExpr, const 
Expr *ObjectExpr,
 LatticeTransferState &State) {
   if (auto *OptionalVal =
   State.Env.getValue(*ObjectExpr, SkipPast::ReferenceThenPointer)) {
-auto *HasValu

[PATCH] D124932: [clang][dataflow] Track `optional` contents in `optional` model.

2022-06-09 Thread Yitzhak Mandelbaum 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 rGdd38caf3b5b7: [clang][dataflow] Track `optional` contents in 
`optional` model. (authored by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124932

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

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -2165,7 +2165,6 @@
 }
   )",
   UnorderedElementsAre(Pair("check-1", "unsafe: input.cc:9:7")));
-
   ExpectLatticeChecksFor(
   R"(
 #include "unchecked_optional_access_test.h"
@@ -2231,8 +2230,95 @@
   UnorderedElementsAre(Pair("check", "unsafe: input.cc:8:7")));
 }
 
+TEST_P(UncheckedOptionalAccessTest, OptionalValueOptional) {
+  // Basic test that nested values are populated.  We nest an optional because
+  // its easy to use in a test, but the type of the nested value shouldn't
+  // matter.
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+using Foo = $ns::$optional;
+
+void target($ns::$optional foo) {
+  if (foo && *foo) {
+foo->value();
+/*[[access]]*/
+  }
+}
+  )",
+  UnorderedElementsAre(Pair("access", "safe")));
+
+  // Mutation is supported for nested values.
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+using Foo = $ns::$optional;
+
+void target($ns::$optional foo) {
+  if (foo && *foo) {
+foo->reset();
+foo->value();
+/*[[reset]]*/
+  }
+}
+  )",
+  UnorderedElementsAre(Pair("reset", "unsafe: input.cc:9:9")));
+}
+
+// Tests that structs can be nested. We use an optional field because its easy
+// to use in a test, but the type of the field shouldn't matter.
+TEST_P(UncheckedOptionalAccessTest, OptionalValueStruct) {
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+struct Foo {
+  $ns::$optional opt;
+};
+
+void target($ns::$optional foo) {
+  if (foo && foo->opt) {
+foo->opt.value();
+/*[[access]]*/
+  }
+}
+  )",
+  UnorderedElementsAre(Pair("access", "safe")));
+}
+
+TEST_P(UncheckedOptionalAccessTest, OptionalValueInitialization) {
+  // FIXME: Fix when to initialize `value`. All unwrapping should be safe in
+  // this example, but `value` initialization is done multiple times during the
+  // fixpoint iterations and joining the environment won't correctly merge them.
+  ExpectLatticeChecksFor(
+  R"(
+#include "unchecked_optional_access_test.h"
+
+using Foo = $ns::$optional;
+
+void target($ns::$optional foo, bool b) {
+  if (!foo.has_value()) return;
+  if (b) {
+if (!foo->has_value()) return;
+// We have created `foo.value()`.
+foo->value();
+  } else {
+if (!foo->has_value()) return;
+// We have created `foo.value()` again, in a different environment.
+foo->value();
+  }
+  // Now we merge the two values. UncheckedOptionalAccessModel::merge() will
+  // throw away the "value" property.
+  foo->value();
+  /*[[merge]]*/
+}
+  )",
+  UnorderedElementsAre(Pair("merge", "unsafe: input.cc:19:7")));
+}
+
 // FIXME: Add support for:
 // - constructors (copy, move)
 // - assignment operators (default, copy, move)
 // - invalidation (passing optional by non-const reference/pointer)
-// - nested `optional` values
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -179,9 +179,15 @@
 
 /// Returns the symbolic value that represents the "has_value" property of the
 /// optional value `OptionalVal`. Returns null if `OptionalVal` is null.
-BoolValue *getHasValue(Value *OptionalVal) {
-  if (OptionalVal) {
-return cast(OptionalVal->getProperty("has_value"));
+BoolValue *getHasValue(Environment &Env, Value *OptionalVal) {
+  if (OptionalVal != nullptr) {
+auto *HasValueVal =
+cast_or_null(OptionalVal->getProperty("has_value"));
+if (HasValueVal == nullptr) {
+  HasValueVal = &Env.makeAtomicBoolValue();
+  OptionalVal->setProperty("has_value", *HasValueVal);
+}
+return HasValueVal;
   }
   return nullptr;
 }
@@ -218,6 +224,50 @@
  .getDesugaredType(ASTCtx));
 }
 
+///

[PATCH] D125919: Drop qualifiers from return types in C (DR423)

2022-06-09 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

In D125919#3569928 , @aaron.ballman 
wrote:

> In D125919#3560523 , @aaron.ballman 
> wrote:
>
>> All that said, I think you can see why I'm hoping to get an answer from WG14 
>> as to what to do. Reasonable folks are disagreeing on what the standard 
>> requires here.
>
> The discussion on the WG14 reflector seems to be settling down to a consensus 
> position that the `_Atomic` qualifier is only syntactically a qualifier and 
> its use designates an entirely new type. When the standard says "unqualified 
> type", the `_Atomic` is not considered a qualification. So we should *not* be 
> stripping the `_Atomic` as I was doing in this patch. (SC22WG14.22200 has 
> most of the details spelled out nicely, if you have access to the reflectors.)

What a strange position.  *All* qualifiers produce an "entirely new type".  But 
okay, if the committee wants to pretend that `_Atomic` is meaningful in return 
values, I guess we all have to live with that.

> I had asked other questions in related areas that also got answers.
>
> `const void func(volatile void);` -- the return type is adjusted to `void`; 
> the parameter type is UB (by lack of specification) and we can do what we 
> want here. We currently diagnose the parameter as being invalid: 
> https://godbolt.org/z/9c8bTrerY. Our behavior with the parameter is 
> consistent with GCC and EDG.
>
> `const int main(void)` -- this is valid and equivalent to `int main(void)`, 
> so it should be accepted; we currently reject: https://godbolt.org/z/v43h596ev
>
> `const int func(void); int func(void) { }` -- this is DR423. It is valid, the 
> composite type is `int(void)`; we give a conflicting types error: 
> https://godbolt.org/z/Yb841r7Ex

Is that only because of the type compositing rules, or are they saying that the 
type of the first is `const int (void)`, which is different from `int (void)`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125919

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


[PATCH] D126781: [CodeGen] Keep track info of lazy-emitted symbols in ModuleBuilder

2022-06-09 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.

Okay, LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D126781

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


  1   2   3   >