[PATCH] D131938: [C++20] [Coroutines] Disable to take the address of labels in coroutines

2022-08-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D131938#3727954 , @ychen wrote:

>> Since the coroutines are going to split into pieces in the middle end so the 
>> address of labels are ambiguous that time.
>
> Do we split in the middle or copy the whole computed goto CFG?

Yes.

> I'd imagine the branch on a dynamic block address is like `n`-way branch 
> which is not feasible to split. Does/Would it fix the problem by letting the 
> ramp/resume function each have its own dispatch table? I skimmed through the 
> blockaddress handling during function cloning which looks insufficient to 
> handle this issue: 
> https://github.com/llvm/llvm-project/blob/e20d210eef92f3952de0e89ef2f01a146480a13b/llvm/lib/Transforms/Utils/CloneFunction.cpp#L177-L182,
>  it says "It is only legal to clone a function if a block address within that 
> function is never referenced outside of the function." . This is not true 
> when the dispatch table is a global variable.

The key problem here is that the compiler don't know the idea 'dispatch table'. 
The dispatch table is just a global variable. And coroutines should just leave 
the global variable there just like other global variables.

> "It is only legal to clone a function if a block address within that function 
> is never referenced outside of the function."

This also shows the problem. The coroutines are multiple functions indeed.


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

https://reviews.llvm.org/D131938

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


[PATCH] D132008: [clang-format] Handle return type auto followed by l_paren

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

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132008

Files:
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24887,7 +24887,7 @@
 // the user's own fault
   verifyFormat("integral auto(x) = y;"); // actually a declaration, but this is
  // clearly the user's own fault
-  verifyFormat("auto(*p)() = f;");   // actually a declaration; TODO FIXME
+  verifyFormat("auto (*p)() = f;");
 }
 
 TEST_F(FormatTest, Cpp20ModulesSupport) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3337,9 +3337,11 @@
   }
 
   // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
-  if (Left.is(tok::kw_auto) &&
-  Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+  if (Left.is(tok::kw_auto) && Right.isOneOf(TT_LambdaLBrace, 
TT_FunctionLBrace,
+ // function return type 'auto'
+ TT_FunctionTypeLParen)) {
 return true;
+  }
 
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24887,7 +24887,7 @@
 // the user's own fault
   verifyFormat("integral auto(x) = y;"); // actually a declaration, but this is
  // clearly the user's own fault
-  verifyFormat("auto(*p)() = f;");   // actually a declaration; TODO FIXME
+  verifyFormat("auto (*p)() = f;");
 }
 
 TEST_F(FormatTest, Cpp20ModulesSupport) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3337,9 +3337,11 @@
   }
 
   // trailing return type 'auto': []() -> auto {}, auto foo() -> auto {}
-  if (Left.is(tok::kw_auto) &&
-  Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace))
+  if (Left.is(tok::kw_auto) && Right.isOneOf(TT_LambdaLBrace, TT_FunctionLBrace,
+ // function return type 'auto'
+ TT_FunctionTypeLParen)) {
 return true;
+  }
 
   // auto{x} auto(x)
   if (Left.is(tok::kw_auto) && Right.isOneOf(tok::l_paren, tok::l_brace))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131938: [C++20] [Coroutines] Disable to take the address of labels in coroutines

2022-08-16 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

> Since the coroutines are going to split into pieces in the middle end so the 
> address of labels are ambiguous that time.

Do we split in the middle or copy the whole computed goto CFG? I'd imagine the 
branch on a dynamic block address is like `n`-way branch which is not feasible 
to split. Does it fix the problem by letting the ramp/result each have their 
own dispatch table? I skimmed through the blockaddress handling during function 
cloning which looks insufficient to handle this issue: 
https://github.com/llvm/llvm-project/blob/e20d210eef92f3952de0e89ef2f01a146480a13b/llvm/lib/Transforms/Utils/CloneFunction.cpp#L177-L182,
 it says "It is only legal to clone a function if a block address within that 
function is never referenced outside of the function." . This is not true when 
the dispatch table is a global variable.


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

https://reviews.llvm.org/D131938

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


[PATCH] D131919: Move googletest to the third-party directory

2022-08-16 Thread Tom Stellard via Phabricator via cfe-commits
tstellar updated this revision to Diff 453194.
tstellar added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131919

Files:
  clang/CMakeLists.txt
  compiler-rt/CMakeLists.txt
  lld/CMakeLists.txt
  lldb/cmake/modules/LLDBStandalone.cmake
  llvm/CMakeLists.txt
  llvm/cmake/modules/HandleLLVMOptions.cmake
  llvm/utils/unittest/CMakeLists.txt
  llvm/utils/unittest/UnitTestMain/CMakeLists.txt
  llvm/utils/unittest/UnitTestMain/TestMain.cpp
  llvm/utils/unittest/googlemock/LICENSE.txt
  llvm/utils/unittest/googlemock/README.LLVM
  llvm/utils/unittest/googlemock/include/gmock/gmock-actions.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-cardinalities.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-function-mocker.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-generated-actions.h
  
llvm/utils/unittest/googlemock/include/gmock/gmock-generated-function-mockers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-generated-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-more-actions.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-more-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-nice-strict.h
  llvm/utils/unittest/googlemock/include/gmock/gmock-spec-builders.h
  llvm/utils/unittest/googlemock/include/gmock/gmock.h
  
llvm/utils/unittest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h
  llvm/utils/unittest/googlemock/include/gmock/internal/custom/gmock-matchers.h
  llvm/utils/unittest/googlemock/include/gmock/internal/custom/gmock-port.h
  llvm/utils/unittest/googlemock/include/gmock/internal/gmock-internal-utils.h
  llvm/utils/unittest/googlemock/include/gmock/internal/gmock-port.h
  llvm/utils/unittest/googlemock/include/gmock/internal/gmock-pp.h
  llvm/utils/unittest/googlemock/src/gmock-all.cc
  llvm/utils/unittest/googlemock/src/gmock-cardinalities.cc
  llvm/utils/unittest/googlemock/src/gmock-internal-utils.cc
  llvm/utils/unittest/googlemock/src/gmock-matchers.cc
  llvm/utils/unittest/googlemock/src/gmock-spec-builders.cc
  llvm/utils/unittest/googlemock/src/gmock.cc
  llvm/utils/unittest/googletest/LICENSE.TXT
  llvm/utils/unittest/googletest/README.LLVM
  llvm/utils/unittest/googletest/include/gtest/gtest-death-test.h
  llvm/utils/unittest/googletest/include/gtest/gtest-matchers.h
  llvm/utils/unittest/googletest/include/gtest/gtest-message.h
  llvm/utils/unittest/googletest/include/gtest/gtest-param-test.h
  llvm/utils/unittest/googletest/include/gtest/gtest-printers.h
  llvm/utils/unittest/googletest/include/gtest/gtest-spi.h
  llvm/utils/unittest/googletest/include/gtest/gtest-test-part.h
  llvm/utils/unittest/googletest/include/gtest/gtest-typed-test.h
  llvm/utils/unittest/googletest/include/gtest/gtest.h
  llvm/utils/unittest/googletest/include/gtest/gtest_pred_impl.h
  llvm/utils/unittest/googletest/include/gtest/gtest_prod.h
  llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-port.h
  llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest-printers.h
  llvm/utils/unittest/googletest/include/gtest/internal/custom/gtest.h
  llvm/utils/unittest/googletest/include/gtest/internal/custom/raw-ostream.h
  
llvm/utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-filepath.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-internal.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-param-util.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-port-arch.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-port.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-string.h
  llvm/utils/unittest/googletest/include/gtest/internal/gtest-type-util.h
  llvm/utils/unittest/googletest/src/gtest-all.cc
  llvm/utils/unittest/googletest/src/gtest-death-test.cc
  llvm/utils/unittest/googletest/src/gtest-filepath.cc
  llvm/utils/unittest/googletest/src/gtest-internal-inl.h
  llvm/utils/unittest/googletest/src/gtest-matchers.cc
  llvm/utils/unittest/googletest/src/gtest-port.cc
  llvm/utils/unittest/googletest/src/gtest-printers.cc
  llvm/utils/unittest/googletest/src/gtest-test-part.cc
  llvm/utils/unittest/googletest/src/gtest-typed-test.cc
  llvm/utils/unittest/googletest/src/gtest.cc
  mlir/CMakeLists.txt
  polly/CMakeLists.txt
  third-party/unittest/CMakeLists.txt
  third-party/unittest/UnitTestMain/CMakeLists.txt
  third-party/unittest/UnitTestMain/TestMain.cpp
  third-party/unittest/googlemock/LICENSE.txt
  third-party/unittest/googlemock/README.LLVM
  third-party/unittest/googlemock/include/gmock/gmock-actions.h
  third-party/unittest/googlemock/include/gmock/gmock-cardinalities.h
  third-party/unittest/googlemock/include/gmock/gmock-function-mocker.h
  

[PATCH] D131953: [PowerPC][Coroutines] Add tail-call check with context information for coroutines

2022-08-16 Thread Ting Wang via Phabricator via cfe-commits
tingwang marked an inline comment as done.
tingwang added a comment.

In D131953#3727900 , @ChuanqiXu wrote:

> LGTM with comment addressed. Thanks!

Thank you! I'm looking forward to comments from ppc.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131953

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


[PATCH] D131953: [PowerPC][Coroutines] Add tail-call check with context information for coroutines

2022-08-16 Thread Ting Wang via Phabricator via cfe-commits
tingwang updated this revision to Diff 453193.
tingwang added a comment.

For default implementation of `supportsTailCallFor`, return 
`supportsTailCalls()` as suggested in comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131953

Files:
  clang/test/CodeGenCoroutines/pr56329.cpp
  llvm/include/llvm/Analysis/TargetTransformInfo.h
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
  llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h
  llvm/lib/Transforms/Coroutines/CoroSplit.cpp
  llvm/test/Transforms/Coroutines/coro-split-musttail-ppc64le.ll

