[clang] [clang-format] Fix a bug in aligning trailing comments (PR #67221)

2023-09-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format


Changes

Fixes #67116.

---
Full diff: https://github.com/llvm/llvm-project/pull/67221.diff


2 Files Affected:

- (modified) clang/lib/Format/WhitespaceManager.cpp (+1-1) 
- (modified) clang/unittests/Format/FormatTestComments.cpp (+6) 


``diff
diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index b7bd8d27dc976b1..ccd60ac3b48c456 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1062,7 +1062,7 @@ void WhitespaceManager::alignTrailingComments() {
   auto OriginalSpaces =
   Changes[i].OriginalWhitespaceRange.getEnd().getRawEncoding() -
   Changes[i].OriginalWhitespaceRange.getBegin().getRawEncoding() -
-  Changes[i].Tok->NewlinesBefore;
+  Changes[i].Tok->LastNewlineOffset;
   unsigned RestoredLineLength = Changes[i].StartOfTokenColumn +
 Changes[i].TokenLength + OriginalSpaces;
   // If leaving comments makes the line exceed the column limit, give up to
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 001c5bf5fcda14e..1198329b7b5a8f0 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -3053,6 +3053,12 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) {
"}",
Style);
 
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
+  verifyNoChange("#define FOO\\\n"
+ "  /* foo(); */ \\\n"
+ "  bar();",
+ Style);
+
   // Allow to keep 2 empty lines
   Style.MaxEmptyLinesToKeep = 2;
   EXPECT_EQ("// do not touch\n"

``




https://github.com/llvm/llvm-project/pull/67221
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Fix a bug in aligning trailing comments (PR #67221)

2023-09-22 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/67221

Fixes #67116.

>From 9fa6ed9430896ee9164260227f0791986c750f0f Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 22 Sep 2023 23:47:23 -0700
Subject: [PATCH] [clang-format] Fix a bug in aligning trailing comments

Fixes #67116.
---
 clang/lib/Format/WhitespaceManager.cpp| 2 +-
 clang/unittests/Format/FormatTestComments.cpp | 6 ++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index b7bd8d27dc976b1..ccd60ac3b48c456 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1062,7 +1062,7 @@ void WhitespaceManager::alignTrailingComments() {
   auto OriginalSpaces =
   Changes[i].OriginalWhitespaceRange.getEnd().getRawEncoding() -
   Changes[i].OriginalWhitespaceRange.getBegin().getRawEncoding() -
-  Changes[i].Tok->NewlinesBefore;
+  Changes[i].Tok->LastNewlineOffset;
   unsigned RestoredLineLength = Changes[i].StartOfTokenColumn +
 Changes[i].TokenLength + OriginalSpaces;
   // If leaving comments makes the line exceed the column limit, give up to
diff --git a/clang/unittests/Format/FormatTestComments.cpp 
b/clang/unittests/Format/FormatTestComments.cpp
index 001c5bf5fcda14e..1198329b7b5a8f0 100644
--- a/clang/unittests/Format/FormatTestComments.cpp
+++ b/clang/unittests/Format/FormatTestComments.cpp
@@ -3053,6 +3053,12 @@ TEST_F(FormatTestComments, AlignTrailingCommentsLeave) {
"}",
Style);
 
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
+  verifyNoChange("#define FOO\\\n"
+ "  /* foo(); */ \\\n"
+ "  bar();",
+ Style);
+
   // Allow to keep 2 empty lines
   Style.MaxEmptyLinesToKeep = 2;
   EXPECT_EQ("// do not touch\n"

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


[libunwind] [libunwind] Pass -Wl,--export-dynamic on all supported platforms (PR #67205)

2023-09-22 Thread Fangrui Song via cfe-commits


@@ -10,8 +10,10 @@ link_flags = []
 if @LIBUNWIND_ENABLE_CET@:
 compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).

MaskRay wrote:

for non-ELF platforms.

AIX linker doesn't have this option.

https://github.com/llvm/llvm-project/pull/67205
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [libunwind] Pass -Wl,--export-dynamic on all supported platforms (PR #67205)

2023-09-22 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay edited 
https://github.com/llvm/llvm-project/pull/67205
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [libunwind] Pass -Wl,--export-dynamic on all supported platforms (PR #67205)

2023-09-22 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay approved this pull request.


https://github.com/llvm/llvm-project/pull/67205
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [libunwind] Pass -Wl,--export-dynamic on all supported platforms (PR #67205)

2023-09-22 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> the missing -Wl,--export dynamic flag

typo: missing `-`

https://github.com/llvm/llvm-project/pull/67205
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ORC] Implement basic reoptimization. (PR #67050)

2023-09-22 Thread via cfe-commits


@@ -0,0 +1,28 @@
+//=== RedirectionManager.cpp - Redirection manager interface in Orc 
---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ExecutionEngine/Orc/RedirectionManager.h"
+
+#define DEBUG_TYPE "orc"
+
+using namespace llvm;
+using namespace llvm::orc;
+
+void RedirectionManager::anchor() {}
+
+Error RedirectableSymbolManager::createRedirectableSymbols(
+ResourceTrackerSP RT, const SymbolMap &InitialDests) {
+  auto &JD = RT->getJITDylib();
+
+  if (auto Err = JD.define(std::make_unique(
+   *this, InitialDests),
+   RT))
+return Err;
+
+  return Error::success();

lhames wrote:

This could just be:
```c++
  return JD.define(std::make_unique(*this, 
InitialDests), RT);
```

https://github.com/llvm/llvm-project/pull/67050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ORC] Implement basic reoptimization. (PR #67050)

2023-09-22 Thread via cfe-commits


@@ -0,0 +1,179 @@
+//===-- JITLinkRedirectableSymbolManager.cpp - JITLink redirection in Orc 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+
+#define DEBUG_TYPE "orc"
+
+using namespace llvm;
+using namespace llvm::orc;
+
+void JITLinkRedirectableSymbolManager::emitRedirectableSymbols(
+std::unique_ptr R,
+const SymbolAddrMap &InitialDests) {
+  std::unique_lock Lock(Mutex);
+  if (GetNumAvailableStubs() < InitialDests.size())
+if (auto Err = grow(InitialDests.size() - GetNumAvailableStubs())) {
+  ES.reportError(std::move(Err));
+  R->failMaterialization();
+  return;
+}
+
+  JITDylib &TargetJD = R->getTargetJITDylib();
+  SymbolMap NewSymbolDefs;
+  std::vector Symbols;
+  for (auto &[K, V] : InitialDests) {
+StubHandle StubID = AvailableStubs.back();
+if (SymbolToStubs[&TargetJD].count(K)) {
+  ES.reportError(make_error(
+  "Tried to create duplicate redirectable symbols",
+  inconvertibleErrorCode()));
+  R->failMaterialization();
+  return;
+}
+dbgs() << *K << "\n";

lhames wrote:

Stray debugging output?

https://github.com/llvm/llvm-project/pull/67050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ORC] Implement basic reoptimization. (PR #67050)

2023-09-22 Thread via cfe-commits


@@ -0,0 +1,179 @@
+//===-- JITLinkRedirectableSymbolManager.cpp - JITLink redirection in Orc 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+
+#define DEBUG_TYPE "orc"
+
+using namespace llvm;
+using namespace llvm::orc;
+
+void JITLinkRedirectableSymbolManager::emitRedirectableSymbols(
+std::unique_ptr R,
+const SymbolAddrMap &InitialDests) {
+  std::unique_lock Lock(Mutex);
+  if (GetNumAvailableStubs() < InitialDests.size())
+if (auto Err = grow(InitialDests.size() - GetNumAvailableStubs())) {
+  ES.reportError(std::move(Err));
+  R->failMaterialization();
+  return;
+}
+
+  JITDylib &TargetJD = R->getTargetJITDylib();
+  SymbolMap NewSymbolDefs;
+  std::vector Symbols;
+  for (auto &[K, V] : InitialDests) {
+StubHandle StubID = AvailableStubs.back();
+if (SymbolToStubs[&TargetJD].count(K)) {
+  ES.reportError(make_error(
+  "Tried to create duplicate redirectable symbols",
+  inconvertibleErrorCode()));
+  R->failMaterialization();
+  return;
+}
+dbgs() << *K << "\n";
+SymbolToStubs[&TargetJD][K] = StubID;
+NewSymbolDefs[K] = JumpStubs[StubID];
+NewSymbolDefs[K].setFlags(V.getFlags());
+Symbols.push_back(K);
+AvailableStubs.pop_back();
+  }
+
+  if (auto Err = R->replace(absoluteSymbols(NewSymbolDefs))) {
+ES.reportError(std::move(Err));
+R->failMaterialization();
+return;
+  }
+
+  if (auto Err = redirectInner(TargetJD, InitialDests)) {
+ES.reportError(std::move(Err));
+R->failMaterialization();
+return;
+  }
+
+  auto Err = R->withResourceKeyDo([&](ResourceKey Key) {
+TrackedResources[Key].insert(TrackedResources[Key].end(), Symbols.begin(),
+ Symbols.end());
+  });
+  if (Err) {
+ES.reportError(std::move(Err));
+R->failMaterialization();
+return;
+  }
+}
+
+Error JITLinkRedirectableSymbolManager::redirect(
+JITDylib &TargetJD, const SymbolAddrMap &NewDests) {
+  std::unique_lock Lock(Mutex);
+  return redirectInner(TargetJD, NewDests);
+}
+
+Error JITLinkRedirectableSymbolManager::redirectInner(
+JITDylib &TargetJD, const SymbolAddrMap &NewDests) {
+  std::vector PtrWrites;
+  for (auto &[K, V] : NewDests) {
+if (!SymbolToStubs[&TargetJD].count(K))
+  return make_error(
+  "Tried to redirect non-existent redirectalbe symbol",
+  inconvertibleErrorCode());
+StubHandle StubID = SymbolToStubs[&TargetJD].at(K);
+PtrWrites.push_back({StubPointers[StubID].getAddress(), V.getAddress()});
+  }
+  if (auto Err = 
ES.getExecutorProcessControl().getMemoryAccess().writePointers(
+  PtrWrites))
+return Err;
+  return Error::success();
+}
+
+Error JITLinkRedirectableSymbolManager::grow(unsigned Need) {
+  unsigned OldSize = JumpStubs.size();
+  unsigned NumNewStubs = alignTo(Need, StubBlockSize);
+  unsigned NewSize = OldSize + NumNewStubs;
+
+  JumpStubs.resize(NewSize);
+  StubPointers.resize(NewSize);
+  AvailableStubs.reserve(NewSize);
+
+  SymbolLookupSet LookupSymbols;
+  DenseMap NewDefsMap;
+
+  Triple TT = ES.getTargetTriple();
+  auto G = std::make_unique(
+  "", TT, TT.isArch64Bit() ? 8 : 4,
+  TT.isLittleEndian() ? support::little : support::big,
+  jitlink::getGenericEdgeKindName);
+  auto &PointerSection =
+  G->createSection(StubPtrTableName, MemProt::Write | MemProt::Read);
+  auto &StubsSection =
+  G->createSection(JumpStubTableName, MemProt::Exec | MemProt::Read);
+
+  for (size_t I = OldSize; I < NewSize; I++) {
+auto Pointer = AnonymousPtrCreator(*G, PointerSection, nullptr, 0);
+if (auto Err = Pointer.takeError())
+  return Err;
+
+StringRef PtrSymName = StubPtrSymbolName(I);
+Pointer->setName(PtrSymName);
+Pointer->setScope(jitlink::Scope::Default);
+LookupSymbols.add(ES.intern(PtrSymName));
+NewDefsMap[ES.intern(PtrSymName)] = &StubPointers[I];
+
+auto Stub = PtrJumpStubCreator(*G, StubsSection, *Pointer);
+if (auto Err = Stub.takeError())
+  return Err;
+
+StringRef JumpStubSymName = JumpStubSymbolName(I);
+Stub->setName(JumpStubSymName);
+Stub->setScope(jitlink::Scope::Default);
+LookupSymbols.add(ES.intern(JumpStubSymName));
+NewDefsMap[ES.intern(JumpStubSymName)] = &JumpStubs[I];
+  }

lhames wrote:

We only need one anchor symbol to trigger emission of the graph. Eventually I 
think this could be sped up by emitting:
```asm
.section 
__.<++Idx>:
  ... stubs ...
.section 
__.:
  ... ptrs ...
```

Then looking up `__JumpStubTableName.` and `__StubPtrTableName.` and 
using the stub and pointer

[clang] [ORC] Implement basic reoptimization. (PR #67050)

2023-09-22 Thread via cfe-commits

https://github.com/lhames requested changes to this pull request.

Just reviewing the `RedirectionManager` interface and implementation patch for 
now. I have some minor comments, but otherwise this is looking amazing -- thank 
you very much @sunho!

https://github.com/llvm/llvm-project/pull/67050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ORC] Implement basic reoptimization. (PR #67050)

2023-09-22 Thread via cfe-commits


@@ -0,0 +1,179 @@
+//===-- JITLinkRedirectableSymbolManager.cpp - JITLink redirection in Orc 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+
+#define DEBUG_TYPE "orc"
+
+using namespace llvm;
+using namespace llvm::orc;
+
+void JITLinkRedirectableSymbolManager::emitRedirectableSymbols(
+std::unique_ptr R,
+const SymbolAddrMap &InitialDests) {
+  std::unique_lock Lock(Mutex);
+  if (GetNumAvailableStubs() < InitialDests.size())
+if (auto Err = grow(InitialDests.size() - GetNumAvailableStubs())) {
+  ES.reportError(std::move(Err));
+  R->failMaterialization();
+  return;
+}
+
+  JITDylib &TargetJD = R->getTargetJITDylib();
+  SymbolMap NewSymbolDefs;
+  std::vector Symbols;
+  for (auto &[K, V] : InitialDests) {
+StubHandle StubID = AvailableStubs.back();
+if (SymbolToStubs[&TargetJD].count(K)) {
+  ES.reportError(make_error(
+  "Tried to create duplicate redirectable symbols",
+  inconvertibleErrorCode()));
+  R->failMaterialization();
+  return;
+}
+dbgs() << *K << "\n";
+SymbolToStubs[&TargetJD][K] = StubID;
+NewSymbolDefs[K] = JumpStubs[StubID];
+NewSymbolDefs[K].setFlags(V.getFlags());
+Symbols.push_back(K);
+AvailableStubs.pop_back();
+  }
+
+  if (auto Err = R->replace(absoluteSymbols(NewSymbolDefs))) {
+ES.reportError(std::move(Err));
+R->failMaterialization();
+return;
+  }
+
+  if (auto Err = redirectInner(TargetJD, InitialDests)) {
+ES.reportError(std::move(Err));
+R->failMaterialization();
+return;
+  }

lhames wrote:

I think the call to `redirectInner` should precede the call to replace: As soon 
as replace runs anyone waiting on `NewSymbolDefs` will be notified that those 
symbols are available, but they're not actually usable until the call to 
`redirectInner`, right?

You should also return the stubs to the pool on all three of the failure paths 
(or add a FIXME that we should do that in the future).

https://github.com/llvm/llvm-project/pull/67050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ORC] Implement basic reoptimization. (PR #67050)

2023-09-22 Thread via cfe-commits


@@ -0,0 +1,179 @@
+//===-- JITLinkRedirectableSymbolManager.cpp - JITLink redirection in Orc 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "llvm/ExecutionEngine/Orc/JITLinkRedirectableSymbolManager.h"
+#include "llvm/ExecutionEngine/Orc/Core.h"
+
+#define DEBUG_TYPE "orc"
+
+using namespace llvm;
+using namespace llvm::orc;
+
+void JITLinkRedirectableSymbolManager::emitRedirectableSymbols(
+std::unique_ptr R,
+const SymbolAddrMap &InitialDests) {
+  std::unique_lock Lock(Mutex);
+  if (GetNumAvailableStubs() < InitialDests.size())
+if (auto Err = grow(InitialDests.size() - GetNumAvailableStubs())) {
+  ES.reportError(std::move(Err));
+  R->failMaterialization();
+  return;
+}
+
+  JITDylib &TargetJD = R->getTargetJITDylib();
+  SymbolMap NewSymbolDefs;
+  std::vector Symbols;
+  for (auto &[K, V] : InitialDests) {
+StubHandle StubID = AvailableStubs.back();
+if (SymbolToStubs[&TargetJD].count(K)) {
+  ES.reportError(make_error(
+  "Tried to create duplicate redirectable symbols",
+  inconvertibleErrorCode()));
+  R->failMaterialization();
+  return;
+}
+dbgs() << *K << "\n";
+SymbolToStubs[&TargetJD][K] = StubID;
+NewSymbolDefs[K] = JumpStubs[StubID];
+NewSymbolDefs[K].setFlags(V.getFlags());
+Symbols.push_back(K);
+AvailableStubs.pop_back();
+  }
+
+  if (auto Err = R->replace(absoluteSymbols(NewSymbolDefs))) {
+ES.reportError(std::move(Err));
+R->failMaterialization();
+return;
+  }
+
+  if (auto Err = redirectInner(TargetJD, InitialDests)) {
+ES.reportError(std::move(Err));
+R->failMaterialization();
+return;
+  }
+
+  auto Err = R->withResourceKeyDo([&](ResourceKey Key) {
+TrackedResources[Key].insert(TrackedResources[Key].end(), Symbols.begin(),
+ Symbols.end());
+  });
+  if (Err) {
+ES.reportError(std::move(Err));
+R->failMaterialization();
+return;
+  }
+}
+
+Error JITLinkRedirectableSymbolManager::redirect(
+JITDylib &TargetJD, const SymbolAddrMap &NewDests) {
+  std::unique_lock Lock(Mutex);
+  return redirectInner(TargetJD, NewDests);
+}
+
+Error JITLinkRedirectableSymbolManager::redirectInner(
+JITDylib &TargetJD, const SymbolAddrMap &NewDests) {
+  std::vector PtrWrites;
+  for (auto &[K, V] : NewDests) {
+if (!SymbolToStubs[&TargetJD].count(K))
+  return make_error(
+  "Tried to redirect non-existent redirectalbe symbol",
+  inconvertibleErrorCode());
+StubHandle StubID = SymbolToStubs[&TargetJD].at(K);
+PtrWrites.push_back({StubPointers[StubID].getAddress(), V.getAddress()});
+  }
+  if (auto Err = 
ES.getExecutorProcessControl().getMemoryAccess().writePointers(
+  PtrWrites))
+return Err;
+  return Error::success();

lhames wrote:

This could just be:
```c++
return 
ES.getExecutorProcessControl().getMemoryAccess().writePointers(PtrWrites);
```

https://github.com/llvm/llvm-project/pull/67050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [ORC] Implement basic reoptimization. (PR #67050)

2023-09-22 Thread via cfe-commits


@@ -0,0 +1,102 @@
+//===- RedirectionManager.h - Redirection manager interface -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Redirection manager interface that redirects a call to symbol to another.
+//
+//===--===//
+
+#ifndef LLVM_EXECUTIONENGINE_ORC_REDIRECTIONMANAGER_H
+#define LLVM_EXECUTIONENGINE_ORC_REDIRECTIONMANAGER_H
+
+#include "llvm/ExecutionEngine/Orc/Core.h"
+
+namespace llvm {
+namespace orc {
+
+/// Base class for performing redirection of call to symbol to another symbol 
in
+/// runtime.
+class RedirectionManager {
+public:
+  /// Symbol name to symbol definition map.
+  using SymbolAddrMap = DenseMap;
+
+  virtual ~RedirectionManager() = default;
+  /// Change the redirection destination of given symbols to new destination
+  /// symbols.
+  virtual Error redirect(JITDylib &JD, const SymbolAddrMap &NewDests) = 0;
+
+  /// Change the redirection destination of given symbol to new destination
+  /// symbol.
+  virtual Error redirect(JITDylib &JD, SymbolStringPtr Symbol,
+ ExecutorSymbolDef NewDest) {
+return redirect(JD, {{Symbol, NewDest}});
+  }
+
+private:
+  virtual void anchor();
+};
+
+/// Base class for managing redirectable symbols in which a call
+/// gets redirected to another symbol in runtime.
+class RedirectableSymbolManager : public RedirectionManager {
+public:
+  /// Create redirectable symbols with given symbol names and initial
+  /// desitnation symbol addresses.
+  Error createRedirectableSymbols(ResourceTrackerSP RT,
+  const SymbolMap &InitialDests);
+
+  /// Create a single redirectable symbol with given symbol name and initial
+  /// desitnation symbol address.
+  Error createRedirectableSymbol(ResourceTrackerSP RT, SymbolStringPtr Symbol,
+ ExecutorSymbolDef InitialDest) {
+return createRedirectableSymbols(RT, {{Symbol, InitialDest}});
+  }
+
+  /// Emit redirectable symbol
+  virtual void
+  emitRedirectableSymbols(std::unique_ptr MR,
+  const SymbolMap &InitialDests) = 0;
+};
+
+class RedirectableMaterializationUnit : public MaterializationUnit {
+public:
+  RedirectableMaterializationUnit(RedirectableSymbolManager &RM,
+  const SymbolMap &InitialDests)
+  : MaterializationUnit(convertToFlags(InitialDests)), RM(RM),
+InitialDests(InitialDests) {}
+
+  StringRef getName() const override {
+return "RedirectableSymbolMaterializationUnit";
+  }
+
+  void materialize(std::unique_ptr R) override {
+RM.emitRedirectableSymbols(std::move(R), std::move(InitialDests));
+  }
+
+  void discard(const JITDylib &JD, const SymbolStringPtr &Name) override {
+InitialDests.erase(Name);
+  }
+
+private:
+  static MaterializationUnit::Interface
+  convertToFlags(const SymbolMap &InitialDests) {
+SymbolFlagsMap Flags;
+for (auto [K, V] : InitialDests) {
+  Flags[K] = V.getFlags();
+}

lhames wrote:

No braces needed for single-line loops. :)

https://github.com/llvm/llvm-project/pull/67050
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e5f169f - Revert "[ORC][LLJIT] Move enable-debugger-support utility out of LLJITBuilder."

2023-09-22 Thread Lang Hames via cfe-commits

Author: Lang Hames
Date: 2023-09-22T21:43:41-07:00
New Revision: e5f169f91a86af3490d9251387b3f5455941bb83

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

LOG: Revert "[ORC][LLJIT] Move enable-debugger-support utility out of 
LLJITBuilder."

This reverts commit e1a5bb59b91d60c0d87feb78f0e0614589a4c927 while I
investigate the bot failure at
https://lab.llvm.org/buildbot/#/builders/168/builds/15831

Added: 


Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
clang/unittests/Interpreter/InterpreterTest.cpp
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
llvm/tools/lli/lli.cpp

Removed: 
llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h
llvm/lib/ExecutionEngine/Orc/DebuggerSupport.cpp



diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 2692d0618b8649e..2c4dfc9a611e021 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -17,7 +17,6 @@
 #include "clang/Interpreter/PartialTranslationUnit.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
-#include "llvm/ExecutionEngine/Orc/DebuggerSupport.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
@@ -47,13 +46,8 @@ 
IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
   JTMB.addFeatures(TI.getTargetOpts().Features);
   LLJITBuilder Builder;
   Builder.setJITTargetMachineBuilder(JTMB);
-  Builder.setPrePlatformSetup(
-  [](LLJIT &J) {
-// Try to enable debugging of JIT'd code (only works with JITLink for
-// ELF and MachO).
-consumeError(enableDebuggerSupport(J));
-return llvm::Error::success();
-  });
+  // Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
+  Builder.setEnableDebuggerSupport(true);
 
   if (auto JitOrErr = Builder.create())
 Jit = std::move(*JitOrErr);

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index a29a2ebac434ab5..51741fd1a27ef4a 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -152,7 +152,9 @@ int main(int argc, const char **argv) {
   llvm::InitializeAllAsmPrinters();
 
   if (OptHostSupportsJit) {
-auto J = llvm::orc::LLJITBuilder().create();
+auto J = llvm::orc::LLJITBuilder()
+   .setEnableDebuggerSupport(true)
+   .create();
 if (J)
   llvm::outs() << "true\n";
 else {

diff  --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index 70e10b1e53bd9d6..8700f506d9b17d4 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -52,7 +52,9 @@ TEST(InterpreterTest, CatchException) {
   llvm::InitializeNativeTargetAsmPrinter();
 
   {
-auto J = llvm::orc::LLJITBuilder().create();
+auto J = llvm::orc::LLJITBuilder()
+ .setEnableDebuggerSupport(true)
+ .create();
 if (!J) {
   // The platform does not support JITs.
   // Using llvm::consumeError will require typeinfo for ErrorInfoBase, we

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 5f2911e9a7adad3..62e5bacbdd0b6d8 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -191,7 +191,9 @@ static std::string MangleName(NamedDecl *ND) {
 }
 
 static bool HostSupportsJit() {
-  auto J = llvm::orc::LLJITBuilder().create();
+  auto J = llvm::orc::LLJITBuilder()
+ .setEnableDebuggerSupport(true)
+ .create();
   if (J)
 return true;
   LLVMConsumeError(llvm::wrap(J.takeError()));

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h 
b/llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h
deleted file mode 100644
index 1b47d7d41bb9b5a..000
--- a/llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h
+++ /dev/null
@@ -1,28 +0,0 @@
-//===-- DebugerSupport.h - Utils for enabling debugger support --*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache

[clang] [clang-format][NFC] Clean up alignTrailingComments() (PR #67218)

2023-09-22 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/67218

None

>From b00e6394bb1fe30be40e040b9201c4f3f1b28cd3 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Fri, 22 Sep 2023 21:33:02 -0700
Subject: [PATCH] [clang-format][NFC] Clean up alignTrailingComments()

---
 clang/lib/Format/WhitespaceManager.cpp | 98 ++
 1 file changed, 51 insertions(+), 47 deletions(-)

diff --git a/clang/lib/Format/WhitespaceManager.cpp 
b/clang/lib/Format/WhitespaceManager.cpp
index b7bd8d27dc976b1..d7e5612928ef764 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -1042,68 +1042,67 @@ void WhitespaceManager::alignChainedConditionals() {
 }
 
 void WhitespaceManager::alignTrailingComments() {
-  unsigned MinColumn = 0;
-  unsigned MaxColumn = UINT_MAX;
-  unsigned StartOfSequence = 0;
+  const int Size = Changes.size();
+  int MinColumn = 0;
+  int StartOfSequence = 0;
   bool BreakBeforeNext = false;
-  unsigned Newlines = 0;
-  unsigned int NewLineThreshold = 1;
+  int NewLineThreshold = 1;
   if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Always)
 NewLineThreshold = Style.AlignTrailingComments.OverEmptyLines + 1;
 
-  for (unsigned i = 0, e = Changes.size(); i != e; ++i) {
-if (Changes[i].StartOfBlockComment)
+  for (int I = 0, MaxColumn = INT_MAX, Newlines = 0; I < Size; ++I) {
+auto &C = Changes[I];
+if (C.StartOfBlockComment)
   continue;
-Newlines += Changes[i].NewlinesBefore;
-if (!Changes[i].IsTrailingComment)
+Newlines += C.NewlinesBefore;
+if (!C.IsTrailingComment)
   continue;
 
 if (Style.AlignTrailingComments.Kind == FormatStyle::TCAS_Leave) {
-  auto OriginalSpaces =
-  Changes[i].OriginalWhitespaceRange.getEnd().getRawEncoding() -
-  Changes[i].OriginalWhitespaceRange.getBegin().getRawEncoding() -
-  Changes[i].Tok->NewlinesBefore;
-  unsigned RestoredLineLength = Changes[i].StartOfTokenColumn +
-Changes[i].TokenLength + OriginalSpaces;
+  const int OriginalSpaces =
+  C.OriginalWhitespaceRange.getEnd().getRawEncoding() -
+  C.OriginalWhitespaceRange.getBegin().getRawEncoding() -
+  C.Tok->NewlinesBefore;
+  assert(OriginalSpaces >= 0);
+  const auto RestoredLineLength =
+  C.StartOfTokenColumn + C.TokenLength + OriginalSpaces;
   // If leaving comments makes the line exceed the column limit, give up to
   // leave the comments.
-  if (RestoredLineLength >= Style.ColumnLimit && Style.ColumnLimit != 0)
+  if (RestoredLineLength >= Style.ColumnLimit && Style.ColumnLimit > 0)
 break;
-  Changes[i].Spaces = OriginalSpaces;
+  C.Spaces = OriginalSpaces;
   continue;
 }
 
-unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
-unsigned ChangeMaxColumn;
-
-if (Style.ColumnLimit == 0)
-  ChangeMaxColumn = UINT_MAX;
-else if (Style.ColumnLimit >= Changes[i].TokenLength)
-  ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
-else
-  ChangeMaxColumn = ChangeMinColumn;
+const int ChangeMinColumn = C.StartOfTokenColumn;
+int ChangeMaxColumn;
 
 // If we don't create a replacement for this change, we have to consider
 // it to be immovable.
-if (!Changes[i].CreateReplacement)
+if (!C.CreateReplacement)
+  ChangeMaxColumn = ChangeMinColumn;
+else if (Style.ColumnLimit == 0)
+  ChangeMaxColumn = INT_MAX;
+else if (Style.ColumnLimit >= C.TokenLength)
+  ChangeMaxColumn = Style.ColumnLimit - C.TokenLength;
+else
   ChangeMaxColumn = ChangeMinColumn;
 
-if (i + 1 != e && Changes[i + 1].ContinuesPPDirective)
+if (I + 1 < Size && Changes[I + 1].ContinuesPPDirective) {
   ChangeMaxColumn -= 2;
+  assert(ChangeMaxColumn >= 0);
+}
 
-// We don't want to align namespace end comments.
-bool DontAlignThisComment = i > 0 && Changes[i].NewlinesBefore == 0 &&
-Changes[i - 1].Tok->is(TT_NamespaceRBrace);
 bool WasAlignedWithStartOfNextLine = false;
-if (Changes[i].NewlinesBefore >= 1) { // A comment on its own line.
-  unsigned CommentColumn = SourceMgr.getSpellingColumnNumber(
-  Changes[i].OriginalWhitespaceRange.getEnd());
-  for (unsigned j = i + 1; j != e; ++j) {
-if (Changes[j].Tok->is(tok::comment))
+if (C.NewlinesBefore >= 1) { // A comment on its own line.
+  const auto CommentColumn =
+  
SourceMgr.getSpellingColumnNumber(C.OriginalWhitespaceRange.getEnd());
+  for (int J = I + 1; J < Size; ++J) {
+if (Changes[J].Tok->is(tok::comment))
   continue;
 
-unsigned NextColumn = SourceMgr.getSpellingColumnNumber(
-Changes[j].OriginalWhitespaceRange.getEnd());
+const auto NextColumn = SourceMgr.getSpellingColumnNumber(
+Changes[J].OriginalWhitespaceRange.getEnd());
 // 

[clang] [Clang][RISCV] Handle RVV tuple types correctly as OutputOperands for inline asm (PR #67018)

2023-09-22 Thread Craig Topper via cfe-commits

topperc wrote:

Does this mean the backend register allocation will pick a large LMUL register 
the same size as the whole tuple and force the register to be overly aligned? 
For example an lmul=1 seg2 tuple can use v0+v1, or v1+v2, or v2+v3, etc. But 
lmul=2 can only use v0+v1, v2+v3, v4+v5, etc.

https://github.com/llvm/llvm-project/pull/67018
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)

2023-09-22 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik commented:

Looks good but I want more tests.

https://github.com/llvm/llvm-project/pull/67147
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)

2023-09-22 Thread Shafik Yaghmour via cfe-commits

https://github.com/shafik edited https://github.com/llvm/llvm-project/pull/67147
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)

2023-09-22 Thread Shafik Yaghmour via cfe-commits


@@ -31,6 +31,13 @@ static_assert(b, "");
 constexpr int one = true;
 static_assert(one == 1, "");
 
+constexpr bool b2 = bool();

shafik wrote:

There are a lot of scalars: https://eel.is/c++draft/basic.types.general#9

Can we have a test for each case?

https://github.com/llvm/llvm-project/pull/67147
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Turn -Wenum-constexpr-conversion into a hard error (PR #67170)

2023-09-22 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

This change is a lot more involved, this is on my list of things to do. See the 
discussion here: https://reviews.llvm.org/D150226



https://github.com/llvm/llvm-project/pull/67170
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [HIP] Support compressing device binary (PR #67162)

2023-09-22 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/67162

>From aa1aee8695a062c472dbb9efd1e87a2ba7cdc58b Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Thu, 21 Sep 2023 13:52:16 -0400
Subject: [PATCH] [HIP] Support compressing device binary

Add option -f[no-]offload-compress to clang to enable/disable
compression of device binary for HIP. By default it is disabled.

Add option -compress to clang-offload-bundler to enable
compression of offload bundle. By default it is disabled.

When enabled, zstd or zlib is used for compression when
available.

When disabled, it is NFC compared to previous behavior. The
same offload bundle format is used as before.

Clang-offload-bundler automatically detects whether the
input file to be unbundled is compressed and the compression
method and decompress if necessary.
---
 clang/docs/ClangOffloadBundler.rst|  27 ++
 clang/include/clang/Driver/OffloadBundler.h   |  37 ++
 clang/include/clang/Driver/Options.td |   4 +
 clang/lib/Driver/OffloadBundler.cpp   | 337 +++---
 clang/lib/Driver/ToolChains/Clang.cpp |   7 +
 .../test/Driver/clang-offload-bundler-zlib.c  |  75 
 .../test/Driver/clang-offload-bundler-zstd.c  |  72 
 .../ClangOffloadBundler.cpp   |  10 +
 8 files changed, 525 insertions(+), 44 deletions(-)
 create mode 100644 clang/test/Driver/clang-offload-bundler-zlib.c
 create mode 100644 clang/test/Driver/clang-offload-bundler-zstd.c

diff --git a/clang/docs/ClangOffloadBundler.rst 
b/clang/docs/ClangOffloadBundler.rst
index d08bf4b97781fa4..1e21d3e7264d5c3 100644
--- a/clang/docs/ClangOffloadBundler.rst
+++ b/clang/docs/ClangOffloadBundler.rst
@@ -309,3 +309,30 @@ target by comparing bundle ID's. Two bundle ID's are 
considered compatible if:
   * Their offload kind are the same
   * Their target triple are the same
   * Their GPUArch are the same
+
+Compression and Decompression
+=
+
+``clang-offload-bundler`` provides features to compress and decompress the full
+bundle, leveraging inherent redundancies within the bundle entries. Use the
+`-compress` command-line option to enable this compression capability.
+
+The compressed offload bundle begins with a header followed by the compressed 
binary data:
+
+- **Magic Number (4 bytes)**:
+This is a unique identifier to distinguish compressed offload bundles. The 
value is the string 'CCOB' (Compressed Clang Offload Bundle).
+
+- **Version Number (16-bit unsigned int)**:
+This denotes the version of the compressed offload bundle format. The 
current version is `1`.
+
+- **Compression Method (16-bit unsigned int)**:
+This field indicates the compression method used. The value corresponds to 
either `zlib` or `zstd`, represented as a 16-bit unsigned integer cast from the 
LLVM compression enumeration.
+
+- **Uncompressed Binary Size (32-bit unsigned int)**:
+This is the size (in bytes) of the binary data before it was compressed.
+
+- **Hash (64-bit unsigned int)**:
+This is a 64-bit truncated MD5 hash of the uncompressed binary data. It 
serves for verification and caching purposes.
+
+- **Compressed Data**:
+The actual compressed binary data follows the header. Its size can be 
inferred from the total size of the file minus the header size.
diff --git a/clang/include/clang/Driver/OffloadBundler.h 
b/clang/include/clang/Driver/OffloadBundler.h
index 28473c53662de2c..17df31d31071d99 100644
--- a/clang/include/clang/Driver/OffloadBundler.h
+++ b/clang/include/clang/Driver/OffloadBundler.h
@@ -19,6 +19,7 @@
 
 #include "llvm/Support/Error.h"
 #include "llvm/TargetParser/Triple.h"
+#include 
 #include 
 #include 
 
@@ -26,11 +27,15 @@ namespace clang {
 
 class OffloadBundlerConfig {
 public:
+  OffloadBundlerConfig();
+
   bool AllowNoHost = false;
   bool AllowMissingBundles = false;
   bool CheckInputArchive = false;
   bool PrintExternalCommands = false;
   bool HipOpenmpCompatible = false;
+  bool Compress = false;
+  bool Verbose = false;
 
   unsigned BundleAlignment = 1;
   unsigned HostInputIndex = ~0u;
@@ -84,6 +89,38 @@ struct OffloadTargetInfo {
   std::string str() const;
 };
 
+// CompressedOffloadBundle represents the format for the compressed offload
+// bundles.
+//
+// The format is as follows:
+// - Magic Number (4 bytes) - A constant "CCOB".
+// - Version (2 bytes)
+// - Compression Method (2 bytes) - Uses the values from
+// llvm::compression::Format.
+// - Uncompressed Size (4 bytes).
+// - Truncated MD5 Hash (8 bytes).
+// - Compressed Data (variable length).
+
+class CompressedOffloadBundle {
+private:
+  static inline const size_t MagicSize = 4;
+  static inline const size_t VersionFieldSize = sizeof(uint16_t);
+  static inline const size_t MethodFieldSize = sizeof(uint16_t);
+  static inline const size_t SizeFieldSize = sizeof(uint32_t);
+  static inline const size_t HashFieldSize = 8;
+  static inline const size_t HeaderSize = MagicSize 

[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-09-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clangd


Changes

Shows align for records and fields declarations in hover information.

Example:
```cpp
struct A {
  char a;
  short b;
};
```

For this struct hover informations shows:
```
Size: 4 bytes
Align: 2 bytes
```

![image](https://github.com/llvm/llvm-project/assets/12231048/4b5b150b-d81e-4da5-936c-da81ec866570)


---
Full diff: https://github.com/llvm/llvm-project/pull/67213.diff


3 Files Affected:

- (modified) clang-tools-extra/clangd/Hover.cpp (+5) 
- (modified) clang-tools-extra/clangd/Hover.h (+2) 
- (modified) clang-tools-extra/clangd/unittests/HoverTests.cpp (+11) 


``diff
diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 0ec85fc24df151b..f2cc6637069532b 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1001,6 +1001,8 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
   if (auto *RD = llvm::dyn_cast(&ND)) {
 if (auto Size = Ctx.getTypeSizeInCharsIfKnown(RD->getTypeForDecl()))
   HI.Size = Size->getQuantity() * 8;
+if (!RD->isInvalidDecl() && !RD->isDependentType())
+  HI.Align = Ctx.getTypeAlign(RD->getTypeForDecl());
 return;
   }
 
@@ -1009,6 +1011,7 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
 if (Record)
   Record = Record->getDefinition();
 if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
+  HI.Align = Ctx.getTypeAlign(FD->getType());
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Record);
   HI.Offset = Layout.getFieldOffset(FD->getFieldIndex());
   if (FD->isBitField())
@@ -1488,6 +1491,8 @@ markup::Document HoverInfo::present() const {
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
   }
+  if (Align)
+Output.addParagraph().appendText("Align: " + formatSize(*Align));
 
   if (CalleeArgInfo) {
 assert(CallPassType);
diff --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h
index 6a61100912918ea..fe689de44732ebe 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -97,6 +97,8 @@ struct HoverInfo {
   std::optional Offset;
   /// Contains the padding following a field within the enclosing class.
   std::optional Padding;
+  /// Contains the alignment of fields and types where it's interesting.
+  std::optional Align;
   // Set when symbol is inside function call. Contains information extracted
   // from the callee definition about the argument this is passed as.
   std::optional CalleeArgInfo;
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 8c88cd52574536c..c5623759a7c2041 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -92,6 +92,7 @@ TEST(Hover, Structured) {
  HI.Offset = 0;
  HI.Size = 8;
  HI.Padding = 56;
+ HI.Align = 8;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -110,6 +111,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Size = 8;
  HI.Padding = 120;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -128,6 +130,7 @@ TEST(Hover, Structured) {
  HI.Type = "int";
  HI.Offset = 0;
  HI.Size = 1;
+ HI.Align = 32;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -192,6 +195,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Offset = 0;
  HI.Size = 8;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -204,6 +208,7 @@ TEST(Hover, Structured) {
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
  HI.Size = 8;
+ HI.Align = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1375,6 +1380,7 @@ class Foo final {})cpp";
  HI.Offset = 8;
  HI.Size = 1;
  HI.Padding = 23;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}}};
   for (const auto &Case : Cases) {
@@ -1411,6 +1417,7 @@ class Foo final {})cpp";
 EXPECT_EQ(H->Value, Expected.Value);
 EXPECT_EQ(H->Size, Expected.Size);
 EXPECT_EQ(H->Offset, Expected.Offset);
+EXPECT_EQ(H->Align, Expected.Align);
 EXPECT_EQ(H->AccessSpecifier, Expected.AccessSpecifier);
 EXPECT_EQ(H->CalleeArgInfo, Expected.CalleeArgInfo);
 EXPECT_EQ(H->CallPassType, Expected.CallPassType);
@@ -3448,6 +3455,7 @@ template  class Foo {})",
 HI.Size = 32;
 HI.Offset = 96;
 HI.Padding = 32;
+HI.Align = 32;
   },
   R"(field foo
 
@@ -3455,6 +3463,7 @@ Type: type (aka can_type)
 Value = value
 Offset: 12 bytes
 Size: 4 bytes (+4 bytes padding)
+Align: 4 bytes
 
 // I

[clang-tools-extra] [clangd] Show alignment for records and fields decls (PR #67213)

2023-09-22 Thread via cfe-commits

https://github.com/sr-tream created 
https://github.com/llvm/llvm-project/pull/67213

Shows align for records and fields declarations in hover information.

Example:
```cpp
struct A {
  char a;
  short b;
};
```

For this struct hover informations shows:
```
Size: 4 bytes
Align: 2 bytes
```

![image](https://github.com/llvm/llvm-project/assets/12231048/4b5b150b-d81e-4da5-936c-da81ec866570)


>From 0798df861525112f25c2480b77cca453f928d6c3 Mon Sep 17 00:00:00 2001
From: SR_team 
Date: Sat, 23 Sep 2023 03:49:23 +0300
Subject: [PATCH] [clangd] Show alignment for records and fields decls

---
 clang-tools-extra/clangd/Hover.cpp|  5 +
 clang-tools-extra/clangd/Hover.h  |  2 ++
 clang-tools-extra/clangd/unittests/HoverTests.cpp | 11 +++
 3 files changed, 18 insertions(+)

diff --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 0ec85fc24df151b..f2cc6637069532b 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -1001,6 +1001,8 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
   if (auto *RD = llvm::dyn_cast(&ND)) {
 if (auto Size = Ctx.getTypeSizeInCharsIfKnown(RD->getTypeForDecl()))
   HI.Size = Size->getQuantity() * 8;
+if (!RD->isInvalidDecl() && !RD->isDependentType())
+  HI.Align = Ctx.getTypeAlign(RD->getTypeForDecl());
 return;
   }
 
@@ -1009,6 +1011,7 @@ void addLayoutInfo(const NamedDecl &ND, HoverInfo &HI) {
 if (Record)
   Record = Record->getDefinition();
 if (Record && !Record->isInvalidDecl() && !Record->isDependentType()) {
+  HI.Align = Ctx.getTypeAlign(FD->getType());
   const ASTRecordLayout &Layout = Ctx.getASTRecordLayout(Record);
   HI.Offset = Layout.getFieldOffset(FD->getFieldIndex());
   if (FD->isBitField())
@@ -1488,6 +1491,8 @@ markup::Document HoverInfo::present() const {
   llvm::formatv(" (+{0} padding)", formatSize(*Padding)).str());
 }
   }
+  if (Align)
+Output.addParagraph().appendText("Align: " + formatSize(*Align));
 
   if (CalleeArgInfo) {
 assert(CallPassType);
diff --git a/clang-tools-extra/clangd/Hover.h b/clang-tools-extra/clangd/Hover.h
index 6a61100912918ea..fe689de44732ebe 100644
--- a/clang-tools-extra/clangd/Hover.h
+++ b/clang-tools-extra/clangd/Hover.h
@@ -97,6 +97,8 @@ struct HoverInfo {
   std::optional Offset;
   /// Contains the padding following a field within the enclosing class.
   std::optional Padding;
+  /// Contains the alignment of fields and types where it's interesting.
+  std::optional Align;
   // Set when symbol is inside function call. Contains information extracted
   // from the callee definition about the argument this is passed as.
   std::optional CalleeArgInfo;
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 8c88cd52574536c..c5623759a7c2041 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -92,6 +92,7 @@ TEST(Hover, Structured) {
  HI.Offset = 0;
  HI.Size = 8;
  HI.Padding = 56;
+ HI.Align = 8;
  HI.AccessSpecifier = "private";
}},
   // Union field
@@ -110,6 +111,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Size = 8;
  HI.Padding = 120;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Bitfield
@@ -128,6 +130,7 @@ TEST(Hover, Structured) {
  HI.Type = "int";
  HI.Offset = 0;
  HI.Size = 1;
+ HI.Align = 32;
  HI.AccessSpecifier = "public";
}},
   // Local to class method.
@@ -192,6 +195,7 @@ TEST(Hover, Structured) {
  HI.Type = "char";
  HI.Offset = 0;
  HI.Size = 8;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}},
   // Struct definition shows size.
@@ -204,6 +208,7 @@ TEST(Hover, Structured) {
  HI.Kind = index::SymbolKind::Struct;
  HI.Definition = "struct X {}";
  HI.Size = 8;
+ HI.Align = 8;
}},
   // Variable with template type
   {R"cpp(
@@ -1375,6 +1380,7 @@ class Foo final {})cpp";
  HI.Offset = 8;
  HI.Size = 1;
  HI.Padding = 23;
+ HI.Align = 8;
  HI.AccessSpecifier = "public";
}}};
   for (const auto &Case : Cases) {
@@ -1411,6 +1417,7 @@ class Foo final {})cpp";
 EXPECT_EQ(H->Value, Expected.Value);
 EXPECT_EQ(H->Size, Expected.Size);
 EXPECT_EQ(H->Offset, Expected.Offset);
+EXPECT_EQ(H->Align, Expected.Align);
 EXPECT_EQ(H->AccessSpecifier, Expected.AccessSpecifier);
 EXPECT_EQ(H->CalleeArgInfo, Expected.CalleeArgInfo);
 EXPECT_EQ(H->CallPassType, Expected.CallPassType);
@@ -3448,6 +3455,7 @@ template  class Foo {})",
 HI.Size = 32;
 HI.Offset = 96;
 HI.Padding = 32;
+HI.Align = 32;
   

[clang] Modify BoundsSan to improve debuggability (PR #65972)

2023-09-22 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka requested changes to this pull request.

the code LGTM,
but llvm-project/llvm/test/Instrumentation/BoundsChecking/ test is needed

Maybe just extend 
llvm-project/llvm/test/Instrumentation/BoundsChecking/simple.ll

https://github.com/llvm/llvm-project/pull/65972
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Modify BoundsSan to improve debuggability (PR #65972)

2023-09-22 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka edited 
https://github.com/llvm/llvm-project/pull/65972
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Modify BoundsSan to improve debuggability (PR #65972)

2023-09-22 Thread Vitaly Buka via cfe-commits


@@ -0,0 +1,83 @@
+; RUN: llc -O3 -mtriple arm64-linux -filetype asm -o - %s | FileCheck %s 
-check-prefix CHECK-ASM
+; What this test does is check that even with nomerge, the functions still get 
merged in
+; compiled code as the ubsantrap call gets lowered to a single instruction: 
brk.

vitalybuka wrote:

you don't change MC, so I don't think we need the test here

However we need a test in llvm-project/llvm/test/Instrumentation/BoundsChecking/

https://github.com/llvm/llvm-project/pull/65972
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Modify BoundsSan to improve debuggability (PR #65972)

2023-09-22 Thread Vitaly Buka via cfe-commits


@@ -180,19 +183,27 @@ static bool addBoundsChecking(Function &F, 
TargetLibraryInfo &TLI,
   // will create a fresh block every time it is called.
   BasicBlock *TrapBB = nullptr;
   auto GetTrapBB = [&TrapBB](BuilderTy &IRB) {
-if (TrapBB && SingleTrapBB)
-  return TrapBB;
-
 Function *Fn = IRB.GetInsertBlock()->getParent();
-// FIXME: This debug location doesn't make a lot of sense in the
-// `SingleTrapBB` case.
 auto DebugLoc = IRB.getCurrentDebugLocation();
 IRBuilder<>::InsertPointGuard Guard(IRB);
+
+if (TrapBB && SingleTrapBB && !DebugTrapBB)
+  return TrapBB;
+
 TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn);
 IRB.SetInsertPoint(TrapBB);
 
-auto *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap);
-CallInst *TrapCall = IRB.CreateCall(F, {});
+Intrinsic::ID IntrID = DebugTrapBB ? Intrinsic::ubsantrap : 
Intrinsic::trap;
+auto *F = Intrinsic::getDeclaration(Fn->getParent(), IntrID);
+
+CallInst *TrapCall;
+if (DebugTrapBB) {
+  TrapCall =
+  IRB.CreateCall(F, ConstantInt::get(IRB.getInt8Ty(), Fn->size()));

vitalybuka wrote:

>> (TrapBB->getParent()->size() * 0x1 + CheckHandlerID)

> Why * 0x1 ?

anything that above CheckHandlerID so lower two bytes are still CheckHandlerID
and upper bytes you counter 

but i missed that it's i8
So keep your version

https://github.com/llvm/llvm-project/pull/65972
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Recommit "Implement [[msvc::no_unique_address]] (#65675)" (PR #67199)

2023-09-22 Thread Richard Smith via cfe-commits


@@ -1798,11 +1798,24 @@ def ArmMveStrictPolymorphism : TypeAttr, 
TargetSpecificAttr {
   let Documentation = [ArmMveStrictPolymorphismDocs];
 }
 
-def NoUniqueAddress : InheritableAttr, TargetSpecificAttr 
{
-  let Spellings = [CXX11<"", "no_unique_address", 201803>];
+def NoUniqueAddress : InheritableAttr {
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  // No spellings because instances of this attribute are created by
+  // MSNoUniqueAddress and ItaniumNoUniqueAddress
+  let Spellings = [];
+  let Documentation = [InternalOnly];
+}
+
+def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
   let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  let Spellings = [CXX11<"msvc", "no_unique_address", 201803>];
+  let Documentation = [MSNoUniqueAddressDocs];
+}
+
+def ItaniumNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {

zygoloid wrote:

I don't think this attribute name makes sense: this is the standard attribute 
(which just happens to have no effect on the MS ABI), not something specific to 
the Itanium ABI.

https://github.com/llvm/llvm-project/pull/67199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147655: Implement mangling rules for C++20 concepts and requires-expressions.

2023-09-22 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In D147655#4649864 , @dyung wrote:

> Hi @rsmith, we have an internal test where your change seems to have changed 
> the mangling in C++17 mode and wanted to check if that was intentional.

[...]

> Are these changes in non-C++20 mode intentional?

Yes, they're intentional. Unfortunately we could have mangling collisions here 
when using the old ABI rule; these two different templates would have the same 
mangling:

  template  T returnit() {return I;};
  template  T returnit() { return I; }

But... it looks like this case is missing from the list of affected cases in 
the change description and the release notes. Sorry about that. Release notes 
updated in rGaaa79a59317f859485d701d1eb68ac4cb213e1d1 
.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147655

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


[clang] aaa79a5 - [release notes] Add forgotten case to list of changed manglings.

2023-09-22 Thread Richard Smith via cfe-commits

Author: Richard Smith
Date: 2023-09-22T17:40:07-07:00
New Revision: aaa79a59317f859485d701d1eb68ac4cb213e1d1

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

LOG: [release notes] Add forgotten case to list of changed manglings.

Added: 


Modified: 
clang/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 477a40630f11097..8b5e48d1758d96d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -51,6 +51,8 @@ C++ Specific Potentially Breaking Changes
   parameter lists or requires-clauses. This causes mangled names to change for
   function templates in the following cases:
 
+  - When a template parameter in a function template depends on a previous
+template parameter, such as ``template void f()``.
   - When the function has any constraints, whether from constrained template
   parameters or requires-clauses.
   - When the template parameter list includes a deduced type -- either



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


[clang] ce8c228 - Use llvm::drop_begin and llvm::drop_end (NFC)

2023-09-22 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-09-22T17:29:10-07:00
New Revision: ce8c22856e3526ee7ab8ff037cdd7a7e1670c4a7

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

LOG: Use llvm::drop_begin and llvm::drop_end (NFC)

Added: 


Modified: 
clang/lib/AST/TextNodeDumper.cpp
llvm/lib/CodeGen/GlobalISel/Utils.cpp
llvm/lib/CodeGen/MachineCopyPropagation.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/MCA/Stages/EntryStage.cpp
llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Removed: 




diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index 5c8600035638b3b..233dc6c6359515a 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -1901,8 +1901,7 @@ void TextNodeDumper::VisitFunctionDecl(const FunctionDecl 
*D) {
 auto Overrides = MD->overridden_methods();
 OS << "Overrides: [ ";
 dumpOverride(*Overrides.begin());
-for (const auto *Override :
- llvm::make_range(Overrides.begin() + 1, Overrides.end())) {
+for (const auto *Override : llvm::drop_begin(Overrides)) {
   OS << ", ";
   dumpOverride(Override);
 }

diff  --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp 
b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index acc7b8098d1f0d8..473c3f452f8b1d9 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -1173,7 +1173,7 @@ llvm::getVectorSplat(const MachineInstr &MI, const 
MachineRegisterInfo &MRI) {
   if (auto Splat = getIConstantSplatSExtVal(MI, MRI))
 return RegOrConstant(*Splat);
   auto Reg = MI.getOperand(1).getReg();
-  if (any_of(make_range(MI.operands_begin() + 2, MI.operands_end()),
+  if (any_of(drop_begin(MI.operands(), 2),
  [&Reg](const MachineOperand &Op) { return Op.getReg() != Reg; }))
 return std::nullopt;
   return RegOrConstant(Reg);

diff  --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp 
b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index 488ef31e1dd1e35..a032b31a1fc7c62 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -1147,11 +1147,11 @@ void 
MachineCopyPropagation::EliminateSpillageCopies(MachineBasicBlock &MBB) {
   return;
 
 // If violate property#2, we don't fold the chain.
-for (const MachineInstr *Spill : make_range(SC.begin() + 1, SC.end()))
+for (const MachineInstr *Spill : drop_begin(SC))
   if (CopySourceInvalid.count(Spill))
 return;
 
-for (const MachineInstr *Reload : make_range(RC.begin(), RC.end() - 1))
+for (const MachineInstr *Reload : drop_end(RC))
   if (CopySourceInvalid.count(Reload))
 return;
 

diff  --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 81dfa14f2e6b57e..b76e355996ea530 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -130,7 +130,7 @@ Value *PHINode::removeIncomingValue(unsigned Idx, bool 
DeletePHIIfEmpty) {
   // clients might not expect this to happen.  The code as it is thrashes the
   // use/def lists, which is kinda lame.
   std::copy(op_begin() + Idx + 1, op_end(), op_begin() + Idx);
-  copyIncomingBlocks(make_range(block_begin() + Idx + 1, block_end()), Idx);
+  copyIncomingBlocks(drop_begin(blocks(), Idx + 1), Idx);
 
   // Nuke the last value.
   Op<-1>().set(nullptr);

diff  --git a/llvm/lib/MCA/Stages/EntryStage.cpp 
b/llvm/lib/MCA/Stages/EntryStage.cpp
index 5c82ce780478c39..3a47ffe80391fe2 100644
--- a/llvm/lib/MCA/Stages/EntryStage.cpp
+++ b/llvm/lib/MCA/Stages/EntryStage.cpp
@@ -67,8 +67,7 @@ llvm::Error EntryStage::cycleResume() {
 
 llvm::Error EntryStage::cycleEnd() {
   // Find the first instruction which hasn't been retired.
-  auto Range =
-  make_range(Instructions.begin() + NumRetired, Instructions.end());
+  auto Range = drop_begin(Instructions, NumRetired);
   auto It = find_if(Range, [](const std::unique_ptr &I) {
 return !I->isRetired();
   });

diff  --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp 
b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
index 141821afa9c5915..60bb820585ac0a2 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
@@ -5517,11 +5517,9 @@ bool 
AArch64InstructionSelector::tryOptBuildVecToSubregToReg(
   const RegisterBank &DstRB = *RBI.getRegBank(Dst, MRI, TRI);
   if (EltRB != DstRB)
 return false;
-  if (any_of(make_range(I.operands_begin() + 2, I.operands_end()),
- [&MRI](const MachineOperand &Op) {
-   return !getOpcodeDef(TargetOpcode::G_IMPLICIT_DEF, Op.getReg(),
-MRI);

[clang] 3bca659 - Use llvm::is_contained (NFC)

2023-09-22 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-09-22T17:20:50-07:00
New Revision: 3bca65955668b478bcf2cac49f1731f20da8da9c

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

LOG: Use llvm::is_contained (NFC)

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp
mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 46eae3596d2a8fe..d42a21976821a4c 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -1187,9 +1187,7 @@ class DSAStackTy {
 if (!Top)
   return false;
 
-return llvm::any_of(Top->IteratorVarDecls, [VD](const VarDecl *IteratorVD) 
{
-  return IteratorVD == VD->getCanonicalDecl();
-});
+return llvm::is_contained(Top->IteratorVarDecls, VD->getCanonicalDecl());
   }
   /// get captured field from ImplicitDefaultFirstprivateFDs
   VarDecl *getImplicitFDCapExprDecl(const FieldDecl *FD) const {

diff  --git a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp 
b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
index 6d8a96a3ad23f3e..d60a1a1cda849c7 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp
@@ -1514,8 +1514,7 @@ vectorizeLinalgOpPrecondition(LinalgOp linalgOp,
   ArrayRef inputVectorSizes,
   bool vectorizeNDExtract) {
   // tensor with dimension of 0 cannot be vectorized.
-  if (llvm::any_of(linalgOp.getStaticShape(),
-   [](int64_t dim) { return dim == 0; }))
+  if (llvm::is_contained(linalgOp.getStaticShape(), 0))
 return failure();
   // Check API contract for input vector sizes.
   if (!inputVectorSizes.empty() &&

diff  --git a/mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp 
b/mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp
index d96ed69982870b4..dfec17986800417 100644
--- a/mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp
+++ b/mlir/lib/Dialect/NVGPU/IR/NVGPUDialect.cpp
@@ -444,11 +444,11 @@ LogicalResult isAllowedSizeN(int sizeN, Type typeA) {
 176, 192, 208, 224, 240, 256};
   if (typeA.isBF16() || typeA.isF16() || typeA.isTF32() ||
   typeA.isFloat8E4M3FN() || typeA.isFloat8E5M2())
-if (llvm::any_of(allowedN, [&](int n) { return sizeN == n; }))
+if (llvm::is_contained(allowedN, sizeN))
   return success();
 
   if (typeA.isInteger(8) || typeA.isInteger(1))
-if (llvm::any_of(allowedNshort, [&](int n) { return sizeN == n; }))
+if (llvm::is_contained(allowedNshort, sizeN))
   return success();
   return failure();
 }



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


[clang] [clang] Implement constexpr bit_cast for vectors (PR #66894)

2023-09-22 Thread Richard Smith via cfe-commits


@@ -7095,6 +7096,40 @@ class APValueToBufferConverter {
 return true;
   }
 
+  bool visitVector(const APValue &Val, QualType Ty, CharUnits Offset) {
+const auto *VT = Ty->castAs();
+unsigned VectorLength = Val.getVectorLength();
+
+if (VT->isExtVectorBoolType()) {
+  // Special handling for OpenCL bool vectors: we need to pack the vector
+  // of 1-bit unsigned integers into a single integer with the 
corresponding
+  // bits set, then write out the resulting integer.
+
+  CharUnits VecWidthBits = Info.Ctx.getTypeSizeInChars(VT) * 8;
+
+  APSInt Bits(VecWidthBits.getQuantity());
+  for (unsigned I = 0; I != VectorLength; ++I) {
+const APValue &SubObj = Val.getVectorElt(I);
+assert(SubObj.isInt() && "Bool vector element isn't an int?");
+Bits.setBitVal(I, !SubObj.getInt().isZero());

zygoloid wrote:

I think that'd be fine. It doesn't seem like those vectors are well-supported 
elsewhere in Clang and LLVM (for example, I hit a miscompile bug #67060 while 
trying to figure out how they are stored in memory), so I think it's fine if 
they're also not well-supported by constant evaluation, at least for now.

https://github.com/llvm/llvm-project/pull/66894
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-09-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1


Changes

This change avoids a crash in BasicValueFactory by checking the bit width of an 
APSInt to avoid calling getZExtValue if greater than 64-bits. This was caught 
by our internal, randomized test generator.

Clang invocation
clang -cc1 -analyzer-checker=optin.portability.UnixAPI case.c

/llvm/include/llvm/ADT/APInt.h:1488:
uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64
  && "Too many bits for uint64_t"' failed.
...

 #9 
llvm::APInt::getZExtValue() const /llvm/include/llvm/ADT/APInt.h:1488:5 clang::BinaryOperatorKind, llvm::APSInt const&, llvm::APSInt const&) /clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:307:37 llvm::IntrusiveRefCntPtr, clang::BinaryOperatorKind, clang::ento::NonLoc, clang::ento::NonLoc, clang::QualType) /clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:531:31 llvm::IntrusiveRefCntPtr, clang::BinaryOperatorKind, clang::ento::SVal, clang::ento::SVal, clang::QualType) /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:532:26 ... --- Full diff: https://github.com/llvm/llvm-project/pull/67212.diff 2 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp (+6) - (added) clang/test/Analysis/int128-nocrash.c (+10) ``diff diff --git a/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp b/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp index 5924f6a671c2ac1..351735cdf42dc8f 100644 --- a/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp +++ b/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp @@ -275,6 +275,9 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op, if (V2.isSigned() && V2.isNegative()) return nullptr; + if (V2.getBitWidth() > 64) +return nullptr; + uint64_t Amt = V2.getZExtValue(); if (Amt >= V1.getBitWidth()) @@ -298,6 +301,9 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op, if (V2.isSigned() && V2.isNegative()) return nullptr; + if (V2.getBitWidth() > 64) +return nullptr; + uint64_t Amt = V2.getZExtValue(); if (Amt >= V1.getBitWidth()) diff --git a/clang/test/Analysis/int128-nocrash.c b/clang/test/Analysis/int128-nocrash.c new file mode 100644 index 000..0e9d2322080b8b8 --- /dev/null +++ b/clang/test/Analysis/int128-nocrash.c @@ -0,0 +1,10 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=optin.portability.UnixAPI \ +// RUN:-triple x86_64-pc-linux-gnu -x c %s + +// Don't crash! +// expected-no-diagnostics +const __int128_t a = ( ((__int128_t)1) << 64 | 1); + +void b() { + 2 >> a; +} `` https://github.com/llvm/llvm-project/pull/67212 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t integers (PR #67212)

2023-09-22 Thread via cfe-commits

https://github.com/vabridgers created 
https://github.com/llvm/llvm-project/pull/67212

This change avoids a crash in BasicValueFactory by checking the bit width of an 
APSInt to avoid calling getZExtValue if greater than 64-bits. This was caught 
by our internal, randomized test generator.

Clang invocation
clang -cc1 -analyzer-checker=optin.portability.UnixAPI case.c

/llvm/include/llvm/ADT/APInt.h:1488:
uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64
  && "Too many bits for uint64_t"' failed.
...

 #9  llvm::APInt::getZExtValue() const
 /llvm/include/llvm/ADT/APInt.h:1488:5
 clang::BinaryOperatorKind, llvm::APSInt const&, llvm::APSInt const&)
 /clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:307:37
 llvm::IntrusiveRefCntPtr,
 clang::BinaryOperatorKind, clang::ento::NonLoc, clang::ento::NonLoc,
 clang::QualType)
 /clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:531:31
 llvm::IntrusiveRefCntPtr,
 clang::BinaryOperatorKind, clang::ento::SVal, clang::ento::SVal,
 clang::QualType)
 /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:532:26
...

>From 48eab239bdee98edd52bfad52e1b938a1a7966b8 Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Sat, 23 Sep 2023 01:26:14 +0200
Subject: [PATCH] [analyzer] Fix crash in BasicValueFactory.cpp with __int128_t
 integers

This change avoids a crash in BasicValueFactory by checking the bit
width of an APSInt to avoid calling getZExtValue if greater than
64-bits.

Clang invocation
clang -cc1 -analyzer-checker=optin.portability.UnixAPI case.c

/llvm/include/llvm/ADT/APInt.h:1488:
uint64_t llvm::APInt::getZExtValue() const: Assertion `getActiveBits() <= 64
  && "Too many bits for uint64_t"' failed.
...

 #9  llvm::APInt::getZExtValue() const
 /llvm/include/llvm/ADT/APInt.h:1488:5
 clang::BinaryOperatorKind, llvm::APSInt const&, llvm::APSInt const&)
 /clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp:307:37
 llvm::IntrusiveRefCntPtr,
 clang::BinaryOperatorKind, clang::ento::NonLoc, clang::ento::NonLoc,
 clang::QualType)
 /clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp:531:31
 llvm::IntrusiveRefCntPtr,
 clang::BinaryOperatorKind, clang::ento::SVal, clang::ento::SVal,
 clang::QualType)
 /clang/lib/StaticAnalyzer/Core/SValBuilder.cpp:532:26
...
---
 clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp |  6 ++
 clang/test/Analysis/int128-nocrash.c| 10 ++
 2 files changed, 16 insertions(+)
 create mode 100644 clang/test/Analysis/int128-nocrash.c

diff --git a/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp 
b/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
index 5924f6a671c2ac1..351735cdf42dc8f 100644
--- a/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BasicValueFactory.cpp
@@ -275,6 +275,9 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op,
   if (V2.isSigned() && V2.isNegative())
 return nullptr;
 
+  if (V2.getBitWidth() > 64)
+return nullptr;
+
   uint64_t Amt = V2.getZExtValue();
 
   if (Amt >= V1.getBitWidth())
@@ -298,6 +301,9 @@ BasicValueFactory::evalAPSInt(BinaryOperator::Opcode Op,
   if (V2.isSigned() && V2.isNegative())
 return nullptr;
 
+  if (V2.getBitWidth() > 64)
+return nullptr;
+
   uint64_t Amt = V2.getZExtValue();
 
   if (Amt >= V1.getBitWidth())
diff --git a/clang/test/Analysis/int128-nocrash.c 
b/clang/test/Analysis/int128-nocrash.c
new file mode 100644
index 000..0e9d2322080b8b8
--- /dev/null
+++ b/clang/test/Analysis/int128-nocrash.c
@@ -0,0 +1,10 @@
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.portability.UnixAPI \
+// RUN:-triple x86_64-pc-linux-gnu -x c %s
+
+// Don't crash!
+// expected-no-diagnostics
+const __int128_t a = ( ((__int128_t)1) << 64 | 1);
+
+void b() { 
+  2 >> a; 
+}

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


[clang] [compiler-rt] Implement __extendxftf2 for x86_64 (PR #66918)

2023-09-22 Thread Alexander Shaposhnikov via cfe-commits

https://github.com/alexander-shaposhnikov updated 
https://github.com/llvm/llvm-project/pull/66918

>From 84cb5de329c228702da9f864312df31dc00692dc Mon Sep 17 00:00:00 2001
From: Alexander Shaposhnikov 
Date: Wed, 20 Sep 2023 14:25:46 +
Subject: [PATCH] Implement __extendxftf2 for x86_64

---
 compiler-rt/lib/builtins/CMakeLists.txt   |  1 +
 compiler-rt/lib/builtins/extendxftf2.c| 23 +++
 compiler-rt/lib/builtins/fp_extend.h  | 24 +++
 compiler-rt/lib/builtins/fp_extend_impl.inc   | 48 ++
 compiler-rt/test/builtins/Unit/addtf3_test.c  |  2 +-
 compiler-rt/test/builtins/Unit/divtf3_test.c  |  2 +-
 .../test/builtins/Unit/extenddftf2_test.c |  2 +-
 .../test/builtins/Unit/extendhftf2_test.c |  2 +-
 .../test/builtins/Unit/extendsftf2_test.c |  2 +-
 .../test/builtins/Unit/extendxftf2_test.c | 66 +++
 .../test/builtins/Unit/floatditf_test.c   |  2 +-
 .../test/builtins/Unit/floatsitf_test.c   |  2 +-
 .../test/builtins/Unit/floatunditf_test.c |  2 +-
 .../test/builtins/Unit/floatunsitf_test.c |  2 +-
 compiler-rt/test/builtins/Unit/fp_test.h  | 55 +---
 compiler-rt/test/builtins/Unit/multf3_test.c  |  2 +-
 compiler-rt/test/builtins/Unit/subtf3_test.c  |  2 +-
 17 files changed, 205 insertions(+), 34 deletions(-)
 create mode 100644 compiler-rt/lib/builtins/extendxftf2.c
 create mode 100644 compiler-rt/test/builtins/Unit/extendxftf2_test.c

diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index 43ef62ffb115d9d..b3e6e8c8b517d83 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -280,6 +280,7 @@ endif ()
 # long double is not 80 bits on Android or MSVC.
 set(x86_80_BIT_SOURCES
   divxc3.c
+  extendxftf2.c
   fixxfdi.c
   fixxfti.c
   fixunsxfdi.c
diff --git a/compiler-rt/lib/builtins/extendxftf2.c 
b/compiler-rt/lib/builtins/extendxftf2.c
new file mode 100644
index 000..aa5355e94839f93
--- /dev/null
+++ b/compiler-rt/lib/builtins/extendxftf2.c
@@ -0,0 +1,23 @@
+//===-- lib/extendxftf2.c - long double -> quad conversion *- C 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Assumption: long double is a IEEE 80 bit floating point type padded to 128
+// bits.
+
+// TODO: use fp_lib.h once QUAD_PRECISION is available on x86_64.
+#if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__) \
+   && (defined(__FLOAT128__) || 
defined(__SIZEOF_FLOAT128__))
+#define SRC_80
+#define DST_QUAD
+#include "fp_extend_impl.inc"
+
+COMPILER_RT_ABI __float128 __extendxftf2(long double a) {
+  return __extendXfYf2__(a);
+}
+
+#endif
diff --git a/compiler-rt/lib/builtins/fp_extend.h 
b/compiler-rt/lib/builtins/fp_extend.h
index eee4722bf90e69f..fc23c1c2d7a6a81 100644
--- a/compiler-rt/lib/builtins/fp_extend.h
+++ b/compiler-rt/lib/builtins/fp_extend.h
@@ -20,14 +20,18 @@
 typedef float src_t;
 typedef uint32_t src_rep_t;
 #define SRC_REP_C UINT32_C
+static const int srcBits = sizeof(src_t) * CHAR_BIT;
 static const int srcSigBits = 23;
+static const int srcSigFracBits = 23;
 #define src_rep_t_clz clzsi
 
 #elif defined SRC_DOUBLE
 typedef double src_t;
 typedef uint64_t src_rep_t;
 #define SRC_REP_C UINT64_C
+static const int srcBits = sizeof(src_t) * CHAR_BIT;
 static const int srcSigBits = 52;
+static const int srcSigFracBits = 52;
 static __inline int src_rep_t_clz(src_rep_t a) {
 #if defined __LP64__
   return __builtin_clzl(a);
@@ -39,6 +43,16 @@ static __inline int src_rep_t_clz(src_rep_t a) {
 #endif
 }
 
+#elif defined SRC_80
+typedef long double src_t;
+typedef __uint128_t src_rep_t;
+#define SRC_REP_C (__uint128_t)
+// sign bit, exponent and significand occupy the lower 80 bits.
+static const int srcBits = 80;
+// significand stores the integer bit.
+static const int srcSigBits = 64;
+static const int srcSigFracBits = 63;
+
 #elif defined SRC_HALF
 #ifdef COMPILER_RT_HAS_FLOAT16
 typedef _Float16 src_t;
@@ -47,7 +61,9 @@ typedef uint16_t src_t;
 #endif
 typedef uint16_t src_rep_t;
 #define SRC_REP_C UINT16_C
+static const int srcBits = sizeof(src_t) * CHAR_BIT;
 static const int srcSigBits = 10;
+static const int srcSigFracBits = 10;
 #define src_rep_t_clz __builtin_clz
 
 #else
@@ -59,18 +75,26 @@ typedef float dst_t;
 typedef uint32_t dst_rep_t;
 #define DST_REP_C UINT32_C
 static const int dstSigBits = 23;
+static const int dstSigFracBits = 23;
 
 #elif defined DST_DOUBLE
 typedef double dst_t;
 typedef uint64_t dst_rep_t;
 #define DST_REP_C UINT64_C
 static const int dstSigBits = 52;
+static const int dstSigFracBits = 52;
 
 #elif defined DST_QUAD
+// TODO: use fp_lib.h once QUAD_PRECISION is available on x86_64.
+#if __LDBL_MA

[clang-tools-extra] [compiler-rt] Implement __extendxftf2 for x86_64 (PR #66918)

2023-09-22 Thread Alexander Shaposhnikov via cfe-commits

https://github.com/alexander-shaposhnikov updated 
https://github.com/llvm/llvm-project/pull/66918

>From 84cb5de329c228702da9f864312df31dc00692dc Mon Sep 17 00:00:00 2001
From: Alexander Shaposhnikov 
Date: Wed, 20 Sep 2023 14:25:46 +
Subject: [PATCH] Implement __extendxftf2 for x86_64

---
 compiler-rt/lib/builtins/CMakeLists.txt   |  1 +
 compiler-rt/lib/builtins/extendxftf2.c| 23 +++
 compiler-rt/lib/builtins/fp_extend.h  | 24 +++
 compiler-rt/lib/builtins/fp_extend_impl.inc   | 48 ++
 compiler-rt/test/builtins/Unit/addtf3_test.c  |  2 +-
 compiler-rt/test/builtins/Unit/divtf3_test.c  |  2 +-
 .../test/builtins/Unit/extenddftf2_test.c |  2 +-
 .../test/builtins/Unit/extendhftf2_test.c |  2 +-
 .../test/builtins/Unit/extendsftf2_test.c |  2 +-
 .../test/builtins/Unit/extendxftf2_test.c | 66 +++
 .../test/builtins/Unit/floatditf_test.c   |  2 +-
 .../test/builtins/Unit/floatsitf_test.c   |  2 +-
 .../test/builtins/Unit/floatunditf_test.c |  2 +-
 .../test/builtins/Unit/floatunsitf_test.c |  2 +-
 compiler-rt/test/builtins/Unit/fp_test.h  | 55 +---
 compiler-rt/test/builtins/Unit/multf3_test.c  |  2 +-
 compiler-rt/test/builtins/Unit/subtf3_test.c  |  2 +-
 17 files changed, 205 insertions(+), 34 deletions(-)
 create mode 100644 compiler-rt/lib/builtins/extendxftf2.c
 create mode 100644 compiler-rt/test/builtins/Unit/extendxftf2_test.c

diff --git a/compiler-rt/lib/builtins/CMakeLists.txt 
b/compiler-rt/lib/builtins/CMakeLists.txt
index 43ef62ffb115d9d..b3e6e8c8b517d83 100644
--- a/compiler-rt/lib/builtins/CMakeLists.txt
+++ b/compiler-rt/lib/builtins/CMakeLists.txt
@@ -280,6 +280,7 @@ endif ()
 # long double is not 80 bits on Android or MSVC.
 set(x86_80_BIT_SOURCES
   divxc3.c
+  extendxftf2.c
   fixxfdi.c
   fixxfti.c
   fixunsxfdi.c
diff --git a/compiler-rt/lib/builtins/extendxftf2.c 
b/compiler-rt/lib/builtins/extendxftf2.c
new file mode 100644
index 000..aa5355e94839f93
--- /dev/null
+++ b/compiler-rt/lib/builtins/extendxftf2.c
@@ -0,0 +1,23 @@
+//===-- lib/extendxftf2.c - long double -> quad conversion *- C 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+// Assumption: long double is a IEEE 80 bit floating point type padded to 128
+// bits.
+
+// TODO: use fp_lib.h once QUAD_PRECISION is available on x86_64.
+#if __LDBL_MANT_DIG__ == 64 && defined(__x86_64__) \
+   && (defined(__FLOAT128__) || 
defined(__SIZEOF_FLOAT128__))
+#define SRC_80
+#define DST_QUAD
+#include "fp_extend_impl.inc"
+
+COMPILER_RT_ABI __float128 __extendxftf2(long double a) {
+  return __extendXfYf2__(a);
+}
+
+#endif
diff --git a/compiler-rt/lib/builtins/fp_extend.h 
b/compiler-rt/lib/builtins/fp_extend.h
index eee4722bf90e69f..fc23c1c2d7a6a81 100644
--- a/compiler-rt/lib/builtins/fp_extend.h
+++ b/compiler-rt/lib/builtins/fp_extend.h
@@ -20,14 +20,18 @@
 typedef float src_t;
 typedef uint32_t src_rep_t;
 #define SRC_REP_C UINT32_C
+static const int srcBits = sizeof(src_t) * CHAR_BIT;
 static const int srcSigBits = 23;
+static const int srcSigFracBits = 23;
 #define src_rep_t_clz clzsi
 
 #elif defined SRC_DOUBLE
 typedef double src_t;
 typedef uint64_t src_rep_t;
 #define SRC_REP_C UINT64_C
+static const int srcBits = sizeof(src_t) * CHAR_BIT;
 static const int srcSigBits = 52;
+static const int srcSigFracBits = 52;
 static __inline int src_rep_t_clz(src_rep_t a) {
 #if defined __LP64__
   return __builtin_clzl(a);
@@ -39,6 +43,16 @@ static __inline int src_rep_t_clz(src_rep_t a) {
 #endif
 }
 
+#elif defined SRC_80
+typedef long double src_t;
+typedef __uint128_t src_rep_t;
+#define SRC_REP_C (__uint128_t)
+// sign bit, exponent and significand occupy the lower 80 bits.
+static const int srcBits = 80;
+// significand stores the integer bit.
+static const int srcSigBits = 64;
+static const int srcSigFracBits = 63;
+
 #elif defined SRC_HALF
 #ifdef COMPILER_RT_HAS_FLOAT16
 typedef _Float16 src_t;
@@ -47,7 +61,9 @@ typedef uint16_t src_t;
 #endif
 typedef uint16_t src_rep_t;
 #define SRC_REP_C UINT16_C
+static const int srcBits = sizeof(src_t) * CHAR_BIT;
 static const int srcSigBits = 10;
+static const int srcSigFracBits = 10;
 #define src_rep_t_clz __builtin_clz
 
 #else
@@ -59,18 +75,26 @@ typedef float dst_t;
 typedef uint32_t dst_rep_t;
 #define DST_REP_C UINT32_C
 static const int dstSigBits = 23;
+static const int dstSigFracBits = 23;
 
 #elif defined DST_DOUBLE
 typedef double dst_t;
 typedef uint64_t dst_rep_t;
 #define DST_REP_C UINT64_C
 static const int dstSigBits = 52;
+static const int dstSigFracBits = 52;
 
 #elif defined DST_QUAD
+// TODO: use fp_lib.h once QUAD_PRECISION is available on x86_64.
+#if __LDBL_MA

[clang] [Driver] Move assertion check before checking Output.isFilename (PR #67210)

2023-09-22 Thread Brad Smith via cfe-commits

https://github.com/brad0 created https://github.com/llvm/llvm-project/pull/67210

None

>From 39053d20aeec2fea1d0ef14bd9dde6a3454f83a7 Mon Sep 17 00:00:00 2001
From: Brad Smith 
Date: Fri, 22 Sep 2023 19:35:21 -0400
Subject: [PATCH] [Driver] Move assertion check before checking
 Output.isFilename

---
 clang/lib/Driver/ToolChains/Cuda.cpp  | 6 +++---
 clang/lib/Driver/ToolChains/DragonFly.cpp | 3 +--
 clang/lib/Driver/ToolChains/Flang.cpp | 3 +--
 clang/lib/Driver/ToolChains/FreeBSD.cpp   | 3 +--
 clang/lib/Driver/ToolChains/Gnu.cpp   | 2 +-
 clang/lib/Driver/ToolChains/Hexagon.cpp   | 2 +-
 clang/lib/Driver/ToolChains/NetBSD.cpp| 3 +--
 clang/lib/Driver/ToolChains/OpenBSD.cpp   | 3 +--
 clang/lib/Driver/ToolChains/PS4CPU.cpp| 3 +--
 clang/lib/Driver/ToolChains/Solaris.cpp   | 3 +--
 clang/lib/Driver/ToolChains/XCore.cpp | 3 +--
 11 files changed, 13 insertions(+), 21 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp 
b/clang/lib/Driver/ToolChains/Cuda.cpp
index 97472a302715bb9..e95ff98e6c940f1 100644
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -572,14 +572,14 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
  const char *LinkingOutput) const {
   const auto &TC =
   static_cast(getToolChain());
+  ArgStringList CmdArgs;
+
   assert(TC.getTriple().isNVPTX() && "Wrong platform");
 
-  ArgStringList CmdArgs;
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
   }
 
   if (mustEmitDebugInfo(Args) == EmitSameDebugInfoAsHost)
diff --git a/clang/lib/Driver/ToolChains/DragonFly.cpp 
b/clang/lib/Driver/ToolChains/DragonFly.cpp
index 82c975990a32511..a1e4937231572b7 100644
--- a/clang/lib/Driver/ToolChains/DragonFly.cpp
+++ b/clang/lib/Driver/ToolChains/DragonFly.cpp
@@ -85,11 +85,10 @@ void dragonfly::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back("elf_i386");
   }
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 11c9d90c701f0ce..10f785ce7ab9075 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -565,11 +565,10 @@ void Flang::ConstructJob(Compilation &C, const JobAction 
&JA,
 }
   }
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
   }
 
   assert(Input.isFilename() && "Invalid input.");
diff --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 4c46861bbbd74ef..636828b0171fe41 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -232,11 +232,10 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 }
   }
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
-  } else {
-assert(Output.isNothing() && "Invalid output.");
   }
 
   if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 1b4a94d72cc0a66..5949d9872c54f72 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -117,11 +117,11 @@ void tools::gcc::Common::ConstructJob(Compilation &C, 
const JobAction &JA,
 break;
   }
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
   } else {
-assert(Output.isNothing() && "Unexpected output");
 CmdArgs.push_back("-fsyntax-only");
   }
 
diff --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 0d6980c003a72b5..e7dca1053dc8d8a 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -218,11 +218,11 @@ void hexagon::Assembler::ConstructJob(Compilation &C, 
const JobAction &JA,
 
   addSanitizerRuntimes(HTC, Args, CmdArgs);
 
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
   if (Output.isFilename()) {
 CmdArgs.push_back("-o");
 CmdArgs.push_back(Output.getFilename());
   } e

[libunwind] [libunwind] Pass -Wl,--export-dynamic on all supported platforms (PR #67205)

2023-09-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind


Changes

I was trying to run the tests on FreeBSD and noticed that we weren't printing 
symbol names. It turns out this is because of the missing -Wl,--export dynamic 
flag. Instead of hardcoding the name of the flag and only passing it for Linux 
hosts, use a pre-existing CMake variable instead. I was not aware of this flag, 
but it appears to have been supported for the past 16 years (with support for 
more platforms added later): 
https://gitlab.kitware.com/cmake/cmake/-/commit/66d1930f5674f08e09f455b3f0777f2de3e0717e

---
Full diff: https://github.com/llvm/llvm-project/pull/67205.diff


3 Files Affected:

- (modified) libunwind/test/configs/llvm-libunwind-merged.cfg.in (+4-2) 
- (modified) libunwind/test/configs/llvm-libunwind-shared.cfg.in (+4-2) 
- (modified) libunwind/test/configs/llvm-libunwind-static.cfg.in (+4-2) 


``diff
diff --git a/libunwind/test/configs/llvm-libunwind-merged.cfg.in 
b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
index 10650f7edf66a2f..e6fafd1edd9756f 100644
--- a/libunwind/test/configs/llvm-libunwind-merged.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
@@ -11,8 +11,10 @@ link_flags = []
 if @LIBUNWIND_ENABLE_CET@:
 compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).
+if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
+link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')
 
 if '@CMAKE_DL_LIBS@':
 link_flags.append('-l@CMAKE_DL_LIBS@')
diff --git a/libunwind/test/configs/llvm-libunwind-shared.cfg.in 
b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
index 97185e57234ff7f..f2e98c7a388dd32 100644
--- a/libunwind/test/configs/llvm-libunwind-shared.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
@@ -10,8 +10,10 @@ link_flags = []
 if @LIBUNWIND_ENABLE_CET@:
 compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).
+if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
+link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')
 
 if '@CMAKE_DL_LIBS@':
 link_flags.append('-l@CMAKE_DL_LIBS@')
diff --git a/libunwind/test/configs/llvm-libunwind-static.cfg.in 
b/libunwind/test/configs/llvm-libunwind-static.cfg.in
index fc6a18d057f3884..1fbdec249855d4a 100644
--- a/libunwind/test/configs/llvm-libunwind-static.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-static.cfg.in
@@ -13,8 +13,10 @@ if @LIBUNWIND_ENABLE_THREADS@:
 if @LIBUNWIND_ENABLE_CET@:
 compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).
+if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
+link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')
 
 if '@CMAKE_DL_LIBS@':
 link_flags.append('-l@CMAKE_DL_LIBS@')

``




https://github.com/llvm/llvm-project/pull/67205
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [libunwind] Pass -Wl,--export-dynamic on all supported platforms (PR #67205)

2023-09-22 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson created 
https://github.com/llvm/llvm-project/pull/67205

I was trying to run the tests on FreeBSD and noticed that we weren't printing 
symbol names. It turns out this is because of the missing -Wl,--export dynamic 
flag. Instead of hardcoding the name of the flag and only passing it for Linux 
hosts, use a pre-existing CMake variable instead. I was not aware of this flag, 
but it appears to have been supported for the past 16 years (with support for 
more platforms added later): 
https://gitlab.kitware.com/cmake/cmake/-/commit/66d1930f5674f08e09f455b3f0777f2de3e0717e

>From 6f459b7cf539c17192e765578ac9f938e4f3af3f Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Fri, 22 Sep 2023 16:11:49 -0700
Subject: [PATCH] [libunwind] Pass -Wl,--export-dynamic on all supported
 platforms

I was trying to run the tests on FreeBSD and noticed that we weren't
printing symbol names. It turns out this is because of the missing
-Wl,--export dynamic flag. Instead of hardcoding the name of the flag
and only passing it for Linux hosts, use a pre-existing CMake variable
instead. I was not aware of this flag, but it appears to have been
supported for the past 16 years (with support for more platforms added
later): 
https://gitlab.kitware.com/cmake/cmake/-/commit/66d1930f5674f08e09f455b3f0777f2de3e0717e
---
 libunwind/test/configs/llvm-libunwind-merged.cfg.in | 6 --
 libunwind/test/configs/llvm-libunwind-shared.cfg.in | 6 --
 libunwind/test/configs/llvm-libunwind-static.cfg.in | 6 --
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/libunwind/test/configs/llvm-libunwind-merged.cfg.in 
b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
index 10650f7edf66a2f..e6fafd1edd9756f 100644
--- a/libunwind/test/configs/llvm-libunwind-merged.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-merged.cfg.in
@@ -11,8 +11,10 @@ link_flags = []
 if @LIBUNWIND_ENABLE_CET@:
 compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).
+if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
+link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')
 
 if '@CMAKE_DL_LIBS@':
 link_flags.append('-l@CMAKE_DL_LIBS@')
diff --git a/libunwind/test/configs/llvm-libunwind-shared.cfg.in 
b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
index 97185e57234ff7f..f2e98c7a388dd32 100644
--- a/libunwind/test/configs/llvm-libunwind-shared.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-shared.cfg.in
@@ -10,8 +10,10 @@ link_flags = []
 if @LIBUNWIND_ENABLE_CET@:
 compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).
+if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
+link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')
 
 if '@CMAKE_DL_LIBS@':
 link_flags.append('-l@CMAKE_DL_LIBS@')
diff --git a/libunwind/test/configs/llvm-libunwind-static.cfg.in 
b/libunwind/test/configs/llvm-libunwind-static.cfg.in
index fc6a18d057f3884..1fbdec249855d4a 100644
--- a/libunwind/test/configs/llvm-libunwind-static.cfg.in
+++ b/libunwind/test/configs/llvm-libunwind-static.cfg.in
@@ -13,8 +13,10 @@ if @LIBUNWIND_ENABLE_THREADS@:
 if @LIBUNWIND_ENABLE_CET@:
 compile_flags.append('-fcf-protection=full')
 
-if '@CMAKE_SYSTEM_NAME@' == 'Linux':
-link_flags.append('-Wl,--export-dynamic')
+# Add -Wl,--export-dynamic if supported by the linker (this CMake variable will
+# be empty for Apple platforms).
+if len('@CMAKE_EXE_EXPORTS_CXX_FLAG@'):
+link_flags.append('@CMAKE_EXE_EXPORTS_CXX_FLAG@')
 
 if '@CMAKE_DL_LIBS@':
 link_flags.append('-l@CMAKE_DL_LIBS@')

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


[clang] e1a5bb5 - [ORC][LLJIT] Move enable-debugger-support utility out of LLJITBuilder.

2023-09-22 Thread Lang Hames via cfe-commits

Author: Lang Hames
Date: 2023-09-22T16:18:20-07:00
New Revision: e1a5bb59b91d60c0d87feb78f0e0614589a4c927

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

LOG: [ORC][LLJIT] Move enable-debugger-support utility out of LLJITBuilder.

This change means that debugger support only needs to be linked in if it's
used. The code size of debugger support is expected to increase as we improve
it (e.g. pulling in DWARF parsing), so making it an optional extra is useful
for controlling final binary sizes.

Added: 
llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h
llvm/lib/ExecutionEngine/Orc/DebuggerSupport.cpp

Modified: 
clang/lib/Interpreter/IncrementalExecutor.cpp
clang/tools/clang-repl/ClangRepl.cpp
clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
clang/unittests/Interpreter/InterpreterTest.cpp
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
llvm/lib/ExecutionEngine/Orc/CMakeLists.txt
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
llvm/tools/lli/lli.cpp

Removed: 




diff  --git a/clang/lib/Interpreter/IncrementalExecutor.cpp 
b/clang/lib/Interpreter/IncrementalExecutor.cpp
index 2c4dfc9a611e021..2692d0618b8649e 100644
--- a/clang/lib/Interpreter/IncrementalExecutor.cpp
+++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
@@ -17,6 +17,7 @@
 #include "clang/Interpreter/PartialTranslationUnit.h"
 #include "llvm/ExecutionEngine/ExecutionEngine.h"
 #include "llvm/ExecutionEngine/Orc/CompileUtils.h"
+#include "llvm/ExecutionEngine/Orc/DebuggerSupport.h"
 #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
 #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
@@ -46,8 +47,13 @@ 
IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
   JTMB.addFeatures(TI.getTargetOpts().Features);
   LLJITBuilder Builder;
   Builder.setJITTargetMachineBuilder(JTMB);
-  // Enable debugging of JIT'd code (only works on JITLink for ELF and MachO).
-  Builder.setEnableDebuggerSupport(true);
+  Builder.setPrePlatformSetup(
+  [](LLJIT &J) {
+// Try to enable debugging of JIT'd code (only works with JITLink for
+// ELF and MachO).
+consumeError(enableDebuggerSupport(J));
+return llvm::Error::success();
+  });
 
   if (auto JitOrErr = Builder.create())
 Jit = std::move(*JitOrErr);

diff  --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index 51741fd1a27ef4a..a29a2ebac434ab5 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/ClangRepl.cpp
@@ -152,9 +152,7 @@ int main(int argc, const char **argv) {
   llvm::InitializeAllAsmPrinters();
 
   if (OptHostSupportsJit) {
-auto J = llvm::orc::LLJITBuilder()
-   .setEnableDebuggerSupport(true)
-   .create();
+auto J = llvm::orc::LLJITBuilder().create();
 if (J)
   llvm::outs() << "true\n";
 else {

diff  --git 
a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp 
b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
index 8700f506d9b17d4..70e10b1e53bd9d6 100644
--- a/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
+++ b/clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp
@@ -52,9 +52,7 @@ TEST(InterpreterTest, CatchException) {
   llvm::InitializeNativeTargetAsmPrinter();
 
   {
-auto J = llvm::orc::LLJITBuilder()
- .setEnableDebuggerSupport(true)
- .create();
+auto J = llvm::orc::LLJITBuilder().create();
 if (!J) {
   // The platform does not support JITs.
   // Using llvm::consumeError will require typeinfo for ErrorInfoBase, we

diff  --git a/clang/unittests/Interpreter/InterpreterTest.cpp 
b/clang/unittests/Interpreter/InterpreterTest.cpp
index 62e5bacbdd0b6d8..5f2911e9a7adad3 100644
--- a/clang/unittests/Interpreter/InterpreterTest.cpp
+++ b/clang/unittests/Interpreter/InterpreterTest.cpp
@@ -191,9 +191,7 @@ static std::string MangleName(NamedDecl *ND) {
 }
 
 static bool HostSupportsJit() {
-  auto J = llvm::orc::LLJITBuilder()
- .setEnableDebuggerSupport(true)
- .create();
+  auto J = llvm::orc::LLJITBuilder().create();
   if (J)
 return true;
   LLVMConsumeError(llvm::wrap(J.takeError()));

diff  --git a/llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h 
b/llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h
new file mode 100644
index 000..1b47d7d41bb9b5a
--- /dev/null
+++ b/llvm/include/llvm/ExecutionEngine/Orc/DebuggerSupport.h
@@ -0,0 +1,28 @@
+//===-- DebugerSupport.h - Utils for enabling debugger support --*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+//

[libunwind] ab78962 - [libunwind] Relax a REQUIRES on a test that passes on FreeBSD

2023-09-22 Thread Alex Richardson via cfe-commits

Author: Alex Richardson
Date: 2023-09-22T16:16:16-07:00
New Revision: ab7896231e176e52801702b7221bcac2f4ffbd59

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

LOG: [libunwind] Relax a REQUIRES on a test that passes on FreeBSD

Added: 


Modified: 
libunwind/test/forceunwind.pass.cpp

Removed: 




diff  --git a/libunwind/test/forceunwind.pass.cpp 
b/libunwind/test/forceunwind.pass.cpp
index 8c26551b6d0b678..265b2ec6a49a469 100644
--- a/libunwind/test/forceunwind.pass.cpp
+++ b/libunwind/test/forceunwind.pass.cpp
@@ -7,7 +7,7 @@
 //
 
//===--===//
 
-// REQUIRES: linux
+// REQUIRES: linux || freebsd
 
 // TODO: Figure out why this fails with Memory Sanitizer.
 // XFAIL: msan



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


[clang] [clang][modules] Move `SLocEntry` search into `ASTReader` (PR #66966)

2023-09-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 ready_for_review 
https://github.com/llvm/llvm-project/pull/66966
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Move `SLocEntry` search into `ASTReader` (PR #66966)

2023-09-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 edited 
https://github.com/llvm/llvm-project/pull/66966
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] [libunwind][libc++][libc++abi] Add cross-compilation flags to tests (PR #67201)

2023-09-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind


Changes

There is currently only limited support for passing target-specific flags (e.g. 
-mabi= or -march=) to the testsuites if you don't have a compiler (or wrapper 
script) that defaults to the expected flags. However, some targets (e.g. 
RISC-V) may require additional flags beyond the basic --target= that is already 
added by the current infrastructure.

When cross-compiling with CMake, the recommended approach is to define a 
toolchain file that specifies the necessary flags needed to compile for a given 
target. There are two interesting variables here that we should also be passing 
when building the test binaries:
- CMAKE_CXX_FLAGS_INIT defines the flags we need for compilation jobs and will 
specify flags such as -mabi= and -march=
- CMAKE_EXE_LINKER_FLAGS_INIT defines the linker flags that are needed to 
cross-compile for a given target. When not cross-compiling these variables will 
generally be empty.

This patch only adds these flags to the default libc++ configurations, but if 
the clang-cl/gcc configurations could also benefit from this I'll update the 
patch.

This should be a possible alternative to https://reviews.llvm.org/D151056 and 
https://github.com/llvm/llvm-project/pull/65517

---
Full diff: https://github.com/llvm/llvm-project/pull/67201.diff


8 Files Affected:

- (modified) libcxx/test/configs/llvm-libc++-shared.cfg.in (+2-2) 
- (modified) libcxx/test/configs/llvm-libc++-static.cfg.in (+2-2) 
- (modified) libcxxabi/test/configs/llvm-libc++abi-merged.cfg.in (+2-2) 
- (modified) libcxxabi/test/configs/llvm-libc++abi-shared.cfg.in (+2-2) 
- (modified) libcxxabi/test/configs/llvm-libc++abi-static.cfg.in (+2-2) 
- (modified) libunwind/test/configs/llvm-libunwind-merged.cfg.in (+2-2) 
- (modified) libunwind/test/configs/llvm-libunwind-shared.cfg.in (+2-2) 
- (modified) libunwind/test/configs/llvm-libunwind-static.cfg.in (+2-2) 


``diff
diff --git a/libcxx/test/configs/llvm-libc++-shared.cfg.in 
b/libcxx/test/configs/llvm-libc++-shared.cfg.in
index 143b3b3feae1109..82e7129d8f166a0 100644
--- a/libcxx/test/configs/llvm-libc++-shared.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-shared.cfg.in
@@ -7,10 +7,10 @@ config.substitutions.append(('%{flags}',
 '-pthread' + (' -isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if 
'@CMAKE_OSX_SYSROOT@' else '')
 ))
 config.substitutions.append(('%{compile_flags}',
-'-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support'
+'@CMAKE_CXX_FLAGS_INIT@ -nostdinc++ -I %{include} -I %{target-include} -I 
%{libcxx}/test/support'
 ))
 config.substitutions.append(('%{link_flags}',
-'-nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++'
+'@CMAKE_EXE_LINKER_FLAGS_INIT@ -nostdlib++ -L %{lib} -Wl,-rpath,%{lib} 
-lc++'
 ))
 config.substitutions.append(('%{exec}',
 '%{executor} --execdir %T -- '
diff --git a/libcxx/test/configs/llvm-libc++-static.cfg.in 
b/libcxx/test/configs/llvm-libc++-static.cfg.in
index e866d4f52a0629d..3dc4af1c000d59f 100644
--- a/libcxx/test/configs/llvm-libc++-static.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-static.cfg.in
@@ -7,10 +7,10 @@ config.substitutions.append(('%{flags}',
 '-pthread' + (' -isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if 
'@CMAKE_OSX_SYSROOT@' else '')
 ))
 config.substitutions.append(('%{compile_flags}',
-'-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support'
+'@CMAKE_CXX_FLAGS_INIT@ -nostdinc++ -I %{include} -I %{target-include} -I 
%{libcxx}/test/support'
 ))
 config.substitutions.append(('%{link_flags}',
-'-nostdlib++ -L %{lib} -lc++ -lc++abi'
+'@CMAKE_EXE_LINKER_FLAGS_INIT@ -nostdlib++ -L %{lib} -lc++ -lc++abi'
 ))
 config.substitutions.append(('%{exec}',
 '%{executor} --execdir %T -- '
diff --git a/libcxxabi/test/configs/llvm-libc++abi-merged.cfg.in 
b/libcxxabi/test/configs/llvm-libc++abi-merged.cfg.in
index c6fa4301b459ce9..861fc26baccaaf7 100644
--- a/libcxxabi/test/configs/llvm-libc++abi-merged.cfg.in
+++ b/libcxxabi/test/configs/llvm-libc++abi-merged.cfg.in
@@ -6,11 +6,11 @@ config.substitutions.append(('%{flags}',
 '-isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if '@CMAKE_OSX_SYSROOT@' else 
''
 ))
 config.substitutions.append(('%{compile_flags}',
-'-nostdinc++ -I %{include} -I %{cxx-include} -I %{cxx-target-include} 
%{maybe-include-libunwind} -D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS 
' +
+'@CMAKE_CXX_FLAGS_INIT@ -nostdinc++ -I %{include} -I %{cxx-include} -I 
%{cxx-target-include} %{maybe-include-libunwind} 
-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS ' +
 '-I %{libcxx}/test/support -I %{libcxx}/src'
 ))
 config.substitutions.append(('%{link_flags}',
-'-nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++ -pthread'
+'@CMAKE_EXE_LINKER_FLAGS_INIT@ -nostdlib++ -L %{lib} -Wl,-rpath,%{lib} 
-lc++ -pthread'
 ))
 config.substitutions.append(('%{exec}',
 '%{executor} --execdir %T -- '
diff --git a/libcxxabi/test/configs/llvm-libc++abi-shared.

[libunwind] [libunwind][libc++][libc++abi] Add cross-compilation flags to tests (PR #67201)

2023-09-22 Thread Alexander Richardson via cfe-commits

https://github.com/arichardson created 
https://github.com/llvm/llvm-project/pull/67201

There is currently only limited support for passing target-specific flags (e.g. 
-mabi= or -march=) to the testsuites if you don't have a compiler (or wrapper 
script) that defaults to the expected flags. However, some targets (e.g. 
RISC-V) may require additional flags beyond the basic --target= that is already 
added by the current infrastructure.

When cross-compiling with CMake, the recommended approach is to define a 
toolchain file that specifies the necessary flags needed to compile for a given 
target. There are two interesting variables here that we should also be passing 
when building the test binaries:
- CMAKE_CXX_FLAGS_INIT defines the flags we need for compilation jobs and will 
specify flags such as -mabi= and -march=
- CMAKE_EXE_LINKER_FLAGS_INIT defines the linker flags that are needed to 
cross-compile for a given target. When not cross-compiling these variables will 
generally be empty.

This patch only adds these flags to the default libc++ configurations, but if 
the clang-cl/gcc configurations could also benefit from this I'll update the 
patch.

This should be a possible alternative to https://reviews.llvm.org/D151056 and 
https://github.com/llvm/llvm-project/pull/65517

>From 72464ba171bc303f692f9a73012a4d1060ca0dda Mon Sep 17 00:00:00 2001
From: Alex Richardson 
Date: Wed, 6 Sep 2023 11:41:56 -0700
Subject: [PATCH] [libunwind][libc++][libc++abi] Add cross-compilation flags to
 tests

There is currently only limited support for passing target-specific
flags (e.g. -mabi= or -march=) to the testsuites if you don't have a
compiler (or wrapper script) that defaults to the expected flags.
However, some targets (e.g. RISC-V) may require additional flags beyond
the basic --target= that is already added by the current infrastructure.

When cross-compiling with CMake, the recommended approach is to define
a toolchain file that specifies the necessary flags needed to compile for
a given target. There are two interesting variables here that we should
also be passing when building the test binaries:
- CMAKE_CXX_FLAGS_INIT defines the flags we need for compilation jobs
   and will specify flags such as -mabi= and -march=
- CMAKE_EXE_LINKER_FLAGS_INIT defines the linker flags that are needed to
  cross-compile for a given target.
When not cross-compiling these variables will generally be empty.

This patch only adds these flags to the default libc++ configurations, but
if the clang-cl/gcc configurations could also benefit from this I'll update
the patch.
---
 libcxx/test/configs/llvm-libc++-shared.cfg.in   | 4 ++--
 libcxx/test/configs/llvm-libc++-static.cfg.in   | 4 ++--
 libcxxabi/test/configs/llvm-libc++abi-merged.cfg.in | 4 ++--
 libcxxabi/test/configs/llvm-libc++abi-shared.cfg.in | 4 ++--
 libcxxabi/test/configs/llvm-libc++abi-static.cfg.in | 4 ++--
 libunwind/test/configs/llvm-libunwind-merged.cfg.in | 4 ++--
 libunwind/test/configs/llvm-libunwind-shared.cfg.in | 4 ++--
 libunwind/test/configs/llvm-libunwind-static.cfg.in | 4 ++--
 8 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/libcxx/test/configs/llvm-libc++-shared.cfg.in 
b/libcxx/test/configs/llvm-libc++-shared.cfg.in
index 143b3b3feae1109..82e7129d8f166a0 100644
--- a/libcxx/test/configs/llvm-libc++-shared.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-shared.cfg.in
@@ -7,10 +7,10 @@ config.substitutions.append(('%{flags}',
 '-pthread' + (' -isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if 
'@CMAKE_OSX_SYSROOT@' else '')
 ))
 config.substitutions.append(('%{compile_flags}',
-'-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support'
+'@CMAKE_CXX_FLAGS_INIT@ -nostdinc++ -I %{include} -I %{target-include} -I 
%{libcxx}/test/support'
 ))
 config.substitutions.append(('%{link_flags}',
-'-nostdlib++ -L %{lib} -Wl,-rpath,%{lib} -lc++'
+'@CMAKE_EXE_LINKER_FLAGS_INIT@ -nostdlib++ -L %{lib} -Wl,-rpath,%{lib} 
-lc++'
 ))
 config.substitutions.append(('%{exec}',
 '%{executor} --execdir %T -- '
diff --git a/libcxx/test/configs/llvm-libc++-static.cfg.in 
b/libcxx/test/configs/llvm-libc++-static.cfg.in
index e866d4f52a0629d..3dc4af1c000d59f 100644
--- a/libcxx/test/configs/llvm-libc++-static.cfg.in
+++ b/libcxx/test/configs/llvm-libc++-static.cfg.in
@@ -7,10 +7,10 @@ config.substitutions.append(('%{flags}',
 '-pthread' + (' -isysroot {}'.format('@CMAKE_OSX_SYSROOT@') if 
'@CMAKE_OSX_SYSROOT@' else '')
 ))
 config.substitutions.append(('%{compile_flags}',
-'-nostdinc++ -I %{include} -I %{target-include} -I %{libcxx}/test/support'
+'@CMAKE_CXX_FLAGS_INIT@ -nostdinc++ -I %{include} -I %{target-include} -I 
%{libcxx}/test/support'
 ))
 config.substitutions.append(('%{link_flags}',
-'-nostdlib++ -L %{lib} -lc++ -lc++abi'
+'@CMAKE_EXE_LINKER_FLAGS_INIT@ -nostdlib++ -L %{lib} -lc++ -lc++abi'
 ))
 config.substitutions.append(('%{exec}',
 '%{executor} --execdir %T -- '
diff --git a/libcx

[PATCH] D152206: [Basic] Support 64-bit x86 target for UEFI

2023-09-22 Thread Prabhu Karthikeyan Rajasekaran via Phabricator via cfe-commits
Prabhuk updated this revision to Diff 557263.
Prabhuk added a comment.

Updated the test name and added comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152206

Files:
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/TargetParser/Triple.cpp
  llvm/unittests/IR/DataLayoutTest.cpp
  llvm/unittests/TargetParser/TripleTest.cpp


Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -462,6 +462,7 @@
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::UEFI, T.getOS());
   EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+  EXPECT_EQ(Triple::COFF, T.getObjectFormat());
 
   T = Triple("wasm32-unknown-unknown");
   EXPECT_EQ(Triple::wasm32, T.getArch());
Index: llvm/unittests/IR/DataLayoutTest.cpp
===
--- llvm/unittests/IR/DataLayoutTest.cpp
+++ llvm/unittests/IR/DataLayoutTest.cpp
@@ -11,6 +11,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
+#include "llvm/TargetParser/Triple.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 
@@ -104,4 +105,11 @@
   EXPECT_EQ(Align(4 * 8), DL->getPrefTypeAlign(V8F32Ty));
 }
 
+TEST(DataLayoutTest, UEFI) {
+  Triple TT = Triple("x86_64-unknown-uefi");
+
+  // Test UEFI X86_64 Mangling Component.
+  EXPECT_STREQ(DataLayout::getManglingComponent(TT), "-m:w");
+}
+
 } // anonymous namespace
Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -799,6 +799,8 @@
   case Triple::x86_64:
 if (T.isOSWindows())
   return Triple::COFF;
+else if (T.isUEFI())
+  return Triple::COFF;
 return Triple::ELF;
 
   case Triple::aarch64_be:
Index: llvm/lib/IR/DataLayout.cpp
===
--- llvm/lib/IR/DataLayout.cpp
+++ llvm/lib/IR/DataLayout.cpp
@@ -171,7 +171,7 @@
 return "-m:l";
   if (T.isOSBinFormatMachO())
 return "-m:o";
-  if (T.isOSWindows() && T.isOSBinFormatCOFF())
+  if ((T.isOSWindows() || T.isUEFI()) && T.isOSBinFormatCOFF())
 return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";
   if (T.isOSBinFormatXCOFF())
 return "-m:a";


Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -462,6 +462,7 @@
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::UEFI, T.getOS());
   EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+  EXPECT_EQ(Triple::COFF, T.getObjectFormat());
 
   T = Triple("wasm32-unknown-unknown");
   EXPECT_EQ(Triple::wasm32, T.getArch());
Index: llvm/unittests/IR/DataLayoutTest.cpp
===
--- llvm/unittests/IR/DataLayoutTest.cpp
+++ llvm/unittests/IR/DataLayoutTest.cpp
@@ -11,6 +11,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
+#include "llvm/TargetParser/Triple.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 
@@ -104,4 +105,11 @@
   EXPECT_EQ(Align(4 * 8), DL->getPrefTypeAlign(V8F32Ty));
 }
 
+TEST(DataLayoutTest, UEFI) {
+  Triple TT = Triple("x86_64-unknown-uefi");
+
+  // Test UEFI X86_64 Mangling Component.
+  EXPECT_STREQ(DataLayout::getManglingComponent(TT), "-m:w");
+}
+
 } // anonymous namespace
Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -799,6 +799,8 @@
   case Triple::x86_64:
 if (T.isOSWindows())
   return Triple::COFF;
+else if (T.isUEFI())
+  return Triple::COFF;
 return Triple::ELF;
 
   case Triple::aarch64_be:
Index: llvm/lib/IR/DataLayout.cpp
===
--- llvm/lib/IR/DataLayout.cpp
+++ llvm/lib/IR/DataLayout.cpp
@@ -171,7 +171,7 @@
 return "-m:l";
   if (T.isOSBinFormatMachO())
 return "-m:o";
-  if (T.isOSWindows() && T.isOSBinFormatCOFF())
+  if ((T.isOSWindows() || T.isUEFI()) && T.isOSBinFormatCOFF())
 return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";
   if (T.isOSBinFormatXCOFF())
 return "-m:a";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152206: [Basic] Support 64-bit x86 target for UEFI

2023-09-22 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added inline comments.



Comment at: llvm/unittests/IR/DataLayoutTest.cpp:108
 
+TEST(DataLayoutTest, TargetTripleManglingComponent) {
+  Triple TT = Triple("x86_64-unknown-uefi");

UEFI may be a better name in case we test more properties in the future.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152206

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


[clang] [Driver] Implement ToolChain on Haiku (PR #66038)

2023-09-22 Thread Brad Smith via cfe-commits

https://github.com/brad0 closed https://github.com/llvm/llvm-project/pull/66038
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8ea7430 - [Driver] Implement ToolChain on Haiku (#66038)

2023-09-22 Thread via cfe-commits

Author: Brad Smith
Date: 2023-09-22T18:17:44-04:00
New Revision: 8ea74302007465e4e824d420b103c2d23bd5838b

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

LOG: [Driver] Implement ToolChain on Haiku (#66038)

Instead of passing everything off to GCC, add a ToolChain for Haiku to allow 
Clang to properly link things on its own.

Co-authored-by: X512 
Co-authored-by: David Karoly 

Added: 
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/lib/crti.o
clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/lib/crtn.o

clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/lib/init_term_dyn.o

clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/lib/start_dyn.o

clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtbegin.o

clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtbeginS.o

clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtend.o

clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/crtendS.o

clang/test/Driver/Inputs/haiku_x86_64_tree/boot/system/develop/tools/lib/gcc/x86_64-unknown-haiku/13.2.0/include/c++/.keep

Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/lib/Driver/ToolChains/Haiku.cpp
clang/lib/Driver/ToolChains/Haiku.h
clang/test/Driver/haiku.c
clang/test/Driver/haiku.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 61f5100f1385a13..1b4a94d72cc0a66 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2224,6 +2224,12 @@ bool 
Generic_GCC::GCCInstallationDetector::getBiarchSibling(Multilib &M) const {
 void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
 const llvm::Triple &TargetTriple, SmallVectorImpl &Prefixes,
 StringRef SysRoot) {
+
+  if (TargetTriple.isOSHaiku()) {
+Prefixes.push_back(concat(SysRoot, "/boot/system/develop/tools"));
+return;
+  }
+
   if (TargetTriple.isOSSolaris()) {
 // Solaris is a special case.
 // The GCC installation is under

diff  --git a/clang/lib/Driver/ToolChains/Haiku.cpp 
b/clang/lib/Driver/ToolChains/Haiku.cpp
index 55fc0533f699fab..33d71f030e51c51 100644
--- a/clang/lib/Driver/ToolChains/Haiku.cpp
+++ b/clang/lib/Driver/ToolChains/Haiku.cpp
@@ -9,20 +9,141 @@
 #include "Haiku.h"
 #include "CommonArgs.h"
 #include "clang/Config/config.h"
+#include "clang/Driver/Compilation.h"
 #include "llvm/Support/Path.h"
 
 using namespace clang::driver;
+using namespace clang::driver::tools;
 using namespace clang::driver::toolchains;
 using namespace clang;
 using namespace llvm::opt;
 
+void haiku::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+   const InputInfo &Output,
+   const InputInfoList &Inputs,
+   const ArgList &Args,
+   const char *LinkingOutput) const {
+  const toolchains::Haiku &ToolChain =
+  static_cast(getToolChain());
+  const Driver &D = ToolChain.getDriver();
+  const llvm::Triple::ArchType Arch = ToolChain.getArch();
+  const bool Static = Args.hasArg(options::OPT_static);
+  const bool Shared = Args.hasArg(options::OPT_shared);
+  ArgStringList CmdArgs;
+
+  // Silence warning for "clang -g foo.o -o foo"
+  Args.ClaimAllArgs(options::OPT_g_Group);
+  // and "clang -emit-llvm foo.o -o foo"
+  Args.ClaimAllArgs(options::OPT_emit_llvm);
+  // and for "clang -w foo.o -o foo". Other warning options are already
+  // handled somewhere else.
+  Args.ClaimAllArgs(options::OPT_w);
+
+  // Silence warning for "clang -pie foo.o -o foo"
+  Args.ClaimAllArgs(options::OPT_pie);
+
+  if (!D.SysRoot.empty())
+CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
+
+  CmdArgs.push_back("--eh-frame-hdr");
+  if (Static) {
+CmdArgs.push_back("-Bstatic");
+  } else {
+if (Args.hasArg(options::OPT_rdynamic))
+  CmdArgs.push_back("-export-dynamic");
+if (Shared)
+  CmdArgs.push_back("-shared");
+CmdArgs.push_back("--enable-new-dtags");
+  }
+
+  CmdArgs.push_back("-shared");
+
+  if (!Shared)
+CmdArgs.push_back("--no-undefined");
+
+  if (Arch == llvm::Triple::riscv64)
+CmdArgs.push_back("-X");
+
+  assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
+  if (Output.isFilename()) {
+CmdArgs.push_back("-o");
+CmdArgs.push_back(Output.getFilename());
+  }
+
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
+   options::OPT_r)) {
+CmdArgs.

[clang] [clang][modules] Move `SLocEntry` search into `ASTReader` (PR #66966)

2023-09-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 edited 
https://github.com/llvm/llvm-project/pull/66966
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][modules] Move `SLocEntry` search into `ASTReader` (PR #66966)

2023-09-22 Thread Jan Svoboda via cfe-commits

https://github.com/jansvoboda11 updated 
https://github.com/llvm/llvm-project/pull/66966

>From 4edf9d8559339a12108d9c4d1e2f3bb062a5a768 Mon Sep 17 00:00:00 2001
From: Jan Svoboda 
Date: Wed, 20 Sep 2023 17:30:45 -0700
Subject: [PATCH 1/5] [clang][modules] Move `SLocEntry` search into `ASTReader`

In `getFileID()` the `SourceManager` ends up doing a binary search over its 
buffer of `SLocEntries`. For modules, this binary search fully deserializes the 
entire `SLocEntry` block for visited each entry. This shows up in profiles of 
the dependency scanner, since that operation includes decompressing buffers 
associated with some entries.

This patch moves the binary search over loaded entries into `ASTReader`, which 
now only performs partial deserialization during the binary search, speeding up 
the scanner by ~3.3%.
---
 clang/include/clang/Basic/SourceManager.h |  3 +
 clang/include/clang/Serialization/ASTReader.h |  6 ++
 clang/lib/Basic/SourceManager.cpp | 70 +--
 clang/lib/Serialization/ASTReader.cpp | 63 +
 4 files changed, 75 insertions(+), 67 deletions(-)

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..a4c7facddd53d64 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -533,6 +533,9 @@ class ExternalSLocEntrySource {
   /// entry from being loaded.
   virtual bool ReadSLocEntry(int ID) = 0;
 
+  /// Get the index ID for the loaded SourceLocation offset.
+  virtual int getSLocEntryID(SourceLocation::UIntTy SLocOffset) = 0;
+
   /// Retrieve the module import location and name for the given ID, if
   /// in fact it was loaded from a module (rather than, say, a precompiled
   /// header).
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index dc1eb21c27801fe..e643fcf4c930f09 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -2153,6 +2153,12 @@ class ASTReader
 
   /// Read the source location entry with index ID.
   bool ReadSLocEntry(int ID) override;
+  /// Get the index ID for the loaded SourceLocation offset.
+  int getSLocEntryID(SourceLocation::UIntTy SLocOffset) override;
+  /// Read the offset of the SLocEntry at the given index in the given module
+  /// file.
+  std::optional readSLocOffset(ModuleFile *F,
+   unsigned Index);
 
   /// Retrieve the module import location and module name for the
   /// given source manager entry ID.
diff --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 0521ac7b30339ab..f881afc2e46c5c6 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -864,74 +864,10 @@ FileID 
SourceManager::getFileIDLocal(SourceLocation::UIntTy SLocOffset) const {
 /// This function knows that the SourceLocation is in a loaded buffer, not a
 /// local one.
 FileID SourceManager::getFileIDLoaded(SourceLocation::UIntTy SLocOffset) const 
{
-  if (SLocOffset < CurrentLoadedOffset) {
-assert(0 && "Invalid SLocOffset or bad function choice");
-return FileID();
-  }
-
-  // Essentially the same as the local case, but the loaded array is sorted
-  // in the other direction (decreasing order).
-  // GreaterIndex is the one where the offset is greater, which is actually a
-  // lower index!
-  unsigned GreaterIndex = 0;
-  unsigned LessIndex = LoadedSLocEntryTable.size();
-  if (LastFileIDLookup.ID < 0) {
-// Prune the search space.
-int LastID = LastFileIDLookup.ID;
-if (getLoadedSLocEntryByID(LastID).getOffset() > SLocOffset)
-  GreaterIndex =
-  (-LastID - 2) + 1; // Exclude LastID, else we would have hit the 
cache
-else
-  LessIndex = -LastID - 2;
-  }
-
-  // First do a linear scan from the last lookup position, if possible.
-  unsigned NumProbes;
+  int ID = ExternalSLocEntries->getSLocEntryID(SLocOffset);
   bool Invalid = false;
-  for (NumProbes = 0; NumProbes < 8; ++NumProbes, ++GreaterIndex) {
-// Make sure the entry is loaded!
-const SrcMgr::SLocEntry &E = getLoadedSLocEntry(GreaterIndex, &Invalid);
-if (Invalid)
-  return FileID(); // invalid entry.
-if (E.getOffset() <= SLocOffset) {
-  FileID Res = FileID::get(-int(GreaterIndex) - 2);
-  LastFileIDLookup = Res;
-  NumLinearScans += NumProbes + 1;
-  return Res;
-}
-  }
-
-  // Linear scan failed. Do the binary search.
-  NumProbes = 0;
-  while (true) {
-++NumProbes;
-unsigned MiddleIndex = (LessIndex - GreaterIndex) / 2 + GreaterIndex;
-const SrcMgr::SLocEntry &E = getLoadedSLocEntry(MiddleIndex, &Invalid);
-if (Invalid)
-  return FileID(); // invalid entry.
-
-if (E.getOffset() > SLocOffset) {
-  if (GreaterIndex == MiddleIndex) {
-assert(0 && "binary search missed the entry");
-retur

[PATCH] D152206: [Basic] Support 64-bit x86 target for UEFI

2023-09-22 Thread Prabhu Karthikeyan Rajasekaran via Phabricator via cfe-commits
Prabhuk updated this revision to Diff 557261.
Prabhuk added a comment.

Add DataLayoutTest for UEFI target.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152206

Files:
  llvm/lib/IR/DataLayout.cpp
  llvm/lib/TargetParser/Triple.cpp
  llvm/unittests/IR/DataLayoutTest.cpp
  llvm/unittests/TargetParser/TripleTest.cpp


Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -462,6 +462,7 @@
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::UEFI, T.getOS());
   EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+  EXPECT_EQ(Triple::COFF, T.getObjectFormat());
 
   T = Triple("wasm32-unknown-unknown");
   EXPECT_EQ(Triple::wasm32, T.getArch());
Index: llvm/unittests/IR/DataLayoutTest.cpp
===
--- llvm/unittests/IR/DataLayoutTest.cpp
+++ llvm/unittests/IR/DataLayoutTest.cpp
@@ -11,6 +11,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
+#include "llvm/TargetParser/Triple.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 
@@ -104,4 +105,9 @@
   EXPECT_EQ(Align(4 * 8), DL->getPrefTypeAlign(V8F32Ty));
 }
 
+TEST(DataLayoutTest, TargetTripleManglingComponent) {
+  Triple TT = Triple("x86_64-unknown-uefi");
+  EXPECT_STREQ(DataLayout::getManglingComponent(TT), "-m:w");
+}
+
 } // anonymous namespace
Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -799,6 +799,8 @@
   case Triple::x86_64:
 if (T.isOSWindows())
   return Triple::COFF;
+else if (T.isUEFI())
+  return Triple::COFF;
 return Triple::ELF;
 
   case Triple::aarch64_be:
Index: llvm/lib/IR/DataLayout.cpp
===
--- llvm/lib/IR/DataLayout.cpp
+++ llvm/lib/IR/DataLayout.cpp
@@ -171,7 +171,7 @@
 return "-m:l";
   if (T.isOSBinFormatMachO())
 return "-m:o";
-  if (T.isOSWindows() && T.isOSBinFormatCOFF())
+  if ((T.isOSWindows() || T.isUEFI()) && T.isOSBinFormatCOFF())
 return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";
   if (T.isOSBinFormatXCOFF())
 return "-m:a";


Index: llvm/unittests/TargetParser/TripleTest.cpp
===
--- llvm/unittests/TargetParser/TripleTest.cpp
+++ llvm/unittests/TargetParser/TripleTest.cpp
@@ -462,6 +462,7 @@
   EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
   EXPECT_EQ(Triple::UEFI, T.getOS());
   EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+  EXPECT_EQ(Triple::COFF, T.getObjectFormat());
 
   T = Triple("wasm32-unknown-unknown");
   EXPECT_EQ(Triple::wasm32, T.getArch());
Index: llvm/unittests/IR/DataLayoutTest.cpp
===
--- llvm/unittests/IR/DataLayoutTest.cpp
+++ llvm/unittests/IR/DataLayoutTest.cpp
@@ -11,6 +11,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Type.h"
+#include "llvm/TargetParser/Triple.h"
 #include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
 
@@ -104,4 +105,9 @@
   EXPECT_EQ(Align(4 * 8), DL->getPrefTypeAlign(V8F32Ty));
 }
 
+TEST(DataLayoutTest, TargetTripleManglingComponent) {
+  Triple TT = Triple("x86_64-unknown-uefi");
+  EXPECT_STREQ(DataLayout::getManglingComponent(TT), "-m:w");
+}
+
 } // anonymous namespace
Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -799,6 +799,8 @@
   case Triple::x86_64:
 if (T.isOSWindows())
   return Triple::COFF;
+else if (T.isUEFI())
+  return Triple::COFF;
 return Triple::ELF;
 
   case Triple::aarch64_be:
Index: llvm/lib/IR/DataLayout.cpp
===
--- llvm/lib/IR/DataLayout.cpp
+++ llvm/lib/IR/DataLayout.cpp
@@ -171,7 +171,7 @@
 return "-m:l";
   if (T.isOSBinFormatMachO())
 return "-m:o";
-  if (T.isOSWindows() && T.isOSBinFormatCOFF())
+  if ((T.isOSWindows() || T.isUEFI()) && T.isOSBinFormatCOFF())
 return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";
   if (T.isOSBinFormatXCOFF())
 return "-m:a";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Recommit "Implement [[msvc::no_unique_address]] (#65675)" (PR #67199)

2023-09-22 Thread Amy Huang via cfe-commits

amykhuang wrote:

Previous commit attempt caused sphinx errors. Also, because we now have two 
attributes for the itanium and MSVC versions, there are two separate sections 
in the documentation, which I didn't realize before.

https://github.com/llvm/llvm-project/pull/67199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Recommit "Implement [[msvc::no_unique_address]] (#65675)" (PR #67199)

2023-09-22 Thread Amy Huang via cfe-commits

https://github.com/amykhuang edited 
https://github.com/llvm/llvm-project/pull/67199
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Recommit "Implement [[msvc::no_unique_address]] (#65675)" (PR #67199)

2023-09-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

Change the attribute docs so that there is a separate one for the MSVC
attribute.

This reverts commit 71f9e7695b87298f9855d8890f0e6a3b89381eb5.


---

Patch is 25.37 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/67199.diff


9 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+16-3) 
- (modified) clang/include/clang/Basic/AttrDocs.td (+9) 
- (modified) clang/lib/AST/Decl.cpp (+8-3) 
- (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+45-8) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (+10) 
- (added) clang/test/Layout/ms-no-unique-address.cpp (+381) 
- (modified) clang/test/Preprocessor/has_attribute.cpp (+4-1) 
- (added) clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp (+19) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 21a3b5226623cf2..3da91d25ec97347 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1798,11 +1798,24 @@ def ArmMveStrictPolymorphism : TypeAttr, 
TargetSpecificAttr {
   let Documentation = [ArmMveStrictPolymorphismDocs];
 }
 
-def NoUniqueAddress : InheritableAttr, TargetSpecificAttr 
{
-  let Spellings = [CXX11<"", "no_unique_address", 201803>];
+def NoUniqueAddress : InheritableAttr {
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  // No spellings because instances of this attribute are created by
+  // MSNoUniqueAddress and ItaniumNoUniqueAddress
+  let Spellings = [];
+  let Documentation = [InternalOnly];
+}
+
+def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
   let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  let Spellings = [CXX11<"msvc", "no_unique_address", 201803>];
+  let Documentation = [MSNoUniqueAddressDocs];
+}
+
+def ItaniumNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  let Spellings = [CXX11<"", "no_unique_address", 201803>];
   let Documentation = [NoUniqueAddressDocs];
-  let SimpleHandler = 1;
 }
 
 def ReturnsTwice : InheritableAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b13baa46754cfd4..d16ce23c067982d 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1408,6 +1408,15 @@ in C++11 onwards.
   }];
 }
 
+def MSNoUniqueAddressDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+On MSVC targets, ``[[no_unique_address]]`` is ignored; use
+``[[msvc::no_unique_address]]`` instead. Currently there is no guarantee of ABI
+compatibility or stability with MSVC.
+  }];
+}
+
 def ObjCRequiresSuperDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 08ae2087cfe70eb..07aee0d87c835a8 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4507,9 +4507,14 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
 
   // Otherwise, [...] the circumstances under which the object has zero size
   // are implementation-defined.
-  // FIXME: This might be Itanium ABI specific; we don't yet know what the MS
-  // ABI will do.
-  return true;
+  if (!Ctx.getTargetInfo().getCXXABI().isMicrosoft())
+return true;
+
+  // MS ABI: has nonzero size if it is a class type with class type fields,
+  // whether or not they have nonzero size
+  return !llvm::any_of(CXXRD->fields(), [](const FieldDecl *Field) {
+return Field->getType()->getAs();
+  });
 }
 
 bool FieldDecl::isPotentiallyOverlapping() const {
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 8afd88ae7be27b3..f1f2275da44dcad 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2545,7 +2545,10 @@ struct MicrosoftRecordLayoutBuilder {
 CharUnits Alignment;
   };
   typedef llvm::DenseMap BaseOffsetsMapTy;
-  MicrosoftRecordLayoutBuilder(const ASTContext &Context) : Context(Context) {}
+  MicrosoftRecordLayoutBuilder(const ASTContext &Context,
+   EmptySubobjectMap *EmptySubobjects)
+  : Context(Context), EmptySubobjects(EmptySubobjects) {}
+
 private:
   MicrosoftRecordLayoutBuilder(const MicrosoftRecordLayoutBuilder &) = delete;
   void operator=(const MicrosoftRecordLayoutBuilder &) = delete;
@@ -2595,6 +2598,8 @@ struct MicrosoftRecordLayoutBuilder {
   llvm::SmallPtrSetImpl &HasVtorDispSet,
   const CXXRecordDecl *RD) const;
   const ASTContext &Context;
+  EmptySubobjectMap *EmptySubobjects;
+
   /// The size of the record being laid out.
   CharUnits Size;
   /// The non-virtual size of the record layout.
@@ -2908,8 +2913,7 @@ static bool recordUsesEBO(const RecordDecl *RD) {
 }
 
 void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
-const CXXRecordDecl *RD,
-const CXXR

[clang] Recommit "Implement [[msvc::no_unique_address]] (#65675)" (PR #67199)

2023-09-22 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/67199

Change the attribute docs so that there is a separate one for the MSVC
attribute.

This reverts commit 71f9e7695b87298f9855d8890f0e6a3b89381eb5.


>From b1f0feeaed93edfdd692858e9d63ab6bbb94c0a5 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Fri, 22 Sep 2023 14:40:14 -0700
Subject: [PATCH] Recommit "Implement [[msvc::no_unique_address]] (#65675)"

Change the attribute docs so that there is a separate one for the MSVC
attribute.

This reverts commit 71f9e7695b87298f9855d8890f0e6a3b89381eb5.
---
 clang/include/clang/Basic/Attr.td |  19 +-
 clang/include/clang/Basic/AttrDocs.td |   9 +
 clang/lib/AST/Decl.cpp|  11 +-
 clang/lib/AST/RecordLayoutBuilder.cpp |  53 ++-
 clang/lib/Parse/ParseDeclCXX.cpp  |   3 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  10 +
 clang/test/Layout/ms-no-unique-address.cpp| 381 ++
 clang/test/Preprocessor/has_attribute.cpp |   5 +-
 .../SemaCXX/cxx2a-ms-no-unique-address.cpp|  19 +
 9 files changed, 494 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Layout/ms-no-unique-address.cpp
 create mode 100644 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 21a3b5226623cf2..3da91d25ec97347 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1798,11 +1798,24 @@ def ArmMveStrictPolymorphism : TypeAttr, 
TargetSpecificAttr {
   let Documentation = [ArmMveStrictPolymorphismDocs];
 }
 
-def NoUniqueAddress : InheritableAttr, TargetSpecificAttr 
{
-  let Spellings = [CXX11<"", "no_unique_address", 201803>];
+def NoUniqueAddress : InheritableAttr {
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  // No spellings because instances of this attribute are created by
+  // MSNoUniqueAddress and ItaniumNoUniqueAddress
+  let Spellings = [];
+  let Documentation = [InternalOnly];
+}
+
+def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
   let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  let Spellings = [CXX11<"msvc", "no_unique_address", 201803>];
+  let Documentation = [MSNoUniqueAddressDocs];
+}
+
+def ItaniumNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  let Spellings = [CXX11<"", "no_unique_address", 201803>];
   let Documentation = [NoUniqueAddressDocs];
-  let SimpleHandler = 1;
 }
 
 def ReturnsTwice : InheritableAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b13baa46754cfd4..d16ce23c067982d 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1408,6 +1408,15 @@ in C++11 onwards.
   }];
 }
 
+def MSNoUniqueAddressDocs : Documentation {
+  let Category = DocCatField;
+  let Content = [{
+On MSVC targets, ``[[no_unique_address]]`` is ignored; use
+``[[msvc::no_unique_address]]`` instead. Currently there is no guarantee of ABI
+compatibility or stability with MSVC.
+  }];
+}
+
 def ObjCRequiresSuperDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 08ae2087cfe70eb..07aee0d87c835a8 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4507,9 +4507,14 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
 
   // Otherwise, [...] the circumstances under which the object has zero size
   // are implementation-defined.
-  // FIXME: This might be Itanium ABI specific; we don't yet know what the MS
-  // ABI will do.
-  return true;
+  if (!Ctx.getTargetInfo().getCXXABI().isMicrosoft())
+return true;
+
+  // MS ABI: has nonzero size if it is a class type with class type fields,
+  // whether or not they have nonzero size
+  return !llvm::any_of(CXXRD->fields(), [](const FieldDecl *Field) {
+return Field->getType()->getAs();
+  });
 }
 
 bool FieldDecl::isPotentiallyOverlapping() const {
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 8afd88ae7be27b3..f1f2275da44dcad 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2545,7 +2545,10 @@ struct MicrosoftRecordLayoutBuilder {
 CharUnits Alignment;
   };
   typedef llvm::DenseMap BaseOffsetsMapTy;
-  MicrosoftRecordLayoutBuilder(const ASTContext &Context) : Context(Context) {}
+  MicrosoftRecordLayoutBuilder(const ASTContext &Context,
+   EmptySubobjectMap *EmptySubobjects)
+  : Context(Context), EmptySubobjects(EmptySubobjects) {}
+
 private:
   MicrosoftRecordLayoutBuilder(const MicrosoftRecordLayoutBuilder &) = delete;
   void operator=(const MicrosoftRecordLayoutBuilder &) = delete;
@@ -2595,6 +2598,8 @@ struct MicrosoftRecordLayoutBuilder {
   llvm::SmallPtrSetImpl &HasVtorDi

[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-22 Thread Artem Belevich via cfe-commits


@@ -537,59 +537,46 @@ void NVPTXAsmPrinter::emitKernelFunctionDirectives(const 
Function &F,
raw_ostream &O) const {
   // If the NVVM IR has some of reqntid* specified, then output
   // the reqntid directive, and set the unspecified ones to 1.
-  // If none of reqntid* is specified, don't output reqntid directive.
-  unsigned reqntidx, reqntidy, reqntidz;
-  bool specified = false;
-  if (!getReqNTIDx(F, reqntidx))
-reqntidx = 1;
-  else
-specified = true;
-  if (!getReqNTIDy(F, reqntidy))
-reqntidy = 1;
-  else
-specified = true;
-  if (!getReqNTIDz(F, reqntidz))
-reqntidz = 1;
-  else
-specified = true;
-
-  if (specified)
-O << ".reqntid " << reqntidx << ", " << reqntidy << ", " << reqntidz
+  // If none of Reqntid* is specified, don't output reqntid directive.
+  unsigned Reqntidx, Reqntidy, Reqntidz;
+  Reqntidx = Reqntidy = Reqntidz = 1;
+  bool ReqSpecified = false;
+  ReqSpecified |= getReqNTIDx(F, Reqntidx);
+  ReqSpecified |= getReqNTIDy(F, Reqntidy);
+  ReqSpecified |= getReqNTIDz(F, Reqntidz);
+
+  if (ReqSpecified)
+O << ".reqntid " << Reqntidx << ", " << Reqntidy << ", " << Reqntidz
   << "\n";
 
   // If the NVVM IR has some of maxntid* specified, then output
   // the maxntid directive, and set the unspecified ones to 1.
   // If none of maxntid* is specified, don't output maxntid directive.
-  unsigned maxntidx, maxntidy, maxntidz;
-  specified = false;
-  if (!getMaxNTIDx(F, maxntidx))
-maxntidx = 1;
-  else
-specified = true;
-  if (!getMaxNTIDy(F, maxntidy))
-maxntidy = 1;
-  else
-specified = true;
-  if (!getMaxNTIDz(F, maxntidz))
-maxntidz = 1;
-  else
-specified = true;
-
-  if (specified)
-O << ".maxntid " << maxntidx << ", " << maxntidy << ", " << maxntidz
+  unsigned Maxntidx, Maxntidy, Maxntidz;
+  Maxntidx = Maxntidy = Maxntidz = 1;
+  bool MaxSpecified = false;
+  MaxSpecified |= getMaxNTIDx(F, Maxntidx);
+  MaxSpecified |= getMaxNTIDy(F, Maxntidy);
+  MaxSpecified |= getMaxNTIDz(F, Maxntidz);
+
+  if (MaxSpecified)
+O << ".maxntid " << Maxntidx << ", " << Maxntidy << ", " << Maxntidz
   << "\n";
 
-  unsigned mincta;
-  if (getMinCTASm(F, mincta))
-O << ".minnctapersm " << mincta << "\n";
+  unsigned Mincta = 0;
+  if (getMinCTASm(F, Mincta))
+O << ".minnctapersm " << Mincta << "\n";
 
-  unsigned maxnreg;
-  if (getMaxNReg(F, maxnreg))
-O << ".maxnreg " << maxnreg << "\n";
+  unsigned Maxnreg = 0;
+  if (getMaxNReg(F, Maxnreg))
+O << ".maxnreg " << Maxnreg << "\n";
+
+  unsigned Maxclusterrank = 0;

Artem-B wrote:

I've talked to @alinas who has more experience dealing with IR and she also 
thinks that ignoring `maxclusterrank` metadata on older GPUs is the right 
choice here.

https://github.com/llvm/llvm-project/pull/66496
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "Implement [[msvc::no_unique_address]] (#65675)" (PR #67198)

2023-09-22 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 9779a731a65fd8daee4d0a4b6945e882263b062e 
159cc6b5d3cea0c4b51bd5dac7728a3cfa379f28 -- clang/lib/AST/Decl.cpp 
clang/lib/AST/RecordLayoutBuilder.cpp clang/lib/Parse/ParseDeclCXX.cpp 
clang/lib/Sema/SemaDeclAttr.cpp clang/test/Preprocessor/has_attribute.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 8afd88ae7..30c94b0de 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2546,6 +2546,7 @@ struct MicrosoftRecordLayoutBuilder {
   };
   typedef llvm::DenseMap BaseOffsetsMapTy;
   MicrosoftRecordLayoutBuilder(const ASTContext &Context) : Context(Context) {}
+
 private:
   MicrosoftRecordLayoutBuilder(const MicrosoftRecordLayoutBuilder &) = delete;
   void operator=(const MicrosoftRecordLayoutBuilder &) = delete;
@@ -2908,8 +2909,7 @@ static bool recordUsesEBO(const RecordDecl *RD) {
 }
 
 void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
-const CXXRecordDecl *RD,
-const CXXRecordDecl *BaseDecl,
+const CXXRecordDecl *RD, const CXXRecordDecl *BaseDecl,
 const ASTRecordLayout &BaseLayout,
 const ASTRecordLayout *&PreviousBaseLayout) {
   // Insert padding between two bases if the left first one is zero sized or

``




https://github.com/llvm/llvm-project/pull/67198
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "Implement [[msvc::no_unique_address]] (#65675)" (PR #67198)

2023-09-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

This reverts commit 4a55d426967b9c70f5dea7b3a389e11393a4f4c4.

Reverting because this breaks sphinx documentation, and even with it
fixed the format of the attribute makes the no_unique_address
documentation show up twice.


---

Patch is 25.26 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/67198.diff


9 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (+3-16) 
- (modified) clang/include/clang/Basic/AttrDocs.td (-4) 
- (modified) clang/lib/AST/Decl.cpp (+3-8) 
- (modified) clang/lib/AST/RecordLayoutBuilder.cpp (+8-45) 
- (modified) clang/lib/Parse/ParseDeclCXX.cpp (+1-2) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (-10) 
- (removed) clang/test/Layout/ms-no-unique-address.cpp (-381) 
- (modified) clang/test/Preprocessor/has_attribute.cpp (+1-4) 
- (removed) clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp (-19) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bb8d204f33dc531..21a3b5226623cf2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1798,24 +1798,11 @@ def ArmMveStrictPolymorphism : TypeAttr, 
TargetSpecificAttr {
   let Documentation = [ArmMveStrictPolymorphismDocs];
 }
 
-def NoUniqueAddress : InheritableAttr {
-  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
-  // No spellings because instances of this attribute are created by
-  // MSNoUniqueAddress and ItaniumNoUniqueAddress
-  let Spellings = [];
-  let Documentation = [NoUniqueAddressDocs];
-}
-
-def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
-  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
-  let Spellings = [CXX11<"msvc", "no_unique_address", 201803>];
-  let Documentation = [NoUniqueAddressDocs];
-}
-
-def ItaniumNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
-  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+def NoUniqueAddress : InheritableAttr, TargetSpecificAttr 
{
   let Spellings = [CXX11<"", "no_unique_address", 201803>];
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
   let Documentation = [NoUniqueAddressDocs];
+  let SimpleHandler = 1;
 }
 
 def ReturnsTwice : InheritableAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 18428d26b5dc8f2..b13baa46754cfd4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1405,10 +1405,6 @@ Example usage:
 
 ``[[no_unique_address]]`` is a standard C++20 attribute. Clang supports its use
 in C++11 onwards.
-
-On MSVC targets, ``[[no_unique_address]]`` is ignored; use
-``[[msvc::no_unique_address]]`` instead. Currently there is no guarantee of ABI
-compatibility or stability.
   }];
 }
 
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 07aee0d87c835a8..08ae2087cfe70eb 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4507,14 +4507,9 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
 
   // Otherwise, [...] the circumstances under which the object has zero size
   // are implementation-defined.
-  if (!Ctx.getTargetInfo().getCXXABI().isMicrosoft())
-return true;
-
-  // MS ABI: has nonzero size if it is a class type with class type fields,
-  // whether or not they have nonzero size
-  return !llvm::any_of(CXXRD->fields(), [](const FieldDecl *Field) {
-return Field->getType()->getAs();
-  });
+  // FIXME: This might be Itanium ABI specific; we don't yet know what the MS
+  // ABI will do.
+  return true;
 }
 
 bool FieldDecl::isPotentiallyOverlapping() const {
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index f1f2275da44dcad..8afd88ae7be27b3 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2545,10 +2545,7 @@ struct MicrosoftRecordLayoutBuilder {
 CharUnits Alignment;
   };
   typedef llvm::DenseMap BaseOffsetsMapTy;
-  MicrosoftRecordLayoutBuilder(const ASTContext &Context,
-   EmptySubobjectMap *EmptySubobjects)
-  : Context(Context), EmptySubobjects(EmptySubobjects) {}
-
+  MicrosoftRecordLayoutBuilder(const ASTContext &Context) : Context(Context) {}
 private:
   MicrosoftRecordLayoutBuilder(const MicrosoftRecordLayoutBuilder &) = delete;
   void operator=(const MicrosoftRecordLayoutBuilder &) = delete;
@@ -2598,8 +2595,6 @@ struct MicrosoftRecordLayoutBuilder {
   llvm::SmallPtrSetImpl &HasVtorDispSet,
   const CXXRecordDecl *RD) const;
   const ASTContext &Context;
-  EmptySubobjectMap *EmptySubobjects;
-
   /// The size of the record being laid out.
   CharUnits Size;
   /// The non-virtual size of the record layout.
@@ -2913,7 +2908,8 @@ static bool recordUsesEBO(const RecordDecl *RD) {
 }
 
 void MicrosoftRecordLayoutBuilder::layoutNonVirtualBase(
-const CXXRecordDecl *RD, const CXXRecordDecl *BaseDecl,
+const CXXRec

[clang] 71f9e76 - Revert "Implement [[msvc::no_unique_address]] (#65675)" (#67198)

2023-09-22 Thread via cfe-commits

Author: Amy Huang
Date: 2023-09-22T14:39:00-07:00
New Revision: 71f9e7695b87298f9855d8890f0e6a3b89381eb5

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

LOG: Revert "Implement [[msvc::no_unique_address]] (#65675)" (#67198)

This reverts commit 4a55d426967b9c70f5dea7b3a389e11393a4f4c4.

Reverting because this breaks sphinx documentation, and even with it
fixed the format of the attribute makes the no_unique_address
documentation show up twice.

Added: 


Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/AST/Decl.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Preprocessor/has_attribute.cpp

Removed: 
clang/test/Layout/ms-no-unique-address.cpp
clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp



diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bb8d204f33dc531..21a3b5226623cf2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1798,24 +1798,11 @@ def ArmMveStrictPolymorphism : TypeAttr, 
TargetSpecificAttr {
   let Documentation = [ArmMveStrictPolymorphismDocs];
 }
 
-def NoUniqueAddress : InheritableAttr {
-  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
-  // No spellings because instances of this attribute are created by
-  // MSNoUniqueAddress and ItaniumNoUniqueAddress
-  let Spellings = [];
-  let Documentation = [NoUniqueAddressDocs];
-}
-
-def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
-  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
-  let Spellings = [CXX11<"msvc", "no_unique_address", 201803>];
-  let Documentation = [NoUniqueAddressDocs];
-}
-
-def ItaniumNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
-  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+def NoUniqueAddress : InheritableAttr, TargetSpecificAttr 
{
   let Spellings = [CXX11<"", "no_unique_address", 201803>];
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
   let Documentation = [NoUniqueAddressDocs];
+  let SimpleHandler = 1;
 }
 
 def ReturnsTwice : InheritableAttr {

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 18428d26b5dc8f2..b13baa46754cfd4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1405,10 +1405,6 @@ Example usage:
 
 ``[[no_unique_address]]`` is a standard C++20 attribute. Clang supports its use
 in C++11 onwards.
-
-On MSVC targets, ``[[no_unique_address]]`` is ignored; use
-``[[msvc::no_unique_address]]`` instead. Currently there is no guarantee of ABI
-compatibility or stability.
   }];
 }
 

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 07aee0d87c835a8..08ae2087cfe70eb 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4507,14 +4507,9 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
 
   // Otherwise, [...] the circumstances under which the object has zero size
   // are implementation-defined.
-  if (!Ctx.getTargetInfo().getCXXABI().isMicrosoft())
-return true;
-
-  // MS ABI: has nonzero size if it is a class type with class type fields,
-  // whether or not they have nonzero size
-  return !llvm::any_of(CXXRD->fields(), [](const FieldDecl *Field) {
-return Field->getType()->getAs();
-  });
+  // FIXME: This might be Itanium ABI specific; we don't yet know what the MS
+  // ABI will do.
+  return true;
 }
 
 bool FieldDecl::isPotentiallyOverlapping() const {

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index f1f2275da44dcad..8afd88ae7be27b3 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2545,10 +2545,7 @@ struct MicrosoftRecordLayoutBuilder {
 CharUnits Alignment;
   };
   typedef llvm::DenseMap BaseOffsetsMapTy;
-  MicrosoftRecordLayoutBuilder(const ASTContext &Context,
-   EmptySubobjectMap *EmptySubobjects)
-  : Context(Context), EmptySubobjects(EmptySubobjects) {}
-
+  MicrosoftRecordLayoutBuilder(const ASTContext &Context) : Context(Context) {}
 private:
   MicrosoftRecordLayoutBuilder(const MicrosoftRecordLayoutBuilder &) = delete;
   void operator=(const MicrosoftRecordLayoutBuilder &) = delete;
@@ -2598,8 +2595,6 @@ struct MicrosoftRecordLayoutBuilder {
   llvm::SmallPtrSetImpl &HasVtorDispSet,
   const CXXRecordDecl *RD) const;
   const ASTContext &Context;
-  EmptySubobjectMap *EmptySubobjects;
-
   /// The size of the record being laid out.
   CharUnits Size;
   /// The non-virtual size of the record layout.
@@ -2913,7 +2908,8 @@ static bool recordUsesEBO(const RecordDecl *RD) {
 }
 
 void Micros

[clang] Revert "Implement [[msvc::no_unique_address]] (#65675)" (PR #67198)

2023-09-22 Thread Amy Huang via cfe-commits

https://github.com/amykhuang closed 
https://github.com/llvm/llvm-project/pull/67198
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Revert "Implement [[msvc::no_unique_address]] (#65675)" (PR #67198)

2023-09-22 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/67198

This reverts commit 4a55d426967b9c70f5dea7b3a389e11393a4f4c4.

Reverting because this breaks sphinx documentation, and even with it
fixed the format of the attribute makes the no_unique_address
documentation show up twice.


>From 159cc6b5d3cea0c4b51bd5dac7728a3cfa379f28 Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Fri, 22 Sep 2023 14:37:10 -0700
Subject: [PATCH] Revert "Implement [[msvc::no_unique_address]] (#65675)"

This reverts commit 4a55d426967b9c70f5dea7b3a389e11393a4f4c4.

Reverting because this breaks sphinx documentation, and even with it
fixed the format of the attribute makes the no_unique_address
documentation show up twice.
---
 clang/include/clang/Basic/Attr.td |  19 +-
 clang/include/clang/Basic/AttrDocs.td |   4 -
 clang/lib/AST/Decl.cpp|  11 +-
 clang/lib/AST/RecordLayoutBuilder.cpp |  53 +--
 clang/lib/Parse/ParseDeclCXX.cpp  |   3 +-
 clang/lib/Sema/SemaDeclAttr.cpp   |  10 -
 clang/test/Layout/ms-no-unique-address.cpp| 381 --
 clang/test/Preprocessor/has_attribute.cpp |   5 +-
 .../SemaCXX/cxx2a-ms-no-unique-address.cpp|  19 -
 9 files changed, 16 insertions(+), 489 deletions(-)
 delete mode 100644 clang/test/Layout/ms-no-unique-address.cpp
 delete mode 100644 clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bb8d204f33dc531..21a3b5226623cf2 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1798,24 +1798,11 @@ def ArmMveStrictPolymorphism : TypeAttr, 
TargetSpecificAttr {
   let Documentation = [ArmMveStrictPolymorphismDocs];
 }
 
-def NoUniqueAddress : InheritableAttr {
-  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
-  // No spellings because instances of this attribute are created by
-  // MSNoUniqueAddress and ItaniumNoUniqueAddress
-  let Spellings = [];
-  let Documentation = [NoUniqueAddressDocs];
-}
-
-def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
-  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
-  let Spellings = [CXX11<"msvc", "no_unique_address", 201803>];
-  let Documentation = [NoUniqueAddressDocs];
-}
-
-def ItaniumNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
-  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+def NoUniqueAddress : InheritableAttr, TargetSpecificAttr 
{
   let Spellings = [CXX11<"", "no_unique_address", 201803>];
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
   let Documentation = [NoUniqueAddressDocs];
+  let SimpleHandler = 1;
 }
 
 def ReturnsTwice : InheritableAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 18428d26b5dc8f2..b13baa46754cfd4 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1405,10 +1405,6 @@ Example usage:
 
 ``[[no_unique_address]]`` is a standard C++20 attribute. Clang supports its use
 in C++11 onwards.
-
-On MSVC targets, ``[[no_unique_address]]`` is ignored; use
-``[[msvc::no_unique_address]]`` instead. Currently there is no guarantee of ABI
-compatibility or stability.
   }];
 }
 
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 07aee0d87c835a8..08ae2087cfe70eb 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4507,14 +4507,9 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
 
   // Otherwise, [...] the circumstances under which the object has zero size
   // are implementation-defined.
-  if (!Ctx.getTargetInfo().getCXXABI().isMicrosoft())
-return true;
-
-  // MS ABI: has nonzero size if it is a class type with class type fields,
-  // whether or not they have nonzero size
-  return !llvm::any_of(CXXRD->fields(), [](const FieldDecl *Field) {
-return Field->getType()->getAs();
-  });
+  // FIXME: This might be Itanium ABI specific; we don't yet know what the MS
+  // ABI will do.
+  return true;
 }
 
 bool FieldDecl::isPotentiallyOverlapping() const {
diff --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index f1f2275da44dcad..8afd88ae7be27b3 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2545,10 +2545,7 @@ struct MicrosoftRecordLayoutBuilder {
 CharUnits Alignment;
   };
   typedef llvm::DenseMap BaseOffsetsMapTy;
-  MicrosoftRecordLayoutBuilder(const ASTContext &Context,
-   EmptySubobjectMap *EmptySubobjects)
-  : Context(Context), EmptySubobjects(EmptySubobjects) {}
-
+  MicrosoftRecordLayoutBuilder(const ASTContext &Context) : Context(Context) {}
 private:
   MicrosoftRecordLayoutBuilder(const MicrosoftRecordLayoutBuilder &) = delete;
   void operator=(const MicrosoftRecordLayoutBuilder &) = delete;
@@ -2598,8 +2595,6 @@ struct MicrosoftRecordLayoutBuilder {

[PATCH] D145214: [TSAN] add support for riscv64

2023-09-22 Thread Aditya Kumar via Phabricator via cfe-commits
hiraditya accepted this revision.
hiraditya added a comment.
This revision is now accepted and ready to land.

I tested it on a licheepi board (riscv64 debian) and all the tests passed. LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D145214

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


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-22 Thread Pranav Kant via cfe-commits

https://github.com/pranavk updated 
https://github.com/llvm/llvm-project/pull/67196

>From 8c07729b195fa78133258b03a31e8668d70a922d Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 20:50:32 +
Subject: [PATCH 1/2] [clang] Predefined macros for float128 support

---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e5db8a654e6707d..9e4d4d398a21da5 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1076,6 +1076,8 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
+  if (TI.hasFloat128Type())
+DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
 
   // Define a __POINTER_WIDTH__ macro for stdint.h.
   Builder.defineMacro("__POINTER_WIDTH__",

>From 0978352c91562f82229daeb1fb65f27f04f93d97 Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 21:23:51 +
Subject: [PATCH 2/2] Fix test

---
 clang/test/Preprocessor/init.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c
index 59c5122afe1e4c3..395c4cebfa5be76 100644
--- a/clang/test/Preprocessor/init.c
+++ b/clang/test/Preprocessor/init.c
@@ -1576,6 +1576,20 @@
 // EMSCRIPTEN-NEXT:#define __EMSCRIPTEN__ 1
 // WEBASSEMBLY-NEXT:#define __FINITE_MATH_ONLY__ 0
 // WEBASSEMBLY-NEXT:#define __FLOAT128__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_DECIMAL_DIG__ 36
+// WEBASSEMBLY-NEXT:#define __FLT128_DENORM_MIN__ 
6.47517511943802511092443895822764655e-4966Q
+// WEBASSEMBLY-NEXT:#define __FLT128_DIG__ 33
+// WEBASSEMBLY-NEXT:#define __FLT128_EPSILON__ 
1.92592994438723585305597794258492732e-34Q
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_DENORM__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_INFINITY__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_HAS_QUIET_NAN__ 1
+// WEBASSEMBLY-NEXT:#define __FLT128_MANT_DIG__ 113
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX_10_EXP__ 4932
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX_EXP__ 16384
+// WEBASSEMBLY-NEXT:#define __FLT128_MAX__ 
1.18973149535723176508575932662800702e+4932Q
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN_10_EXP__ (-4931)
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN_EXP__ (-16381)
+// WEBASSEMBLY-NEXT:#define __FLT128_MIN__ 
3.36210314311209350626267781732175260e-4932Q
 // WEBASSEMBLY-NOT:#define __FLT16_DECIMAL_DIG__
 // WEBASSEMBLY-NOT:#define __FLT16_DENORM_MIN__
 // WEBASSEMBLY-NOT:#define __FLT16_DIG__

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


[clang] Implement [[msvc::no_unique_address]] (PR #65675)

2023-09-22 Thread Fangrui Song via cfe-commits

MaskRay wrote:

The supposed doc fix (for `doc-clang-html`?) #67195 caused `error: Record 
`NoUniqueAddress', field `Documentation' exists but does not have a list 
value`. I have reverted #67195.

https://github.com/llvm/llvm-project/pull/65675
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 2d27bf2 - Revert "Fix attr docs from previous no-unique-adderss change (#67195)"

2023-09-22 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-09-22T14:04:16-07:00
New Revision: 2d27bf23369561e68456025aa24cb46fee130482

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

LOG: Revert "Fix attr docs from previous no-unique-adderss change (#67195)"

This reverts commit 44f2db7493454b41d2f5c81b76bd30f2f035ed31.

It caused
```
error: Record `NoUniqueAddress', field `Documentation' exists but does not have 
a list value
```

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 35eb6ff63132629..bb8d204f33dc531 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1803,6 +1803,7 @@ def NoUniqueAddress : InheritableAttr {
   // No spellings because instances of this attribute are created by
   // MSNoUniqueAddress and ItaniumNoUniqueAddress
   let Spellings = [];
+  let Documentation = [NoUniqueAddressDocs];
 }
 
 def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {



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


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

Expose some predefined macros for Float128 support.

---
Full diff: https://github.com/llvm/llvm-project/pull/67196.diff


1 Files Affected:

- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+2) 


``diff
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e5db8a654e6707d..9e4d4d398a21da5 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1076,6 +1076,8 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
+  if (TI.hasFloat128Type())
+DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
 
   // Define a __POINTER_WIDTH__ macro for stdint.h.
   Builder.defineMacro("__POINTER_WIDTH__",

``




https://github.com/llvm/llvm-project/pull/67196
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-22 Thread Pranav Kant via cfe-commits

https://github.com/pranavk edited 
https://github.com/llvm/llvm-project/pull/67196
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Predefined macros for float128 support (PR #67196)

2023-09-22 Thread Pranav Kant via cfe-commits

https://github.com/pranavk created 
https://github.com/llvm/llvm-project/pull/67196

None

>From 8c07729b195fa78133258b03a31e8668d70a922d Mon Sep 17 00:00:00 2001
From: Pranav Kant 
Date: Fri, 22 Sep 2023 20:50:32 +
Subject: [PATCH] [clang] Predefined macros for float128 support

---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index e5db8a654e6707d..9e4d4d398a21da5 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -1076,6 +1076,8 @@ static void InitializePredefinedMacros(const TargetInfo 
&TI,
   DefineFloatMacros(Builder, "FLT", &TI.getFloatFormat(), "F");
   DefineFloatMacros(Builder, "DBL", &TI.getDoubleFormat(), "");
   DefineFloatMacros(Builder, "LDBL", &TI.getLongDoubleFormat(), "L");
+  if (TI.hasFloat128Type())
+DefineFloatMacros(Builder, "FLT128", &TI.getFloat128Format(), "Q");
 
   // Define a __POINTER_WIDTH__ macro for stdint.h.
   Builder.defineMacro("__POINTER_WIDTH__",

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


[clang] Fix attr docs from previous no-unique-adderss change (PR #67195)

2023-09-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

Previous change in https://github.com/llvm/llvm-project/pull/65675 broke the 
docs generation. 

---
Full diff: https://github.com/llvm/llvm-project/pull/67195.diff


1 Files Affected:

- (modified) clang/include/clang/Basic/Attr.td (-1) 


``diff
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bb8d204f33dc531..35eb6ff63132629 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1803,7 +1803,6 @@ def NoUniqueAddress : InheritableAttr {
   // No spellings because instances of this attribute are created by
   // MSNoUniqueAddress and ItaniumNoUniqueAddress
   let Spellings = [];
-  let Documentation = [NoUniqueAddressDocs];
 }
 
 def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {

``




https://github.com/llvm/llvm-project/pull/67195
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix attr docs from previous no-unique-adderss change (PR #67195)

2023-09-22 Thread Amy Huang via cfe-commits

https://github.com/amykhuang closed 
https://github.com/llvm/llvm-project/pull/67195
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 44f2db7 - Fix attr docs from previous no-unique-adderss change (#67195)

2023-09-22 Thread via cfe-commits

Author: Amy Huang
Date: 2023-09-22T13:55:48-07:00
New Revision: 44f2db7493454b41d2f5c81b76bd30f2f035ed31

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

LOG: Fix attr docs from previous no-unique-adderss change (#67195)

Previous change in https://github.com/llvm/llvm-project/pull/65675 broke
the docs generation.

Added: 


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

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bb8d204f33dc531..35eb6ff63132629 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1803,7 +1803,6 @@ def NoUniqueAddress : InheritableAttr {
   // No spellings because instances of this attribute are created by
   // MSNoUniqueAddress and ItaniumNoUniqueAddress
   let Spellings = [];
-  let Documentation = [NoUniqueAddressDocs];
 }
 
 def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {



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


[clang] Fix attr docs from previous no-unique-adderss change (PR #67195)

2023-09-22 Thread Amy Huang via cfe-commits

https://github.com/amykhuang edited 
https://github.com/llvm/llvm-project/pull/67195
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Fix attr docs from previous no-unique-adderss change (PR #67195)

2023-09-22 Thread Amy Huang via cfe-commits

https://github.com/amykhuang created 
https://github.com/llvm/llvm-project/pull/67195

None

>From d5347c906ac7db40f9b31ad0c0bcd193df453e4e Mon Sep 17 00:00:00 2001
From: Amy Huang 
Date: Fri, 22 Sep 2023 13:54:28 -0700
Subject: [PATCH] Fix attr docs from previous no-unique-adderss change

---
 clang/include/clang/Basic/Attr.td | 1 -
 1 file changed, 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index bb8d204f33dc531..35eb6ff63132629 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1803,7 +1803,6 @@ def NoUniqueAddress : InheritableAttr {
   // No spellings because instances of this attribute are created by
   // MSNoUniqueAddress and ItaniumNoUniqueAddress
   let Spellings = [];
-  let Documentation = [NoUniqueAddressDocs];
 }
 
 def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {

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


[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-22 Thread Artem Belevich via cfe-commits


@@ -537,59 +537,46 @@ void NVPTXAsmPrinter::emitKernelFunctionDirectives(const 
Function &F,
raw_ostream &O) const {
   // If the NVVM IR has some of reqntid* specified, then output
   // the reqntid directive, and set the unspecified ones to 1.
-  // If none of reqntid* is specified, don't output reqntid directive.
-  unsigned reqntidx, reqntidy, reqntidz;
-  bool specified = false;
-  if (!getReqNTIDx(F, reqntidx))
-reqntidx = 1;
-  else
-specified = true;
-  if (!getReqNTIDy(F, reqntidy))
-reqntidy = 1;
-  else
-specified = true;
-  if (!getReqNTIDz(F, reqntidz))
-reqntidz = 1;
-  else
-specified = true;
-
-  if (specified)
-O << ".reqntid " << reqntidx << ", " << reqntidy << ", " << reqntidz
+  // If none of Reqntid* is specified, don't output reqntid directive.
+  unsigned Reqntidx, Reqntidy, Reqntidz;
+  Reqntidx = Reqntidy = Reqntidz = 1;
+  bool ReqSpecified = false;
+  ReqSpecified |= getReqNTIDx(F, Reqntidx);
+  ReqSpecified |= getReqNTIDy(F, Reqntidy);
+  ReqSpecified |= getReqNTIDz(F, Reqntidz);
+
+  if (ReqSpecified)
+O << ".reqntid " << Reqntidx << ", " << Reqntidy << ", " << Reqntidz
   << "\n";
 
   // If the NVVM IR has some of maxntid* specified, then output
   // the maxntid directive, and set the unspecified ones to 1.
   // If none of maxntid* is specified, don't output maxntid directive.
-  unsigned maxntidx, maxntidy, maxntidz;
-  specified = false;
-  if (!getMaxNTIDx(F, maxntidx))
-maxntidx = 1;
-  else
-specified = true;
-  if (!getMaxNTIDy(F, maxntidy))
-maxntidy = 1;
-  else
-specified = true;
-  if (!getMaxNTIDz(F, maxntidz))
-maxntidz = 1;
-  else
-specified = true;
-
-  if (specified)
-O << ".maxntid " << maxntidx << ", " << maxntidy << ", " << maxntidz
+  unsigned Maxntidx, Maxntidy, Maxntidz;
+  Maxntidx = Maxntidy = Maxntidz = 1;
+  bool MaxSpecified = false;
+  MaxSpecified |= getMaxNTIDx(F, Maxntidx);
+  MaxSpecified |= getMaxNTIDy(F, Maxntidy);
+  MaxSpecified |= getMaxNTIDz(F, Maxntidz);
+
+  if (MaxSpecified)
+O << ".maxntid " << Maxntidx << ", " << Maxntidy << ", " << Maxntidz
   << "\n";
 
-  unsigned mincta;
-  if (getMinCTASm(F, mincta))
-O << ".minnctapersm " << mincta << "\n";
+  unsigned Mincta = 0;
+  if (getMinCTASm(F, Mincta))
+O << ".minnctapersm " << Mincta << "\n";
 
-  unsigned maxnreg;
-  if (getMaxNReg(F, maxnreg))
-O << ".maxnreg " << maxnreg << "\n";
+  unsigned Maxnreg = 0;
+  if (getMaxNReg(F, Maxnreg))
+O << ".maxnreg " << Maxnreg << "\n";
+
+  unsigned Maxclusterrank = 0;

Artem-B wrote:

We do not have a good way to issue any diagnostics from LLVM, so the choice 
would be to either reject the IR as invalid, or make an effort to compile to 
valid PTX. Right now we're neither here nor there. 

I'd be fine with either of the options above. That said, ignoring metadata 
which we can't apply seems OK to me.




https://github.com/llvm/llvm-project/pull/66496
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-22 Thread Artem Belevich via cfe-commits


@@ -5607,6 +5607,21 @@ bool Sema::CheckRegparmAttr(const ParsedAttr &AL, 
unsigned &numParams) {
   return false;
 }
 
+// Helper to get CudaArch.
+static CudaArch getCudaArch(const TargetInfo &TI) {

Artem-B wrote:

You may need to verify that `TI->getTriple()->isNVPTX()` before casting, but 
other than that, LGTM.


https://github.com/llvm/llvm-project/pull/66496
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)

2023-09-22 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr resolved 
https://github.com/llvm/llvm-project/pull/67147
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-22 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/67166

>From 3982b40f82c6cb91c9bec407cea6b7a4cdc4220e Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Fri, 22 Sep 2023 08:21:21 -0500
Subject: [PATCH 1/9] [InstSimplify] Add tests for simplify `llvm.ptrmask`; NFC

Differential Revision: https://reviews.llvm.org/D156632
---
 llvm/test/Transforms/InstSimplify/ptrmask.ll | 143 +++
 1 file changed, 143 insertions(+)
 create mode 100644 llvm/test/Transforms/InstSimplify/ptrmask.ll

diff --git a/llvm/test/Transforms/InstSimplify/ptrmask.ll 
b/llvm/test/Transforms/InstSimplify/ptrmask.ll
new file mode 100644
index 000..0af7186978ae5bc
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/ptrmask.ll
@@ -0,0 +1,143 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 2
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+
+declare ptr @llvm.ptrmask.p0.i32(ptr, i32)
+declare ptr @llvm.ptrmask.p0.i64(ptr, i64)
+
+define ptr @ptrmask_simplify_poison_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_poison_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 
poison)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 poison)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_undef_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_undef_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[P]], i32 
undef)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 undef)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_0_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_0_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 0)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 0)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_1s_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_1s_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 -1)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 -1)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_1s_mask_i32_fail(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_1s_mask_i32_fail
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[P]], i32 -1)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 -1)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_poison_ptr(i64 %m) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_poison_ptr
+; CHECK-SAME: (i64 [[M:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr poison, i64 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr poison, i64 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_undef_ptr(i32 %m) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_undef_ptr
+; CHECK-SAME: (i32 [[M:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr undef, i32 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr undef, i32 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_null_ptr(i64 %m) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_null_ptr
+; CHECK-SAME: (i64 [[M:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr null, i64 [[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr null, i64 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_ptrmask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_ptrmask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[M:%.*]] = ptrtoint ptr [[P]] to i64
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %m = ptrtoint ptr %p to i64
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_ptrmask_i32_fail(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_ptrmask_i32_fail
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[M:%.*]] = ptrtoint ptr [[P]] to i32
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[P]], i32 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %m = ptrtoint ptr %p to i32
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_aligned_unused(ptr align 64 %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_aligned_unused
+; CHECK-SAME: (ptr align 64 [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 -64)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 -64)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_aligned_unused_i32_fail(ptr align 64 %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_aligned_unu

[clang] [clang][Interp] Handle CXXScalarValueInitExprs (PR #67147)

2023-09-22 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/67147

>From aaf450faf7a26bb60de14b81fe7a661adb830273 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 22 Sep 2023 16:27:11 +0200
Subject: [PATCH] [clang][Interp] Handle CXXScalarValueInitExprs

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 6 ++
 clang/lib/AST/Interp/ByteCodeExprGen.h   | 1 +
 clang/test/AST/Interp/literals.cpp   | 7 +++
 3 files changed, 14 insertions(+)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e813d4fa651ceaf..c804bab7ce567d0 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1488,6 +1488,12 @@ bool ByteCodeExprGen::VisitOffsetOfExpr(const 
OffsetOfExpr *E) {
   return this->emitOffsetOf(T, E, E);
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXScalarValueInitExpr(
+const CXXScalarValueInitExpr *E) {
+  return this->visitZeroInitializer(E->getType(), E);
+}
+
 template  bool ByteCodeExprGen::discard(const Expr *E) 
{
   if (E->containsErrors())
 return false;
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 47a3f75f13459d0..7cfe4d9251c5f05 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -106,6 +106,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitCXXConstructExpr(const CXXConstructExpr *E);
   bool VisitSourceLocExpr(const SourceLocExpr *E);
   bool VisitOffsetOfExpr(const OffsetOfExpr *E);
+  bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;
diff --git a/clang/test/AST/Interp/literals.cpp 
b/clang/test/AST/Interp/literals.cpp
index ceda59405ea9105..b2210eb1c51b1e1 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -31,6 +31,13 @@ static_assert(b, "");
 constexpr int one = true;
 static_assert(one == 1, "");
 
+constexpr bool b2 = bool();
+static_assert(!b2, "");
+constexpr int ScalarInitInt = int();
+static_assert(ScalarInitInt == 0, "");
+constexpr float ScalarInitFloat = float();
+static_assert(ScalarInitFloat == 0.0f, "");
+
 namespace IntegralCasts {
   constexpr int i = 12;
   constexpr unsigned int ui = i;

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


[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-22 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B resolved 
https://github.com/llvm/llvm-project/pull/66496
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-22 Thread Artem Belevich via cfe-commits

https://github.com/Artem-B resolved 
https://github.com/llvm/llvm-project/pull/66496
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Fix detection of libc++ with empty sysroot. (PR #66947)

2023-09-22 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall closed 
https://github.com/llvm/llvm-project/pull/66947
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7ca8c21 - [Driver] Fix detection of libc++ with empty sysroot. (#66947)

2023-09-22 Thread via cfe-commits

Author: Sam McCall
Date: 2023-09-22T22:29:25+02:00
New Revision: 7ca8c21af36acb117529e797b3d36e85a286ca47

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

LOG: [Driver] Fix detection of libc++ with empty sysroot. (#66947)

b1e3cd1d79443603dc003441e07cdd8d30bb7f26 dropped the leading slash here,
presumably unintentionally.

(I don't understand Driver well enough to know how/where this is
supposed
to be tested, but it broke clangd on any project that uses the
system-installed -stdlib=libc++ on a standard debian install)

Added: 


Modified: 
clang/lib/Driver/ToolChains/Gnu.cpp
clang/unittests/Driver/ToolChainTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index e909549d20708fe..61f5100f1385a13 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -3100,6 +3100,8 @@ Generic_GCC::addLibCxxIncludePaths(const 
llvm::opt::ArgList &DriverArgs,
llvm::opt::ArgStringList &CC1Args) const {
   const Driver &D = getDriver();
   std::string SysRoot = computeSysRoot();
+  if (SysRoot.empty())
+SysRoot = llvm::sys::path::get_separator();
 
   auto AddIncludePath = [&](StringRef Path, bool TargetDirRequired = false) {
 std::string Version = detectLibcxxVersion(Path);

diff  --git a/clang/unittests/Driver/ToolChainTest.cpp 
b/clang/unittests/Driver/ToolChainTest.cpp
index ae567abb81a9bb4..731b6c98c67929c 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -19,10 +19,12 @@
 #include "clang/Driver/Driver.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
+#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
 
@@ -316,6 +318,52 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
   }
 }
 
+MATCHER_P(jobHasArgs, Substr, "") {
+  const driver::Command &C = arg;
+  std::string Args = "";
+  llvm::ListSeparator Sep(" ");
+  for (const char *Arg : C.getArguments()) {
+Args += Sep;
+Args += Arg;
+  }
+  if (is_style_windows(llvm::sys::path::Style::native))
+std::replace(Args.begin(), Args.end(), '\\', '/');
+  if (llvm::StringRef(Args).contains(Substr))
+return true;
+  *result_listener << "whose args are '" << Args << "'";
+  return false;
+}
+
+TEST(ToolChainTest, VFSGnuLibcxxPathNoSysroot) {
+  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
+
+  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
+  struct TestDiagnosticConsumer : public DiagnosticConsumer {};
+  IntrusiveRefCntPtr InMemoryFileSystem(
+  new llvm::vfs::InMemoryFileSystem);
+
+  const char *EmptyFiles[] = {
+  "foo.cpp",
+  "/bin/clang",
+  "/usr/include/c++/v1/cstdio",
+  };
+
+  for (const char *Path : EmptyFiles)
+InMemoryFileSystem->addFile(Path, 0,
+llvm::MemoryBuffer::getMemBuffer("\n"));
+
+  {
+DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
+Driver TheDriver("/bin/clang", "x86_64-unknown-linux-gnu", Diags,
+ "clang LLVM compiler", InMemoryFileSystem);
+std::unique_ptr C(TheDriver.BuildCompilation(
+{"/bin/clang", "-fsyntax-only", "-stdlib=libc++", "foo.cpp"}));
+ASSERT_TRUE(C);
+EXPECT_THAT(C->getJobs(), testing::ElementsAre(jobHasArgs(
+  "-internal-isystem /usr/include/c++/v1")));
+  }
+}
+
 TEST(ToolChainTest, DefaultDriverMode) {
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
 



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


[clang] Implement [[msvc::no_unique_address]] (PR #65675)

2023-09-22 Thread Amy Huang via cfe-commits

https://github.com/amykhuang closed 
https://github.com/llvm/llvm-project/pull/65675
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 4a55d42 - Implement [[msvc::no_unique_address]] (#65675)

2023-09-22 Thread via cfe-commits

Author: Amy Huang
Date: 2023-09-22T13:28:38-07:00
New Revision: 4a55d426967b9c70f5dea7b3a389e11393a4f4c4

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

LOG: Implement [[msvc::no_unique_address]] (#65675)

This implements the [[msvc::no_unique_address]] attribute.

There is not ABI compatibility in this patch because the attribute is
relatively new and there's still some uncertainty in the MSVC version.

Bug: https://github.com/llvm/llvm-project/issues/49358

Also see https://reviews.llvm.org/D157762.

Added: 
clang/test/Layout/ms-no-unique-address.cpp
clang/test/SemaCXX/cxx2a-ms-no-unique-address.cpp

Modified: 
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/AST/Decl.cpp
clang/lib/AST/RecordLayoutBuilder.cpp
clang/lib/Parse/ParseDeclCXX.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/test/Preprocessor/has_attribute.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 21a3b5226623cf2..bb8d204f33dc531 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1798,11 +1798,24 @@ def ArmMveStrictPolymorphism : TypeAttr, 
TargetSpecificAttr {
   let Documentation = [ArmMveStrictPolymorphismDocs];
 }
 
-def NoUniqueAddress : InheritableAttr, TargetSpecificAttr 
{
-  let Spellings = [CXX11<"", "no_unique_address", 201803>];
+def NoUniqueAddress : InheritableAttr {
   let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  // No spellings because instances of this attribute are created by
+  // MSNoUniqueAddress and ItaniumNoUniqueAddress
+  let Spellings = [];
+  let Documentation = [NoUniqueAddressDocs];
+}
+
+def MSNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  let Spellings = [CXX11<"msvc", "no_unique_address", 201803>];
+  let Documentation = [NoUniqueAddressDocs];
+}
+
+def ItaniumNoUniqueAddress : InheritableAttr, 
TargetSpecificAttr {
+  let Subjects = SubjectList<[NonBitField], ErrorDiag>;
+  let Spellings = [CXX11<"", "no_unique_address", 201803>];
   let Documentation = [NoUniqueAddressDocs];
-  let SimpleHandler = 1;
 }
 
 def ReturnsTwice : InheritableAttr {

diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index b13baa46754cfd4..18428d26b5dc8f2 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -1405,6 +1405,10 @@ Example usage:
 
 ``[[no_unique_address]]`` is a standard C++20 attribute. Clang supports its use
 in C++11 onwards.
+
+On MSVC targets, ``[[no_unique_address]]`` is ignored; use
+``[[msvc::no_unique_address]]`` instead. Currently there is no guarantee of ABI
+compatibility or stability.
   }];
 }
 

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 08ae2087cfe70eb..07aee0d87c835a8 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4507,9 +4507,14 @@ bool FieldDecl::isZeroSize(const ASTContext &Ctx) const {
 
   // Otherwise, [...] the circumstances under which the object has zero size
   // are implementation-defined.
-  // FIXME: This might be Itanium ABI specific; we don't yet know what the MS
-  // ABI will do.
-  return true;
+  if (!Ctx.getTargetInfo().getCXXABI().isMicrosoft())
+return true;
+
+  // MS ABI: has nonzero size if it is a class type with class type fields,
+  // whether or not they have nonzero size
+  return !llvm::any_of(CXXRD->fields(), [](const FieldDecl *Field) {
+return Field->getType()->getAs();
+  });
 }
 
 bool FieldDecl::isPotentiallyOverlapping() const {

diff  --git a/clang/lib/AST/RecordLayoutBuilder.cpp 
b/clang/lib/AST/RecordLayoutBuilder.cpp
index 8afd88ae7be27b3..f1f2275da44dcad 100644
--- a/clang/lib/AST/RecordLayoutBuilder.cpp
+++ b/clang/lib/AST/RecordLayoutBuilder.cpp
@@ -2545,7 +2545,10 @@ struct MicrosoftRecordLayoutBuilder {
 CharUnits Alignment;
   };
   typedef llvm::DenseMap BaseOffsetsMapTy;
-  MicrosoftRecordLayoutBuilder(const ASTContext &Context) : Context(Context) {}
+  MicrosoftRecordLayoutBuilder(const ASTContext &Context,
+   EmptySubobjectMap *EmptySubobjects)
+  : Context(Context), EmptySubobjects(EmptySubobjects) {}
+
 private:
   MicrosoftRecordLayoutBuilder(const MicrosoftRecordLayoutBuilder &) = delete;
   void operator=(const MicrosoftRecordLayoutBuilder &) = delete;
@@ -2595,6 +2598,8 @@ struct MicrosoftRecordLayoutBuilder {
   llvm::SmallPtrSetImpl &HasVtorDispSet,
   const CXXRecordDecl *RD) const;
   const ASTContext &Context;
+  EmptySubobjectMap *EmptySubobjects;
+
   /// The size of the record being laid out.
   CharUnits Size;
   /// The non-virtual size of the record layout.
@@ -2908,8 +2913,7 @@ sta

[clang] [Driver] Fix detection of libc++ with empty sysroot. (PR #66947)

2023-09-22 Thread Shoaib Meenai via cfe-commits


@@ -316,6 +318,52 @@ TEST(ToolChainTest, VFSSolarisMultiGCCInstallation) {
   }
 }
 
+MATCHER_P(jobHasArgs, Substr, "") {
+  const driver::Command &C = arg;
+  std::string Args = "";
+  llvm::ListSeparator Sep(" ");
+  for (const char *Arg : C.getArguments()) {
+Args += Sep;
+Args += Arg;
+  }
+  if (is_style_windows(llvm::sys::path::Style::native))
+std::replace(Args.begin(), Args.end(), '\\', '/');
+  if (llvm::StringRef(Args).contains(Substr))
+return true;
+  *result_listener << "whose args are '" << Args << "'";

smeenai wrote:

Cool, sounds good.

https://github.com/llvm/llvm-project/pull/66947
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Driver] Fix detection of libc++ with empty sysroot. (PR #66947)

2023-09-22 Thread Shoaib Meenai via cfe-commits

https://github.com/smeenai resolved 
https://github.com/llvm/llvm-project/pull/66947
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-22 Thread Florian Hahn via cfe-commits


@@ -183,8 +183,7 @@ define <16 x i8> @ptrmask_align8_ptr_align1(ptr align 1 
%ptr) {
 ; TODO: Should be able to drop the ptrmask

fhahn wrote:

remove TODO now?

https://github.com/llvm/llvm-project/pull/67166
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-22 Thread Florian Hahn via cfe-commits


@@ -196,8 +195,7 @@ define <16 x i8> @ptrmask_align8_ptr_align8(ptr align 8 
%ptr) {
 ; TODO: Should be able to drop the ptrmask

fhahn wrote:

remove TODO now

https://github.com/llvm/llvm-project/pull/67166
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D153485: [dataflow] use true/false literals in formulas, rather than variables

2023-09-22 Thread Vlad Vereschaka via Phabricator via cfe-commits
vvereschaka added a comment.

Hi @sammccall,

also failed `FAIL: Clang-Unit::69` test on these builders

- https://lab.llvm.org/buildbot/#/builders/86/builds/65581
- https://lab.llvm.org/buildbot/#/builders/60/builds/14027
- https://lab.llvm.org/buildbot/#/builders/119/builds/15226


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153485

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-22 Thread via cfe-commits

https://github.com/goldsteinn edited 
https://github.com/llvm/llvm-project/pull/67166
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-22 Thread via cfe-commits

https://github.com/goldsteinn updated 
https://github.com/llvm/llvm-project/pull/67166

>From 3982b40f82c6cb91c9bec407cea6b7a4cdc4220e Mon Sep 17 00:00:00 2001
From: Noah Goldstein 
Date: Fri, 22 Sep 2023 08:21:21 -0500
Subject: [PATCH 1/9] [InstSimplify] Add tests for simplify `llvm.ptrmask`; NFC

Differential Revision: https://reviews.llvm.org/D156632
---
 llvm/test/Transforms/InstSimplify/ptrmask.ll | 143 +++
 1 file changed, 143 insertions(+)
 create mode 100644 llvm/test/Transforms/InstSimplify/ptrmask.ll

diff --git a/llvm/test/Transforms/InstSimplify/ptrmask.ll 
b/llvm/test/Transforms/InstSimplify/ptrmask.ll
new file mode 100644
index 000..0af7186978ae5bc
--- /dev/null
+++ b/llvm/test/Transforms/InstSimplify/ptrmask.ll
@@ -0,0 +1,143 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 2
+; RUN: opt < %s -passes=instsimplify -S | FileCheck %s
+
+declare ptr @llvm.ptrmask.p0.i32(ptr, i32)
+declare ptr @llvm.ptrmask.p0.i64(ptr, i64)
+
+define ptr @ptrmask_simplify_poison_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_poison_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 
poison)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 poison)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_undef_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_undef_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[P]], i32 
undef)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 undef)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_0_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_0_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 0)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 0)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_1s_mask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_1s_mask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 -1)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 -1)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_1s_mask_i32_fail(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_1s_mask_i32_fail
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[P]], i32 -1)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 -1)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_poison_ptr(i64 %m) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_poison_ptr
+; CHECK-SAME: (i64 [[M:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr poison, i64 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr poison, i64 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_undef_ptr(i32 %m) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_undef_ptr
+; CHECK-SAME: (i32 [[M:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr undef, i32 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr undef, i32 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_null_ptr(i64 %m) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_null_ptr
+; CHECK-SAME: (i64 [[M:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr null, i64 [[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr null, i64 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_ptrmask(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_ptrmask
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[M:%.*]] = ptrtoint ptr [[P]] to i64
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %m = ptrtoint ptr %p to i64
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_ptrmask_i32_fail(ptr %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_ptrmask_i32_fail
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT:[[M:%.*]] = ptrtoint ptr [[P]] to i32
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[P]], i32 
[[M]])
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %m = ptrtoint ptr %p to i32
+  %r = call ptr @llvm.ptrmask.p0.i32(ptr %p, i32 %m)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_aligned_unused(ptr align 64 %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_aligned_unused
+; CHECK-SAME: (ptr align 64 [[P:%.*]]) {
+; CHECK-NEXT:[[R:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[P]], i64 -64)
+; CHECK-NEXT:ret ptr [[R]]
+;
+  %r = call ptr @llvm.ptrmask.p0.i64(ptr %p, i64 -64)
+  ret ptr %r
+}
+
+define ptr @ptrmask_simplify_aligned_unused_i32_fail(ptr align 64 %p) {
+; CHECK-LABEL: define ptr @ptrmask_simplify_aligned_unu

[clang] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread via cfe-commits

https://github.com/michaelrj-google resolved 
https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread via cfe-commits

https://github.com/michaelrj-google resolved 
https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread via cfe-commits

https://github.com/michaelrj-google resolved 
https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread via cfe-commits

https://github.com/michaelrj-google resolved 
https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread via cfe-commits

https://github.com/michaelrj-google resolved 
https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread via cfe-commits

https://github.com/michaelrj-google resolved 
https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [libc] Refactor scanf reader to match printf (PR #66023)

2023-09-22 Thread via cfe-commits

https://github.com/michaelrj-google resolved 
https://github.com/llvm/llvm-project/pull/66023
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >