[PATCH] D158709: [Headers][Modules] Make separate headers for the stdarg.h and stddef.h pieces so that they can be modularized

2023-08-24 Thread Ian Anderson via Phabricator via cfe-commits
iana created this revision.
iana added reviewers: aaron.ballman, rsmith, efriedma, ldionne.
Herald added subscribers: Enna1, ributzka, mstorsjo, kadircet, arphaman.
Herald added a project: All.
iana requested review of this revision.
Herald added projects: clang, Sanitizers, LLVM, clang-tools-extra.
Herald added subscribers: cfe-commits, llvm-commits, Sanitizers.

stdarg.h and stddef.h have to be textual headers in their upcoming modules to 
support their `__needs_xxx` macros. That means that they won't get precompiled 
into their modules' pcm, and instead their declarations will go into every 
other pcm that uses them. For now that's ok since the type merger can handle 
the declarations in these headers, but it's suboptimal at best. Make separate 
headers for all of the pieces so that they can be properly modularized.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158709

Files:
  clang-tools-extra/clang-include-fixer/find-all-symbols/STLPostfixHeaderMap.cpp
  clang-tools-extra/clangd/index/CanonicalIncludes.cpp
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/__stdarg___gnuc_va_list.h
  clang/lib/Headers/__stdarg___va_copy.h
  clang/lib/Headers/__stdarg_va_arg.h
  clang/lib/Headers/__stdarg_va_copy.h
  clang/lib/Headers/__stdarg_va_list.h
  clang/lib/Headers/__stddef_null.h
  clang/lib/Headers/__stddef_nullptr_t.h
  clang/lib/Headers/__stddef_offsetof.h
  clang/lib/Headers/__stddef_ptrdiff_t.h
  clang/lib/Headers/__stddef_rsize_t.h
  clang/lib/Headers/__stddef_size_t.h
  clang/lib/Headers/__stddef_unreachable.h
  clang/lib/Headers/__stddef_wchar_t.h
  clang/lib/Headers/__stddef_wint_t.h
  clang/lib/Headers/stdarg.h
  clang/lib/Headers/stddef.h
  clang/test/Headers/stddef.c
  clang/test/Headers/stddefneeds.c
  compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
  llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn

Index: llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
+++ llvm/utils/gn/secondary/clang/lib/Headers/BUILD.gn
@@ -95,7 +95,21 @@
 "__clang_hip_math.h",
 "__clang_hip_runtime_wrapper.h",
 "__clang_hip_stdlib.h",
+"__stdarg___gnuc_va_list.h",
+"__stdarg___va_copy.h",
+"__stdarg_va_arg.h",
+"__stdarg_va_copy.h",
+"__stdarg_va_list.h",
 "__stddef_max_align_t.h",
+"__stddef_null.h",
+"__stddef_nullptr_t.h",
+"__stddef_offsetof.h",
+"__stddef_ptrdiff_t.h",
+"__stddef_rsize_t.h",
+"__stddef_size_t.h",
+"__stddef_unreachable.h",
+"__stddef_wchar_t.h",
+"__stddef_wint_t.h",
 "__wmmintrin_aes.h",
 "__wmmintrin_pclmul.h",
 "adxintrin.h",
Index: compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
===
--- compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
+++ compiler-rt/lib/gwp_asan/guarded_pool_allocator.h
@@ -20,6 +20,15 @@
 #include 
 #include 
 // IWYU pragma: no_include <__stddef_max_align_t.h>
+// IWYU pragma: no_include <__stddef_null.h>
+// IWYU pragma: no_include <__stddef_nullptr_t.h>
+// IWYU pragma: no_include <__stddef_offsetof.h>
+// IWYU pragma: no_include <__stddef_ptrdiff_t.h>
+// IWYU pragma: no_include <__stddef_rsize_t.h>
+// IWYU pragma: no_include <__stddef_size_t.h>
+// IWYU pragma: no_include <__stddef_unreachable.h>
+// IWYU pragma: no_include <__stddef_wchar_t.h>
+// IWYU pragma: no_include <__stddef_wint_t.h>
 
 namespace gwp_asan {
 // This class is the primary implementation of the allocator portion of GWP-
Index: clang/test/Headers/stddefneeds.c
===
--- clang/test/Headers/stddefneeds.c
+++ clang/test/Headers/stddefneeds.c
@@ -38,7 +38,7 @@
 ptrdiff_t p2;
 size_t s2;
 rsize_t r2; // c99-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'size_t' declared here}}
+// c99-note@__stddef_size_t.h:*{{'size_t' declared here}} c23-note@__stddef_size_t.h:*{{'size_t' declared here}}
 wchar_t wc2; // c99-error{{unknown type}} c23-error{{unknown type}}
 void *v2 = NULL; // c99-error{{undeclared identifier}} c23-error{{undeclared identifier}}
 nullptr_t n2; // c99-error{{unknown type}} c23-error{{unknown type}}
@@ -96,7 +96,7 @@
 // __need_nullptr_t generates an error in  // c99-error@stddef.h:*{{expected function body}}
+#include  // c99-error@__stddef_nullptr_t.h:*{{expected function body}}
 
 ptrdiff_t p6;
 size_t s6;
Index: clang/test/Headers/stddef.c
===
--- clang/test/Headers/stddef.c
+++ clang/test/Headers/stddef.c
@@ -22,7 +22,7 @@
 ptrdiff_t p1;
 size_t s1;
 rsize_t r1; // c99-error{{unknown type}} c11-error{{unknown type}} c23-error{{unknown type}}
-// c99-note@stddef.h:*{{'size_t' declared here}} c11-note@stddef.h:*{{'size_t' declared here}} c23-note@stddef.h:*{{'

[PATCH] D158601: [Clang] Always constant-evaluate operands of comparisons to nullptr

2023-08-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

@ChuanqiXu Thanks. Do you think this needs to be backported for coroutine 
support?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158601

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


[clang] 4866a6e - [clang][dataflow] Produce pointer values for callees of member operator calls.

2023-08-24 Thread Martin Braenne via cfe-commits

Author: Martin Braenne
Date: 2023-08-24T07:12:14Z
New Revision: 4866a6e1d3327a0499ef0e017a973a78d4e377bc

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

LOG: [clang][dataflow] Produce pointer values for callees of member operator 
calls.

Calls to member operators are a special case in that their callees have pointer
type. The callees of non-operator non-static member functions are not pointers.
See the comments in the code for details.

This issue came up in the Crubit nullability check; the fact that we weren't
modeling the `PointerValue` caused non-convergence.

Reviewed By: ymandel, xazax.hun

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

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 8617cf4c8ca4a2..200a981584bb76 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -175,12 +175,16 @@ class TransferVisitor : public 
ConstStmtVisitor {
 const ValueDecl *VD = S->getDecl();
 assert(VD != nullptr);
 
-// `DeclRefExpr`s to fields and non-static methods aren't glvalues, and
-// there's also no sensible `Value` we can assign to them, so skip them.
-if (isa(VD))
-  return;
-if (auto *Method = dyn_cast(VD);
-Method && !Method->isStatic())
+// Some `DeclRefExpr`s aren't glvalues, so we can't associate them with a
+// `StorageLocation`, and there's also no sensible `Value` that we can
+// assign to them. Examples:
+// - Non-static member variables
+// - Non static member functions
+//   Note: Member operators are an exception to this, but apparently only
+//   if the `DeclRefExpr` is used within the callee of a
+//   `CXXOperatorCallExpr`. In other cases, for example when applying the
+//   address-of operator, the `DeclRefExpr` is a prvalue.
+if (!S->isGLValue())
   return;
 
 auto *DeclLoc = Env.getStorageLocation(*VD);

diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 4c31de3c8085bd..ef28f2f233b844 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5588,6 +5588,59 @@ TEST(TransferTest, BuiltinFunctionModeled) {
   });
 }
 
+// Check that a callee of a member operator call is modeled as a 
`PointerValue`.
+// Member operator calls are unusual in that their callee is a pointer that
+// stems from a `FunctionToPointerDecay`. In calls to non-operator non-static
+// member functions, the callee is a `MemberExpr` (which does not have pointer
+// type).
+// We want to make sure that we produce a pointer value for the callee in this
+// specific scenario and that its storage location is durable (for 
convergence).
+TEST(TransferTest, MemberOperatorCallModelsPointerForCallee) {
+  std::string Code = R"(
+struct S {
+  bool operator!=(S s);
+};
+void target() {
+  S s;
+  (void)(s != s);
+  (void)(s != s);
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+using ast_matchers::selectFirst;
+using ast_matchers::match;
+using ast_matchers::traverse;
+using ast_matchers::cxxOperatorCallExpr;
+
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+auto Matches = match(
+traverse(TK_AsIs, cxxOperatorCallExpr().bind("call")), ASTCtx);
+
+ASSERT_EQ(Matches.size(), 2);
+
+auto *Call1 = Matches[0].getNodeAs("call");
+auto *Call2 = Matches[1].getNodeAs("call");
+
+ASSERT_THAT(Call1, NotNull());
+ASSERT_THAT(Call2, NotNull());
+
+EXPECT_EQ(cast(Call1->getCallee())->getCastKind(),
+  CK_FunctionToPointerDecay);
+EXPECT_EQ(cast(Call2->getCallee())->getCastKind(),
+  CK_FunctionToPointerDecay);
+
+auto *Ptr1 = cast(Env.getValue(*Call1->getCallee()));
+auto *Ptr2 = cast(Env.getValue(*Call2->getCallee()));
+
+ASSERT_EQ(&Ptr1->getPointeeLoc(), &Ptr2->getPointeeLoc());
+  });
+}
+
 // Check that fields of anonymous records are modeled.
 TEST(TransferTest, AnonymousStruct) {
   std::string Code = R"(



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


[PATCH] D158592: [clang][dataflow] Produce pointer values for callees of member operator calls.

2023-08-24 Thread Martin Böhme 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 rG4866a6e1d332: [clang][dataflow] Produce pointer values for 
callees of member operator calls. (authored by mboehme).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158592

Files:
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5588,6 +5588,59 @@
   });
 }
 
+// Check that a callee of a member operator call is modeled as a 
`PointerValue`.
+// Member operator calls are unusual in that their callee is a pointer that
+// stems from a `FunctionToPointerDecay`. In calls to non-operator non-static
+// member functions, the callee is a `MemberExpr` (which does not have pointer
+// type).
+// We want to make sure that we produce a pointer value for the callee in this
+// specific scenario and that its storage location is durable (for 
convergence).
+TEST(TransferTest, MemberOperatorCallModelsPointerForCallee) {
+  std::string Code = R"(
+struct S {
+  bool operator!=(S s);
+};
+void target() {
+  S s;
+  (void)(s != s);
+  (void)(s != s);
+  // [[p]]
+}
+  )";
+  runDataflow(
+  Code,
+  [](const llvm::StringMap> &Results,
+ ASTContext &ASTCtx) {
+using ast_matchers::selectFirst;
+using ast_matchers::match;
+using ast_matchers::traverse;
+using ast_matchers::cxxOperatorCallExpr;
+
+const Environment &Env = getEnvironmentAtAnnotation(Results, "p");
+
+auto Matches = match(
+traverse(TK_AsIs, cxxOperatorCallExpr().bind("call")), ASTCtx);
+
+ASSERT_EQ(Matches.size(), 2);
+
+auto *Call1 = Matches[0].getNodeAs("call");
+auto *Call2 = Matches[1].getNodeAs("call");
+
+ASSERT_THAT(Call1, NotNull());
+ASSERT_THAT(Call2, NotNull());
+
+EXPECT_EQ(cast(Call1->getCallee())->getCastKind(),
+  CK_FunctionToPointerDecay);
+EXPECT_EQ(cast(Call2->getCallee())->getCastKind(),
+  CK_FunctionToPointerDecay);
+
+auto *Ptr1 = cast(Env.getValue(*Call1->getCallee()));
+auto *Ptr2 = cast(Env.getValue(*Call2->getCallee()));
+
+ASSERT_EQ(&Ptr1->getPointeeLoc(), &Ptr2->getPointeeLoc());
+  });
+}
+
 // Check that fields of anonymous records are modeled.
 TEST(TransferTest, AnonymousStruct) {
   std::string Code = R"(
Index: clang/lib/Analysis/FlowSensitive/Transfer.cpp
===
--- clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -175,12 +175,16 @@
 const ValueDecl *VD = S->getDecl();
 assert(VD != nullptr);
 
-// `DeclRefExpr`s to fields and non-static methods aren't glvalues, and
-// there's also no sensible `Value` we can assign to them, so skip them.
-if (isa(VD))
-  return;
-if (auto *Method = dyn_cast(VD);
-Method && !Method->isStatic())
+// Some `DeclRefExpr`s aren't glvalues, so we can't associate them with a
+// `StorageLocation`, and there's also no sensible `Value` that we can
+// assign to them. Examples:
+// - Non-static member variables
+// - Non static member functions
+//   Note: Member operators are an exception to this, but apparently only
+//   if the `DeclRefExpr` is used within the callee of a
+//   `CXXOperatorCallExpr`. In other cases, for example when applying the
+//   address-of operator, the `DeclRefExpr` is a prvalue.
+if (!S->isGLValue())
   return;
 
 auto *DeclLoc = Env.getStorageLocation(*VD);


Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5588,6 +5588,59 @@
   });
 }
 
+// Check that a callee of a member operator call is modeled as a `PointerValue`.
+// Member operator calls are unusual in that their callee is a pointer that
+// stems from a `FunctionToPointerDecay`. In calls to non-operator non-static
+// member functions, the callee is a `MemberExpr` (which does not have pointer
+// type).
+// We want to make sure that we produce a pointer value for the callee in this
+// specific scenario and that its storage location is durable (for convergence).
+TEST(TransferTest, MemberOperatorCallModelsPointerForCallee) {
+  std::string Code = R"(
+struct S {
+  bool operator!=(S s);
+};
+void target() {
+  S s;
+  (void)(s != s)

[PATCH] D158363: [clang-format] Fix segmentation fault when formatting nested namespaces

2023-08-24 Thread Arkadiy Yudintsev via Phabricator via cfe-commits
d0nc1h0t updated this revision to Diff 553017.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158363

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4223,6 +4223,16 @@
"void foo() {}\n"
"} // namespace ns\n",
Style);
+
+  FormatStyle LLVMWithCompactInnerNamespace = getLLVMStyle();
+  LLVMWithCompactInnerNamespace.CompactNamespaces = true;
+  LLVMWithCompactInnerNamespace.NamespaceIndentation = FormatStyle::NI_Inner;
+  verifyFormat("namespace ns1 { namespace ns2 { namespace ns3 {\n"
+"// block for debug mode\n"
+"#ifndef NDEBUG\n"
+"#endif\n"
+"}}} // namespace ns1::ns2::ns3",
+   LLVMWithCompactInnerNamespace);
 }
 
 TEST_F(FormatTest, NamespaceMacros) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -386,11 +386,14 @@
   // Reduce indent level for bodies of namespaces which were compacted,
   // but only if their content was indented in the first place.
   auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
-  auto OutdentBy = I[J]->Level - TheLine->Level;
+  int OutdentBy = I[J]->Level - TheLine->Level;
+  assert(OutdentBy >= 0);
   for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
++CompactedLine) {
-if (!(*CompactedLine)->InPPDirective)
-  (*CompactedLine)->Level -= OutdentBy;
+if (!(*CompactedLine)->InPPDirective) {
+  const int Level = (*CompactedLine)->Level;
+  (*CompactedLine)->Level = std::max(Level - OutdentBy, 0);
+}
   }
 }
 return J - 1;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4223,6 +4223,16 @@
"void foo() {}\n"
"} // namespace ns\n",
Style);
+
+  FormatStyle LLVMWithCompactInnerNamespace = getLLVMStyle();
+  LLVMWithCompactInnerNamespace.CompactNamespaces = true;
+  LLVMWithCompactInnerNamespace.NamespaceIndentation = FormatStyle::NI_Inner;
+  verifyFormat("namespace ns1 { namespace ns2 { namespace ns3 {\n"
+"// block for debug mode\n"
+"#ifndef NDEBUG\n"
+"#endif\n"
+"}}} // namespace ns1::ns2::ns3",
+   LLVMWithCompactInnerNamespace);
 }
 
 TEST_F(FormatTest, NamespaceMacros) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -386,11 +386,14 @@
   // Reduce indent level for bodies of namespaces which were compacted,
   // but only if their content was indented in the first place.
   auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
-  auto OutdentBy = I[J]->Level - TheLine->Level;
+  int OutdentBy = I[J]->Level - TheLine->Level;
+  assert(OutdentBy >= 0);
   for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
++CompactedLine) {
-if (!(*CompactedLine)->InPPDirective)
-  (*CompactedLine)->Level -= OutdentBy;
+if (!(*CompactedLine)->InPPDirective) {
+  const int Level = (*CompactedLine)->Level;
+  (*CompactedLine)->Level = std::max(Level - OutdentBy, 0);
+}
   }
 }
 return J - 1;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158630: [clang][dataflow][WIP] Prototype for pointer value widening ("unknown storage location" flavor)

2023-08-24 Thread Martin Böhme via Phabricator via cfe-commits
mboehme updated this revision to Diff 553021.
mboehme added a comment.

Added comment on self-referential data structurs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158630

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

Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -3843,10 +3843,7 @@
   }
 }
   )cc";
-  // FIXME: Implement pointer value widening to make analysis converge.
-  ASSERT_THAT_ERROR(
-  checkDataflowWithNoopAnalysis(Code),
-  llvm::FailedWithMessage("maximum number of iterations reached"));
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
 TEST(TransferTest, LoopDereferencingChangingRecordPointerConverges) {
@@ -3868,10 +3865,7 @@
   }
 }
   )cc";
-  // FIXME: Implement pointer value widening to make analysis converge.
-  ASSERT_THAT_ERROR(
-  checkDataflowWithNoopAnalysis(Code),
-  llvm::FailedWithMessage("maximum number of iterations reached"));
+  ASSERT_THAT_ERROR(checkDataflowWithNoopAnalysis(Code), llvm::Succeeded());
 }
 
 TEST(TransferTest, DoesNotCrashOnUnionThisExpr) {
Index: clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -161,6 +161,16 @@
 return CurrentEnv.makeTopBoolValue();
   }
 
+  if (auto *PrevPtr = dyn_cast(&Prev)) {
+auto &CurPtr = cast(Current);
+
+if (&PrevPtr->getPointeeLoc() != &CurPtr.getPointeeLoc())
+  // TODO: Widen properties
+  return CurrentEnv.create(
+  CurrentEnv.getDataflowAnalysisContext().getUnknownStorageLocation(
+  CurPtr.getPointeeLoc().getType()));
+  }
+
   // FIXME: Add other built-in model widening.
 
   // Custom-model widening.
@@ -658,6 +668,20 @@
 void Environment::setValue(const StorageLocation &Loc, Value &Val) {
   assert(!isa(&Val) || &cast(&Val)->getLoc() == &Loc);
 
+  // TODO: Currently, if `Loc` is an unknown storage location, just bail out.
+  // But is this the right thing to do?
+  // Alternatives:
+  // - Assert that `Loc` is not an unknown storage location. But then that
+  //   potentially puts the burden of testing on the caller. And what else would
+  //   they do except not set the value?
+  // - Because the unknown storage location is conceptually a "top", it
+  //   effectively refers to the set of _all_ possible storage locations. So,
+  //   because we could be potentially setting the value of any storage,
+  //   maybe we should blow away _all_ of the entries in `LocToVal`? Or at least
+  //   those whose type is one that is compatible with `Loc` in the sense that
+  //   it can refer to a value of type `Loc.getType()`?
+  if (getDataflowAnalysisContext().isUnknownStorageLocation(Loc))
+return;
   LocToVal[&Loc] = &Val;
 }
 
@@ -686,6 +710,8 @@
 }
 
 Value *Environment::getValue(const StorageLocation &Loc) const {
+  if (getDataflowAnalysisContext().isUnknownStorageLocation(Loc))
+return nullptr;
   return LocToVal.lookup(&Loc);
 }
 
Index: clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
===
--- clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -90,6 +90,35 @@
   return Loc;
 }
 
+StorageLocation &
+DataflowAnalysisContext::getUnknownStorageLocation(QualType Ty) {
+  // FIXME: Deal with self-referential data structures correctly.
+  // e.g. `struct S { S& s; };` will currently cause an infinite loop in this
+  // function, I think.
+  auto Res = UnknownStorageLocations.try_emplace(Ty, nullptr);
+  if (Res.second) {
+if (!Ty.isNull() && Ty->isRecordType()) {
+  llvm::DenseMap FieldLocs;
+  for (const FieldDecl *Field : getModeledFields(Ty))
+FieldLocs.insert({Field, &getUnknownStorageLocation(
+ Field->getType().getNonReferenceType())});
+  Res.first->second =
+  &arena().create(Ty, std::move(FieldLocs));
+} else {
+  Res.first->second = &arena().create(Ty);
+}
+  }
+  return *Res.first->second;
+}
+
+bool DataflowAnalysisContext::isUnknownStorageLocation(
+const StorageLocation &Loc) const {
+  auto Iter = UnknownStorageLocations.find(Loc.getType());
+  if (Iter == UnknownStorageLocations.end())
+return false;
+  return Iter->second == &Loc;
+}
+
 PointerValue &
 DataflowAna

[PATCH] D158601: [Clang] Always constant-evaluate operands of comparisons to nullptr

2023-08-24 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu added a comment.

In D158601#4612908 , @cor3ntin wrote:

> @ChuanqiXu Thanks. Do you think this needs to be backported for coroutine 
> support?

For coroutine support, I don't think it is needed. It is a pretty corner case 
and Tobias had mentioned there are too many back ports now 
(https://discourse.llvm.org/t/llvm-17-0-0-rc3-released/72946). Although he 
doesn't throw any requirement to us, I think it may better to lift our bar for 
backporting patches now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158601

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


[PATCH] D157810: [clang][ExtractAPI] Create extractapi::RecordLocation

2023-08-24 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

LGTM




Comment at: clang/include/clang/ExtractAPI/API.h:137
 
-/// DocComment is a vector of RawComment::CommentLine.
+/// Slightly cut down version of PresumedLoc to suite the needs of
+/// ExtractAPI.

s/suite/suit


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

https://reviews.llvm.org/D157810

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


[PATCH] D158706: [Driver] Remove Myriad.cpp

2023-08-24 Thread Brad Smith via Phabricator via cfe-commits
brad added inline comments.



Comment at: clang/lib/Driver/ToolChains/Gnu.cpp:2958
   default:
 return getTriple().getVendor() != llvm::Triple::Myriad;
   }

You might as well remove this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158706

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


[PATCH] D158616: To allow RAV to visit initializer when bitfield and initializer both given

2023-08-24 Thread Nouman Amir via Phabricator via cfe-commits
NoumanAmir657 added a comment.

The pre-commit checks passed now when I built again. Looking into test for this 
now


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158616

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


[PATCH] D158671: [NFC][Clang] Fix static analyzer concerns

2023-08-24 Thread Daniel Grumberg via Phabricator via cfe-commits
dang accepted this revision.
dang added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h:195
 SymbolReference Context;
-auto Record = dyn_cast(Decl->getDeclContext());
+auto Record = cast(Decl->getDeclContext());
 Context.Name = Record->getName();

NIT: It's not immediately obvious that the check `if 
(Decl->isStaticDataMember())` guarantees that `Decl->getDeclContext()` is a 
`RecordDecl`. Would you mind adding a comment static that?


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

https://reviews.llvm.org/D158671

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


[clang] 09ccc55 - Fix [-Werror,-Wsign-compare] error. NFC.

2023-08-24 Thread Kai Luo via cfe-commits

Author: Kai Luo
Date: 2023-08-24T07:56:43Z
New Revision: 09ccc5563ebe70be2b5a5421df43cd5720ba1f5b

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

LOG: Fix [-Werror,-Wsign-compare] error. NFC.

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index ef28f2f233b844..8100db2aec4090 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -5621,7 +5621,7 @@ TEST(TransferTest, 
MemberOperatorCallModelsPointerForCallee) {
 auto Matches = match(
 traverse(TK_AsIs, cxxOperatorCallExpr().bind("call")), ASTCtx);
 
-ASSERT_EQ(Matches.size(), 2);
+ASSERT_EQ(Matches.size(), 2UL);
 
 auto *Call1 = Matches[0].getNodeAs("call");
 auto *Call2 = Matches[1].getNodeAs("call");



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


[PATCH] D158715: [Driver] Cleanup last vestiges of Minix / Contiki support

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

Cleanup what is left after https://reviews.llvm.org/D158461


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158715

Files:
  clang/docs/tools/clang-formatted-files.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Lex/InitHeaderSearch.cpp
  clang/test/Preprocessor/predefined-macros-no-warnings.c


Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- clang/test/Preprocessor/predefined-macros-no-warnings.c
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -145,7 +145,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-freebsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-fuchsia
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-kfreebsd
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-minix
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-solaris
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-win32-cygnus
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-win32-gnu
Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -332,10 +332,6 @@
   case llvm::Triple::DragonFly:
 AddPath("/usr/include/c++/5.0", CXXSystem, false);
 break;
-  case llvm::Triple::Minix:
-AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
-"", "", "", triple);
-break;
   default:
 break;
   }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -554,8 +554,7 @@
   }
 
   // Skip further flag support on OSes which don't support '-m32' or '-m64'.
-  if (Target.getArch() == llvm::Triple::tce ||
-  Target.getOS() == llvm::Triple::Minix)
+  if (Target.getArch() == llvm::Triple::tce)
 return Target;
 
   // On AIX, the env OBJECT_MODE may affect the resulting arch variant.
Index: clang/docs/tools/clang-formatted-files.txt
===
--- clang/docs/tools/clang-formatted-files.txt
+++ clang/docs/tools/clang-formatted-files.txt
@@ -402,7 +402,6 @@
 clang/lib/Driver/ToolChains/AVR.h
 clang/lib/Driver/ToolChains/CloudABI.cpp
 clang/lib/Driver/ToolChains/CommonArgs.h
-clang/lib/Driver/ToolChains/Contiki.cpp
 clang/lib/Driver/ToolChains/CrossWindows.h
 clang/lib/Driver/ToolChains/DragonFly.h
 clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -416,7 +415,6 @@
 clang/lib/Driver/ToolChains/Hurd.h
 clang/lib/Driver/ToolChains/InterfaceStubs.cpp
 clang/lib/Driver/ToolChains/InterfaceStubs.h
-clang/lib/Driver/ToolChains/Minix.h
 clang/lib/Driver/ToolChains/MipsLinux.cpp
 clang/lib/Driver/ToolChains/MSP430.h
 clang/lib/Driver/ToolChains/PPCFreeBSD.cpp


Index: clang/test/Preprocessor/predefined-macros-no-warnings.c
===
--- clang/test/Preprocessor/predefined-macros-no-warnings.c
+++ clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -145,7 +145,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-freebsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-fuchsia
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-kfreebsd
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-minix
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-solaris
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-win32-cygnus
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple i686-win32-gnu
Index: clang/lib/Lex/InitHeaderSearch.cpp
===
--- clang/lib/Lex/InitHeaderSearch.cpp
+++ clang/lib/Lex/InitHeaderSearch.cpp
@@ -332,10 +332,6 @@
   case llvm::Triple::DragonFly:
 AddPath("/usr/include/c++/5.0", CXXSystem, false);
 break;
-  case llvm::Triple::Minix:
-AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
-"", "", "", triple);
-break;
   default:
 break;
   }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -554,8 +554,7 @@
   }
 
   // Skip further flag support on OSes which don't support '-m32' or '-m64'.
-  if (Target.getArch() == llvm::Triple::tce ||
-  Target.getOS() == llvm::Triple::Minix)
+  if (Target.getArch() == llvm::Triple::tce)
 return Target;
 
   // On AIX, the env OBJECT_MODE may affect the resulting arch variant.
Index: clang/docs/tools/clang-formatted-files.txt
==

[PATCH] D158363: [clang-format] Fix segmentation fault when formatting nested namespaces

2023-08-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan accepted this revision.
owenpan added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:389
   auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
-  auto OutdentBy = I[J]->Level - TheLine->Level;
+  int OutdentBy = I[J]->Level - TheLine->Level;
+  assert(OutdentBy >= 0);

I forgot to suggest `const`.



Comment at: clang/unittests/Format/FormatTest.cpp:4231-4234
+"// block for debug mode\n"
+"#ifndef NDEBUG\n"
+"#endif\n"
+"}}} // namespace ns1::ns2::ns3",

Did you run `git-clang-format`?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158363

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


[PATCH] D158671: [NFC][Clang] Fix static analyzer concerns

2023-08-24 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:610-612
   if (isa(Method)) {
 Name = Method->getNameAsString();
+if (cast(Method)->isExplicit())

Maybe we can just do this, so we don't `isa` two times.



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

https://reviews.llvm.org/D158671

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


[clang] 547bce3 - Revert "[clang-format] Break long string literals in C#, etc."

2023-08-24 Thread David Spickett via cfe-commits

Author: David Spickett
Date: 2023-08-24T08:15:17Z
New Revision: 547bce36132ae0d92226599b6b8702051571461f

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

LOG: Revert "[clang-format] Break long string literals in C#, etc."

This reverts commit 16ccba51072bbc5ff4c66f91f939163dc91e5d96.

This is failing across Linaro's bots e.g.:
https://lab.llvm.org/buildbot/#/builders/188/builds/34393

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/BreakableToken.cpp
clang/lib/Format/BreakableToken.h
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTestCSharp.cpp
clang/unittests/Format/FormatTestJS.cpp
clang/unittests/Format/FormatTestJava.cpp
clang/unittests/Format/FormatTestVerilog.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 871d7c63cdace9..3b3f6f2860906a 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -2722,8 +2722,6 @@ the configuration (without a prefix: ``Auto``).
 **BreakStringLiterals** (``Boolean``) :versionbadge:`clang-format 3.9` :ref:`¶ 
`
   Allow breaking string literals when formatting.
 
-  In C, C++, and Objective-C:
-
   .. code-block:: c++
 
  true:
@@ -2733,34 +2731,7 @@ the configuration (without a prefix: ``Auto``).
 
  false:
  const char* x =
- "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
-
-  In C#, Java, and JavaScript:
-
-  .. code-block:: c++
-
- true:
- var x = "veryVeryVeryVeryVeryVe" +
- "ryVeryVeryVeryVeryVery" +
- "VeryLongString";
-
- false:
- var x =
- "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
-  C# and JavaScript interpolated strings are not broken.
-
-  In Verilog:
-
-  .. code-block:: c++
-
- true:
- string x = {"veryVeryVeryVeryVeryVe",
- "ryVeryVeryVeryVeryVery",
- "VeryLongString"};
-
- false:
- string x =
- "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
+   "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
 
 .. _ColumnLimit:
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index b7b25657927aa6..192cc68e51fad7 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -2008,8 +2008,6 @@ struct FormatStyle {
   bool BreakAfterJavaFieldAnnotations;
 
   /// Allow breaking string literals when formatting.
-  ///
-  /// In C, C++, and Objective-C:
   /// \code
   ///true:
   ///const char* x = "veryVeryVeryVeryVeryVe"
@@ -2018,34 +2016,8 @@ struct FormatStyle {
   ///
   ///false:
   ///const char* x =
-  ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
-  /// \endcode
-  ///
-  /// In C#, Java, and JavaScript:
-  /// \code
-  ///true:
-  ///var x = "veryVeryVeryVeryVeryVe" +
-  ///"ryVeryVeryVeryVeryVery" +
-  ///"VeryLongString";
-  ///
-  ///false:
-  ///var x =
-  ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
+  ///  "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
   /// \endcode
-  /// C# and JavaScript interpolated strings are not broken.
-  ///
-  /// In Verilog:
-  /// \code
-  ///true:
-  ///string x = {"veryVeryVeryVeryVeryVe",
-  ///"ryVeryVeryVeryVeryVery",
-  ///"VeryLongString"};
-  ///
-  ///false:
-  ///string x =
-  ///"veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
-  /// \endcode
-  ///
   /// \version 3.9
   bool BreakStringLiterals;
 

diff  --git a/clang/lib/Format/BreakableToken.cpp 
b/clang/lib/Format/BreakableToken.cpp
index 4264ea188c2159..af1e0748fafa97 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -292,120 +292,6 @@ void BreakableStringLiteral::insertBreak(unsigned 
LineIndex,
   Prefix, InPPDirective, 1, StartColumn);
 }
 
-BreakableStringLiteralUsingOperators::BreakableStringLiteralUsingOperators(
-const FormatToken &Tok, QuoteStyleType QuoteStyle, bool UnindentPlus,
-unsigned StartColumn, unsigned UnbreakableTailLength, bool InPPDirective,
-encoding::Encoding Encoding, const FormatStyle &Style)
-: BreakableStringLiteral(
-  Tok, StartColumn, /*Prefix=*/QuoteStyle == SingleQuotes ? "'"
-: QuoteStyle == AtDoubleQuotes? "@\""
- 

[PATCH] D154093: [clang-format] Break long string literals in C#, etc.

2023-08-24 Thread David Spickett via Phabricator via cfe-commits
DavidSpickett added a comment.

This was causing failures on a large number of Linaro's bots. Judging by how 
widespread it was, reproducing could be as simple as adding 
`-DLLVM_ENABLE_ASSERTIONS=True` to your CMake config.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154093

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


[PATCH] D158571: [clang-format][NFC] Replace !is() with isNot()

2023-08-24 Thread Owen Pan via Phabricator via cfe-commits
owenpan updated this revision to Diff 553032.
owenpan added a comment.

Rebased to 825cec2 
 and ran 
`git-clang-format`.


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

https://reviews.llvm.org/D158571

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/DefinitionBlockSeparator.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenSource.h
  clang/lib/Format/MacroExpander.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/SortJavaScriptImports.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/WhitespaceManager.cpp

Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -590,14 +590,14 @@
 
   // A new line starts, re-initialize line status tracking bools.
   // Keep the match state if a string literal is continued on this line.
-  if (i == 0 || !Changes[i].Tok->is(tok::string_literal) ||
-  !Changes[i - 1].Tok->is(tok::string_literal)) {
+  if (i == 0 || Changes[i].Tok->isNot(tok::string_literal) ||
+  Changes[i - 1].Tok->isNot(tok::string_literal)) {
 FoundMatchOnLine = false;
   }
   LineIsComment = true;
 }
 
-if (!Changes[i].Tok->is(tok::comment))
+if (Changes[i].Tok->isNot(tok::comment))
   LineIsComment = false;
 
 if (Changes[i].Tok->is(tok::comma)) {
@@ -731,10 +731,10 @@
   SpacesRequiredBefore = 0;
 }
 
-if (!Current || !Current->is(tok::identifier))
+if (!Current || Current->isNot(tok::identifier))
   return false;
 
-if (!Current->Previous || !Current->Previous->is(tok::pp_define))
+if (!Current->Previous || Current->Previous->isNot(tok::pp_define))
   return false;
 
 // For a macro function, 0 spaces are required between the
@@ -781,7 +781,7 @@
   LineIsComment = true;
 }
 
-if (!Changes[I].Tok->is(tok::comment))
+if (Changes[I].Tok->isNot(tok::comment))
   LineIsComment = false;
 
 if (!AlignMacrosMatches(Changes[I]))
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -394,7 +394,7 @@
 ParseDefault();
 continue;
   }
-  if (CanContainBracedList && !FormatTok->is(TT_MacroBlockBegin) &&
+  if (CanContainBracedList && FormatTok->isNot(TT_MacroBlockBegin) &&
   tryToParseBracedList()) {
 continue;
   }
@@ -615,7 +615,7 @@
   LBraceStack.pop_back();
   break;
 case tok::identifier:
-  if (!Tok->is(TT_StatementMacro))
+  if (Tok->isNot(TT_StatementMacro))
 break;
   [[fallthrough]];
 case tok::at:
@@ -799,8 +799,8 @@
   if (eof())
 return IfLBrace;
 
-  if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd)
- : !FormatTok->is(tok::r_brace)) {
+  if (MacroBlock ? FormatTok->isNot(TT_MacroBlockEnd)
+ : FormatTok->isNot(tok::r_brace)) {
 Line->Level = InitialLevel;
 FormatTok->setBlockKind(BK_Block);
 return IfLBrace;
@@ -1080,7 +1080,7 @@
   bool MaybeIncludeGuard = IfNDef;
   if (IncludeGuard == IG_Inited && MaybeIncludeGuard) {
 for (auto &Line : Lines) {
-  if (!Line.Tokens.front().Tok->is(tok::comment)) {
+  if (Line.Tokens.front().Tok->isNot(tok::comment)) {
 MaybeIncludeGuard = false;
 IncludeGuard = IG_Rejected;
 break;
@@ -1612,7 +1612,7 @@
 nextToken();
 if (FormatTok->is(tok::kw_public))
   nextToken();
-if (!FormatTok->is(tok::string_literal))
+if (FormatTok->isNot(tok::string_literal))
   return;
 nextToken();
 if (FormatTok->is(tok::semi))
@@ -1887,8 +1887,9 @@
   // a new unwrapped line, so they are special cased below.
   size_t TokenCount = Line->Tokens.size();
   if (Style.isJavaScript() && FormatTok->is(Keywords.kw_function) &&
-  (TokenCount > 1 || (TokenCount == 1 && !Line->Tokens.front().Tok->is(
- Keywords.kw_async {
+  (TokenCount > 1 ||
+   (TokenCount == 1 &&
+Line->Tokens.front().Tok->isNot(Keywords.kw_async {
 tryToParseJSFunction();
 break;
   }
@@ -2872,7 +2873,7 @@
   FormatTok->is(tok::l_brace)) {
 do {
   nextToken();
-} while (!FormatTok->is(tok::r_brace));
+} while (FormatTok->isNot(tok::r_brace));
 nextToken();
   }
 
@@ -2895,7 +2896,7 @@
   addUnwrappedLine();
 else
   NeedsUnwrappedLine = true;
-  } else if (!FormatTok-

[clang] 91c4db0 - [clang-format][NFC] Replace !is() with isNot()

2023-08-24 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-08-24T01:27:24-07:00
New Revision: 91c4db00612b205c6d0f56990b657c5646ad2a3b

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

LOG: [clang-format][NFC] Replace !is() with isNot()

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

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/DefinitionBlockSeparator.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Format/FormatTokenSource.h
clang/lib/Format/MacroExpander.cpp
clang/lib/Format/QualifierAlignmentFixer.cpp
clang/lib/Format/SortJavaScriptImports.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/WhitespaceManager.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index b23eb549650a7e..386235de1f8f04 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -430,11 +430,11 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
 return true;
   }
 
-  if (Current.is(TT_ObjCMethodExpr) && !Previous.is(TT_SelectorName) &&
+  if (Current.is(TT_ObjCMethodExpr) && Previous.isNot(TT_SelectorName) &&
   State.Line->startsWith(TT_ObjCMethodSpecifier)) {
 return true;
   }
-  if (Current.is(TT_SelectorName) && !Previous.is(tok::at) &&
+  if (Current.is(TT_SelectorName) && Previous.isNot(tok::at) &&
   CurrentState.ObjCSelectorNameFound && CurrentState.BreakBeforeParameter 
&&
   (Style.ObjCBreakBeforeNestedBlockParam ||
!Current.startsSequence(TT_SelectorName, tok::colon, tok::caret))) {
@@ -469,7 +469,7 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
 return true;
   }
 
-  if (!State.Line->First->is(tok::kw_enum) && State.Column <= NewLineColumn)
+  if (State.Line->First->isNot(tok::kw_enum) && State.Column <= NewLineColumn)
 return false;
 
   if (Style.AlwaysBreakBeforeMultilineStrings &&
@@ -578,8 +578,8 @@ bool ContinuationIndenter::mustBreak(const LineState 
&State) {
 // Don't always break between a JavaScript `function` and the function
 // name.
 !Style.isJavaScript()) ||
-   (Current.is(tok::kw_operator) && !Previous.is(tok::coloncolon))) &&
-  !Previous.is(tok::kw_template) && CurrentState.BreakBeforeParameter) {
+   (Current.is(tok::kw_operator) && Previous.isNot(tok::coloncolon))) &&
+  Previous.isNot(tok::kw_template) && CurrentState.BreakBeforeParameter) {
 return true;
   }
 
@@ -815,7 +815,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   // Exclude relational operators, as there, it is always more desirable to
   // have the LHS 'left' of the RHS.
   const FormatToken *P = Current.getPreviousNonComment();
-  if (!Current.is(tok::comment) && P &&
+  if (Current.isNot(tok::comment) && P &&
   (P->isOneOf(TT_BinaryOperator, tok::comma) ||
(P->is(TT_ConditionalExpr) && P->is(tok::colon))) &&
   !P->isOneOf(TT_OverloadedOperator, TT_CtorInitializerComma) &&
@@ -830,8 +830,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 // Don't do this if there are only two operands. In these cases, there is
 // always a nice vertical separation between them and the extra line break
 // does not help.
-bool HasTwoOperands =
-P->OperatorIndex == 0 && !P->NextOperator && 
!P->is(TT_ConditionalExpr);
+bool HasTwoOperands = P->OperatorIndex == 0 && !P->NextOperator &&
+  P->isNot(TT_ConditionalExpr);
 if ((!BreakBeforeOperator &&
  !(HasTwoOperands &&
Style.AlignOperands != FormatStyle::OAS_DontAlign)) ||
@@ -850,7 +850,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
 CurrentState.NestedBlockIndent = State.Column;
   } else if (!Current.isOneOf(tok::comment, tok::caret) &&
  ((Previous.is(tok::comma) &&
-   !Previous.is(TT_OverloadedOperator)) ||
+   Previous.isNot(TT_OverloadedOperator)) ||
   (Previous.is(tok::colon) && Previous.is(TT_ObjCMethodExpr {
 CurrentState.LastSpace = State.Column;
   } else if (Previous.is(TT_CtorInitializerColon) &&
@@ -952,9 +952,9 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState 
&State,
   //
   // is common and should be formatted like a free-standing function. The same
   // goes for wrapping before the lambda return type arrow.
-  if (!Current.is(TT_LambdaArrow) &&
+  if (Current.isNot(TT_LambdaArrow) &&
   (!Style.isJavaScript() || Current.Nesting

[PATCH] D158571: [clang-format][NFC] Replace !is() with isNot()

2023-08-24 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG91c4db00612b: [clang-format][NFC] Replace !is() with isNot() 
(authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158571

Files:
  clang/lib/Format/ContinuationIndenter.cpp
  clang/lib/Format/DefinitionBlockSeparator.cpp
  clang/lib/Format/Format.cpp
  clang/lib/Format/FormatToken.h
  clang/lib/Format/FormatTokenLexer.cpp
  clang/lib/Format/FormatTokenSource.h
  clang/lib/Format/MacroExpander.cpp
  clang/lib/Format/QualifierAlignmentFixer.cpp
  clang/lib/Format/SortJavaScriptImports.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/lib/Format/UnwrappedLineFormatter.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/WhitespaceManager.cpp

Index: clang/lib/Format/WhitespaceManager.cpp
===
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -590,14 +590,14 @@
 
   // A new line starts, re-initialize line status tracking bools.
   // Keep the match state if a string literal is continued on this line.
-  if (i == 0 || !Changes[i].Tok->is(tok::string_literal) ||
-  !Changes[i - 1].Tok->is(tok::string_literal)) {
+  if (i == 0 || Changes[i].Tok->isNot(tok::string_literal) ||
+  Changes[i - 1].Tok->isNot(tok::string_literal)) {
 FoundMatchOnLine = false;
   }
   LineIsComment = true;
 }
 
-if (!Changes[i].Tok->is(tok::comment))
+if (Changes[i].Tok->isNot(tok::comment))
   LineIsComment = false;
 
 if (Changes[i].Tok->is(tok::comma)) {
@@ -731,10 +731,10 @@
   SpacesRequiredBefore = 0;
 }
 
-if (!Current || !Current->is(tok::identifier))
+if (!Current || Current->isNot(tok::identifier))
   return false;
 
-if (!Current->Previous || !Current->Previous->is(tok::pp_define))
+if (!Current->Previous || Current->Previous->isNot(tok::pp_define))
   return false;
 
 // For a macro function, 0 spaces are required between the
@@ -781,7 +781,7 @@
   LineIsComment = true;
 }
 
-if (!Changes[I].Tok->is(tok::comment))
+if (Changes[I].Tok->isNot(tok::comment))
   LineIsComment = false;
 
 if (!AlignMacrosMatches(Changes[I]))
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -394,7 +394,7 @@
 ParseDefault();
 continue;
   }
-  if (CanContainBracedList && !FormatTok->is(TT_MacroBlockBegin) &&
+  if (CanContainBracedList && FormatTok->isNot(TT_MacroBlockBegin) &&
   tryToParseBracedList()) {
 continue;
   }
@@ -615,7 +615,7 @@
   LBraceStack.pop_back();
   break;
 case tok::identifier:
-  if (!Tok->is(TT_StatementMacro))
+  if (Tok->isNot(TT_StatementMacro))
 break;
   [[fallthrough]];
 case tok::at:
@@ -799,8 +799,8 @@
   if (eof())
 return IfLBrace;
 
-  if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd)
- : !FormatTok->is(tok::r_brace)) {
+  if (MacroBlock ? FormatTok->isNot(TT_MacroBlockEnd)
+ : FormatTok->isNot(tok::r_brace)) {
 Line->Level = InitialLevel;
 FormatTok->setBlockKind(BK_Block);
 return IfLBrace;
@@ -1080,7 +1080,7 @@
   bool MaybeIncludeGuard = IfNDef;
   if (IncludeGuard == IG_Inited && MaybeIncludeGuard) {
 for (auto &Line : Lines) {
-  if (!Line.Tokens.front().Tok->is(tok::comment)) {
+  if (Line.Tokens.front().Tok->isNot(tok::comment)) {
 MaybeIncludeGuard = false;
 IncludeGuard = IG_Rejected;
 break;
@@ -1612,7 +1612,7 @@
 nextToken();
 if (FormatTok->is(tok::kw_public))
   nextToken();
-if (!FormatTok->is(tok::string_literal))
+if (FormatTok->isNot(tok::string_literal))
   return;
 nextToken();
 if (FormatTok->is(tok::semi))
@@ -1887,8 +1887,9 @@
   // a new unwrapped line, so they are special cased below.
   size_t TokenCount = Line->Tokens.size();
   if (Style.isJavaScript() && FormatTok->is(Keywords.kw_function) &&
-  (TokenCount > 1 || (TokenCount == 1 && !Line->Tokens.front().Tok->is(
- Keywords.kw_async {
+  (TokenCount > 1 ||
+   (TokenCount == 1 &&
+Line->Tokens.front().Tok->isNot(Keywords.kw_async {
 tryToParseJSFunction();
 break;
   }
@@ -2872,7 +2873,7 @@
   FormatTok->is(tok::l_brace)) {
 do {
   nextToken();
-} while (!FormatTok->is(tok::r_brace));
+} while (FormatTok->isNot(tok::r_brace));
 nextToken();
   }
 
@@ -2895,7 +2896,7 @@
   addUnwra

[PATCH] D158558: [clang] - Add missing builtin name to AtomicExpr JSON dump

2023-08-24 Thread serge via Phabricator via cfe-commits
serge-sans-paille added a comment.

I don't have a strong opinion on the synchronization with `TextNodeDumper`. I'm 
pretty sure I didn't update it while adding fields for the Attribute nodes 
though...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158558

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


[PATCH] D158601: [Clang] Always constant-evaluate operands of comparisons to nullptr

2023-08-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added a comment.

Gotcha. Given there are other stuffs I need to backport, this will have to wait 
clang 18! I don't want to give undue work to tobias and testers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158601

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


[PATCH] D158601: [Clang] Always constant-evaluate operands of comparisons to nullptr

2023-08-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 553038.
cor3ntin added a comment.

Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158601

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/compare-cxx2a.cpp


Index: clang/test/SemaCXX/compare-cxx2a.cpp
===
--- clang/test/SemaCXX/compare-cxx2a.cpp
+++ clang/test/SemaCXX/compare-cxx2a.cpp
@@ -461,3 +461,21 @@
   template bool f6() { return 0 < y6; } // expected-note 
{{instantiation of}}
   void g6() { f6(); } // expected-note {{instantiation of}}
 }
+
+
+namespace GH64923 {
+using nullptr_t = decltype(nullptr);
+struct MyTask{};
+constexpr MyTask DoAnotherThing() {
+return {};
+}
+
+constexpr nullptr_t operator++(MyTask &&T); // expected-note 2{{declared here}}
+void DoSomething() {
+  if constexpr (++DoAnotherThing() != nullptr) {} // expected-error 
{{constexpr if condition is not a constant expression}} \
+  // expected-note  
{{undefined function 'operator++' cannot be used in a constant expression}}
+
+  if constexpr (nullptr == ++DoAnotherThing()) {} // expected-error 
{{constexpr if condition is not a constant expression}} \
+  // expected-note  
{{undefined function 'operator++' cannot be used in a constant expression}}
+}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13310,6 +13310,10 @@
 // C++11 [expr.rel]p4, [expr.eq]p3: If two operands of type std::nullptr_t
 // are compared, the result is true of the operator is <=, >= or ==, and
 // false otherwise.
+LValue Res;
+if (!EvaluatePointer(E->getLHS(), Res, Info) ||
+!EvaluatePointer(E->getRHS(), Res, Info))
+  return false;
 return Success(CmpResult::Equal, E);
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,6 +198,11 @@
 - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
   (`#64171 `_).
 
+- Expressions producing ``nullptr`` are correctly evaluated
+  by the constant interpreter when appearing as the operand
+  of a binary comparision.
+  (`#64923 _``)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.


Index: clang/test/SemaCXX/compare-cxx2a.cpp
===
--- clang/test/SemaCXX/compare-cxx2a.cpp
+++ clang/test/SemaCXX/compare-cxx2a.cpp
@@ -461,3 +461,21 @@
   template bool f6() { return 0 < y6; } // expected-note {{instantiation of}}
   void g6() { f6(); } // expected-note {{instantiation of}}
 }
+
+
+namespace GH64923 {
+using nullptr_t = decltype(nullptr);
+struct MyTask{};
+constexpr MyTask DoAnotherThing() {
+return {};
+}
+
+constexpr nullptr_t operator++(MyTask &&T); // expected-note 2{{declared here}}
+void DoSomething() {
+  if constexpr (++DoAnotherThing() != nullptr) {} // expected-error {{constexpr if condition is not a constant expression}} \
+  // expected-note  {{undefined function 'operator++' cannot be used in a constant expression}}
+
+  if constexpr (nullptr == ++DoAnotherThing()) {} // expected-error {{constexpr if condition is not a constant expression}} \
+  // expected-note  {{undefined function 'operator++' cannot be used in a constant expression}}
+}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13310,6 +13310,10 @@
 // C++11 [expr.rel]p4, [expr.eq]p3: If two operands of type std::nullptr_t
 // are compared, the result is true of the operator is <=, >= or ==, and
 // false otherwise.
+LValue Res;
+if (!EvaluatePointer(E->getLHS(), Res, Info) ||
+!EvaluatePointer(E->getRHS(), Res, Info))
+  return false;
 return Success(CmpResult::Equal, E);
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,6 +198,11 @@
 - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
   (`#64171 `_).
 
+- Expressions producing ``nullptr`` are correctly evaluated
+  by the constant interpreter when appearing as the operand
+  of a binary comparision.
+  (`#64923 

[clang] 0e63f1a - [clang-format] Annotate constructor/destructor names

2023-08-24 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2023-08-24T01:32:52-07:00
New Revision: 0e63f1aacc0040e9a16fa2fab15a140b1686e2ab

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

LOG: [clang-format] Annotate constructor/destructor names

Annotate constructor/destructor names as FunctionDeclarationName.

Fixes #63046.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index b6b4172818d171..97df0b447b4baa 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3097,6 +3097,76 @@ static unsigned maxNestingDepth(const AnnotatedLine 
&Line) {
   return Result;
 }
 
+// Returns the name of a function with no return type, e.g. a constructor or
+// destructor.
+static FormatToken *getFunctionName(const AnnotatedLine &Line) {
+  for (FormatToken *Tok = Line.getFirstNonComment(), *Name = nullptr; Tok;
+   Tok = Tok->getNextNonComment()) {
+// Skip C++11 attributes both before and after the function name.
+if (Tok->is(tok::l_square) && Tok->is(TT_AttributeSquare)) {
+  Tok = Tok->MatchingParen;
+  if (!Tok)
+break;
+  continue;
+}
+
+// Make sure the name is followed by a pair of parentheses.
+if (Name)
+  return Tok->is(tok::l_paren) && Tok->MatchingParen ? Name : nullptr;
+
+// Skip keywords that may precede the constructor/destructor name.
+if (Tok->isOneOf(tok::kw_friend, tok::kw_inline, tok::kw_virtual,
+ tok::kw_constexpr, tok::kw_consteval, tok::kw_explicit)) {
+  continue;
+}
+
+// A qualified name may start from the global namespace.
+if (Tok->is(tok::coloncolon)) {
+  Tok = Tok->Next;
+  if (!Tok)
+break;
+}
+
+// Skip to the unqualified part of the name.
+while (Tok->startsSequence(tok::identifier, tok::coloncolon)) {
+  assert(Tok->Next);
+  Tok = Tok->Next->Next;
+  if (!Tok)
+break;
+}
+
+// Skip the `~` if a destructor name.
+if (Tok->is(tok::tilde)) {
+  Tok = Tok->Next;
+  if (!Tok)
+break;
+}
+
+// Make sure the name is not already annotated, e.g. as NamespaceMacro.
+if (Tok->isNot(tok::identifier) || Tok->isNot(TT_Unknown))
+  break;
+
+Name = Tok;
+  }
+
+  return nullptr;
+}
+
+// Checks if Tok is a constructor/destructor name qualified by its class name.
+static bool isCtorOrDtorName(const FormatToken *Tok) {
+  assert(Tok && Tok->is(tok::identifier));
+  const auto *Prev = Tok->Previous;
+
+  if (Prev && Prev->is(tok::tilde))
+Prev = Prev->Previous;
+
+  if (!Prev || !Prev->endsSequence(tok::coloncolon, tok::identifier))
+return false;
+
+  assert(Prev->Previous);
+  return Prev->Previous->TokenText == Tok->TokenText;
+}
+
 void TokenAnnotator::annotate(AnnotatedLine &Line) {
   for (auto &Child : Line.Children)
 annotate(*Child);
@@ -3117,6 +3187,14 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
   ExpressionParser ExprParser(Style, Keywords, Line);
   ExprParser.parse();
 
+  if (Style.isCpp()) {
+auto *Tok = getFunctionName(Line);
+if (Tok && ((!Scopes.empty() && Scopes.back() == ST_Class) ||
+Line.endsWith(TT_FunctionLBrace) || isCtorOrDtorName(Tok))) {
+  Tok->setFinalizedType(TT_FunctionDeclarationName);
+}
+  }
+
   if (Line.startsWith(TT_ObjCMethodSpecifier))
 Line.Type = LT_ObjCMethodDecl;
   else if (Line.startsWith(TT_ObjCDecl))
@@ -3133,6 +3211,10 @@ void TokenAnnotator::annotate(AnnotatedLine &Line) {
 static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current,
   const AnnotatedLine &Line) {
   assert(Current.Previous);
+
+  if (Current.is(TT_FunctionDeclarationName))
+return true;
+
   if (!Current.Tok.getIdentifierInfo())
 return false;
 
@@ -3313,9 +3395,11 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   bool LineIsFunctionDeclaration = false;
   for (FormatToken *Tok = Current, *AfterLastAttribute = nullptr; Tok;
Tok = Tok->Next) {
+if (Tok->Previous->EndsCppAttributeGroup)
+  AfterLastAttribute = Tok;
 if (isFunctionDeclarationName(Style.isCpp(), *Tok, Line)) {
   LineIsFunctionDeclaration = true;
-  Tok->setType(TT_FunctionDeclarationName);
+  Tok->setFinalizedType(TT_FunctionDeclarationName);
   if (AfterLastAttribute &&
   mustBreakAfterAttributes(*AfterLastAttribute, Style)) {
 AfterLastAttribute->MustBreakBefore = true;
@@ -3323,8 +3407,6 @@ void 
TokenAnnotator::calculateFormatting

[PATCH] D157963: [clang-format] Annotate constructor/destructor names

2023-08-24 Thread Owen Pan via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e63f1aacc00: [clang-format] Annotate constructor/destructor 
names (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157963

Files:
  clang/lib/Format/TokenAnnotator.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
@@ -1589,6 +1589,54 @@
   Tokens = annotate("void f [[noreturn]] () {}");
   ASSERT_EQ(Tokens.size(), 12u) << Tokens;
   EXPECT_TOKEN(Tokens[1], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("class Foo { public: Foo(); };");
+  ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("class Foo { public: ~Foo(); };");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::identifier, TT_FunctionDeclarationName);
+
+  Tokens = annotate("struct Foo { [[deprecated]] Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[8], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { [[deprecated]] ~Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { Foo() [[deprecated]] {} };");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[11], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { ~Foo() [[deprecated]] {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { [[deprecated]] explicit Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 17u) << Tokens;
+  EXPECT_TOKEN(Tokens[9], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[12], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("struct Foo { virtual [[deprecated]] ~Foo() {} };");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[13], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Foo::Foo() {}");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[2], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[5], tok::l_brace, TT_FunctionLBrace);
+
+  Tokens = annotate("Foo::~Foo() {}");
+  ASSERT_EQ(Tokens.size(), 9u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::identifier, TT_FunctionDeclarationName);
+  EXPECT_TOKEN(Tokens[6], tok::l_brace, TT_FunctionLBrace);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsC11GenericSelection) {
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -16542,7 +16542,7 @@
 
   verifyFormat("int f();", SpaceFuncDef);
   verifyFormat("void f (int a, T b) {}", SpaceFuncDef);
-  verifyFormat("A::A() : a(1) {}", SpaceFuncDef);
+  verifyFormat("A::A () : a(1) {}", SpaceFuncDef);
   verifyFormat("void f() __attribute__((asdf));", SpaceFuncDef);
   verifyFormat("#define A(x) x", SpaceFuncDef);
   verifyFormat("#define A (x) x", SpaceFuncDef);
@@ -16567,7 +16567,7 @@
   // verifyFormat("T A::operator() () {}", SpaceFuncDef);
   verifyFormat("auto lambda = [] () { return 0; };", SpaceFuncDef);
   verifyFormat("int x = int(y);", SpaceFuncDef);
-  verifyFormat("M(std::size_t R, std::size_t C) : C(C), data(R) {}",
+  verifyFormat("M (std::size_t R, std::size_t C) : C(C), data(R) {}",
SpaceFuncDef);
 
   FormatStyle SpaceIfMacros = getLLVMStyle();
@@ -26242,18 +26242,18 @@
   FormatStyle Style = getLLVMStyle();
   EXPECT_EQ(Style.BreakAfterAttributes, FormatStyle::ABS_Never);
 
-  const StringRef Code("[[nodiscard]] inline int f(int &i);\n"
-   "[[foo([[]])]] [[nodiscard]]\n"
-   "int g(int &i);\n"
-   "[[nodiscard]]\n"
-   "inline int f(int &i) {\n"
-   "  i = 1;\n"
-   "  return 0;\n"
-   "}\n"
-   "[[foo([[]])]] [[nodiscard]] int g(int &i) {\n"
-   "  i = 0;\n"
-   "  return 1;\n"
-   "}");
+  constexpr StringRef Code("[[no

[PATCH] D156344: Disable call to fma for soft-float

2023-08-24 Thread Kishan Parmar via Phabricator via cfe-commits
long5hot added a comment.

@nemanjai , @jhibbits  should i land on this commit, because as @shchenz  said, 
similiar to D158632  review we are having 
plan to do same for PPC.


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

https://reviews.llvm.org/D156344

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


[PATCH] D158718: [Clang] Handle ellipsises in abiguous cast expressions.

2023-08-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`(T())(foo)` is a cast expression because `T()`
is treated as a type-id, and the expression is valid.

However, `(T())(foo...)` is not a valid cast-expression,
because `(type-id)(foo...)` is invalid.
Yet, it is a valid postfix expression, ie,
`T().operator()(foo...)`

We previously would uncontitionally consider the whole thing
a cast expression and complained about expecting a
right parenthesis after `foo`.

We do keep track of whether we are in a context where the
type-id is ambiguous to keep the existing diagnostics for
the non ambiguous case (ie `(void)(foo...)`).

Fixes #64926


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158718

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/Parser/cxx-ambig-paren-expr.cpp

Index: clang/test/Parser/cxx-ambig-paren-expr.cpp
===
--- clang/test/Parser/cxx-ambig-paren-expr.cpp
+++ clang/test/Parser/cxx-ambig-paren-expr.cpp
@@ -70,3 +70,24 @@
 return;
 }
 
+namespace GH64926 {
+template
+void PackInAmbiguousCastExpression(Args... args) {
+	  (void) (Args::foo()...); // expected-error {{expression contains unexpanded parameter pack 'Args'}} \
+// expected-error {{expected ')'}} expected-note {{to match this '('}}
+
+(void) (args...);  // expected-error {{expression contains unexpanded parameter pack 'args'}} \
+   // expected-error {{expected ')'}} expected-note {{to match this '('}}
+
+(void) (((args))...);  // expected-error {{expression contains unexpanded parameter pack 'args'}} \
+   // expected-error {{expected ')'}} expected-note {{to match this '('}}
+
+(void) (((args...)));  // expected-error {{expression contains unexpanded parameter pack 'args'}} \
+   // expected-error {{expected ')'}} expected-note {{to match this '('}}
+(T()) (Args::foo()...);
+(T()) (args...);
+(T()) (((args))...);
+(T()) (((args...))); // expected-error {{expression contains unexpanded parameter pack 'args'}} \
+ // expected-error {{expected ')'}} expected-note {{to match this '('}}
+}
+}
Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -53,6 +53,7 @@
 : PP(pp), PreferredType(pp.isCodeCompletionEnabled()), Actions(actions),
   Diags(PP.getDiagnostics()), GreaterThanIsOperator(true),
   ColonIsSacred(false), InMessageExpression(false),
+  InAmbiguousCXXParenExprParsing(false),
   TemplateParameterDepth(0), ParsingInObjCContainer(false) {
   SkipFunctionBodies = pp.isCodeCompletionEnabled() || skipFunctionBodies;
   Tok.startToken();
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -3981,6 +3981,7 @@
   // If it is not a cast-expression, NotCastExpr will be true and no token
   // will be consumed.
   ColonProt.restore();
+  SaveAndRestore AmbiguousParenRAII(InAmbiguousCXXParenExprParsing, true);
   Result = ParseCastExpression(AnyCastExpr,
false/*isAddressofOperand*/,
NotCastExpr,
Index: clang/lib/Parse/ParseExpr.cpp
===
--- clang/lib/Parse/ParseExpr.cpp
+++ clang/lib/Parse/ParseExpr.cpp
@@ -28,6 +28,7 @@
 #include "clang/Parse/RAIIObjectsForParser.h"
 #include "clang/Sema/DeclSpec.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
+#include "clang/Sema/Ownership.h"
 #include "clang/Sema/ParsedTemplate.h"
 #include "clang/Sema/Scope.h"
 #include "clang/Sema/TypoCorrection.h"
@@ -3164,6 +3165,14 @@
 return ParseFoldExpression(ArgExprs[0], T);
   }
 
+  // If we find an ellipsis, this cannot be part of a cast expression,
+  // stop there and try to parse a simple expression instead.
+  // This handles `(T())(expr...)`.
+  if(InAmbiguousCXXParenExprParsing && isTypeCast && Tok.is(tok::ellipsis)
+  && ExprType == Parser::CastExpr && getLangOpts().CPlusPlus) {
+return ExprError();
+  }
+
   ExprType = SimpleExpr;
   Result = Actions.ActOnParenListExpr(OpenLoc, Tok.getLocation(),
   ArgExprs);
Index: clang/include/clang/Parse/Parser.h
===
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -245,6 +245,10 @@
   /// should not be set directly.

[PATCH] D158433: [Clang] Do not change the type of captured vars when checking lambda constraints

2023-08-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 553047.
cor3ntin added a comment.

Missing curlies


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158433

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- clang/test/SemaCXX/lambda-capture-type-deduction.cpp
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -246,3 +246,17 @@
 static_assert(is_same);
   };
 }
+
+namespace GH61267 {
+template  concept C = true;
+
+template
+void f(int) {
+  int i;
+  [i](P) {}(0);
+  i = 4;
+}
+
+void test() { f(0);  }
+
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -19723,13 +19723,6 @@
 FunctionScopesIndex == MaxFunctionScopesIndex && VarDC == DC)
   return true;
 
-// When evaluating some attributes (like enable_if) we might refer to a
-// function parameter appertaining to the same declaration as that
-// attribute.
-if (const auto *Parm = dyn_cast(Var);
-Parm && Parm->getDeclContext() == DC)
-  return true;
-
 // Only block literals, captured statements, and lambda expressions can
 // capture; other scopes don't work.
 DeclContext *ParentDC =
@@ -19757,6 +19750,14 @@
   CSI->getCapture(Var).markUsed(BuildAndDiagnose);
   break;
 }
+
+// When evaluating some attributes (like enable_if) we might refer to a
+// function parameter appertaining to the same declaration as that
+// attribute.
+if (const auto *Parm = dyn_cast(Var);
+Parm && Parm->getDeclContext() == DC)
+  return true;
+
 // If we are instantiating a generic lambda call operator body,
 // we do not want to capture new variables.  What was captured
 // during either a lambdas transformation or initial parsing
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -15289,11 +15289,10 @@
   FD->setInvalidDecl();
 }
 
-static void RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator,
-   Sema &S) {
-  CXXRecordDecl *const LambdaClass = CallOperator->getParent();
+LambdaScopeInfo *Sema::RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator) {
+  CXXRecordDecl *LambdaClass = CallOperator->getParent();
 
-  LambdaScopeInfo *LSI = S.PushLambdaScope();
+  LambdaScopeInfo *LSI = PushLambdaScope();
   LSI->CallOperator = CallOperator;
   LSI->Lambda = LambdaClass;
   LSI->ReturnType = CallOperator->getReturnType();
@@ -15317,7 +15316,7 @@
 if (C.capturesVariable()) {
   ValueDecl *VD = C.getCapturedVar();
   if (VD->isInitCapture())
-S.CurrentInstantiationScope->InstantiatedLocal(VD, VD);
+CurrentInstantiationScope->InstantiatedLocal(VD, VD);
   const bool ByRef = C.getCaptureKind() == LCK_ByRef;
   LSI->addCapture(VD, /*IsBlock*/false, ByRef,
   /*RefersToEnclosingVariableOrCapture*/true, C.getLocation(),
@@ -15334,6 +15333,7 @@
 }
 ++I;
   }
+  return LSI;
 }
 
 Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D,
@@ -15437,7 +15437,7 @@
 assert(inTemplateInstantiation() &&
"There should be an active template instantiation on the stack "
"when instantiating a generic lambda!");
-RebuildLambdaScopeInfo(cast(D), *this);
+RebuildLambdaScopeInfo(cast(D));
   } else {
 // Enter a new function scope
 PushFunctionScope();
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -13,12 +13,14 @@
 #include "clang/Sema/SemaConcept.h"
 #include "TreeTransform.h"
 #include "clang/AST/ASTLambda.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/ExprConcepts.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/OperatorPrecedence.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Overload.h"
+#include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaDiagnostic.h"
 #include "clang/Sema/SemaInternal.h"
@@ -540,11 +542,6 @@
   auto AddSingleCapture = [&](const ValueDecl *CapturedPattern,
   unsigned Index) {
 ValueDecl *CapturedVar = LambdaClass->getCapture(Index)->getCapturedVar();
-if (cast(Function)->isConst()) {
-  QualType T = CapturedVar->getType();
-  T.addConst();
-  CapturedVar->setType(T);
-}
 if (CapturedVar->isInitCapture())
   Scope.InstantiatedL

[PATCH] D151869: [RISCV] Support more builtin for zvfhmin.

2023-08-24 Thread Jianjian Guan via Phabricator via cfe-commits
jacquesguan updated this revision to Diff 553051.
jacquesguan added a comment.
Herald added subscribers: wangpc, sunshaoce.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151869

Files:
  clang/include/clang/Basic/riscv_vector.td
  clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c

Index: clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
===
--- clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
+++ clang/test/CodeGen/RISCV/rvv-intrinsics-handcrafted/zvfhmin.c
@@ -9,7 +9,7 @@
 
 // CHECK-ZVFHMIN-LABEL: @test_vfncvt_f_f_w_f16m1(
 // CHECK-ZVFHMIN-NEXT:  entry:
-// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vfncvt.f.f.w.nxv4f16.nxv4f32.i64( poison,  [[SRC:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vfncvt.f.f.w.nxv4f16.nxv4f32.i64( poison,  [[SRC:%.*]], i64 7, i64 [[VL:%.*]])
 // CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
 //
 vfloat16m1_t test_vfncvt_f_f_w_f16m1(vfloat32m2_t src, size_t vl) {
@@ -25,3 +25,192 @@
 vfloat32m2_t test_vfwcvt_f_f_v_f16m1(vfloat16m1_t src, size_t vl) {
   return __riscv_vfwcvt_f(src, vl);
 }
+
+// CHECK-ZVFHMIN-LABEL: @test_vle16_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vle.nxv4f16.i64( poison, ptr [[BASE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vle16_v_f16m1(const _Float16 *base, size_t vl) {
+  return __riscv_vle16_v_f16m1(base, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vse16_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:call void @llvm.riscv.vse.nxv4f16.i64( [[VALUE:%.*]], ptr [[BASE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret void
+//
+void test_vse16_v_f16m1(_Float16 *base, vfloat16m1_t value, size_t vl) {
+  return __riscv_vse16_v_f16m1(base, value, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vlse16_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vlse.nxv4f16.i64( poison, ptr [[BASE:%.*]], i64 [[BSTRIDE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vlse16_v_f16m1(const _Float16 *base, ptrdiff_t bstride, size_t vl) {
+  return __riscv_vlse16_v_f16m1(base, bstride, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vsse16_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:call void @llvm.riscv.vsse.nxv4f16.i64( [[VALUE:%.*]], ptr [[BASE:%.*]], i64 [[BSTRIDE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret void
+//
+void test_vsse16_v_f16m1(_Float16 *base, ptrdiff_t bstride, vfloat16m1_t value, size_t vl) {
+  return __riscv_vsse16_v_f16m1(base, bstride, value, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vluxei32_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vluxei.nxv4f16.nxv4i32.i64( poison, ptr [[BASE:%.*]],  [[BINDEX:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vluxei32_v_f16m1(const _Float16 *base, vuint32m2_t bindex, size_t vl) {
+  return __riscv_vluxei32_v_f16m1(base, bindex, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vsuxei32_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:call void @llvm.riscv.vsuxei.nxv4f16.nxv4i32.i64( [[VALUE:%.*]], ptr [[BASE:%.*]],  [[BINDEX:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret void
+//
+void test_vsuxei32_v_f16m1(_Float16 *base, vuint32m2_t bindex, vfloat16m1_t value, size_t vl) {
+  return __riscv_vsuxei32_v_f16m1(base, bindex, value, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vloxei32_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call  @llvm.riscv.vloxei.nxv4f16.nxv4i32.i64( poison, ptr [[BASE:%.*]],  [[BINDEX:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP0]]
+//
+vfloat16m1_t test_vloxei32_v_f16m1(const _Float16 *base, vuint32m2_t bindex, size_t vl) {
+  return __riscv_vloxei32_v_f16m1(base, bindex, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vsoxei32_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:call void @llvm.riscv.vsoxei.nxv4f16.nxv4i32.i64( [[VALUE:%.*]], ptr [[BASE:%.*]],  [[BINDEX:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:ret void
+//
+void test_vsoxei32_v_f16m1(_Float16 *base, vuint32m2_t bindex, vfloat16m1_t value, size_t vl) {
+  return __riscv_vsoxei32_v_f16m1(base, bindex, value, vl);
+}
+
+// CHECK-ZVFHMIN-LABEL: @test_vle16ff_v_f16m1(
+// CHECK-ZVFHMIN-NEXT:  entry:
+// CHECK-ZVFHMIN-NEXT:[[TMP0:%.*]] = call { , i64 } @llvm.riscv.vleff.nxv4f16.i64( poison, ptr [[BASE:%.*]], i64 [[VL:%.*]])
+// CHECK-ZVFHMIN-NEXT:[[TMP1:%.*]] = extractvalue { , i64 } [[TMP0]], 0
+// CHECK-ZVFHMIN-NEXT:[[TMP2:%.*]] = extractvalue { , i64 } [[TMP0]], 1
+// CHECK-ZVFHMIN-NEXT:store i64 [[TMP2]], ptr [[NEW_VL:%.*]], align 8
+// CHECK-ZVFHMIN-NEXT:ret  [[TMP1

[PATCH] D158479: [clang] Support elementwise builtin for sizeless vector type

2023-08-24 Thread Paul Walker via Phabricator via cfe-commits
paulwalker-arm added inline comments.



Comment at: clang/test/CodeGen/aarch64-sve-vector-elementwise-ops.c:128-131
+// CHECK-NEXT:[[ELT_MIN:%.*]] = call  
@llvm.umin.nxv16i8( [[VI8:%.*]],  [[VI8]])
+// CHECK-NEXT:[[ELT_MIN1:%.*]] = call  
@llvm.umin.nxv8i16( [[VI16:%.*]],  [[VI16]])
+// CHECK-NEXT:[[ELT_MIN2:%.*]] = call  
@llvm.umin.nxv4i32( [[VI32:%.*]],  [[VI32]])
+// CHECK-NEXT:[[ELT_MIN3:%.*]] = call  
@llvm.umin.nxv2i64( [[VI64:%.*]],  [[VI64]])

These should be `smin` rather than `umin`?



Comment at: clang/test/CodeGen/aarch64-sve-vector-elementwise-ops.c:208-210
+// CHECK-NEXT:[[ELT_COS:%.*]] = call  
@llvm.cos.nxv8f16( [[VF16:%.*]])
+// CHECK-NEXT:[[ELT_COS1:%.*]] = call  
@llvm.cos.nxv4f32( [[VF32:%.*]])
+// CHECK-NEXT:[[ELT_COS2:%.*]] = call  
@llvm.cos.nxv2f64( [[VF64:%.*]])

This highlights a potential sticking point because can we code generate such 
intrinsics for scalable vectors?  LoopVectorize will emit calls to a vector 
math library rather than call this intrinsic directly.  There's also the 
replace-with-veclib pass that will convert such intrinsics, again only if 
there's a suitable math library available.

Is it a good idea to allow builtins that we know will cause a code generation 
failure? Or might result in a scalarised implementation?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158479

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


[PATCH] D156054: [Clang][Sema] DR722 (nullptr and varargs) and missing -Wvarargs diagnostics

2023-08-24 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok updated this revision to Diff 553055.
MitalAshok added a comment.

enums now considered compatible with unsigned/signed versions of their 
underlying type for the purposes of -Wvarargs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156054

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/drs/dr7xx.cpp
  clang/test/CodeGen/xcore-abi.c
  clang/test/Sema/format-pointer.c
  clang/test/Sema/format-strings-pedantic.c
  clang/test/Sema/varargs.c
  clang/test/SemaCXX/format-strings-0x-nopedantic.cpp
  clang/test/SemaCXX/varargs.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -4373,7 +4373,7 @@
 https://cplusplus.github.io/CWG/issues/722.html";>722
 CD2
 Can nullptr be passed to an ellipsis?
-Unknown
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/726.html";>726
Index: clang/test/SemaCXX/varargs.cpp
===
--- clang/test/SemaCXX/varargs.cpp
+++ clang/test/SemaCXX/varargs.cpp
@@ -30,22 +30,28 @@
 
 // Ensure the correct behavior for promotable type UB checking.
 void promotable(int a, ...) {
-  enum Unscoped1 { One = 0x7FFF };
+  enum Unscoped1 { U = 0x7FFF };
   (void)__builtin_va_arg(ap, Unscoped1); // ok
 
-  enum Unscoped2 { Two = 0x };
+  enum Unscoped2 { I = 0x };
   (void)__builtin_va_arg(ap, Unscoped2); // ok
 
-  enum class Scoped { Three };
+  enum Unscoped3 { UL = 0x7FFF };
+  (void)__builtin_va_arg(ap, Unscoped3); // ok
+
+  enum Unscoped4 { L = 0xu };
+  (void)__builtin_va_arg(ap, Unscoped4); // ok
+
+  enum class Scoped { One };
   (void)__builtin_va_arg(ap, Scoped); // ok
 
-  enum Fixed : int { Four };
+  enum Fixed : int { Two };
   (void)__builtin_va_arg(ap, Fixed); // ok
 
-  enum FixedSmall : char { Five };
+  enum FixedSmall : char { Three };
   (void)__builtin_va_arg(ap, FixedSmall); // expected-warning {{second argument to 'va_arg' is of promotable type 'FixedSmall'; this va_arg has undefined behavior because arguments will be promoted to 'int'}}
 
-  enum FixedLarge : long long { Six };
+  enum FixedLarge : long long { Four };
   (void)__builtin_va_arg(ap, FixedLarge); // ok
 
   // Ensure that qualifiers are ignored.
@@ -55,6 +61,24 @@
   (void)__builtin_va_arg(ap, unsigned int);
 
   (void)__builtin_va_arg(ap, bool); // expected-warning {{second argument to 'va_arg' is of promotable type 'bool'; this va_arg has undefined behavior because arguments will be promoted to 'int'}}
+
+  (void)__builtin_va_arg(ap, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'; this va_arg has undefined behavior because arguments will be promoted to 'double'}}
+  (void)__builtin_va_arg(ap, __fp16); // expected-warning {{second argument to 'va_arg' is of promotable type '__fp16'; this va_arg has undefined behavior because arguments will be promoted to 'double'}}
+
+#if __cplusplus >= 201103L
+  (void)__builtin_va_arg(ap, decltype(nullptr)); // expected-warning {{second argument to 'va_arg' is of promotable type 'decltype(nullptr)' (aka 'std::nullptr_t'); this va_arg has undefined behavior because arguments will be promoted to 'void *'}}
+#endif
+
+  (void)__builtin_va_arg(ap, int[3]); // expected-warning {{second argument to 'va_arg' is of promotable type 'int[3]'; this va_arg has undefined behavior because arguments will be promoted to 'int *'}}
+  (void)__builtin_va_arg(ap, const int[3]); // expected-warning {{second argument to 'va_arg' is of promotable type 'const int[3]'; this va_arg has undefined behavior because arguments will be promoted to 'const int *'}}
+
+  // _BitInts aren't promoted
+  (void)__builtin_va_arg(ap, _BitInt(7));
+  (void)__builtin_va_arg(ap, unsigned _BitInt(7));
+  (void)__builtin_va_arg(ap, _BitInt(32));
+  (void)__builtin_va_arg(ap, unsigned _BitInt(32));
+  (void)__builtin_va_arg(ap, _BitInt(33));
+  (void)__builtin_va_arg(ap, unsigned _BitInt(33));
 }
 
 #if __cplusplus >= 201103L
Index: clang/test/SemaCXX/format-strings-0x-nopedantic.cpp
===
--- clang/test/SemaCXX/format-strings-0x-nopedantic.cpp
+++ clang/test/SemaCXX/format-strings-0x-nopedantic.cpp
@@ -5,6 +5,7 @@
 extern int printf(const char *restrict, ...);
 }
 
-void f(char *c) {
+void f(char *c, int *q) {
   printf("%p", c);
+  printf("%p", q);
 }
Index: clang/test/Sema/varargs.c
===
--- clang/test/Sema/varargs.c
+++ clang/test/Sema/varargs.c
@@ -75,6 +75,14 @@
 (void)__builtin_va_arg(args, enum E); // Don't warn here in C
 (void)__builtin_va_arg(args, short); // expected-warning {{secon

[PATCH] D156054: [Clang][Sema] DR722 (nullptr and varargs) and missing -Wvarargs diagnostics

2023-08-24 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok updated this revision to Diff 553056.
MitalAshok added a comment.

clang-format


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156054

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/FormatString.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/CXX/drs/dr7xx.cpp
  clang/test/CodeGen/xcore-abi.c
  clang/test/Sema/format-pointer.c
  clang/test/Sema/format-strings-pedantic.c
  clang/test/Sema/varargs.c
  clang/test/SemaCXX/format-strings-0x-nopedantic.cpp
  clang/test/SemaCXX/varargs.cpp
  clang/www/cxx_dr_status.html

Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -4373,7 +4373,7 @@
 https://cplusplus.github.io/CWG/issues/722.html";>722
 CD2
 Can nullptr be passed to an ellipsis?
-Unknown
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/726.html";>726
Index: clang/test/SemaCXX/varargs.cpp
===
--- clang/test/SemaCXX/varargs.cpp
+++ clang/test/SemaCXX/varargs.cpp
@@ -30,22 +30,28 @@
 
 // Ensure the correct behavior for promotable type UB checking.
 void promotable(int a, ...) {
-  enum Unscoped1 { One = 0x7FFF };
+  enum Unscoped1 { U = 0x7FFF };
   (void)__builtin_va_arg(ap, Unscoped1); // ok
 
-  enum Unscoped2 { Two = 0x };
+  enum Unscoped2 { I = 0x };
   (void)__builtin_va_arg(ap, Unscoped2); // ok
 
-  enum class Scoped { Three };
+  enum Unscoped3 { UL = 0x7FFF };
+  (void)__builtin_va_arg(ap, Unscoped3); // ok
+
+  enum Unscoped4 { L = 0xu };
+  (void)__builtin_va_arg(ap, Unscoped4); // ok
+
+  enum class Scoped { One };
   (void)__builtin_va_arg(ap, Scoped); // ok
 
-  enum Fixed : int { Four };
+  enum Fixed : int { Two };
   (void)__builtin_va_arg(ap, Fixed); // ok
 
-  enum FixedSmall : char { Five };
+  enum FixedSmall : char { Three };
   (void)__builtin_va_arg(ap, FixedSmall); // expected-warning {{second argument to 'va_arg' is of promotable type 'FixedSmall'; this va_arg has undefined behavior because arguments will be promoted to 'int'}}
 
-  enum FixedLarge : long long { Six };
+  enum FixedLarge : long long { Four };
   (void)__builtin_va_arg(ap, FixedLarge); // ok
 
   // Ensure that qualifiers are ignored.
@@ -55,6 +61,24 @@
   (void)__builtin_va_arg(ap, unsigned int);
 
   (void)__builtin_va_arg(ap, bool); // expected-warning {{second argument to 'va_arg' is of promotable type 'bool'; this va_arg has undefined behavior because arguments will be promoted to 'int'}}
+
+  (void)__builtin_va_arg(ap, float); // expected-warning {{second argument to 'va_arg' is of promotable type 'float'; this va_arg has undefined behavior because arguments will be promoted to 'double'}}
+  (void)__builtin_va_arg(ap, __fp16); // expected-warning {{second argument to 'va_arg' is of promotable type '__fp16'; this va_arg has undefined behavior because arguments will be promoted to 'double'}}
+
+#if __cplusplus >= 201103L
+  (void)__builtin_va_arg(ap, decltype(nullptr)); // expected-warning {{second argument to 'va_arg' is of promotable type 'decltype(nullptr)' (aka 'std::nullptr_t'); this va_arg has undefined behavior because arguments will be promoted to 'void *'}}
+#endif
+
+  (void)__builtin_va_arg(ap, int[3]); // expected-warning {{second argument to 'va_arg' is of promotable type 'int[3]'; this va_arg has undefined behavior because arguments will be promoted to 'int *'}}
+  (void)__builtin_va_arg(ap, const int[3]); // expected-warning {{second argument to 'va_arg' is of promotable type 'const int[3]'; this va_arg has undefined behavior because arguments will be promoted to 'const int *'}}
+
+  // _BitInts aren't promoted
+  (void)__builtin_va_arg(ap, _BitInt(7));
+  (void)__builtin_va_arg(ap, unsigned _BitInt(7));
+  (void)__builtin_va_arg(ap, _BitInt(32));
+  (void)__builtin_va_arg(ap, unsigned _BitInt(32));
+  (void)__builtin_va_arg(ap, _BitInt(33));
+  (void)__builtin_va_arg(ap, unsigned _BitInt(33));
 }
 
 #if __cplusplus >= 201103L
Index: clang/test/SemaCXX/format-strings-0x-nopedantic.cpp
===
--- clang/test/SemaCXX/format-strings-0x-nopedantic.cpp
+++ clang/test/SemaCXX/format-strings-0x-nopedantic.cpp
@@ -5,6 +5,7 @@
 extern int printf(const char *restrict, ...);
 }
 
-void f(char *c) {
+void f(char *c, int *q) {
   printf("%p", c);
+  printf("%p", q);
 }
Index: clang/test/Sema/varargs.c
===
--- clang/test/Sema/varargs.c
+++ clang/test/Sema/varargs.c
@@ -75,6 +75,14 @@
 (void)__builtin_va_arg(args, enum E); // Don't warn here in C
 (void)__builtin_va_arg(args, short); // expected-warning {{second argument to 'va_arg' is of promotable type 'short'}}
 (void)__builtin_va_arg(args, char); // expect

[PATCH] D156054: [Clang][Sema] DR722 (nullptr and varargs) and missing -Wvarargs diagnostics

2023-08-24 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok added inline comments.



Comment at: clang/test/SemaCXX/varargs.cpp:34
   enum Unscoped1 { One = 0x7FFF };
-  (void)__builtin_va_arg(ap, Unscoped1); // ok
+  (void)__builtin_va_arg(ap, Unscoped1); // expected-warning {{second argument 
to 'va_arg' is of promotable type 'Unscoped1'; this va_arg has undefined 
behavior because arguments will be promoted to 'int'}}
 

aaron.ballman wrote:
> MitalAshok wrote:
> > MitalAshok wrote:
> > > Unscoped1 is promoted to int when passed to a variadic function.
> > > 
> > > The underlying type for Unscoped1 is unsigned int, so only Unscoped1 and 
> > > unsigned int are compatible, not Unscoped1 and int. An Unscoped1 passed 
> > > to a variadic function must be retrieved via va_arg(ap, int).
> > > 
> > Although I guess the warning is now wrong because even though `void f(int 
> > x, ...) { std::va_list ap; va_start(ap, x); va_arg(ap, Unscoped1); }` `f(0, 
> > Unscoped1{2})` would be UB, `f(0, 2u)` would not be UB.
> > 
> > The user still should be warned about it, so I could create a new warning 
> > "second argument to 'va_arg' is of promotable enumeration type 'Unscoped1'; 
> > this va_arg may have undefined behavior because arguments of this 
> > enumeration type will be promoted to 'int', not the underlying type 
> > 'unsigned int'", and maybe suggest a fix `Unscoped1{va_arg(ap, unsigned)}`.
> > 
> > Or we could ignore it and pretend that int and enums with underlying types 
> > unsigned are compatible for the purposes of va_arg
> I think we shouldn't warn in this case because of C23 7.16.1.1p2:
> 
> >  If type is not compatible with the type of the actual next argument (as 
> > promoted according to
> > the default argument promotions), the behavior is undefined, except for the 
> > following cases:
> > ...
> > one type is compatible with a signed integer type, the other type is 
> > compatible with the
> > corresponding unsigned integer type, and the value is representable in both 
> > types;
> 
> Coupled with C23 6.7.2.2p13: 
> 
> > For all enumerations without a fixed underlying type, each enumerated type 
> > shall be compatible
> > with char or a signed or an unsigned integer type that is not bool or a 
> > bit-precise integer type. The
> > choice of type is implementation-defined., but shall be capable of 
> > representing the values of all
> > the members of the enumeration.
> 
> WDYT?
This seems to have changed very recently between [[ 
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf | N3096 ]] (April 
C23 draft) and [[ https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3149.zip | 
N3149 ]] (July C23 draft) by [[ 
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3112.pdf | N3112 ]].

For reference, the old wording (also in C17) read:

> one type is a signed integer type, the other type is the corresponding 
> unsigned integer type,
> and the value is representable in both types;

So with the current rules, yes they would be compatible and this shouldn't 
warn. I've changed it so it checks types with corresponding signedness.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156054

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


[PATCH] D156624: [clang-tidy] Access checks not done classes derived of std::array

2023-08-24 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo updated this revision to Diff 553062.

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

https://reviews.llvm.org/D156624

Files:
  
clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
===
--- clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/pro-bounds-constant-array-index.cpp
@@ -23,6 +23,9 @@
   return base + 3;
 }
 
+template
+class DerivedArray : public std::array {};
+
 void f(std::array a, int pos) {
   a [ pos / 2 /*comment*/] = 1;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
@@ -68,6 +71,81 @@
   m[const_index(6)] = 3; // OK, constant index and inside bounds
 }
 
+template
+class PrivateDerivedArray : std::array {
+public:
+  T& operator[](size_t n){
+return std::array::operator[](static_cast(n));
+  };
+  T& at(size_t n) {
+return std::array::at(static_cast(n));
+  };
+};
+
+void f_derived(DerivedArray a, int pos) {
+  a [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int j = a[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: do not use array subscript when the index is not an integer constant expression
+
+  a.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(a, pos-1) = 2; // OK, gsl::at() instead of []
+
+  a[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  a[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
+
+  a[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
+
+  a[0] = 3; // OK, constant index and inside bounds
+  a[1] = 3; // OK, constant index and inside bounds
+  a[9] = 3; // OK, constant index and inside bounds
+  a[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyArray = DerivedArray;
+  MyArray m{};
+  m [ pos / 2 /*comment*/] = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use array subscript when the index is not an integer constant expression [cppcoreguidelines-pro-bounds-constant-array-index]
+  int jj = m[pos - 1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: do not use array subscript when the index is not an integer constant expression
+
+  m.at(pos-1) = 2; // OK, at() instead of []
+  gsl::at(m, pos-1) = 2; // OK, gsl::at() instead of []
+  m[-1] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index -1 is negative [cppcoreguidelines-pro-bounds-constant-array-index]
+  m[10] = 4;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements) [cppcoreguidelines-pro-bounds-constant-array-index]
+
+  m[const_index(7)] = 3;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: std::array<> index 10 is past the end of the array (which contains 10 elements)
+
+  m[0] = 3; // OK, constant index and inside bounds
+  m[1] = 3; // OK, constant index and inside bounds
+  m[9] = 3; // OK, constant index and inside bounds
+  m[const_index(6)] = 3; // OK, constant index and inside bounds
+
+  using MyPrivateArray = PrivateDerivedArray;
+  MyPrivateArray pm{};
+  pm [ pos / 2 /*comment*/] = 1;
+  int jjj = pm[pos - 1];
+
+  pm.at(pos-1) = 2; // OK, at() instead of []
+  pm[-1] = 3;
+  pm[10] = 4;
+
+  pm[const_index(7)] = 3;
+
+  pm[0] = 3; // OK, constant index and inside bounds
+  pm[1] = 3; // OK, constant index and inside bounds
+  pm[9] = 3; // OK, constant index and inside bounds
+  pm[const_index(6)] = 3; // OK, constant index and inside bounds
+}
+
+
+
+
 void g() {
   int a[10];
   for (int i = 0; i < 10; ++i) {
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -196,6 +196,10 @@
   ` check
   to ignore predefined expression (e.g., ``__func__``, ...).
 
+- Improved :doc:`cppcoreguidelines-pro-bounds-constant-array-index
+  ` check
+  to perform checks on derived classes of  ``std::array``.
+
 - Improved :doc:`cppcoreguidelines-pro-type-member-init
   ` check to ignore
   dependent delegate constructors.
Index: c

[PATCH] D156624: [clang-tidy] Access checks not done classes derived of std::array

2023-08-24 Thread Jorge Pinto Sousa via Phabricator via cfe-commits
sousajo added a comment.

@PiotrZSL @carlosgalvezp can you please recheck?


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

https://reviews.llvm.org/D156624

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


[PATCH] D158641: [AArch64][Android][DRAFT] Fix FMV ifunc resolver usage on old Android APIs.

2023-08-24 Thread Pavel Iliin via Phabricator via cfe-commits
ilinpv added inline comments.



Comment at: compiler-rt/lib/builtins/cpu_model.c:1382
+return;
+#if defined(__ANDROID__)
+  // ifunc resolvers don't have hwcaps in arguments on Android API lower

MaskRay wrote:
> I am unfamiliar with how Android ndk builds compiler-rt.
> 
> If `__ANDROID_API__ >= 30`, shall we use the regular Linux code path?
I think that leads to shipping different compile-rt libraries depend on 
ANDROID_API. If this is an option to consider than runtime check 
android_get_device_api_level() < 30 can be replaced by `__ANDROID_API__ < 30`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158641

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


[PATCH] D156032: Implement CWG2137 (list-initialization from objects of the same type)

2023-08-24 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok updated this revision to Diff 553069.
MitalAshok added a comment.

rebased onto fast-forwarded main branch

(trying to fix seemingly unrelated CI build failure)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156032

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr21xx.cpp
  clang/test/CXX/drs/dr23xx.cpp
  clang/www/cxx_dr_status.html
  libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp

Index: libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp
===
--- libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp
+++ libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp
@@ -121,7 +121,26 @@
 test_pair_rv();
 test_pair_rv();
 
-test_pair_rv();
+/* For ExplicitTypes::CopyOnly, two of the viable candidates for initializing from a non-const xvalue are:
+ *   pair(const pair&);  // (defaulted copy constructor)
+ *   template explicit pair(const pair&&); [U1 = ExplicitTypes::CopyOnly, U2 = int]
+ * This results in diverging behavior for test_convertible which uses copy-list-initialization
+ * Prior to CWG2137, this would have selected the first (non-explicit) ctor as explicit ctors would not be considered
+ * Afterwards, it should select the second since it is a better match, and then failed because it is explicit
+ *
+ * This may change with future defect reports, and some compilers only have partial support for CWG2137,
+ * so use std::is_convertible directly to avoid a copy-list-initialization
+ */
+{
+  using P1  = std::pair;
+  using P2  = std::pair;
+  using UP1 = std::pair&&;
+  using UP2 = std::pair&&;
+  static_assert(std::is_constructible::value, "");
+  static_assert(std::is_convertible::value, "");
+  static_assert(std::is_constructible::value, "");
+  static_assert(std::is_convertible::value, "");
+}
 test_pair_rv();
 test_pair_rv();
 
Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -12629,7 +12629,7 @@
 https://cplusplus.github.io/CWG/issues/2137.html";>2137
 CD4
 List-initialization from object of same type
-Unknown
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2138.html";>2138
@@ -13673,7 +13673,7 @@
 https://cplusplus.github.io/CWG/issues/2311.html";>2311
 open
 Missed case for guaranteed copy elision
-Not resolved
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2312.html";>2312
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -5,6 +5,16 @@
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
 
+namespace std {
+  __extension__ typedef __SIZE_TYPE__ size_t;
+
+  template struct initializer_list {
+const E *p; size_t n;
+initializer_list(const E *p, size_t n);
+initializer_list();
+  };
+}
+
 #if __cplusplus >= 201103L
 namespace dr2303 { // dr2303: 12
 template 
@@ -37,6 +47,80 @@
 } //namespace dr2303
 #endif
 
+namespace dr2311 {  // dr2311: 18 open
+#if __cplusplus >= 201707L
+template
+void test() {
+  // Ensure none of these expressions try to call a move constructor.
+  T a = T{T(0)};
+  T b{T(0)};
+  auto c{T(0)};
+  T d = {T(0)};
+  auto e = {T(0)};
+#if __cplusplus >= 202302L
+  auto f = auto{T(0)};
+#endif
+  void(*fn)(T);
+  fn({T(0)});
+}
+
+struct NonMovable {
+  NonMovable(int);
+  NonMovable(NonMovable&&) = delete;
+};
+struct NonMovableNonApplicableIList {
+  NonMovableNonApplicableIList(int);
+  NonMovableNonApplicableIList(NonMovableNonApplicableIList&&) = delete;
+  NonMovableNonApplicableIList(std::initializer_list);
+};
+struct ExplicitMovable {
+  ExplicitMovable(int);
+  explicit ExplicitMovable(ExplicitMovable&&);
+};
+struct ExplicitNonMovable {
+  ExplicitNonMovable(int);
+  explicit ExplicitNonMovable(ExplicitNonMovable&&) = delete;
+};
+struct ExplicitNonMovableNonApplicableIList {
+  ExplicitNonMovableNonApplicableIList(int);
+  explicit ExplicitNonMovableNonApplicableIList(ExplicitNonMovableNonApplicableIList&&) = delete;
+  ExplicitNonMovableNonApplicableIList(std::initializer_list);
+};
+struct CopyOnly {
+  CopyOnly(int);
+  CopyOnly(const CopyOnly&);
+  CopyOnly(CopyOnly&&) = delete;
+};
+struct ExplicitCopyOnly {
+ 

[PATCH] D156032: Implement CWG2137 (list-initialization from objects of the same type)

2023-08-24 Thread Mital Ashok via Phabricator via cfe-commits
MitalAshok updated this revision to Diff 553070.
MitalAshok added a comment.

Remove accidental unrelated changelog


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D156032

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/drs/dr14xx.cpp
  clang/test/CXX/drs/dr21xx.cpp
  clang/test/CXX/drs/dr23xx.cpp
  clang/www/cxx_dr_status.html
  libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp

Index: libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp
===
--- libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp
+++ libcxx/test/std/utilities/utility/pairs/pairs.pair/ctor.pair_U_V_move.pass.cpp
@@ -121,7 +121,26 @@
 test_pair_rv();
 test_pair_rv();
 
-test_pair_rv();
+/* For ExplicitTypes::CopyOnly, two of the viable candidates for initializing from a non-const xvalue are:
+ *   pair(const pair&);  // (defaulted copy constructor)
+ *   template explicit pair(const pair&&); [U1 = ExplicitTypes::CopyOnly, U2 = int]
+ * This results in diverging behavior for test_convertible which uses copy-list-initialization
+ * Prior to CWG2137, this would have selected the first (non-explicit) ctor as explicit ctors would not be considered
+ * Afterwards, it should select the second since it is a better match, and then failed because it is explicit
+ *
+ * This may change with future defect reports, and some compilers only have partial support for CWG2137,
+ * so use std::is_convertible directly to avoid a copy-list-initialization
+ */
+{
+  using P1  = std::pair;
+  using P2  = std::pair;
+  using UP1 = std::pair&&;
+  using UP2 = std::pair&&;
+  static_assert(std::is_constructible::value, "");
+  static_assert(std::is_convertible::value, "");
+  static_assert(std::is_constructible::value, "");
+  static_assert(std::is_convertible::value, "");
+}
 test_pair_rv();
 test_pair_rv();
 
Index: clang/www/cxx_dr_status.html
===
--- clang/www/cxx_dr_status.html
+++ clang/www/cxx_dr_status.html
@@ -12629,7 +12629,7 @@
 https://cplusplus.github.io/CWG/issues/2137.html";>2137
 CD4
 List-initialization from object of same type
-Unknown
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2138.html";>2138
@@ -13673,7 +13673,7 @@
 https://cplusplus.github.io/CWG/issues/2311.html";>2311
 open
 Missed case for guaranteed copy elision
-Not resolved
+Clang 18
   
   
 https://cplusplus.github.io/CWG/issues/2312.html";>2312
Index: clang/test/CXX/drs/dr23xx.cpp
===
--- clang/test/CXX/drs/dr23xx.cpp
+++ clang/test/CXX/drs/dr23xx.cpp
@@ -5,6 +5,16 @@
 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors 2>&1 | FileCheck %s
 
+namespace std {
+  __extension__ typedef __SIZE_TYPE__ size_t;
+
+  template struct initializer_list {
+const E *p; size_t n;
+initializer_list(const E *p, size_t n);
+initializer_list();
+  };
+}
+
 #if __cplusplus >= 201103L
 namespace dr2303 { // dr2303: 12
 template 
@@ -37,6 +47,80 @@
 } //namespace dr2303
 #endif
 
+namespace dr2311 {  // dr2311: 18 open
+#if __cplusplus >= 201707L
+template
+void test() {
+  // Ensure none of these expressions try to call a move constructor.
+  T a = T{T(0)};
+  T b{T(0)};
+  auto c{T(0)};
+  T d = {T(0)};
+  auto e = {T(0)};
+#if __cplusplus >= 202302L
+  auto f = auto{T(0)};
+#endif
+  void(*fn)(T);
+  fn({T(0)});
+}
+
+struct NonMovable {
+  NonMovable(int);
+  NonMovable(NonMovable&&) = delete;
+};
+struct NonMovableNonApplicableIList {
+  NonMovableNonApplicableIList(int);
+  NonMovableNonApplicableIList(NonMovableNonApplicableIList&&) = delete;
+  NonMovableNonApplicableIList(std::initializer_list);
+};
+struct ExplicitMovable {
+  ExplicitMovable(int);
+  explicit ExplicitMovable(ExplicitMovable&&);
+};
+struct ExplicitNonMovable {
+  ExplicitNonMovable(int);
+  explicit ExplicitNonMovable(ExplicitNonMovable&&) = delete;
+};
+struct ExplicitNonMovableNonApplicableIList {
+  ExplicitNonMovableNonApplicableIList(int);
+  explicit ExplicitNonMovableNonApplicableIList(ExplicitNonMovableNonApplicableIList&&) = delete;
+  ExplicitNonMovableNonApplicableIList(std::initializer_list);
+};
+struct CopyOnly {
+  CopyOnly(int);
+  CopyOnly(const CopyOnly&);
+  CopyOnly(CopyOnly&&) = delete;
+};
+struct ExplicitCopyOnly {
+  ExplicitCopyOnly(int);
+  explicit ExplicitCopyOnly(con

[PATCH] D158695: [clang] Fix missing contract flag in sqrt intrinsic

2023-08-24 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/test/CodeGen/fp-contract-fast-pragma.cpp:11
 #pragma clang fp contract(fast)
-  return a * b + c;
+  return a * b + c + __builtin_sqrtf(a);
 }

Should leave the existing test function alone and add a new one. Also can you 
test some cases with nested different values


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

https://reviews.llvm.org/D158695

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


[PATCH] D158695: [clang] Fix missing contract flag in sqrt intrinsic

2023-08-24 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:501
   if (CGF.Builder.getIsFPConstrained()) {
 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());

rjmccall wrote:
> Is this existing condition not good enough, and why?
It's only in the strictfp branch for some reason, I don't think both would be 
needed



Comment at: clang/test/CodeGen/fp-contract-fast-pragma.cpp:2
 // RUN: %clang_cc1 -O3 -triple %itanium_abi_triple -emit-llvm -o - %s | 
FileCheck %s
 
 // Is FP_CONTRACT honored in a simple case?

Should also check constrained run line


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

https://reviews.llvm.org/D158695

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


[PATCH] D153114: [clangd] [C++20] [Modules] Support C++20 modules for clangd

2023-08-24 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Aside: I've been doing some investigation into how modules+clangd could work in 
our huge monorepo (specifically bazel + distributed build cluster).
It looks feasible (with some serious effort) to get all BMI/index/etc data we 
need for transitive modules to be generated by a copy of clangd running in the 
distributed build system itself, and likely this will perform better than 
anything involving building in-process.
So it seems plausible to add a coarse-grained extension point for this, and 
assume that the "find-and-build-modules" part we're adding now doesn't have to 
scale to that size. (We'd still like it to scale to projects the size of 
Chromium, which is roughly 10x LLVM and our usual proxy for "large local 
project"). I think we can make some simplifying assumptions even beyond 
experimental stage:

- the module graph will fit in memory
- the compilation database will fit in memory
- the set of files in the project is enumerable
- reading all the source files in the project is possible: takes minutes but 
not hours

In D153114#4612843 , @ChuanqiXu wrote:

> @sammccall here is a question (or double check) about the intended initial 
> version.
>
> This is the requirement for the initial version:
>
>> Don't attempt any cross-file or cross-version coordination: i.e. don't try 
>> to reuse BMIs between different files, don't try to reuse BMIs between 
>> (preamble) reparses of the same file, don't try to persist the module graph. 
>> Instead, when building a preamble, synchronously scan for the module graph, 
>> build the required PCMs on the single preamble thread with filenames private 
>> to that preamble, and then proceed to build the preamble.
>
> And all of us agree that it will be the job of the preamble to manage the 
> module files in the end of the day. I just want to ask or double check that 
> it might be OK to not related the module files with preamble in the initial 
> version, right?
>
> Since the definition (or description) of preamble is:
>
>> A preamble can be reused between multiple versions of the file until 
>> invalidated by a modification to a header, compile commands or modification 
>> to relevant part of the current file.
>
> And it looks like it beyonds the scope of the our requirement of the initial 
> patch.

On the one hand, if building modules in the AST works and is simpler, sure we 
can delay the "preamble optimization" for them.

But I don't really expect this is the case:

- as we've established, you can reach `import` statements inside the preamble 
region (`#include` a textual header that itself contains an `import`). So you 
need to build at least some of the required BMIs before building the preamble, 
doing it when parsing the main AST is not enough. (I believe the current 
version of the patch will just fail to parse some code in the preamble in this 
case).
- rebuilding BMIs with every preamble (not trying to reuse/cache/version them 
yet) will be pretty slow. But if we rebuild them every main-file reparse (i.e. 
every keystroke!) I think this is going to be intolerably slow to the point of 
not even being useful as a prototype.
- I only see two things that are really different between building during 
preamble vs building during AST, and neither are a lot of work:
  - invalidation: we need the preamble to be invalid if imports outside the 
preamble region have changed, or if the inputs of modules themselves have 
changed. But I think we can punt on all of this for now, and just not rebuild 
the preamble sometimes when we should. (Workaround: manually touch the preamble 
region after adding imports)
  - we need to attach the modules to PreambleData, rather than having them 
local to `ParsedAST::build`. But this really does not seem like much work at 
all - as we're not (yet) sharing modules through the filesystem, encapsulating 
the lifetime of a generated module in an object is something we should be doing 
right from the start anyway.
- given this, adding the code to ASTWorker and then moving it to PreambleWorker 
later seems like it doesn't save anything much over doing it right in the first 
place


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

https://reviews.llvm.org/D153114

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


[PATCH] D158558: [clang] - Add missing builtin name to AtomicExpr JSON dump

2023-08-24 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.

In D158558#4613139 , 
@serge-sans-paille wrote:

> I don't have a strong opinion on the synchronization with `TextNodeDumper`. 
> I'm pretty sure I didn't update it while adding fields for the Attribute 
> nodes though...

We usually try to keep them marginally in sync with one another (they're both 
intended debugging aids, so if you need the info in one form, it's plausible 
you'd need it in the other as well), but there's no hard requirement given that 
they're debugging aids.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158558

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


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/target_parallel_for_simd_tl_codegen.cpp:30
+// OMP51-NEXT:  entry:
+// OMP51-NEXT:[[DOTGLOBAL_TID__ADDR_I:%.*]] = alloca i32, align 4
+// OMP51-NEXT:[[DOTPART_ID__ADDR_I:%.*]] = alloca ptr, align 8

sandeepkosuri wrote:
> ABataev wrote:
> > Why removed these checks?
> I did not remove any check lines in this function.
> But I removed checks in `omp_task_entry` function that were not related to my 
> changes, to avoid failures. I only wanted to check whether 
> `__kmpc_set_thread_limit()` is called.
> 
> Same for all the other test cases.
Better to restore it to be able to use the script in future without many changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D153701: [Clang] Implement P2718R0 "Lifetime extension in range-based for loops"

2023-08-24 Thread Yurong via Phabricator via cfe-commits
yronglin added a comment.

ping~ @hubert.reinterpretcast @rsmith


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153701

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


[PATCH] D158671: [NFC][Clang] Fix static analyzer concerns

2023-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM with some nits




Comment at: clang/include/clang/ExtractAPI/ExtractAPIVisitor.h:195
 SymbolReference Context;
-auto Record = dyn_cast(Decl->getDeclContext());
+auto Record = cast(Decl->getDeclContext());
 Context.Name = Record->getName();

dang wrote:
> NIT: It's not immediately obvious that the check `if 
> (Decl->isStaticDataMember())` guarantees that `Decl->getDeclContext()` is a 
> `RecordDecl`. Would you mind adding a comment static that?




Comment at: clang/lib/ExtractAPI/DeclarationFragments.cpp:610-612
   if (isa(Method)) {
 Name = Method->getNameAsString();
+if (cast(Method)->isExplicit())

Fznamznon wrote:
> Maybe we can just do this, so we don't `isa` two times.
> 
+1 to this, `isa` followed by `cast` is a code smell.


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

https://reviews.llvm.org/D158671

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


[PATCH] D158363: [clang-format] Fix segmentation fault when formatting nested namespaces

2023-08-24 Thread Arkadiy Yudintsev via Phabricator via cfe-commits
d0nc1h0t updated this revision to Diff 553085.
d0nc1h0t added a comment.

Added missing const + clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158363

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4223,6 +4223,16 @@
"void foo() {}\n"
"} // namespace ns\n",
Style);
+
+  FormatStyle LLVMWithCompactInnerNamespace = getLLVMStyle();
+  LLVMWithCompactInnerNamespace.CompactNamespaces = true;
+  LLVMWithCompactInnerNamespace.NamespaceIndentation = FormatStyle::NI_Inner;
+  verifyFormat("namespace ns1 { namespace ns2 { namespace ns3 {\n"
+   "// block for debug mode\n"
+   "#ifndef NDEBUG\n"
+   "#endif\n"
+   "}}} // namespace ns1::ns2::ns3",
+   LLVMWithCompactInnerNamespace);
 }
 
 TEST_F(FormatTest, NamespaceMacros) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -386,11 +386,14 @@
   // Reduce indent level for bodies of namespaces which were compacted,
   // but only if their content was indented in the first place.
   auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
-  auto OutdentBy = I[J]->Level - TheLine->Level;
+  const int OutdentBy = I[J]->Level - TheLine->Level;
+  assert(OutdentBy >= 0);
   for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
++CompactedLine) {
-if (!(*CompactedLine)->InPPDirective)
-  (*CompactedLine)->Level -= OutdentBy;
+if (!(*CompactedLine)->InPPDirective) {
+  const int Level = (*CompactedLine)->Level;
+  (*CompactedLine)->Level = std::max(Level - OutdentBy, 0);
+}
   }
 }
 return J - 1;


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -4223,6 +4223,16 @@
"void foo() {}\n"
"} // namespace ns\n",
Style);
+
+  FormatStyle LLVMWithCompactInnerNamespace = getLLVMStyle();
+  LLVMWithCompactInnerNamespace.CompactNamespaces = true;
+  LLVMWithCompactInnerNamespace.NamespaceIndentation = FormatStyle::NI_Inner;
+  verifyFormat("namespace ns1 { namespace ns2 { namespace ns3 {\n"
+   "// block for debug mode\n"
+   "#ifndef NDEBUG\n"
+   "#endif\n"
+   "}}} // namespace ns1::ns2::ns3",
+   LLVMWithCompactInnerNamespace);
 }
 
 TEST_F(FormatTest, NamespaceMacros) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -386,11 +386,14 @@
   // Reduce indent level for bodies of namespaces which were compacted,
   // but only if their content was indented in the first place.
   auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
-  auto OutdentBy = I[J]->Level - TheLine->Level;
+  const int OutdentBy = I[J]->Level - TheLine->Level;
+  assert(OutdentBy >= 0);
   for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
++CompactedLine) {
-if (!(*CompactedLine)->InPPDirective)
-  (*CompactedLine)->Level -= OutdentBy;
+if (!(*CompactedLine)->InPPDirective) {
+  const int Level = (*CompactedLine)->Level;
+  (*CompactedLine)->Level = std::max(Level - OutdentBy, 0);
+}
   }
 }
 return J - 1;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158433: [Clang] Do not change the type of captured vars when checking lambda constraints

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158433

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


[PATCH] D158363: [clang-format] Fix segmentation fault when formatting nested namespaces

2023-08-24 Thread Arkadiy Yudintsev via Phabricator via cfe-commits
d0nc1h0t marked an inline comment as done.
d0nc1h0t added a comment.

Fixed. (Relied on auto-formatting in the IDE)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158363

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


[PATCH] D158526: [clang] Properly print unnamed members in diagnostics

2023-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM aside from a small nit




Comment at: clang/lib/AST/Decl.cpp:4567-4569
+  DeclarationName Name = getDeclName();
+  Name.print(OS, Policy);
+}

This way we're not reimplementing the same logic that `NamedDecl` does (in case 
we update that logic at some point in the future).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158526

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


[PATCH] D154784: [clang] Fix crash caused by PseudoObjectExprBitfields::NumSubExprs overflow

2023-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/AST/Stmt.h:596-597
 
-// These don't need to be particularly wide, because they're
-// strictly limited by the forms of expressions we permit.
-unsigned NumSubExprs : 8;
-unsigned ResultIndex : 32 - 8 - NumExprBits;
+unsigned NumSubExprs : 16;
+unsigned ResultIndex : 16;
   };

dblaikie wrote:
> aaron.ballman wrote:
> > yronglin wrote:
> > > yronglin wrote:
> > > > dblaikie wrote:
> > > > > yronglin wrote:
> > > > > > dblaikie wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > yronglin wrote:
> > > > > > > > > dblaikie wrote:
> > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > > > Could/should we add some error checking in the ctor 
> > > > > > > > > > > > > to assert that we don't overflow these longer 
> > > > > > > > > > > > > values/just hit the bug later on?
> > > > > > > > > > > > > 
> > > > > > > > > > > > > (& could we use `unsigned short` here rather than 
> > > > > > > > > > > > > bitfields?)
> > > > > > > > > > > > We've already got them packed in with other bit-fields 
> > > > > > > > > > > > from the expression bits, so I think it's reasonable to 
> > > > > > > > > > > > continue the pattern of using bit-fields (that way we 
> > > > > > > > > > > > don't accidentally end up with padding between the 
> > > > > > > > > > > > unnamed bits at the start and the named bits in this 
> > > > > > > > > > > > object).
> > > > > > > > > > > > 
> > > > > > > > > > > > I think adding some assertions would not be a bad idea 
> > > > > > > > > > > > as a follow-up.
> > > > > > > > > > > Maybe some unconditional (rather than only in asserts 
> > > > > > > > > > > builds) error handling? (report_fatal_error, if this is 
> > > > > > > > > > > low priority enough to not have an elegant failure mode, 
> > > > > > > > > > > but something where we don't just overflow and carry on 
> > > > > > > > > > > would be good... )
> > > > > > > > > > Ping on this? I worry this code has just punted the same 
> > > > > > > > > > bug further down, but not plugged the hole/ensured we don't 
> > > > > > > > > > overflow on novel/larger inputs.
> > > > > > > > > Sorry for the late reply, I was looking through the emails 
> > > > > > > > > and found this. I agree add some assertions to check the 
> > > > > > > > > value is a good idea, It's easy to help people catch bugs, at 
> > > > > > > > > least with when `-DLLVM_ENABLE_ASSERTIONS=ON`, and I'm glad 
> > > > > > > > > to work on it, but one thing that worries me is that, in 
> > > > > > > > > ASTReader, we access this field directly, not through the 
> > > > > > > > > constructor or accessor, and we have to add assertions 
> > > > > > > > > everywhere. 
> > > > > > > > > https://github.com/llvm/llvm-project/blob/05b4310c8aec7a050574277ced08a0ab86b27681/clang/lib/Serialization/ASTReaderStmt.cpp#L1382
> > > > > > > > I don't think we have to add too many assertions. As best I can 
> > > > > > > > tell, we'll need one in each of the `PseudoObjectExpr` 
> > > > > > > > constructors and one in 
> > > > > > > > `ASTStmtReader::VisitPseudoObjectExpr()`, but those are the 
> > > > > > > > only places we assign a value into the bit-field. Three 
> > > > > > > > assertions isn't a lot, but if we're worried, we could add a 
> > > > > > > > setter method that does the assertion and use the setter in all 
> > > > > > > > three places.
> > > > > > > My concern wasn't (well, wasn't entirely) about adding more 
> > > > > > > assertions - but about having a reliable error here. The patch 
> > > > > > > only makes the sizes larger, but doesn't have a hard-stop in case 
> > > > > > > those sizes are exceeded again (which, admittedly, is much harder 
> > > > > > > to do - maybe it's totally unreachable now, for all practical 
> > > > > > > purposes?) 
> > > > > > > 
> > > > > > > I suspect with more carefully constructed recursive inputs could 
> > > > > > > still reach the higher limit & I think it'd be good to fail hard 
> > > > > > > in that case in some way? (it's probably rare enough that a 
> > > > > > > report_fatal_error would be not-the-worst-thing-ever)
> > > > > > > 
> > > > > > > But good assertions would be nice too (the old code only failed 
> > > > > > > when you hit /exactly/ on just the overflow value, and any more 
> > > > > > > than that the wraparound would not crash/fail, but misbehave) - I 
> > > > > > > did add the necessary assertion to ArrayRef (begin <= end) which 
> > > > > > > would've helped detect this more reliably, but some assert 
> > > > > > > checking for overflow in the ctor would be good too (with all the 
> > > > > > > usual nuance/care in checking for overflow) - unless we're going 
> > > > > > > to make that into a fatal or other real error.
> > > > > > Sorry for the very late reply. I have no preference between 
> > > > > > assertion and 

[PATCH] D157572: [clang] Add `[[clang::library_extension]]` attribute

2023-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D157572#4612141 , @cjdb wrote:

> I don't dislike it, but I am a bit concerned about misuse being noisy.

So you're concerned that a library author uses `diagnose_if` to add a 
diagnostic to a warning group that makes the diagnostic seem too chatty, so the 
user disables the group and loses the compiler's diagnostics? Or are there 
other kinds of misuse you're worried about?

> As much as I hate suppressing diagnostics, I think there needs to be a way to 
> suppress the `diagnose_if` forms of warning without suppressing something 
> that the compiler would otherwise generate. Something like:
>
> - `-Wno-deprecated`: suppresses anything that `-Wdeprecated` would turn on.
> - `-Wno-deprecated=diagnose_if`: just the ones flagged by `diagnose_if`.
> - `-Wno-deprecated=non-diagnose_if`: complement to #2.
>
> (and similarly for `-Wno-error=`.)
>
> I'm not sure about the system header knob though: `[[deprecated]]` and 
> `[[nodiscard]]` still show up even when the declaration is in a system header?

Correct, those will still show up when the declaration is in a system header 
but not when the use is in a system header: https://godbolt.org/z/PjqKbGsrr

We currently have `-Wuser-defined-warnings` as the warning group for 
`diagnose_if` warning diagnostics, so I wonder if it would make sense to allow 
`-Wno-deprecated` suppresses anything that `-Wdeprecated` would turn on, while 
`-Wdeprecated -Wno-user-defined-warnings` would turn on only the 
compiler-generated deprecation warnings and not the diagnose_if-generated ones?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157572

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


[PATCH] D158730: [DebugMetadata][DwarfDebug] Don't retain local types with -fno-eliminate-unused-debug-types

2023-08-24 Thread Vladislav Dzhidzhoev via Phabricator via cfe-commits
dzhidzhoev created this revision.
dzhidzhoev added reviewers: aprantl, dblaikie, jdoerfert, dexonsmith, rnk, 
nickdesaulniers.
Herald added a subscriber: hiraditya.
Herald added a project: All.
dzhidzhoev requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Don't retain local types in DICompileUnit, only attach them to the
corresponding subprogram, as it is more clear.

It's supposed to be committed along with https://reviews.llvm.org/D144006.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158730

Files:
  clang/test/CodeGen/debug-info-unused-types.c
  clang/test/CodeGen/debug-info-unused-types.cpp
  llvm/lib/IR/DIBuilder.cpp


Index: llvm/lib/IR/DIBuilder.cpp
===
--- llvm/lib/IR/DIBuilder.cpp
+++ llvm/lib/IR/DIBuilder.cpp
@@ -625,7 +625,8 @@
   assert((isa(T) || (isa(T) &&
  cast(T)->isDefinition() == false)) 
&&
  "Expected type or subprogram declaration");
-  AllRetainTypes.emplace_back(T);
+  if (!isa_and_nonnull(T->getScope()))
+AllRetainTypes.emplace_back(T);
 }
 
 DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; }
Index: clang/test/CodeGen/debug-info-unused-types.cpp
===
--- clang/test/CodeGen/debug-info-unused-types.cpp
+++ clang/test/CodeGen/debug-info-unused-types.cpp
@@ -13,12 +13,14 @@
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "baz"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAZ"
-// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "z"
-// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
-// CHECK: [[RETTYPES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]], [[TYPE0]], 
{{![0-9]+}}, [[TYPE6:![0-9]+]], [[TYPE2]]}
-// CHECK: [[TYPE4]] = !DIDerivedType(tag: DW_TAG_typedef, name: "foo"
-// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: 
"bar"
-// CHECK: [[TYPE6]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: 
"y"
+// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], 
{{![0-9]+}}}
+// CHECK: [[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "foo"
+// CHECK: [[TYPE3]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: 
"bar"
+// CHECK: [[SP:![0-9]+]] = distinct !DISubprogram(name: "quux", {{.*}}, 
retainedNodes: [[SPRETNODES:![0-9]+]]
+// CHECK: [[SPRETNODES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]]}
+// CHECK: [[TYPE4]] = distinct !DICompositeType(tag: DW_TAG_class_type, name: 
"y", scope: [[SP]]
+// CHECK: [[TYPE5]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: 
"z", scope: [[SP]]
+// CHECK: [[TYPE6:![0-9]+]] = !DIEnumerator(name: "Z"
 
 // NODBG-NOT: !DI{{CompositeType|Enumerator|DerivedType}}
 
Index: clang/test/CodeGen/debug-info-unused-types.c
===
--- clang/test/CodeGen/debug-info-unused-types.c
+++ clang/test/CodeGen/debug-info-unused-types.c
@@ -18,13 +18,15 @@
 // CHECK: !DICompileUnit{{.+}}retainedTypes: [[RETTYPES:![0-9]+]]
 // CHECK: [[TYPE0:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "bar"
 // CHECK: [[TYPE1:![0-9]+]] = !DIEnumerator(name: "BAR"
-// CHECK: [[TYPE2:![0-9]+]] = !DICompositeType(tag: DW_TAG_enumeration_type, 
name: "z"
-// CHECK: [[TYPE3:![0-9]+]] = !DIEnumerator(name: "Z"
-// CHECK: [[RETTYPES]] = !{[[TYPE4:![0-9]+]], [[TYPE5:![0-9]+]], [[TYPE0]], 
[[TYPE6:![0-9]+]], {{![0-9]+}}, [[TYPE7:![0-9]+]], [[TYPE2]], [[TYPE8:![0-9]+]]}
-// CHECK: [[TYPE4]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
-// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
-// CHECK: [[TYPE6]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
-// CHECK: [[TYPE7]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "y"
+// CHECK: [[RETTYPES]] = !{[[TYPE2:![0-9]+]], [[TYPE3:![0-9]+]], [[TYPE0]], 
[[TYPE4:![0-9]+]], {{![0-9]+}}}
+// CHECK: [[TYPE2]] = !DIDerivedType(tag: DW_TAG_typedef, name: "my_int"
+// CHECK: [[TYPE3]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "foo"
+// CHECK: [[TYPE4]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"baz"
+// CHECK: [[SP:![0-9]+]] = distinct !DISubprogram(name: "quux", {{.*}}, 
retainedNodes: [[SPRETNODES:![0-9]+]]
+// CHECK: [[SPRETNODES]] = !{[[TYPE5:![0-9]+]], [[TYPE6:![0-9]+]], 
[[TYPE8:![0-9]+]]}
+// CHECK: [[TYPE5]] = distinct !DICompositeType(tag: DW_TAG_structure_type, 
name: "y"
+// CHECK: [[TYPE6]] = !DICompositeType(tag: DW_TAG_enumeration_type, name: "z"
+// CHECK: [[TYPE7:![0-9]+]] = !DIEnumerator(name: "Z"
 // CHECK: [[TYPE8]] = distinct !DICompositeType(tag: DW_TAG_union_type, name: 
"w"
 
 // Check that debug info is not emitted for the typedef, struct, enum, and

[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-24 Thread Sandeep via Phabricator via cfe-commits
sandeepkosuri marked an inline comment as done.
sandeepkosuri added inline comments.



Comment at: clang/test/OpenMP/target_parallel_for_simd_tl_codegen.cpp:30
+// OMP51-NEXT:  entry:
+// OMP51-NEXT:[[DOTGLOBAL_TID__ADDR_I:%.*]] = alloca i32, align 4
+// OMP51-NEXT:[[DOTPART_ID__ADDR_I:%.*]] = alloca ptr, align 8

ABataev wrote:
> sandeepkosuri wrote:
> > ABataev wrote:
> > > Why removed these checks?
> > I did not remove any check lines in this function.
> > But I removed checks in `omp_task_entry` function that were not related to 
> > my changes, to avoid failures. I only wanted to check whether 
> > `__kmpc_set_thread_limit()` is called.
> > 
> > Same for all the other test cases.
> Better to restore it to be able to use the script in future without many 
> changes
But a few check lines are failing on windows, while passing on debian.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D158223: [clang] Add clang::unnamed_addr attribute that marks globals' address as not significant

2023-08-24 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:1416-1417
+not significant. This allows global constants with the same contents to be
+merged. This can break global pointer identity, i.e. two different globals have
+the same address.
+

aeubanks wrote:
> rnk wrote:
> > erichkeane wrote:
> > > aeubanks wrote:
> > > > erichkeane wrote:
> > > > > aeubanks wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > aeubanks wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > aeubanks wrote:
> > > > > > > > > > aaron.ballman wrote:
> > > > > > > > > > > What happens for tentative definitions where the value 
> > > > > > > > > > > isn't known? e.g.,
> > > > > > > > > > > ```
> > > > > > > > > > > [[clang::unnamed_addr]] int i1, i2;
> > > > > > > > > > > ```
> > > > > > > > > > > 
> > > > > > > > > > > What happens if the types are similar but not the same?
> > > > > > > > > > > ```
> > > > > > > > > > > [[clang::unnamed_addr]] signed int i1 = 32;
> > > > > > > > > > > [[clang::unnamed_addr]] unsigned int i2 = 32;
> > > > > > > > > > > ```
> > > > > > > > > > > 
> > > > > > > > > > > Should we diagnose taking the address of such an 
> > > > > > > > > > > attributed variable so users have some hope of spotting 
> > > > > > > > > > > the non-conforming situations?
> > > > > > > > > > > 
> > > > > > > > > > > Does this attribute have impacts across translation unit 
> > > > > > > > > > > boundaries (perhaps only when doing LTO) or only within a 
> > > > > > > > > > > single TU?
> > > > > > > > > > > 
> > > > > > > > > > > What does this attribute do in C++ in the presence of 
> > > > > > > > > > > constructors and destructors? e.g.,
> > > > > > > > > > > ```
> > > > > > > > > > > struct S {
> > > > > > > > > > >   S();
> > > > > > > > > > >   ~S();
> > > > > > > > > > > };
> > > > > > > > > > > 
> > > > > > > > > > > [[clang::unnamed_addr]] S s1, s2; // Are these merged and 
> > > > > > > > > > > there's only one ctor/dtor call?
> > > > > > > > > > > ```
> > > > > > > > > > globals are only mergeable if they're known to be constant 
> > > > > > > > > > and have the same value/size. this can be done at compile 
> > > > > > > > > > time only if the optimizer can see the constant values, or 
> > > > > > > > > > at link time
> > > > > > > > > > 
> > > > > > > > > > so nothing would happen in any of the cases you've given.
> > > > > > > > > > 
> > > > > > > > > > but yeah that does imply that we should warn when the 
> > > > > > > > > > attribute is used on non const, non-POD globals. I'll 
> > > > > > > > > > update this patch to do that
> > > > > > > > > > 
> > > > > > > > > > as mentioned in the description, we actually do want to 
> > > > > > > > > > take the address of these globals for table-driven parsing, 
> > > > > > > > > > but we don't care about identity equality
> > > > > > > > > > globals are only mergeable if they're known to be constant 
> > > > > > > > > > and have the same value/size. this can be done at compile 
> > > > > > > > > > time only if the optimizer can see the constant values, or 
> > > > > > > > > > at link time
> > > > > > > > > >
> > > > > > > > > > so nothing would happen in any of the cases you've given.
> > > > > > > > > 
> > > > > > > > > A that's good to know. So I assume we *will* merge these?
> > > > > > > > > 
> > > > > > > > > ```
> > > > > > > > > struct S {
> > > > > > > > >   int i, j;
> > > > > > > > >   float f;
> > > > > > > > > };
> > > > > > > > > 
> > > > > > > > > [[clang::unnamed_addr]] const S s1 = { 1, 2, 3.0f };
> > > > > > > > > [[clang::unnamed_addr]] const S s2 = { 1, 2, 3.0f };
> > > > > > > > > [[clang::unnamed_addr]] const S s3 = s2;
> > > > > > > > > ```
> > > > > > > > > 
> > > > > > > > > > but yeah that does imply that we should warn when the 
> > > > > > > > > > attribute is used on non const, non-POD globals. I'll 
> > > > > > > > > > update this patch to do that
> > > > > > > > > 
> > > > > > > > > Thank you, I think that will be more user-friendly
> > > > > > > > > 
> > > > > > > > > > as mentioned in the description, we actually do want to 
> > > > > > > > > > take the address of these globals for table-driven parsing, 
> > > > > > > > > > but we don't care about identity equality
> > > > > > > > > 
> > > > > > > > > Yeah, I still wonder if we want to diagnose just the same -- 
> > > > > > > > > if the address is never taken, there's not really a way to 
> > > > > > > > > notice the optimization, but if the address is taken, you 
> > > > > > > > > basically get UB (and I think we should explicitly document 
> > > > > > > > > it as such). Given how easy it is to accidentally take the 
> > > > > > > > > address of something (like via a reference in C++), I think 
> > > > > > > > > we should warn by default, but still have a warning group for 
> > > > > > > > > folks who want to live life dangerously.
> > > > > > > > > > globals are only mergeable if they're known to be cons

[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-24 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: clang/test/OpenMP/target_parallel_for_simd_tl_codegen.cpp:30
+// OMP51-NEXT:  entry:
+// OMP51-NEXT:[[DOTGLOBAL_TID__ADDR_I:%.*]] = alloca i32, align 4
+// OMP51-NEXT:[[DOTPART_ID__ADDR_I:%.*]] = alloca ptr, align 8

sandeepkosuri wrote:
> ABataev wrote:
> > sandeepkosuri wrote:
> > > ABataev wrote:
> > > > Why removed these checks?
> > > I did not remove any check lines in this function.
> > > But I removed checks in `omp_task_entry` function that were not related 
> > > to my changes, to avoid failures. I only wanted to check whether 
> > > `__kmpc_set_thread_limit()` is called.
> > > 
> > > Same for all the other test cases.
> > Better to restore it to be able to use the script in future without many 
> > changes
> But a few check lines are failing on windows, while passing on debian.
It must be investigated, it is bad idea just to remove these checks. Most 
probably related to the order of the expressions emission.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

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


[PATCH] D158626: [AArch64] Add missing vrnd intrinsics

2023-08-24 Thread Max Iyengar via Phabricator via cfe-commits
miyengar updated this revision to Diff 553104.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158626

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/aarch64-v8.5a-neon-frint3264-intrinsic.c
  llvm/lib/Target/AArch64/AArch64InstrFormats.td
  llvm/test/CodeGen/AArch64/v8.5a-neon-frint3264-intrinsic.ll

Index: llvm/test/CodeGen/AArch64/v8.5a-neon-frint3264-intrinsic.ll
===
--- llvm/test/CodeGen/AArch64/v8.5a-neon-frint3264-intrinsic.ll
+++ llvm/test/CodeGen/AArch64/v8.5a-neon-frint3264-intrinsic.ll
@@ -81,3 +81,85 @@
   %val = tail call <4 x float> @llvm.aarch64.neon.frint64z.v4f32(<4 x float> %a)
   ret <4 x float> %val
 }
+
+declare <1 x double> @llvm.aarch64.neon.frint32x.v1f64(<1 x double>)
+declare <2 x double> @llvm.aarch64.neon.frint32x.v2f64(<2 x double>)
+declare <1 x double> @llvm.aarch64.neon.frint32z.v1f64(<1 x double>)
+declare <2 x double> @llvm.aarch64.neon.frint32z.v2f64(<2 x double>)
+
+define dso_local <1 x double> @t_vrnd32x_f64(<1 x double> %a) {
+; CHECK-LABEL: t_vrnd32x_f64:
+; CHECK: frint32x d0, d0
+; CHECK-NEXT:ret
+entry:
+  %val = tail call <1 x double> @llvm.aarch64.neon.frint32x.v1f64(<1 x double> %a)
+  ret <1 x double> %val
+}
+
+define dso_local <2 x double> @t_vrnd32xq_f64(<2 x double> %a) {
+; CHECK-LABEL: t_vrnd32xq_f64:
+; CHECK: frint32x v0.2d, v0.2d
+; CHECK-NEXT:ret
+entry:
+  %val = tail call <2 x double> @llvm.aarch64.neon.frint32x.v2f64(<2 x double> %a)
+  ret <2 x double> %val
+}
+
+define dso_local <1 x double> @t_vrnd32z_f64(<1 x double> %a) {
+; CHECK-LABEL: t_vrnd32z_f64:
+; CHECK: frint32z d0, d0
+; CHECK-NEXT:ret
+entry:
+  %val = tail call <1 x double> @llvm.aarch64.neon.frint32z.v1f64(<1 x double> %a)
+  ret <1 x double> %val
+}
+
+define dso_local <2 x double> @t_vrnd32zq_f64(<2 x double> %a) {
+; CHECK-LABEL: t_vrnd32zq_f64:
+; CHECK: frint32z v0.2d, v0.2d
+; CHECK-NEXT:ret
+entry:
+  %val = tail call <2 x double> @llvm.aarch64.neon.frint32z.v2f64(<2 x double> %a)
+  ret <2 x double> %val
+}
+
+declare <1 x double> @llvm.aarch64.neon.frint64x.v1f64(<1 x double>)
+declare <2 x double> @llvm.aarch64.neon.frint64x.v2f64(<2 x double>)
+declare <1 x double> @llvm.aarch64.neon.frint64z.v1f64(<1 x double>)
+declare <2 x double> @llvm.aarch64.neon.frint64z.v2f64(<2 x double>)
+
+define dso_local <1 x double> @t_vrnd64x_f64(<1 x double> %a) {
+; CHECK-LABEL: t_vrnd64x_f64:
+; CHECK: frint64x d0, d0
+; CHECK-NEXT:ret
+entry:
+  %val = tail call <1 x double> @llvm.aarch64.neon.frint64x.v1f64(<1 x double> %a)
+  ret <1 x double> %val
+}
+
+define dso_local <2 x double> @t_vrnd64xq_f64(<2 x double> %a) {
+; CHECK-LABEL: t_vrnd64xq_f64:
+; CHECK: frint64x v0.2d, v0.2d
+; CHECK-NEXT:ret
+entry:
+  %val = tail call <2 x double> @llvm.aarch64.neon.frint64x.v2f64(<2 x double> %a)
+  ret <2 x double> %val
+}
+
+define dso_local <1 x double> @t_vrnd64z_f64(<1 x double> %a) {
+; CHECK-LABEL: t_vrnd64z_f64:
+; CHECK: frint64z d0, d0
+; CHECK-NEXT:ret
+entry:
+  %val = tail call <1 x double> @llvm.aarch64.neon.frint64z.v1f64(<1 x double> %a)
+  ret <1 x double> %val
+}
+
+define dso_local <2 x double> @t_vrnd64zq_f64(<2 x double> %a) {
+; CHECK-LABEL: t_vrnd64zq_f64:
+; CHECK: frint64z v0.2d, v0.2d
+; CHECK-NEXT:ret
+entry:
+  %val = tail call <2 x double> @llvm.aarch64.neon.frint64z.v2f64(<2 x double> %a)
+  ret <2 x double> %val
+}
Index: llvm/lib/Target/AArch64/AArch64InstrFormats.td
===
--- llvm/lib/Target/AArch64/AArch64InstrFormats.td
+++ llvm/lib/Target/AArch64/AArch64InstrFormats.td
@@ -6292,24 +6292,27 @@
 : SIMDTwoVectorFP;
 
 // Supports only S and D element sizes
-let mayRaiseFPException = 1, Uses = [FPCR] in
-multiclass SIMDTwoVectorSD opc, string asm,
+multiclass SIMDTwoVectorSD {
-
-  def v2f32 : BaseSIMDTwoSameVector<0, U, 00, opc, 0b00, V64,
+  let mayRaiseFPException = 1, Uses = [FPCR] in {
+def v2f32 : BaseSIMDTwoSameVector<0, U, 00, {0b, opc}, 0b00, V64,
 asm, ".2s", ".2s",
   [(set (v2f32 V64:$Rd), (OpNode (v2f32 V64:$Rn)))]>;
-  def v4f32 : BaseSIMDTwoSameVector<1, U, 00, opc, 0b00, V128,
+def v4f32 : BaseSIMDTwoSameVector<1, U, 00, {0b, opc}, 0b00, V128,
 asm, ".4s", ".4s",
   [(set (v4f32 V128:$Rd), (OpNode (v4f32 V128:$Rn)))]>;
-  def v2f64 : BaseSIMDTwoSameVector<1, U, 01, opc, 0b00, V128,
+def v2f64 : BaseSIMDTwoSameVector<1, U, 01, {0b, opc}, 0b00, V128,
 asm, ".2d", ".2d",
   [(set (v2f64 V128:$Rd), (OpNode (v2f64 V128:$Rn)))]>;
+  }
+
+  def : Pat<(v1f64 (OpNode (v1f64 FPR64:$Rn))),
+   (!cas

[PATCH] D158626: [AArch64] Add missing vrnd intrinsics

2023-08-24 Thread Max Iyengar via Phabricator via cfe-commits
miyengar marked an inline comment as done.
miyengar added a comment.

Thank you for the feedback! I've added an amended patch using the pre-existing 
instruction. Also, I've tried to submit the patch with context this time.




Comment at: llvm/lib/Target/AArch64/AArch64InstrFormats.td:6297
   [(set (v2f64 V128:$Rd), (OpNode (v2f64 V128:$Rn)))]>;
+def f64 : BaseSingleOperandFPData<{0b0100, U, opc},
+FPR64, f64, asm, null_frag>;

dmgreen wrote:
> This looks like it is defining a new instruction. Does that already exist 
> somewhere? Probably from somewhere like FRIntNNT.
Ah thanks! I've amended this to use the already existing instruction 
(FRINT32ZDr) as defined in FRIntNNT


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158626

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


[clang] ff7d2fa - Update a broken link in documentation; NFC

2023-08-24 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2023-08-24T09:52:30-04:00
New Revision: ff7d2fabe074d95cefb683d4a742eec172bd36d5

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

LOG: Update a broken link in documentation; NFC

This links to the same information but in a new location.

Added: 


Modified: 
clang/include/clang/Basic/AttrDocs.td

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 5bda379df3a488..f19fe66bfedc1f 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -2777,7 +2777,7 @@ On x86 targets, this attribute changes the calling 
convention to
 as possible in registers. It also tries to utilize registers for the
 return value whenever it is possible.
 
-.. _`__regcall`: https://software.intel.com/en-us/node/693069
+.. _`__regcall`: 
https://www.intel.com/content/www/us/en/docs/dpcpp-cpp-compiler/developer-guide-reference/2023-2/c-c-sycl-calling-conventions.html
   }];
 }
 



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


[PATCH] D158733: [Clang] Fix a crash when an invalid immediate function call appears in a cast

2023-08-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Fixes #64949


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158733

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/cxx2a-consteval.cpp
  llvm/cmake/modules/HandleLLVMOptions.cmake


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -610,7 +610,7 @@
   # crash if LLVM is built with GCC and LTO enabled (#57740).  Until
   # these bugs are fixed, we need to disable dead store eliminations
   # based on object lifetime.
-  add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
+  # add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
 endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
 
 # Modules enablement for GCC-compatible compilers:
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1103,3 +1103,23 @@
 // expected-note {{read of 
non-const variable 'bad' is not allowed in a constant expression}}
 }
 }
+
+namespace GH64949 {
+struct f {
+  int g; // expected-note {{subobject declared here}}
+  constexpr ~f() {}
+};
+class h {
+
+public:
+  consteval h(char *) {}
+  consteval operator int() const { return 1; }
+  f i;
+};
+
+void k() { (int)h{nullptr}; }
+// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a 
constant expression}}
+// expected-note@-2 {{subobject 'g' is not initialized}}
+
+
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -18352,15 +18352,17 @@
 SemaRef.FailedImmediateInvocations.insert(CE);
 Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit();
 if (auto *FunctionalCast = dyn_cast(InnerExpr))
-  InnerExpr = FunctionalCast->getSubExpr();
+  InnerExpr = FunctionalCast->getSubExpr()->IgnoreImplicit();
 FunctionDecl *FD = nullptr;
 if (auto *Call = dyn_cast(InnerExpr))
   FD = cast(Call->getCalleeDecl());
 else if (auto *Call = dyn_cast(InnerExpr))
   FD = Call->getConstructor();
-else
-  llvm_unreachable("unhandled decl kind");
-assert(FD && FD->isImmediateFunction());
+else if (auto *Cast = dyn_cast(InnerExpr))
+  FD = dyn_cast_or_null(Cast->getConversionFunction());
+
+assert(FD && FD->isImmediateFunction &&
+   "could not find an immediate function in this expression");
 SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call)
 << FD << FD->isConsteval();
 if (auto Context =
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,6 +198,10 @@
 - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
   (`#64171 `_).
 
+- Fix a crash when an immediate invocation is not a constant expression
+  and appear in an implicit cast.
+  (`#64949 `_).
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.


Index: llvm/cmake/modules/HandleLLVMOptions.cmake
===
--- llvm/cmake/modules/HandleLLVMOptions.cmake
+++ llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -610,7 +610,7 @@
   # crash if LLVM is built with GCC and LTO enabled (#57740).  Until
   # these bugs are fixed, we need to disable dead store eliminations
   # based on object lifetime.
-  add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
+  # add_flag_if_supported("-fno-lifetime-dse" CMAKE_CXX_FLAGS)
 endif ( LLVM_COMPILER_IS_GCC_COMPATIBLE )
 
 # Modules enablement for GCC-compatible compilers:
Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1103,3 +1103,23 @@
 // expected-note {{read of non-const variable 'bad' is not allowed in a constant expression}}
 }
 }
+
+namespace GH64949 {
+struct f {
+  int g; // expected-note {{subobject declared here}}
+  constexpr ~f() {}
+};
+class h {
+
+public:
+  consteval h(char *) {}
+  consteval operator int() const { return 1; }
+  f i;
+};
+
+void k() { (int)h{nullptr}; }
+// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a constant expression}}
+// expected-note@-2 {{subob

[PATCH] D158733: [Clang] Fix a crash when an invalid immediate function call appears in a cast

2023-08-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 553109.
cor3ntin added a comment.

Remove accidentyally commited change


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158733

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


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1103,3 +1103,23 @@
 // expected-note {{read of 
non-const variable 'bad' is not allowed in a constant expression}}
 }
 }
+
+namespace GH64949 {
+struct f {
+  int g; // expected-note {{subobject declared here}}
+  constexpr ~f() {}
+};
+class h {
+
+public:
+  consteval h(char *) {}
+  consteval operator int() const { return 1; }
+  f i;
+};
+
+void k() { (int)h{nullptr}; }
+// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a 
constant expression}}
+// expected-note@-2 {{subobject 'g' is not initialized}}
+
+
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -18352,15 +18352,17 @@
 SemaRef.FailedImmediateInvocations.insert(CE);
 Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit();
 if (auto *FunctionalCast = dyn_cast(InnerExpr))
-  InnerExpr = FunctionalCast->getSubExpr();
+  InnerExpr = FunctionalCast->getSubExpr()->IgnoreImplicit();
 FunctionDecl *FD = nullptr;
 if (auto *Call = dyn_cast(InnerExpr))
   FD = cast(Call->getCalleeDecl());
 else if (auto *Call = dyn_cast(InnerExpr))
   FD = Call->getConstructor();
-else
-  llvm_unreachable("unhandled decl kind");
-assert(FD && FD->isImmediateFunction());
+else if (auto *Cast = dyn_cast(InnerExpr))
+  FD = dyn_cast_or_null(Cast->getConversionFunction());
+
+assert(FD && FD->isImmediateFunction &&
+   "could not find an immediate function in this expression");
 SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call)
 << FD << FD->isConsteval();
 if (auto Context =
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,6 +198,10 @@
 - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
   (`#64171 `_).
 
+- Fix a crash when an immediate invocation is not a constant expression
+  and appear in an implicit cast.
+  (`#64949 `_).
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.


Index: clang/test/SemaCXX/cxx2a-consteval.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval.cpp
+++ clang/test/SemaCXX/cxx2a-consteval.cpp
@@ -1103,3 +1103,23 @@
 // expected-note {{read of non-const variable 'bad' is not allowed in a constant expression}}
 }
 }
+
+namespace GH64949 {
+struct f {
+  int g; // expected-note {{subobject declared here}}
+  constexpr ~f() {}
+};
+class h {
+
+public:
+  consteval h(char *) {}
+  consteval operator int() const { return 1; }
+  f i;
+};
+
+void k() { (int)h{nullptr}; }
+// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a constant expression}}
+// expected-note@-2 {{subobject 'g' is not initialized}}
+
+
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -18352,15 +18352,17 @@
 SemaRef.FailedImmediateInvocations.insert(CE);
 Expr *InnerExpr = CE->getSubExpr()->IgnoreImplicit();
 if (auto *FunctionalCast = dyn_cast(InnerExpr))
-  InnerExpr = FunctionalCast->getSubExpr();
+  InnerExpr = FunctionalCast->getSubExpr()->IgnoreImplicit();
 FunctionDecl *FD = nullptr;
 if (auto *Call = dyn_cast(InnerExpr))
   FD = cast(Call->getCalleeDecl());
 else if (auto *Call = dyn_cast(InnerExpr))
   FD = Call->getConstructor();
-else
-  llvm_unreachable("unhandled decl kind");
-assert(FD && FD->isImmediateFunction());
+else if (auto *Cast = dyn_cast(InnerExpr))
+  FD = dyn_cast_or_null(Cast->getConversionFunction());
+
+assert(FD && FD->isImmediateFunction &&
+   "could not find an immediate function in this expression");
 SemaRef.Diag(CE->getBeginLoc(), diag::err_invalid_consteval_call)
 << FD << FD->isConsteval();
 if (auto Context =
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/Re

[PATCH] D140828: [C++] Implement "Deducing this" (P0847R7)

2023-08-24 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: clang/lib/Sema/SemaOverload.cpp:911-915
   if (X->getNumParams() != Y->getNumParams())
 return false;
   for (unsigned I = 0; I < X->getNumParams(); ++I)
 if (!Ctx.hasSameUnqualifiedType(X->getParamDecl(I)->getType(),
 Y->getParamDecl(I)->getType()))

cor3ntin wrote:
> aaron.ballman wrote:
> > Do we need changes here?
> Yes, although I need to figure out a test
We need changes.
Which changes is not obvious to me. 
https://lists.isocpp.org/core/2023/08/14711.php 



Comment at: clang/lib/Sema/SemaOverload.cpp:996-999
   // match than the non-reversed version.
   return FD->getNumParams() != 2 ||
  !S.Context.hasSameUnqualifiedType(FD->getParamDecl(0)->getType(),
FD->getParamDecl(1)->getType()) ||

cor3ntin wrote:
> aaron.ballman wrote:
> > Do we need changes here?
> Yes, although I need to figure out a test
UGH, phab ate my comment...
This does not need change.

if the operator has 2 non object parameters, it is implied that it is a 
non-member binary operator 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D140828

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


[PATCH] D157813: [VE][Clang] Change to enable VPU flag by default

2023-08-24 Thread Kazushi Marukawa via Phabricator via cfe-commits
kaz7 marked 3 inline comments as done.
kaz7 added a comment.

ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D157813

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


[clang] 158f4f3 - [Clang] Do not change the type of captured vars when checking lambda constraints

2023-08-24 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-24T16:10:08+02:00
New Revision: 158f4f30adb4bfd390057742a32934e4344e8fd3

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

LOG: [Clang] Do not change the type of captured vars when checking lambda 
constraints

When checking the constraint of a lambda, we need to respect the constness
of the call operator when establishing the type of capture variables.

In D124351, this was done by adding const to the captured variable...
However, that would change the type of the variable outside of the scope
of the lambda, which is clearly not the desired outcome.

Instead, to ensure const-correctness, we need to populate
a LambdaScopeInfo with the capture variables before checking the
constraints of a generic lambda.

There is no changelog as I'd like to tentatively propose we backport
this change to RC3 as it is a regression introduced in the Clang 17
cycle.

Fixes #61267

Reviewed By: aaron.ballman, #clang-language-wg

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index c992e8763057bd..807a52886ccb19 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7343,6 +7343,8 @@ class Sema final {
CXXConversionDecl *Conv,
Expr *Src);
 
+  sema::LambdaScopeInfo *RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator);
+
   /// Check whether the given expression is a valid constraint expression.
   /// A diagnostic is emitted if it is not, false is returned, and
   /// PossibleNonPrimary will be set to true if the failure might be due to a

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index f24b549dd2ef7a..fa3dadf68229ee 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -13,12 +13,14 @@
 #include "clang/Sema/SemaConcept.h"
 #include "TreeTransform.h"
 #include "clang/AST/ASTLambda.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/ExprConcepts.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/OperatorPrecedence.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Overload.h"
+#include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaDiagnostic.h"
 #include "clang/Sema/SemaInternal.h"
@@ -540,11 +542,6 @@ bool Sema::addInstantiatedCapturesToScope(
   auto AddSingleCapture = [&](const ValueDecl *CapturedPattern,
   unsigned Index) {
 ValueDecl *CapturedVar = LambdaClass->getCapture(Index)->getCapturedVar();
-if (cast(Function)->isConst()) {
-  QualType T = CapturedVar->getType();
-  T.addConst();
-  CapturedVar->setType(T);
-}
 if (CapturedVar->isInitCapture())
   Scope.InstantiatedLocal(CapturedPattern, CapturedVar);
   };
@@ -714,6 +711,22 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD,
 Record = const_cast(Method->getParent());
   }
   CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
+
+  // When checking the constraints of a lambda, we need to restore a
+  // LambdaScopeInfo populated with correct capture information so that the 
type
+  // of a variable referring to a capture is correctly const-adjusted.
+  FunctionScopeRAII FuncScope(*this);
+  if (isLambdaCallOperator(FD)) {
+LambdaScopeInfo *LSI = RebuildLambdaScopeInfo(
+const_cast(cast(FD)));
+// Constraints are checked from the parent context of the lambda, so we set
+// AfterParameterList to false, so that `tryCaptureVariable` finds
+// explicit captures in the appropriate context.
+LSI->AfterParameterList = false;
+  } else {
+FuncScope.disable();
+  }
+
   return CheckConstraintSatisfaction(
   FD, {FD->getTrailingRequiresClause()}, *MLTAL,
   SourceRange(UsageLoc.isValid() ? UsageLoc : FD->getLocation()),
@@ -902,10 +915,13 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints(
   }
   CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
   FunctionScopeRAII FuncScope(*this);
-  if (isLambdaCallOperator(Decl))
-PushLambdaScope();
-  else
+
+  if (isLambdaCallOperator(Decl)) {
+LambdaScopeInfo *LSI = RebuildLambdaScopeInfo(cast(Decl));
+LSI->AfterParameterList = false;
+  } else {
 FuncScope.disable();
+  }
 
   llvm::SmallVector Converted;
   return CheckConstraintSatisfaction(Template, TemplateAC, Conver

[PATCH] D158707: [analyzer] Fix a few size-type signedness inconsistency related to DynamicExtent

2023-08-24 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy added a comment.

Thanks for creating this commit, it's a useful improvement!

I added some inline comments on minor implementation details; moreover, note 
that "Releted checkers:" (instead of "related") is a typo in the commit message.

I also have a less concrete question about the root cause of these bugs. Does 
this commit fix the "root" of the issue by eliminating some misuse of correctly 
implemented (but perhaps surprising) `SVal` / `APSInt` arithmetic; or is there 
an underlying bug in the `SVal` / `APSInt` arithmetic which is just avoided 
(and not eliminated) by this commit? In the latter case, what obstacles prevent 
us from fixing the root cause?




Comment at: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp:202-203
   // CHECK UPPER BOUND
-  DefinedOrUnknownSVal Size = getDynamicExtent(state, Reg, svalBuilder);
+  SVal Size = svalBuilder.convertToArrayIndex(
+  getDynamicExtent(state, Reg, svalBuilder));
   if (auto KnownSize = Size.getAs()) {

I wonder whether it would be better to move this conversion into the definition 
of `getDynamicExtent` to ensure that it has a consistent return type. Are there 
any situations where it's useful that `getDynamicExtent` can return something 
that's not an `ArrayIndexTy`?



Comment at: clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp:180-183
+  SVal CountReached =
+  SVB.evalBinOp(State, BO_GE, Idx, Count, ASTCtx.BoolTy);
+  if (!CountReached.isUndef() &&
+  State->assume(*CountReached.getAs(), true))

I think checking the nullness of `getAs()` is more elegant than using a 
separate `isUndef()` check.

On a longer term / as a separate improvement, I'd also think about allowing 
`UndefinedVal` as the argument of the `assert()`-like functions, because the 
`evalBinOp` -> `assert` combination is very common in checkers and IIRC in most 
checkers the branch of `UndefinedVal` will produce the same result as 
`UnknownVal`.



Comment at: clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp:186-192
   const ElementRegion *const ER = RegionManager.getElementRegion(
-  CE.getArgExpr(1)->getType()->getPointeeType(), Idx, SuperRegion,
-  Ctx.getASTContext());
+  ElemType,
+  SVB.evalBinOp(State, BO_Add, Idx, MROffset, SVB.getArrayIndexType())
+  .castAs(),
+  SuperRegion, Ctx.getASTContext());
 
   ReqRegions.push_back(ER->getAs());

I'd use `getAs()` and a conditional to avoid crashes in the 
(theoretical) case that `evalBinOp` returns `UnknownVal`; and I suspect that 
`getAs()` is superfluous because `MemRegion` is a base class of 
`ElementRegion`.



Comment at: clang/lib/StaticAnalyzer/Core/DynamicExtent.cpp:92
+
+  return ElementCount.castAs();
+}

Are you sure that this cannot cause crashes? (E.g. did you check that there is 
no corner case when `getElementExtent` returns 0?)

I can accept this cast, especially if you have a clear proof that it's valid, 
but I'd prefer a more defensive solution that turns `UndefinedVal` into 
`UnknownVal` either here or preferably in the `assert()` function family that 
consumes the results from functions like this. 



Comment at: clang/test/Analysis/array-bound-v2-constraint-check.c:1
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,alpha.security.ArrayBoundV2,debug.ExprInspection \
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,unix,alpha.security.ArrayBoundV2,debug.ExprInspection \
 // RUN:   -analyzer-config eagerly-assume=false -verify %s

Perhaps only enable `unix.Malloc` to ensure that this test is not affected by 
changes to other checkers in the `unix` group. (It's enough for the testcase 
that you added.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158707

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


[PATCH] D158433: [Clang] Do not change the type of captured vars when checking lambda constraints

2023-08-24 Thread Corentin Jabot 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 rG158f4f30adb4: [Clang] Do not change the type of captured 
vars when checking lambda constraints (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158433

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaConcept.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/SemaCXX/lambda-capture-type-deduction.cpp

Index: clang/test/SemaCXX/lambda-capture-type-deduction.cpp
===
--- clang/test/SemaCXX/lambda-capture-type-deduction.cpp
+++ clang/test/SemaCXX/lambda-capture-type-deduction.cpp
@@ -246,3 +246,17 @@
 static_assert(is_same);
   };
 }
+
+namespace GH61267 {
+template  concept C = true;
+
+template
+void f(int) {
+  int i;
+  [i](P) {}(0);
+  i = 4;
+}
+
+void test() { f(0);  }
+
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -19722,13 +19722,6 @@
 FunctionScopesIndex == MaxFunctionScopesIndex && VarDC == DC)
   return true;
 
-// When evaluating some attributes (like enable_if) we might refer to a
-// function parameter appertaining to the same declaration as that
-// attribute.
-if (const auto *Parm = dyn_cast(Var);
-Parm && Parm->getDeclContext() == DC)
-  return true;
-
 // Only block literals, captured statements, and lambda expressions can
 // capture; other scopes don't work.
 DeclContext *ParentDC =
@@ -19756,6 +19749,14 @@
   CSI->getCapture(Var).markUsed(BuildAndDiagnose);
   break;
 }
+
+// When evaluating some attributes (like enable_if) we might refer to a
+// function parameter appertaining to the same declaration as that
+// attribute.
+if (const auto *Parm = dyn_cast(Var);
+Parm && Parm->getDeclContext() == DC)
+  return true;
+
 // If we are instantiating a generic lambda call operator body,
 // we do not want to capture new variables.  What was captured
 // during either a lambdas transformation or initial parsing
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -15289,11 +15289,10 @@
   FD->setInvalidDecl();
 }
 
-static void RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator,
-   Sema &S) {
-  CXXRecordDecl *const LambdaClass = CallOperator->getParent();
+LambdaScopeInfo *Sema::RebuildLambdaScopeInfo(CXXMethodDecl *CallOperator) {
+  CXXRecordDecl *LambdaClass = CallOperator->getParent();
 
-  LambdaScopeInfo *LSI = S.PushLambdaScope();
+  LambdaScopeInfo *LSI = PushLambdaScope();
   LSI->CallOperator = CallOperator;
   LSI->Lambda = LambdaClass;
   LSI->ReturnType = CallOperator->getReturnType();
@@ -15317,7 +15316,7 @@
 if (C.capturesVariable()) {
   ValueDecl *VD = C.getCapturedVar();
   if (VD->isInitCapture())
-S.CurrentInstantiationScope->InstantiatedLocal(VD, VD);
+CurrentInstantiationScope->InstantiatedLocal(VD, VD);
   const bool ByRef = C.getCaptureKind() == LCK_ByRef;
   LSI->addCapture(VD, /*IsBlock*/false, ByRef,
   /*RefersToEnclosingVariableOrCapture*/true, C.getLocation(),
@@ -15334,6 +15333,7 @@
 }
 ++I;
   }
+  return LSI;
 }
 
 Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D,
@@ -15437,7 +15437,7 @@
 assert(inTemplateInstantiation() &&
"There should be an active template instantiation on the stack "
"when instantiating a generic lambda!");
-RebuildLambdaScopeInfo(cast(D), *this);
+RebuildLambdaScopeInfo(cast(D));
   } else {
 // Enter a new function scope
 PushFunctionScope();
Index: clang/lib/Sema/SemaConcept.cpp
===
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -13,12 +13,14 @@
 #include "clang/Sema/SemaConcept.h"
 #include "TreeTransform.h"
 #include "clang/AST/ASTLambda.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/ExprConcepts.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/Basic/OperatorPrecedence.h"
 #include "clang/Sema/EnterExpressionEvaluationContext.h"
 #include "clang/Sema/Initialization.h"
 #include "clang/Sema/Overload.h"
+#include "clang/Sema/ScopeInfo.h"
 #include "clang/Sema/Sema.h"
 #include "clang/Sema/SemaDiagnostic.h"
 #include "clang/Sema/SemaInternal.h"
@@ -540,11 +542,6 @@
   auto AddSingleCapture = [&](const ValueDecl *CapturedPattern,
   unsigned Index) {
 ValueDecl *CapturedVar = LambdaClass->getCapture(Index)->getCapturedVar();
-if (cast(Function)->isCo

[clang] 3f98cdc - [Clang] Always constant-evaluate operands of comparisons to nullptr

2023-08-24 Thread Corentin Jabot via cfe-commits

Author: Corentin Jabot
Date: 2023-08-24T16:11:10+02:00
New Revision: 3f98cdc815bddd2b69e3298fa104c0305503292e

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

LOG: [Clang]  Always constant-evaluate operands of comparisons to nullptr

even if we know what the result is going to be.
There may be side effects we ought not to ignore,

Fixes #64923

Reviewed By: ChuanqiXu

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/AST/ExprConstant.cpp
clang/test/SemaCXX/compare-cxx2a.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42b4afa455e38a..0f6ad2e70c7d5f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -198,6 +198,11 @@ Bug Fixes to C++ Support
 - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
   (`#64171 `_).
 
+- Expressions producing ``nullptr`` are correctly evaluated
+  by the constant interpreter when appearing as the operand
+  of a binary comparision.
+  (`#64923 _``)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 9f4c758b81303c..51fdef708dde5a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -13310,6 +13310,10 @@ EvaluateComparisonBinaryOperator(EvalInfo &Info, const 
BinaryOperator *E,
 // C++11 [expr.rel]p4, [expr.eq]p3: If two operands of type std::nullptr_t
 // are compared, the result is true of the operator is <=, >= or ==, and
 // false otherwise.
+LValue Res;
+if (!EvaluatePointer(E->getLHS(), Res, Info) ||
+!EvaluatePointer(E->getRHS(), Res, Info))
+  return false;
 return Success(CmpResult::Equal, E);
   }
 

diff  --git a/clang/test/SemaCXX/compare-cxx2a.cpp 
b/clang/test/SemaCXX/compare-cxx2a.cpp
index 0cb48bcfcec27a..619e16aa745817 100644
--- a/clang/test/SemaCXX/compare-cxx2a.cpp
+++ b/clang/test/SemaCXX/compare-cxx2a.cpp
@@ -461,3 +461,21 @@ namespace PR52537 {
   template bool f6() { return 0 < y6; } // expected-note 
{{instantiation of}}
   void g6() { f6(); } // expected-note {{instantiation of}}
 }
+
+
+namespace GH64923 {
+using nullptr_t = decltype(nullptr);
+struct MyTask{};
+constexpr MyTask DoAnotherThing() {
+return {};
+}
+
+constexpr nullptr_t operator++(MyTask &&T); // expected-note 2{{declared here}}
+void DoSomething() {
+  if constexpr (++DoAnotherThing() != nullptr) {} // expected-error 
{{constexpr if condition is not a constant expression}} \
+  // expected-note  
{{undefined function 'operator++' cannot be used in a constant expression}}
+
+  if constexpr (nullptr == ++DoAnotherThing()) {} // expected-error 
{{constexpr if condition is not a constant expression}} \
+  // expected-note  
{{undefined function 'operator++' cannot be used in a constant expression}}
+}
+}



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


[PATCH] D158601: [Clang] Always constant-evaluate operands of comparisons to nullptr

2023-08-24 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3f98cdc815bd: [Clang]  Always constant-evaluate operands of 
comparisons to nullptr (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158601

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/SemaCXX/compare-cxx2a.cpp


Index: clang/test/SemaCXX/compare-cxx2a.cpp
===
--- clang/test/SemaCXX/compare-cxx2a.cpp
+++ clang/test/SemaCXX/compare-cxx2a.cpp
@@ -461,3 +461,21 @@
   template bool f6() { return 0 < y6; } // expected-note 
{{instantiation of}}
   void g6() { f6(); } // expected-note {{instantiation of}}
 }
+
+
+namespace GH64923 {
+using nullptr_t = decltype(nullptr);
+struct MyTask{};
+constexpr MyTask DoAnotherThing() {
+return {};
+}
+
+constexpr nullptr_t operator++(MyTask &&T); // expected-note 2{{declared here}}
+void DoSomething() {
+  if constexpr (++DoAnotherThing() != nullptr) {} // expected-error 
{{constexpr if condition is not a constant expression}} \
+  // expected-note  
{{undefined function 'operator++' cannot be used in a constant expression}}
+
+  if constexpr (nullptr == ++DoAnotherThing()) {} // expected-error 
{{constexpr if condition is not a constant expression}} \
+  // expected-note  
{{undefined function 'operator++' cannot be used in a constant expression}}
+}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13310,6 +13310,10 @@
 // C++11 [expr.rel]p4, [expr.eq]p3: If two operands of type std::nullptr_t
 // are compared, the result is true of the operator is <=, >= or ==, and
 // false otherwise.
+LValue Res;
+if (!EvaluatePointer(E->getLHS(), Res, Info) ||
+!EvaluatePointer(E->getRHS(), Res, Info))
+  return false;
 return Success(CmpResult::Equal, E);
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,6 +198,11 @@
 - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
   (`#64171 `_).
 
+- Expressions producing ``nullptr`` are correctly evaluated
+  by the constant interpreter when appearing as the operand
+  of a binary comparision.
+  (`#64923 _``)
+
 Bug Fixes to AST Handling
 ^
 - Fixed an import failure of recursive friend class template.


Index: clang/test/SemaCXX/compare-cxx2a.cpp
===
--- clang/test/SemaCXX/compare-cxx2a.cpp
+++ clang/test/SemaCXX/compare-cxx2a.cpp
@@ -461,3 +461,21 @@
   template bool f6() { return 0 < y6; } // expected-note {{instantiation of}}
   void g6() { f6(); } // expected-note {{instantiation of}}
 }
+
+
+namespace GH64923 {
+using nullptr_t = decltype(nullptr);
+struct MyTask{};
+constexpr MyTask DoAnotherThing() {
+return {};
+}
+
+constexpr nullptr_t operator++(MyTask &&T); // expected-note 2{{declared here}}
+void DoSomething() {
+  if constexpr (++DoAnotherThing() != nullptr) {} // expected-error {{constexpr if condition is not a constant expression}} \
+  // expected-note  {{undefined function 'operator++' cannot be used in a constant expression}}
+
+  if constexpr (nullptr == ++DoAnotherThing()) {} // expected-error {{constexpr if condition is not a constant expression}} \
+  // expected-note  {{undefined function 'operator++' cannot be used in a constant expression}}
+}
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -13310,6 +13310,10 @@
 // C++11 [expr.rel]p4, [expr.eq]p3: If two operands of type std::nullptr_t
 // are compared, the result is true of the operator is <=, >= or ==, and
 // false otherwise.
+LValue Res;
+if (!EvaluatePointer(E->getLHS(), Res, Info) ||
+!EvaluatePointer(E->getRHS(), Res, Info))
+  return false;
 return Success(CmpResult::Equal, E);
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -198,6 +198,11 @@
 - Update ``FunctionDeclBitfields.NumFunctionDeclBits``. This fixes:
   (`#64171 `_).
 
+- Expressions producing ``nullptr`` are correctly evaluated
+  by the constant interpreter wh

[PATCH] D158411: [clang] [MinGW] Pass LTO options to the linker

2023-08-24 Thread Mateusz Mikuła via Phabricator via cfe-commits
mati865 accepted this revision.
mati865 added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158411

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


[PATCH] D158694: [libc++] Re-enable the __std_module test

2023-08-24 Thread Louis Dionne via Phabricator via cfe-commits
ldionne updated this revision to Diff 553120.
ldionne added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Also touch a Clang file just to trigger their CI pipeline.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158694

Files:
  clang/foo
  libcxx/test/libcxx/clang_modules_include.gen.py


Index: libcxx/test/libcxx/clang_modules_include.gen.py
===
--- libcxx/test/libcxx/clang_modules_include.gen.py
+++ libcxx/test/libcxx/clang_modules_include.gen.py
@@ -44,11 +44,8 @@
 #include <{header}>
 """)
 
-# TODO: Remove the UNSUPPORTED{BLOCKLIT}: modules-build once issues with this 
test have been figured out.
 print(f"""\
 //--- __std_clang_module.compile.pass.mm
-// UNSUPPORTED{BLOCKLIT}: modules-build
-
 // RUN{BLOCKLIT}: %{{cxx}} %s %{{flags}} %{{compile_flags}} -fmodules 
-fcxx-modules -fmodules-cache-path=%t -fsyntax-only
 
 // REQUIRES{BLOCKLIT}: modules-build


Index: libcxx/test/libcxx/clang_modules_include.gen.py
===
--- libcxx/test/libcxx/clang_modules_include.gen.py
+++ libcxx/test/libcxx/clang_modules_include.gen.py
@@ -44,11 +44,8 @@
 #include <{header}>
 """)
 
-# TODO: Remove the UNSUPPORTED{BLOCKLIT}: modules-build once issues with this test have been figured out.
 print(f"""\
 //--- __std_clang_module.compile.pass.mm
-// UNSUPPORTED{BLOCKLIT}: modules-build
-
 // RUN{BLOCKLIT}: %{{cxx}} %s %{{flags}} %{{compile_flags}} -fmodules -fcxx-modules -fmodules-cache-path=%t -fsyntax-only
 
 // REQUIRES{BLOCKLIT}: modules-build
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151904: [clang-repl][CUDA] Add an unit test for interactive CUDA

2023-08-24 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

@argentite ping.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151904

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


[PATCH] D158140: WIP: [clang-repl] Basic WebAssembly support for running inside a JS engine

2023-08-24 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: clang/lib/Interpreter/WASM.cpp:79
+  int Result =
+  lld::wasm::link(LinkerArgs, llvm::outs(), llvm::errs(), false, false);
+  if (!Result)

sbc100 wrote:
> v.g.vassilev wrote:
> > sbc100 wrote:
> > > argentite wrote:
> > > > v.g.vassilev wrote:
> > > > > I am not sure how we can solve that dependency here. Worst case 
> > > > > scenario, could we check if `lld` is installed and make a system call?
> > > > AFAIK we can't really `exec()` within Emscripten.
> > > This looks its using the in-process call to the linker library, rather 
> > > then an exec of the linker process.. which could work.   But is it OK to 
> > > have the compiler depend on the linker like this?
> > Well, this is what we would like to avoid. Somehow. Initially, I thought we 
> > could move the relevant lld bits in the ORC infrastructure but maybe that’s 
> > not a good idea after all. Is there a suitable place where we could move 
> > that lld logic in LLVM?
> Perhaps you could wrap all of this in `if __EMSCRIPTEN__` or even something 
> like `if STATICALLY_LINKED_LLD` so it would only be available in your special 
> build of the compiler?
@argentite could we try @sbc100's proposal?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158140

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


[PATCH] D158591: Add support of Windows Trace Logging macros

2023-08-24 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added inline comments.



Comment at: clang/lib/Sema/Sema.cpp:1495-1499
+  DeclContext *DC = CurContext;
+  while (DC && !isa(DC) && !isa(DC) &&
+ !isa(DC) && !isa(DC))
+DC = DC->getParent();
+  return dyn_cast_or_null(DC);

RIscRIpt wrote:
> cor3ntin wrote:
> > RIscRIpt wrote:
> > > cor3ntin wrote:
> > > > I think this is reimplementing `getCurFunctionOrMethodDecl`
> > > > maybe we want to do 
> > > > 
> > > > ```
> > > > if(Decl* DC = getCurFunctionOrMethodDecl())
> > > > return DC;
> > > > return dyn_cast_or_null(CurrentContext);
> > > > ```
> > > > 
> > > > Or something like that
> > > Well, unfortunately, not really.
> > > 
> > > The previous implementation did call `getCurFunctionOrMethodDecl()`, but 
> > > it returned nullptr when we were inside a RecordDecl.
> > > If you examine the implementation of `getFunctionLevelDeclContext(bool 
> > > AllowLambda)`, it halts if `isa(DC)`. I tried patching 
> > > `getFunctionLevelDeclContext()` to skip RecordDecl, but this triggered 
> > > around 70 clang/tests. I didn't want to delve into understanding the 
> > > failure of each test. If you believe there's an issue with our current 
> > > code, I can allocate time to investigate each specific test case.
> > You are right, i missed that.
> > I wish we had a better name for this function but I can't think of anything
> A perfect name would be `getFunctionLevelDeclContext`, but it's taken. 
> Welp... I'll try to dig-into related functions, and update when I find 
> something. An alternative solution would be to parameterize (in some way) 
> `getFunctionLevelDeclContext` (e.g. add bool flags, or list of skippable 
> types, etc.).
> A perfect name would be getFunctionLevelDeclContext, but it's taken. 
No, it's not. I found a better one, which was hiding in a plain sight.

Regarding using a common implementation: with a new function name it's clear 
that we cannot do that - they serve different purposes. For example, this 
function may return `BlockDecl` or `CapturedDecl` (which is accepted by 
`PredefinedExpr::ComputeName`) whereas  `getFunctionLevelDeclContext` cannot.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158591

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


[PATCH] D158591: Add support of Windows Trace Logging macros

2023-08-24 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 553122.
RIscRIpt marked an inline comment as done.
RIscRIpt added a comment.

Rebase onto main, address review comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158591

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ms_predefined_expr.cpp

Index: clang/test/Sema/ms_predefined_expr.cpp
===
--- clang/test/Sema/ms_predefined_expr.cpp
+++ clang/test/Sema/ms_predefined_expr.cpp
@@ -168,3 +168,40 @@
 void test_char_injection(decltype(sizeof('"')), decltype(sizeof("()"))) {
   unused("" __FUNCSIG__); // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
 }
+
+void test_in_struct_init() {
+  struct {
+char F[sizeof(__FUNCTION__)];
+  } s1 = { __FUNCTION__ }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
+
+  struct {
+char F[sizeof("F:" __FUNCTION__)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  } s2 = { "F:" __FUNCTION__ }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+
+  class C {
+public:
+  struct {
+char F[sizeof(__FUNCTION__)];
+  } s;
+  } c1 = { { __FUNCTION__ } }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
+}
+
+void test_in_constexpr_struct_init() {
+  struct {
+char F[sizeof(__FUNCTION__)];
+  } constexpr s1 = { __FUNCTION__ }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
+  ASSERT_EQ(__FUNCTION__, s1.F);
+
+  struct {
+char F[sizeof("F:" __FUNCTION__)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  } constexpr s2 = { "F:" __FUNCTION__ }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  ASSERT_EQ("F:" __FUNCTION__, s2.F); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+
+  class C {
+public:
+  struct {
+char F[sizeof("F:" __FUNCTION__)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  } s;
+  } constexpr c1 = { { "F:" __FUNCTION__ } }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  ASSERT_EQ("F:" __FUNCTION__, c1.s.F); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -1984,7 +1984,7 @@
   // Note: Although function local macros are defined only inside functions,
   // we ensure a valid `CurrentDecl` even outside of a function. This allows
   // expansion of macros into empty string literals without additional checks.
-  Decl *CurrentDecl = getCurLocalScopeDecl();
+  Decl *CurrentDecl = cast_or_null(getPredefinedExprDeclContext());
   if (!CurrentDecl)
 CurrentDecl = Context.getTranslationUnitDecl();
 
@@ -3705,7 +3705,7 @@
 
 ExprResult Sema::BuildPredefinedExpr(SourceLocation Loc,
  PredefinedExpr::IdentKind IK) {
-  Decl *currentDecl = getCurLocalScopeDecl();
+  Decl *currentDecl = cast_or_null(getPredefinedExprDeclContext());
   if (!currentDecl) {
 Diag(Loc, diag::ext_predef_outside_function);
 currentDecl = Context.getTranslationUnitDecl();
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1491,16 +1491,12 @@
   return nullptr;
 }
 
-Decl *Sema::getCurLocalScopeDecl() {
-  if (const BlockScopeInfo *BSI = getCurBlock())
-return BSI->TheDecl;
-  if (const LambdaScopeInfo *LSI = getCurLambda())
-return LSI->CallOperator;
-  if (const CapturedRegionScopeInfo *CSI = getCurCapturedRegion())
-return CSI->TheCapturedDecl;
-  if (NamedDecl *ND = getCurFunctionOrMethodDecl())
-return ND;
-  return nullptr;
+DeclContext *Sema::getPredefinedExprDeclContext() {
+  DeclContext *DC = CurContext;
+  while (DC && !isa(DC) && !isa(DC) &&
+ !isa(DC) && !isa(DC))
+DC = DC->getParent();
+  return DC;
 }
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/Ex

[PATCH] D158641: [AArch64][Android][DRAFT] Fix FMV ifunc resolver usage on old Android APIs.

2023-08-24 Thread Elliott Hughes via Phabricator via cfe-commits
enh added inline comments.



Comment at: compiler-rt/lib/builtins/cpu_model.c:1382
+return;
+#if defined(__ANDROID__)
+  // ifunc resolvers don't have hwcaps in arguments on Android API lower

ilinpv wrote:
> MaskRay wrote:
> > I am unfamiliar with how Android ndk builds compiler-rt.
> > 
> > If `__ANDROID_API__ >= 30`, shall we use the regular Linux code path?
> I think that leads to shipping different compile-rt libraries depend on 
> ANDROID_API. If this is an option to consider than runtime check 
> android_get_device_api_level() < 30 can be replaced by `__ANDROID_API__ < 30`
depends what you mean... in 10 years or so, yes, no-one is likely to still care 
about the older API levels and we can just delete this. but until then, no, 
there's _one_ copy of compiler-rt that everyone uses, and although _OS 
developers_ don't need to support anything more than a couple of years old, 
most app developers are targeting far lower API levels than that (to maximize 
the number of possible customers).

TL;DR: "you could add that condition to the `#if`, but no-one would use it for 
a decade". (and i think the comment and `if` below should make it clear enough 
to future archeologists when this code block can be removed :-) )


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158641

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


[PATCH] D158666: [Clang] Fix linker error for function multiversioning

2023-08-24 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a comment.

A couple of observations with regard to compatibility:

gcc,, at least by default, emits the TC implementations as local functions, the 
resolver as a weak global function, and the undecorated name as an ifunc. When 
only a TC declaration (not a definition) is present, gcc still emits the 
resolver and ifunc, but a failure then occurs at line time since the 
implementation symbols referenced by the resolver function cannot be resolved 
to the local symbols emitted for a TU with the TC definitions. I can only guess 
that this is intentional; that inter-TU calls are intended to be dispatched via 
the ifunc+resolver and that TC use is therefore restricted to TUs that have 
definitions. Clang, at least by default, emits the TC implementations as global 
functions that can be resolved for direct reference by other TUs. This could be 
seen as potentially exposing implementation details (e.g., the author of the TC 
functions might reserve the right to change the list of targets without 
worrying about breaking usage by other TUs.

For TUs that only have a declaration of the function without TC, it will be 
necessary to recompile the TUs that define TC functions no matter what. This is 
because the calling TU (that has neither a declaration nor a definition of the 
function with TC applied) cannot know to dispatch to the ifunc+resolver and 
cannot provide a definition for the undecorated function name (not even an 
alias since it doesn't know to do so).


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

https://reviews.llvm.org/D158666

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


[PATCH] D158591: Add support of Windows Trace Logging macros

2023-08-24 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt updated this revision to Diff 553123.
RIscRIpt marked an inline comment as done.
RIscRIpt added a comment.

Use isa<...> in getPredefinedExprDeclContext


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158591

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/test/Sema/ms_predefined_expr.cpp

Index: clang/test/Sema/ms_predefined_expr.cpp
===
--- clang/test/Sema/ms_predefined_expr.cpp
+++ clang/test/Sema/ms_predefined_expr.cpp
@@ -168,3 +168,40 @@
 void test_char_injection(decltype(sizeof('"')), decltype(sizeof("()"))) {
   unused("" __FUNCSIG__); // expected-warning{{expansion of predefined identifier '__FUNCSIG__' to a string literal is a Microsoft extension}}
 }
+
+void test_in_struct_init() {
+  struct {
+char F[sizeof(__FUNCTION__)];
+  } s1 = { __FUNCTION__ }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
+
+  struct {
+char F[sizeof("F:" __FUNCTION__)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  } s2 = { "F:" __FUNCTION__ }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+
+  class C {
+public:
+  struct {
+char F[sizeof(__FUNCTION__)];
+  } s;
+  } c1 = { { __FUNCTION__ } }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
+}
+
+void test_in_constexpr_struct_init() {
+  struct {
+char F[sizeof(__FUNCTION__)];
+  } constexpr s1 = { __FUNCTION__ }; // expected-warning{{initializing an array from a '__FUNCTION__' predefined identifier is a Microsoft extension}}
+  ASSERT_EQ(__FUNCTION__, s1.F);
+
+  struct {
+char F[sizeof("F:" __FUNCTION__)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  } constexpr s2 = { "F:" __FUNCTION__ }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  ASSERT_EQ("F:" __FUNCTION__, s2.F); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+
+  class C {
+public:
+  struct {
+char F[sizeof("F:" __FUNCTION__)]; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  } s;
+  } constexpr c1 = { { "F:" __FUNCTION__ } }; // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+  ASSERT_EQ("F:" __FUNCTION__, c1.s.F); // expected-warning{{expansion of predefined identifier '__FUNCTION__' to a string literal is a Microsoft extension}}
+}
Index: clang/lib/Sema/SemaExpr.cpp
===
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -1984,7 +1984,7 @@
   // Note: Although function local macros are defined only inside functions,
   // we ensure a valid `CurrentDecl` even outside of a function. This allows
   // expansion of macros into empty string literals without additional checks.
-  Decl *CurrentDecl = getCurLocalScopeDecl();
+  Decl *CurrentDecl = cast_or_null(getPredefinedExprDeclContext());
   if (!CurrentDecl)
 CurrentDecl = Context.getTranslationUnitDecl();
 
@@ -3705,7 +3705,7 @@
 
 ExprResult Sema::BuildPredefinedExpr(SourceLocation Loc,
  PredefinedExpr::IdentKind IK) {
-  Decl *currentDecl = getCurLocalScopeDecl();
+  Decl *currentDecl = cast_or_null(getPredefinedExprDeclContext());
   if (!currentDecl) {
 Diag(Loc, diag::ext_predef_outside_function);
 currentDecl = Context.getTranslationUnitDecl();
Index: clang/lib/Sema/Sema.cpp
===
--- clang/lib/Sema/Sema.cpp
+++ clang/lib/Sema/Sema.cpp
@@ -1491,16 +1491,11 @@
   return nullptr;
 }
 
-Decl *Sema::getCurLocalScopeDecl() {
-  if (const BlockScopeInfo *BSI = getCurBlock())
-return BSI->TheDecl;
-  if (const LambdaScopeInfo *LSI = getCurLambda())
-return LSI->CallOperator;
-  if (const CapturedRegionScopeInfo *CSI = getCurCapturedRegion())
-return CSI->TheCapturedDecl;
-  if (NamedDecl *ND = getCurFunctionOrMethodDecl())
-return ND;
-  return nullptr;
+DeclContext *Sema::getPredefinedExprDeclContext() {
+  DeclContext *DC = CurContext;
+  while (DC && !isa(DC))
+DC = DC->getParent();
+  return DC;
 }
 
 LangAS Sema::getDefaultCXXMethodAddrSpace() const {
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConsta

[PATCH] D158591: Add support of Windows Trace Logging macros

2023-08-24 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added a comment.

I missed this comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158591

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


[PATCH] D158733: [Clang] Fix a crash when an invalid immediate function call appears in a cast

2023-08-24 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added a comment.
This revision is now accepted and ready to land.

1 nit that the build bots caught, else I'm happy.




Comment at: clang/lib/Sema/SemaExpr.cpp:18364
+
+assert(FD && FD->isImmediateFunction &&
+   "could not find an immediate function in this expression");




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158733

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


[PATCH] D158591: Add support of Windows Trace Logging macros

2023-08-24 Thread Richard Dzenis via Phabricator via cfe-commits
RIscRIpt added a comment.

The current implementation of `getPredefinedExprDeclContext` could be easily 
moved to a static function inside `clang/lib/Sema/SemaExpr.cpp` as it depends 
only on `Sema::CurContext` WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158591

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


[clang] f4c886b - [clang] Properly print unnamed members in diagnostics

2023-08-24 Thread via cfe-commits

Author: Podchishchaeva, Mariya
Date: 2023-08-24T07:24:29-07:00
New Revision: f4c886b6aaeac0a48f3bdeda3103887599373842

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

LOG: [clang] Properly print unnamed members in diagnostics

Use member's type when printing.
This also fixes a bug in warning diagnostic for out of order
initialization with designated initializers so it points to a valid
source location when an anonymous member is being initialized.

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

Reviewed By: aaron.ballman, shafik

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/Sema/SemaInit.cpp
clang/test/AST/ast-dump-APValue-anon-union.cpp
clang/test/CXX/special/class.dtor/p5-0x.cpp
clang/test/Sema/transparent-union.c
clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
clang/test/SemaObjCXX/arc-0x.mm

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 0f6ad2e70c7d5f..8d9f4a5b86b54c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -166,6 +166,9 @@ Bug Fixes in This Version
   The current solution may bring performance regressions if the awaiters have
   non-static data members. See
   `#64945 `_ for details.
+- Clang now prints unnamed members in diagnostic messages instead of giving an
+  empty ''. Fixes
+  (`#63759 `_)
 
 Bug Fixes to Compiler Builtins
 ^^

diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index f6e38e5c57440d..a4390052890fff 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3182,6 +3182,8 @@ class FieldDecl : public DeclaratorDecl, public 
Mergeable {
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classofKind(Kind K) { return K >= firstField && K <= lastField; }
+
+  void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
 };
 
 /// An instance of this object exists for each enum constant

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 7971a03153650c..60c80f2b075336 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4557,6 +4557,16 @@ void FieldDecl::setCapturedVLAType(const 
VariableArrayType *VLAType) {
   CapturedVLAType = VLAType;
 }
 
+void FieldDecl::printName(raw_ostream &OS, const PrintingPolicy &Policy) const 
{
+  // Print unnamed members using name of their type.
+  if (isAnonymousStructOrUnion()) {
+this->getType().print(OS, Policy);
+return;
+  }
+  // Otherwise, do the normal printing.
+  DeclaratorDecl::printName(OS, Policy);
+}
+
 
//===--===//
 // TagDecl Implementation
 
//===--===//

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index a21fdb771a4d66..d915d06ab2f1b8 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -2858,7 +2858,8 @@ InitListChecker::CheckDesignatedInitializer(const 
InitializedEntity &Entity,
 
   if (PrevField &&
   PrevField->getFieldIndex() > KnownField->getFieldIndex()) {
-SemaRef.Diag(DIE->getBeginLoc(), diag::ext_designated_init_reordered)
+SemaRef.Diag(DIE->getInit()->getBeginLoc(),
+ diag::ext_designated_init_reordered)
 << KnownField << PrevField << DIE->getSourceRange();
 
 unsigned OldIndex = StructuredIndex - 1;

diff  --git a/clang/test/AST/ast-dump-APValue-anon-union.cpp 
b/clang/test/AST/ast-dump-APValue-anon-union.cpp
index 1ed87e66561496..906bfe4857ed03 100644
--- a/clang/test/AST/ast-dump-APValue-anon-union.cpp
+++ b/clang/test/AST/ast-dump-APValue-anon-union.cpp
@@ -40,13 +40,13 @@ void Test() {
 
   constexpr U0 u0b{3.1415f};
   // CHECK:  | `-VarDecl {{.*}}  col:{{.*}} u0b 'const 
U0':'const U0' constexpr listinit
-  // CHECK-NEXT:  |   |-value: Union . Union .f Float 3.141500e+00
+  // CHECK-NEXT:  |   |-value: Union .U0::(anonymous union at {{.*}}) Union .f 
Float 3.141500e+00
 
   constexpr U1 u1a{};
   // CHECK:  | `-VarDecl {{.*}}  col:{{.*}} u1a 'const 
U1':'const U1' constexpr listinit
-  // CHECK-NEXT:  |   |-value: Union . Union .f Float 0.00e+00
+  // CHECK-NEXT:  |   |-value: Union .U1::(anonymous union at {{.*}}) Union .f 
Float 0.00e+00
 
   constexpr U1 u1b{3.1415f};
   // CHECK:`-VarDecl {{.*}}  col:{{.*}}

[PATCH] D158526: [clang] Properly print unnamed members in diagnostics

2023-08-24 Thread Mariya Podchishchaeva 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 rGf4c886b6aaea: [clang] Properly print unnamed members in 
diagnostics (authored by Fznamznon).

Changed prior to commit:
  https://reviews.llvm.org/D158526?vs=552410&id=553128#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158526

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/Decl.h
  clang/lib/AST/Decl.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/AST/ast-dump-APValue-anon-union.cpp
  clang/test/CXX/special/class.dtor/p5-0x.cpp
  clang/test/Sema/transparent-union.c
  clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
  clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
  clang/test/SemaObjCXX/arc-0x.mm

Index: clang/test/SemaObjCXX/arc-0x.mm
===
--- clang/test/SemaObjCXX/arc-0x.mm
+++ clang/test/SemaObjCXX/arc-0x.mm
@@ -161,7 +161,7 @@
 
   struct S1 {
 union {
-  union { // expected-note {{copy constructor of 'S1' is implicitly deleted because field '' has a deleted copy constructor}} expected-note {{copy assignment operator of 'S1' is implicitly deleted because field '' has a deleted copy assignment operator}} expected-note 4 {{'S1' is implicitly deleted because field '' has a deleted}}
+  union { // expected-note-re {{copy constructor of 'S1' is implicitly deleted because field 'test_union::S1::(anonymous union at {{.*}})' has a deleted copy constructor}} expected-note-re {{copy assignment operator of 'S1' is implicitly deleted because field 'test_union::S1::(anonymous union at {{.*}})' has a deleted copy assignment operator}} expected-note-re 4 {{'S1' is implicitly deleted because field 'test_union::S1::(anonymous union at {{.*}})' has a deleted}}
 id f0; // expected-note-re 2 .*}} of '(anonymous union at {{.*}}' is implicitly deleted because variant field 'f0' is an ObjC pointer}}
 char f1;
   };
@@ -172,7 +172,7 @@
   struct S2 {
 union {
   // FIXME: the note should say 'f0' is causing the special functions to be deleted.
-  struct { // expected-note 6 {{'S2' is implicitly deleted because variant field '' has a non-trivial}}
+  struct { // expected-note-re 6 {{'S2' is implicitly deleted because variant field 'test_union::S2::(anonymous struct at {{.*}})' has a non-trivial}}
 id f0;
 int f1;
   };
@@ -194,8 +194,8 @@
   };
 
   static union { // expected-error {{call to implicitly-deleted default constructor of}}
-union { // expected-note-re {{default constructor of '(unnamed union at {{.*}}' is implicitly deleted because field '' has a deleted default constructor}}
-  union { // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because field '' has a deleted default constructor}}
+union { // expected-note-re {{default constructor of '(unnamed union at {{.*}}' is implicitly deleted because field 'test_union::(anonymous union at {{.*}})' has a deleted default constructor}}
+  union { // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because field 'test_union::(anonymous union at {{.*}})' has a deleted default constructor}}
 __weak id g1; // expected-note-re {{default constructor of '(anonymous union at {{.*}}' is implicitly deleted because variant field 'g1' is an ObjC pointer}}
 int g2;
   };
Index: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
===
--- clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
+++ clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp
@@ -227,3 +227,23 @@
 .a = 1, // reorder-error {{field 'b' will be initialized after field 'a'}}
 };
 }
+
+namespace GH63759 {
+struct C {
+  int y = 1;
+  union {
+int a;
+short b;
+  };
+  int x = 1;
+};
+
+void foo() {
+  C c1 = {.x = 3, .a = 1}; // reorder-error-re {{ISO C++ requires field designators to be specified in declaration order; field 'x' will be initialized after field 'GH63759::C::(anonymous union at {{.*}})'}}
+   // reorder-note@-1 {{previous initialization for field 'x' is here}}
+
+  C c2 = {.a = 3, .y = 1}; // reorder-error-re {{ISO C++ requires field designators to be specified in declaration order; field 'GH63759::C::(anonymous union at {{.*}})' will be initialized after field 'y'}}
+   // reorder-note-re@-1 {{previous initialization for field 'GH63759::C::(anonymous union at {{.*}})' is here}}
+   //
+}
+}
Index: clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
===
--- clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
+++ clang/test/SemaCXX/cxx0x-nontrivial-union.cpp
@@ -136,7 +136,7 @@
 
   template struct Test

[PATCH] D158739: AIX: Issue an error when specifying an alias for a common symbol

2023-08-24 Thread Stephen Peckham via Phabricator via cfe-commits
stephenpeckham created this revision.
stephenpeckham added reviewers: hubert.reinterpretcast, DiggerLin, jhenderson.
Herald added subscribers: jeroen.dobbelaere, kbarton, hiraditya, nemanjai.
Herald added a project: All.
stephenpeckham requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

There is no support in XCOFF for labels on common symbols.  Therefore, an alias 
for a common symbol is not supported.  Issue an error in the front end when an 
aliasee is a common symbol.  Issue a similar error in the back end in case an 
IR specifies an alias for a common symbol.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158739

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGen/aix-common.c
  llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
  llvm/test/CodeGen/PowerPC/aix-common.ll

Index: llvm/test/CodeGen/PowerPC/aix-common.ll
===
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/aix-common.ll
@@ -0,0 +1,15 @@
+; RUN: not llc -filetype=obj -mtriple powerpc-ibm-aix-xcoff -o %t.o < %s 2>&1 | FileCheck %s
+; RUN: not llc -filetype=asm -mtriple powerpc-ibm-aix-xcoff -o %t.o < %s 2>&1 | FileCheck %s
+; RUN: not llc -filetype=obj -mtriple powerpc64-ibm-aix-xcoff -o %t.o < %s 2>&1 | FileCheck %s
+; RUN: not llc -filetype=asm -mtriple powerpc64-ibm-aix-xcoff -o %t.o < %s 2>&1 | FileCheck %s
+@x= common global i32 0, align 4
+
+@y= alias i32, ptr @x
+
+; Function Attrs: noinline nounwind optnone
+define ptr @g() #0 {
+entry:
+  ret ptr @y
+}
+; CHECK: LLVM ERROR: Aliases to common variables are not allowed on AIX:
+; CHECK:Alias attribute for y is invalid because x is common.
Index: llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
===
--- llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -2762,11 +2762,21 @@
 
   // Construct an aliasing list for each GlobalObject.
   for (const auto &Alias : M.aliases()) {
-const GlobalObject *Base = Alias.getAliaseeObject();
-if (!Base)
+const GlobalObject *Aliasee = Alias.getAliaseeObject();
+if (!Aliasee)
   report_fatal_error(
   "alias without a base object is not yet supported on AIX");
-GOAliasMap[Base].push_back(&Alias);
+
+if (Aliasee->hasCommonLinkage()) {
+  report_fatal_error("Aliases to common variables are not allowed on AIX:"
+ "\n\tAlias attribute for " +
+ Alias.getGlobalIdentifier() +
+ " is invalid because " + Aliasee->getName() +
+ " is common.",
+ false);
+}
+
+GOAliasMap[Aliasee].push_back(&Alias);
   }
 
   return Result;
Index: clang/test/CodeGen/aix-common.c
===
--- /dev/null
+++ clang/test/CodeGen/aix-common.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple powerpc-ibm-aix   -S -fcommon %s -verify -o -
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -S -fcommon %s -verify -o -
+int xx;
+extern int yy __attribute__((__alias__("xx") )); //expected-error {{alias to a variable in a common section is not allowed}}
+
+void *gg() { return &yy; }
+
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -563,8 +563,8 @@
 }
 
 static bool checkAliasedGlobal(
-DiagnosticsEngine &Diags, SourceLocation Location, bool IsIFunc,
-const llvm::GlobalValue *Alias, const llvm::GlobalValue *&GV,
+ASTContext &Context, DiagnosticsEngine &Diags, SourceLocation Location,
+bool IsIFunc, const llvm::GlobalValue *Alias, const llvm::GlobalValue *&GV,
 const llvm::MapVector &MangledDeclNames,
 SourceRange AliasRange) {
   GV = getAliasedGlobal(Alias);
@@ -573,6 +573,14 @@
 return false;
   }
 
+  if (GV->hasCommonLinkage()) {
+const llvm::Triple &Triple = Context.getTargetInfo().getTriple();
+if (Triple.getObjectFormat() == llvm::Triple::XCOFF) {
+  Diags.Report(Location, diag::err_alias_to_common);
+  return false;
+}
+  }
+
   if (GV->isDeclaration()) {
 Diags.Report(Location, diag::err_alias_to_undefined) << IsIFunc << IsIFunc;
 Diags.Report(Location, diag::note_alias_requires_mangled_name)
@@ -633,7 +641,7 @@
 StringRef MangledName = getMangledName(GD);
 llvm::GlobalValue *Alias = GetGlobalValue(MangledName);
 const llvm::GlobalValue *GV = nullptr;
-if (!checkAliasedGlobal(Diags, Location, IsIFunc, Alias, GV,
+if (!checkAliasedGlobal(getContext(), Diags, Location, IsIFunc, Alias, GV,
 MangledDeclNames, Range)) {
   Error = true;
   continue;
Index: clang/include/clang/Basic/D

[PATCH] D158666: [Clang] Fix linker error for function multiversioning

2023-08-24 Thread Tom Honermann via Phabricator via cfe-commits
tahonermann added a comment.

I think it would also be a good idea to exercise the test case for a target 
that lacks ifunc support to ensure that inter-TU calls work as expected.


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

https://reviews.llvm.org/D158666

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


[PATCH] D158707: [analyzer] Fix a few size-type signedness inconsistency related to DynamicExtent

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

Maybe its too early for the patch, but if a nonlocal change, like changing some 
Core functionality, we usually measure the real world implications and compare 
it against some baseline to get an idea how this affects the whole system. It 
also helps uncovering corner cases and crashes. Have you done some 
measurements? If not, @donat.Nagy might could help you out gathering some 
statistics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158707

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


[PATCH] D158707: [analyzer] Fix a few size-type signedness inconsistency related to DynamicExtent

2023-08-24 Thread Ding Fei via Phabricator via cfe-commits
danix800 added a comment.

In D158707#4613743 , @donat.nagy 
wrote:

> Thanks for creating this commit, it's a useful improvement!
>
> I added some inline comments on minor implementation details; moreover, note 
> that "Releted checkers:" (instead of "related") is a typo in the commit 
> message.
>
> I also have a less concrete question about the root cause of these bugs. Does 
> this commit fix the "root" of the issue by eliminating some misuse of 
> correctly implemented (but perhaps surprising) `SVal` / `APSInt` arithmetic; 
> or is there an underlying bug in the `SVal` / `APSInt` arithmetic which is 
> just avoided (and not eliminated) by this commit? In the latter case, what 
> obstacles prevent us from fixing the root cause?

For the observed signed compared to unsigned unexpectation from ArrayBoundV2,
the constraint manager does give the CORRECT result.

It's a misuse of the constraint API, mainly caused by unexpected unsigned extent
set by memory modeling. Actually `ArrayBoundV2::getSimplifiedOffsets()` has 
clear
comment that this `signed <-> unsigned` comparison is problematic.

  // TODO: once the constraint manager is smart enough to handle non simplified
  // symbolic expressions remove this function. Note that this can not be used 
in
  // the constraint manager as is, since this does not handle overflows. It is
  // safe to assume, however, that memory offsets will not overflow.
  // NOTE: callers of this function need to be aware of the effects of overflows
  // and signed<->unsigned conversions!
  static std::pair
  getSimplifiedOffsets(NonLoc offset, nonloc::ConcreteInt extent,
   SValBuilder &svalBuilder) {


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158707

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


[PATCH] D158733: [Clang] Fix a crash when an invalid immediate function call appears in a cast

2023-08-24 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/test/SemaCXX/cxx2a-consteval.cpp:1120
+
+void k() { (int)h{nullptr}; }
+// expected-error@-1 {{call to consteval function 'GH64949::h::h' is not a 
constant expression}}

Another variety maybe worthing adding a test for 

```
int k() { return h{nullptr}; }
``` 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158733

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


[PATCH] D158707: [analyzer] Fix a few size-type signedness inconsistency related to DynamicExtent

2023-08-24 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/ArrayBoundCheckerV2.cpp:202-203
   // CHECK UPPER BOUND
-  DefinedOrUnknownSVal Size = getDynamicExtent(state, Reg, svalBuilder);
+  SVal Size = svalBuilder.convertToArrayIndex(
+  getDynamicExtent(state, Reg, svalBuilder));
   if (auto KnownSize = Size.getAs()) {

donat.nagy wrote:
> I wonder whether it would be better to move this conversion into the 
> definition of `getDynamicExtent` to ensure that it has a consistent return 
> type. Are there any situations where it's useful that `getDynamicExtent` can 
> return something that's not an `ArrayIndexTy`?
Use consistent return type is necessary. The problem is which version should we 
choose.
I didn't touch this before I can get a clear selection.

At first I tended to think that all extent/count should be unsigned, but 
quickly dropped this idea
since `getDynamicExtentWithOffset` gives reasonable note that extent/offset 
(even count) can
be negative.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158707

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


[PATCH] D158707: [analyzer] Fix a few size-type signedness inconsistency related to DynamicExtent

2023-08-24 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/lib/StaticAnalyzer/Checkers/MPI-Checker/MPIChecker.cpp:180-183
+  SVal CountReached =
+  SVB.evalBinOp(State, BO_GE, Idx, Count, ASTCtx.BoolTy);
+  if (!CountReached.isUndef() &&
+  State->assume(*CountReached.getAs(), true))

donat.nagy wrote:
> I think checking the nullness of `getAs()` is more elegant than using a 
> separate `isUndef()` check.
> 
> On a longer term / as a separate improvement, I'd also think about allowing 
> `UndefinedVal` as the argument of the `assert()`-like functions, because the 
> `evalBinOp` -> `assert` combination is very common in checkers and IIRC in 
> most checkers the branch of `UndefinedVal` will produce the same result as 
> `UnknownVal`.
Thanks for the advice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158707

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


[PATCH] D158285: [NFC][CLANG] Fix wrong orders of function arguments positions

2023-08-24 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1468-1477
   std::optional getRangeForNegatedSymSym(const SymSymExpr *SSE) {
 return getRangeForNegatedExpr(
 [SSE, State = this->State]() -> SymbolRef {
   if (SSE->getOpcode() == BO_Sub)
 return State->getSymbolManager().getSymSymExpr(
-SSE->getRHS(), BO_Sub, SSE->getLHS(), SSE->getType());
+SSE->getLHS(), BO_Sub, SSE->getRHS(), SSE->getType());
   return nullptr;

tahonermann wrote:
> steakhal wrote:
> > Now this is within my realm.
> > This code applies the following transformation: `-(X - Y)  =>  (Y - X)` .
> > Consequently, this is intentional.
> Ideally, this change would have tripped up a test. Do we have tests that 
> attempt to verify source locations such that one could be added? I know 
> testing source locations is difficult and tedious.
> Ideally, this change would have tripped up a test.
I think it did. I had a quick look at the premerge test bot on buildkite, and 
there is a test failure likely related to this hunk. See 
clang/test/Analysis/ptr-arith.c
Check [[ 
https://buildkite.com/llvm-project/premerge-checks/builds/171979#018a0995-4c0b-4703-aef0-75e0a8def7c7
 | buildkite ]].



Comment at: clang/lib/StaticAnalyzer/Core/RangeConstraintManager.cpp:1529-1536
   // If ranges were not previously found,
   // try to find a reversed expression (y > x).
   if (!QueriedRangeSet) {
 const BinaryOperatorKind ROP =
 BinaryOperator::reverseComparisonOp(QueriedOP);
-SymSym = SymMgr.getSymSymExpr(RHS, ROP, LHS, T);
+SymSym = SymMgr.getSymSymExpr(LHS, ROP, RHS, T);
 QueriedRangeSet = getConstraint(State, SymSym);

steakhal wrote:
> If you have recommendations on improving the comments of the surrounding 
> context, let me know.
This breaks the test: clang/test/Analysis/constraint_manager_conditions.cpp
Check [[ 
https://buildkite.com/llvm-project/premerge-checks/builds/171979#018a0995-4c0b-4703-aef0-75e0a8def7c7
 | buildkite ]].


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158285

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


[PATCH] D117929: [XRay] Add support for RISCV

2023-08-24 Thread Ashwin Poduval via Phabricator via cfe-commits
ashwin98 updated this revision to Diff 553135.

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

https://reviews.llvm.org/D117929

Files:
  clang/lib/Driver/XRayArgs.cpp
  compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
  compiler-rt/lib/xray/CMakeLists.txt
  compiler-rt/lib/xray/xray_interface.cpp
  compiler-rt/lib/xray/xray_riscv.cpp
  compiler-rt/lib/xray/xray_trampoline_riscv32.S
  compiler-rt/lib/xray/xray_trampoline_riscv64.S
  compiler-rt/lib/xray/xray_tsc.h
  llvm/lib/CodeGen/XRayInstrumentation.cpp
  llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/xray-attribute-instrumentation.ll

Index: llvm/test/CodeGen/RISCV/xray-attribute-instrumentation.ll
===
--- /dev/null
+++ llvm/test/CodeGen/RISCV/xray-attribute-instrumentation.ll
@@ -0,0 +1,24 @@
+; RUN: llc -mtriple=riscv32-unknown-linux-gnu -mattr=+d -verify-machineinstrs < %s | FileCheck --check-prefix=CHECK %s
+; RUN: llc -mtriple=riscv64-unknown-linux-gnu -mattr=+d -verify-machineinstrs < %s | FileCheck --check-prefix=CHECK --check-prefix=CHECK-RISCV64 %s
+
+define i32 @foo() nounwind "function-instrument"="xray-always" {
+; CHECK: .p2align 2
+; CHECK-LABEL:   .Lxray_sled_0:
+; CHECK-NEXT:j .Ltmp0
+; CHECK-COUNT-14:nop
+; CHECK-RISCV64-COUNT-4: nop
+; CHECK-LABEL:   .Ltmp0:
+  ret i32 0
+; CHECK: .p2align 2
+; CHECK-LABEL:   .Lxray_sled_1:
+; CHECK-NEXT:j .Ltmp1
+; CHECK-COUNT-14:nop
+; CHECK-RISCV64-COUNT-4: nop
+; CHECK-LABEL:   .Ltmp1:
+; CHECK-NEXT:ret
+}
+; CHECK: .section xray_instr_map,"ao",@progbits,foo
+; CHECK-LABEL:   .Lxray_sleds_start0:
+; CHECK: .Lxray_sled_0-[[TMP:.Ltmp[0-9]+]]
+; CHECK: .Lxray_sled_1-[[TMP:.Ltmp[0-9]+]]
+; CHECK-LABEL:   .Lxray_sleds_end0:
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -160,6 +160,11 @@
 assert(i < RISCV::NUM_TARGET_REGS && "Register out of range");
 return UserReservedRegister[i];
   }
+  // Add XRay support - needs double precision floats at present and does not
+  // support compressed instructions
+  bool isXRaySupported() const override {
+return hasStdExtD() && !hasStdExtC();
+  }
 
   bool hasMacroFusion() const { return hasLUIADDIFusion(); }
 
Index: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
===
--- llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -16,6 +16,7 @@
 #include "MCTargetDesc/RISCVMCExpr.h"
 #include "MCTargetDesc/RISCVTargetStreamer.h"
 #include "RISCV.h"
+#include "RISCVSubtarget.h"
 #include "RISCVMachineFunctionInfo.h"
 #include "RISCVTargetMachine.h"
 #include "TargetInfo/RISCVTargetInfo.h"
@@ -84,6 +85,11 @@
   // Wrapper needed for tblgenned pseudo lowering.
   bool lowerOperand(const MachineOperand &MO, MCOperand &MCOp) const;
 
+  // XRay Support
+  void LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr *MI);
+  void LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr *MI);
+  void LowerPATCHABLE_TAIL_CALL(const MachineInstr *MI);
+
   void emitStartOfAsmFile(Module &M) override;
   void emitEndOfAsmFile(Module &M) override;
 
@@ -93,6 +99,8 @@
 
 private:
   void emitAttributes();
+  // XRay Support
+  void emitSled(const MachineInstr *MI, SledKind Kind);
 
   void emitNTLHint(const MachineInstr *MI);
 
@@ -167,6 +175,27 @@
   case RISCV::PseudoRVVInitUndefM4:
   case RISCV::PseudoRVVInitUndefM8:
 return;
+  case TargetOpcode::PATCHABLE_FUNCTION_ENTER: {
+// This switch case section is only for handling XRay sleds.
+//
+// patchable-function-entry is handled in lowerToMCInst
+// Therefore, we break out of the switch statement if we encounter it here.
+const Function &F = MI->getParent()->getParent()->getFunction();
+if (F.hasFnAttribute("patchable-function-entry")) {
+  break;
+}
+
+LowerPATCHABLE_FUNCTION_ENTER(MI);
+return;
+  }
+  case TargetOpcode::PATCHABLE_FUNCTION_EXIT: {
+LowerPATCHABLE_FUNCTION_EXIT(MI);
+return;
+  }
+  case TargetOpcode::PATCHABLE_TAIL_CALL: {
+LowerPATCHABLE_TAIL_CALL(MI);
+return;
+  }
   }
 
   MCInst OutInst;
@@ -282,11 +311,68 @@
   SetupMachineFunction(MF);
   emitFunctionBody();
 
+  // Emit the XRay table
+  emitXRayTable();
+
   if (!isSameAttribute())
 RTS.emitDirectiveOptionPop();
   return false;
 }
 
+void RISCVAsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr *MI) {
+  emitSled(MI, SledKind::FUNCTION_ENTER);
+}
+
+void RISCVAsmPrinter::LowerPATCHABLE_FUNCTION_EXIT(const MachineInstr *MI) {
+  emitSled(MI, SledKind::FUNCTION_EXIT);
+}
+
+void RISCVAsmPrinter::LowerPATCHABL

[PATCH] D117929: [XRay] Add support for RISCV

2023-08-24 Thread Ashwin Poduval via Phabricator via cfe-commits
ashwin98 added inline comments.



Comment at: compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake:83
 set(ALL_XRAY_SUPPORTED_ARCH ${X86_64} ${ARM32} ${ARM64} ${MIPS32} ${MIPS64}
-   powerpc64le ${HEXAGON} ${LOONGARCH64})
+   powerpc64le ${HEXAGON} ${LOONGARCH64} #[[${RISCV32}]] 
${RISCV64})
 endif()

MaskRay wrote:
> Just make RISCV32 available? Otherwise we wouldn't need `riscv32_SOURCES`
Done



Comment at: compiler-rt/lib/xray/xray_riscv.cpp:51
+encodeRTypeInstruction(uint32_t Opcode, uint32_t Rs1, uint32_t Rs2,
+   uint32_t Rd) XRAY_NEVER_INSTRUMENT {
+  return (Rs2 << 20 | Rs1 << 15 | Rd << 7 | Opcode);

MaskRay wrote:
> For new functions, consider dropping `XRAY_NEVER_INSTRUMENT`. The runtime 
> library cannot be instrumented with `-fxray-instrument` and I an unsure why 
> the original impl adds a lot of `XRAY_NEVER_INSTRUMENT`.
Done



Comment at: compiler-rt/lib/xray/xray_riscv.cpp:52
+   uint32_t Rd) XRAY_NEVER_INSTRUMENT {
+  return (Rs2 << 20 | Rs1 << 15 | Rd << 7 | Opcode);
+}

MaskRay wrote:
> 
Done



Comment at: compiler-rt/lib/xray/xray_riscv.cpp:286
+  const XRaySledEntry &Sled) XRAY_NEVER_INSTRUMENT {
+  // FIXME: Implement for riscv?
+  return false;

MaskRay wrote:
> Unimplemented features should use TODO instead of FIXME.
Done



Comment at: compiler-rt/lib/xray/xray_riscv.cpp:162
+uint32_t HighestTracingHookAddr =
+(reinterpret_cast(TracingHook + 0x800) >> 44) & 0xf;
+// We typecast the Tracing Hook to a 32 bit value for RISCV32

MaskRay wrote:
> ashwin98 wrote:
> > jrtc27 wrote:
> > > This is definitely wrong; you probably mean `(((TracingHook >> 32) + 
> > > 0x800) >> 12) & 0xf`?
> > True
> `(x + 0x800) >> 12` is used many times. We need a helper like 
> `lld/ELF/Arch/RISCV.cpp hi20`. Ditto for lo12.
Done. I think I'd frequently looked at the MIPS trampolines while writing this 
code - I noticed that they were casting the Tracing Hook to int64_t, instead of 
uint64_t (and int32/uint32 for the 32 bit ISA), which requires the & operation, 
since >> is an arithmetic shift operation for signed integers. Changing the 
cast operations to uint64_t should eliminate those & operations without 
breaking anything else, right?



Comment at: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp:322
 
+void RISCVAsmPrinter::LowerPATCHABLE_FUNCTION_ENTER(const MachineInstr *MI) {
+  emitSled(MI, SledKind::FUNCTION_ENTER);

MaskRay wrote:
> I have many comments in D140727 (LoongArch port). Many are probably useful 
> here as well.
I had a look at this. Two things which stuck out to me (both in xray_riscv.cpp):
- changing inline static to static inline (done)
- your note about the PO_ style hurting readability when instructions are only 
used once. In this case, we're using some instructions repeatedly, so I'm 
guessing it makes sense to continue with the enum, but I can get rid of it if 
that works better.


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

https://reviews.llvm.org/D117929

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


[clang] dbccf3c - [clang] - Add missing builtin name to AtomicExpr JSON dump

2023-08-24 Thread via cfe-commits

Author: serge-sans-paille
Date: 2023-08-24T17:09:49+02:00
New Revision: dbccf3c6f13d2afeecec77136460c5e359164eae

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

LOG: [clang] - Add missing builtin name to AtomicExpr JSON dump

As a side effect, introduce AtomicExpr::getOpAsString() to dump the
AtomicOp string representation.

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

Added: 
clang/test/AST/ast-dump-atomic-json.c

Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/AST/JSONNodeDumper.h
clang/lib/AST/JSONNodeDumper.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 6737721e1ed1b2..8d1235be78a4ad 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -6480,6 +6480,15 @@ class AtomicExpr : public Expr {
   QualType getValueType() const;
 
   AtomicOp getOp() const { return Op; }
+  StringRef getOpAsString() const {
+switch (Op) {
+#define BUILTIN(ID, TYPE, ATTRS)
+#define ATOMIC_BUILTIN(ID, TYPE, ATTRS)
\
+  case AO##ID: 
\
+return #ID;
+#include "clang/Basic/Builtins.def"
+}
+  }
   unsigned getNumSubExprs() const { return NumSubExprs; }
 
   Expr **getSubExprs() { return reinterpret_cast(SubExprs); }

diff  --git a/clang/include/clang/AST/JSONNodeDumper.h 
b/clang/include/clang/AST/JSONNodeDumper.h
index 0ce272df8df65b..4def5389137fa4 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -285,6 +285,7 @@ class JSONNodeDumper
   void VisitBinaryOperator(const BinaryOperator *BO);
   void VisitCompoundAssignOperator(const CompoundAssignOperator *CAO);
   void VisitMemberExpr(const MemberExpr *ME);
+  void VisitAtomicExpr(const AtomicExpr *AE);
   void VisitCXXNewExpr(const CXXNewExpr *NE);
   void VisitCXXDeleteExpr(const CXXDeleteExpr *DE);
   void VisitCXXThisExpr(const CXXThisExpr *TE);

diff  --git a/clang/lib/AST/JSONNodeDumper.cpp 
b/clang/lib/AST/JSONNodeDumper.cpp
index 139dfce41e914c..e67c2c7e216dce 100644
--- a/clang/lib/AST/JSONNodeDumper.cpp
+++ b/clang/lib/AST/JSONNodeDumper.cpp
@@ -1179,6 +1179,10 @@ void JSONNodeDumper::VisitBlockDecl(const BlockDecl *D) {
   attributeOnlyIfTrue("capturesThis", D->capturesCXXThis());
 }
 
+void JSONNodeDumper::VisitAtomicExpr(const AtomicExpr *AE) {
+  JOS.attribute("name", AE->getOpAsString());
+}
+
 void JSONNodeDumper::VisitObjCEncodeExpr(const ObjCEncodeExpr *OEE) {
   JOS.attribute("encodedType", createQualType(OEE->getEncodedType()));
 }

diff  --git a/clang/test/AST/ast-dump-atomic-json.c 
b/clang/test/AST/ast-dump-atomic-json.c
new file mode 100644
index 00..fd1de94ff94197
--- /dev/null
+++ b/clang/test/AST/ast-dump-atomic-json.c
@@ -0,0 +1,128 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-ast-dump=json %s | FileCheck %s
+
+int foo(int * ptr) {
+  return __atomic_load_n(ptr, __ATOMIC_SEQ_CST);
+}
+
+// NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
+// using --filters=AtomicExpr
+
+
+// CHECK-NOT: {{^}}Dumping
+// CHECK:  "kind": "AtomicExpr",
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": 132,
+// CHECK-NEXT:"col": 10,
+// CHECK-NEXT:"tokLen": 15
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": 169,
+// CHECK-NEXT:"col": 47,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "int"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "valueCategory": "prvalue",
+// CHECK-NEXT:  "name": "__atomic_load_n",
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "ImplicitCastExpr",
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "offset": 148,
+// CHECK-NEXT:  "col": 26,
+// CHECK-NEXT:  "tokLen": 3
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "offset": 148,
+// CHECK-NEXT:  "col": 26,
+// CHECK-NEXT:  "tokLen": 3
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "int *"
+// CHECK-NEXT:},
+// CHECK-NEXT:"valueCategory": "prvalue",
+// CHECK-NEXT:"castKind": "LValueToRValue",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "DeclRefExpr",
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": 148,
+// CHECK-NEXT:"col": 26,
+// CHECK-NEXT:"tokLen": 3
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"o

[PATCH] D158558: [clang] - Add missing builtin name to AtomicExpr JSON dump

2023-08-24 Thread serge 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 rGdbccf3c6f13d: [clang] - Add missing builtin name to 
AtomicExpr JSON dump (authored by serge-sans-paille).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158558

Files:
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/JSONNodeDumper.h
  clang/lib/AST/JSONNodeDumper.cpp
  clang/test/AST/ast-dump-atomic-json.c

Index: clang/test/AST/ast-dump-atomic-json.c
===
--- /dev/null
+++ clang/test/AST/ast-dump-atomic-json.c
@@ -0,0 +1,128 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value -ast-dump=json %s | FileCheck %s
+
+int foo(int * ptr) {
+  return __atomic_load_n(ptr, __ATOMIC_SEQ_CST);
+}
+
+// NOTE: CHECK lines have been autogenerated by gen_ast_dump_json_test.py
+// using --filters=AtomicExpr
+
+
+// CHECK-NOT: {{^}}Dumping
+// CHECK:  "kind": "AtomicExpr",
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": 132,
+// CHECK-NEXT:"col": 10,
+// CHECK-NEXT:"tokLen": 15
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": 169,
+// CHECK-NEXT:"col": 47,
+// CHECK-NEXT:"tokLen": 1
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "int"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "valueCategory": "prvalue",
+// CHECK-NEXT:  "name": "__atomic_load_n",
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "ImplicitCastExpr",
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "offset": 148,
+// CHECK-NEXT:  "col": 26,
+// CHECK-NEXT:  "tokLen": 3
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "offset": 148,
+// CHECK-NEXT:  "col": 26,
+// CHECK-NEXT:  "tokLen": 3
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "int *"
+// CHECK-NEXT:},
+// CHECK-NEXT:"valueCategory": "prvalue",
+// CHECK-NEXT:"castKind": "LValueToRValue",
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// CHECK-NEXT:  "id": "0x{{.*}}",
+// CHECK-NEXT:  "kind": "DeclRefExpr",
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"offset": 148,
+// CHECK-NEXT:"col": 26,
+// CHECK-NEXT:"tokLen": 3
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"offset": 148,
+// CHECK-NEXT:"col": 26,
+// CHECK-NEXT:"tokLen": 3
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "type": {
+// CHECK-NEXT:   "qualType": "int *"
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "valueCategory": "lvalue",
+// CHECK-NEXT:  "referencedDecl": {
+// CHECK-NEXT:   "id": "0x{{.*}}",
+// CHECK-NEXT:   "kind": "ParmVarDecl",
+// CHECK-NEXT:   "name": "ptr",
+// CHECK-NEXT:   "type": {
+// CHECK-NEXT:"qualType": "int *"
+// CHECK-NEXT:   }
+// CHECK-NEXT:  }
+// CHECK-NEXT: }
+// CHECK-NEXT:]
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "IntegerLiteral",
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "spellingLoc": {
+// CHECK-NEXT:   "offset": 417,
+// CHECK-NEXT:   "file": "",
+// CHECK-NEXT:   "line": 13,
+// CHECK-NEXT:   "presumedLine": 12,
+// CHECK-NEXT:   "col": 26,
+// CHECK-NEXT:   "tokLen": 1
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "expansionLoc": {
+// CHECK-NEXT:   "offset": 153,
+// CHECK-NEXT:   "file": "{{.*}}",
+// CHECK-NEXT:   "line": 4,
+// CHECK-NEXT:   "col": 31,
+// CHECK-NEXT:   "tokLen": 16
+// CHECK-NEXT:  }
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "spellingLoc": {
+// CHECK-NEXT:   "offset": 417,
+// CHECK-NEXT:   "file": "",
+// CHECK-NEXT:   "line": 13,
+// CHECK-NEXT:   "presumedLine": 12,
+// CHECK-NEXT:   "col": 26,
+// CHECK-NEXT:   "tokLen": 1
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "expansionLoc": {
+// CHECK-NEXT:   "offset": 153,
+// CHECK-NEXT:   "file": "{{.*}}",
+// CHECK-NEXT:   "line": 4,
+// CHECK-NEXT:   "col": 31,
+// CHECK-NEXT:   "tokLen": 16
+// CHECK-NEXT:  }
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "int"
+// CHECK-NEXT:},
+// CHECK-NEXT:"valueCategory": "prvalue",
+// CHECK-NEXT:"value": "5"
+// CHECK-NEXT:   }
+// CHECK-NEXT:  ]
+// CHECK-NEXT: }
Index: clang/lib/AST/JSONNodeDumper.cpp
===
--- clang/lib/AST/JSONNodeDumper.cpp
+++ clang/lib/AST/JSONNodeDumper.cpp
@@ -117

[PATCH] D158707: [analyzer] Fix a few size-type signedness inconsistency related to DynamicExtent

2023-08-24 Thread Ding Fei via Phabricator via cfe-commits
danix800 added inline comments.



Comment at: clang/test/Analysis/array-bound-v2-constraint-check.c:1
-// RUN: %clang_analyze_cc1 
-analyzer-checker=core,alpha.security.ArrayBoundV2,debug.ExprInspection \
+// RUN: %clang_analyze_cc1 
-analyzer-checker=core,unix,alpha.security.ArrayBoundV2,debug.ExprInspection \
 // RUN:   -analyzer-config eagerly-assume=false -verify %s

donat.nagy wrote:
> Perhaps only enable `unix.Malloc` to ensure that this test is not affected by 
> changes to other checkers in the `unix` group. (It's enough for the testcase 
> that you added.)
Correct! Thanks for reminding!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158707

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


[PATCH] D152054: [OpenMP] Codegen support for thread_limit on target directive

2023-08-24 Thread Sandeep via Phabricator via cfe-commits
sandeepkosuri updated this revision to Diff 553139.
sandeepkosuri added a comment.

Edited the LIT test cases to use more script generated check lines.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152054

Files:
  clang/include/clang/Basic/OpenMPKinds.h
  clang/lib/Basic/OpenMPKinds.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntime.h
  clang/lib/CodeGen/CGStmtOpenMP.cpp
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/target_codegen.cpp
  clang/test/OpenMP/target_parallel_for_simd_tl_codegen.cpp
  clang/test/OpenMP/target_parallel_for_tl_codegen.cpp
  clang/test/OpenMP/target_parallel_generic_loop_tl_codegen.cpp
  clang/test/OpenMP/target_parallel_tl_codegen.cpp
  clang/test/OpenMP/target_simd_tl_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMP.td
  llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
  openmp/runtime/src/kmp.h
  openmp/runtime/src/kmp_csupport.cpp
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_global.cpp
  openmp/runtime/src/kmp_runtime.cpp
  openmp/runtime/test/target/target_thread_limit.cpp

Index: openmp/runtime/test/target/target_thread_limit.cpp
===
--- /dev/null
+++ openmp/runtime/test/target/target_thread_limit.cpp
@@ -0,0 +1,168 @@
+// RUN: %libomp-cxx-compile -fopenmp-version=51
+// RUN: %libomp-run | FileCheck %s --check-prefix OMP51
+
+#include 
+#include 
+
+void foo() {
+#pragma omp parallel num_threads(10)
+  { printf("\ntarget: foo(): parallel num_threads(10)"); }
+}
+
+int main(void) {
+
+  int tl = 4;
+  printf("\nmain: thread_limit = %d", omp_get_thread_limit());
+  // OMP51: main: thread_limit = {{[0-9]+}}
+
+#pragma omp target thread_limit(tl)
+  {
+printf("\ntarget: thread_limit = %d", omp_get_thread_limit());
+// OMP51: target: thread_limit = 4
+// check whether thread_limit is honoured
+#pragma omp parallel
+{ printf("\ntarget: parallel"); }
+// OMP51: target: parallel
+// OMP51: target: parallel
+// OMP51: target: parallel
+// OMP51: target: parallel
+// OMP51-NOT: target: parallel
+
+// check whether num_threads is honoured
+#pragma omp parallel num_threads(2)
+{ printf("\ntarget: parallel num_threads(2)"); }
+// OMP51: target: parallel num_threads(2)
+// OMP51: target: parallel num_threads(2)
+// OMP51-NOT: target: parallel num_threads(2)
+
+// check whether thread_limit is honoured when there is a conflicting
+// num_threads
+#pragma omp parallel num_threads(10)
+{ printf("\ntarget: parallel num_threads(10)"); }
+// OMP51: target: parallel num_threads(10)
+// OMP51: target: parallel num_threads(10)
+// OMP51: target: parallel num_threads(10)
+// OMP51: target: parallel num_threads(10)
+// OMP51-NOT: target: parallel num_threads(10)
+
+// check whether threads are limited across functions
+foo();
+// OMP51: target: foo(): parallel num_threads(10)
+// OMP51: target: foo(): parallel num_threads(10)
+// OMP51: target: foo(): parallel num_threads(10)
+// OMP51: target: foo(): parallel num_threads(10)
+// OMP51-NOT: target: foo(): parallel num_threads(10)
+
+// check if user can set num_threads at runtime
+omp_set_num_threads(2);
+#pragma omp parallel
+{ printf("\ntarget: parallel with omp_set_num_thread(2)"); }
+// OMP51: target: parallel with omp_set_num_thread(2)
+// OMP51: target: parallel with omp_set_num_thread(2)
+// OMP51-NOT: target: parallel with omp_set_num_thread(2)
+
+// make sure thread_limit is unaffected by omp_set_num_threads
+printf("\ntarget: thread_limit = %d", omp_get_thread_limit());
+// OMP51: target: thread_limit = 4
+  }
+
+// checking consecutive target regions with different thread_limits
+#pragma omp target thread_limit(3)
+  {
+printf("\nsecond target: thread_limit = %d", omp_get_thread_limit());
+// OMP51: second target: thread_limit = 3
+#pragma omp parallel
+{ printf("\nsecond target: parallel"); }
+// OMP51: second target: parallel
+// OMP51: second target: parallel
+// OMP51: second target: parallel
+// OMP51-NOT: second target: parallel
+  }
+
+  // confirm that thread_limit's effects are limited to target region
+  printf("\nmain: thread_limit = %d", omp_get_thread_limit());
+  // OMP51: main: thread_limit = {{[0-9]+}}
+#pragma omp parallel num_threads(10)
+  { printf("\nmain: parallel num_threads(10)"); }
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51: main: parallel num_threads(10)
+  // OMP51-NOT: main: parallel num_threads(10)
+
+// check combined target dire

[PATCH] D158695: [clang] Fix missing contract flag in sqrt intrinsic

2023-08-24 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl marked 4 inline comments as done.
yaxunl added inline comments.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:501
   if (CGF.Builder.getIsFPConstrained()) {
 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());

arsenm wrote:
> rjmccall wrote:
> > Is this existing condition not good enough, and why?
> It's only in the strictfp branch for some reason, I don't think both would be 
> needed
It seems I just need to move the RAII out of that condition.



Comment at: clang/test/CodeGen/fp-contract-fast-pragma.cpp:2
 // RUN: %clang_cc1 -O3 -triple %itanium_abi_triple -emit-llvm -o - %s | 
FileCheck %s
 
 // Is FP_CONTRACT honored in a simple case?

arsenm wrote:
> Should also check constrained run line
will do



Comment at: clang/test/CodeGen/fp-contract-fast-pragma.cpp:11
 #pragma clang fp contract(fast)
-  return a * b + c;
+  return a * b + c + __builtin_sqrtf(a);
 }

arsenm wrote:
> Should leave the existing test function alone and add a new one. Also can you 
> test some cases with nested different values
pragma clang fp cannot be used inside compound statements. It is only allowed 
in either function scope or at the beginning of a compound statement. 
Essentially, it can only enable/disable contracting at a granularity of the 
function level. I can add a test for enabling/disabling it in different 
functions.


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

https://reviews.llvm.org/D158695

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


[PATCH] D158695: [clang] Fix missing contract flag in sqrt intrinsic

2023-08-24 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl updated this revision to Diff 553141.
yaxunl marked 3 inline comments as done.
yaxunl added a comment.

revised by comments


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

https://reviews.llvm.org/D158695

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/fp-contract-fast-pragma.cpp


Index: clang/test/CodeGen/fp-contract-fast-pragma.cpp
===
--- clang/test/CodeGen/fp-contract-fast-pragma.cpp
+++ clang/test/CodeGen/fp-contract-fast-pragma.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -O3 -triple %itanium_abi_triple -emit-llvm -o - %s | 
FileCheck %s
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -O3 \
+// RUN:   -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
 
 // Is FP_CONTRACT honored in a simple case?
 float fp_contract_1(float a, float b, float c) {
@@ -67,3 +69,18 @@
   // CHECK-NEXT: fadd float %[[M]], %c
   return a * b + c;
 }
+
+
+#pragma clang fp contract(fast)
+float fp_contract_7(float a) {
+// CHECK: _Z13fp_contract_7f
+// CHECK: tail call contract float @llvm.sqrt.f32(float %a)
+  return __builtin_sqrtf(a);
+}
+
+float fp_contract_8(float a) {
+// CHECK: _Z13fp_contract_8f
+// CHECK: tail call float @llvm.sqrt.f32(float %a)
+#pragma clang fp contract(off)
+  return __builtin_sqrtf(a);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -495,8 +495,8 @@
 unsigned ConstrainedIntrinsicID) {
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, 
Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0 });
   } else {


Index: clang/test/CodeGen/fp-contract-fast-pragma.cpp
===
--- clang/test/CodeGen/fp-contract-fast-pragma.cpp
+++ clang/test/CodeGen/fp-contract-fast-pragma.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -O3 -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-strict-floating-point -O3 \
+// RUN:   -triple %itanium_abi_triple -emit-llvm -o - %s | FileCheck %s
 
 // Is FP_CONTRACT honored in a simple case?
 float fp_contract_1(float a, float b, float c) {
@@ -67,3 +69,18 @@
   // CHECK-NEXT: fadd float %[[M]], %c
   return a * b + c;
 }
+
+
+#pragma clang fp contract(fast)
+float fp_contract_7(float a) {
+// CHECK: _Z13fp_contract_7f
+// CHECK: tail call contract float @llvm.sqrt.f32(float %a)
+  return __builtin_sqrtf(a);
+}
+
+float fp_contract_8(float a) {
+// CHECK: _Z13fp_contract_8f
+// CHECK: tail call float @llvm.sqrt.f32(float %a)
+#pragma clang fp contract(off)
+  return __builtin_sqrtf(a);
+}
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -495,8 +495,8 @@
 unsigned ConstrainedIntrinsicID) {
   llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
 
+  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   if (CGF.Builder.getIsFPConstrained()) {
-CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
 Function *F = CGF.CGM.getIntrinsic(ConstrainedIntrinsicID, Src0->getType());
 return CGF.Builder.CreateConstrainedFPCall(F, { Src0 });
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158140: WIP: [clang-repl] Basic WebAssembly support for running inside a JS engine

2023-08-24 Thread Anubhab Ghosh via Phabricator via cfe-commits
argentite added a comment.

Yes, I think that's the simplest solution. `__EMSCRIPTEN__` probably won't work 
because somebody may want to build for Emscripten without lld. 
`STATICALLY_LINKED_LLD` would probably be better. But I could not figure out 
how to do that in the build system.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158140

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


[PATCH] D158695: [clang] Fix missing contract flag in sqrt intrinsic

2023-08-24 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm added inline comments.



Comment at: clang/test/CodeGen/fp-contract-fast-pragma.cpp:77
+// CHECK: _Z13fp_contract_7f
+// CHECK: tail call contract float @llvm.sqrt.f32(float %a)
+  return __builtin_sqrtf(a);

This isn't demonstrating the strict support, probably need to add the pragma 
fenv_access for the -fexperimental-strict-floating-point  run line


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

https://reviews.llvm.org/D158695

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


[PATCH] D158707: [analyzer] Fix a few size-type signedness inconsistency related to DynamicExtent

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

As a general comment on requiring all extents to be of unsigned APSInts.
Checkers, like the `MallocChecker`, binds the result of arbitrary expression's 
values (the argument of malloc, for example) as extents of some regions.
Usually, that argument is of an `unsigned` static type, thus even if some other 
expression is there, and implicit cast will turn it into `unsigned`.
However, in CSA, we don't respect such casts, thus if it was signed, we will 
bind a signed value as an extent.

Here is an example  demonstrating this:

  int n = conjure();
  clang_analyzer_dump(n);  // conj
  clang_analyzer_value(n); // i32
  
  char *p = (char*)malloc(n);
  clang_analyzer_dump(clang_analyzer_getExtent(p));  // conj
  clang_analyzer_value(clang_analyzer_getExtent(p)); // i32

Consequently, I'm not sure it's possible to turn extents "unsigned", without 
fixing casts.
I was sort of expecting this, but I didn't know real world issues materialized 
by this in the domain of extents.
Usually, they just happen to work, so I didn't really bother with it.
This was actually what I intended to deliver with my comment at D158499#4609046 
.

By this comment I'm not suggesting that this is a lost cause, or we shouldn't 
move in this direction. I think something like this would make sense, but I'd 
need to delve into the change to make sure.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D158707

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


  1   2   3   >