Index: llvm/test/Transforms/Coroutines/coro-split-musttail-ppc64le.ll
===
--- /dev/null
+++ llvm/test/Transforms/Coroutines/coro-split-musttail-ppc64le.ll
@@ -0,0 +1,74 @@
+; Tests that some target (e.g. ppc) can support tail call under condition.
+; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S \
+; RUN: -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 | FileCheck %s
+; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S \
+; RUN: -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr10 --code-model=medium \
+; RUN: | FileCheck %s --check-prefix=CHECK-PCREL
+
+define void @f() #0 {
+entry:
+  %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
+  %alloc = call i8* @malloc(i64 16) #3
+  %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
+
+  %save = call token @llvm.coro.save(i8* null)
+  %addr1 = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+  %pv1 = bitcast i8* %addr1 to void (i8*)*
+  call fastcc void %pv1(i8* null)
+
+  %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
+  switch i8 %suspend, label %exit [
+i8 0, label %await.ready
+i8 1, label %exit
+  ]
+await.ready:
+  %save2 = call token @llvm.coro.save(i8* null)
+  %addr2 = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+  %pv2 = bitcast i8* %addr2 to void (i8*)*
+  call fastcc void %pv2(i8* null)
+
+  %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
+  switch i8 %suspend2, label %exit [
+i8 0, label %exit
+i8 1, label %exit
+  ]
+exit:
+  call i1 @llvm.coro.end(i8* null, i1 false)
+  ret void
+}
+
+; Verify that in the initial function resume is not marked with musttail.
+; CHECK-LABEL: @f(
+; CHECK: %[[addr1:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+; CHECK-NEXT: %[[pv1:.+]] = bitcast i8* %[[addr1]] to void (i8*)*
+; CHECK-NOT: musttail call fastcc void %[[pv1]](i8* null)
+
+; Verify that ppc target not using PC-Relative addressing in the resume part resume call is not marked with musttail.
+; CHECK-LABEL: @f.resume(
+; CHECK: %[[addr2:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+; CHECK-NEXT: %[[pv2:.+]] = bitcast i8* %[[addr2]] to void (i8*)*
+; CHECK-NEXT: call fastcc void %[[pv2]](i8* null)
+
+; Verify that ppc target using PC-Relative addressing in the resume part resume call is marked with musttail.
+; CHECK-PCREL-LABEL: @f.resume(
+; CHECK-PCREL: %[[addr2:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+; CHECK-PCREL-NEXT: %[[pv2:.+]] = bitcast i8* %[[addr2]] to void (i8*)*
+; CHECK-PCREL-NEXT: musttail call fastcc void %[[pv2]](i8* null)
+; CHECK-PCREL-NEXT: ret void
+
+declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*) #1
+declare i1 @llvm.coro.alloc(token) #2
+declare i64 @llvm.coro.size.i64() #3
+declare i8* @llvm.coro.begin(token, i8* writeonly) #2
+declare token @llvm.coro.save(i8*) #2
+declare i8* @llvm.coro.frame() #3
+declare i8 @llvm.coro.suspend(token, i1) #2
+declare i8* @llvm.coro.free(token, i8* nocapture readonly) #1
+declare i1 @llvm.coro.end(i8*, i1) #2
+declare i8* @llvm.coro.subfn.addr(i8* nocapture readonly, i8) #1
+declare i8* @malloc(i64)
+
+attributes #0 = { presplitcoroutine }
+attributes #1 = { argmemonly nounwind readonly }
+attributes #2 = { nounwind }
+attributes #3 = { nounwind readnone }
Index: llvm/lib/Transforms/Coroutines/CoroSplit.cpp
===
--- llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -1362,7 +1362,7 @@
 // for symmetrical coroutine control transfer (C++ Coroutines TS extension).
 // This transformation is done only in the resume part of the coroutine that has
 // identical signature and calling convention as the coro.resume call.
-static void addMustTailToCoroResumes(Function ) {
+static void addMustTailToCoroResumes(Function , TargetTransformInfo ) {
   bool changed = false;
 
   // Collect potential resume instructions.
@@ -1374,7 +1374,9 @@
 
   // Set musttail on those that are followed by a ret instruction.
   for (CallInst *Call : Resumes)
-if (simplifyTerminatorLeadingToRet(Call->getNextNode())) {
+// Skip 

[PATCH] D131940: [clang-format] Handle comments between access specifier and colon

2022-08-16 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2185f64771f0: [clang-format] Handle comments between access 
specifier and colon (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131940

Files:
  clang/lib/Format/FormatToken.h
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24799,6 +24799,11 @@
"int i;\n"
"};\n",
Style);
+  verifyFormat("class C {\n"
+   "  public /* comment */:\n"
+   "int i;\n"
+   "};",
+   Style);
   verifyFormat("struct S {\n"
"  private:\n"
"class C {\n"
@@ -24827,6 +24832,11 @@
"  int i;\n"
"};\n",
Style);
+  verifyFormat("class C {\n"
+   "   public /**/:\n"
+   "  int i;\n"
+   "};",
+   Style);
 }
 
 TEST_F(FormatTest, LimitlessStringsAndComments) {
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -584,8 +584,12 @@
   }
 
   bool isAccessSpecifier(bool ColonRequired = true) const {
-return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
-   (!ColonRequired || (Next && Next->is(tok::colon)));
+if (!isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private))
+  return false;
+if (!ColonRequired)
+  return true;
+const auto NextNonComment = getNextNonComment();
+return NextNonComment && NextNonComment->is(tok::colon);
   }
 
   bool canBePointerOrReferenceQualifier() const {


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24799,6 +24799,11 @@
"int i;\n"
"};\n",
Style);
+  verifyFormat("class C {\n"
+   "  public /* comment */:\n"
+   "int i;\n"
+   "};",
+   Style);
   verifyFormat("struct S {\n"
"  private:\n"
"class C {\n"
@@ -24827,6 +24832,11 @@
"  int i;\n"
"};\n",
Style);
+  verifyFormat("class C {\n"
+   "   public /**/:\n"
+   "  int i;\n"
+   "};",
+   Style);
 }
 
 TEST_F(FormatTest, LimitlessStringsAndComments) {
Index: clang/lib/Format/FormatToken.h
===
--- clang/lib/Format/FormatToken.h
+++ clang/lib/Format/FormatToken.h
@@ -584,8 +584,12 @@
   }
 
   bool isAccessSpecifier(bool ColonRequired = true) const {
-return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
-   (!ColonRequired || (Next && Next->is(tok::colon)));
+if (!isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private))
+  return false;
+if (!ColonRequired)
+  return true;
+const auto NextNonComment = getNextNonComment();
+return NextNonComment && NextNonComment->is(tok::colon);
   }
 
   bool canBePointerOrReferenceQualifier() const {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2185f64 - [clang-format] Handle comments between access specifier and colon

2022-08-16 Thread via cfe-commits

Author: owenca
Date: 2022-08-16T20:18:21-07:00
New Revision: 2185f64771f039774d54a0be654cce39931580bf

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

LOG: [clang-format] Handle comments between access specifier and colon

Fixes #56740.

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

Added: 


Modified: 
clang/lib/Format/FormatToken.h
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 7d963cf6af7f7..21ed9bb5e04ef 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -584,8 +584,12 @@ struct FormatToken {
   }
 
   bool isAccessSpecifier(bool ColonRequired = true) const {
-return isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private) &&
-   (!ColonRequired || (Next && Next->is(tok::colon)));
+if (!isOneOf(tok::kw_public, tok::kw_protected, tok::kw_private))
+  return false;
+if (!ColonRequired)
+  return true;
+const auto NextNonComment = getNextNonComment();
+return NextNonComment && NextNonComment->is(tok::colon);
   }
 
   bool canBePointerOrReferenceQualifier() const {

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index ef68c528cb5c6..dc450029ccc2d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24799,6 +24799,11 @@ TEST_F(FormatTest, IndentAccessModifiers) {
"int i;\n"
"};\n",
Style);
+  verifyFormat("class C {\n"
+   "  public /* comment */:\n"
+   "int i;\n"
+   "};",
+   Style);
   verifyFormat("struct S {\n"
"  private:\n"
"class C {\n"
@@ -24827,6 +24832,11 @@ TEST_F(FormatTest, IndentAccessModifiers) {
"  int i;\n"
"};\n",
Style);
+  verifyFormat("class C {\n"
+   "   public /**/:\n"
+   "  int i;\n"
+   "};",
+   Style);
 }
 
 TEST_F(FormatTest, LimitlessStringsAndComments) {



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


[PATCH] D131953: [PowerPC][Coroutines] Add tail-call check with context information for coroutines

2022-08-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added a comment.
This revision is now accepted and ready to land.

LGTM with comment addressed. Thanks!




Comment at: llvm/include/llvm/Analysis/TargetTransformInfoImpl.h:346
 
+  bool supportsTailCallFor(const CallBase *CB) const { return true; }
+

The default implementation should return `supportsTailCalls()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131953

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


[PATCH] D131953: [PowerPC][Coroutines] Add tail-call check with context information for coroutines

2022-08-16 Thread Ting Wang via Phabricator via cfe-commits
tingwang updated this revision to Diff 453188.
tingwang added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Update according to comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131953

Files:
  clang/test/CodeGenCoroutines/pr56329.cpp
  llvm/include/llvm/Analysis/TargetTransformInfo.h
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/lib/Analysis/TargetTransformInfo.cpp
  llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
  llvm/lib/Target/PowerPC/PPCTargetTransformInfo.h
  llvm/lib/Transforms/Coroutines/CoroSplit.cpp
  llvm/test/Transforms/Coroutines/coro-split-musttail-ppc64le.ll

Index: llvm/test/Transforms/Coroutines/coro-split-musttail-ppc64le.ll
===
--- /dev/null
+++ llvm/test/Transforms/Coroutines/coro-split-musttail-ppc64le.ll
@@ -0,0 +1,74 @@
+; Tests that some target (e.g. ppc) can support tail call under condition.
+; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S \
+; RUN: -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 | FileCheck %s
+; RUN: opt < %s -passes='cgscc(coro-split),simplifycfg,early-cse' -S \
+; RUN: -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr10 --code-model=medium \
+; RUN: | FileCheck %s --check-prefix=CHECK-PCREL
+
+define void @f() #0 {
+entry:
+  %id = call token @llvm.coro.id(i32 0, i8* null, i8* null, i8* null)
+  %alloc = call i8* @malloc(i64 16) #3
+  %vFrame = call noalias nonnull i8* @llvm.coro.begin(token %id, i8* %alloc)
+
+  %save = call token @llvm.coro.save(i8* null)
+  %addr1 = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+  %pv1 = bitcast i8* %addr1 to void (i8*)*
+  call fastcc void %pv1(i8* null)
+
+  %suspend = call i8 @llvm.coro.suspend(token %save, i1 false)
+  switch i8 %suspend, label %exit [
+i8 0, label %await.ready
+i8 1, label %exit
+  ]
+await.ready:
+  %save2 = call token @llvm.coro.save(i8* null)
+  %addr2 = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+  %pv2 = bitcast i8* %addr2 to void (i8*)*
+  call fastcc void %pv2(i8* null)
+
+  %suspend2 = call i8 @llvm.coro.suspend(token %save2, i1 false)
+  switch i8 %suspend2, label %exit [
+i8 0, label %exit
+i8 1, label %exit
+  ]
+exit:
+  call i1 @llvm.coro.end(i8* null, i1 false)
+  ret void
+}
+
+; Verify that in the initial function resume is not marked with musttail.
+; CHECK-LABEL: @f(
+; CHECK: %[[addr1:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+; CHECK-NEXT: %[[pv1:.+]] = bitcast i8* %[[addr1]] to void (i8*)*
+; CHECK-NOT: musttail call fastcc void %[[pv1]](i8* null)
+
+; Verify that ppc target not using PC-Relative addressing in the resume part resume call is not marked with musttail.
+; CHECK-LABEL: @f.resume(
+; CHECK: %[[addr2:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+; CHECK-NEXT: %[[pv2:.+]] = bitcast i8* %[[addr2]] to void (i8*)*
+; CHECK-NEXT: call fastcc void %[[pv2]](i8* null)
+
+; Verify that ppc target using PC-Relative addressing in the resume part resume call is marked with musttail.
+; CHECK-PCREL-LABEL: @f.resume(
+; CHECK-PCREL: %[[addr2:.+]] = call i8* @llvm.coro.subfn.addr(i8* null, i8 0)
+; CHECK-PCREL-NEXT: %[[pv2:.+]] = bitcast i8* %[[addr2]] to void (i8*)*
+; CHECK-PCREL-NEXT: musttail call fastcc void %[[pv2]](i8* null)
+; CHECK-PCREL-NEXT: ret void
+
+declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*) #1
+declare i1 @llvm.coro.alloc(token) #2
+declare i64 @llvm.coro.size.i64() #3
+declare i8* @llvm.coro.begin(token, i8* writeonly) #2
+declare token @llvm.coro.save(i8*) #2
+declare i8* @llvm.coro.frame() #3
+declare i8 @llvm.coro.suspend(token, i1) #2
+declare i8* @llvm.coro.free(token, i8* nocapture readonly) #1
+declare i1 @llvm.coro.end(i8*, i1) #2
+declare i8* @llvm.coro.subfn.addr(i8* nocapture readonly, i8) #1
+declare i8* @malloc(i64)
+
+attributes #0 = { presplitcoroutine }
+attributes #1 = { argmemonly nounwind readonly }
+attributes #2 = { nounwind }
+attributes #3 = { nounwind readnone }
Index: llvm/lib/Transforms/Coroutines/CoroSplit.cpp
===
--- llvm/lib/Transforms/Coroutines/CoroSplit.cpp
+++ llvm/lib/Transforms/Coroutines/CoroSplit.cpp
@@ -1362,7 +1362,7 @@
 // for symmetrical coroutine control transfer (C++ Coroutines TS extension).
 // This transformation is done only in the resume part of the coroutine that has
 // identical signature and calling convention as the coro.resume call.
-static void addMustTailToCoroResumes(Function ) {
+static void addMustTailToCoroResumes(Function , TargetTransformInfo ) {
   bool changed = false;
 
   // Collect potential resume instructions.
@@ -1374,7 +1374,9 @@
 
   // Set musttail on those that are followed by a ret instruction.
   for (CallInst *Call : Resumes)
-if (simplifyTerminatorLeadingToRet(Call->getNextNode())) {
+// Skip targets 

[PATCH] D129833: Use @llvm.threadlocal.address intrinsic to access TLS

2022-08-16 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D129833#3717291 , @jyknight wrote:

> Note that this change caused LLVM to no longer be aware that a TLS variable 
> cannot be NULL. Thus, code like:
>
>   __thread int x;
>   int main() {
> int* y = 
> return *y;
>   }
>
> built with `clang -O -fsanitize=null` emits a null-pointer check, when it 
> wouldn't previously. I think llvm.threadlocal.address's return value probably 
> ought to be given the nonnull attribute. We also might want to infer other 
> properties of the returned pointer based on knowledge of the global value 
> parameter, such as alignment.
>
> Furthermore, while the above problem should simply be a very minor 
> optimization degradation, in fact it caused miscompiles, due to a 
> pre-existing bug in the X86 backend. I've sent 
> https://reviews.llvm.org/D131716 to fix //that// part of the problem.

The NonNull attribute is added in 
https://github.com/llvm/llvm-project/commit/d68ba43ad24791181280fdb0f34b6be380db7a32.

And I am working on adding Align properties. But I meet problems since the 
alignment of threadlocal_address intrinsic depends on its argument so we can't 
set the alignment for its declaration and we probably need to set the alignment 
for its call, which means we need to set the alignment when in IRBuilder. Do 
you think this is good?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129833

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


[PATCH] D131928: [libcxx][spaceship][doc] Repair links and clean up spaceship progress doc

2022-08-16 Thread Kent Ross via Phabricator via cfe-commits
mumbleskates added a comment.

Sorry! Something has gone horribly wrong with my usage of arcanist and it 
diffed against a very old version of `main`. i will try to repair the reviewers 
list.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131928

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


[PATCH] D131928: [libcxx][spaceship][doc] Repair links and clean up spaceship progress doc

2022-08-16 Thread Kent Ross via Phabricator via cfe-commits
mumbleskates updated this revision to Diff 453186.
mumbleskates added a comment.

- Merge branch 'main' into doc2


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131928

Files:
  libcxx/docs/Status/SpaceshipProjects.csv


Index: libcxx/docs/Status/SpaceshipProjects.csv
===
--- libcxx/docs/Status/SpaceshipProjects.csv
+++ libcxx/docs/Status/SpaceshipProjects.csv
@@ -29,31 +29,31 @@
 | `[unique.ptr.special] `_,| `unique_ptr 
`_,[comparisons.three.way],Adrian 
Vogelsgesang,|Complete|
 | `[util.smartptr.shared.cmp] `_,| 
`shared_ptr `_,[comparisons.three.way],Adrian 
Vogelsgesang,|Complete|
 | `[type.index.members] `_,| `type_index 
`_,None,Adrian Vogelsgesang,|Complete|
-| `[charconv.syn] `_,| 
to_chars_result,None,Mark de Wever,|Complete|
-| `[charconv.syn] `_,| 
from_chars_result,None,Mark de Wever,|Complete|
+| `[charconv.syn] `_,| `to_chars_result 
`_,None,Mark de Wever,|Complete|
+| `[charconv.syn] `_,| `from_chars_result 
`_,None,Mark de Wever,|Complete|
 | `[stacktrace.entry.cmp] `_,| 
stacktrace_entry,None,Unassigned,|Not Started|
 | `[stacktrace.basic.cmp] `_,| 
basic_stacktrace,[alg.three.way],Unassigned,|Not Started|
-| `[string.cmp] `_,| `basic_string 
`,None,Mark de Wever,|Complete|
+| `[string.cmp] `_,| `basic_string 
`_,None,Mark de Wever,|Complete|
 | `[string.view.comparison] `_,| 
`basic_string_view `_,None,Mark de 
Wever,|Complete|
-| `[array.syn] `_ (`general 
`_),| 
array,[expos.only.func],Unassigned,|Not Started|
-| `[deque.syn] `_ (`general 
`_),| 
deque,[expos.only.func],Unassigned,|Not Started|
-| `[forward.list.syn] `_ (`general 
`_),| 
forward_list,[expos.only.func],Unassigned,|Not Started|
-| `[list.syn] `_ (`general 
`_),| 
list,[expos.only.func],Unassigned,|Not Started|
-| `[vector.syn] `_ (`general 
`_),| 
vector,[expos.only.func],Unassigned,|Not Started|
-| `[associative.map.syn] `_ (`general 
`_),"| map
+| `[array.syn] `_ (`general 
`_),| 
array,[expos.only.func],Unassigned,|Not Started|
+| `[deque.syn] `_ (`general 
`_),| 
deque,[expos.only.func],Unassigned,|Not Started|
+| `[forward.list.syn] `_ (`general 
`_),| 
forward_list,[expos.only.func],Unassigned,|Not Started|
+| `[list.syn] `_ (`general 
`_),| 
list,[expos.only.func],Unassigned,|Not Started|
+| `[vector.syn] `_ (`general 
`_),| 
vector,[expos.only.func],Unassigned,|Not Started|
+| `[associative.map.syn] `_ (`general 
`_),"| map
 | multimap",[expos.only.func],Unassigned,|Not Started|
-| `[associative.set.syn] `_ (`general 
`_),"| multiset
+| `[associative.set.syn] `_ (`general 
`_),"| multiset
 | set",[expos.only.func],Unassigned,|Not Started|
 | `[queue.ops] `_,| queue,None,Unassigned,|Not 
Started|
 | `[stack.ops] `_,| stack,None,Unassigned,|Not 
Started|
-| `[reverse.iter.cmp] `_,| 
reverse_iterator,None,Mikhail Maltsev,|Complete|
+| `[reverse.iter.cmp] `_,| 
`reverse_iterator `_,None,Mikhail 
Maltsev,|Complete|
 | 

[PATCH] D131928: [libcxx][spaceship][doc] Repair links and clean up spaceship progress doc

2022-08-16 Thread Kent Ross via Phabricator via cfe-commits
mumbleskates updated this revision to Diff 453184.
mumbleskates added a comment.
Herald added subscribers: Michael137, yota9, ayermolo, StephenFan, sstefan1, 
JDevlieghere, kbarton.
Herald added a reviewer: JDevlieghere.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: aaron.ballman.
Herald added a reviewer: rafauler.
Herald added a reviewer: Amir.
Herald added a reviewer: maksfb.

- Merge remote-tracking branch 'upstream/main' into doc2


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131928

Files:
  bolt/lib/Core/BinaryContext.cpp
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-move/Move.cpp
  clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp
  clang-tools-extra/clangd/URI.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang-tools-extra/pseudo/lib/cxx/cxx.bnf
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Transfer.h
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/AST/Decl.cpp
  clang/lib/Analysis/CFG.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/ReachableCode.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/Driver/ToolChains/Darwin.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/SemaTemplateDeduction.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
  clang/test/CodeGen/bpf-abiinfo.c
  clang/test/CodeGen/debug-info-alias-pointer.c
  clang/test/CodeGen/partial-order-variadic.cpp
  clang/test/CodeGenCXX/debug-info-auto-return.cpp
  clang/test/CodeGenCXX/no_auto_return_lambda.cpp
  clang/test/CodeGenCXX/pragma-init_seg.cpp
  clang/test/CodeGenCXX/threadlocal_address.cpp
  clang/test/Driver/Xarch.c
  clang/test/Driver/apple-kext-mkernel.c
  clang/test/Driver/arc.c
  clang/test/Driver/avr-ld.c
  clang/test/Driver/avr-toolchain.c
  clang/test/Driver/bindings.c
  clang/test/Driver/cc-log-diagnostics.c
  clang/test/Driver/cpp-precomp.c
  clang/test/Driver/darwin-debug-flags.c
  clang/test/Driver/darwin-dsymutil.c
  clang/test/Driver/darwin-iphone-defaults.m
  clang/test/Driver/darwin-stdlib.cpp
  clang/test/Driver/darwin-verify-debug.c
  clang/test/Driver/diagnostics.c
  clang/test/Driver/exceptions.m
  clang/test/Driver/redundant-args.c
  clang/test/Headers/float-darwin.c
  clang/test/Headers/tgmath-darwin.c
  clang/test/PCH/reloc.c
  clang/test/SemaCXX/member-class-11.cpp
  clang/test/SemaCXX/unreachable-code.cpp
  clang/test/SemaCXX/warn-comma-operator.cpp
  clang/test/SemaTemplate/ms-unqualified-base-class.cpp
  clang/test/lit.cfg.py
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp
  clang/unittests/AST/DeclTest.cpp
  clang/unittests/Analysis/CFGBuildResult.h
  clang/unittests/Analysis/CFGTest.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Format/FormatTestJava.cpp
  clang/utils/TableGen/CMakeLists.txt
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
  compiler-rt/CMakeLists.txt
  compiler-rt/lib/fuzzer/FuzzerInternal.h
  compiler-rt/lib/fuzzer/FuzzerLoop.cpp
  compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp
  compiler-rt/lib/msan/msan_report.cpp
  compiler-rt/lib/ubsan/CMakeLists.txt
  flang/CMakeLists.txt
  flang/cmake/modules/AddFlang.cmake
  flang/docs/PolymorphicEntities.md
  flang/lib/Decimal/CMakeLists.txt
  flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
  flang/runtime/CMakeLists.txt
  flang/runtime/FortranMain/CMakeLists.txt
  flang/test/Lower/OpenACC/acc-data-operands.f90
  flang/test/Transforms/simplifyintrinsics.fir
  libc/config/linux/CMakeLists.txt
  libc/config/linux/aarch64/entrypoints.txt
  libc/config/linux/x86_64/entrypoints.txt
  libc/include/llvm-libc-types/CMakeLists.txt
  libc/src/CMakeLists.txt
  libc/src/stdio/printf_core/CMakeLists.txt
  libc/test/src/CMakeLists.txt
  libc/test/src/stdio/printf_core/parser_test.cpp
  libc/utils/UnitTest/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/docs/Status/SpaceshipProjects.csv
  

[PATCH] D131928: [libcxx][spaceship][doc] Repair links and clean up spaceship progress doc

2022-08-16 Thread Kent Ross via Phabricator via cfe-commits
mumbleskates updated this revision to Diff 453183.
mumbleskates added a comment.
Herald added subscribers: cfe-commits, llvm-commits, libc-commits, 
openmp-commits, lldb-commits, Sanitizers, anlunx, mtrofin, Enna1, bzcheeseman, 
kosarev, pmatos, asb, pcwang-thead, arjunp, sdasgup3, luke957, carlosgalvezp, 
wenzhicui, wrengr, armkevincheng, ormris, foad, jsmolens, eric-k256, cota, 
mravishankar, teijeong, frasercrmck, rdzhabarov, ecnelises, tatianashp, wenlei, 
ThomasRaoux, mehdi_amini, jdoerfert, msifontes, jurahul, Kayjukh, grosul1, 
Joonsoo, stephenneuendorffer, kerbowa, liufengdb, aartbik, mgester, 
arpith-jacob, csigg, nicolasvasilache, antiagainst, shauheen, rriddle, 
luismarques, apazos, sameer.abuasal, pengfei, s.egerton, Jim, lebedev.ri, 
kadircet, jocewei, rupprecht, PkmX, arphaman, the_o, brucehoult, MartinMosbeck, 
rogfer01, steven_wu, edward-jones, zzheng, MaskRay, jrtc27, niosHD, sabuasal, 
simoncook, johnrusso, rbar, aheejin, hiraditya, arichardson, sbc100, mgorny, 
nhaehnle, jvesely, nemanjai, emaste, dylanmckay, arsenm, qcolombet, MatzeB.
Herald added a reviewer: lebedev.ri.
Herald added a reviewer: jhenderson.
Herald added a reviewer: antiagainst.
Herald added a reviewer: nicolasvasilache.
Herald added a reviewer: herhut.
Herald added a reviewer: rriddle.
Herald added a reviewer: antiagainst.
Herald added a reviewer: aartbik.
Herald added a reviewer: MaskRay.
Herald added a reviewer: sscalpone.
Herald added a reviewer: aartbik.
Herald added a reviewer: aartbik.
Herald added a reviewer: sjarus.
Herald added a reviewer: clementval.
Herald added a reviewer: bondhugula.
Herald added a reviewer: NoQ.
Herald added a reviewer: dcaballe.
Herald added projects: clang, Sanitizers, LLDB, OpenMP, libc-project, MLIR, 
LLVM, clang-tools-extra, Flang.

- Revert "use a version of the link that does not currently 404 on wg21.link"


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131928

Files:
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-move/Move.cpp
  clang-tools-extra/clang-tidy/objc/NSDateFormatterCheck.cpp
  clang-tools-extra/clangd/URI.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang-tools-extra/clangd/refactor/Rename.cpp
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Expr.h
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/include/clang/Analysis/FlowSensitive/Transfer.h
  clang/lib/AST/Decl.cpp
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/lib/Analysis/ReachableCode.cpp
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
  clang/test/CodeGenCXX/pragma-init_seg.cpp
  clang/test/Driver/avr-ld.c
  clang/test/Driver/avr-toolchain.c
  clang/test/SemaCXX/unreachable-code.cpp
  clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
  compiler-rt/lib/msan/msan_report.cpp
  compiler-rt/lib/ubsan/CMakeLists.txt
  flang/cmake/modules/AddFlang.cmake
  flang/docs/PolymorphicEntities.md
  flang/include/flang/Common/idioms.h
  flang/lib/Decimal/CMakeLists.txt
  flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
  flang/runtime/CMakeLists.txt
  flang/runtime/FortranMain/CMakeLists.txt
  flang/test/Lower/OpenACC/acc-data-operands.f90
  flang/test/Transforms/simplifyintrinsics.fir
  libc/config/linux/aarch64/entrypoints.txt
  libc/config/linux/x86_64/entrypoints.txt
  libc/src/CMakeLists.txt
  libc/src/stdio/printf_core/CMakeLists.txt
  libc/test/src/CMakeLists.txt
  libc/test/src/stdio/printf_core/parser_test.cpp
  libc/utils/UnitTest/CMakeLists.txt
  libcxx/CMakeLists.txt
  libcxx/docs/Status/SpaceshipProjects.csv
  libcxx/include/system_error
  libcxx/test/std/diagnostics/syserr/syserr.compare/cmp_error_code.pass.cpp
  libcxx/test/std/diagnostics/syserr/syserr.compare/cmp_error_condition.pass.cpp
  
libcxx/test/std/diagnostics/syserr/syserr.errcat/syserr.errcat.nonvirtuals/cmp.pass.cpp
  libcxx/test/support/MoveOnly.h
  libcxx/test/support/test_macros.h
  lld/test/ELF/edata-etext.s
  lld/wasm/SyntheticSections.cpp
  lldb/examples/customization/bin-utils/binutils.py
  lldb/examples/customization/import-python/importcmd.py
  lldb/examples/customization/pwd-cd-and-system/utils.py
  lldb/examples/darwin/heap_find/heap.py
  lldb/examples/python/bsd.py
  lldb/examples/python/cmdtemplate.py
  lldb/examples/python/delta.py
  lldb/examples/python/diagnose_nsstring.py
  lldb/examples/python/diagnose_unwind.py
  lldb/examples/python/gdbremote.py
  lldb/examples/python/globals.py
  lldb/examples/python/jump.py
  lldb/examples/python/lldb_module_utils.py
  lldb/examples/python/lldbtk.py
  lldb/examples/python/mach_o.py
  lldb/examples/python/memory.py
  

[clang] da6187f - [Clang] followup D128745, add a missing ClangABICompat check

2022-08-16 Thread Yuanfang Chen via cfe-commits

Author: Yuanfang Chen
Date: 2022-08-16T18:40:00-07:00
New Revision: da6187f566b7881cb8350621aea9bd582de569b9

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

LOG: [Clang] followup D128745, add a missing ClangABICompat check

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CodeGen/partial-order-variadic.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 6836f7c090be2..ac0b3fe8e04a2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2445,6 +2445,9 @@ static bool isSameTemplateArg(ASTContext ,
   if (X.getKind() != Y.getKind())
 return false;
 
+  bool ClangABICompat14 =
+  Context.getLangOpts().getClangABICompat() <= 
LangOptions::ClangABI::Ver14;
+
   switch (X.getKind()) {
 case TemplateArgument::Null:
   llvm_unreachable("Comparing NULL template argument");
@@ -2477,30 +2480,42 @@ static bool isSameTemplateArg(ASTContext ,
 }
 
 case TemplateArgument::Pack:
-  unsigned PackIterationSize = X.pack_size();
-  if (X.pack_size() != Y.pack_size()) {
-if (!PartialOrdering)
+  if (ClangABICompat14) {
+if (X.pack_size() != Y.pack_size())
   return false;
 
-// C++0x [temp.deduct.type]p9:
-// During partial ordering, if Ai was originally a pack expansion:
-// - if P does not contain a template argument corresponding to Ai then
-//   Ai is ignored;
-bool XHasMoreArg = X.pack_size() > Y.pack_size();
-if (!(XHasMoreArg && X.pack_elements().back().isPackExpansion()) &&
-!(!XHasMoreArg && Y.pack_elements().back().isPackExpansion()))
-  return false;
+for (TemplateArgument::pack_iterator XP = X.pack_begin(),
+ XPEnd = X.pack_end(),
+ YP = Y.pack_begin();
+ XP != XPEnd; ++XP, ++YP)
+  if (!isSameTemplateArg(Context, *XP, *YP, PackExpansionMatchesPack))
+return false;
+  } else {
+unsigned PackIterationSize = X.pack_size();
+if (X.pack_size() != Y.pack_size()) {
+  if (!PartialOrdering)
+return false;
+
+  // C++0x [temp.deduct.type]p9:
+  // During partial ordering, if Ai was originally a pack expansion:
+  // - if P does not contain a template argument corresponding to Ai
+  //   then Ai is ignored;
+  bool XHasMoreArg = X.pack_size() > Y.pack_size();
+  if (!(XHasMoreArg && X.pack_elements().back().isPackExpansion()) &&
+  !(!XHasMoreArg && Y.pack_elements().back().isPackExpansion()))
+return false;
+
+  if (XHasMoreArg)
+PackIterationSize = Y.pack_size();
+}
 
-if (XHasMoreArg)
-  PackIterationSize = Y.pack_size();
+ArrayRef XP = X.pack_elements();
+ArrayRef YP = Y.pack_elements();
+for (unsigned i = 0; i < PackIterationSize; ++i)
+  if (!isSameTemplateArg(Context, XP[i], YP[i], PartialOrdering,
+ PackExpansionMatchesPack))
+return false;
   }
-
-  ArrayRef XP = X.pack_elements();
-  ArrayRef YP = Y.pack_elements();
-  for (unsigned i = 0; i < PackIterationSize; ++i)
-if (!isSameTemplateArg(Context, XP[i], YP[i], PartialOrdering,
-   PackExpansionMatchesPack))
-  return false;
   return true;
   }
 

diff  --git a/clang/test/CodeGen/partial-order-variadic.cpp 
b/clang/test/CodeGen/partial-order-variadic.cpp
index 496a7da42208a..9a366c83e222c 100644
--- a/clang/test/CodeGen/partial-order-variadic.cpp
+++ b/clang/test/CodeGen/partial-order-variadic.cpp
@@ -3,20 +3,28 @@
 
 #if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 14
 
+// CHECK-14: %"struct.temp_func_order_example3::S" = type { i8 }
+
 // CHECK-14: define dso_local void @_ZN24temp_func_order_example31hEi(i32 
noundef %i)
-// CHECK-14-NEXT: entry:
-// CHECK-14-NEXT:   %i.addr = alloca i32, align 4
-// CHECK-14-NEXT:   %r = alloca ptr, align 8
-// CHECK-14-NEXT:   store i32 %i, ptr %i.addr, align 4
-// CHECK-14-NEXT:   %call = call noundef nonnull align 4 dereferenceable(4) 
ptr @_ZN24temp_func_order_example31gIiJEEERiPT_DpT0_(ptr noundef %i.addr)
-// CHECK-14-NEXT:   store ptr %call, ptr %r, align 8
-// CHECK-14-NEXT:   ret void
+// CHECK-14-NEXT:  entry:
+// CHECK-14-NEXT:%i.addr = alloca i32, align 4
+// CHECK-14-NEXT:%r = alloca ptr, align 8
+// CHECK-14-NEXT:%a = alloca %"struct.temp_func_order_example3::S", align 1
+// CHECK-14-NEXT:store i32 %i, ptr %i.addr, align 4
+// CHECK-14-NEXT:%call = call noundef 

[PATCH] D131874: [Clang] Tighten restrictions on enum out of range diagnostic to avoid constant initialization

2022-08-16 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

I confirmed that this fixes all remaining issues on our end. Thank you!


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

https://reviews.llvm.org/D131874

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


[PATCH] D128440: [WebAssembly] Initial support for reference type funcref in clang

2022-08-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

It would be good to add tests for more error conditions like in the externref 
patch and also additional errors like trying to apply __funcref to types that 
aren't function pointers.




Comment at: clang/include/clang/Basic/Attr.td:4053
+  let Spellings = [Keyword<"__funcref">];
+  let Documentation = [Undocumented];
+}

It would be good to document this!



Comment at: clang/lib/Sema/SemaChecking.cpp:4525
+  case WebAssembly::BI__builtin_wasm_ref_null_func:
+return (SemaBuiltinWasmRefNullFunc(TheCall));
+  }

Are the extra parentheses meaningful here?



Comment at: clang/lib/Sema/SemaChecking.cpp:6552-6555
+  // The call we get looks like
+  // CallExpr
+  // `- ImplicitCastExpr
+  //   `- DeclRefExpr

How do these parts correspond to the original source code?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128440

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


[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-08-16 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D128745#3727770 , @abrachet wrote:

> In D128745#3727715 , @ychen wrote:
>
>> In D128745#3727697 , @abrachet 
>> wrote:
>>
>>> This is breaking us.
>>>
>>>   template  struct S; // #1
>>>   
>>>   template  struct S {}; // #2
>>>
>>> The following compiled before but is now broken, (we use 
>>> `-fclang-abi-compat=13.0`). We get a warning from 
>>> `-Winvalid-partial-specialization`
>>>
>>> This change _does_ make https://eel.is/c++draft/temp.func.order#example-5 
>>> work, ie for function overload resolution but regresses the type deduction 
>>> example above.
>>>
>>> There seem to be examples in the standard that suggest #2 is more 
>>> specialized. @mcgrathr found 
>>> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1432 and 
>>> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1395 among 
>>> others. WDYT?
>>
>> I tried your test case but was unable to reproduce the issue. Is this the 
>> complete test case? I'm asking because the provided test case does not 
>> involve deduction.
>
> Just that input is enough to get the error. I did `clang++ test.cpp 
> -fsyntax-only -fclang-abi-compat=14.0`

Thanks, it works now. I was missing `-fclang-abi-compat=14.0`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-08-16 Thread Alex Brachet via Phabricator via cfe-commits
abrachet added a comment.

In D128745#3727715 , @ychen wrote:

> In D128745#3727697 , @abrachet 
> wrote:
>
>> This is breaking us.
>>
>>   template  struct S; // #1
>>   
>>   template  struct S {}; // #2
>>
>> The following compiled before but is now broken, (we use 
>> `-fclang-abi-compat=13.0`). We get a warning from 
>> `-Winvalid-partial-specialization`
>>
>> This change _does_ make https://eel.is/c++draft/temp.func.order#example-5 
>> work, ie for function overload resolution but regresses the type deduction 
>> example above.
>>
>> There seem to be examples in the standard that suggest #2 is more 
>> specialized. @mcgrathr found 
>> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1432 and 
>> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1395 among 
>> others. WDYT?
>
> I tried your test case but was unable to reproduce the issue. Is this the 
> complete test case? I'm asking because the provided test case does not 
> involve deduction.

Just that input is enough to get the error. I did `clang++ test.cpp 
-fsyntax-only -fclang-abi-compat=14.0`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-08-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

Very nice! This LGTM with all these small comments addressed. Sorry for the 
long delay in reviewing.




Comment at: clang/include/clang/AST/ASTContext.h:1149
 #include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) CanQualType SingletonId;
+#include "clang/Basic/WebAssemblyReferenceTypes.def"

I have no idea what's going on here in the code, but it seems that the existing 
convention is to put `CanQualType SingletonId;` on a separate line.



Comment at: clang/include/clang/AST/Type.h:1973
+  bool isWebAssemblyReferenceType() const;
+  bool isWebAssemblyExternrefType() const;
   /// Determines if this is a sizeless type supported by the

Looks like there should be a newline here.



Comment at: clang/include/clang/Basic/AddressSpaces.h:59-60
 
+  wasm_var,
+  wasm_externref,
   // This denotes the count of language-specific address spaces and also

What is `wasm_var`? It would be good to have a short comment here (and newline 
afterward).



Comment at: clang/include/clang/Basic/Builtins.def:50
 //  p -> pid_t
+//  e -> wasm externref
 //  . -> "...".  This may only occur at the end of the function list.





Comment at: clang/include/clang/Basic/BuiltinsWebAssembly.def:193
+// Reference Types builtins
+// Some builtins are polymorphic - see 't' as part of the third argument,
+// in which case the argument spec (second argument) is unused.

Looks like this comment about polymorphism is out of date. (Also it would be 
good to add a newline after this.)



Comment at: clang/include/clang/Basic/WebAssemblyReferenceTypes.def:9
+//
+//  This file defines externref_t, funcref_t, and the like.  The macros are:
+//

Maybe we should only mention `externref_t` for now. 



Comment at: clang/lib/AST/ASTContext.cpp:2258
+Width = 0; 
\
+Align = 8; /* ? */ 
\
+break;

I assume things will break if you say 0 here, but would 1 work?



Comment at: clang/lib/AST/ASTContext.cpp:3984
+QualType ASTContext::getExternrefType() const {
+  if (Target->hasFeature("reference-types")) {
+#define WASM_REF_TYPE(Name, MangledName, Id, SingletonId, AS)  
\

Do we need `Target.getTriple().isWasm()` here as well?



Comment at: clang/lib/AST/ItaniumMangle.cpp:3147
+type_name = MangledName;   
\
+Out << (type_name == InternalName ? "u" : "") << type_name.size()  
\
+<< type_name;  
\

Our `MangledName` is not the same as our `InternalName`, so it looks like this 
condition will never be true. Should be follow the simpler pattern from the 
previous two targets instead?



Comment at: clang/lib/Basic/Targets/DirectX.h:44-45
+0, // ptr64
+1, // wasm_var
+10,// wasm_externref
 };

What are these for? I'm surprised we need to do anything here in the DirectX 
target. Same for the similar lines in other targets.



Comment at: clang/lib/CodeGen/CGDebugInfo.cpp:806-807
+  SingletonId =
\
+  DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,   
\
+ MangledName, TheCU, TheCU->getFile(), 0); 
\
+return SingletonId;
\

How did you choose this?



Comment at: clang/lib/CodeGen/TargetInfo.h:353
+  /// Return the WebAssembly externref reference type.
+  virtual llvm::Type *getWasmExternrefReferenceType() const { return nullptr; }
   /// Emit the device-side copy of the builtin surface type.

missing whitespace.



Comment at: clang/test/CodeGen/WebAssembly/wasm-externref.c:11-13
+externref_t get_null() {
+  return __builtin_wasm_ref_null_extern();
+}

Do we need this here since the builtin is also tested in builtins-wasm.c? Are 
there more ways to use `externref_t` that we should test here?



Comment at: clang/test/Sema/wasm-refs-and-tables.c:3
+
+// Note: As WebAssembly references are sizeless types, we don't exhaustively
+// test for cases covered by sizeless-1.c and similar tests.

Should this file be just `wasm-refs.c` since it doesn't do anything with tables 
yet? Same for the next one.



Comment at: clang/test/SemaTemplate/address_space-dependent.cpp:46
 void tooBig() {
-  __attribute__((address_space(I))) int *bounds; // expected-error {{address 
space is larger than the 

[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-08-16 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D128745#3727715 , @ychen wrote:

> In D128745#3727697 , @abrachet 
> wrote:
>
>> This is breaking us.
>>
>>   template  struct S; // #1
>>   
>>   template  struct S {}; // #2
>>
>> The following compiled before but is now broken, (we use 
>> `-fclang-abi-compat=13.0`). We get a warning from 
>> `-Winvalid-partial-specialization`
>>
>> This change _does_ make https://eel.is/c++draft/temp.func.order#example-5 
>> work, ie for function overload resolution but regresses the type deduction 
>> example above.
>>
>> There seem to be examples in the standard that suggest #2 is more 
>> specialized. @mcgrathr found 
>> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1432 and 
>> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1395 among 
>> others. WDYT?
>
> I tried your test case but was unable to reproduce the issue. Is this the 
> complete test case? I'm asking because the provided test case does not 
> involve deduction.

Or do you mean the duction for partial ordering, then I did a simple `S a` 
which seems fine?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-08-16 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added a comment.

In D128745#3727697 , @abrachet wrote:

> This is breaking us.
>
>   template  struct S; // #1
>   
>   template  struct S {}; // #2
>
> The following compiled before but is now broken, (we use 
> `-fclang-abi-compat=13.0`). We get a warning from 
> `-Winvalid-partial-specialization`
>
> This change _does_ make https://eel.is/c++draft/temp.func.order#example-5 
> work, ie for function overload resolution but regresses the type deduction 
> example above.
>
> There seem to be examples in the standard that suggest #2 is more 
> specialized. @mcgrathr found 
> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1432 and 
> https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1395 among 
> others. WDYT?

I tried your test case but was unable to reproduce the issue. Is this the 
complete test case? I'm asking because the provided test case does not involve 
deduction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D131933: DebugInfo: Remove auto return type representation support

2022-08-16 Thread David Blaikie 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 rG06c70e9b998c: DebugInfo: Remove auto return type 
representation support (authored by dblaikie).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131933

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/test/CodeGenCXX/debug-info-auto-return.cpp
  clang/test/CodeGenCXX/no_auto_return_lambda.cpp

Index: clang/test/CodeGenCXX/no_auto_return_lambda.cpp
===
--- clang/test/CodeGenCXX/no_auto_return_lambda.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited %s -o - | FileCheck %s
-
-// We emit "auto" for deduced return types for member functions but we should
-// not emitting "auto" for deduced return types for lambdas call function which
-// will be implmented as operator() in a class type. This test will verify that
-// behavior.
-
-__attribute__((used)) int g() {
-  auto f = []() { return 10; };
-  return f();
-}
-
-// g() is not a member function so we should not emit "auto" for the deduced
-// return type.
-//
-// CHECK: !DISubprogram(name: "g",{{.*}}, type: ![[FUN_TYPE:[0-9]+]],{{.*}}
-// CHECK: ![[FUN_TYPE]] = !DISubroutineType(types: ![[TYPE_NODE:[0-9]+]])
-// CHECK: ![[TYPE_NODE]] = !{![[INT_TYPE:[0-9]+]]}
-// CHECK: ![[INT_TYPE]] = !DIBasicType(name: "int", {{.*}})
-
-// operator() of the local lambda should have the same return type as g()
-//
-// CHECK: distinct !DISubprogram(name: "operator()",{{.*}}, type: ![[FUN_TYPE_LAMBDA:[0-9]+]],{{.*}}
-// CHECK: ![[FUN_TYPE_LAMBDA]] = !DISubroutineType({{.*}}types: ![[TYPE_NODE_LAMBDA:[0-9]+]])
-// CHECK: ![[TYPE_NODE_LAMBDA]] = !{![[INT_TYPE]], {{.*}}
Index: clang/test/CodeGenCXX/debug-info-auto-return.cpp
===
--- clang/test/CodeGenCXX/debug-info-auto-return.cpp
+++ clang/test/CodeGenCXX/debug-info-auto-return.cpp
@@ -2,17 +2,20 @@
 // RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple x86_64-linux-gnu %s -o - \
 // RUN:   -O0 -disable-llvm-passes \
 // RUN:   -debug-info-kind=standalone \
-// RUN: | FileCheck %s
+// RUN: | FileCheck --implicit-check-not="\"auto\"" --implicit-check-not=DISubprogram %s
 
-// CHECK: !DISubprogram(name: "findMax",{{.*}}, type: ![[FUN_TYPE:[0-9]+]],{{.*}}
+// CHECK: !DISubprogram(name: "findMax",{{.*}}, type: [[FUN_TYPE:![0-9]+]], {{.*}}spFlags: DISPFlagDefinition, {{.*}} declaration: [[DECL:![0-9]+]]
 
-// CHECK: ![[FUN_TYPE]] = !DISubroutineType(types: ![[TYPE_NODE:[0-9]+]])
-// CHECK-NEXT: ![[TYPE_NODE]] = !{![[DOUBLE_TYPE:[0-9]+]], {{.*}}
-// CHECK-NEXT: ![[DOUBLE_TYPE]] = !DIBasicType(name: "double", {{.*}})
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "myClass",
+// CHECK-SAME: elements: [[MEMBERS:![0-9]+]],
+
+// CHECK: [[MEMBERS]] = !{}
+
+// CHECK: [[FUN_TYPE]] = !DISubroutineType(types: [[TYPE_NODE:![0-9]+]])
+// CHECK-NEXT: [[TYPE_NODE]] = !{[[DOUBLE_TYPE:![0-9]+]],
+// CHECK-NEXT: [[DOUBLE_TYPE]] = !DIBasicType(name: "double",
+// CHECK: [[DECL]] = !DISubprogram(name: "findMax",{{.*}}, type: [[FUN_TYPE]],
 
-// CHECK: !DISubroutineType(types: ![[TYPE_DECL_NODE:[0-9]+]])
-// CHECK-NEXT: ![[TYPE_DECL_NODE]] = !{![[AUTO_TYPE:[0-9]+]], {{.*}}
-// CHECK-NEXT: ![[AUTO_TYPE]] = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto")
 struct myClass {
   auto findMax();
 };
Index: clang/lib/CodeGen/CGDebugInfo.h
===
--- clang/lib/CodeGen/CGDebugInfo.h
+++ clang/lib/CodeGen/CGDebugInfo.h
@@ -177,7 +177,6 @@
   /// ivars and property accessors.
   llvm::DIType *CreateType(const BuiltinType *Ty);
   llvm::DIType *CreateType(const ComplexType *Ty);
-  llvm::DIType *CreateType(const AutoType *Ty);
   llvm::DIType *CreateType(const BitIntType *Ty);
   llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
   llvm::DIType *CreateQualifiedType(const FunctionProtoType *Ty,
@@ -231,10 +230,10 @@
   /// not updated to include implicit \c this pointer. Use this routine
   /// to get a method type which includes \c this pointer.
   llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
-llvm::DIFile *F, bool decl);
+llvm::DIFile *F);
   llvm::DISubroutineType *
   getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
-llvm::DIFile *Unit, bool decl);
+llvm::DIFile *Unit);
   llvm::DISubroutineType *
   getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
   /// \return debug info descriptor for vtable.
Index: clang/lib/CodeGen/CGDebugInfo.cpp

[clang] 06c70e9 - DebugInfo: Remove auto return type representation support

2022-08-16 Thread David Blaikie via cfe-commits

Author: David Blaikie
Date: 2022-08-17T00:35:05Z
New Revision: 06c70e9b998ca289630ee1629ec09b6dd51b29b9

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

LOG: DebugInfo: Remove auto return type representation support

Seems this complicated lldb sufficiently for some cases that it hasn't
been worth supporting/fixing there - and it so far hasn't provided any
new use cases/value for debug info consumers, so let's remove it until
someone has a use case for it.

(side note: the original implementation of this still had a bug (I
should've caught it in review) that we still didn't produce
auto-returning function declarations in types where the function wasn't
instantiatied (that requires a fix to remove the `if
getContainedAutoType` condition in
`CGDebugInfo::CollectCXXMemberFunctions` - without that, auto returning
functions were still being handled the same as member function templates
and special member functions - never added to the member list, only
attached to the type via the declaration chain from the definition)

Further discussion about this in D123319

This reverts commit 5ff992bca208a0e37ca6338fc735aec6aa848b72: [DEBUG-INFO] 
Change how we handle auto return types for lambda operator() to be consistent 
with gcc

This reverts commit c83602fdf51b2692e3bacb06bf861f20f74e987f: [DWARF5][clang]: 
Added support for DebugInfo generation for auto return type for C++ member 
functions.

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

Added: 


Modified: 
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGDebugInfo.h
clang/test/CodeGenCXX/debug-info-auto-return.cpp

Removed: 
clang/test/CodeGenCXX/no_auto_return_lambda.cpp



diff  --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 0469de766d78c..3d78a13d30aa8 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -883,10 +883,6 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType 
*BT) {
   return DBuilder.createBasicType(BTName, Size, Encoding);
 }
 
-llvm::DIType *CGDebugInfo::CreateType(const AutoType *Ty) {
-  return DBuilder.createUnspecifiedType("auto");
-}
-
 llvm::DIType *CGDebugInfo::CreateType(const BitIntType *Ty) {
 
   StringRef Name = Ty->isUnsigned() ? "unsigned _BitInt" : "_BitInt";
@@ -1647,18 +1643,16 @@ void CGDebugInfo::CollectRecordFields(
 
 llvm::DISubroutineType *
 CGDebugInfo::getOrCreateMethodType(const CXXMethodDecl *Method,
-   llvm::DIFile *Unit, bool decl) {
-  const auto *Func = Method->getType()->castAs();
+   llvm::DIFile *Unit) {
+  const FunctionProtoType *Func = 
Method->getType()->getAs();
   if (Method->isStatic())
 return cast_or_null(
 getOrCreateType(QualType(Func, 0), Unit));
-  return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit, 
decl);
+  return getOrCreateInstanceMethodType(Method->getThisType(), Func, Unit);
 }
 
-llvm::DISubroutineType *
-CGDebugInfo::getOrCreateInstanceMethodType(QualType ThisPtr,
-   const FunctionProtoType *Func,
-   llvm::DIFile *Unit, bool decl) {
+llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
+QualType ThisPtr, const FunctionProtoType *Func, llvm::DIFile *Unit) {
   FunctionProtoType::ExtProtoInfo EPI = Func->getExtProtoInfo();
   Qualifiers  = EPI.TypeQuals;
   Qc.removeConst();
@@ -1681,20 +1675,9 @@ CGDebugInfo::getOrCreateInstanceMethodType(QualType 
ThisPtr,
   assert(Args.size() && "Invalid number of arguments!");
 
   SmallVector Elts;
+
   // First element is always return type. For 'void' functions it is NULL.
-  QualType temp = Func->getReturnType();
-  if (temp->getTypeClass() == Type::Auto && decl) {
-const AutoType *AT = cast(temp);
-
-// It may be tricky in some cases to link the specification back the lambda
-// call operator and so we skip emitting "auto" for lambdas. This is
-// consistent with gcc as well.
-if (AT->isDeduced() && ThisPtr->getPointeeCXXRecordDecl()->isLambda())
-  Elts.push_back(getOrCreateType(AT->getDeducedType(), Unit));
-else
-  Elts.push_back(CreateType(AT));
-  } else
-Elts.push_back(Args[0]);
+  Elts.push_back(Args[0]);
 
   // "this" pointer is always first argument.
   const CXXRecordDecl *RD = ThisPtr->getPointeeCXXRecordDecl();
@@ -1747,7 +1730,7 @@ llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
   isa(Method) || isa(Method);
 
   StringRef MethodName = getFunctionName(Method);
-  llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit, true);
+  llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit);
 
   // Since a single ctor/dtor corresponds 

[PATCH] D128745: [c++] implements DR692, DR1395 and tentatively DR1432, about partial ordering of variadic template partial specialization or function template

2022-08-16 Thread Alex Brachet via Phabricator via cfe-commits
abrachet added subscribers: mcgrathr, abrachet.
abrachet added a comment.

This is breaking us.

  template  struct S; // #1
  
  template  struct S {}; // #2

The following compiled before but is now broken, (we use 
`-fclang-abi-compat=13.0`). We get a warning from 
`-Winvalid-partial-specialization`

This change _does_ make https://eel.is/c++draft/temp.func.order#example-5 work, 
ie for function overload resolution but regresses the type deduction example 
above.

There seem to be examples in the standard that suggest #2 is more specialized. 
@mcgrathr found 
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1432 and 
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1395 among 
others. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128745

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


[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

2022-08-16 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

(still a fair few unhandled comments from the last round - guess work to 
address those is still ongoing)




Comment at: llvm/include/llvm/Support/Compression.h:95-98
+  static CompressionSpecRef Unknown;
+  static CompressionSpecRef None;
+  static CompressionSpecRef Zlib;
+  static CompressionSpecRef ZStd;

ckissane wrote:
> dblaikie wrote:
> > Generally we don't want more variables that need global constructors in 
> > LLVM - so these should probably be function-local statics in functions 
> > instead.
> > (I don't think we need a CompressionSpecRef for `Unknown` or `None`, though)
> these are just shortcuts to the function local statics of `CompressionSpecRef 
> getCompressionSpec(uint8_t Kind)`
Yeah, though they're still globals with non-trivial construction, which is to 
be avoided in LLVM ( 
https://llvm.org/docs/CodingStandards.html#do-not-use-static-constructors )

So they should either be removed (I think that's probably the right tradeoff, 
and the one I showed in my proposal - callers that want only one specific 
compression algorithm can pay the small runtime overhead of going through the 
switch unnecessarily) or replaced with global functions that use function local 
statics so the initialization is only paid when the functions are called, and 
not by every program that links in LLVM for any reason.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131992

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


[PATCH] D132003: [clang][ARM][NFC] Clean up signed conversion and undefined macros in builtin header

2022-08-16 Thread Dominic Chen via Phabricator via cfe-commits
ddcc created this revision.
ddcc added reviewers: tmatheson, javed.absar, SjoerdMeijer.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
ddcc requested review of this revision.
Herald added a project: clang.

These warnings were identified while debugging modules with Wsystem-headers.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132003

Files:
  clang/lib/Headers/arm_acle.h

Index: clang/lib/Headers/arm_acle.h
===
--- clang/lib/Headers/arm_acle.h
+++ clang/lib/Headers/arm_acle.h
@@ -64,7 +64,7 @@
 }
 #endif
 
-#if __ARM_32BIT_STATE
+#if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
 #define __dbg(t) __builtin_arm_dbg(t)
 #endif
 
@@ -82,7 +82,7 @@
 /* 8.6.1 Data prefetch */
 #define __pld(addr) __pldx(0, 0, 0, addr)
 
-#if __ARM_32BIT_STATE
+#if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
 #define __pldx(access_kind, cache_level, retention_policy, addr) \
   __builtin_arm_prefetch(addr, access_kind, 1)
 #else
@@ -93,7 +93,7 @@
 /* 8.6.2 Instruction prefetch */
 #define __pli(addr) __plix(0, 0, addr)
 
-#if __ARM_32BIT_STATE
+#if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
 #define __plix(cache_level, retention_policy, addr) \
   __builtin_arm_prefetch(addr, 0, 0)
 #else
@@ -140,17 +140,17 @@
 /* CLZ */
 static __inline__ uint32_t __attribute__((__always_inline__, __nodebug__))
 __clz(uint32_t __t) {
-  return __builtin_clz(__t);
+  return (uint32_t)__builtin_clz(__t);
 }
 
 static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
 __clzl(unsigned long __t) {
-  return __builtin_clzl(__t);
+  return (unsigned long)__builtin_clzl(__t);
 }
 
 static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
 __clzll(uint64_t __t) {
-  return __builtin_clzll(__t);
+  return (uint64_t)__builtin_clzll(__t);
 }
 
 /* CLS */
@@ -201,7 +201,7 @@
 
 static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
 __rev16ll(uint64_t __t) {
-  return (((uint64_t)__rev16(__t >> 32)) << 32) | __rev16(__t);
+  return (((uint64_t)__rev16(__t >> 32)) << 32) | (uint64_t)__rev16((uint32_t)__t);
 }
 
 static __inline__ unsigned long __attribute__((__always_inline__, __nodebug__))
@@ -216,7 +216,7 @@
 /* REVSH */
 static __inline__ int16_t __attribute__((__always_inline__, __nodebug__))
 __revsh(int16_t __t) {
-  return __builtin_bswap16(__t);
+  return (int16_t)__builtin_bswap16((int16_t)__t);
 }
 
 /* RBIT */
@@ -227,7 +227,7 @@
 
 static __inline__ uint64_t __attribute__((__always_inline__, __nodebug__))
 __rbitll(uint64_t __t) {
-#if __ARM_32BIT_STATE
+#if defined(__ARM_32BIT_STATE) && __ARM_32BIT_STATE
   return (((uint64_t)__builtin_arm_rbit(__t)) << 32) |
  __builtin_arm_rbit(__t >> 32);
 #else
@@ -247,7 +247,7 @@
 /*
  * 9.3 16-bit multiplications
  */
-#if __ARM_FEATURE_DSP
+#if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__,__nodebug__))
 __smulbb(int32_t __a, int32_t __b) {
   return __builtin_arm_smulbb(__a, __b);
@@ -281,13 +281,13 @@
  * intrinsics are implemented and the flag is enabled.
  */
 /* 9.4.1 Width-specified saturation intrinsics */
-#if __ARM_FEATURE_SAT
+#if defined(__ARM_FEATURE_SAT) && __ARM_FEATURE_SAT
 #define __ssat(x, y) __builtin_arm_ssat(x, y)
 #define __usat(x, y) __builtin_arm_usat(x, y)
 #endif
 
 /* 9.4.2 Saturating addition and subtraction intrinsics */
-#if __ARM_FEATURE_DSP
+#if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __qadd(int32_t __t, int32_t __v) {
   return __builtin_arm_qadd(__t, __v);
@@ -305,7 +305,7 @@
 #endif
 
 /* 9.4.3 Accumultating multiplications */
-#if __ARM_FEATURE_DSP
+#if defined(__ARM_FEATURE_DSP) && __ARM_FEATURE_DSP
 static __inline__ int32_t __attribute__((__always_inline__, __nodebug__))
 __smlabb(int32_t __a, int32_t __b, int32_t __c) {
   return __builtin_arm_smlabb(__a, __b, __c);
@@ -334,13 +334,13 @@
 
 
 /* 9.5.4 Parallel 16-bit saturation */
-#if __ARM_FEATURE_SIMD32
+#if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32
 #define __ssat16(x, y) __builtin_arm_ssat16(x, y)
 #define __usat16(x, y) __builtin_arm_usat16(x, y)
 #endif
 
 /* 9.5.5 Packing and unpacking */
-#if __ARM_FEATURE_SIMD32
+#if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32
 typedef int32_t int8x4_t;
 typedef int32_t int16x2_t;
 typedef uint32_t uint8x4_t;
@@ -365,7 +365,7 @@
 #endif
 
 /* 9.5.6 Parallel selection */
-#if __ARM_FEATURE_SIMD32
+#if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32
 static __inline__ uint8x4_t __attribute__((__always_inline__, __nodebug__))
 __sel(uint8x4_t __a, uint8x4_t __b) {
   return __builtin_arm_sel(__a, __b);
@@ -373,7 +373,7 @@
 #endif
 
 /* 9.5.7 Parallel 8-bit addition and subtraction */
-#if __ARM_FEATURE_SIMD32
+#if defined(__ARM_FEATURE_SIMD32) && __ARM_FEATURE_SIMD32
 static __inline__ int8x4_t 

[PATCH] D132001: [clang-format] Fix regressions in WhitespaceSensitiveMacros

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

Fixes https://github.com/llvm/llvm-project/issues/54522.
Fixes https://github.com/llvm/llvm-project/issues/57158.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D132001

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -273,6 +273,19 @@
   EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
+  FormatStyle Style = getLLVMStyle();
+  Style.WhitespaceSensitiveMacros.push_back("FOO");
+
+  auto Tokens = annotate("FOO(1+2 )\n", Style);
+  EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_UntouchableMacroFunc);
+
+  Tokens = annotate("FOO(a:b:c)\n", Style);
+  EXPECT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_UntouchableMacroFunc);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsLBracesInMacroDefinition) {
   auto Tokens = annotate("#define BEGIN NS {");
   EXPECT_EQ(Tokens.size(), 6u) << Tokens;
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23807,6 +23807,10 @@
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");
 
+  // Newlines are important here.
+  verifyFormat("FOO(1+2 )\n", Style);
+  verifyFormat("FOO(a:b:c)\n", Style);
+
   // Don't use the helpers here, since 'mess up' will change the whitespace
   // and these are all whitespace sensitive by definition
   EXPECT_EQ("FOO(String-ized+But(: :Still)=Intentional);",
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2007,7 +2007,8 @@
 
 if (FollowedByNewline && (Text.size() >= 5 || FunctionLike) &&
 tokenCanStartNewLine(*FormatTok) && Text == Text.upper()) {
-  PreviousToken->setFinalizedType(TT_FunctionLikeOrFreestandingMacro);
+  if (PreviousToken->isNot(TT_UntouchableMacroFunc))
+
PreviousToken->setFinalizedType(TT_FunctionLikeOrFreestandingMacro);
   addUnwrappedLine();
   return;
 }


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -273,6 +273,19 @@
   EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) {
+  FormatStyle Style = getLLVMStyle();
+  Style.WhitespaceSensitiveMacros.push_back("FOO");
+
+  auto Tokens = annotate("FOO(1+2 )\n", Style);
+  EXPECT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_UntouchableMacroFunc);
+
+  Tokens = annotate("FOO(a:b:c)\n", Style);
+  EXPECT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_UntouchableMacroFunc);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsLBracesInMacroDefinition) {
   auto Tokens = annotate("#define BEGIN NS {");
   EXPECT_EQ(Tokens.size(), 6u) << Tokens;
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -23807,6 +23807,10 @@
   FormatStyle Style = getLLVMStyle();
   Style.WhitespaceSensitiveMacros.push_back("FOO");
 
+  // Newlines are important here.
+  verifyFormat("FOO(1+2 )\n", Style);
+  verifyFormat("FOO(a:b:c)\n", Style);
+
   // Don't use the helpers here, since 'mess up' will change the whitespace
   // and these are all whitespace sensitive by definition
   EXPECT_EQ("FOO(String-ized+But(: :Still)=Intentional);",
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -2007,7 +2007,8 @@
 
 if (FollowedByNewline && (Text.size() >= 5 || FunctionLike) &&
 tokenCanStartNewLine(*FormatTok) && Text == Text.upper()) {
-  PreviousToken->setFinalizedType(TT_FunctionLikeOrFreestandingMacro);
+  if (PreviousToken->isNot(TT_UntouchableMacroFunc))
+

[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Oleg Smolsky via Phabricator via cfe-commits
oleg.smolsky marked 3 inline comments as done.
oleg.smolsky added a comment.

In D131985#3727568 , @Eugene.Zelenko 
wrote:

> In D131985#3727544 , @oleg.smolsky 
> wrote:
>
>> In D131985#3727436 , @njames93 
>> wrote:
>>
>>> The idea of this check is good, but restricting it to only return 
>>> statements seems baffling. A general check that could remove useless parens 
>>> would have a lot more value.
>>
>> Of course a more general check would be more generally useful. Yet that 
>> requires a lot more code as handling many more contexts in involved in C++.
>>
>> Basically this change addresses a concrete, somewhat wide-spread silly habit 
>> that exists in the wild.
>
> I recently observed in the wild patterns like:
>
>   std::vector data;
>   
>   for (std::vector::iterator it = data.begin(); it != 
> data.end(); ++it)
> std::cout << (*it) << std::endl;

While I have not seen that one, I've seen something similar, with even more 
involved syntax:

  for (auto it = data.begin(); it != data.end(); ++it)
 std::cout << (*it).something << std::endl;

people write wild syntax...


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

https://reviews.llvm.org/D131985

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


[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

In D131985#3727544 , @oleg.smolsky 
wrote:

> In D131985#3727436 , @njames93 
> wrote:
>
>> The idea of this check is good, but restricting it to only return statements 
>> seems baffling. A general check that could remove useless parens would have 
>> a lot more value.
>
> Of course a more general check would be more generally useful. Yet that 
> requires a lot more code as handling many more contexts in involved in C++.
>
> Basically this change addresses a concrete, somewhat wide-spread silly habit 
> that exists in the wild.

I recently observed in the wild patterns like:

  std::vector data;
  
  for (std::vector::iterator it = data.begin(); it != data.end(); 
++it)
std::cout << (*it) << std::endl;


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

https://reviews.llvm.org/D131985

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


[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Oleg Smolsky via Phabricator via cfe-commits
oleg.smolsky marked 3 inline comments as done.
oleg.smolsky added a comment.

Thanks for the quick review, Eugene!




Comment at: clang-tools-extra/docs/ReleaseNotes.rst:110
+
+  Checks for `return` statements with redundant parenthesis.
+

Eugene.Zelenko wrote:
> Please use double back-ticks for language constructs.
Done.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst:4
+readability-return-with-redundant-parens
+=
+

Eugene.Zelenko wrote:
> Please make same length as check name.
Done



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst:6
+
+Checks for `return` statements with redundant parenthesis.
+

Eugene.Zelenko wrote:
> Please use double back-ticks for language constructs.
Done.


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

https://reviews.llvm.org/D131985

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


[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Oleg Smolsky via Phabricator via cfe-commits
oleg.smolsky updated this revision to Diff 453157.
oleg.smolsky added a comment.

Improve mark up in the docs.


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

https://reviews.llvm.org/D131985

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
  clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp

Index: clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-return-with-redundant-parens %t
+
+int good() {
+  return 1;
+}
+
+int simple1() {
+  return (1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
+
+int complex1() {
+  int a = 0;
+  return (a + a * (a + a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return a + a * (a + a);{{$}}
+}
+
+int no_space() {
+  return(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - readability-return-with-redundant-parens
+
+readability-return-with-redundant-parens
+
+
+Checks for ``return`` statements with redundant parenthesis.
+
+Example
+---
+
+.. code-block:: c++
+
+  void f() {
+return (1);  // Note, the parenthesis here are redundant.
+  }
+
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -353,6 +353,7 @@
`readability-redundant-smartptr-get `_, "Yes"
`readability-redundant-string-cstr `_, "Yes"
`readability-redundant-string-init `_, "Yes"
+   `readability-return-with-redundant-parens `_, "Yes"
`readability-simplify-boolean-expr `_, "Yes"
`readability-simplify-subscript-expr `_, "Yes"
`readability-static-accessed-through-instance `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -104,6 +104,11 @@
 
   Warns when a struct or class uses const or reference (lvalue or rvalue) data members.
 
+- New :doc:`readability-return-with-redundant-parens
+  ` check.
+
+  Checks for ``return`` statements with redundant parenthesis.
+
 New check aliases
 ^
 
Index: clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
@@ -0,0 +1,38 @@
+//===--- ReturnWithRedundantParensCheck.h - clang-tidy --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find and remove redundant parenthesis surrounding returned expression.
+///
+/// Examples:
+/// \code
+///   void f() { return (1); } ==> void f() { return 1; }
+/// \endcode
+class ReturnWithRedundantParensCheck : public ClangTidyCheck {
+public:
+  ReturnWithRedundantParensCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // 

[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Oleg Smolsky via Phabricator via cfe-commits
oleg.smolsky added a comment.

In D131985#3727436 , @njames93 wrote:

> The idea of this check is good, but restricting it to only return statements 
> seems baffling. A general check that could remove useless parens would have a 
> lot more value.

Of course a more general check would be more generally useful. Yet that 
requires a lot more code as handling many more contexts in involved in C++.

Basically this change addresses a concrete, somewhat wide-spread silly habit 
that exists in the wild.


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

https://reviews.llvm.org/D131985

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


[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tools-extra/docs/ReleaseNotes.rst:110
+
+  Checks for `return` statements with redundant parenthesis.
+

Please use double back-ticks for language constructs.


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

https://reviews.llvm.org/D131985

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


[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Oleg Smolsky via Phabricator via cfe-commits
oleg.smolsky updated this revision to Diff 453155.
oleg.smolsky added a comment.

Add a release note.


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

https://reviews.llvm.org/D131985

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
  clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp

Index: clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-return-with-redundant-parens %t
+
+int good() {
+  return 1;
+}
+
+int simple1() {
+  return (1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
+
+int complex1() {
+  int a = 0;
+  return (a + a * (a + a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return a + a * (a + a);{{$}}
+}
+
+int no_space() {
+  return(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - readability-return-with-redundant-parens
+
+readability-return-with-redundant-parens
+=
+
+Checks for `return` statements with redundant parenthesis.
+
+Example
+---
+
+.. code-block:: c++
+
+  void f() {
+return (1);  // Note, the parenthesis here are redundant.
+  }
+
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -353,6 +353,7 @@
`readability-redundant-smartptr-get `_, "Yes"
`readability-redundant-string-cstr `_, "Yes"
`readability-redundant-string-init `_, "Yes"
+   `readability-return-with-redundant-parens `_, "Yes"
`readability-simplify-boolean-expr `_, "Yes"
`readability-simplify-subscript-expr `_, "Yes"
`readability-static-accessed-through-instance `_, "Yes"
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -104,6 +104,11 @@
 
   Warns when a struct or class uses const or reference (lvalue or rvalue) data members.
 
+- New :doc:`readability-return-with-redundant-parens
+  ` check.
+
+  Checks for `return` statements with redundant parenthesis.
+
 New check aliases
 ^
 
Index: clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
@@ -0,0 +1,38 @@
+//===--- ReturnWithRedundantParensCheck.h - clang-tidy --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find and remove redundant parenthesis surrounding returned expression.
+///
+/// Examples:
+/// \code
+///   void f() { return (1); } ==> void f() { return 1; }
+/// \endcode
+class ReturnWithRedundantParensCheck : public ClangTidyCheck {
+public:
+  ReturnWithRedundantParensCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // 

[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Entry in Release Notes is still missing.




Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst:4
+readability-return-with-redundant-parens
+=
+

Please make same length as check name.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst:6
+
+Checks for `return` statements with redundant parenthesis.
+

Please use double back-ticks for language constructs.


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

https://reviews.llvm.org/D131985

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


[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Oleg Smolsky via Phabricator via cfe-commits
oleg.smolsky updated this revision to Diff 453151.
oleg.smolsky added a comment.

Add docs.


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

https://reviews.llvm.org/D131985

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
  clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp

Index: clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-return-with-redundant-parens %t
+
+int good() {
+  return 1;
+}
+
+int simple1() {
+  return (1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
+
+int complex1() {
+  int a = 0;
+  return (a + a * (a + a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return a + a * (a + a);{{$}}
+}
+
+int no_space() {
+  return(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
Index: clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
===
--- /dev/null
+++ clang-tools-extra/docs/clang-tidy/checks/readability/return-with-redundant-parens.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - readability-return-with-redundant-parens
+
+readability-return-with-redundant-parens
+=
+
+Checks for `return` statements with redundant parenthesis.
+
+Example
+---
+
+.. code-block:: c++
+
+  void f() {
+return (1);  // Note, the parenthesis here are redundant.
+  }
+
Index: clang-tools-extra/docs/clang-tidy/checks/list.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -353,6 +353,7 @@
`readability-redundant-smartptr-get `_, "Yes"
`readability-redundant-string-cstr `_, "Yes"
`readability-redundant-string-init `_, "Yes"
+   `readability-return-with-redundant-parens `_, "Yes"
`readability-simplify-boolean-expr `_, "Yes"
`readability-simplify-subscript-expr `_, "Yes"
`readability-static-accessed-through-instance `_, "Yes"
Index: clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
@@ -0,0 +1,38 @@
+//===--- ReturnWithRedundantParensCheck.h - clang-tidy --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find and remove redundant parenthesis surrounding returned expression.
+///
+/// Examples:
+/// \code
+///   void f() { return (1); } ==> void f() { return 1; }
+/// \endcode
+class ReturnWithRedundantParensCheck : public ClangTidyCheck {
+public:
+  ReturnWithRedundantParensCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
Index: clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
@@ -0,0 +1,68 @@
+//===--- ReturnWithRedundantParensCheck.cpp - clang-tidy *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open 

[PATCH] D131598: [Clang][BPF]: Force sign/zero extension for return values in caller

2022-08-16 Thread Yonghong Song 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 rGd9198f64d9be: [Clang][BPF]: Force sign/zero extension for 
return values in caller (authored by yonghong-song).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131598

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/bpf-abiinfo.c


Index: clang/test/CodeGen/bpf-abiinfo.c
===
--- /dev/null
+++ clang/test/CodeGen/bpf-abiinfo.c
@@ -0,0 +1,24 @@
+// REQUIRES: bpf-registered-target
+// RUN: %clang_cc1 -triple bpf -O2 -emit-llvm -disable-llvm-passes %s -o - | 
FileCheck %s
+
+_Bool bar_bool(void);
+unsigned char bar_char(void);
+short bar_short(void);
+int bar_int(void);
+
+int foo_bool(void) {
+if (bar_bool() != 1) return 0; else return 1;
+}
+// CHECK: %call = call i1 @bar_bool()
+int foo_char(void) {
+if (bar_char() != 10) return 0; else return 1;
+}
+// CHECK: %call = call i8 @bar_char()
+int foo_short(void) {
+if (bar_short() != 10) return 0; else return 1;
+}
+// CHECK: %call = call i16 @bar_short()
+int foo_int(void) {
+if (bar_int() != 10) return 0; else return 1;
+}
+// CHECK: %call = call i32 @bar_int()
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -11499,6 +11499,56 @@
 };
 } // end anonymous namespace
 
+//===--===//
+// BPF ABI Implementation
+//===--===//
+
+namespace {
+
+class BPFABIInfo : public DefaultABIInfo {
+public:
+  BPFABIInfo(CodeGenTypes ) : DefaultABIInfo(CGT) {}
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const {
+if (RetTy->isVoidType())
+  return ABIArgInfo::getIgnore();
+
+if (isAggregateTypeForABI(RetTy))
+  return getNaturalAlignIndirect(RetTy);
+
+// Treat an enum type as its underlying type.
+if (const EnumType *EnumTy = RetTy->getAs())
+  RetTy = EnumTy->getDecl()->getIntegerType();
+
+ASTContext  = getContext();
+if (const auto *EIT = RetTy->getAs())
+  if (EIT->getNumBits() > Context.getTypeSize(Context.Int128Ty))
+return getNaturalAlignIndirect(RetTy);
+
+// Caller will do necessary sign/zero extension.
+return ABIArgInfo::getDirect();
+  }
+
+  void computeInfo(CGFunctionInfo ) const override {
+FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+for (auto  : FI.arguments())
+  I.info = classifyArgumentType(I.type);
+  }
+
+};
+
+class BPFTargetCodeGenInfo : public TargetCodeGenInfo {
+public:
+  BPFTargetCodeGenInfo(CodeGenTypes )
+  : TargetCodeGenInfo(std::make_unique(CGT)) {}
+
+  const BPFABIInfo () const {
+return static_cast(TargetCodeGenInfo::getABIInfo());
+  }
+};
+
+}
+
 
//===--===//
 // Driver code
 
//===--===//
@@ -11727,6 +11777,9 @@
   : hasFP64   ? 64
   : 32));
   }
+  case llvm::Triple::bpfeb:
+  case llvm::Triple::bpfel:
+return SetCGInfo(new BPFTargetCodeGenInfo(Types));
   }
 }
 


Index: clang/test/CodeGen/bpf-abiinfo.c
===
--- /dev/null
+++ clang/test/CodeGen/bpf-abiinfo.c
@@ -0,0 +1,24 @@
+// REQUIRES: bpf-registered-target
+// RUN: %clang_cc1 -triple bpf -O2 -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
+
+_Bool bar_bool(void);
+unsigned char bar_char(void);
+short bar_short(void);
+int bar_int(void);
+
+int foo_bool(void) {
+if (bar_bool() != 1) return 0; else return 1;
+}
+// CHECK: %call = call i1 @bar_bool()
+int foo_char(void) {
+if (bar_char() != 10) return 0; else return 1;
+}
+// CHECK: %call = call i8 @bar_char()
+int foo_short(void) {
+if (bar_short() != 10) return 0; else return 1;
+}
+// CHECK: %call = call i16 @bar_short()
+int foo_int(void) {
+if (bar_int() != 10) return 0; else return 1;
+}
+// CHECK: %call = call i32 @bar_int()
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -11499,6 +11499,56 @@
 };
 } // end anonymous namespace
 
+//===--===//
+// BPF ABI Implementation
+//===--===//
+
+namespace {
+
+class BPFABIInfo : public DefaultABIInfo {
+public:
+  BPFABIInfo(CodeGenTypes ) : DefaultABIInfo(CGT) {}

[clang] d9198f6 - [Clang][BPF]: Force sign/zero extension for return values in caller

2022-08-16 Thread Yonghong Song via cfe-commits

Author: Yonghong Song
Date: 2022-08-16T16:08:01-07:00
New Revision: d9198f64d9be149acdad109cd053b6acdd9635d2

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

LOG: [Clang][BPF]: Force sign/zero extension for return values in caller

Currently bpf supports calling kernel functions (x86_64, arm64, etc.)
in bpf programs. Tejun discovered a problem where the x86_64 func
return value (a unsigned char type) is stored in 8-bit subregister %al
and the other 56-bits in %rax might be garbage. But based on current
bpf ABI, the bpf program assumes the whole %rax holds the correct value
as the callee is supposed to do necessary sign/zero extension.
This mismatch between bpf and x86_64 caused the incorrect results.

To resolve this problem, this patch forced caller to do needed
sign/zero extension for 8/16-bit return values as well. Note that
32-bit return values already had sign/zero extension even without
this patch.

For example, for the test case attached to this patch:

  $  cat t.c
  _Bool bar_bool(void);
  unsigned char bar_char(void);
  short bar_short(void);
  int bar_int(void);
  int foo_bool(void) {
if (bar_bool() != 1) return 0; else return 1;
  }
  int foo_char(void) {
if (bar_char() != 10) return 0; else return 1;
  }
  int foo_short(void) {
if (bar_short() != 10) return 0; else return 1;
  }
  int foo_int(void) {
if (bar_int() != 10) return 0; else return 1;
  }

Without this patch, generated call insns in IR looks like:
%call = call zeroext i1 @bar_bool()
%call = call zeroext i8 @bar_char()
%call = call signext i16 @bar_short()
%call = call i32 @bar_int()
So it is assumed that zero extension has been done for return values of
bar_bool()and bar_char(). Sign extension has been done for the return
value of bar_short(). The return value of bar_int() does not have any
assumption so caller needs to do necessary shifting to get correct
32bit values.

With this patch, generated call insns in IR looks like:
%call = call i1 @bar_bool()
%call = call i8 @bar_char()
%call = call i16 @bar_short()
%call = call i32 @bar_int()
There are no assumptions for return values of the above four function calls,
so necessary shifting is necessary for all of them.

The following is the objdump file difference for function foo_char().
Without this patch:
  0010 :
   2:   85 10 00 00 ff ff ff ff call -1
   3:   bf 01 00 00 00 00 00 00 r1 = r0
   4:   b7 00 00 00 01 00 00 00 r0 = 1
   5:   15 01 01 00 0a 00 00 00 if r1 == 10 goto +1 
   6:   b7 00 00 00 00 00 00 00 r0 = 0
  0038 :
   7:   95 00 00 00 00 00 00 00 exit

With this patch:
  0018 :
   3:   85 10 00 00 ff ff ff ff call -1
   4:   bf 01 00 00 00 00 00 00 r1 = r0
   5:   57 01 00 00 ff 00 00 00 r1 &= 255
   6:   b7 00 00 00 01 00 00 00 r0 = 1
   7:   15 01 01 00 0a 00 00 00 if r1 == 10 goto +1 
   8:   b7 00 00 00 00 00 00 00 r0 = 0
  0048 :
   9:   95 00 00 00 00 00 00 00 exit
The zero extension of the return 'char' value is done here.

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

Added: 
clang/test/CodeGen/bpf-abiinfo.c

Modified: 
clang/lib/CodeGen/TargetInfo.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index bbc40ad3a50a..2790c665c6dd 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -11499,6 +11499,56 @@ class CSKYTargetCodeGenInfo : public TargetCodeGenInfo 
{
 };
 } // end anonymous namespace
 
+//===--===//
+// BPF ABI Implementation
+//===--===//
+
+namespace {
+
+class BPFABIInfo : public DefaultABIInfo {
+public:
+  BPFABIInfo(CodeGenTypes ) : DefaultABIInfo(CGT) {}
+
+  ABIArgInfo classifyReturnType(QualType RetTy) const {
+if (RetTy->isVoidType())
+  return ABIArgInfo::getIgnore();
+
+if (isAggregateTypeForABI(RetTy))
+  return getNaturalAlignIndirect(RetTy);
+
+// Treat an enum type as its underlying type.
+if (const EnumType *EnumTy = RetTy->getAs())
+  RetTy = EnumTy->getDecl()->getIntegerType();
+
+ASTContext  = getContext();
+if (const auto *EIT = RetTy->getAs())
+  if (EIT->getNumBits() > Context.getTypeSize(Context.Int128Ty))
+return getNaturalAlignIndirect(RetTy);
+
+// Caller will do necessary sign/zero extension.
+return ABIArgInfo::getDirect();
+  }
+
+  void computeInfo(CGFunctionInfo ) const override {
+FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
+for (auto  : FI.arguments())
+  I.info = 

[PATCH] D131009: [analyzer] Fixing a bug raising false positives of stack block object leaking under ARC

2022-08-16 Thread Ziqing Luo via Phabricator via cfe-commits
ziqingluo-90 updated this revision to Diff 453144.
ziqingluo-90 added a comment.

Addressing @NoQ 's comment.  Let the symbolic execution simulator put a block 
object in an `UnknownSpaceRegion` from the start if ARC is enabled.  Because in 
such cases whether the block is on stack or in heap depends on the 
implementation.  And, those blocks will be moved to the heap when necessary.   
So they will never trigger a stack address leak issue.

Removing those ARC checking in `StackAddrEscapeChecker` since they are no 
longer needed.


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

https://reviews.llvm.org/D131009

Files:
  clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp
  clang/lib/StaticAnalyzer/Core/MemRegion.cpp
  clang/test/Analysis/stack-capture-leak-arc.mm
  clang/test/Analysis/stack-capture-leak-no-arc.mm

Index: clang/test/Analysis/stack-capture-leak-no-arc.mm
===
--- clang/test/Analysis/stack-capture-leak-no-arc.mm
+++ clang/test/Analysis/stack-capture-leak-no-arc.mm
@@ -4,6 +4,7 @@
 typedef void (^dispatch_block_t)(void);
 void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);
 extern dispatch_queue_t queue;
+void f(int);
 
 void test_block_inside_block_async_no_leak() {
   int x = 123;
@@ -35,3 +36,46 @@
   return outer; // expected-warning-re{{Address of stack-allocated block declared on line {{.+}} is captured by a returned block}}
 }
 
+// The block literal defined in this function could leak once being
+// called.
+void output_block(dispatch_block_t * blk) {
+  int x = 0;
+  *blk = ^{ f(x); }; // expected-warning {{Address of stack-allocated block declared on line 43 is still referred to by the stack variable 'blk' upon returning to the caller.  This will be a dangling reference [core.StackAddressEscape]}}
+}
+
+// The block literal captures nothing thus is treated as a constant.
+void output_constant_block(dispatch_block_t * blk) {
+  *blk = ^{ };
+}
+
+// A block can leak if it captures at least one variable and is not
+// under ARC when its' stack frame expires.
+void test_block_leak() {
+  __block dispatch_block_t blk;
+  int x = 0;
+  dispatch_block_t p = ^{
+blk = ^{ // expected-warning {{Address of stack-allocated block declared on line 57 is still referred to by the stack variable 'blk' upon returning to the caller.  This will be a dangling reference [core.StackAddressEscape]}}
+  f(x);
+};
+  };
+
+  p();
+  blk();
+  output_block();
+  blk();
+}
+
+// A block captures nothing is a constant thus never leaks.
+void test_constant_block_no_leak() {
+  __block dispatch_block_t blk;
+  dispatch_block_t p = ^{
+blk = ^{
+  f(0);
+};
+  };
+  
+  p();
+  blk();
+  output_constant_block();
+  blk();
+}
Index: clang/test/Analysis/stack-capture-leak-arc.mm
===
--- clang/test/Analysis/stack-capture-leak-arc.mm
+++ clang/test/Analysis/stack-capture-leak-arc.mm
@@ -8,6 +8,7 @@
 typedef long dispatch_time_t;
 void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);
 void dispatch_barrier_sync(dispatch_queue_t queue, dispatch_block_t block);
+void f(int);
 
 extern dispatch_queue_t queue;
 extern dispatch_once_t *predicate;
@@ -187,3 +188,40 @@
   }
   dispatch_barrier_sync(queue, ^{});
 }
+
+void output_block(dispatch_block_t * blk) {
+  int x = 0;
+  *blk = ^{ f(x); };
+}
+
+// Block objects themselves can never leak under ARC.
+void test_no_block_leak() {
+  __block dispatch_block_t blk;
+  int x = 0;
+  dispatch_block_t p = ^{
+blk = ^{
+  f(x);
+};
+  };
+  p();
+  blk();
+  output_block();
+  blk();
+}
+
+// Block objects do not leak under ARC but stack variables of
+// non-object kind indirectly referred by a block can leak.
+dispatch_block_t test_block_referencing_variable_leak() {
+  int x = 0;
+  __block int * p = 
+  __block int * q = 
+  
+  dispatch_async(queue, ^{// expected-warning {{Address of stack memory associated with local variable 'x' is captured by an asynchronously-executed block \
+[alpha.core.StackAddressAsyncEscape]}}
+  ++(*p);
+});
+  return (dispatch_block_t) ^{// expected-warning {{Address of stack memory associated with local variable 'x' is captured by a returned block \
+[core.StackAddressEscape]}}
+++(*q);
+  };
+}
Index: clang/lib/StaticAnalyzer/Core/MemRegion.cpp
===
--- clang/lib/StaticAnalyzer/Core/MemRegion.cpp
+++ clang/lib/StaticAnalyzer/Core/MemRegion.cpp
@@ -1076,14 +1076,18 @@
 sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
   }
   else {
-if (LC) {
+bool IsArcManagedBlock = BD->getASTContext().getLangOpts().ObjCAutoRefCount;
+
+// ARC managed blocks can be initialized on stack or directly in heap
+// depending on the implementations.  So we initialize them with
+// UnknownRegion.
+if 

[PATCH] D131528: [Clang] Restrict non fixed enum to a value outside the range of the enumeration values warning to context requiring a constant expression

2022-08-16 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

In D131528#3723231 , @ayermolo wrote:

> In D131528#3722395 , @shafik wrote:
>
>> In D131528#3719430 , @ayermolo 
>> wrote:
>>
>>> Was this and previous change intended to capture this case?
>>>  const enum NumberType neg_one = (enum NumberType) ((enum NumberType) 0 - 
>>> (enum NumberType) 1);
>>
>> That was not intended and I plan on fixing that.
>
> Ah I see. Thanks for elaborating. Can you tag me in the fix diff please.

D131874  seems like the fix for that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131528

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


[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Nathan James via Phabricator via cfe-commits
njames93 added a comment.

The idea of this check is good, but restricting it to only return statements 
seems baffling. A general check that could remove useless parens would have a 
lot more value.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131985

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


[PATCH] D131990: [DRAFT][WebAssembly] Do not support `[[clang::musttail]]` by default

2022-08-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

For reference, the existing error from the backend is something like this:

  test.cpp:9:5: error: WebAssembly 'tail-call' feature not enabled
  int foo(int x) {
  ^

Note that it points to the beginning of the callee rather than the specific 
line containing the tail call.

Ideally we would get the current fatal error and diagnostic message with the 
more specific context from this patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131990

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


[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added a comment.

Please add documentation and mention new check in Release Notes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131985

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


[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

2022-08-16 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 453143.
ckissane added a comment.

- remove extra includes of ADT/Optional


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131992

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

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

[PATCH] D128440: [WebAssembly] Initial support for reference type funcref in clang

2022-08-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

Oops, sorry about that. Will take a look.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128440

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


[PATCH] D131009: [analyzer] Fixing a bug raising false positives of stack block object leaking under ARC

2022-08-16 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/StackAddrEscapeChecker.cpp:313-315
+  // Under ARC, blocks are retained and released automatically:
+  if (isArcManagedBlock(Referred, Ctx))
+return false;

ziqingluo-90 wrote:
> NoQ wrote:
> > Aha ok, it sounds like we can no longer be sure that the block is on the 
> > stack at this point, did I get it right?
> > 
> > In this case I think it's more productive to have the block's memory space 
> > be `UnknownSpaceRegion` from the start, so that it fell through the memory 
> > space check, both here and at other call sites of `isArcManagedBlock()` (so 
> > it can be removed), and in any other code that relies on memory spaces (so 
> > this mistake is never made again).
> //" ..., did I get it right?"//  Yes.
> 
> This suggestion makes sense to me.  To my understanding, I need to modify the 
> symbolic execution engine to address it.  So shall I do it in a new patch?
There's no need to make a new review, you can update the current review. The 
test stays the same after all, who knows maybe we'll end up reverting to this 
solution. It's nice to have all approaches considered and explored behind the 
same link that ultimately ends up in the commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131009

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


[PATCH] D130747: [pseudo] wip/prototype: eliminate identifier ambiguities in the grammar.

2022-08-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang-tools-extra/pseudo/lib/cxx/cxx.bnf:39
 namespace-name := IDENTIFIER
-namespace-name := namespace-alias
-namespace-alias := IDENTIFIER
 class-name := IDENTIFIER
 class-name := simple-template-id

hokein wrote:
> this can be removed as well, but the `class-head-name` rule uses it. 
Can't we use `class-head-name := nested-name-specifier_opt type-name` as 
`class-name` and `type-name` now match?

(Oops, not sure how i lost this comment)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130747

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


[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

2022-08-16 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added inline comments.



Comment at: llvm/include/llvm/Support/Compression.h:95-98
+  static CompressionSpecRef Unknown;
+  static CompressionSpecRef None;
+  static CompressionSpecRef Zlib;
+  static CompressionSpecRef ZStd;

dblaikie wrote:
> Generally we don't want more variables that need global constructors in LLVM 
> - so these should probably be function-local statics in functions instead.
> (I don't think we need a CompressionSpecRef for `Unknown` or `None`, though)
these are just shortcuts to the function local statics of `CompressionSpecRef 
getCompressionSpec(uint8_t Kind)`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131992

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


[PATCH] D130747: [pseudo] wip/prototype: eliminate identifier ambiguities in the grammar.

2022-08-16 Thread Sam McCall via Phabricator via cfe-commits
sammccall accepted this revision.
sammccall added a comment.
This revision is now accepted and ready to land.

LG, though i think we should eliminate class-name altogether.

This gives most of the perf, which is nice!

The reduction in ambiguous nodes is less impressive than before :-( As 
discussed offline, i think the remaining ambiguous nodes serve a purpose as 
they will assist in correlated disambiguation & keep the representation of 
important concepts uniform. I may be wrong about that, in which case we can 
still drop them later.

The forest size reduction is nice to have, but least critical imo.




Comment at: clang-tools-extra/pseudo/lib/cxx/cxx.bnf:37
 # gram.key
-typedef-name := IDENTIFIER
-typedef-name := simple-template-id
+#! No namespace-alis rules, as they're less interesting and marginal useful.
 namespace-name := IDENTIFIER

Maybe "we don't distinguish between namespaces and namespace aliases, as it's 
hard and uninteresting"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130747

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


[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

2022-08-16 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 453140.
ckissane added a comment.

- compression: remove some usage sugar from


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131992

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

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

[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

2022-08-16 Thread Cole Kissane via Phabricator via cfe-commits
ckissane marked an inline comment as done.
ckissane added inline comments.



Comment at: llvm/include/llvm/Support/Compression.h:48-50
+  const int BestSpeedLevel;
+  const int DefaultLevel;
+  const int BestSizeLevel;

dblaikie wrote:
> These could/should probably go in the `Implementation` since they're not 
> useful when the algorithm isn't available anyway?
done


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131992

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


[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

2022-08-16 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 453139.
ckissane added a comment.

- move compression level members from spec to impl


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131992

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

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

[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

2022-08-16 Thread Cole Kissane via Phabricator via cfe-commits
ckissane updated this revision to Diff 453136.
ckissane added a comment.

- remove Supported member of CompressionSpec


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131992

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

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

[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

2022-08-16 Thread Cole Kissane via Phabricator via cfe-commits
ckissane added inline comments.



Comment at: llvm/lib/Object/Decompressor.cpp:50
+return createError(
+"Decompressor provided nullptr (None) CompressionScheme*");
+  if (!CompressionScheme->Implementation)

dblaikie wrote:
> This probably isn't a useful error message for a user. And this code is 
> unreachable/untestable, right? The above code would've already errored out on 
> "unsupported compression type"?
true, it is essentially a repeat of the above


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131992

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


[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

2022-08-16 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

Probably easier to review if it's framed somewhat more like @MaskRay and my 
examples - backwards compatible, without fixing all the API users as we can 
discuss those separately.

Though it is useful to have one or two example uses - but having all the API 
uses being updated in one patch could lead us to discussing the same issues 
repeatedly if we try to review it all in one go.




Comment at: llvm/include/llvm/Object/Decompressor.h:52-53
   uint64_t DecompressedSize;
+  compression::CompressionSpecRef CompressionScheme =
+  compression::CompressionSpecRefs::Zlib;
 };

I think the member should be the CompressionImpl, rather than the specref - 
null if no decompression is requested/needed, and non-null if it's 
required/provided by the `consumeCompressedSectionHeader`.



Comment at: llvm/include/llvm/Support/Compression.h:35-36
+
+typedef CompressionSpec *CompressionSpecRef;
+typedef CompressionImpl *CompressionImplRef;
+

`Ref` when it's actually a pointer might be confusing - not sure if these add 
more value over using the raw pointers themselves?



Comment at: llvm/include/llvm/Support/Compression.h:38-39
+
+CompressionSpecRef getCompressionSpec(uint8_t Kind);
+CompressionSpecRef getCompressionSpec(CompressionKind Kind);
+CompressionSpecRef getSchemeDetails(CompressionImplRef Implementation);

Probably don't need both of these, just the one that takes the enum type?



Comment at: llvm/include/llvm/Support/Compression.h:40
+CompressionSpecRef getCompressionSpec(CompressionKind Kind);
+CompressionSpecRef getSchemeDetails(CompressionImplRef Implementation);
+

I don't think we need this function?



Comment at: llvm/include/llvm/Support/Compression.h:44
+  const CompressionKind Kind;
+  CompressionImpl *Implementation;
+  const StringRef Name;

This should probably be a const member & the CompressionImpl's probably 
immutable, but could be `const` too, just to be explicit



Comment at: llvm/include/llvm/Support/Compression.h:46
+  const StringRef Name;
+  const bool Supported;
+  const StringRef Status; // either "supported", or "unsupported: REASON"

Probably don't need this member - it should be communicated by the 
non-null-ness of `Implementation`?



Comment at: llvm/include/llvm/Support/Compression.h:48-50
+  const int BestSpeedLevel;
+  const int DefaultLevel;
+  const int BestSizeLevel;

These could/should probably go in the `Implementation` since they're not useful 
when the algorithm isn't available anyway?



Comment at: llvm/include/llvm/Support/Compression.h:87
+
+  CompressionSpecRef spec() { return getCompressionSpec(Kind); }
+

the imple could have a pointer back to the spec, rather than having to do 
another lookup/need another function? (though, if the levels are moved to the 
impl, maybe this API is not needed?)



Comment at: llvm/include/llvm/Support/Compression.h:95-98
+  static CompressionSpecRef Unknown;
+  static CompressionSpecRef None;
+  static CompressionSpecRef Zlib;
+  static CompressionSpecRef ZStd;

Generally we don't want more variables that need global constructors in LLVM - 
so these should probably be function-local statics in functions instead.
(I don't think we need a CompressionSpecRef for `Unknown` or `None`, though)



Comment at: llvm/lib/Object/Decompressor.cpp:50
+return createError(
+"Decompressor provided nullptr (None) CompressionScheme*");
+  if (!CompressionScheme->Implementation)

This probably isn't a useful error message for a user. And this code is 
unreachable/untestable, right? The above code would've already errored out on 
"unsupported compression type"?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131992

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


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

2022-08-16 Thread Abraham Corea Diaz via Phabricator via cfe-commits
abrahamcd marked 2 inline comments as done.
abrahamcd added a comment.

Hi, checking in on this again, thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128372

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


[PATCH] D131872: [Intrinsics] Add initial support for NonNull attribute

2022-08-16 Thread Alexander Shaposhnikov via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
alexander-shaposhnikov marked an inline comment as done.
Closed by commit rGd68ba43ad247: [Intrinsics] Add initial support for NonNull 
attribute (authored by alexander-shaposhnikov).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131872

Files:
  clang/test/CodeGenCXX/threadlocal_address.cpp
  llvm/include/llvm/IR/Intrinsics.td
  llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
  llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
  llvm/test/CodeGen/X86/threadlocal_address.ll
  llvm/utils/TableGen/CodeGenIntrinsics.h
  llvm/utils/TableGen/CodeGenTarget.cpp
  llvm/utils/TableGen/IntrinsicEmitter.cpp

Index: llvm/utils/TableGen/IntrinsicEmitter.cpp
===
--- llvm/utils/TableGen/IntrinsicEmitter.cpp
+++ llvm/utils/TableGen/IntrinsicEmitter.cpp
@@ -700,11 +700,13 @@
 unsigned numAttrs = 0;
 
 // The argument attributes are alreadys sorted by argument index.
+assert(is_sorted(Intrinsic.ArgumentAttributes) &&
+   "Argument attributes are not sorted");
+
 unsigned Ai = 0, Ae = Intrinsic.ArgumentAttributes.size();
 if (Ae) {
   while (Ai != Ae) {
 unsigned AttrIdx = Intrinsic.ArgumentAttributes[Ai].Index;
-
 OS << "  const Attribute::AttrKind AttrParam" << AttrIdx << "[]= {";
 ListSeparator LS(",");
 
@@ -721,6 +723,9 @@
   case CodeGenIntrinsic::NoUndef:
 OS << LS << "Attribute::NoUndef";
 break;
+  case CodeGenIntrinsic::NonNull:
+OS << LS << "Attribute::NonNull";
+break;
   case CodeGenIntrinsic::Returned:
 OS << LS << "Attribute::Returned";
 break;
@@ -756,7 +761,8 @@
 OS << LSV << V;
   OS << "};\n";
 }
-
+// AttributeList::ReturnIndex = 0, AttrParam0 corresponds to return
+// value.
 OS << "  AS[" << numAttrs++ << "] = AttributeList::get(C, "
<< AttrIdx << ", AttrParam" << AttrIdx;
 if (!AllValuesAreZero)
Index: llvm/utils/TableGen/CodeGenTarget.cpp
===
--- llvm/utils/TableGen/CodeGenTarget.cpp
+++ llvm/utils/TableGen/CodeGenTarget.cpp
@@ -893,6 +893,9 @@
   } else if (R->isSubClassOf("NoUndef")) {
 unsigned ArgNo = R->getValueAsInt("ArgNo");
 ArgumentAttributes.emplace_back(ArgNo, NoUndef, 0);
+  } else if (R->isSubClassOf("NonNull")) {
+unsigned ArgNo = R->getValueAsInt("ArgNo");
+ArgumentAttributes.emplace_back(ArgNo, NonNull, 0);
   } else if (R->isSubClassOf("Returned")) {
 unsigned ArgNo = R->getValueAsInt("ArgNo");
 ArgumentAttributes.emplace_back(ArgNo, Returned, 0);
Index: llvm/utils/TableGen/CodeGenIntrinsics.h
===
--- llvm/utils/TableGen/CodeGenIntrinsics.h
+++ llvm/utils/TableGen/CodeGenIntrinsics.h
@@ -154,6 +154,7 @@
 NoCapture,
 NoAlias,
 NoUndef,
+NonNull,
 Returned,
 ReadOnly,
 WriteOnly,
Index: llvm/test/CodeGen/X86/threadlocal_address.ll
===
--- llvm/test/CodeGen/X86/threadlocal_address.ll
+++ llvm/test/CodeGen/X86/threadlocal_address.ll
@@ -37,5 +37,5 @@
   ret i32 %3
 }
 
-declare ptr @llvm.threadlocal.address(ptr) nounwind readnone willreturn
-declare ptr addrspace(1) @llvm.threadlocal.address.p1(ptr addrspace(1)) nounwind readnone willreturn
+declare nonnull ptr @llvm.threadlocal.address(ptr nonnull) nounwind readnone willreturn
+declare nonnull ptr addrspace(1) @llvm.threadlocal.address.p1(ptr addrspace(1) nonnull) nounwind readnone willreturn
Index: llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
===
--- llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
+++ llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
@@ -23,7 +23,7 @@
   }
 
   ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
-  declare ptr @llvm.threadlocal.address.p0(ptr) #0
+  declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
 
   attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
 
Index: llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
===
--- llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
+++ llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
@@ -33,7 +33,7 @@
   }
 
   ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
-  declare ptr @llvm.threadlocal.address.p0(ptr) #0
+  declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
 
   attributes #0 = { nocallback nofree nosync nounwind readnone 

[clang] d68ba43 - [Intrinsics] Add initial support for NonNull attribute

2022-08-16 Thread Alexander Shaposhnikov via cfe-commits

Author: Alexander Shaposhnikov
Date: 2022-08-16T21:28:23Z
New Revision: d68ba43ad24791181280fdb0f34b6be380db7a32

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

LOG: [Intrinsics] Add initial support for NonNull attribute

Add initial support for NonNull attribute.
(https://github.com/llvm/llvm-project/issues/57113)

Test plan:

verify that for
__thread int x;
int main() {

int* y = 
return *y;
}
(with this patch) clang -O -fsanitize=null -S -emit-llvm -o -
doesn't emit a null-pointer check

Differential revision: https://reviews.llvm.org/D131872

Added: 


Modified: 
clang/test/CodeGenCXX/threadlocal_address.cpp
llvm/include/llvm/IR/Intrinsics.td
llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
llvm/test/CodeGen/X86/threadlocal_address.ll
llvm/utils/TableGen/CodeGenIntrinsics.h
llvm/utils/TableGen/CodeGenTarget.cpp
llvm/utils/TableGen/IntrinsicEmitter.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/threadlocal_address.cpp 
b/clang/test/CodeGenCXX/threadlocal_address.cpp
index a55b1ee6e08de..625db30dd0e7b 100644
--- a/clang/test/CodeGenCXX/threadlocal_address.cpp
+++ b/clang/test/CodeGenCXX/threadlocal_address.cpp
@@ -20,11 +20,11 @@ int g() {
 // CHECK-NEXT: %[[RET:.+]] = load i32, ptr %[[IA2]], align 4
 // CHECK-NEXT: ret i32 %[[RET]]
 //
-// CHECK: declare ptr @llvm.threadlocal.address.p0(ptr) #[[ATTR_NUM:.+]]
+// CHECK: declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) 
#[[ATTR_NUM:.+]]
 //
 // CHECK-O1-LABEL: @_Z1gv
 // CHECK-O1-NEXT: entry:
-// CHECK-O1-NEXT:   %[[I_ADDR:.+]] = {{.*}}call ptr 
@llvm.threadlocal.address.p0(ptr nonnull @i)
+// CHECK-O1-NEXT:   %[[I_ADDR:.+]] = {{.*}}call ptr 
@llvm.threadlocal.address.p0(ptr @i)
 // CHECK-O1-NEXT:   %[[VAL:.+]] = load i32, ptr %[[I_ADDR]]
 // CHECK-O1-NEXT:   %[[INC:.+]] = add nsw i32 %[[VAL]], 1
 // CHECK-O1-NEXT:   store i32 %[[INC]], ptr %[[I_ADDR]]
@@ -56,7 +56,7 @@ int f() {
 //
 // CHECK-O1-LABEL: @_Z1fv
 // CHECK-O1-NEXT: entry:
-// CHECK-O1-NEXT:   %[[J_ADDR:.+]] = {{.*}}call ptr 
@llvm.threadlocal.address.p0(ptr nonnull @_ZZ1fvE1j)
+// CHECK-O1-NEXT:   %[[J_ADDR:.+]] = {{.*}}call ptr 
@llvm.threadlocal.address.p0(ptr @_ZZ1fvE1j)
 // CHECK-O1-NEXT:   %[[VAL:.+]] = load i32, ptr %[[J_ADDR]]
 // CHECK-O1-NEXT:   %[[INC:.+]] = add nsw i32 %[[VAL]], 1
 // CHECK-O1-NEXT:   store i32 %[[INC]], ptr %[[J_ADDR]]

diff  --git a/llvm/include/llvm/IR/Intrinsics.td 
b/llvm/include/llvm/IR/Intrinsics.td
index 2fb29a4f3eb9d..8a04c495edb11 100644
--- a/llvm/include/llvm/IR/Intrinsics.td
+++ b/llvm/include/llvm/IR/Intrinsics.td
@@ -84,6 +84,11 @@ class NoUndef : IntrinsicProperty {
   int ArgNo = idx.Value;
 }
 
+// NonNull - The specified argument is not null.
+class NonNull : IntrinsicProperty {
+  int ArgNo = idx.Value;
+}
+
 class Align : IntrinsicProperty {
   int ArgNo = idx.Value;
   int Align = align;
@@ -1407,7 +1412,8 @@ def int_ptrmask: DefaultAttrsIntrinsic<[llvm_anyptr_ty], 
[LLVMMatchType<0>, llvm
 
 // Intrinsic to wrap a thread local variable.
 def int_threadlocal_address : DefaultAttrsIntrinsic<[llvm_anyptr_ty], 
[LLVMMatchType<0>],
-   [IntrNoMem, IntrSpeculatable, IntrWillReturn]>;
+[NonNull, 
NonNull>,
+ IntrNoMem, 
IntrSpeculatable, IntrWillReturn]>;
 
 def int_experimental_stepvector : DefaultAttrsIntrinsic<[llvm_anyvector_ty],
 [], [IntrNoMem]>;

diff  --git a/llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir 
b/llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
index 8d03401df9cfd..6dce371138e94 100644
--- a/llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
+++ b/llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86.mir
@@ -33,7 +33,7 @@
   }
 
   ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable 
willreturn
-  declare ptr @llvm.threadlocal.address.p0(ptr) #0
+  declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
 
   attributes #0 = { nocallback nofree nosync nounwind readnone speculatable 
willreturn }
 

diff  --git a/llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir 
b/llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
index dadd1be16c5b9..afc9ff5374de5 100644
--- a/llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
+++ b/llvm/test/CodeGen/X86/peephole-nofold-tpoff-x86_64.mir
@@ -23,7 +23,7 @@
   }
 
   ; Function Attrs: nocallback nofree nosync nounwind readnone speculatable 
willreturn
-  declare ptr @llvm.threadlocal.address.p0(ptr) #0
+  declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #0
 
   attributes #0 = { nocallback nofree nosync nounwind readnone 

[clang] 585f62b - CodeGen: correct handling of debug info generation for aliases

2022-08-16 Thread Saleem Abdulrasool via cfe-commits

Author: Saleem Abdulrasool
Date: 2022-08-16T21:27:05Z
New Revision: 585f62be1a438ca132aa443e556d102bc908a072

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

LOG: CodeGen: correct handling of debug info generation for aliases

When aliasing a static array, the aliasee is going to be a GEP which
points to the value.  We should strip pointer casts before forming the
reference.  This was occluded by the use of opaque pointers.

This problem has existed since the introduction of the debug info
generation for aliases in b1ea0191a42074341847d767609f66a26b6d5a41.  The
test case would assert due to the invalid cast with or without
`-no-opaque-pointers` at that revision.

Fixes: #57179

Added: 
clang/test/CodeGen/debug-info-alias-pointer.c

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index c30bccb1bbd30..0921008e254c3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -5338,7 +5338,7 @@ void CodeGenModule::EmitAliasDefinition(GlobalDecl GD) {
   // Emit global alias debug information.
   if (isa(D))
 if (CGDebugInfo *DI = getModuleDebugInfo())
-  DI->EmitGlobalAlias(cast(GA->getAliasee()), GD);
+  
DI->EmitGlobalAlias(cast(GA->getAliasee()->stripPointerCasts()),
 GD);
 }
 
 void CodeGenModule::emitIFuncDefinition(GlobalDecl GD) {

diff  --git a/clang/test/CodeGen/debug-info-alias-pointer.c 
b/clang/test/CodeGen/debug-info-alias-pointer.c
new file mode 100644
index 0..507a101fe0dc5
--- /dev/null
+++ b/clang/test/CodeGen/debug-info-alias-pointer.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s
+// REQUIRES: asserts
+
+struct S {
+  void *p;
+};
+
+struct S s[] = {
+  { .p = (void *)0, },
+};
+
+extern struct S t __attribute__((__alias__("s")));
+
+// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, name: "t", 
scope: {{.*}}, entity: {{.*}}, file: {{.*}}, line: 12)



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


[PATCH] D131934: [clang][deps] Compute command-lines for dependencies immediately

2022-08-16 Thread Ben Langmuir via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5482432bf6cc: [clang][deps] Compute command-lines for 
dependencies immediately (authored by benlangmuir).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131934

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "clang/Driver/Driver.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
@@ -268,10 +269,7 @@
   Modules.insert(I, {{MD.ID, InputIndex}, std::move(MD)});
 }
 
-ID.CommandLine =
-FD.getCommandLine([&](const ModuleID , ModuleOutputKind MOK) {
-  return lookupModuleOutput(MID, MOK);
-});
+ID.CommandLine = FD.CommandLine;
 Inputs.push_back(std::move(ID));
   }
 
@@ -301,10 +299,7 @@
   {"file-deps", toJSONSorted(MD.FileDeps)},
   {"clang-module-deps", toJSONSorted(MD.ClangModuleDeps)},
   {"clang-modulemap-file", MD.ClangModuleMapFile},
-  {"command-line", MD.getCanonicalCommandLine(
-   [&](const ModuleID , ModuleOutputKind MOK) {
- return lookupModuleOutput(MID, MOK);
-   })},
+  {"command-line", MD.getCanonicalCommandLine()},
   };
   OutModules.push_back(std::move(O));
 }
@@ -330,42 +325,6 @@
   }
 
 private:
-  std::string lookupModuleOutput(const ModuleID , ModuleOutputKind MOK) {
-// Cache the PCM path, since it will be queried repeatedly for each module.
-// The other outputs are only queried once during getCanonicalCommandLine.
-auto PCMPath = PCMPaths.insert({MID, ""});
-if (PCMPath.second)
-  PCMPath.first->second = constructPCMPath(MID);
-switch (MOK) {
-case ModuleOutputKind::ModuleFile:
-  return PCMPath.first->second;
-case ModuleOutputKind::DependencyFile:
-  return PCMPath.first->second + ".d";
-case ModuleOutputKind::DependencyTargets:
-  // Null-separate the list of targets.
-  return join(ModuleDepTargets, StringRef("\0", 1));
-case ModuleOutputKind::DiagnosticSerializationFile:
-  return PCMPath.first->second + ".diag";
-}
-llvm_unreachable("Fully covered switch above!");
-  }
-
-  /// Construct a path for the explicitly built PCM.
-  std::string constructPCMPath(ModuleID MID) const {
-auto MDIt = Modules.find(IndexedModuleID{MID, 0});
-assert(MDIt != Modules.end());
-const ModuleDeps  = MDIt->second;
-
-StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
-StringRef ModuleCachePath = llvm::sys::path::parent_path(
-llvm::sys::path::parent_path(MD.ImplicitModulePCMPath));
-
-SmallString<256> ExplicitPCMPath(!ModuleFilesDir.empty() ? ModuleFilesDir
- : ModuleCachePath);
-llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
-return std::string(ExplicitPCMPath);
-  }
-
   struct IndexedModuleID {
 ModuleID ID;
 mutable size_t InputIndex;
@@ -395,7 +354,6 @@
   std::mutex Lock;
   std::unordered_map
   Modules;
-  std::unordered_map PCMPaths;
   std::vector Inputs;
 };
 
@@ -417,6 +375,42 @@
   return false;
 }
 
+/// Construct a path for the explicitly built PCM.
+static std::string constructPCMPath(ModuleID MID, StringRef OutputDir) {
+  SmallString<256> ExplicitPCMPath(OutputDir);
+  llvm::sys::path::append(ExplicitPCMPath, MID.ContextHash,
+  MID.ModuleName + "-" + MID.ContextHash + ".pcm");
+  return std::string(ExplicitPCMPath);
+}
+
+static std::string lookupModuleOutput(const ModuleID , ModuleOutputKind MOK,
+  StringRef OutputDir) {
+  std::string PCMPath = constructPCMPath(MID, OutputDir);
+  switch (MOK) {
+  case ModuleOutputKind::ModuleFile:
+return PCMPath;
+  case ModuleOutputKind::DependencyFile:
+return PCMPath + ".d";
+  case ModuleOutputKind::DependencyTargets:
+// Null-separate the list of targets.
+return join(ModuleDepTargets, StringRef("\0", 1));
+  case ModuleOutputKind::DiagnosticSerializationFile:
+return PCMPath + 

[clang] 5482432 - [clang][deps] Compute command-lines for dependencies immediately

2022-08-16 Thread Ben Langmuir via cfe-commits

Author: Ben Langmuir
Date: 2022-08-16T14:25:27-07:00
New Revision: 5482432bf6cc7e334894734ebbdac0a97ee98b19

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

LOG: [clang][deps] Compute command-lines for dependencies immediately

Instead of delaying the generation of command-lines to after all
dependencies are reported, compute them immediately. This is partly in
preparation for splitting the TU driver command into its constituent cc1
and other jobs, but it also just simplifies working with the compiler
invocation for modules if they are not "without paths".

Also change the computation of the default output path in
clang-scan-deps to scrape the implicit module cache from the
command-line rather than get it from the dependency, since that is now
unavailable at the time we make the callback.

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

Added: 


Modified: 
clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp

Removed: 




diff  --git 
a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h 
b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
index aabc1e6b16678..9b4257dd70316 100644
--- a/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
+++ b/clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
@@ -23,6 +23,10 @@ namespace clang {
 namespace tooling {
 namespace dependencies {
 
+/// A callback to lookup module outputs for "-fmodule-file=", "-o" etc.
+using LookupModuleOutputCallback =
+llvm::function_ref;
+
 /// The full dependencies and module graph for a specific input.
 struct FullDependencies {
   /// The identifier of the C++20 module this translation unit exports.
@@ -45,17 +49,8 @@ struct FullDependencies {
   /// determined that the 
diff erences are benign for this compilation.
   std::vector ClangModuleDeps;
 
-  /// The original command line of the TU (excluding the compiler executable).
-  std::vector OriginalCommandLine;
-
-  /// Get the full command line.
-  ///
-  /// \param LookupModuleOutput This function is called to fill in
-  ///   "-fmodule-file=", "-o" and other output
-  ///   arguments for dependencies.
-  std::vector getCommandLine(
-  llvm::function_ref
-  LookupModuleOutput) const;
+  /// The command line of the TU (excluding the compiler executable).
+  std::vector CommandLine;
 };
 
 struct FullDependenciesResult {
@@ -92,12 +87,16 @@ class DependencyScanningTool {
   ///function for a single \c DependencyScanningTool in a
   ///single build. Use a 
diff erent one for 
diff erent tools,
   ///and clear it between builds.
+  /// \param LookupModuleOutput This function is called to fill in
+  ///   "-fmodule-file=", "-o" and other output
+  ///   arguments for dependencies.
   ///
   /// \returns a \c StringError with the diagnostic output if clang errors
   /// occurred, \c FullDependencies otherwise.
   llvm::Expected
   getFullDependencies(const std::vector ,
   StringRef CWD, const llvm::StringSet<> ,
+  LookupModuleOutputCallback LookupModuleOutput,
   llvm::Optional ModuleName = None);
 
 private:
@@ -106,8 +105,9 @@ class DependencyScanningTool {
 
 class FullDependencyConsumer : public DependencyConsumer {
 public:
-  FullDependencyConsumer(const llvm::StringSet<> )
-  : AlreadySeen(AlreadySeen) {}
+  FullDependencyConsumer(const llvm::StringSet<> ,
+ LookupModuleOutputCallback LookupModuleOutput)
+  : AlreadySeen(AlreadySeen), LookupModuleOutput(LookupModuleOutput) {}
 
   void handleDependencyOutputOpts(const DependencyOutputOptions &) override {}
 
@@ -127,6 +127,11 @@ class FullDependencyConsumer : public DependencyConsumer {
 ContextHash = std::move(Hash);
   }
 
+  std::string lookupModuleOutput(const ModuleID ,
+ ModuleOutputKind Kind) override {
+return LookupModuleOutput(ID, Kind);
+  }
+
   FullDependenciesResult getFullDependencies(
   const std::vector ) const;
 
@@ -138,6 +143,7 @@ class FullDependencyConsumer : public DependencyConsumer {
   std::string ContextHash;
   std::vector OutputPaths;
   const llvm::StringSet<> 
+  LookupModuleOutputCallback LookupModuleOutput;
 };
 
 } // end 

[PATCH] D131632: [clang] Enable output of SARIF diagnostics

2022-08-16 Thread Vaibhav Yenamandra via Phabricator via cfe-commits
vaibhav.y added inline comments.



Comment at: clang/lib/Frontend/SARIFDiagnostic.cpp:75
+emitFilename(FE->getName(), Loc.getManager());
+// FIXME: No current way to add file-only location to SARIF object
+  }

abrahamcd wrote:
> @vaibhav.y , just wanted to confirm, the SarifDiagnosticWriter can only add 
> locations that include row/column numbers, correct?
Yes, this is currently not supported. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131632

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


[PATCH] D131632: [clang] Enable output of SARIF diagnostics

2022-08-16 Thread Abraham Corea Diaz via Phabricator via cfe-commits
abrahamcd updated this revision to Diff 453126.
abrahamcd added a comment.

Fixed FileCheck test case and added multiple source range error.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131632

Files:
  clang/include/clang/Frontend/SARIFDiagnostic.h
  clang/include/clang/Frontend/SARIFDiagnosticPrinter.h
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInstance.cpp
  clang/lib/Frontend/FrontendAction.cpp
  clang/lib/Frontend/SARIFDiagnostic.cpp
  clang/lib/Frontend/SARIFDiagnosticPrinter.cpp
  clang/test/Frontend/sarif-diagnostics.cpp
  clang/unittests/Frontend/CMakeLists.txt
  clang/unittests/Frontend/SARIFDiagnosticTest.cpp

Index: clang/unittests/Frontend/SARIFDiagnosticTest.cpp
===
--- /dev/null
+++ clang/unittests/Frontend/SARIFDiagnosticTest.cpp
@@ -0,0 +1,123 @@
+// RUN: %clang -fdiagnostics-format=sarif %s -o %t.exe -DGTEST
+// RUN: %clang -fsyntax-only -Wall -Wextra -fdiagnostics-format=sarif %s 2>
+// %t.diags || true RUN: %t.exe < %t.diags
+
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Program.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+
+namespace {
+
+constexpr llvm::StringRef BrokenProgram = R"(// Example errors below start on line 2
+void main() {
+  int i = hello;
+
+  float test = 1a.0;
+
+  if (true)
+bool Yes = true;
+return;
+
+  bool j = hi;
+}
+})";
+
+TEST(SARIFDiagnosticTest, TestFields) {
+  llvm::SmallString<256> SearchDir;
+  llvm::sys::fs::current_path(SearchDir);
+  
+  SearchDir.append("/../../../bin");
+
+  llvm::ErrorOr ClangPathOrErr =
+  llvm::sys::findProgramByName("clang", {SearchDir});
+  ASSERT_TRUE(ClangPathOrErr);
+  const std::string  = *ClangPathOrErr;
+
+  llvm::ErrorOr EchoPathOrErr =
+  llvm::sys::findProgramByName("echo");
+  ASSERT_TRUE(EchoPathOrErr);
+  const std::string  = *EchoPathOrErr;
+
+  int EchoInputFD;
+  llvm::SmallString<32> EchoInputFile, EchoOutputFile;
+  llvm::sys::fs::createTemporaryFile("echo-input", "", EchoInputFD,
+ EchoInputFile);
+  llvm::sys::fs::createTemporaryFile("echo-output", "", EchoOutputFile);
+  llvm::FileRemover InputRemover(EchoInputFile.c_str());
+  llvm::FileRemover OutputRemover(EchoOutputFile.c_str());
+
+  llvm::Optional Redirects[] = {
+  EchoInputFile.str(), EchoOutputFile.str(), llvm::StringRef("")};
+
+  int RunResult = llvm::sys::ExecuteAndWait(EchoPath, {"echo", BrokenProgram},
+llvm::None, Redirects);
+  ASSERT_EQ(RunResult, 0);
+
+  llvm::SmallString<32> ClangErrFile;
+  llvm::sys::fs::createTemporaryFile("clang-err", "", ClangErrFile);
+  llvm::FileRemover ClangErrRemover(ClangErrFile.c_str());
+
+  llvm::Optional ClangRedirects[] = {
+  EchoOutputFile.str(), llvm::StringRef(""), ClangErrFile.str()};
+  llvm::StringRef Args[] = {"clang",
+"-xc++",
+"-",
+"-fsyntax-only",
+"-Wall",
+"-Wextra",
+"-fdiagnostics-format=sarif"};
+
+  int ClangResult =
+  llvm::sys::ExecuteAndWait(ClangPath, Args, llvm::None, ClangRedirects);
+  ASSERT_EQ(ClangResult, 1);
+
+  auto ClangErrBuf = llvm::MemoryBuffer::getFile(ClangErrFile.c_str());
+  ASSERT_TRUE(ClangErrBuf);
+  llvm::StringRef ClangErr = ClangErrBuf.get()->getBuffer();
+  ASSERT_EQ(ClangErr.str(), "hi");
+
+  llvm::Expected Value = llvm::json::parse(ClangErr.str());
+  ASSERT_FALSE(!Value);
+
+  llvm::json::Object *SarifDoc = Value->getAsObject();
+
+  const llvm::json::Array *Runs = SarifDoc->getArray("runs");
+  const llvm::json::Object *TheRun = Runs->back().getAsObject();
+  const llvm::json::Array *Results = TheRun->getArray("results");
+  
+  // Check Artifacts
+  const llvm::json::Array *Artifacts = TheRun->getArray("artifacts");
+  const llvm::json::Object *TheArtifact = Artifacts->back().getAsObject();
+  const llvm::json::Object *Location = TheArtifact->getObject("location");
+
+  ASSERT_TRUE(Location->getInteger("index").has_value());
+  ASSERT_TRUE(Location->getString("uri").has_value());
+
+  EXPECT_EQ(Location->getInteger("index").value(), 0);
+  EXPECT_EQ(Location->getString("uri").value(), "file://");
+
+  // Check Driver
+  const llvm::json::Object *Driver =
+  TheRun->getObject("tool")->getObject("driver");
+
+  ASSERT_TRUE(Driver->getString("name").has_value());
+  ASSERT_TRUE(Driver->getString("fullName").has_value());
+
+  EXPECT_EQ(Driver->getString("name").value(), "clang");
+  EXPECT_EQ(Driver->getString("fullName").value(), "clang-15");
+
+  // Check Rules
+  const 

[PATCH] D131992: [Support] compression proposal for a enum->spec->impl approach

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

[compression] move to a enum->spec->impl approach 
+ None compression is signified by a nullptr for a CompressionSpecRef
+ Lack of support (lack of impl) is signified by a nullptr for a 
CompressionImplRef 
+ move away from fancy fake enum approach


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131992

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

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

[PATCH] D131978: [clang-format] Concepts: allow identifiers after negation

2022-08-16 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel added a comment.

In D131978#3727110 , 
@HazardyKnusperkeks wrote:

> It's late (where I am). I thought we had something like 
> `ClosesRequiresClause` for concepts too.
> But on the other hand, this should affect requires clauses, right? So a test 
> for that would fail before your patch.

Sorry, I'm not familiar with these tests enough to know what exactly you mean, 
but thank you for the review
Also, since this is my first change, I cannot commit this myself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131978

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


[PATCH] D127233: [CodeGen] Sort llvm.global_ctors by lexing order before emission

2022-08-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:580
+I = DelayedCXXInitPosition.find(D);
+unsigned LexOrder = I == DelayedCXXInitPosition.end() ? ~0U : I->second;
+AddGlobalCtor(Fn, 65535, LexOrder, COMDATKey);

ychen wrote:
> efriedma wrote:
> > ychen wrote:
> > > efriedma wrote:
> > > > This ensures delayed initialization calls are ordered relative to each 
> > > > other... but are they ordered correctly relative to non-delayed 
> > > > initialization calls?  I'm skeptical that using a LexOrder of "~0U" is 
> > > > really correct.  (For example, if you change the variable "b" in your 
> > > > testcase to a struct with a destructor.)
> > > Hmm, That's a great point. I didn't think of that. I'll take a look.
> > Using `CXXGlobalInits.size()` like this is sort of hard to reason about: 
> > multiple values can end up with the same LexOrder.  (I'm not sure if all 
> > the values with the same LexOrder end up sorted correctly.)
> > 
> > Instead of trying to reason about whether this is right, can we just use a 
> > separate counter to assign a unique index to each global init?
> Agreed that this whole thing is confusing if not looked at closely. IIUC, 
> LexOrder is unique for each global variables and all global variables with an 
> initialization are pushed into `CXXGlobalInits` in lexing order regardless of 
> deferred/non-deferred emission. I could add a counter which basically tracks 
> the size of `CXXGlobalInits`. Which do you think is more clear: add an 
> explicit counter or add more comments to `CXXGlobalInits` explaining the 
> usage?
For each global, CXXGlobalInits is supposed to contain either a pointer to a 
function, or nullptr to indicate emission was delayed.  I guess that works as a 
unique ordering.  But it looks like this codepath doesn't actually insert 
anything into CXXGlobalInits; it skips that, and goes straight to 
AddGlobalCtor.  I think that would lead to multiple globals with the same 
index?  (Not 100% sure about this since the CXXGlobalInits code is scattered 
all over.)

If we do expect that there won't be multiple globals with the same index, 
please add an assertion after we sort GlobalCtors, that there aren't any 
entries with the same LexOrder value (besides ~0).

A comment explaining the uniqueness of LexOrder is probably sufficient, given 
nothing else is trying to produce a LexOrder.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127233

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


[PATCH] D131978: [clang-format] Concepts: allow identifiers after negation

2022-08-16 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks accepted this revision.
HazardyKnusperkeks added a comment.
This revision is now accepted and ready to land.

In D131978#3727084 , @rymiel wrote:

> Added negation unary operator check to TokenAnnotatorTest
>
> Is this what you meant? Although, I didn't touch the TokenType since it was 
> already correct before i changed anything

It's late (where I am). I thought we had something like `ClosesRequiresClause` 
for concepts too.
But on the other hand, this should affect requires clauses, right? So a test 
for that would fail before your patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131978

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


[PATCH] D131683: Diagnosing the Future Keywords

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

updated.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131683

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/include/clang/Basic/IdentifierTable.h
  clang/include/clang/Basic/TokenKinds.def
  clang/lib/Basic/IdentifierTable.cpp
  clang/lib/Lex/Preprocessor.cpp
  clang/test/Lexer/keywords_test.c
  clang/test/Lexer/keywords_test.cpp

Index: clang/test/Lexer/keywords_test.cpp
===
--- clang/test/Lexer/keywords_test.cpp
+++ clang/test/Lexer/keywords_test.cpp
@@ -15,6 +15,8 @@
 // RUN: %clang -std=c++03 -target i686-windows-msvc -DMS -fno-declspec -fsyntax-only %s
 // RUN: %clang -std=c++03 -target x86_64-scei-ps4 -fno-declspec -fsyntax-only %s
 
+// RUN: %clang_cc1 -std=c++98 -DFutureKeyword -fsyntax-only %s
+
 #define IS_KEYWORD(NAME) _Static_assert(!__is_identifier(NAME), #NAME)
 #define NOT_KEYWORD(NAME) _Static_assert(__is_identifier(NAME), #NAME)
 #define IS_TYPE(NAME) void is_##NAME##_type() { int f(NAME); }
@@ -61,6 +63,11 @@
 // Concepts keywords
 CXX20_KEYWORD(concept);
 CXX20_KEYWORD(requires);
+CXX20_KEYWORD(consteval);
+CXX20_KEYWORD(constinit);
+CXX20_KEYWORD(co_await);
+CXX20_KEYWORD(co_return);
+CXX20_KEYWORD(co_yield);
 
 // __declspec extension
 DECLSPEC_KEYWORD(__declspec);
@@ -70,3 +77,27 @@
 IS_TYPE(__char16_t);
 IS_KEYWORD(__char32_t);
 IS_TYPE(__char32_t);
+
+#ifdef FutureKeyword
+
+int nullptr; // expected-warning {{'nullptr' is a keyword in C++11}}
+int decltype;  // expected-warning {{'decltype' is a keyword in C++11}}
+int alignof;  // expected-warning {{'alignof' is a keyword in C++11}}
+int alignas;  // expected-warning {{'alignas' is a keyword in C++11}}
+int char16_t;  // expected-warning {{'char16_t' is a keyword in C++11}}
+int char32_t;  // expected-warning {{'char32_t' is a keyword in C++11}}
+int constexpr;  // expected-warning {{'constexpr' is a keyword in C++11}}
+int noexcept;  // expected-warning {{'noexcept' is a keyword in C++11}}
+int static_assert; // expected-warning {{'static_assert' is a keyword in C++11}}
+char thread_local; // expected-warning {{'thread_local' is a keyword in C++11}}
+
+int co_await; // expected-warning {{'co_await' is a keyword in C++20}}
+char co_return; // expected-warning {{'co_return' is a keyword in C++20}}
+char co_yield; // expected-warning {{'co_yield' is a keyword in C++20}}
+float align; // expected-warning {{'align' is a keyword in C++20}}
+int constinit; // expected-warning {{'constinit' is a keyword in C++20}}
+int consteval; // expected-warning {{'alignas' is a keyword in C++20}}
+int requires; // expected-warning {{'requires' is a keyword in C++20}}
+int concept; // expected-warning {{'concept' is a keyword in C++20}}
+
+#endif
Index: clang/test/Lexer/keywords_test.c
===
--- clang/test/Lexer/keywords_test.c
+++ clang/test/Lexer/keywords_test.c
@@ -14,6 +14,41 @@
 // RUN: %clang_cc1 -std=c99 -fms-extensions -fno-declspec -E %s -o - \
 // RUN: | FileCheck --check-prefix=CHECK-MS-KEYWORDS-WITHOUT-DECLSPEC %s
 
+// RUN: %clang_cc1 -std=c99 -DC99 -fsyntax-only %s
+// RUN: %clang_cc1 -std=c2x -DC99 -DC23 -fsyntax-only %s
+
+// RUN: %clang_cc1 -std=c89 -DFutureKeyword -fsyntax-only %s
+
+#define IS_KEYWORD(NAME) _Static_assert(!__is_identifier(NAME), #NAME)
+#define NOT_KEYWORD(NAME) _Static_assert(__is_identifier(NAME), #NAME)
+
+#if defined(C99)
+#define C99_KEYWORD(NAME)  IS_KEYWORD(NAME)
+#else
+#define C99_KEYWORD(NAME)  NOT_KEYWORD(NAME)
+#endif
+
+#if defined(C23)
+#define C23_KEYWORD(NAME)  IS_KEYWORD(NAME)
+#else
+#define C23_KEYWORD(NAME)  NOT_KEYWORD(NAME)
+#endif
+
+// C99 Keywords.
+C99_KEYWORD(restrict);
+C99_KEYWORD(inline);
+
+// C23 Keywords.
+C23_KEYWORD(bool);
+C23_KEYWORD(true);
+C23_KEYWORD(false);
+C23_KEYWORD(remove_quals);
+C23_KEYWORD(static_assert);
+C23_KEYWORD(typeof);
+C23_KEYWORD(thread_local);
+C23_KEYWORD(alignas);
+C23_KEYWORD(alignof);
+
 void f() {
 // CHECK-NONE: int asm
 // CHECK-GNU-KEYWORDS: asm ("ret" : :)
@@ -52,3 +87,19 @@
 #else
 void has_static_assert();
 #endif
+
+#ifdef FutureKeyword
+
+  int restrict; // expected-warning {{'restrict' is a keyword in C99}}
+  int inline;  // expected-warning {{'inline' is a keyword in C99}}
+
+  int bool; // expected-warning {{'bool' is a keyword in C23}}
+  char true; // expected-warning {{'true' is a keyword in C23}}
+  char false; // expected-warning {{'false' is a keyword in C23}}
+  float align; // expected-warning {{'align' is a keyword in C23}}
+  int typeof; // expected-warning {{'typeof' is a keyword in C23}}
+int alignas; // expected-warning {{'alignas' is a keyword in C23}}
+  int remove_quals; // expected-warning {{'remove_quals' is a keyword in C23}}
+  int static_assert; // 

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

2022-08-16 Thread Richard Trieu via Phabricator via cfe-commits
rtrieu added a comment.

This patch has been moving back and forth between 
`IsIntegerLiteralConstantExpr` and `getIntegerLiteralSubexpressionValue`.  The 
first function is preexisting and the second one is a new function.  The final 
patch seems to settle on using just `getIntegerLiteralSubexpressionValue`.  Can 
you explain why the existing function does not meet your needs?  It wasn't 
clear from the update messages why you went that way.

Besides that, there is added support for multiple unary operators, but only 
minus is tested.  Each one should have at least a positive and a negative test 
to show it is supported.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130510

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


[PATCH] D127233: [CodeGen] Sort llvm.global_ctors by lexical order before emission

2022-08-16 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:580
+I = DelayedCXXInitPosition.find(D);
+unsigned LexOrder = I == DelayedCXXInitPosition.end() ? ~0U : I->second;
+AddGlobalCtor(Fn, 65535, LexOrder, COMDATKey);

efriedma wrote:
> ychen wrote:
> > efriedma wrote:
> > > This ensures delayed initialization calls are ordered relative to each 
> > > other... but are they ordered correctly relative to non-delayed 
> > > initialization calls?  I'm skeptical that using a LexOrder of "~0U" is 
> > > really correct.  (For example, if you change the variable "b" in your 
> > > testcase to a struct with a destructor.)
> > Hmm, That's a great point. I didn't think of that. I'll take a look.
> Using `CXXGlobalInits.size()` like this is sort of hard to reason about: 
> multiple values can end up with the same LexOrder.  (I'm not sure if all the 
> values with the same LexOrder end up sorted correctly.)
> 
> Instead of trying to reason about whether this is right, can we just use a 
> separate counter to assign a unique index to each global init?
Agreed that this whole thing is confusing if not looked at closely. IIUC, 
LexOrder is unique for each global variables and all global variables with an 
initialization are pushed into `CXXGlobalInits` in lexing order regardless of 
deferred/non-deferred emission. I could add a counter which basically tracks 
the size of `CXXGlobalInits`. Which do you think is more clear: add an explicit 
counter or add more comments to `CXXGlobalInits` explaining the usage?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127233

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


[PATCH] D131978: [clang-format] Concepts: allow identifiers after negation

2022-08-16 Thread Emilia Dreamer via Phabricator via cfe-commits
rymiel updated this revision to Diff 453107.
rymiel added a comment.

Added negation unary operator check to TokenAnnotatorTest


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131978

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -328,6 +328,13 @@
   EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
   EXPECT_TOKEN(Tokens[16], tok::ampamp, TT_BinaryOperator);
 
+  Tokens = annotate("template \n"
+"concept C = Foo && !Bar;");
+
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[10], tok::exclaim, TT_UnaryOperator);
+
   Tokens = annotate("template \n"
 "concept C = requires(T t) {\n"
 "  { t.foo() };\n"
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24109,6 +24109,15 @@
"concept DelayedCheck = false || requires(T t) { t.bar(); } && "
"sizeof(T) <= 8;");
 
+  verifyFormat("template \n"
+   "concept DelayedCheck = Unit && !DerivedUnit;");
+
+  verifyFormat("template \n"
+   "concept DelayedCheck = Unit && !(DerivedUnit);");
+
+  verifyFormat("template \n"
+   "concept DelayedCheck = Unit && !!DerivedUnit;");
+
   verifyFormat("template \n"
"concept DelayedCheck = !!false || requires(T t) { t.bar(); } "
"&& sizeof(T) <= 8;");
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3537,7 +3537,8 @@
   switch (FormatTok->Previous->Tok.getKind()) {
   case tok::coloncolon:  // Nested identifier.
   case tok::ampamp:  // Start of a function or variable for the
-  case tok::pipepipe:// constraint expression.
+  case tok::pipepipe:// constraint expression. (binary)
+  case tok::exclaim: // The same as above, but unary.
   case tok::kw_requires: // Initial identifier of a requires clause.
   case tok::equal:   // Initial identifier of a concept declaration.
 break;


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -328,6 +328,13 @@
   EXPECT_TOKEN(Tokens[13], tok::ampamp, TT_BinaryOperator);
   EXPECT_TOKEN(Tokens[16], tok::ampamp, TT_BinaryOperator);
 
+  Tokens = annotate("template \n"
+"concept C = Foo && !Bar;");
+
+  ASSERT_EQ(Tokens.size(), 14u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+  EXPECT_TOKEN(Tokens[10], tok::exclaim, TT_UnaryOperator);
+
   Tokens = annotate("template \n"
 "concept C = requires(T t) {\n"
 "  { t.foo() };\n"
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24109,6 +24109,15 @@
"concept DelayedCheck = false || requires(T t) { t.bar(); } && "
"sizeof(T) <= 8;");
 
+  verifyFormat("template \n"
+   "concept DelayedCheck = Unit && !DerivedUnit;");
+
+  verifyFormat("template \n"
+   "concept DelayedCheck = Unit && !(DerivedUnit);");
+
+  verifyFormat("template \n"
+   "concept DelayedCheck = Unit && !!DerivedUnit;");
+
   verifyFormat("template \n"
"concept DelayedCheck = !!false || requires(T t) { t.bar(); } "
"&& sizeof(T) <= 8;");
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -3537,7 +3537,8 @@
   switch (FormatTok->Previous->Tok.getKind()) {
   case tok::coloncolon:  // Nested identifier.
   case tok::ampamp:  // Start of a function or variable for the
-  case tok::pipepipe:// constraint expression.
+  case tok::pipepipe:// constraint expression. (binary)
+  case tok::exclaim: // The same as above, but unary.
   case tok::kw_requires: // Initial identifier of a requires clause.
   case tok::equal:   // Initial identifier of a concept declaration.
 break;

[PATCH] D131268: [HLSL] Generate buffer subscript operators

2022-08-16 Thread Chris Bieneman via Phabricator via cfe-commits
beanz added inline comments.



Comment at: clang/test/CodeGenHLSL/buffer-array-operator.hlsl:3
+
+const RWBuffer In;
+RWBuffer Out;

python3kgae wrote:
> beanz wrote:
> > python3kgae wrote:
> > > Why add const instead of using Buffer directly?
> > > 
> > Making this const forces the const methods to be used. It is just to drive 
> > the correct validation and code generation.
> So maybe we don't need Buffer at all, just use const RWBuffer for read-only 
> usage?
I think there would likely be some code incompatibilities if we alias `Buffer` 
to `const RWBuffer`, but that would be interesting to consider.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131268

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


[PATCH] D129016: [PowerPC] implemented @llvm.ppc.kill.canary to corrupt stack guard

2022-08-16 Thread Paul Scoropan via Phabricator via cfe-commits
pscoro updated this revision to Diff 453105.
pscoro added a comment.

Re added chain fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129016

Files:
  clang/include/clang/Basic/BuiltinsPPC.def
  clang/lib/Basic/Targets/PPC.cpp
  clang/test/CodeGen/PowerPC/builtins-ppc-stackprotect.c
  llvm/include/llvm/IR/IntrinsicsPowerPC.td
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll

Index: llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/kill-canary-intrinsic.ll
@@ -0,0 +1,206 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-AIX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-AIX64
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-LINUX-LE
+
+; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-aix -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr8 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-AIX
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr8 --ppc-asm-full-reg-names < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-aix -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr8 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-AIX64
+; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr8 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-LINUX-LE
+
+; RUN: llc -verify-machineinstrs -O0 -mtriple=powerpc-unknown-aix -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-AIX-FAST
+; RUN: llc -verify-machineinstrs -O0 -mtriple=powerpc64-unknown-linux-gnu -ppc-vsr-nums-as-vr \
+; RUN:   -mcpu=pwr7 --ppc-asm-full-reg-names < %s | FileCheck %s -check-prefix=CHECK-FAST
+
+attributes #1 = { nounwind }
+declare void @llvm.ppc.kill.canary()
+define dso_local void @test_kill_canary() #1 {
+; CHECK-AIX-LABEL: test_kill_canary:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:blr
+;
+; CHECK-LABEL: test_kill_canary:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:blr
+;
+; CHECK-AIX64-LABEL: test_kill_canary:
+; CHECK-AIX64:   # %bb.0: # %entry
+; CHECK-AIX64-NEXT:blr
+;
+; CHECK-LINUX-LE-LABEL: test_kill_canary:
+; CHECK-LINUX-LE:   # %bb.0: # %entry
+; CHECK-LINUX-LE-NEXT:blr
+;
+; CHECK-AIX-FAST-LABEL: test_kill_canary:
+; CHECK-AIX-FAST:   # %bb.0: # %entry
+; CHECK-AIX-FAST-NEXT:blr
+;
+; CHECK-FAST-LABEL: test_kill_canary:
+; CHECK-FAST:   # %bb.0: # %entry
+; CHECK-FAST-NEXT:blr
+entry:
+  call void @llvm.ppc.kill.canary()
+  ret void
+}
+
+attributes #0 = { sspreq }
+; Function Attrs: sspreq
+define dso_local void @test_kill_canary_ssp() #0 #1 {
+; CHECK-AIX-LABEL: test_kill_canary_ssp:
+; CHECK-AIX:   # %bb.0: # %entry
+; CHECK-AIX-NEXT:mflr r0
+; CHECK-AIX-NEXT:stw r0, 8(r1)
+; CHECK-AIX-NEXT:stwu r1, -64(r1)
+; CHECK-AIX-NEXT:lwz r3, L..C0(r2) # @__ssp_canary_word
+; CHECK-AIX-NEXT:lwz r4, 0(r3)
+; CHECK-AIX-NEXT:stw r4, 60(r1)
+; CHECK-AIX-NEXT:lwz r4, 0(r3)
+; CHECK-AIX-NEXT:not r4, r4
+; CHECK-AIX-NEXT:stw r4, 60(r1)
+; CHECK-AIX-NEXT:lwz r3, 0(r3)
+; CHECK-AIX-NEXT:lwz r4, 60(r1)
+; CHECK-AIX-NEXT:cmplw r3, r4
+; CHECK-AIX-NEXT:bne cr0, L..BB1_2
+; CHECK-AIX-NEXT:  # %bb.1: # %entry
+; CHECK-AIX-NEXT:addi r1, r1, 64
+; CHECK-AIX-NEXT:lwz r0, 8(r1)
+; CHECK-AIX-NEXT:mtlr r0
+; CHECK-AIX-NEXT:blr
+; CHECK-AIX-NEXT:  L..BB1_2: # %entry
+; CHECK-AIX-NEXT:bl .__stack_chk_fail[PR]
+; CHECK-AIX-NEXT:nop
+;
+; CHECK-LABEL: test_kill_canary_ssp:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:mflr r0
+; CHECK-NEXT:std r0, 16(r1)
+; CHECK-NEXT:stdu r1, -128(r1)
+; CHECK-NEXT:ld r3, -28688(r13)
+; CHECK-NEXT:std r3, 120(r1)
+; CHECK-NEXT:ld r3, -28688(r13)
+; CHECK-NEXT:not r3, r3
+; CHECK-NEXT:std r3, 120(r1)
+; CHECK-NEXT:ld r3, 120(r1)
+; CHECK-NEXT:ld r4, -28688(r13)
+; CHECK-NEXT:cmpld r4, r3
+; CHECK-NEXT:bne cr0, .LBB1_2
+; CHECK-NEXT:  # %bb.1: # %entry
+; CHECK-NEXT:addi r1, r1, 128
+; CHECK-NEXT:ld r0, 16(r1)
+; CHECK-NEXT:mtlr r0
+; 

[PATCH] D127233: [CodeGen] Sort llvm.global_ctors by lexical order before emission

2022-08-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:580
+I = DelayedCXXInitPosition.find(D);
+unsigned LexOrder = I == DelayedCXXInitPosition.end() ? ~0U : I->second;
+AddGlobalCtor(Fn, 65535, LexOrder, COMDATKey);

ychen wrote:
> efriedma wrote:
> > This ensures delayed initialization calls are ordered relative to each 
> > other... but are they ordered correctly relative to non-delayed 
> > initialization calls?  I'm skeptical that using a LexOrder of "~0U" is 
> > really correct.  (For example, if you change the variable "b" in your 
> > testcase to a struct with a destructor.)
> Hmm, That's a great point. I didn't think of that. I'll take a look.
Using `CXXGlobalInits.size()` like this is sort of hard to reason about: 
multiple values can end up with the same LexOrder.  (I'm not sure if all the 
values with the same LexOrder end up sorted correctly.)

Instead of trying to reason about whether this is right, can we just use a 
separate counter to assign a unique index to each global init?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127233

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


[PATCH] D131990: [DRAFT][WebAssembly] Do not support `[[clang::musttail]]` by default

2022-08-16 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
Herald added subscribers: pmatos, wingo, ecnelises, sunfish, jgravelle-google, 
sbc100, dschuff.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
tlively requested review of this revision.
Herald added subscribers: cfe-commits, aheejin.
Herald added a project: clang.

WebAssembly is not able to emit tail calls unless the `tail-call` target feature
is enabled and when it is not enabled, trying to compile musttail calls produces
a fatal error in the backend. To reflect this reality, disable support for the
`[[clang::musttail]]` attribute when targeting WebAssembly without the
`tail-call` feature.

Marked draft for further discussion because I'm not sure getting this:

  test.cpp:10:7: warning: unknown attribute 'musttail' ignored 
[-Wunknown-attributes]
  [[clang::musttail]] return bar(x * 10);

is actually better developer experience than getting a fatal error with a
description of the WebAssembly-specific problem. Users can also check for the
presence of the `__wasm_tail_call__` macro as an alternative to checking
`__has_cpp_attribute(clang::musttail)` with this patch, but I'm not sure that's
documented anywhere.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131990

Files:
  clang/include/clang/Basic/Attr.td


Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -414,6 +414,11 @@
 def TargetSupportsInitPriority : TargetSpec {
   let CustomCode = [{ !Target.getTriple().isOSzOS() }];
 }
+
+def TargetSupportsMustTail : TargetSpec {
+  let CustomCode = [{ !Target.getTriple().isWasm() || 
Target.hasFeature("tail-call") }];
+}
+
 // Attribute subject match rules that are used for #pragma clang attribute.
 //
 // A instance of AttrSubjectMatcherRule represents an individual match rule.
@@ -1433,7 +1438,7 @@
   let SimpleHandler = 1;
 }
 
-def MustTail : StmtAttr {
+def MustTail : StmtAttr, TargetSpecificAttr {
   let Spellings = [Clang<"musttail">];
   let Documentation = [MustTailDocs];
   let Subjects = SubjectList<[ReturnStmt], ErrorDiag, "return statements">;


Index: clang/include/clang/Basic/Attr.td
===
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -414,6 +414,11 @@
 def TargetSupportsInitPriority : TargetSpec {
   let CustomCode = [{ !Target.getTriple().isOSzOS() }];
 }
+
+def TargetSupportsMustTail : TargetSpec {
+  let CustomCode = [{ !Target.getTriple().isWasm() || Target.hasFeature("tail-call") }];
+}
+
 // Attribute subject match rules that are used for #pragma clang attribute.
 //
 // A instance of AttrSubjectMatcherRule represents an individual match rule.
@@ -1433,7 +1438,7 @@
   let SimpleHandler = 1;
 }
 
-def MustTail : StmtAttr {
+def MustTail : StmtAttr, TargetSpecificAttr {
   let Spellings = [Clang<"musttail">];
   let Documentation = [MustTailDocs];
   let Subjects = SubjectList<[ReturnStmt], ErrorDiag, "return statements">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131978: [clang-format] Concepts: allow identifiers after negation

2022-08-16 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

Nice patch. Could you please also extend the test in `TokenAnnotatorTests.cpp`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131978

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


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

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

This looks correct to me! Any further concerns @erichkeane or @rtrieu?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130510

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


[PATCH] D130747: [pseudo] wip/prototype: eliminate identifier ambiguities in the grammar.

2022-08-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

New data on the patch:

| file | ambiguous nodes | forest size  | glrParse 
performance |
| SemaCodeComplete.cpp | 11k -> 5.7K | 10.4MB -> 7.9MB  | 7.1MB/s -> 
9.98MB/s  |
| AST.cpp  | 1.3k -> 0.73K   | 0.99MB -> 0.77MB | 6.7MB/s -> 
8.4MB/s   |
|




Comment at: clang-tools-extra/pseudo/lib/cxx/cxx.bnf:39
 namespace-name := IDENTIFIER
-namespace-name := namespace-alias
-namespace-alias := IDENTIFIER
 class-name := IDENTIFIER
 class-name := simple-template-id

this can be removed as well, but the `class-head-name` rule uses it. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130747

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


[PATCH] D130747: [pseudo] wip/prototype: eliminate identifier ambiguities in the grammar.

2022-08-16 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 453098.
hokein added a comment.

update based on the offline discussion -- we'd like to keep all categories of
IDENTIFIER (type-name, namespace-name, template-name, template-name) as they
are useful in disambiguation, but we eliminate the ambiguities per each category

- eliminate all different type rules (class-name, enum-name, typedef-name), 
fold them into a unified type-name, this removes the #1 type-name ambiguity, 
and gives us a big performance boost;
- remove the namespace-alis rules, as they're less interesting and marginal 
useful;


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D130747

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


Index: clang-tools-extra/pseudo/test/glr.cpp
===
--- clang-tools-extra/pseudo/test/glr.cpp
+++ clang-tools-extra/pseudo/test/glr.cpp
@@ -12,10 +12,7 @@
 // CHECK-NEXT: │ └─; := tok[8]
 // CHECK-NEXT: └─statement~simple-declaration := decl-specifier-seq 
init-declarator-list ;
 // CHECK-NEXT:   ├─decl-specifier-seq~simple-type-specifier := 
-// CHECK-NEXT:   │ ├─simple-type-specifier~type-name := 
-// CHECK-NEXT:   │ │ ├─type-name~IDENTIFIER := tok[5]
-// CHECK-NEXT:   │ │ ├─type-name~IDENTIFIER := tok[5]
-// CHECK-NEXT:   │ │ └─type-name~IDENTIFIER := tok[5]
+// CHECK-NEXT:   │ ├─simple-type-specifier~IDENTIFIER := tok[5]
 // CHECK-NEXT:   │ └─simple-type-specifier~IDENTIFIER := tok[5]
 // CHECK-NEXT:   ├─init-declarator-list~ptr-declarator := ptr-operator 
ptr-declarator
 // CHECK-NEXT:   │ ├─ptr-operator~* := tok[6]
@@ -23,12 +20,11 @@
 // CHECK-NEXT:   └─; := tok[8]
 }
 
-// CHECK:  3 Ambiguous nodes:
+// CHECK:  2 Ambiguous nodes:
 // CHECK-NEXT: 1 simple-type-specifier
 // CHECK-NEXT: 1 statement
-// CHECK-NEXT: 1 type-name
 // CHECK-EMPTY:
 // CHECK-NEXT: 0 Opaque nodes:
 // CHECK-EMPTY:
-// CHECK-NEXT: Ambiguity: 0.40 misparses/token
+// CHECK-NEXT: Ambiguity: 0.20 misparses/token
 // CHECK-NEXT: Unparsed: 0.00%
Index: clang-tools-extra/pseudo/lib/cxx/cxx.bnf
===
--- clang-tools-extra/pseudo/lib/cxx/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx/cxx.bnf
@@ -34,14 +34,10 @@
 _ := declaration-seq
 
 # gram.key
-typedef-name := IDENTIFIER
-typedef-name := simple-template-id
+#! No namespace-alis rules, as they're less interesting and marginal useful.
 namespace-name := IDENTIFIER
-namespace-name := namespace-alias
-namespace-alias := IDENTIFIER
 class-name := IDENTIFIER
 class-name := simple-template-id
-enum-name := IDENTIFIER
 template-name := IDENTIFIER
 
 # gram.basic
@@ -391,9 +387,12 @@
 builtin-type := FLOAT
 builtin-type := DOUBLE
 builtin-type := VOID
-type-name := class-name
-type-name := enum-name
-type-name := typedef-name
+#! Unlike C++ standard grammar, we don't distinguish the underlying type 
(class,
+#! enum, typedef) of the IDENTIFIER, as these ambiguities are "local" and don't
+#! affect the final parse tree. Eliminating them gives a significant 
performance
+#! boost to the parser.
+type-name := IDENTIFIER
+type-name := simple-template-id
 elaborated-type-specifier := class-key nested-name-specifier_opt IDENTIFIER
 elaborated-type-specifier := class-key simple-template-id
 elaborated-type-specifier := class-key nested-name-specifier TEMPLATE_opt 
simple-template-id


Index: clang-tools-extra/pseudo/test/glr.cpp
===
--- clang-tools-extra/pseudo/test/glr.cpp
+++ clang-tools-extra/pseudo/test/glr.cpp
@@ -12,10 +12,7 @@
 // CHECK-NEXT: │ └─; := tok[8]
 // CHECK-NEXT: └─statement~simple-declaration := decl-specifier-seq init-declarator-list ;
 // CHECK-NEXT:   ├─decl-specifier-seq~simple-type-specifier := 
-// CHECK-NEXT:   │ ├─simple-type-specifier~type-name := 
-// CHECK-NEXT:   │ │ ├─type-name~IDENTIFIER := tok[5]
-// CHECK-NEXT:   │ │ ├─type-name~IDENTIFIER := tok[5]
-// CHECK-NEXT:   │ │ └─type-name~IDENTIFIER := tok[5]
+// CHECK-NEXT:   │ ├─simple-type-specifier~IDENTIFIER := tok[5]
 // CHECK-NEXT:   │ └─simple-type-specifier~IDENTIFIER := tok[5]
 // CHECK-NEXT:   ├─init-declarator-list~ptr-declarator := ptr-operator ptr-declarator
 // CHECK-NEXT:   │ ├─ptr-operator~* := tok[6]
@@ -23,12 +20,11 @@
 // CHECK-NEXT:   └─; := tok[8]
 }
 
-// CHECK:  3 Ambiguous nodes:
+// CHECK:  2 Ambiguous nodes:
 // CHECK-NEXT: 1 simple-type-specifier
 // CHECK-NEXT: 1 statement
-// CHECK-NEXT: 1 type-name
 // CHECK-EMPTY:
 // CHECK-NEXT: 0 Opaque nodes:
 // CHECK-EMPTY:
-// CHECK-NEXT: Ambiguity: 0.40 misparses/token
+// CHECK-NEXT: Ambiguity: 0.20 misparses/token
 // CHECK-NEXT: Unparsed: 0.00%
Index: clang-tools-extra/pseudo/lib/cxx/cxx.bnf
===
--- 

[PATCH] D131541: [Sema] Fix friend destructor declarations after D130936

2022-08-16 Thread Roy Jacobson via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG68786f063275: [Sema] Fix friend destructor declarations 
after D130936 (authored by royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131541

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaCXX/member-class-11.cpp

Index: clang/test/SemaCXX/member-class-11.cpp
===
--- clang/test/SemaCXX/member-class-11.cpp
+++ clang/test/SemaCXX/member-class-11.cpp
@@ -26,4 +26,56 @@
   ~B(); // expected-error {{expected the class name after '~' to name the enclosing class}}
 };
 
+template 
+struct D {
+  friend T::S::~S();
+private:
+  static constexpr int secret = 42;
+};
+
+template 
+struct E {
+  friend T::S::~V();
+};
+
+struct BadInstantiation {
+  struct S {
+struct V {};
+  };
+};
+
+struct GoodInstantiation {
+  struct V {
+~V();
+  };
+  using S = V;
+};
+
+// FIXME: We should diagnose this while instantiating.
+E x;
+E y;
+
+struct Q {
+  struct S { ~S(); };
+};
+
+Q::S::~S() {
+  void foo(int);
+  foo(D::secret);
+}
+
+struct X {
+  ~X();
+};
+struct Y;
+
+struct Z1 {
+  friend X::~Y(); // expected-error {{expected the class name after '~' to name the enclosing class}}
+};
+
+template 
+struct Z2 {
+  friend X::~Y(); // expected-error {{expected the class name after '~' to name the enclosing class}}
+};
+
 }
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -11514,16 +11514,25 @@
 if (CXXConstructorDecl *Constructor = dyn_cast(NewFD)) {
   CheckConstructor(Constructor);
 } else if (CXXDestructorDecl *Destructor =
-dyn_cast(NewFD)) {
-  CXXRecordDecl *Record = Destructor->getParent();
-  QualType ClassType = Context.getTypeDeclType(Record);
-
-  DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
-  Context.getCanonicalType(ClassType));
-  if (NewFD->getDeclName() != Name) {
-Diag(NewFD->getLocation(), diag::err_destructor_name);
-NewFD->setInvalidDecl();
-return Redeclaration;
+   dyn_cast(NewFD)) {
+  // We check here for invalid destructor names.
+  // If we have a friend destructor declaration that is dependent, we can't
+  // diagnose right away because cases like this are still valid:
+  // template  struct A { friend T::X::~Y(); };
+  // struct B { struct Y { ~Y(); }; using X = Y; };
+  // template struct A;
+  if (NewFD->getFriendObjectKind() == Decl::FriendObjectKind::FOK_None ||
+  !Destructor->getThisType()->isDependentType()) {
+CXXRecordDecl *Record = Destructor->getParent();
+QualType ClassType = Context.getTypeDeclType(Record);
+
+DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
+Context.getCanonicalType(ClassType));
+if (NewFD->getDeclName() != Name) {
+  Diag(NewFD->getLocation(), diag::err_destructor_name);
+  NewFD->setInvalidDecl();
+  return Redeclaration;
+}
   }
 } else if (auto *Guide = dyn_cast(NewFD)) {
   if (auto *TD = Guide->getDescribedFunctionTemplate())
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 68786f0 - [Sema] Fix friend destructor declarations after D130936

2022-08-16 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-08-16T22:28:19+03:00
New Revision: 68786f06327519b30ab3ee2ba27451ec051bbb6f

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

LOG: [Sema] Fix friend destructor declarations after D130936

I accidentally broke friend destructor declarations in D130936.

Modify it to skip performing the destructor name check if we have a dependent 
friend declaration.

Reviewed By: hubert.reinterpretcast

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

Added: 


Modified: 
clang/lib/Sema/SemaDecl.cpp
clang/test/SemaCXX/member-class-11.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 94009d33fa94e..7e7433d13d002 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -11514,16 +11514,25 @@ bool Sema::CheckFunctionDeclaration(Scope *S, 
FunctionDecl *NewFD,
 if (CXXConstructorDecl *Constructor = dyn_cast(NewFD)) 
{
   CheckConstructor(Constructor);
 } else if (CXXDestructorDecl *Destructor =
-dyn_cast(NewFD)) {
-  CXXRecordDecl *Record = Destructor->getParent();
-  QualType ClassType = Context.getTypeDeclType(Record);
-
-  DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
-  Context.getCanonicalType(ClassType));
-  if (NewFD->getDeclName() != Name) {
-Diag(NewFD->getLocation(), diag::err_destructor_name);
-NewFD->setInvalidDecl();
-return Redeclaration;
+   dyn_cast(NewFD)) {
+  // We check here for invalid destructor names.
+  // If we have a friend destructor declaration that is dependent, we can't
+  // diagnose right away because cases like this are still valid:
+  // template  struct A { friend T::X::~Y(); };
+  // struct B { struct Y { ~Y(); }; using X = Y; };
+  // template struct A;
+  if (NewFD->getFriendObjectKind() == Decl::FriendObjectKind::FOK_None ||
+  !Destructor->getThisType()->isDependentType()) {
+CXXRecordDecl *Record = Destructor->getParent();
+QualType ClassType = Context.getTypeDeclType(Record);
+
+DeclarationName Name = Context.DeclarationNames.getCXXDestructorName(
+Context.getCanonicalType(ClassType));
+if (NewFD->getDeclName() != Name) {
+  Diag(NewFD->getLocation(), diag::err_destructor_name);
+  NewFD->setInvalidDecl();
+  return Redeclaration;
+}
   }
 } else if (auto *Guide = dyn_cast(NewFD)) {
   if (auto *TD = Guide->getDescribedFunctionTemplate())

diff  --git a/clang/test/SemaCXX/member-class-11.cpp 
b/clang/test/SemaCXX/member-class-11.cpp
index 68873ebad9d1d..20d6bce954f19 100644
--- a/clang/test/SemaCXX/member-class-11.cpp
+++ b/clang/test/SemaCXX/member-class-11.cpp
@@ -26,4 +26,56 @@ struct C {
   ~B(); // expected-error {{expected the class name after '~' to name the 
enclosing class}}
 };
 
+template 
+struct D {
+  friend T::S::~S();
+private:
+  static constexpr int secret = 42;
+};
+
+template 
+struct E {
+  friend T::S::~V();
+};
+
+struct BadInstantiation {
+  struct S {
+struct V {};
+  };
+};
+
+struct GoodInstantiation {
+  struct V {
+~V();
+  };
+  using S = V;
+};
+
+// FIXME: We should diagnose this while instantiating.
+E x;
+E y;
+
+struct Q {
+  struct S { ~S(); };
+};
+
+Q::S::~S() {
+  void foo(int);
+  foo(D::secret);
+}
+
+struct X {
+  ~X();
+};
+struct Y;
+
+struct Z1 {
+  friend X::~Y(); // expected-error {{expected the class name after '~' to 
name the enclosing class}}
+};
+
+template 
+struct Z2 {
+  friend X::~Y(); // expected-error {{expected the class name after '~' to 
name the enclosing class}}
+};
+
 }



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


[PATCH] D127233: [CodeGen] Sort llvm.global_ctors by lexical order before emission

2022-08-16 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 453095.
ychen added a comment.

- rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127233

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/test/CodeGenCXX/static-init-inline-variable.cpp

Index: clang/test/CodeGenCXX/static-init-inline-variable.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/static-init-inline-variable.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -std=c++17 -S -emit-llvm -disable-llvm-passes -o - %s -triple x86_64-linux-gnu | FileCheck %s
+
+struct A {
+  int x;
+  A(int x) : x(x) {}
+  ~A() {}
+};
+
+inline int a = 1;
+inline A b(a + 1);
+inline int c = b.x + 1;
+int d = c;
+
+// CHECK: @llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init, ptr @b }, { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.2, ptr @c }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_static_init_inline_variable.cpp, ptr null }]
Index: clang/lib/CodeGen/ItaniumCXXABI.cpp
===
--- clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2687,7 +2687,7 @@
 }
 
 CGF.FinishFunction();
-AddGlobalCtor(GlobalInitFn, Priority, nullptr);
+AddGlobalCtor(GlobalInitFn, Priority);
   }
 
   if (getCXXABI().useSinitAndSterm())
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -282,12 +282,15 @@
 
 public:
   struct Structor {
-Structor() : Priority(0), Initializer(nullptr), AssociatedData(nullptr) {}
-Structor(int Priority, llvm::Constant *Initializer,
+Structor()
+: Priority(0), LexOrder(~0u), Initializer(nullptr),
+  AssociatedData(nullptr) {}
+Structor(int Priority, unsigned LexOrder, llvm::Constant *Initializer,
  llvm::Constant *AssociatedData)
-: Priority(Priority), Initializer(Initializer),
+: Priority(Priority), LexOrder(LexOrder), Initializer(Initializer),
   AssociatedData(AssociatedData) {}
 int Priority;
+unsigned LexOrder;
 llvm::Constant *Initializer;
 llvm::Constant *AssociatedData;
   };
@@ -1602,6 +1605,7 @@
 
   // FIXME: Hardcoding priority here is gross.
   void AddGlobalCtor(llvm::Function *Ctor, int Priority = 65535,
+ unsigned LexOrder = ~0U,
  llvm::Constant *AssociatedData = nullptr);
   void AddGlobalDtor(llvm::Function *Dtor, int Priority = 65535,
  bool IsDtorAttrFunc = false);
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -47,6 +47,7 @@
 #include "clang/CodeGen/BackendUtil.h"
 #include "clang/CodeGen/ConstantInitBuilder.h"
 #include "clang/Frontend/FrontendDiagnostic.h"
+#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/ADT/Triple.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
@@ -560,6 +561,9 @@
 if (PGOStats.hasDiagnostics())
   PGOStats.reportDiagnostics(getDiags(), getCodeGenOpts().MainFileName);
   }
+  llvm::stable_sort(GlobalCtors, [](const Structor , const Structor ) {
+return L.LexOrder < R.LexOrder;
+  });
   EmitCtorList(GlobalCtors, "llvm.global_ctors");
   EmitCtorList(GlobalDtors, "llvm.global_dtors");
   EmitGlobalAnnotations();
@@ -1584,9 +1588,10 @@
 /// AddGlobalCtor - Add a function to the list that will be called before
 /// main() runs.
 void CodeGenModule::AddGlobalCtor(llvm::Function *Ctor, int Priority,
+  unsigned LexOrder,
   llvm::Constant *AssociatedData) {
   // FIXME: Type coercion of void()* types.
-  GlobalCtors.push_back(Structor(Priority, Ctor, AssociatedData));
+  GlobalCtors.push_back(Structor(Priority, LexOrder, Ctor, AssociatedData));
 }
 
 /// AddGlobalDtor - Add a function to the list that will be called
@@ -1600,7 +1605,7 @@
   }
 
   // FIXME: Type coercion of void()* types.
-  GlobalDtors.push_back(Structor(Priority, Dtor, nullptr));
+  GlobalDtors.push_back(Structor(Priority, ~0U, Dtor, nullptr));
 }
 
 void CodeGenModule::EmitCtorList(CtorList , const char *GlobalName) {
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -577,8 +577,11 @@
 // SelectAny globals will be comdat-folded. Put the initializer into a
 // COMDAT group associated with the global, so the initializers get folded
 // too.
-
-

[PATCH] D127233: [CodeGen] Sort llvm.global_ctors by lexical order before emission

2022-08-16 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen updated this revision to Diff 453094.
ychen added a comment.

- use correct lexing order for non-deferred constructors.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127233

Files:
  clang/lib/CodeGen/CGDeclCXX.cpp
  clang/test/CodeGenCXX/static-init-inline-variable.cpp


Index: clang/test/CodeGenCXX/static-init-inline-variable.cpp
===
--- clang/test/CodeGenCXX/static-init-inline-variable.cpp
+++ clang/test/CodeGenCXX/static-init-inline-variable.cpp
@@ -1,7 +1,14 @@
 // RUN: %clang_cc1 -std=c++17 -S -emit-llvm -disable-llvm-passes -o - %s 
-triple x86_64-linux-gnu | FileCheck %s
 
+struct A {
+  int x;
+  A(int x) : x(x) {}
+  ~A() {}
+};
+
 inline int a = 1;
-inline int b = a + 1;
-inline int c = b + 1;
+inline A b(a + 1);
+inline int c = b.x + 1;
 int d = c;
-// CHECK: @llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ 
i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.2, ptr @b }, { i32, 
ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.1, ptr @c }, { i32, ptr, ptr 
} { i32 65535, ptr @_GLOBAL__sub_I_static_init_inline_variable.cpp, ptr null }]
+
+// CHECK: @llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ 
i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init, ptr @b }, { i32, ptr, 
ptr } { i32 65535, ptr @__cxx_global_var_init.2, ptr @c }, { i32, ptr, ptr } { 
i32 65535, ptr @_GLOBAL__sub_I_static_init_inline_variable.cpp, ptr null }]
\ No newline at end of file
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -578,7 +578,9 @@
 // COMDAT group associated with the global, so the initializers get folded
 // too.
 I = DelayedCXXInitPosition.find(D);
-unsigned LexOrder = I == DelayedCXXInitPosition.end() ? ~0U : I->second;
+// CXXGlobalInits.size() is the lex order for non-deferred emission.
+unsigned LexOrder =
+I == DelayedCXXInitPosition.end() ? CXXGlobalInits.size() : I->second;
 AddGlobalCtor(Fn, 65535, LexOrder, COMDATKey);
 if (COMDATKey && (getTriple().isOSBinFormatELF() ||
   getTarget().getCXXABI().isMicrosoft())) {


Index: clang/test/CodeGenCXX/static-init-inline-variable.cpp
===
--- clang/test/CodeGenCXX/static-init-inline-variable.cpp
+++ clang/test/CodeGenCXX/static-init-inline-variable.cpp
@@ -1,7 +1,14 @@
 // RUN: %clang_cc1 -std=c++17 -S -emit-llvm -disable-llvm-passes -o - %s -triple x86_64-linux-gnu | FileCheck %s
 
+struct A {
+  int x;
+  A(int x) : x(x) {}
+  ~A() {}
+};
+
 inline int a = 1;
-inline int b = a + 1;
-inline int c = b + 1;
+inline A b(a + 1);
+inline int c = b.x + 1;
 int d = c;
-// CHECK: @llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.2, ptr @b }, { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.1, ptr @c }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_static_init_inline_variable.cpp, ptr null }]
+
+// CHECK: @llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init, ptr @b }, { i32, ptr, ptr } { i32 65535, ptr @__cxx_global_var_init.2, ptr @c }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__sub_I_static_init_inline_variable.cpp, ptr null }]
\ No newline at end of file
Index: clang/lib/CodeGen/CGDeclCXX.cpp
===
--- clang/lib/CodeGen/CGDeclCXX.cpp
+++ clang/lib/CodeGen/CGDeclCXX.cpp
@@ -578,7 +578,9 @@
 // COMDAT group associated with the global, so the initializers get folded
 // too.
 I = DelayedCXXInitPosition.find(D);
-unsigned LexOrder = I == DelayedCXXInitPosition.end() ? ~0U : I->second;
+// CXXGlobalInits.size() is the lex order for non-deferred emission.
+unsigned LexOrder =
+I == DelayedCXXInitPosition.end() ? CXXGlobalInits.size() : I->second;
 AddGlobalCtor(Fn, 65535, LexOrder, COMDATKey);
 if (COMDATKey && (getTriple().isOSBinFormatELF() ||
   getTarget().getCXXABI().isMicrosoft())) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131986: [inlining] Add a clang option to control inlining of functions based on stack size

2022-08-16 Thread Arthur Eubanks via Phabricator via cfe-commits
aeubanks accepted this revision.
aeubanks added a comment.
This revision is now accepted and ready to land.

perhaps a test that "inline-max-stacksze" doesn't appear if the flag isn't 
specified?


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

https://reviews.llvm.org/D131986

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


[clang] 7d8ae9f - [NFC][PowerPC] Add missing NOCOMPAT checks for builtins-ppc-xlcompat.c

2022-08-16 Thread Lei Huang via cfe-commits

Author: Lei Huang
Date: 2022-08-16T13:56:33-05:00
New Revision: 7d8ae9f755d7ae65ab116220d6d42108ee10f815

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

LOG: [NFC][PowerPC] Add missing NOCOMPAT checks for builtins-ppc-xlcompat.c

Followup patch to address request from https://reviews.llvm.org/D124093

Reviewed By: amyk

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

Added: 


Modified: 
clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c

Removed: 




diff  --git a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c 
b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
index 1344f551ba9ff..a86d9547558e3 100644
--- a/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
+++ b/clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
@@ -21,29 +21,38 @@ vector unsigned int res_vui;
 void test() {
 // CHECK-LABEL: @test(
 // CHECK-NEXT:  entry:
-// CHECK-LE-LABEL: @test(
-// CHECK-LE-NEXT:  entry:
+// NOCOMPAT-LABEL: @test(
+// NOCOMPAT-NEXT:  entry:
 
   res_vf = vec_ctf(vsll, 4);
 // CHECK: [[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @vsll, align 16
 // CHECK-NEXT:[[TMP1:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvsxdsp(<2 x 
i64> [[TMP0]])
 // CHECK-NEXT:fmul <4 x float> [[TMP1]], 
+// NOCOMPAT:  [[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @vsll, align 16
+// NOCOMPAT-NEXT: [[CONV:%.*]] = sitofp <2 x i64> [[TMP0]] to <2 x double>
+// NOCOMPAT-NEXT: fmul <2 x double> [[CONV]], 
 
   res_vf = vec_ctf(vull, 4);
 // CHECK: [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* @vull, align 16
 // CHECK-NEXT:[[TMP3:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvuxdsp(<2 x 
i64> [[TMP2]])
 // CHECK-NEXT:fmul <4 x float> [[TMP3]], 
+// NOCOMPAT:  [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* @vull, align 16
+// NOCOMPAT-NEXT: [[CONV1:%.*]] = uitofp <2 x i64> [[TMP2]] to <2 x double>
+// NOCOMPAT-NEXT: fmul <2 x double> [[CONV1]], 
 
   res_vsll = vec_cts(vd, 4);
 // CHECK: [[TMP4:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
 // CHECK-NEXT:fmul <2 x double> [[TMP4]], 
 // CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpsxws(<2 x double>
+// NOCOMPAT:  [[TMP4:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// NOCOMPAT-NEXT: fmul <2 x double> [[TMP4]], 
 
   res_vull = vec_ctu(vd, 4);
 // CHECK: [[TMP8:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
 // CHECK-NEXT:fmul <2 x double> [[TMP8]], 
 // CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
-// NONCOMPAT: call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
+// NOCOMPAT:  [[TMP7:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// NOCOMPAT-NEXT: fmul <2 x double> [[TMP7]], 
 
   res_vd = vec_round(vd);
 // CHECK: call double @llvm.ppc.readflm()



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


[PATCH] D131622: [NFC][PowerPC] Add missing NOCOMPAT checks for builtins-ppc-xlcompat.c

2022-08-16 Thread Lei Huang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7d8ae9f755d7: [NFC][PowerPC] Add missing NOCOMPAT checks for 
builtins-ppc-xlcompat.c (authored by lei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131622

Files:
  clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c


Index: clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
===
--- clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
+++ clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
@@ -21,29 +21,38 @@
 void test() {
 // CHECK-LABEL: @test(
 // CHECK-NEXT:  entry:
-// CHECK-LE-LABEL: @test(
-// CHECK-LE-NEXT:  entry:
+// NOCOMPAT-LABEL: @test(
+// NOCOMPAT-NEXT:  entry:
 
   res_vf = vec_ctf(vsll, 4);
 // CHECK: [[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @vsll, align 16
 // CHECK-NEXT:[[TMP1:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvsxdsp(<2 x 
i64> [[TMP0]])
 // CHECK-NEXT:fmul <4 x float> [[TMP1]], 
+// NOCOMPAT:  [[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @vsll, align 16
+// NOCOMPAT-NEXT: [[CONV:%.*]] = sitofp <2 x i64> [[TMP0]] to <2 x double>
+// NOCOMPAT-NEXT: fmul <2 x double> [[CONV]], 
 
   res_vf = vec_ctf(vull, 4);
 // CHECK: [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* @vull, align 16
 // CHECK-NEXT:[[TMP3:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvuxdsp(<2 x 
i64> [[TMP2]])
 // CHECK-NEXT:fmul <4 x float> [[TMP3]], 
+// NOCOMPAT:  [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* @vull, align 16
+// NOCOMPAT-NEXT: [[CONV1:%.*]] = uitofp <2 x i64> [[TMP2]] to <2 x double>
+// NOCOMPAT-NEXT: fmul <2 x double> [[CONV1]], 
 
   res_vsll = vec_cts(vd, 4);
 // CHECK: [[TMP4:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
 // CHECK-NEXT:fmul <2 x double> [[TMP4]], 
 // CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpsxws(<2 x double>
+// NOCOMPAT:  [[TMP4:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// NOCOMPAT-NEXT: fmul <2 x double> [[TMP4]], 
 
   res_vull = vec_ctu(vd, 4);
 // CHECK: [[TMP8:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
 // CHECK-NEXT:fmul <2 x double> [[TMP8]], 
 // CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
-// NONCOMPAT: call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
+// NOCOMPAT:  [[TMP7:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// NOCOMPAT-NEXT: fmul <2 x double> [[TMP7]], 
 
   res_vd = vec_round(vd);
 // CHECK: call double @llvm.ppc.readflm()


Index: clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
===
--- clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
+++ clang/test/CodeGen/PowerPC/builtins-ppc-xlcompat.c
@@ -21,29 +21,38 @@
 void test() {
 // CHECK-LABEL: @test(
 // CHECK-NEXT:  entry:
-// CHECK-LE-LABEL: @test(
-// CHECK-LE-NEXT:  entry:
+// NOCOMPAT-LABEL: @test(
+// NOCOMPAT-NEXT:  entry:
 
   res_vf = vec_ctf(vsll, 4);
 // CHECK: [[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @vsll, align 16
 // CHECK-NEXT:[[TMP1:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvsxdsp(<2 x i64> [[TMP0]])
 // CHECK-NEXT:fmul <4 x float> [[TMP1]], 
+// NOCOMPAT:  [[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @vsll, align 16
+// NOCOMPAT-NEXT: [[CONV:%.*]] = sitofp <2 x i64> [[TMP0]] to <2 x double>
+// NOCOMPAT-NEXT: fmul <2 x double> [[CONV]], 
 
   res_vf = vec_ctf(vull, 4);
 // CHECK: [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* @vull, align 16
 // CHECK-NEXT:[[TMP3:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvuxdsp(<2 x i64> [[TMP2]])
 // CHECK-NEXT:fmul <4 x float> [[TMP3]], 
+// NOCOMPAT:  [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* @vull, align 16
+// NOCOMPAT-NEXT: [[CONV1:%.*]] = uitofp <2 x i64> [[TMP2]] to <2 x double>
+// NOCOMPAT-NEXT: fmul <2 x double> [[CONV1]], 
 
   res_vsll = vec_cts(vd, 4);
 // CHECK: [[TMP4:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
 // CHECK-NEXT:fmul <2 x double> [[TMP4]], 
 // CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpsxws(<2 x double>
+// NOCOMPAT:  [[TMP4:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// NOCOMPAT-NEXT: fmul <2 x double> [[TMP4]], 
 
   res_vull = vec_ctu(vd, 4);
 // CHECK: [[TMP8:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
 // CHECK-NEXT:fmul <2 x double> [[TMP8]], 
 // CHECK: call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
-// NONCOMPAT: call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
+// NOCOMPAT:  [[TMP7:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// NOCOMPAT-NEXT: fmul <2 x double> [[TMP7]], 
 
   res_vd = vec_round(vd);
 // CHECK: call double @llvm.ppc.readflm()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D131934: [clang][deps] Compute command-lines for dependencies immediately

2022-08-16 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir marked 2 inline comments as done.
benlangmuir added inline comments.



Comment at: clang/tools/clang-scan-deps/ClangScanDeps.cpp:403
+
+static std::string getModuleCachePath(ArrayRef Args) {
+  for (StringRef Arg : llvm::reverse(Args)) {

jansvoboda11 wrote:
> Can you split this into separate patch?
This is hard because we don't have the association between input command-line 
and module dependencies in the previous code.  Per our offline discussion I've 
mentioned this in the commit message instead.


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

https://reviews.llvm.org/D131934

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


[PATCH] D131934: [clang][deps] Compute command-lines for dependencies immediately

2022-08-16 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir updated this revision to Diff 453085.
benlangmuir edited the summary of this revision.
benlangmuir added a comment.

Per review

- Add typedef for callback type
- Add comment about mapping paths to "-"
- Update commit message for module cache path computation change


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

https://reviews.llvm.org/D131934

Files:
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningTool.h
  clang/include/clang/Tooling/DependencyScanning/DependencyScanningWorker.h
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -6,6 +6,7 @@
 //
 //===--===//
 
+#include "clang/Driver/Driver.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
@@ -268,10 +269,7 @@
   Modules.insert(I, {{MD.ID, InputIndex}, std::move(MD)});
 }
 
-ID.CommandLine =
-FD.getCommandLine([&](const ModuleID , ModuleOutputKind MOK) {
-  return lookupModuleOutput(MID, MOK);
-});
+ID.CommandLine = FD.CommandLine;
 Inputs.push_back(std::move(ID));
   }
 
@@ -301,10 +299,7 @@
   {"file-deps", toJSONSorted(MD.FileDeps)},
   {"clang-module-deps", toJSONSorted(MD.ClangModuleDeps)},
   {"clang-modulemap-file", MD.ClangModuleMapFile},
-  {"command-line", MD.getCanonicalCommandLine(
-   [&](const ModuleID , ModuleOutputKind MOK) {
- return lookupModuleOutput(MID, MOK);
-   })},
+  {"command-line", MD.getCanonicalCommandLine()},
   };
   OutModules.push_back(std::move(O));
 }
@@ -330,42 +325,6 @@
   }
 
 private:
-  std::string lookupModuleOutput(const ModuleID , ModuleOutputKind MOK) {
-// Cache the PCM path, since it will be queried repeatedly for each module.
-// The other outputs are only queried once during getCanonicalCommandLine.
-auto PCMPath = PCMPaths.insert({MID, ""});
-if (PCMPath.second)
-  PCMPath.first->second = constructPCMPath(MID);
-switch (MOK) {
-case ModuleOutputKind::ModuleFile:
-  return PCMPath.first->second;
-case ModuleOutputKind::DependencyFile:
-  return PCMPath.first->second + ".d";
-case ModuleOutputKind::DependencyTargets:
-  // Null-separate the list of targets.
-  return join(ModuleDepTargets, StringRef("\0", 1));
-case ModuleOutputKind::DiagnosticSerializationFile:
-  return PCMPath.first->second + ".diag";
-}
-llvm_unreachable("Fully covered switch above!");
-  }
-
-  /// Construct a path for the explicitly built PCM.
-  std::string constructPCMPath(ModuleID MID) const {
-auto MDIt = Modules.find(IndexedModuleID{MID, 0});
-assert(MDIt != Modules.end());
-const ModuleDeps  = MDIt->second;
-
-StringRef Filename = llvm::sys::path::filename(MD.ImplicitModulePCMPath);
-StringRef ModuleCachePath = llvm::sys::path::parent_path(
-llvm::sys::path::parent_path(MD.ImplicitModulePCMPath));
-
-SmallString<256> ExplicitPCMPath(!ModuleFilesDir.empty() ? ModuleFilesDir
- : ModuleCachePath);
-llvm::sys::path::append(ExplicitPCMPath, MD.ID.ContextHash, Filename);
-return std::string(ExplicitPCMPath);
-  }
-
   struct IndexedModuleID {
 ModuleID ID;
 mutable size_t InputIndex;
@@ -395,7 +354,6 @@
   std::mutex Lock;
   std::unordered_map
   Modules;
-  std::unordered_map PCMPaths;
   std::vector Inputs;
 };
 
@@ -417,6 +375,42 @@
   return false;
 }
 
+/// Construct a path for the explicitly built PCM.
+static std::string constructPCMPath(ModuleID MID, StringRef OutputDir) {
+  SmallString<256> ExplicitPCMPath(OutputDir);
+  llvm::sys::path::append(ExplicitPCMPath, MID.ContextHash,
+  MID.ModuleName + "-" + MID.ContextHash + ".pcm");
+  return std::string(ExplicitPCMPath);
+}
+
+static std::string lookupModuleOutput(const ModuleID , ModuleOutputKind MOK,
+  StringRef OutputDir) {
+  std::string PCMPath = constructPCMPath(MID, OutputDir);
+  switch (MOK) {
+  case ModuleOutputKind::ModuleFile:
+return PCMPath;
+  case ModuleOutputKind::DependencyFile:
+return PCMPath + ".d";
+  case ModuleOutputKind::DependencyTargets:
+// Null-separate the list of targets.
+return join(ModuleDepTargets, StringRef("\0", 1));
+  case 

[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Oleg Smolsky via Phabricator via cfe-commits
oleg.smolsky updated this revision to Diff 453084.
oleg.smolsky added a comment.

Drop the trailing \n from the main C++ file


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

https://reviews.llvm.org/D131985

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
  clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp

Index: clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-return-with-redundant-parens %t
+
+int good() {
+  return 1;
+}
+
+int simple1() {
+  return (1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
+
+int complex1() {
+  int a = 0;
+  return (a + a * (a + a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return a + a * (a + a);{{$}}
+}
+
+int no_space() {
+  return(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
Index: clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
@@ -0,0 +1,38 @@
+//===--- ReturnWithRedundantParensCheck.h - clang-tidy --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find and remove redundant parenthesis surrounding returned expression.
+///
+/// Examples:
+/// \code
+///   void f() { return (1); } ==> void f() { return 1; }
+/// \endcode
+class ReturnWithRedundantParensCheck : public ClangTidyCheck {
+public:
+  ReturnWithRedundantParensCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
Index: clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
@@ -0,0 +1,69 @@
+//===--- ReturnWithRedundantParensCheck.cpp - clang-tidy *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ReturnWithRedundantParensCheck.h"
+#include "clang/Lex/Lexer.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+namespace {
+bool isLocationInMacroExpansion(const SourceManager , SourceLocation Loc) {
+  return SM.isMacroBodyExpansion(Loc) || SM.isMacroArgExpansion(Loc);
+}
+} // namespace
+
+void ReturnWithRedundantParensCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(
+  isDefinition(), returns(unless(voidType())),
+  hasBody(compoundStmt(hasAnySubstatement(returnStmt(has(expr()
+  .bind("return"))),
+  this);
+}
+
+void ReturnWithRedundantParensCheck::check(
+const ast_matchers::MatchFinder::MatchResult ) {
+  const auto *Block = Result.Nodes.getNodeAs("return");
+  CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin();
+  if (const auto *Return = dyn_cast(*Last)) {
+SourceManager  = *Result.SourceManager;
+
+if (isLocationInMacroExpansion(SM, Return->getSourceRange().getBegin()))
+  return;
+
+assert(!Return->children().empty());
+auto ChildExpr = 

[PATCH] D131986: [inlining] Add a clang option to control inlining of functions based on stack size

2022-08-16 Thread Wolfgang Pieb via Phabricator via cfe-commits
wolfgangp created this revision.
wolfgangp added reviewers: mtrofin, aeubanks.
Herald added a project: All.
wolfgangp requested review of this revision.
Herald added a subscriber: MaskRay.

Adding -finline-max-stacksize= to clang. This generates the function 
attribute` inline-max-stacksize` (introduced in D129904 
, suppressing inlining of functions with 
stack sizes exceeding a specified limit.


https://reviews.llvm.org/D131986

Files:
  clang/docs/ClangCommandLineReference.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGen/inline-stacksize.c


Index: clang/test/CodeGen/inline-stacksize.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-stacksize.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -O2 -finline-max-stacksize=64 -emit-llvm %s -o - | 
FileCheck %s
+
+void foo() {}
+
+// CHECK: define {{.*}}@foo{{.*}}#[[ATTR:[0-9]+]]
+// CHECK: attributes #[[ATTR]] = {{.*}}"inline-max-stacksize"="64"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6592,6 +6592,8 @@
 InlineArg->render(Args, CmdArgs);
   }
 
+  Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
+
   // FIXME: Find a better way to determine whether the language has modules
   // support by default, or just assume that all languages do.
   bool HaveModules =
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -2372,6 +2372,9 @@
   if (getLangOpts().OpenMP && FD->hasAttr())
 getOpenMPRuntime().emitDeclareSimdFunction(FD, F);
 
+  if (CodeGenOpts.InlineMaxStackSize != UINT_MAX)
+F->addFnAttr("inline-max-stacksize", 
llvm::utostr(CodeGenOpts.InlineMaxStackSize));
+
   if (const auto *CB = FD->getAttr()) {
 // Annotate the callback behavior as metadata:
 //  - The callback callee (as argument number).
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1985,6 +1985,11 @@
 def finline_hint_functions: Flag<["-"], "finline-hint-functions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Inline functions which are (explicitly or implicitly) marked 
inline">;
 def finline : Flag<["-"], "finline">, Group;
+def finline_max_stacksize_EQ
+: Joined<["-"], "finline-max-stacksize=">,
+  Group, Flags<[CoreOption, CC1Option]>,
+  HelpText<"Suppress inlining of functions whose stack size exceeds the 
given value">,
+  MarshallingInfoInt, "UINT_MAX">;
 defm jmc : BoolFOption<"jmc",
   CodeGenOpts<"JMCInstrument">, DefaultFalse,
   PosFlag,
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -399,6 +399,9 @@
 /// The kind of inlining to perform.
 ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining)
 
+/// The maximum stack size a function can have to be considered for inlining.
+VALUE_CODEGENOPT(InlineMaxStackSize, 32, UINT_MAX)
+
 // Vector functions library to use.
 ENUM_CODEGENOPT(VecLib, VectorLibrary, 3, NoLibrary)
 
Index: clang/docs/ClangCommandLineReference.rst
===
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -945,6 +945,10 @@
 
 Inline functions which are (explicitly or implicitly) marked inline
 
+.. option:: -finline-max-stacksize=
+
+Suppress inlining of functions with a stacksize larger than  bytes.
+
 .. option:: -fno-legacy-pass-manager, -fexperimental-new-pass-manager
 
 .. option:: -fno-sanitize-ignorelist, -fno-sanitize-blacklist


Index: clang/test/CodeGen/inline-stacksize.c
===
--- /dev/null
+++ clang/test/CodeGen/inline-stacksize.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -O2 -finline-max-stacksize=64 -emit-llvm %s -o - | FileCheck %s
+
+void foo() {}
+
+// CHECK: define {{.*}}@foo{{.*}}#[[ATTR:[0-9]+]]
+// CHECK: attributes #[[ATTR]] = {{.*}}"inline-max-stacksize"="64"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -6592,6 +6592,8 @@
 InlineArg->render(Args, CmdArgs);
   }
 
+  Args.AddLastArg(CmdArgs, options::OPT_finline_max_stacksize_EQ);
+
   // FIXME: Find a better way to determine whether the language has modules
   // support by default, or 

[PATCH] D127233: [CodeGen] Sort llvm.global_ctors by lexical order before emission

2022-08-16 Thread Yuanfang Chen via Phabricator via cfe-commits
ychen added inline comments.



Comment at: clang/lib/CodeGen/CGDeclCXX.cpp:580
+I = DelayedCXXInitPosition.find(D);
+unsigned LexOrder = I == DelayedCXXInitPosition.end() ? ~0U : I->second;
+AddGlobalCtor(Fn, 65535, LexOrder, COMDATKey);

efriedma wrote:
> This ensures delayed initialization calls are ordered relative to each 
> other... but are they ordered correctly relative to non-delayed 
> initialization calls?  I'm skeptical that using a LexOrder of "~0U" is really 
> correct.  (For example, if you change the variable "b" in your testcase to a 
> struct with a destructor.)
Hmm, That's a great point. I didn't think of that. I'll take a look.



Comment at: clang/lib/CodeGen/CodeGenModule.cpp:544
   }
+  llvm::stable_sort(GlobalCtors, [](const Structor , const Structor ) {
+return L.LexOrder < R.LexOrder;

efriedma wrote:
> ychen wrote:
> > rnk wrote:
> > > Please move this sorting into EmitCtorList and apply it to destructors. I 
> > > believe they are currently emitted in source order, and the loader 
> > > executes them in reverse order, so we get the desired reverse source 
> > > order cleanup behavior.
> > I looked into this. They are indeed "currently emitted in source order". 
> > However, if a dtor ever uses an entry in `llvm.global_dtors`, it must have 
> > bailed out of deferred emission here 
> > (https://github.com/llvm/llvm-project/blob/69c09d11f877a35655e285cda96ec0699e385fc9/clang/lib/CodeGen/CodeGenModule.cpp#L3256-L3263),
> >  which is to say, the corresponding ctor is also in lexing order. So the 
> > situation is either the ctor/dtor pair both use lexing order, or there is 
> > no dtor (like `inline int` with an initializer) and the ctor is 
> > deferred/reordered where this patch kicks in.
> > 
> Is MayBeEmittedEagerly always true for variables with destructors?
Yeah, for this and `CodeGenModule::MustBeEmitted`, as long as the destructors 
are not constexpr where init order is not an issue.

https://github.com/llvm/llvm-project/blob/aacf1a9742f714dd432117d82d19a007289c3dee/clang/lib/AST/ASTContext.cpp#L11646-L11648
 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127233

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


[PATCH] D131985: clang-tidy: strip useless parens from `return` statements

2022-08-16 Thread Oleg Smolsky via Phabricator via cfe-commits
oleg.smolsky created this revision.
oleg.smolsky added a reviewer: aaron.ballman.
Herald added subscribers: carlosgalvezp, mgorny.
Herald added a project: All.
oleg.smolsky requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

- this adds a new check: `readability-return-with-redundant-parens`

We can find these with the AST matcher. We exclude macros.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D131985

Files:
  clang-tools-extra/clang-tidy/readability/CMakeLists.txt
  clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
  clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
  clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp

Index: clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/readability-return-with-redundant-parens.cpp
@@ -0,0 +1,24 @@
+// RUN: %check_clang_tidy %s readability-return-with-redundant-parens %t
+
+int good() {
+  return 1;
+}
+
+int simple1() {
+  return (1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
+
+int complex1() {
+  int a = 0;
+  return (a + a * (a + a));
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return a + a * (a + a);{{$}}
+}
+
+int no_space() {
+  return(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: Redundant parens in the 'return' statement [readability-return-with-redundant-parens]
+  // CHECK-FIXES: {{^  }}return 1;{{$}}
+}
Index: clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.h
@@ -0,0 +1,38 @@
+//===--- ReturnWithRedundantParensCheck.h - clang-tidy --*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+/// Find and remove redundant parenthesis surrounding returned expression.
+///
+/// Examples:
+/// \code
+///   void f() { return (1); } ==> void f() { return 1; }
+/// \endcode
+class ReturnWithRedundantParensCheck : public ClangTidyCheck {
+public:
+  ReturnWithRedundantParensCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+};
+
+} // namespace readability
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_RETURNBRACKETSCHECK_H
Index: clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
===
--- /dev/null
+++ clang-tools-extra/clang-tidy/readability/ReturnWithRedundantParensCheck.cpp
@@ -0,0 +1,69 @@
+//===--- ReturnWithRedundantParensCheck.cpp - clang-tidy *- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ReturnWithRedundantParensCheck.h"
+#include "clang/Lex/Lexer.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace readability {
+
+namespace {
+bool isLocationInMacroExpansion(const SourceManager , SourceLocation Loc) {
+  return SM.isMacroBodyExpansion(Loc) || SM.isMacroArgExpansion(Loc);
+}
+} // namespace
+
+void ReturnWithRedundantParensCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  functionDecl(
+  isDefinition(), returns(unless(voidType())),
+  hasBody(compoundStmt(hasAnySubstatement(returnStmt(has(expr()
+  .bind("return"))),
+  this);
+}
+
+void ReturnWithRedundantParensCheck::check(
+const ast_matchers::MatchFinder::MatchResult ) {
+  const auto *Block = Result.Nodes.getNodeAs("return");
+  CompoundStmt::const_reverse_body_iterator Last = Block->body_rbegin();
+  if (const 

[PATCH] D131464: [test] Make tests pass regardless of gnu++14/gnu++17 default

2022-08-16 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D131464#3716905 , @MaskRay wrote:

> Sorry, my previous main comment had been written before I introduced 
> `LIT_CLANG_STD_GROUP` in `llvm/utils/lit/lit/llvm/config.py`. The multiple 
> `%clang_cc1` approach actually looks like the following.
> Note the use of `%stdcxx_17-` to make the test future-proof.
> (It is non-trivial to run one `RUN` line multiples times with different 
> `LIT_CLANG_STD_GROUP`. For now I just test locally with different 
> `LIT_CLANG_STD_GROUP`.)
>
>   // RUN: %clang_cc1 %s -fsyntax-only -verify=expected,precxx17 %stdcxx_11-14 
> -fdata-sections -fcolor-diagnostics
>   // RUN: %clang_cc1 %s -fsyntax-only -verify %stdcxx_17- -fdata-sections 
> -fcolor-diagnostics
>   
>   ...
> TypedefAligned4 TA8c = TA8a + TA8b;  // expected-warning {{passing 4-byte 
> aligned argument to 8-byte aligned parameter 'this' of 'operator+' may result 
> in an unaligned pointer access}} \
>  // expected-warning {{passing 4-byte 
> aligned argument to 8-byte aligned parameter 1 of 'operator+' may result in 
> an unaligned pointer access}} \
>  // precxx17-warning {{passing 4-byte 
> aligned argument to 8-byte aligned parameter 'this' of 'StructAligned8' may 
> result in an unaligned pointer access}}

Personally, I like this style. I tend to be a heavy user of `-verify` prefixes 
though, so I might be biased.

> If this is changed to use `#if __cplusplus >= 201703L`, there will be 
> multiple lines with relative line numbers (e.g. `@-2` `@-4`)
>
>   register int ro; // expected-error {{illegal storage class on file-scoped 
> variable}}
>   #if __cplusplus >= 201703L
>   // expected-error@-2 {{ISO C++17 does not allow 'register' storage class 
> specifier}}
>   #elif __cplusplus >= 201103L
>   // expected-warning@-4 {{'register' storage class specifier is deprecated}}
>   #endif

FWIW, you don't have to use relative markers, but that uses an even less common 
idiom of bookmarks. e.g.,

  register int ro; // expected-error {{illegal storage class on file-scoped 
variable}} \
  #bookmark
  #if __cplusplus >= 201703L
  // expected-error@#bookmark {{ISO C++17 does not allow 'register' storage 
class specifier}}
  #elif __cplusplus >= 201103L
  // expected-warning@#bookmark {{'register' storage class specifier is 
deprecated}}
  #endif



> Personally I prefer multiple `%clang_cc1` over `#if`. The first few lines 
> give users a first impression. The dispatch makes it clear the test has 
> different behaviors with the `%stdcxx_*` described dialects.

I tend to have the same opinion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131464

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


[PATCH] D131926: [clang-tidy] Fix for bugprone-sizeof-expression PR57167

2022-08-16 Thread Chris Hamilton via Phabricator via cfe-commits
chrish_ericsson_atx added a comment.

Sounds fair.  I had taken your acceptance of the change as a green light.  :)  
TBH, the acceptance came much faster than I'd expected-- even though this is a 
trivial and low-risk change, I expected it to sit for at least several days.  
I'll plan to wait a few more days before landing it.


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

https://reviews.llvm.org/D131926

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


[PATCH] D131980: [Passes] Don't run tail-call-elim in -O1

2022-08-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

If you're specifically concerned about sibcall (call->jmp) optimization in the 
backend, it might be better to adjust the backend to avoid sibcalls at -O1, as 
opposed to messing with optimization passes.  (i.e. make 
-fno-optimize-sibling-calls the default at -O1.)  "tail" markings are useful 
for other purposes, like alias analysis, and I don't really want every 
optimization pass/frontend that might add "tail" markings to worry about the 
optimization level.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131980

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


[PATCH] D129855: [clang][PowerPC] Set lld as clang's default linker for PowerPC Linux

2022-08-16 Thread Quinn Pham via Phabricator via cfe-commits
quinnp added a comment.

Hi @MaskRay, could you please take a look at @nemanjai's suggestion?

> ...
> So I would prefer that we handle this in the CMake files if @MaskRay doesn't 
> object.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129855

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


[PATCH] D85599: [PowerPC] Remove isTerminator for TRAP instruction

2022-08-16 Thread Nemanja Ivanovic via Phabricator via cfe-commits
nemanjai added a comment.
Herald added a project: All.

I think we should handle this similarly to `SITargetLowering::splitKillBlock()`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D85599

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


[PATCH] D131979: [clang][UBSan] Fix __builtin_assume_aligned crash

2022-08-16 Thread Wang Yihan via Phabricator via cfe-commits
yihanaa added a comment.

Thanks for your suggestion @erichkeane @rjmccall , I will try to do that


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131979

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


  1   2   >