[clang] b67ce7e - [clang] Use StringRef::starts_with (NFC)

2024-01-31 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2024-01-31T23:54:09-08:00
New Revision: b67ce7e34948d4d954d3cfedb29ffc94861ca0b2

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

LOG: [clang] Use StringRef::starts_with (NFC)

Added: 


Modified: 
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/Targets/X86.cpp
clang/lib/CodeGen/CGObjCMac.cpp
clang/lib/Format/FormatTokenLexer.cpp
clang/lib/Frontend/FrontendActions.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 63e56a8296db3..4363280757714 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -2264,7 +2264,7 @@ printTo(raw_ostream , ArrayRef Args, const 
PrintingPolicy ,
 // If this is the first argument and its string representation
 // begins with the global scope specifier ('::foo'), add a space
 // to avoid printing the diagraph '<:'.
-if (FirstArg && !ArgString.empty() && ArgString[0] == ':')
+if (FirstArg && ArgString.starts_with(":"))
   OS << ' ';
 
 OS << ArgString;

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index a68b662d9401a..c6fc17fcc1b70 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -151,7 +151,7 @@ bool X86TargetInfo::initFeatureMap(
   // Postpone AVX10 features handling after AVX512 settled.
   UpdatedAVX10FeaturesVec.push_back(Feature);
   continue;
-} else if (!HasAVX512F && Feature.substr(0, 7) == "+avx512") {
+} else if (!HasAVX512F && StringRef(Feature).starts_with("+avx512")) {
   HasAVX512F = true;
   LastAVX512 = Feature;
 } else if (HasAVX512F && Feature == "-avx512f") {

diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 517f7cddebc1a..27d77e9a8a551 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -5038,12 +5038,10 @@ std::string CGObjCCommonMac::GetSectionName(StringRef 
Section,
 return ("__DATA," + Section + "," + MachOAttributes).str();
   }
   case llvm::Triple::ELF:
-assert(Section.substr(0, 2) == "__" &&
-   "expected the name to begin with __");
+assert(Section.starts_with("__") && "expected the name to begin with __");
 return Section.substr(2).str();
   case llvm::Triple::COFF:
-assert(Section.substr(0, 2) == "__" &&
-   "expected the name to begin with __");
+assert(Section.starts_with("__") && "expected the name to begin with __");
 return ("." + Section.substr(2) + "$B").str();
   case llvm::Triple::Wasm:
   case llvm::Triple::GOFF:

diff  --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index d7de09ef0e12a..a87d0ba3dbbf9 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -1420,7 +1420,7 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
   // For formatting, treat unterminated string literals like normal string
   // literals.
   if (Tok.is(tok::unknown)) {
-if (!Tok.TokenText.empty() && Tok.TokenText[0] == '"') {
+if (Tok.TokenText.starts_with("\"")) {
   Tok.Tok.setKind(tok::string_literal);
   Tok.IsUnterminatedLiteral = true;
 } else if (Style.isJavaScript() && Tok.TokenText == "''") {

diff  --git a/clang/lib/Frontend/FrontendActions.cpp 
b/clang/lib/Frontend/FrontendActions.cpp
index c1d6e71455365..b9ed5dedfa422 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -826,8 +826,7 @@ void DumpModuleInfoAction::ExecuteAction() {
   auto  = CI.getFileManager();
   auto Buffer = FileMgr.getBufferForFile(getCurrentFile());
   StringRef Magic = (*Buffer)->getMemBufferRef().getBuffer();
-  bool IsRaw = (Magic.size() >= 4 && Magic[0] == 'C' && Magic[1] == 'P' &&
-Magic[2] == 'C' && Magic[3] == 'H');
+  bool IsRaw = Magic.starts_with("CPCH");
   Out << "  Module format: " << (IsRaw ? "raw" : "obj") << "\n";
 
   Preprocessor  = CI.getPreprocessor();



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


[llvm] [clang] [RISCV] Support constraint "s" (PR #80201)

2024-01-31 Thread Kito Cheng via cfe-commits

https://github.com/kito-cheng approved this pull request.

Just one minor comment, otherwise LGTM :)

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


[llvm] [clang] [RISCV] Support constraint "s" (PR #80201)

2024-01-31 Thread Kito Cheng via cfe-commits


@@ -0,0 +1,76 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=riscv32 -relocation-model=static < %s | FileCheck %s 
--check-prefix=RV32
+; RUN: llc -mtriple=riscv64 -relocation-model=pic < %s | FileCheck %s 
--check-prefix=RV64
+
+@var = external dso_local global i32, align 4
+@a = external global [2 x [2 x i32]], align 4
+
+define dso_local void @test() {
+; CHECK-LABEL: test:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:#APP
+; CHECK-NEXT:# var a+12 test
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret{{[l|q]}}

kito-cheng wrote:

I don't see any line check with `CHECK`? maybe you forgot to drop after regen?

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


[llvm] [clang] [RISCV] Support constraint "s" (PR #80201)

2024-01-31 Thread Kito Cheng via cfe-commits

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


[polly] [clang] [clang-format] Add Automatic and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread via cfe-commits

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


[polly] [clang] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread via cfe-commits

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

> The issue is up: #80252

Thanks. Although I feel it is too implementor's view, (I mean the end users can 
hardly understand it), it is much better.

> Yeah, looking at the similarities, there is a decent chance this is the same 
> issue, it's worth trying it out.

Yeah, let's give it a try.


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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] 
<{{.*}}> col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'

ChuanqiXu9 wrote:

In such case, I'd like to introduce unittest. For example 
https://github.com/llvm/llvm-project/blob/main/clang/unittests/Sema/SemaNoloadLookupTest.cpp,
 
https://github.com/llvm/llvm-project/blob/main/clang/unittests/Serialization/VarDeclConstantInitTest.cpp
 and 
https://github.com/llvm/llvm-project/pull/76774/files#diff-b1c26f074f25d8306b5ac4522770a2487a57194176355cf9af17688217573788.

While it may take you 10+ minutes, it will look much prettier than the current 
way.

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> IIRC, in #79959, you're saying the patch have the potential to fix #78850? Is 
> it true?

Yeah, looking at the similarities, there is a decent chance this is the same 
issue, it's worth trying it out.

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


[llvm] [clang] [compiler-rt] [clang-repl] [ORC] Add support for out-of-process execution on ELF (PR #79936)

2024-01-31 Thread Vassil Vassilev via cfe-commits


@@ -16,13 +16,24 @@
 #include "clang/Interpreter/CodeCompletion.h"
 #include "clang/Interpreter/Interpreter.h"
 
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ExecutionEngine/Orc/SimpleRemoteEPC.h"
 #include "llvm/LineEditor/LineEditor.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ManagedStatic.h" // llvm_shutdown
 #include "llvm/Support/Signals.h"
 #include "llvm/Support/TargetSelect.h"
+#include "llvm/TargetParser/Host.h"
 #include 
+#include 
+
+#ifdef LLVM_ON_UNIX
+#include 
+#include 
+#include 
+#endif // LLVM_ON_UNIX

vgvassilev wrote:

Have you had a chance to try it out on Windows? If that's beyond our scope we 
might want to add the platform to the unsupported platforms on the tests.

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


[llvm] [compiler-rt] [clang] [clang-repl] [ORC] Add support for out-of-process execution on ELF (PR #79936)

2024-01-31 Thread Vassil Vassilev via cfe-commits


@@ -143,6 +169,201 @@ ReplListCompleter::operator()(llvm::StringRef Buffer, 
size_t Pos,
   return Comps;
 }
 
+static llvm::Error sanitizeOopArguments(const char *ArgV0) {
+  llvm::Triple SystemTriple(llvm::sys::getProcessTriple());
+  if ((OutOfProcessExecutor.getNumOccurrences() ||
+   OutOfProcessExecutorConnect.getNumOccurrences()) &&
+  (!SystemTriple.isOSBinFormatELF()))
+return llvm::make_error(
+"Out-process-executors are currently only supported on ELF",
+llvm::inconvertibleErrorCode());
+
+  // Only one of -oop-executor and -oop-executor-connect can be used.
+  if (!!OutOfProcessExecutor.getNumOccurrences() &&
+  !!OutOfProcessExecutorConnect.getNumOccurrences())
+return llvm::make_error(
+"Only one of -" + OutOfProcessExecutor.ArgStr + " and -" +
+OutOfProcessExecutorConnect.ArgStr + " can be specified",
+llvm::inconvertibleErrorCode());
+
+  // If -oop-executor was used but no value was specified then use a sensible
+  // default.
+  if (!!OutOfProcessExecutor.getNumOccurrences() &&
+  OutOfProcessExecutor.empty()) {
+llvm::SmallString<256> OOPExecutorPath(llvm::sys::fs::getMainExecutable(
+ArgV0, reinterpret_cast()));
+llvm::sys::path::remove_filename(OOPExecutorPath);
+llvm::sys::path::append(OOPExecutorPath, "llvm-jitlink-executor");
+OutOfProcessExecutor = OOPExecutorPath.str().str();
+  }
+
+  // Out-of-process executors must run with the ORC runtime for destructor 
support.
+  if (OrcRuntimePath.empty() && (OutOfProcessExecutor.getNumOccurrences() || 
OutOfProcessExecutorConnect.getNumOccurrences())) {
+llvm::SmallString<256> OrcPath(llvm::sys::fs::getMainExecutable(
+ArgV0, reinterpret_cast()));
+llvm::sys::path::remove_filename(OrcPath); // Remove clang-repl filename.
+llvm::sys::path::remove_filename(OrcPath); // Remove ./bin directory.
+llvm::sys::path::append(OrcPath, 
"lib/clang/18/lib/x86_64-unknown-linux-gnu/liborc_rt.a");
+OrcRuntimePath = OrcPath.str().str();
+  }
+
+  return llvm::Error::success();
+}
+
+static llvm::Expected>
+launchExecutor() {
+  constexpr int ReadEnd = 0;
+  constexpr int WriteEnd = 1;
+
+  // Pipe FDs.
+  int ToExecutor[2];
+  int FromExecutor[2];
+
+  pid_t ChildPID;
+
+  // Create pipes to/from the executor..
+  if (pipe(ToExecutor) != 0 || pipe(FromExecutor) != 0)
+return llvm::make_error(
+"Unable to create pipe for executor", llvm::inconvertibleErrorCode());
+
+  ChildPID = fork();
+
+  if (ChildPID == 0) {
+// In the child...
+
+// Close the parent ends of the pipes
+close(ToExecutor[WriteEnd]);
+close(FromExecutor[ReadEnd]);
+
+// Execute the child process.
+std::unique_ptr ExecutorPath, FDSpecifier;
+{
+  ExecutorPath = std::make_unique(OutOfProcessExecutor.size() + 1);
+  strcpy(ExecutorPath.get(), OutOfProcessExecutor.data());
+
+  std::string FDSpecifierStr("filedescs=");
+  FDSpecifierStr += llvm::utostr(ToExecutor[ReadEnd]);
+  FDSpecifierStr += ',';
+  FDSpecifierStr += llvm::utostr(FromExecutor[WriteEnd]);
+  FDSpecifier = std::make_unique(FDSpecifierStr.size() + 1);
+  strcpy(FDSpecifier.get(), FDSpecifierStr.c_str());
+}
+
+char *const Args[] = {ExecutorPath.get(), FDSpecifier.get(), nullptr};
+int RC = execvp(ExecutorPath.get(), Args);
+if (RC != 0) {
+  llvm::errs() << "unable to launch out-of-process executor \""
+   << ExecutorPath.get() << "\"\n";
+  exit(1);
+}
+  }
+  // else we're the parent...
+
+  // Close the child ends of the pipes
+  close(ToExecutor[ReadEnd]);
+  close(FromExecutor[WriteEnd]);
+
+  auto S = llvm::orc::SimpleRemoteEPC::Setup();
+
+  return llvm::orc::SimpleRemoteEPC::Create<
+  llvm::orc::FDSimpleRemoteEPCTransport>(
+  std::make_unique(),
+  std::move(S), FromExecutor[ReadEnd], ToExecutor[WriteEnd]);
+}
+
+#if LLVM_ON_UNIX && LLVM_ENABLE_THREADS
+static llvm::Error createTCPSocketError(llvm::Twine Details) {
+  return llvm::make_error(
+  formatv("Failed to connect TCP socket '{0}': {1}",
+  OutOfProcessExecutorConnect, Details),
+  llvm::inconvertibleErrorCode());
+}
+
+static llvm::Expected connectTCPSocket(std::string Host,
+std::string PortStr) {
+  addrinfo *AI;
+  addrinfo Hints{};
+  Hints.ai_family = AF_INET;
+  Hints.ai_socktype = SOCK_STREAM;
+  Hints.ai_flags = AI_NUMERICSERV;
+
+  if (int EC = getaddrinfo(Host.c_str(), PortStr.c_str(), , ))
+return createTCPSocketError("Address resolution failed (" +
+llvm::StringRef(gai_strerror(EC)) + ")");
+
+  // Cycle through the returned addrinfo structures and connect to the first
+  // reachable endpoint.
+  int SockFD;
+  addrinfo *Server;
+  for (Server = AI; Server != nullptr; Server = Server->ai_next) {
+// socket might fail, e.g. if the address family is not supported. Skip to
+// 

[llvm] [compiler-rt] [clang] [clang-repl] [ORC] Add support for out-of-process execution on ELF (PR #79936)

2024-01-31 Thread Vassil Vassilev via cfe-commits


@@ -0,0 +1,61 @@
+// REQUIRES: host-supports-jit, x86_64-linux

vgvassilev wrote:

I believe this test copies some content from other tests. Would it make sense 
to add an extra `RUN` line to the tests themselves?

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


[llvm] [compiler-rt] [clang] [clang-repl] [ORC] Add support for out-of-process execution on ELF (PR #79936)

2024-01-31 Thread Vassil Vassilev via cfe-commits

https://github.com/vgvassilev commented:

Thank you for working on this. This looks very good. I have left comments from 
my first review pass. We probably want to wait for @lhames and @weliveindetail 
to take a look.

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


[clang] [compiler-rt] [llvm] [clang-repl] [ORC] Add support for out-of-process execution on ELF (PR #79936)

2024-01-31 Thread Vassil Vassilev via cfe-commits

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


[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-01-31 Thread Bill Wendling via cfe-commits

bwendling wrote:

This is a first step in improving our `__bdos` implementation. It doesn't 
address the "sub-object" discussion from the previous PR 
(https://github.com/llvm/llvm-project/pull/78526), that will come later on. 
This patch takes care of a common use of `__bdos` that can't be calculated by 
the front-end (i.e. performing a __bdos on an array with an variable index). 
I'll be expanding the cases this can handle in the future.

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


[clang] [polly] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread via cfe-commits


@@ -922,8 +922,39 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int LongName::
+///   AnotherLongName();
 /// \endcode
 RTBS_None,
+/// Break after return type automatically.
+/// This mode doesn't have the same inherent restriction on breaking after
+/// short return types as ``RTBS_None`` and is solely based on
+/// ``PenaltyReturnTypeOnItsOwnLine``.
+/// \code
+///   class A {
+/// int f() { return 0; };
+///   };
+///   int f();
+///   int f() { return 1; }
+///   int
+///   LongName::AnotherLongName();
+/// \endcode
+RTBS_AllowShortType,
+/// Break after return type automatically.
+/// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
+/// This mode will never break after short return types, unlike
+/// ``RTBS_None`` which will only sometimes choose not to break after short
+/// return types.

rmarker wrote:

Done

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


[polly] [clang] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread via cfe-commits


@@ -922,8 +922,39 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int LongName::
+///   AnotherLongName();
 /// \endcode
 RTBS_None,
+/// Break after return type automatically.
+/// This mode doesn't have the same inherent restriction on breaking after
+/// short return types as ``RTBS_None`` and is solely based on
+/// ``PenaltyReturnTypeOnItsOwnLine``.

rmarker wrote:

Done

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


[clang] [polly] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread via cfe-commits


@@ -922,8 +922,39 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int LongName::
+///   AnotherLongName();
 /// \endcode

rmarker wrote:

Done

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


[polly] [clang] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread via cfe-commits


@@ -922,8 +922,39 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int LongName::
+///   AnotherLongName();
 /// \endcode
 RTBS_None,
+/// Break after return type automatically.
+/// This mode doesn't have the same inherent restriction on breaking after
+/// short return types as ``RTBS_None`` and is solely based on
+/// ``PenaltyReturnTypeOnItsOwnLine``.
+/// \code
+///   class A {
+/// int f() { return 0; };
+///   };
+///   int f();
+///   int f() { return 1; }
+///   int
+///   LongName::AnotherLongName();
+/// \endcode
+RTBS_AllowShortType,

rmarker wrote:

Done

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


[polly] [clang] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread via cfe-commits

rmarker wrote:

> +1. In addition, we should deprecate `None` (in documentation only) and 
> rename `AllowShortType` to `Automatic`, followed by `ExceptShortType` which 
> means "`Automatic` except for short return types". Then IMO `ExceptShortType` 
> is unambiguous. If you still think `NeverShortType` is clearer, I would 
> change it to `NotShortType`.

Sounds like a plan.
Updated PR with changes.

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


[polly] [clang] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread via cfe-commits

https://github.com/rmarker updated 
https://github.com/llvm/llvm-project/pull/78011

>From a1312a0a463bb946f336977b5b01ef7afbede678 Mon Sep 17 00:00:00 2001
From: rmarker 
Date: Thu, 11 Jan 2024 15:01:18 +1030
Subject: [PATCH 01/15] [clang-format] Add ShortReturnTypeColumn option.

---
 clang/docs/ClangFormatStyleOptions.rst | 13 +++
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h| 12 ++
 clang/lib/Format/ContinuationIndenter.cpp  |  3 +-
 clang/lib/Format/Format.cpp|  2 +
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  | 44 ++
 7 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f26..7836cc8f1c9bb 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -4999,6 +4999,19 @@ the configuration (without a prefix: ``Auto``).
int bar;   int bar;
  } // namespace b   } // namespace b
 
+.. _ShortReturnTypeColumn:
+
+**ShortReturnTypeColumn** (``Unsigned``) :versionbadge:`clang-format 19` 
:ref:`¶ `
+  When ``AlwaysBreakAfterReturnType`` is ``None``, line breaks are prevented
+  after short return types. This configures the column limit for a type
+  to be regarded as short.
+
+
+  .. note::
+
+   This isn't the length of the type itself, but the column where it
+   finishes. I.e. it includes indentation, etc.
+
 .. _SkipMacroDefinitionBody:
 
 **SkipMacroDefinitionBody** (``Boolean``) :versionbadge:`clang-format 18` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5330cd9caad80..669b420fe21ec 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -184,6 +184,7 @@ AST Matchers
 
 clang-format
 
+- Add ``ShortReturnTypeColumn`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9eb..7fd574c98a394 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3932,6 +3932,17 @@ struct FormatStyle {
   /// \version 13
   unsigned ShortNamespaceLines;
 
+  /// When ``AlwaysBreakAfterReturnType`` is ``None``, line breaks are 
prevented
+  /// after short return types. This configures the column limit for a type
+  /// to be regarded as short.
+  ///
+  /// \note
+  ///  This isn't the length of the type itself, but the column where it
+  ///  finishes. I.e. it includes indentation, etc.
+  /// \endnote
+  /// \version 19
+  unsigned ShortReturnTypeColumn;
+
   /// Do not format macro definition body.
   /// \version 18
   bool SkipMacroDefinitionBody;
@@ -4899,6 +4910,7 @@ struct FormatStyle {
RequiresExpressionIndentation == R.RequiresExpressionIndentation &&
SeparateDefinitionBlocks == R.SeparateDefinitionBlocks &&
ShortNamespaceLines == R.ShortNamespaceLines &&
+   ShortReturnTypeColumn == R.ShortReturnTypeColumn &&
SkipMacroDefinitionBody == R.SkipMacroDefinitionBody &&
SortIncludes == R.SortIncludes &&
SortJavaStaticImport == R.SortJavaStaticImport &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index a3eb9138b2183..3f9c0cc815745 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -328,7 +328,8 @@ bool ContinuationIndenter::canBreak(const LineState ) 
{
 
   // Don't break after very short return types (e.g. "void") as that is often
   // unexpected.
-  if (Current.is(TT_FunctionDeclarationName) && State.Column < 6) {
+  if (Current.is(TT_FunctionDeclarationName) &&
+  State.Column <= Style.ShortReturnTypeColumn) {
 if (Style.AlwaysBreakAfterReturnType == FormatStyle::RTBS_None)
   return false;
   }
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff326dc784783..35478fac7b496 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1085,6 +1085,7 @@ template <> struct MappingTraits {
Style.RequiresExpressionIndentation);
 IO.mapOptional("SeparateDefinitionBlocks", Style.SeparateDefinitionBlocks);
 IO.mapOptional("ShortNamespaceLines", Style.ShortNamespaceLines);
+IO.mapOptional("ShortReturnTypeColumn", Style.ShortReturnTypeColumn);
 IO.mapOptional("SkipMacroDefinitionBody", Style.SkipMacroDefinitionBody);
 IO.mapOptional("SortIncludes", Style.SortIncludes);
 IO.mapOptional("SortJavaStaticImport", Style.SortJavaStaticImport);
@@ -1557,6 +1558,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.RequiresExpressionIndentation = FormatStyle::REI_OuterScope;
   LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
   LLVMStyle.ShortNamespaceLines = 1;
+  

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

The issue is up: https://github.com/llvm/llvm-project/issues/80252

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


[clang] [Clang][test] Limit library search when linking shared lib (PR #80253)

2024-01-31 Thread Chuanqi Xu via cfe-commits

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

LGTM. Thanks.

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


[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Bill Wendling (bwendling)


Changes

If we're able to, we convert a call to __builtin_dynamic_object_size into a 
calculation. This is a cleaner implementation, and has the potential to improve 
optimizations and, especially, inlining, because optimizing around an 
'llvm.objectsize' call isn't trivial.

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+149-6) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (+7-6) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+6) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f3ab5ad7b08ec..2c109821de43c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -26,6 +26,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/OSLog.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
@@ -1051,6 +1052,145 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr 
*E, unsigned Type,
   return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, 
IsSigned));
 }
 
+namespace {
+
+/// \p StructBaseExpr returns the base \p Expr with a structure or union type.
+struct StructBaseExpr : public ConstStmtVisitor {
+  StructBaseExpr() = default;
+
+  
//======//
+  //Visitor Methods
+  
//======//
+
+  const Expr *VisitStmt(const Stmt *S) { return nullptr; }
+
+  const Expr *Visit(const Expr *E) {
+QualType Ty = E->getType();
+if (Ty->isStructureType() || Ty->isUnionType())
+  return E;
+
+return ConstStmtVisitor::Visit(E);
+  }
+
+  const Expr *VisitDeclRefExpr(const DeclRefExpr *E) { return E; }
+
+  const Expr *VisitMemberExpr(const MemberExpr *E) {
+return Visit(E->getBase());
+  }
+  const Expr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
+return Visit(E->getBase());
+  }
+  const Expr *VisitCastExpr(const CastExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const Expr *VisitParenExpr(const ParenExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const Expr *VisitUnaryAddrOf(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+  const Expr *VisitUnaryDeref(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+};
+
+} // end anonymous namespace
+
+/// The offset of a field from the beginning of the record.
+llvm::Value *
+CodeGenFunction::tryEmitObjectSizeCalculation(const Expr *E, unsigned Type,
+  llvm::IntegerType *ResType) {
+  if ((Type & 0x01) != 0)
+// We handle only the whole object size.
+return nullptr;
+
+  E = E->IgnoreParenImpCasts();
+
+  const Expr *Base = StructBaseExpr().Visit(E);
+  if (!Base)
+return nullptr;
+
+  const RecordDecl *RD = Base->getType()->getAsRecordDecl();
+  if (!RD)
+return nullptr;
+
+  // Get the full size of the struct.
+  ASTContext  = getContext();
+  const RecordDecl *OuterRD = RD->getOuterLexicalRecordContext();
+  const clang::Type *RT = OuterRD->getTypeForDecl();
+  CharUnits RecordSize = Ctx.getTypeSizeInChars(RT);
+
+  Value *Res = nullptr;
+
+  if (const auto *U = dyn_cast(E);
+  U && (U->getOpcode() == UO_AddrOf || U->getOpcode() == UO_Deref))
+E = U->getSubExpr()->IgnoreParenImpCasts();
+
+  if (const auto *ASE = dyn_cast(E)) {
+const Expr *Idx = ASE->getIdx();
+Base = ASE->getBase()->IgnoreParenImpCasts();
+
+if (const auto *ME = dyn_cast(Base);
+ME && ME->getType()->isConstantArrayType()) {
+  // The simple case:
+  //
+  // struct s {
+  // int arr[42];
+  // char c;
+  // /* others */
+  // };
+  //
+  // __builtin_dynamic_object_size(>arr[idx], 0);
+  //
+  // We can translate the __builtin_dynamic_object_call into:
+  //
+  // sizeof(struct s) - offsetof(arr) - (idx * sizeof(int))
+  //
+  bool IsSigned = Idx->getType()->isSignedIntegerType();
+  Value *IdxInst = EmitAnyExprToTemp(Idx).getScalarVal();
+  IdxInst = Builder.CreateIntCast(IdxInst, ResType, IsSigned);
+
+  const ConstantArrayType *CAT = cast(ME->getType());
+  CharUnits ElemSize = Ctx.getTypeSizeInChars(CAT->getElementType());
+  Value *ElemSizeInst = Builder.getInt32(ElemSize.getQuantity());
+  ElemSizeInst = Builder.CreateIntCast(ElemSizeInst, ResType, IsSigned);
+
+  // idx * sizeof()
+  Res = Builder.CreateMul(IdxInst, ElemSizeInst, "", !IsSigned, IsSigned);
+
+  // sizeof(struct s)
+  Value *RecordSizeInst = Builder.getInt32(RecordSize.getQuantity());
+  RecordSizeInst = Builder.CreateIntCast(RecordSizeInst, 

[clang] [Clang] Convert __builtin_dynamic_object_size into a calculation (PR #80256)

2024-01-31 Thread Bill Wendling via cfe-commits

https://github.com/bwendling created 
https://github.com/llvm/llvm-project/pull/80256

If we're able to, we convert a call to __builtin_dynamic_object_size into a 
calculation. This is a cleaner implementation, and has the potential to improve 
optimizations and, especially, inlining, because optimizing around an 
'llvm.objectsize' call isn't trivial.

>From d08abc7a9454557ffa43fc14611177f2c4e7fba4 Mon Sep 17 00:00:00 2001
From: Bill Wendling 
Date: Wed, 31 Jan 2024 13:07:53 -0800
Subject: [PATCH] [Clang] Convert __builtin_dynamic_object_size into a
 calculation

If we're able to, we convert a call to __builtin_dynamic_object_size
into a calculation. This is a cleaner implementation, and has the
potential to improve optimizations and, especially, inlining, because
optimizing around an 'llvm.objectsize' call isn't trivial.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 155 ++--
 clang/lib/CodeGen/CGExpr.cpp|  13 +--
 clang/lib/CodeGen/CodeGenFunction.h |   6 ++
 3 files changed, 162 insertions(+), 12 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f3ab5ad7b08ec..2c109821de43c 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -26,6 +26,7 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/OSLog.h"
 #include "clang/AST/OperationKinds.h"
+#include "clang/AST/StmtVisitor.h"
 #include "clang/Basic/TargetBuiltins.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/Basic/TargetOptions.h"
@@ -1051,6 +1052,145 @@ CodeGenFunction::emitFlexibleArrayMemberSize(const Expr 
*E, unsigned Type,
   return Builder.CreateSelect(Cmp, Res, ConstantInt::get(ResType, 0, 
IsSigned));
 }
 
+namespace {
+
+/// \p StructBaseExpr returns the base \p Expr with a structure or union type.
+struct StructBaseExpr : public ConstStmtVisitor {
+  StructBaseExpr() = default;
+
+  
//======//
+  //Visitor Methods
+  
//======//
+
+  const Expr *VisitStmt(const Stmt *S) { return nullptr; }
+
+  const Expr *Visit(const Expr *E) {
+QualType Ty = E->getType();
+if (Ty->isStructureType() || Ty->isUnionType())
+  return E;
+
+return ConstStmtVisitor::Visit(E);
+  }
+
+  const Expr *VisitDeclRefExpr(const DeclRefExpr *E) { return E; }
+
+  const Expr *VisitMemberExpr(const MemberExpr *E) {
+return Visit(E->getBase());
+  }
+  const Expr *VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
+return Visit(E->getBase());
+  }
+  const Expr *VisitCastExpr(const CastExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const Expr *VisitParenExpr(const ParenExpr *E) {
+return Visit(E->getSubExpr());
+  }
+  const Expr *VisitUnaryAddrOf(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+  const Expr *VisitUnaryDeref(const clang::UnaryOperator *E) {
+return Visit(E->getSubExpr());
+  }
+};
+
+} // end anonymous namespace
+
+/// The offset of a field from the beginning of the record.
+llvm::Value *
+CodeGenFunction::tryEmitObjectSizeCalculation(const Expr *E, unsigned Type,
+  llvm::IntegerType *ResType) {
+  if ((Type & 0x01) != 0)
+// We handle only the whole object size.
+return nullptr;
+
+  E = E->IgnoreParenImpCasts();
+
+  const Expr *Base = StructBaseExpr().Visit(E);
+  if (!Base)
+return nullptr;
+
+  const RecordDecl *RD = Base->getType()->getAsRecordDecl();
+  if (!RD)
+return nullptr;
+
+  // Get the full size of the struct.
+  ASTContext  = getContext();
+  const RecordDecl *OuterRD = RD->getOuterLexicalRecordContext();
+  const clang::Type *RT = OuterRD->getTypeForDecl();
+  CharUnits RecordSize = Ctx.getTypeSizeInChars(RT);
+
+  Value *Res = nullptr;
+
+  if (const auto *U = dyn_cast(E);
+  U && (U->getOpcode() == UO_AddrOf || U->getOpcode() == UO_Deref))
+E = U->getSubExpr()->IgnoreParenImpCasts();
+
+  if (const auto *ASE = dyn_cast(E)) {
+const Expr *Idx = ASE->getIdx();
+Base = ASE->getBase()->IgnoreParenImpCasts();
+
+if (const auto *ME = dyn_cast(Base);
+ME && ME->getType()->isConstantArrayType()) {
+  // The simple case:
+  //
+  // struct s {
+  // int arr[42];
+  // char c;
+  // /* others */
+  // };
+  //
+  // __builtin_dynamic_object_size(>arr[idx], 0);
+  //
+  // We can translate the __builtin_dynamic_object_call into:
+  //
+  // sizeof(struct s) - offsetof(arr) - (idx * sizeof(int))
+  //
+  bool IsSigned = Idx->getType()->isSignedIntegerType();
+  Value *IdxInst = EmitAnyExprToTemp(Idx).getScalarVal();
+  IdxInst = Builder.CreateIntCast(IdxInst, ResType, IsSigned);
+
+  const ConstantArrayType *CAT = cast(ME->getType());
+  CharUnits ElemSize = 

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] 
<{{.*}}> col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'

mizvekov wrote:

While normally I would agree, in this case there are no existing AST tests for 
these other kinds of declarations, so I felt appropriate to broaden this test a 
little bit to cover those.

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


[llvm] [clang] [AArch64] Support optional constant offset for constraint "S" (PR #80255)

2024-01-31 Thread Fangrui Song via cfe-commits

MaskRay wrote:

I have some notes about these constraints 
https://maskray.me/blog/2024-01-30-raw-symbol-names-in-inline-assembly

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


[clang] [Clang][test] Limit library search when linking shared lib (PR #80253)

2024-01-31 Thread Wei Wang via cfe-commits

apolloww wrote:

Our internal builds run in chroot and the test fails with the following error

```
/bin/ld: cannot find crti.o: No such file or directory
/bin/ld: cannot find crtbeginS.o: No such file or directory
/bin/ld: cannot find -lgcc
/bin/ld: cannot find -lgcc_s
/bin/ld: cannot find -lc
/bin/ld: cannot find -lgcc
/bin/ld: cannot find -lgcc_s
/bin/ld: cannot find crtendS.o: No such file or directory
/bin/ld: cannot find crtn.o: No such file or directory
```

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits


@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)

mizvekov wrote:

The MR is split in two commits, the first one adds the test, if you click on 
the last commit, you can see the change in the expectation.

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


[clang] [llvm] [AArch64] Support optional constant offset for constraint "S" (PR #80255)

2024-01-31 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-backend-aarch64

Author: Fangrui Song (MaskRay)


Changes

Modify the initial implementation (https://reviews.llvm.org/D46745) to
support a constant offset so that the following code will compile:
```
int a[2][2];
void foo() { asm("// %0" :: "S"(a[1][1])); }
```

We use the generic code path for "s". In GCC's aarch64 port, "S" is
supported for PIC while "s" isn't, making "s" less useful. We implement
"S" but not "s".

Similar to #80201 for RISC-V.


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


5 Files Affected:

- (modified) clang/test/Sema/inline-asm-validate-aarch64.c (+14-3) 
- (modified) llvm/docs/LangRef.rst (+2) 
- (modified) llvm/lib/Target/AArch64/AArch64ISelLowering.cpp (+6-13) 
- (modified) llvm/test/CodeGen/AArch64/inlineasm-S-constraint.ll (+4) 
- (modified) llvm/test/CodeGen/RISCV/inline-asm-S-constraint.ll (+1) 


``diff
diff --git a/clang/test/Sema/inline-asm-validate-aarch64.c 
b/clang/test/Sema/inline-asm-validate-aarch64.c
index 014767d5a3923..1e753d40d8ca0 100644
--- a/clang/test/Sema/inline-asm-validate-aarch64.c
+++ b/clang/test/Sema/inline-asm-validate-aarch64.c
@@ -1,14 +1,24 @@
+// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -verify -DVERIFY %s
 // RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 typedef unsigned char uint8_t;
 
+#ifdef VERIFY
+void test_s(int i) {
+  asm("" :: "s"(i)); // expected-error{{invalid input constraint 's' in asm}}
+
+  /// Codegen error
+  asm("" :: "S"(i));
+  asm("" :: "S"(test_s(i))); // expected-error{{invalid type 'void' in asm 
input for constraint 'S'}}
+}
+#else
 uint8_t constraint_r(uint8_t *addr) {
   uint8_t byte;
 
   __asm__ volatile("ldrb %0, [%1]" : "=r" (byte) : "r" (addr) : "memory");
 // CHECK: warning: value size does not match register size specified by the 
constraint and modifier
 // CHECK: note: use constraint modifier "w"
-// CHECK: fix-it:{{.*}}:{8:26-8:28}:"%w0"
+// CHECK: fix-it:{{.*}}:{[[#@LINE-3]]:26-[[#@LINE-3]]:28}:"%w0"
 
   return byte;
 }
@@ -19,7 +29,7 @@ uint8_t constraint_r_symbolic(uint8_t *addr) {
   __asm__ volatile("ldrb %[s0], [%[s1]]" : [s0] "=r" (byte) : [s1] "r" (addr) 
: "memory");
 // CHECK: warning: value size does not match register size specified by the 
constraint and modifier
 // CHECK: note: use constraint modifier "w"
-// CHECK: fix-it:{{.*}}:{19:26-19:31}:"%w[s0]"
+// CHECK: fix-it:{{.*}}:{[[#@LINE-3]]:26-[[#@LINE-3]]:31}:"%w[s0]"
 
   return byte;
 }
@@ -40,11 +50,11 @@ uint8_t constraint_r_symbolic_macro(uint8_t *addr) {
 // CHECK: warning: value size does not match register size specified by the 
constraint and modifier
 // CHECK: asm ("%w0 %w1 %2" : "+r" (one) : "r" (wide_two));
 // CHECK: note: use constraint modifier "w"
-// CHECK: fix-it:{{.*}}:{47:17-47:19}:"%w2"
 
 void read_write_modifier0(int one, int two) {
   long wide_two = two;
   asm ("%w0 %w1 %2" : "+r" (one) : "r" (wide_two));
+// CHECK: fix-it:{{.*}}:{[[#@LINE-1]]:17-[[#@LINE-1]]:19}:"%w2"
 }
 
 // CHECK-NOT: warning: 
@@ -52,3 +62,4 @@ void read_write_modifier1(int one, int two) {
   long wide_two = two;
   asm ("%w0 %1" : "+r" (one), "+r" (wide_two));
 }
+#endif
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 7a7ddc59ba985..b13f8c7811d16 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -5107,6 +5107,8 @@ AArch64:
   offsets). (However, LLVM currently does this for the ``m`` constraint as
   well.)
 - ``r``: A 32 or 64-bit integer register (W* or X*).
+- ``S``: A symbol or label reference with a constant offset. The generic ``s``
+  is not supported.
 - ``Uci``: Like r, but restricted to registers 8 to 11 inclusive.
 - ``Ucj``: Like r, but restricted to registers 12 to 15 inclusive.
 - ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register.
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index bb19aef978b94..62f160c1c33fc 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10618,7 +10618,7 @@ AArch64TargetLowering::getConstraintType(StringRef 
Constraint) const {
 case 'Z':
   return C_Immediate;
 case 'z':
-case 'S': // A symbolic address
+case 'S': // A symbol or label reference with a constant offset
   return C_Other;
 }
   } else if (parsePredicateConstraint(Constraint))
@@ -10801,19 +10801,12 @@ void 
AArch64TargetLowering::LowerAsmOperandForConstraint(
   Result = DAG.getRegister(AArch64::WZR, MVT::i32);
 break;
   }
-  case 'S': {
-// An absolute symbolic address or label reference.
-if (const GlobalAddressSDNode *GA = dyn_cast(Op)) {
-  Result = DAG.getTargetGlobalAddress(GA->getGlobal(), SDLoc(Op),
-  GA->getValueType(0));
-} else if (const BlockAddressSDNode *BA =
-   

[clang] [llvm] [AArch64] Support optional constant offset for constraint "S" (PR #80255)

2024-01-31 Thread Fangrui Song via cfe-commits

https://github.com/MaskRay created 
https://github.com/llvm/llvm-project/pull/80255

Modify the initial implementation (https://reviews.llvm.org/D46745) to
support a constant offset so that the following code will compile:
```
int a[2][2];
void foo() { asm("// %0" :: "S"([1][1])); }
```

We use the generic code path for "s". In GCC's aarch64 port, "S" is
supported for PIC while "s" isn't, making "s" less useful. We implement
"S" but not "s".

Similar to #80201 for RISC-V.


>From 8ce25b59ac48e3b0a69c28e8af3abe6d7cbf0c42 Mon Sep 17 00:00:00 2001
From: Fangrui Song 
Date: Wed, 31 Jan 2024 23:25:23 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 clang/test/Sema/inline-asm-validate-aarch64.c | 17 ++---
 llvm/docs/LangRef.rst |  2 ++
 .../Target/AArch64/AArch64ISelLowering.cpp| 19 ++-
 .../CodeGen/AArch64/inlineasm-S-constraint.ll |  4 
 .../CodeGen/RISCV/inline-asm-S-constraint.ll  |  1 +
 5 files changed, 27 insertions(+), 16 deletions(-)

diff --git a/clang/test/Sema/inline-asm-validate-aarch64.c 
b/clang/test/Sema/inline-asm-validate-aarch64.c
index 014767d5a3923..1e753d40d8ca0 100644
--- a/clang/test/Sema/inline-asm-validate-aarch64.c
+++ b/clang/test/Sema/inline-asm-validate-aarch64.c
@@ -1,14 +1,24 @@
+// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -verify -DVERIFY %s
 // RUN: %clang_cc1 -triple arm64-apple-darwin -fsyntax-only 
-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
 
 typedef unsigned char uint8_t;
 
+#ifdef VERIFY
+void test_s(int i) {
+  asm("" :: "s"(i)); // expected-error{{invalid input constraint 's' in asm}}
+
+  /// Codegen error
+  asm("" :: "S"(i));
+  asm("" :: "S"(test_s(i))); // expected-error{{invalid type 'void' in asm 
input for constraint 'S'}}
+}
+#else
 uint8_t constraint_r(uint8_t *addr) {
   uint8_t byte;
 
   __asm__ volatile("ldrb %0, [%1]" : "=r" (byte) : "r" (addr) : "memory");
 // CHECK: warning: value size does not match register size specified by the 
constraint and modifier
 // CHECK: note: use constraint modifier "w"
-// CHECK: fix-it:{{.*}}:{8:26-8:28}:"%w0"
+// CHECK: fix-it:{{.*}}:{[[#@LINE-3]]:26-[[#@LINE-3]]:28}:"%w0"
 
   return byte;
 }
@@ -19,7 +29,7 @@ uint8_t constraint_r_symbolic(uint8_t *addr) {
   __asm__ volatile("ldrb %[s0], [%[s1]]" : [s0] "=r" (byte) : [s1] "r" (addr) 
: "memory");
 // CHECK: warning: value size does not match register size specified by the 
constraint and modifier
 // CHECK: note: use constraint modifier "w"
-// CHECK: fix-it:{{.*}}:{19:26-19:31}:"%w[s0]"
+// CHECK: fix-it:{{.*}}:{[[#@LINE-3]]:26-[[#@LINE-3]]:31}:"%w[s0]"
 
   return byte;
 }
@@ -40,11 +50,11 @@ uint8_t constraint_r_symbolic_macro(uint8_t *addr) {
 // CHECK: warning: value size does not match register size specified by the 
constraint and modifier
 // CHECK: asm ("%w0 %w1 %2" : "+r" (one) : "r" (wide_two));
 // CHECK: note: use constraint modifier "w"
-// CHECK: fix-it:{{.*}}:{47:17-47:19}:"%w2"
 
 void read_write_modifier0(int one, int two) {
   long wide_two = two;
   asm ("%w0 %w1 %2" : "+r" (one) : "r" (wide_two));
+// CHECK: fix-it:{{.*}}:{[[#@LINE-1]]:17-[[#@LINE-1]]:19}:"%w2"
 }
 
 // CHECK-NOT: warning: 
@@ -52,3 +62,4 @@ void read_write_modifier1(int one, int two) {
   long wide_two = two;
   asm ("%w0 %1" : "+r" (one), "+r" (wide_two));
 }
+#endif
diff --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index 7a7ddc59ba985..b13f8c7811d16 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -5107,6 +5107,8 @@ AArch64:
   offsets). (However, LLVM currently does this for the ``m`` constraint as
   well.)
 - ``r``: A 32 or 64-bit integer register (W* or X*).
+- ``S``: A symbol or label reference with a constant offset. The generic ``s``
+  is not supported.
 - ``Uci``: Like r, but restricted to registers 8 to 11 inclusive.
 - ``Ucj``: Like r, but restricted to registers 12 to 15 inclusive.
 - ``w``: A 32, 64, or 128-bit floating-point, SIMD or SVE vector register.
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp 
b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index bb19aef978b94..62f160c1c33fc 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -10618,7 +10618,7 @@ AArch64TargetLowering::getConstraintType(StringRef 
Constraint) const {
 case 'Z':
   return C_Immediate;
 case 'z':
-case 'S': // A symbolic address
+case 'S': // A symbol or label reference with a constant offset
   return C_Other;
 }
   } else if (parsePredicateConstraint(Constraint))
@@ -10801,19 +10801,12 @@ void 
AArch64TargetLowering::LowerAsmOperandForConstraint(
   Result = DAG.getRegister(AArch64::WZR, MVT::i32);
 break;
   }
-  case 'S': {
-// An absolute symbolic address or label reference.
-if (const 

[clang] [Clang][test] Limit library search when linking shared lib (PR #80253)

2024-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Wei Wang (apolloww)


Changes

Don't search for unnecessary libs when linking the shared lib. This allows the 
test to run in chroot environment.

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


1 Files Affected:

- (modified) clang/test/Interpreter/cxx20-modules.cppm (+1-1) 


``diff
diff --git a/clang/test/Interpreter/cxx20-modules.cppm 
b/clang/test/Interpreter/cxx20-modules.cppm
index 239968d8c7445..4e56e2fc1528a 100644
--- a/clang/test/Interpreter/cxx20-modules.cppm
+++ b/clang/test/Interpreter/cxx20-modules.cppm
@@ -8,7 +8,7 @@
 // RUN: %clang -std=c++20 %t/mod.cppm --precompile \
 // RUN: -o %t/mod.pcm --target=x86_64-linux-gnu
 // RUN: %clang -fPIC %t/mod.pcm -c -o %t/mod.o --target=x86_64-linux-gnu
-// RUN: %clang -fPIC -shared %t/mod.o -o %t/libmod.so --target=x86_64-linux-gnu
+// RUN: %clang -nostdlib -fPIC -shared %t/mod.o -o %t/libmod.so 
--target=x86_64-linux-gnu
 //
 // RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
 // RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \

``




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


[clang-tools-extra] [clang] [llvm] [mlir] [mlir][docs] Clarified Dialect creation tutorial + fixed typos (PR #77820)

2024-01-31 Thread Mehdi Amini via cfe-commits

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


[llvm] [clang-tools-extra] [mlir] [clang] [mlir][docs] Clarified Dialect creation tutorial + fixed typos (PR #77820)

2024-01-31 Thread Mehdi Amini via cfe-commits


@@ -106,6 +106,12 @@ the LINK_COMPONENTS descriptor.  This allows cmake 
infrastructure to
 generate new library targets with correct linkage, in particular, when
 BUILD_SHARED_LIBS=on or LLVM_LINK_LLVM_DYLIB=on are specified.
 
+Registration of the dialect can be performed globally by editing the
+file include/mlir/InitAllDialects.h.  In this example, we can add

joker-eph wrote:

This is framed as if it is a possibility: I believe this isn't optional, all 
dialects should be there.

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


[clang] [Clang][test] Limit library search when linking shared lib (PR #80253)

2024-01-31 Thread Wei Wang via cfe-commits

https://github.com/apolloww created 
https://github.com/llvm/llvm-project/pull/80253

Don't search for unnecessary libs when linking the shared lib. This allows the 
test to run in chroot environment.

>From adc0635a10fc4d77842863c4f9b731733c9b8062 Mon Sep 17 00:00:00 2001
From: Wei Wang 
Date: Wed, 31 Jan 2024 23:21:45 -0800
Subject: [PATCH] [Clang][test] Limit library search when linking shared lib

---
 clang/test/Interpreter/cxx20-modules.cppm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Interpreter/cxx20-modules.cppm 
b/clang/test/Interpreter/cxx20-modules.cppm
index 239968d8c7445..4e56e2fc1528a 100644
--- a/clang/test/Interpreter/cxx20-modules.cppm
+++ b/clang/test/Interpreter/cxx20-modules.cppm
@@ -8,7 +8,7 @@
 // RUN: %clang -std=c++20 %t/mod.cppm --precompile \
 // RUN: -o %t/mod.pcm --target=x86_64-linux-gnu
 // RUN: %clang -fPIC %t/mod.pcm -c -o %t/mod.o --target=x86_64-linux-gnu
-// RUN: %clang -fPIC -shared %t/mod.o -o %t/libmod.so --target=x86_64-linux-gnu
+// RUN: %clang -nostdlib -fPIC -shared %t/mod.o -o %t/libmod.so 
--target=x86_64-linux-gnu
 //
 // RUN: cat %t/import.cpp | env LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH \
 // RUN: clang-repl -Xcc=-std=c++20 -Xcc=-fmodule-file=M=%t/mod.pcm \

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/80245

>From 23a0d731cfe8593c338fc8ad7920f7aa9270afaa Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:07:16 -0300
Subject: [PATCH 1/2] [NFC] [clang] add test for merging of UsingShadowDecl

---
 clang/test/Modules/cxx20-decls.cppm | 44 +
 1 file changed, 44 insertions(+)
 create mode 100644 clang/test/Modules/cxx20-decls.cppm

diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
new file mode 100644
index 0..052c8e73be247
--- /dev/null
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// FIXME: UsingShadowDecl should have been merged
+// CHECK-NOT:  `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <{{.*}}> 
col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in 
A. hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_ADDR]] <{{.*}}> col:{{.*}} referenced 
foo 'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x[[USING_ADDR]] <{{.*}}> col:{{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT:  `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} 
implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'

>From 895c615a354d540c4e4404fa728bfad2a962c7bf Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:26:10 -0300
Subject: [PATCH 2/2] [clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit
fd8634a09de71.

This problem could manifest itself as ODR check false positives
when importing modules.

Fixes: #80252
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/test/Modules/cxx20-decls.cppm | 6 ++
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7b11ab3a6b2e..a48672951de32 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#80252 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
index 052c8e73be247..ee9f117278884 100644
--- a/clang/test/Modules/cxx20-decls.cppm
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -31,9 +31,7 @@ using xxx = baz::foo;
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
 // CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
 // CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
-// FIXME: UsingShadowDecl should have been merged
-// CHECK-NOT:  `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <{{.*}}> 
col:{{.*}} imported in A. hidden 

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

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


[compiler-rt] [clang] [flang] [llvm] [clang-tools-extra] [mlir] [mlir][tosa] Add dialect version. (PR #79514)

2024-01-31 Thread Mehdi Amini via cfe-commits

joker-eph wrote:

> To be able to flag incompatible bytecode files rather than have it fail later 
> in mysterious ways. E.g., allows for a more strict failure.

That would require some sort of principles and policy around the changes that 
affect the serialization of this and the maintenance of this version number, I 
haven't seen a discussion about this: did I miss it?

Also, TOSA isn't a hermetic dialect: it includes other IR entities from other 
dialects, and changing these would impact this story as well.

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


[llvm] [clang] [CloneFunction][DebugInfo] Avoid cloning DILocalVariables of inlined functions (PR #75385)

2024-01-31 Thread Jeremy Morse via cfe-commits

jmorse wrote:

...ah, actually is it malformed because there's a DICompositeType in the 
retainedNodes list for a DISubprogram? I remember that the verifier considered 
that illegal before your patch landed, but not after.

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


[clang] 48f8b74 - [clang][Interp] Support GenericSelectionExprs

2024-01-31 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-01T08:15:11+01:00
New Revision: 48f8b74c35991fd3842e135481960449b1e25363

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

LOG: [clang][Interp] Support GenericSelectionExprs

Just delegate to the resulting expression.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/test/Sema/c2x-auto.c
clang/test/Sema/c2x-bool.c

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index c0721b0daf9a3..a93635a9f6888 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1940,6 +1940,12 @@ bool ByteCodeExprGen::VisitSizeOfPackExpr(const 
SizeOfPackExpr *E) {
   return this->emitConst(E->getPackLength(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitGenericSelectionExpr(
+const GenericSelectionExpr *E) {
+  return this->delegate(E->getResultExpr());
+}
+
 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 ec88f31ae516a..1710b4446432b 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -108,6 +108,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitOffsetOfExpr(const OffsetOfExpr *E);
   bool VisitCXXScalarValueInitExpr(const CXXScalarValueInitExpr *E);
   bool VisitSizeOfPackExpr(const SizeOfPackExpr *E);
+  bool VisitGenericSelectionExpr(const GenericSelectionExpr *E);
 
 protected:
   bool visitExpr(const Expr *E) override;

diff  --git a/clang/test/Sema/c2x-auto.c b/clang/test/Sema/c2x-auto.c
index 7cbd1db31315a..97754b2fb836b 100644
--- a/clang/test/Sema/c2x-auto.c
+++ b/clang/test/Sema/c2x-auto.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c2x -verify -pedantic -Wno-comments %s
+// RUN: %clang_cc1 -std=c2x -verify -pedantic -Wno-comments %s 
-fexperimental-new-constant-interpreter
 
 void test_basic_types(void) {
   auto undefined; // expected-error {{declaration of variable 'undefined' 
with deduced type 'auto' requires an initializer}}

diff  --git a/clang/test/Sema/c2x-bool.c b/clang/test/Sema/c2x-bool.c
index 0bc147228fda4..98cb8507359d0 100644
--- a/clang/test/Sema/c2x-bool.c
+++ b/clang/test/Sema/c2x-bool.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -std=c2x -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify %s 
-fexperimental-new-constant-interpreter
 
 _Static_assert(_Generic(true, _Bool : 1, default: 0));
 _Static_assert(_Generic(false, _Bool : 1, default: 0));



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


[clang] fa98e28 - [clang][Interp][NFC] Remove unused RecordScope

2024-01-31 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-01T08:03:49+01:00
New Revision: fa98e2861dadaf436b0eb4b38e96a2ccf7c41072

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

LOG: [clang][Interp][NFC] Remove unused RecordScope

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.h

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 971fd09bdfac5..ec88f31ae516a 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -30,7 +30,6 @@ namespace interp {
 
 template  class LocalScope;
 template  class DestructorScope;
-template  class RecordScope;
 template  class VariableScope;
 template  class DeclScope;
 template  class OptionScope;
@@ -219,7 +218,6 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   friend class VariableScope;
   friend class LocalScope;
   friend class DestructorScope;
-  friend class RecordScope;
   friend class DeclScope;
   friend class OptionScope;
   friend class ArrayIndexScope;



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


[clang] a9e8309 - [clang][Interp] Protect Inc/Dec ops against dummy pointers

2024-01-31 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-01T08:03:49+01:00
New Revision: a9e830910bc07733b7a9d4b935cd12a9041623b3

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

LOG: [clang][Interp] Protect Inc/Dec ops against dummy pointers

We create them more often in C, so it's more likely to happen there.

Added: 


Modified: 
clang/lib/AST/Interp/Interp.h
clang/test/AST/Interp/c.c
clang/test/Sema/check-increment.c

Removed: 




diff  --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index b71469b2cba1f..7c7e53564c4b4 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -519,6 +519,9 @@ enum class IncDecOp {
 
 template 
 bool IncDecHelper(InterpState , CodePtr OpPC, const Pointer ) {
+  if (Ptr.isDummy())
+return false;
+
   const T  = Ptr.deref();
   T Result;
 
@@ -1521,6 +1524,9 @@ bool SubOffset(InterpState , CodePtr OpPC) {
 template 
 static inline bool IncDecPtrHelper(InterpState , CodePtr OpPC,
const Pointer ) {
+  if (Ptr.isDummy())
+return false;
+
   using OneT = Integral<8, false>;
 
   const Pointer  = Ptr.deref();

diff  --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index 2bc3d906bcc5e..385944d643a30 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -85,3 +85,13 @@ const intptr_t L = (intptr_t)(&(yy->y)); // expected-error 
{{not a compile-time
 const ptr
diff _t m =  + 137 - 
 _Static_assert(m == 137, ""); // pedantic-ref-warning {{GNU extension}} \
   // pedantic-expected-warning {{GNU extension}}
+
+/// from test/Sema/switch.c, used to cause an assertion failure.
+void f (int z) {
+  while (z) {
+default: z--; // expected-error {{'default' statement not in switch}} \
+  // pedantic-expected-error {{'default' statement not in 
switch}} \
+  // ref-error {{'default' statement not in switch}} \
+  // pedantic-ref-error {{'default' statement not in switch}}
+  }
+}

diff  --git a/clang/test/Sema/check-increment.c 
b/clang/test/Sema/check-increment.c
index 011ebd85a79cd..66321a1c45e29 100644
--- a/clang/test/Sema/check-increment.c
+++ b/clang/test/Sema/check-increment.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s 
-fexperimental-new-constant-interpreter
 // expected-no-diagnostics
 
 int printf(const char *, ...);



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


[polly] [clang-tools-extra] [llvm] [clang] [polly] Add polly-debug flag to print debug info from all parts of polly (PR #78549)

2024-01-31 Thread Karthika Devi C via cfe-commits

https://github.com/kartcq updated 
https://github.com/llvm/llvm-project/pull/78549

>From 1aeb149cb15e83c8880a99aa94db224737331aa6 Mon Sep 17 00:00:00 2001
From: kartcq 
Date: Fri, 15 Dec 2023 02:58:40 -0800
Subject: [PATCH 1/3] [polly] Add polly-debug flag to print debug info from all
 parts of polly

This flag enable the user to print debug Info from all the passes and
helpers inside polly at once. This will help a novice user as well to
work in polly without explicitly having to know which parts of polly has
actually kicked in and pass them via -debug-only.

Change-Id: I6ddb03d5e7debac16413fb364afb8811139c8073
---
 polly/include/polly/Support/PollyDebug.inc| 33 +++
 polly/lib/Analysis/DependenceInfo.cpp |  1 +
 polly/lib/Analysis/PolyhedralInfo.cpp |  1 +
 polly/lib/Analysis/PruneUnprofitable.cpp  |  1 +
 polly/lib/Analysis/ScopBuilder.cpp|  1 +
 polly/lib/Analysis/ScopDetection.cpp  |  1 +
 polly/lib/Analysis/ScopInfo.cpp   |  1 +
 polly/lib/CMakeLists.txt  |  1 +
 polly/lib/CodeGen/CodeGeneration.cpp  |  1 +
 polly/lib/CodeGen/IslAst.cpp  |  1 +
 polly/lib/Support/PollyDebug.cpp  | 27 +++
 polly/lib/Support/SCEVValidator.cpp   |  1 +
 polly/lib/Transform/DeLICM.cpp|  1 +
 polly/lib/Transform/FlattenAlgo.cpp   |  1 +
 polly/lib/Transform/FlattenSchedule.cpp   |  1 +
 polly/lib/Transform/ForwardOpTree.cpp |  1 +
 polly/lib/Transform/ManualOptimizer.cpp   |  1 +
 polly/lib/Transform/MatmulOptimizer.cpp   |  1 +
 polly/lib/Transform/ScheduleOptimizer.cpp |  1 +
 polly/lib/Transform/ScheduleTreeTransform.cpp |  1 +
 polly/lib/Transform/ScopInliner.cpp   |  1 +
 polly/lib/Transform/Simplify.cpp  |  1 +
 polly/lib/Transform/ZoneAlgo.cpp  |  1 +
 23 files changed, 81 insertions(+)
 create mode 100644 polly/include/polly/Support/PollyDebug.inc
 create mode 100644 polly/lib/Support/PollyDebug.cpp

diff --git a/polly/include/polly/Support/PollyDebug.inc 
b/polly/include/polly/Support/PollyDebug.inc
new file mode 100644
index 0..84f13991251d9
--- /dev/null
+++ b/polly/include/polly/Support/PollyDebug.inc
@@ -0,0 +1,33 @@
+//===-PollyDebug.inc -Provide support for debugging Polly passes-*- 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
+//
+//===--===//
+//
+// Functions to aid printing Debug Info of all polly passes.
+//
+//===--===//
+
+
+#ifndef POLLY_DEBUG_H
+#define POLLY_DEBUG_H
+
+#include "llvm/Support/Debug.h"
+namespace polly {
+using namespace llvm;
+bool getPollyDebugFlag();
+#ifndef NDEBUG
+#undef LLVM_DEBUG
+#define LLVM_DEBUG(X)  
\
+  do { 
\
+if (polly::getPollyDebugFlag()) {  
\
+  X;   
\
+} else {   
\
+  DEBUG_WITH_TYPE(DEBUG_TYPE, X);  
\
+}  
\
+  } while (0)
+#endif
+} // namespace polly
+#endif
diff --git a/polly/lib/Analysis/DependenceInfo.cpp 
b/polly/lib/Analysis/DependenceInfo.cpp
index 69257c603877e..5df2e1329687c 100644
--- a/polly/lib/Analysis/DependenceInfo.cpp
+++ b/polly/lib/Analysis/DependenceInfo.cpp
@@ -39,6 +39,7 @@
 using namespace polly;
 using namespace llvm;
 
+#include "polly/Support/PollyDebug.inc"
 #define DEBUG_TYPE "polly-dependence"
 
 static cl::opt OptComputeOut(
diff --git a/polly/lib/Analysis/PolyhedralInfo.cpp 
b/polly/lib/Analysis/PolyhedralInfo.cpp
index 5c77be0a9a1fa..5c7e61f0531d9 100644
--- a/polly/lib/Analysis/PolyhedralInfo.cpp
+++ b/polly/lib/Analysis/PolyhedralInfo.cpp
@@ -32,6 +32,7 @@
 using namespace llvm;
 using namespace polly;
 
+#include "polly/Support/PollyDebug.inc"
 #define DEBUG_TYPE "polyhedral-info"
 
 static cl::opt CheckParallel("polly-check-parallel",
diff --git a/polly/lib/Analysis/PruneUnprofitable.cpp 
b/polly/lib/Analysis/PruneUnprofitable.cpp
index db4a3d73dc33a..c73de1c143ac6 100644
--- a/polly/lib/Analysis/PruneUnprofitable.cpp
+++ b/polly/lib/Analysis/PruneUnprofitable.cpp
@@ -22,6 +22,7 @@
 using namespace llvm;
 using namespace polly;
 
+#include "polly/Support/PollyDebug.inc"
 #define DEBUG_TYPE "polly-prune-unprofitable"
 
 namespace {
diff --git a/polly/lib/Analysis/ScopBuilder.cpp 
b/polly/lib/Analysis/ScopBuilder.cpp
index c62cb2a85c835..b94b36bb22aa2 

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits


@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)

ChuanqiXu9 wrote:

For example, I need to what's the behavior before the patch, then I can have a 
better feeling about how should we test it.

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits


@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)

ChuanqiXu9 wrote:

(I don't know why the comment got duplicated)

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits


@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)

ChuanqiXu9 wrote:

> We usually do small fixups like this during review / post approval, this will 
> not be merged like this, don't worry.
People on the LLVM community tend to be quite flexible on these things.

Yeah, but we still need to a real issue in the end of the day, right?

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


[polly] [clang-tools-extra] [llvm] [clang] [polly] Add polly-debug flag to print debug info from all parts of polly (PR #78549)

2024-01-31 Thread Karthika Devi C via cfe-commits

https://github.com/kartcq updated 
https://github.com/llvm/llvm-project/pull/78549

>From 1aeb149cb15e83c8880a99aa94db224737331aa6 Mon Sep 17 00:00:00 2001
From: kartcq 
Date: Fri, 15 Dec 2023 02:58:40 -0800
Subject: [PATCH 1/3] [polly] Add polly-debug flag to print debug info from all
 parts of polly

This flag enable the user to print debug Info from all the passes and
helpers inside polly at once. This will help a novice user as well to
work in polly without explicitly having to know which parts of polly has
actually kicked in and pass them via -debug-only.

Change-Id: I6ddb03d5e7debac16413fb364afb8811139c8073
---
 polly/include/polly/Support/PollyDebug.inc| 33 +++
 polly/lib/Analysis/DependenceInfo.cpp |  1 +
 polly/lib/Analysis/PolyhedralInfo.cpp |  1 +
 polly/lib/Analysis/PruneUnprofitable.cpp  |  1 +
 polly/lib/Analysis/ScopBuilder.cpp|  1 +
 polly/lib/Analysis/ScopDetection.cpp  |  1 +
 polly/lib/Analysis/ScopInfo.cpp   |  1 +
 polly/lib/CMakeLists.txt  |  1 +
 polly/lib/CodeGen/CodeGeneration.cpp  |  1 +
 polly/lib/CodeGen/IslAst.cpp  |  1 +
 polly/lib/Support/PollyDebug.cpp  | 27 +++
 polly/lib/Support/SCEVValidator.cpp   |  1 +
 polly/lib/Transform/DeLICM.cpp|  1 +
 polly/lib/Transform/FlattenAlgo.cpp   |  1 +
 polly/lib/Transform/FlattenSchedule.cpp   |  1 +
 polly/lib/Transform/ForwardOpTree.cpp |  1 +
 polly/lib/Transform/ManualOptimizer.cpp   |  1 +
 polly/lib/Transform/MatmulOptimizer.cpp   |  1 +
 polly/lib/Transform/ScheduleOptimizer.cpp |  1 +
 polly/lib/Transform/ScheduleTreeTransform.cpp |  1 +
 polly/lib/Transform/ScopInliner.cpp   |  1 +
 polly/lib/Transform/Simplify.cpp  |  1 +
 polly/lib/Transform/ZoneAlgo.cpp  |  1 +
 23 files changed, 81 insertions(+)
 create mode 100644 polly/include/polly/Support/PollyDebug.inc
 create mode 100644 polly/lib/Support/PollyDebug.cpp

diff --git a/polly/include/polly/Support/PollyDebug.inc 
b/polly/include/polly/Support/PollyDebug.inc
new file mode 100644
index 0..84f13991251d9
--- /dev/null
+++ b/polly/include/polly/Support/PollyDebug.inc
@@ -0,0 +1,33 @@
+//===-PollyDebug.inc -Provide support for debugging Polly passes-*- 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
+//
+//===--===//
+//
+// Functions to aid printing Debug Info of all polly passes.
+//
+//===--===//
+
+
+#ifndef POLLY_DEBUG_H
+#define POLLY_DEBUG_H
+
+#include "llvm/Support/Debug.h"
+namespace polly {
+using namespace llvm;
+bool getPollyDebugFlag();
+#ifndef NDEBUG
+#undef LLVM_DEBUG
+#define LLVM_DEBUG(X)  
\
+  do { 
\
+if (polly::getPollyDebugFlag()) {  
\
+  X;   
\
+} else {   
\
+  DEBUG_WITH_TYPE(DEBUG_TYPE, X);  
\
+}  
\
+  } while (0)
+#endif
+} // namespace polly
+#endif
diff --git a/polly/lib/Analysis/DependenceInfo.cpp 
b/polly/lib/Analysis/DependenceInfo.cpp
index 69257c603877e..5df2e1329687c 100644
--- a/polly/lib/Analysis/DependenceInfo.cpp
+++ b/polly/lib/Analysis/DependenceInfo.cpp
@@ -39,6 +39,7 @@
 using namespace polly;
 using namespace llvm;
 
+#include "polly/Support/PollyDebug.inc"
 #define DEBUG_TYPE "polly-dependence"
 
 static cl::opt OptComputeOut(
diff --git a/polly/lib/Analysis/PolyhedralInfo.cpp 
b/polly/lib/Analysis/PolyhedralInfo.cpp
index 5c77be0a9a1fa..5c7e61f0531d9 100644
--- a/polly/lib/Analysis/PolyhedralInfo.cpp
+++ b/polly/lib/Analysis/PolyhedralInfo.cpp
@@ -32,6 +32,7 @@
 using namespace llvm;
 using namespace polly;
 
+#include "polly/Support/PollyDebug.inc"
 #define DEBUG_TYPE "polyhedral-info"
 
 static cl::opt CheckParallel("polly-check-parallel",
diff --git a/polly/lib/Analysis/PruneUnprofitable.cpp 
b/polly/lib/Analysis/PruneUnprofitable.cpp
index db4a3d73dc33a..c73de1c143ac6 100644
--- a/polly/lib/Analysis/PruneUnprofitable.cpp
+++ b/polly/lib/Analysis/PruneUnprofitable.cpp
@@ -22,6 +22,7 @@
 using namespace llvm;
 using namespace polly;
 
+#include "polly/Support/PollyDebug.inc"
 #define DEBUG_TYPE "polly-prune-unprofitable"
 
 namespace {
diff --git a/polly/lib/Analysis/ScopBuilder.cpp 
b/polly/lib/Analysis/ScopBuilder.cpp
index c62cb2a85c835..b94b36bb22aa2 

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits


@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)

ChuanqiXu9 wrote:

Let's file a real issue.

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits

https://github.com/ChuanqiXu9 commented:

IIRC, in https://github.com/llvm/llvm-project/pull/79959, you're saying the 
patch have the potential to fix 
https://github.com/llvm/llvm-project/issues/78850? Is it true?

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] 
<{{.*}}> col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'

ChuanqiXu9 wrote:

Let's avoid checking dumpped text as much as possible. This feels bad if we 
need to update them.

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits


@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)

mizvekov wrote:

We usually do small fixups like this during review / post approval, this will 
not be merged like this, don't worry.
People on the LLVM community tend to be quite flexible on these things.

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits


@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)

ChuanqiXu9 wrote:

Oh, if it is the case, we should mark this as draft. Otherwise, if I don't look 
into every line and I see your funcitonal change is pretty simple, it'll be bad 
if I merge it directly...

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Hmm I have been doing user branches for a while, this saves me time in case I 
want to split the patch off in a separate MR.
It's already the case that this is split into test adding + fixing commits.

In any case, the user branch will be deleted as soon as this is merged.

Can we go ahead, and clarify the rules for the next time, since this is such a 
small patch and windows CI takes 3 hours?

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

Before looking into it, I remember the user branch is only allowed for stacked 
review. If this patch is not the case, let's try to create a new PR.

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


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Chuanqi Xu via cfe-commits

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


[clang] [clang] Accept lambdas in C++03 as an extensions (PR #73376)

2024-01-31 Thread Shafik Yaghmour via cfe-commits

shafik wrote:

This LGTM but we need @llvm-beanz to review

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


[clang] [clang][Interp] Handle imaginary literals (PR #79130)

2024-01-31 Thread Timm Baeder via cfe-commits

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


[clang] 6ff431b - [clang][Interp] Handle imaginary literals (#79130)

2024-01-31 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-02-01T07:13:10+01:00
New Revision: 6ff431b01e29e99c7dbfcda96bdefdff91dcdf7f

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

LOG: [clang][Interp] Handle imaginary literals (#79130)

Initialize the first element to 0 and the second element to the value of
the subexpression.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/ByteCodeExprGen.h
clang/lib/AST/Interp/Context.cpp
clang/test/AST/Interp/complex.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d307739c301ef..c0721b0daf9a3 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -393,6 +393,31 @@ bool ByteCodeExprGen::VisitFloatingLiteral(const 
FloatingLiteral *E) {
   return this->emitConstFloat(E->getValue(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitImaginaryLiteral(
+const ImaginaryLiteral *E) {
+  assert(E->getType()->isAnyComplexType());
+  if (DiscardResult)
+return true;
+
+  if (!Initializing) {
+std::optional LocalIndex = allocateLocal(E, 
/*IsExtended=*/false);
+if (!LocalIndex)
+  return false;
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+  }
+
+  const Expr *SubExpr = E->getSubExpr();
+  PrimType SubExprT = classifyPrim(SubExpr->getType());
+
+  if (!this->visitZeroInitializer(SubExprT, SubExpr->getType(), SubExpr))
+return false;
+  if (!this->emitInitElem(SubExprT, 0, SubExpr))
+return false;
+  return this->visitArrayElemInit(1, SubExpr);
+}
+
 template 
 bool ByteCodeExprGen::VisitParenExpr(const ParenExpr *E) {
   return this->delegate(E->getSubExpr());
@@ -2883,6 +2908,7 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 return false;
   return this->visitZeroInitializer(*T, SubExpr->getType(), SubExpr);
 }
+
 if (!this->visit(SubExpr))
   return false;
 if (!this->emitConstUint8(1, E))

diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 315169d487cd4..971fd09bdfac5 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -61,6 +61,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitCastExpr(const CastExpr *E);
   bool VisitIntegerLiteral(const IntegerLiteral *E);
   bool VisitFloatingLiteral(const FloatingLiteral *E);
+  bool VisitImaginaryLiteral(const ImaginaryLiteral *E);
   bool VisitParenExpr(const ParenExpr *E);
   bool VisitBinaryOperator(const BinaryOperator *E);
   bool VisitLogicalBinOp(const BinaryOperator *E);

diff  --git a/clang/lib/AST/Interp/Context.cpp 
b/clang/lib/AST/Interp/Context.cpp
index ba80a015965b3..5f5a6622f10f3 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -111,11 +111,13 @@ bool Context::evaluateAsInitializer(State , const 
VarDecl *VD,
 #endif
 
   // Ensure global variables are fully initialized.
-  if (shouldBeGloballyIndexed(VD) && !Res.isInvalid() &&
-  (VD->getType()->isRecordType() || VD->getType()->isArrayType())) {
+  if (shouldBeGloballyIndexed(VD) &&
+  (VD->getType()->isRecordType() || VD->getType()->isArrayType() ||
+   VD->getType()->isAnyComplexType())) {
 assert(Res.isLValue());
 
-if (!Res.checkFullyInitialized(C.getState()))
+if (!VD->getType()->isAnyComplexType() &&
+!Res.checkFullyInitialized(C.getState()))
   return false;
 
 // lvalue-to-rvalue conversion.

diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index bb230c2ebe64d..fdd1d738de828 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -61,6 +61,14 @@ static_assert(__real(D3) == 1.0, "");
 static_assert(__imag(D3) == 3.0, "");
 
 
+constexpr _Complex int a = 2i;
+static_assert(__real(a) == 0, "");
+static_assert(__imag(a) == 2, "");
+
+constexpr _Complex double b = 4.0i;
+static_assert(__real(b) == 0, "");
+static_assert(__imag(b) == 4, "");
+
 constexpr int ignored() {
   I2;
   (int)I2;



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


[clang] [clang] Fix crash when declaring invalid lambda member (PR #74110)

2024-01-31 Thread Shafik Yaghmour via cfe-commits


@@ -1526,10 +1526,9 @@ bool CXXRecordDecl::isGenericLambda() const {
 
 #ifndef NDEBUG
 static bool allLookupResultsAreTheSame(const DeclContext::lookup_result ) {
-  for (auto *D : R)
-if (!declaresSameEntity(D, R.front()))
-  return false;
-  return true;
+  return llvm::all_of(R, [&](NamedDecl *D) {
+return D->isInvalidDecl() || declaresSameEntity(D, R.front());
+  });

shafik wrote:

>From what I can tell nowhere is checking what they pass to 
>`declaresSameEntity(...)` but I did not dig too deeply to see if we know they 
>are valid earlier in some way.

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


[clang] a8f317a - [clang][Interp] complex binary operators aren't always initializing

2024-01-31 Thread Timm Bäder via cfe-commits

Author: Timm Bäder
Date: 2024-02-01T07:09:43+01:00
New Revision: a8f317aeaccaa052c9c4cfa4660c40554fbbf223

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

LOG: [clang][Interp] complex binary operators aren't always initializing

The added test case would trigger the removed assertion.

Added: 


Modified: 
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/test/AST/Interp/complex.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d2d47e60b2c4d..d307739c301ef 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -651,7 +651,14 @@ bool ByteCodeExprGen::VisitLogicalBinOp(const 
BinaryOperator *E) {
 
 template 
 bool ByteCodeExprGen::VisitComplexBinOp(const BinaryOperator *E) {
-  assert(Initializing);
+  // Prepare storage for result.
+  if (!Initializing) {
+std::optional LocalIndex = allocateLocal(E, 
/*IsExtended=*/false);
+if (!LocalIndex)
+  return false;
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+  }
 
   const Expr *LHS = E->getLHS();
   const Expr *RHS = E->getRHS();

diff  --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index 8c57df7d9a3ed..bb230c2ebe64d 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -93,6 +93,16 @@ static_assert(__imag(I3) == 0, "");
 /// FIXME: This should work in the new interpreter as well.
 // constexpr _Complex _BitInt(8) A = 0;// = {4};
 
+
+void func(void) {
+  __complex__ int arr;
+  _Complex int result;
+  int ii = 0;
+  int bb = 0;
+  /// The following line will call into the constant interpreter.
+  result = arr * ii;
+}
+
 namespace CastToBool {
   constexpr _Complex int F = {0, 1};
   static_assert(F, "");



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


[clang] [clang-format] Allow decltype in requires clause (PR #78847)

2024-01-31 Thread Emilia Kond via cfe-commits

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


[clang] 9b68c09 - [clang-format] Allow decltype in requires clause (#78847)

2024-01-31 Thread via cfe-commits

Author: Emilia Kond
Date: 2024-02-01T08:00:45+02:00
New Revision: 9b68c095d6b52d6ec0390c653528f65c42e5f570

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

LOG: [clang-format] Allow decltype in requires clause (#78847)

If clang-format is not sure whether a `requires` keyword starts a
requires clause or a requires expression, it looks ahead to see if any
token disqualifies it from being a requires clause. Among these tokens
was `decltype`, since it fell through the switch.

This patch allows decltype to exist in a require clause.

I'm not 100% sure this change won't have repercussions, but that just
means we need more test coverage!

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

Added: 


Modified: 
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp

Removed: 




diff  --git a/clang/lib/Format/UnwrappedLineParser.cpp 
b/clang/lib/Format/UnwrappedLineParser.cpp
index b904e0e56d9eb..0a7f8808f29af 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -3446,11 +3446,6 @@ bool clang::format::UnwrappedLineParser::parseRequires() 
{
 return false;
   }
   break;
-case tok::r_paren:
-case tok::pipepipe:
-  FormatTok = Tokens->setPosition(StoredPosition);
-  parseRequiresClause(RequiresToken);
-  return true;
 case tok::eof:
   // Break out of the loop.
   Lookahead = 50;
@@ -3458,6 +3453,7 @@ bool clang::format::UnwrappedLineParser::parseRequires() {
 case tok::coloncolon:
   LastWasColonColon = true;
   break;
+case tok::kw_decltype:
 case tok::identifier:
   if (FoundType && !LastWasColonColon && OpenAngles == 0) {
 FormatTok = Tokens->setPosition(StoredPosition);

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index f3e443e8829bd..6e5832858c1ec 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -1076,6 +1076,28 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsRequiresClausesAndConcepts) {
 "concept C = (!Foo) && Bar;");
   ASSERT_EQ(Tokens.size(), 19u) << Tokens;
   EXPECT_TOKEN(Tokens[15], tok::ampamp, TT_BinaryOperator);
+
+  Tokens = annotate("void f() & requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 18u) << Tokens;
+  EXPECT_TOKEN(Tokens[4], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("auto f() -> int& requires(C) {}");
+  ASSERT_EQ(Tokens.size(), 20u) << Tokens;
+  EXPECT_TOKEN(Tokens[6], tok::amp, TT_PointerOrReference);
+  EXPECT_TOKEN(Tokens[7], tok::kw_requires, TT_RequiresClause);
+
+  Tokens = annotate("bool x = t && requires(decltype(t) x) { x.foo(); };");
+  ASSERT_EQ(Tokens.size(), 23u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresExpression);
+
+  Tokens = annotate("bool x = t && requires(Foo x) { x.foo(); 
};");
+  ASSERT_EQ(Tokens.size(), 26u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresExpression);
+
+  Tokens = annotate("bool x = t && requires(Foo x) { x.foo(); };");
+  ASSERT_EQ(Tokens.size(), 25u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::kw_requires, TT_RequiresExpression);
 }
 
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) {



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


[clang] Users/mizvekov/bug/clang merge usingshadowdecl (PR #80245)

2024-01-31 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

[clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit 
fd8634a09de71.

This problem could manifest itself as ODR check false positives when importing 
modules.

Fixes: #ISSUE_TO_BE_CREATED

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+3) 
- (modified) clang/lib/AST/ASTContext.cpp (+1-1) 
- (added) clang/test/Modules/cxx20-decls.cppm (+42) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7b11ab3a6b2e..aa14b8e931101 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 71c9c0003d18c..feeb350bf3e0c 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6732,7 +6732,7 @@ bool ASTContext::isSameEntity(const NamedDecl *X, const 
NamedDecl *Y) const {
   // Using shadow declarations with the same target match.
   if (const auto *USX = dyn_cast(X)) {
 const auto *USY = cast(Y);
-return USX->getTargetDecl() == USY->getTargetDecl();
+return declaresSameEntity(USX->getTargetDecl(), USY->getTargetDecl());
   }
 
   // Using declarations with the same qualifier match. (We already know that
diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
new file mode 100644
index 0..ee9f117278884
--- /dev/null
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] 
<{{.*}}> col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_ADDR]] <{{.*}}> col:{{.*}} referenced 
foo 'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x[[USING_ADDR]] <{{.*}}> col:{{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT:  `-UsingShadowDecl 0x[[SHADOW_ADDR]] <{{.*}}> col:{{.*}} 
implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'

``




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


[clang] Users/mizvekov/bug/clang merge usingshadowdecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/80245

[clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit 
fd8634a09de71.

This problem could manifest itself as ODR check false positives when importing 
modules.

Fixes: #ISSUE_TO_BE_CREATED

>From 23a0d731cfe8593c338fc8ad7920f7aa9270afaa Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:07:16 -0300
Subject: [PATCH 1/2] [NFC] [clang] add test for merging of UsingShadowDecl

---
 clang/test/Modules/cxx20-decls.cppm | 44 +
 1 file changed, 44 insertions(+)
 create mode 100644 clang/test/Modules/cxx20-decls.cppm

diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
new file mode 100644
index 0..052c8e73be247
--- /dev/null
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// FIXME: UsingShadowDecl should have been merged
+// CHECK-NOT:  `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <{{.*}}> 
col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in 
A. hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_ADDR]] <{{.*}}> col:{{.*}} referenced 
foo 'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x[[USING_ADDR]] <{{.*}}> col:{{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT:  `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} 
implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'

>From b44f1b2ee3d709c627c1679fe3a252ea564bdd3d Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:26:10 -0300
Subject: [PATCH 2/2] [clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit
fd8634a09de71.

This problem could manifest itself as ODR check false positives
when importing modules.

Fixes: #ISSUE_TO_BE_CREATED
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/AST/ASTContext.cpp| 2 +-
 clang/test/Modules/cxx20-decls.cppm | 6 ++
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7b11ab3a6b2e..aa14b8e931101 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 71c9c0003d18c..feeb350bf3e0c 100644
--- 

[clang] [clang-format] Allow decltype in requires clause (PR #78847)

2024-01-31 Thread Owen Pan via cfe-commits

owenca wrote:

Should we merge this patch?

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


[clang] [C++20] [Modules] Introduce reduced BMI (PR #75894)

2024-01-31 Thread Chuanqi Xu via cfe-commits

ChuanqiXu9 wrote:

@mizvekov would you like to take a look at this? This is related (in some 
level) to what you say https://github.com/llvm/llvm-project/pull/79959. In 
short, in the direction, in the one-phase compilation, the pcm won't be 
compiled into object files. (But it still will in the two-phase compilation).

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


[clang-tools-extra] [clang-tidy] Add AllowStringArrays option to modernize-avoid-c-arrays (PR #71701)

2024-01-31 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] b777bb7 - [clang-tidy] Add AllowStringArrays option to modernize-avoid-c-arrays (#71701)

2024-01-31 Thread via cfe-commits

Author: Piotr Zegar
Date: 2024-02-01T06:47:53+01:00
New Revision: b777bb78b302055eba876a0258ea4b2625ffe71a

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

LOG: [clang-tidy] Add AllowStringArrays option to modernize-avoid-c-arrays 
(#71701)

Add AllowStringArrays option, enabling the exclusion of array types with
deduced sizes constructed from string literals. This includes only var
declarations of array of characters constructed directly from c-strings.

Closes #59475

Added: 

clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays-ignores-strings.cpp

Modified: 
clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/modernize/avoid-c-arrays.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/avoid-c-arrays.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
index d1b15479ffe7a..89790ea70cf22 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
@@ -12,6 +12,8 @@
 
 using namespace clang::ast_matchers;
 
+namespace clang::tidy::modernize {
+
 namespace {
 
 AST_MATCHER(clang::TypeLoc, hasValidBeginLoc) {
@@ -38,16 +40,32 @@ AST_MATCHER(clang::ParmVarDecl, isArgvOfMain) {
 
 } // namespace
 
-namespace clang::tidy::modernize {
+AvoidCArraysCheck::AvoidCArraysCheck(StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  AllowStringArrays(Options.get("AllowStringArrays", false)) {}
+
+void AvoidCArraysCheck::storeOptions(ClangTidyOptions::OptionMap ) {
+  Options.store(Opts, "AllowStringArrays", AllowStringArrays);
+}
 
 void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
+  ast_matchers::internal::Matcher IgnoreStringArrayIfNeededMatcher =
+  anything();
+  if (AllowStringArrays)
+IgnoreStringArrayIfNeededMatcher =
+unless(typeLoc(loc(hasCanonicalType(incompleteArrayType(
+   hasElementType(isAnyCharacter(),
+   hasParent(varDecl(hasInitializer(stringLiteral()),
+ unless(parmVarDecl());
+
   Finder->addMatcher(
   typeLoc(hasValidBeginLoc(), hasType(arrayType()),
   unless(anyOf(hasParent(parmVarDecl(isArgvOfMain())),
hasParent(varDecl(isExternC())),
hasParent(fieldDecl(
hasParent(recordDecl(isExternCContext(),
-   hasAncestor(functionDecl(isExternC())
+   hasAncestor(functionDecl(isExternC(),
+  std::move(IgnoreStringArrayIfNeededMatcher))
   .bind("typeloc"),
   this);
 }

diff  --git a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h 
b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
index 7099f99c86949..719e88e4b3166 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.h
@@ -19,13 +19,19 @@ namespace clang::tidy::modernize {
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/avoid-c-arrays.html
 class AvoidCArraysCheck : public ClangTidyCheck {
 public:
-  AvoidCArraysCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  AvoidCArraysCheck(StringRef Name, ClangTidyContext *Context);
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  void storeOptions(ClangTidyOptions::OptionMap ) override;
   bool isLanguageVersionSupported(const LangOptions ) const override {
 return LangOpts.CPlusPlus11;
   }
-  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
-  void check(const ast_matchers::MatchFinder::MatchResult ) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+
+private:
+  const bool AllowStringArrays;
 };
 
 } // namespace clang::tidy::modernize

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index ad99fe9d08f9c..2a7749d71405c 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -106,6 +106,11 @@ New check aliases
 Changes in existing checks
 ^^
 
+- Improved :doc:`modernize-avoid-c-arrays
+  ` check by introducing the new
+  `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
+  length initialized 

[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-31 Thread Chuanqi Xu via cfe-commits

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


[clang] 8eea582 - [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (#79959)

2024-01-31 Thread via cfe-commits

Author: Chuanqi Xu
Date: 2024-02-01T13:44:32+08:00
New Revision: 8eea582dcb900afb45866a09296624b6fef9dd20

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

LOG: [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (#79959)

Close https://github.com/llvm/llvm-project/issues/79240

Cite the comment from @mizvekov in
//github.com/llvm/llvm-project/issues/79240:

> There are two kinds of bugs / issues relevant here:
>
> Clang bugs that this change hides
> Here we can add a Frontend flag that disables the GMF ODR check, just
> so
> we can keep tracking, testing and fixing these issues.
> The Driver would just always pass that flag.
> We could add that flag in this current issue.
> Bugs in user code:
> I don't think it's worth adding a corresponding Driver flag for
> controlling the above Frontend flag, since we intend it's behavior to
> become default as we fix the problems, and users interested in testing
> the more strict behavior can just use the Frontend flag directly.

This patch follows the suggestion:
- Introduce the CC1 flag `-fskip-odr-check-in-gmf` which is by default
off, so that the every existing test will still be tested with checking
ODR violations.
- Passing `-fskip-odr-check-in-gmf` in the driver to keep the behavior
we intended.
- Edit the document to tell the users who are still interested in more
strict checks can use `-Xclang -fno-skip-odr-check-in-gmf` to get the
existing behavior.

Added: 
clang/test/Driver/modules-skip-odr-check-in-gmf.cpp
clang/test/Modules/skip-odr-check-in-gmf.cppm

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/StandardCPlusPlusModules.rst
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/include/clang/Serialization/ASTReader.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/Modules/concept.cppm
clang/test/Modules/polluted-operator.cppm
clang/test/Modules/pr76638.cppm

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7b11ab3a6b2e..ec9e3ef07057f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -82,7 +82,8 @@ C++20 Feature Support
 
 - Clang won't perform ODR checks for decls in the global module fragment any
   more to ease the implementation and improve the user's using experience.
-  This follows the MSVC's behavior.
+  This follows the MSVC's behavior. Users interested in testing the more strict
+  behavior can use the flag '-Xclang -fno-skip-odr-check-in-gmf'.
   (`#79240 `_).
 
 C++23 Feature Support

diff  --git a/clang/docs/StandardCPlusPlusModules.rst 
b/clang/docs/StandardCPlusPlusModules.rst
index 4e853990a7338..c322805d8db5b 100644
--- a/clang/docs/StandardCPlusPlusModules.rst
+++ b/clang/docs/StandardCPlusPlusModules.rst
@@ -457,6 +457,29 @@ Note that **currently** the compiler doesn't consider 
inconsistent macro definit
 Currently Clang would accept the above example. But it may produce surprising 
results if the
 debugging code depends on consistent use of ``NDEBUG`` also in other 
translation units.
 
+Definitions consistency
+^^^
+
+The C++ language defines that same declarations in 
diff erent translation units should have
+the same definition, as known as ODR (One Definition Rule). Prior to modules, 
the translation
+units don't dependent on each other and the compiler itself can't perform a 
strong
+ODR violation check. With the introduction of modules, now the compiler have
+the chance to perform ODR violations with language semantics across 
translation units.
+
+However, in the practice, we found the existing ODR checking mechanism is not 
stable
+enough. Many people suffers from the false positive ODR violation diagnostics, 
AKA,
+the compiler are complaining two identical declarations have 
diff erent definitions
+incorrectly. Also the true positive ODR violations are rarely reported.
+Also we learned that MSVC don't perform ODR check for declarations in the 
global module
+fragment.
+
+So in order to get better user experience, save the time checking ODR and keep 
consistent
+behavior with MSVC, we disabled the ODR check for the declarations in the 
global module
+fragment by default. Users who want more strict check can still use the
+``-Xclang -fno-skip-odr-check-in-gmf`` flag to get the ODR check enabled. It 
is also
+encouraged to report issues if users find false positive ODR violations or 
false negative ODR
+violations with the flag enabled.
+
 ABI Impacts
 ---
 

diff  --git 

[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-31 Thread Chuanqi Xu via cfe-commits


@@ -457,6 +457,28 @@ Note that **currently** the compiler doesn't consider 
inconsistent macro definit
 Currently Clang would accept the above example. But it may produce surprising 
results if the
 debugging code depends on consistent use of ``NDEBUG`` also in other 
translation units.
 
+Definitions consistency
+^^^
+
+The C++ language defines that same declarations in different translation units 
should have
+the same definition, as known as ODR (One Definition Rule). Prior to modules, 
the translation
+units don't dependent on each other and the compiler itself don't and can't 
perform a strong
+ODR violation check. Sometimes it is the linker does some jobs related to ODR, 
where the
+higher level semantics are missing. With the introduction of modules, now the 
compiler have
+the chance to perform ODR violations with language semantics across 
translation units.
+
+However, in the practice we found the existing ODR checking mechanism may be 
too aggressive.
+In the many issue reports about ODR violation diagnostics, most of them are 
false positive
+ODR violations and the true positive ODR violations are rarely reported. Also 
MSVC don't
+perform ODR check for declarations in the global module fragment.

ChuanqiXu9 wrote:

> Sure, we can move that part of the discussion over there.

I'll add you as CC if they agree to do so. I remember there is policy to forbid 
that. But I am not sure.

> Not on the llvm issue tracker yet, I am working on getting issue + patch up 
> soon.

Got it. Not bad. But generally an issue can let us know what's going on and 
maybe we meet such issues too.

> How are we tracking these issues, is there a special tag for them? We could 
> take a better look, attack this systematically.

No. All of them are falling into the `clang:modules` label. I did a 
just-in-time search and I found:
- https://github.com/llvm/llvm-project/issues/61317
- https://github.com/llvm/llvm-project/issues/60486
- https://github.com/llvm/llvm-project/issues/63595
- https://github.com/llvm/llvm-project/issues/63544
- https://github.com/llvm/llvm-project/issues/62943 

(Maybe there are more)

Note that not all of them fails due to bugs in ODR checker. Some of them fails 
due to bugs in other places and the ODR checker just fires it. Although the 
result is still false positive ODR violation diagnostics.

And there are another camp about, `import-before-include` 
(https://github.com/llvm/llvm-project/issues/61465). From the perspective of 
implementors, they are not the same thing. But from the perspective of users, 
it has a same feelings.

> Right, but reducing these issues takes a lot of effort. On the other hand, 
> it's possible they all reduce to a few simple cases.
> This is my perception so far, working on converting a medium size code base.

Same here.

> So I will go ahead and approve this, even though I feel this might have been 
> too hasty, as long as we are running the clang test suite as before, then we 
> can make progress in fixing all the problems and circle back to always 
> enabling the checker.

Thanks. It is always easy to enable the check by default any time.

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


[clang] [polly] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread Owen Pan via cfe-commits


@@ -922,8 +922,39 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int LongName::
+///   AnotherLongName();
 /// \endcode
 RTBS_None,
+/// Break after return type automatically.
+/// This mode doesn't have the same inherent restriction on breaking after
+/// short return types as ``RTBS_None`` and is solely based on
+/// ``PenaltyReturnTypeOnItsOwnLine``.

owenca wrote:

For example:
```suggestion
/// Break after return type based on ``PenaltyReturnTypeOnItsOwnLine``.
```

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


[clang] [polly] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread Owen Pan via cfe-commits

https://github.com/owenca commented:

There is no need to update the release notes for new option values.

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


[polly] [clang] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread Owen Pan via cfe-commits


@@ -922,8 +922,39 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int LongName::
+///   AnotherLongName();
 /// \endcode
 RTBS_None,
+/// Break after return type automatically.
+/// This mode doesn't have the same inherent restriction on breaking after
+/// short return types as ``RTBS_None`` and is solely based on
+/// ``PenaltyReturnTypeOnItsOwnLine``.
+/// \code
+///   class A {
+/// int f() { return 0; };
+///   };
+///   int f();
+///   int f() { return 1; }
+///   int
+///   LongName::AnotherLongName();
+/// \endcode
+RTBS_AllowShortType,
+/// Break after return type automatically.
+/// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
+/// This mode will never break after short return types, unlike
+/// ``RTBS_None`` which will only sometimes choose not to break after short
+/// return types.

owenca wrote:

For example:
```suggestion
/// Same as ``Automatic`` above, except that there is no break after short
/// return types.
```

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


[clang] [polly] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread Owen Pan via cfe-commits


@@ -922,8 +922,39 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int LongName::
+///   AnotherLongName();
 /// \endcode

owenca wrote:

Change the comments (lines 917-927) to something like the following:
```
/// This is **deprecated**. See ``Automatic`` below.
```

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


[clang] [polly] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread Owen Pan via cfe-commits

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


[polly] [clang] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread Owen Pan via cfe-commits


@@ -922,8 +922,39 @@ struct FormatStyle {
 ///   };
 ///   int f();
 ///   int f() { return 1; }
+///   int LongName::
+///   AnotherLongName();
 /// \endcode
 RTBS_None,
+/// Break after return type automatically.
+/// This mode doesn't have the same inherent restriction on breaking after
+/// short return types as ``RTBS_None`` and is solely based on
+/// ``PenaltyReturnTypeOnItsOwnLine``.
+/// \code
+///   class A {
+/// int f() { return 0; };
+///   };
+///   int f();
+///   int f() { return 1; }
+///   int
+///   LongName::AnotherLongName();
+/// \endcode
+RTBS_AllowShortType,

owenca wrote:

```suggestion
RTBS_Automatic,
```

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


[clang] [clang][Diagnostic] Don't warn about binary literals when using C23. (PR #80244)

2024-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Collin Funk (collinfunk)


Changes

The C23 standard brought binary literals which were previously GNU extensions. 
Silence warnings from -Wgnu-binary-literal when using C23. This warning is 
implied by -Wpedantic.

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


1 Files Affected:

- (modified) clang/lib/Lex/LiteralSupport.cpp (+11-5) 


``diff
diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 0a78638f68051..add4ca76678de 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -1358,11 +1358,17 @@ void 
NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
 
   // Handle simple binary numbers 0b01010
   if ((c1 == 'b' || c1 == 'B') && (s[1] == '0' || s[1] == '1')) {
-// 0b101010 is a C++1y / GCC extension.
-Diags.Report(TokLoc, LangOpts.CPlusPlus14
- ? diag::warn_cxx11_compat_binary_literal
- : LangOpts.CPlusPlus ? diag::ext_binary_literal_cxx14
-  : diag::ext_binary_literal);
+// 0b101010 is a GCC extension subsequently standardized by C23 and C++14.
+if (LangOpts.CPlusPlus) {
+  if (LangOpts.CPlusPlus14)
+Diags.Report(TokLoc, diag::warn_cxx11_compat_binary_literal);
+  else
+Diags.Report(TokLoc, diag::ext_binary_literal_cxx14);
+} else {
+  // TODO: Need new DiagGroup for C23.
+  if (!LangOpts.C23)
+Diags.Report(TokLoc, diag::ext_binary_literal);
+}
 ++s;
 assert(s < ThisTokEnd && "didn't maximally munch?");
 radix = 2;

``




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


[clang] [clang][Diagnostic] Don't warn about binary literals when using C23. (PR #80244)

2024-01-31 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from 
other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang][Diagnostic] Don't warn about binary literals when using C23. (PR #80244)

2024-01-31 Thread Collin Funk via cfe-commits

https://github.com/collinfunk created 
https://github.com/llvm/llvm-project/pull/80244

The C23 standard brought binary literals which were previously GNU extensions. 
Silence warnings from -Wgnu-binary-literal when using C23. This warning is 
implied by -Wpedantic.

>From ef443507e06adcbc604ad8e03d96060e29525394 Mon Sep 17 00:00:00 2001
From: Collin Funk 
Date: Wed, 31 Jan 2024 21:30:39 -0800
Subject: [PATCH] [clang][Diagnostic] Don't warn about binary literals when
 using C23.

The C23 standard brought binary literals which were previously GNU
extensions. Silence warnings from -Wgnu-binary-literal when using C23.
This warning is implied by -Wpedantic.

Signed-off-by: Collin Funk 
---
 clang/lib/Lex/LiteralSupport.cpp | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Lex/LiteralSupport.cpp b/clang/lib/Lex/LiteralSupport.cpp
index 0a78638f68051..add4ca76678de 100644
--- a/clang/lib/Lex/LiteralSupport.cpp
+++ b/clang/lib/Lex/LiteralSupport.cpp
@@ -1358,11 +1358,17 @@ void 
NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) {
 
   // Handle simple binary numbers 0b01010
   if ((c1 == 'b' || c1 == 'B') && (s[1] == '0' || s[1] == '1')) {
-// 0b101010 is a C++1y / GCC extension.
-Diags.Report(TokLoc, LangOpts.CPlusPlus14
- ? diag::warn_cxx11_compat_binary_literal
- : LangOpts.CPlusPlus ? diag::ext_binary_literal_cxx14
-  : diag::ext_binary_literal);
+// 0b101010 is a GCC extension subsequently standardized by C23 and C++14.
+if (LangOpts.CPlusPlus) {
+  if (LangOpts.CPlusPlus14)
+Diags.Report(TokLoc, diag::warn_cxx11_compat_binary_literal);
+  else
+Diags.Report(TokLoc, diag::ext_binary_literal_cxx14);
+} else {
+  // TODO: Need new DiagGroup for C23.
+  if (!LangOpts.C23)
+Diags.Report(TokLoc, diag::ext_binary_literal);
+}
 ++s;
 assert(s < ThisTokEnd && "didn't maximally munch?");
 radix = 2;

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


[libcxx] [llvm] [lldb] [clang-tools-extra] [libc] [clang] [flang] [compiler-rt] [lld] Make clang report invalid target versions for all environment types. (PR #78655)

2024-01-31 Thread via cfe-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/78655

>From f440f44e7e270d4636ad39f4e4223c904e496d3a Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Fri, 19 Jan 2024 00:47:05 +
Subject: [PATCH 1/5] Make clang report invalid target versions for all
 environment.

Followup for https://github.com/llvm/llvm-project/pull/75373

1. Make this feature not just available for android, but everyone.
2. Correct some target triples/
3. Add opencl to the environment type list.
---
 clang/lib/Driver/Driver.cpp  | 19 ++-
 clang/test/CodeGen/fp128_complex.c   |  2 +-
 clang/test/Driver/mips-features.c|  4 ++--
 clang/test/Frontend/fixed_point_bit_widths.c |  4 ++--
 llvm/include/llvm/TargetParser/Triple.h  |  2 +-
 llvm/lib/TargetParser/Triple.cpp | 14 ++
 6 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 1889ea28079df..2d6986d145483 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1430,15 +1430,16 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) {
   const ToolChain  = getToolChain(
   *UArgs, computeTargetTriple(*this, TargetTriple, *UArgs));
 
-  if (TC.getTriple().isAndroid()) {
-llvm::Triple Triple = TC.getTriple();
-StringRef TripleVersionName = Triple.getEnvironmentVersionString();
-
-if (Triple.getEnvironmentVersion().empty() && TripleVersionName != "") {
-  Diags.Report(diag::err_drv_triple_version_invalid)
-  << TripleVersionName << TC.getTripleString();
-  ContainsError = true;
-}
+  // Check if the environment version is valid.
+  llvm::Triple Triple = TC.getTriple();
+  StringRef TripleVersionName = Triple.getEnvironmentVersionString();
+  StringRef TripleObjectFormat = 
Triple.getObjectFormatTypeName(Triple.getObjectFormat());
+
+  if (Triple.getEnvironmentVersion().empty() && TripleVersionName != ""
+&& TripleVersionName != TripleObjectFormat) {
+Diags.Report(diag::err_drv_triple_version_invalid)
+<< TripleVersionName << TC.getTripleString();
+ContainsError = true;
   }
 
   // Report warning when arm64EC option is overridden by specified target
diff --git a/clang/test/CodeGen/fp128_complex.c 
b/clang/test/CodeGen/fp128_complex.c
index 48659d2241684..0e87cbe8ce812 100644
--- a/clang/test/CodeGen/fp128_complex.c
+++ b/clang/test/CodeGen/fp128_complex.c
@@ -1,4 +1,4 @@
-// RUN: %clang -target aarch64-linux-gnuabi %s -S -emit-llvm -o - | FileCheck 
%s
+// RUN: %clang -target aarch64-linux-gnueabi %s -S -emit-llvm -o - | FileCheck 
%s
 
 _Complex long double a, b, c, d;
 void test_fp128_compound_assign(void) {
diff --git a/clang/test/Driver/mips-features.c 
b/clang/test/Driver/mips-features.c
index fad6009ffb89b..18edcd05ea85c 100644
--- a/clang/test/Driver/mips-features.c
+++ b/clang/test/Driver/mips-features.c
@@ -400,12 +400,12 @@
 // LONG-CALLS-DEF-NOT: "long-calls"
 //
 // -mbranch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mbranch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=BRANCH-LIKELY %s
 // BRANCH-LIKELY: argument unused during compilation: '-mbranch-likely'
 //
 // -mno-branch-likely
-// RUN: %clang -target -mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
+// RUN: %clang -target mips-mti-linux-gnu -### -c %s -mno-branch-likely 2>&1 \
 // RUN:   | FileCheck --check-prefix=NO-BRANCH-LIKELY %s
 // NO-BRANCH-LIKELY: argument unused during compilation: '-mno-branch-likely'
 
diff --git a/clang/test/Frontend/fixed_point_bit_widths.c 
b/clang/test/Frontend/fixed_point_bit_widths.c
index ac8db49ed516a..e56f787e824f2 100644
--- a/clang/test/Frontend/fixed_point_bit_widths.c
+++ b/clang/test/Frontend/fixed_point_bit_widths.c
@@ -1,7 +1,7 @@
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - %s | FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-ubuntu-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 // RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=ppc64 %s | 
FileCheck %s
-// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - 
--target=x86_64-scei-ps4-windows10pro-fast %s | FileCheck %s
+// RUN: %clang -x c -ffixed-point -S -emit-llvm -o - --target=x86_64-scei-ps4 
%s | FileCheck %s
 
 /* Primary signed _Accum */
 
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 95014a546f724..525ea6df3643c 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -273,7 +273,7 @@ class Triple {
 Callable,
 Mesh,
 Amplification,
-
+OpenCL,
 OpenHOS,
 
 LastEnvironmentType = OpenHOS
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 

[clang] [clang][Interp] Handle imaginary literals (PR #79130)

2024-01-31 Thread Timm Baeder via cfe-commits

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

>From db25ed3917079ea9bf3c05a899b40415e3c5df8b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Tue, 23 Jan 2024 09:14:02 +0100
Subject: [PATCH] [clang][Interp] Handle imaginary literals

Initialize the first element to 0 and the second element
to the value of the subexpression.
---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 26 
 clang/lib/AST/Interp/ByteCodeExprGen.h   |  1 +
 clang/lib/AST/Interp/Context.cpp |  8 +---
 clang/test/AST/Interp/complex.cpp|  8 
 4 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index d2d47e60b2c4d..aa21b4e7da6e8 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -393,6 +393,31 @@ bool ByteCodeExprGen::VisitFloatingLiteral(const 
FloatingLiteral *E) {
   return this->emitConstFloat(E->getValue(), E);
 }
 
+template 
+bool ByteCodeExprGen::VisitImaginaryLiteral(
+const ImaginaryLiteral *E) {
+  assert(E->getType()->isAnyComplexType());
+  if (DiscardResult)
+return true;
+
+  if (!Initializing) {
+std::optional LocalIndex = allocateLocal(E, 
/*IsExtended=*/false);
+if (!LocalIndex)
+  return false;
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+  }
+
+  const Expr *SubExpr = E->getSubExpr();
+  PrimType SubExprT = classifyPrim(SubExpr->getType());
+
+  if (!this->visitZeroInitializer(SubExprT, SubExpr->getType(), SubExpr))
+return false;
+  if (!this->emitInitElem(SubExprT, 0, SubExpr))
+return false;
+  return this->visitArrayElemInit(1, SubExpr);
+}
+
 template 
 bool ByteCodeExprGen::VisitParenExpr(const ParenExpr *E) {
   return this->delegate(E->getSubExpr());
@@ -2876,6 +2901,7 @@ bool ByteCodeExprGen::VisitUnaryOperator(const 
UnaryOperator *E) {
 return false;
   return this->visitZeroInitializer(*T, SubExpr->getType(), SubExpr);
 }
+
 if (!this->visit(SubExpr))
   return false;
 if (!this->emitConstUint8(1, E))
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.h 
b/clang/lib/AST/Interp/ByteCodeExprGen.h
index 315169d487cd4..971fd09bdfac5 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.h
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -61,6 +61,7 @@ class ByteCodeExprGen : public 
ConstStmtVisitor, bool>,
   bool VisitCastExpr(const CastExpr *E);
   bool VisitIntegerLiteral(const IntegerLiteral *E);
   bool VisitFloatingLiteral(const FloatingLiteral *E);
+  bool VisitImaginaryLiteral(const ImaginaryLiteral *E);
   bool VisitParenExpr(const ParenExpr *E);
   bool VisitBinaryOperator(const BinaryOperator *E);
   bool VisitLogicalBinOp(const BinaryOperator *E);
diff --git a/clang/lib/AST/Interp/Context.cpp b/clang/lib/AST/Interp/Context.cpp
index ba80a015965b3..5f5a6622f10f3 100644
--- a/clang/lib/AST/Interp/Context.cpp
+++ b/clang/lib/AST/Interp/Context.cpp
@@ -111,11 +111,13 @@ bool Context::evaluateAsInitializer(State , const 
VarDecl *VD,
 #endif
 
   // Ensure global variables are fully initialized.
-  if (shouldBeGloballyIndexed(VD) && !Res.isInvalid() &&
-  (VD->getType()->isRecordType() || VD->getType()->isArrayType())) {
+  if (shouldBeGloballyIndexed(VD) &&
+  (VD->getType()->isRecordType() || VD->getType()->isArrayType() ||
+   VD->getType()->isAnyComplexType())) {
 assert(Res.isLValue());
 
-if (!Res.checkFullyInitialized(C.getState()))
+if (!VD->getType()->isAnyComplexType() &&
+!Res.checkFullyInitialized(C.getState()))
   return false;
 
 // lvalue-to-rvalue conversion.
diff --git a/clang/test/AST/Interp/complex.cpp 
b/clang/test/AST/Interp/complex.cpp
index 8c57df7d9a3ed..275d066bbb3aa 100644
--- a/clang/test/AST/Interp/complex.cpp
+++ b/clang/test/AST/Interp/complex.cpp
@@ -61,6 +61,14 @@ static_assert(__real(D3) == 1.0, "");
 static_assert(__imag(D3) == 3.0, "");
 
 
+constexpr _Complex int a = 2i;
+static_assert(__real(a) == 0, "");
+static_assert(__imag(a) == 2, "");
+
+constexpr _Complex double b = 4.0i;
+static_assert(__real(b) == 0, "");
+static_assert(__imag(b) == 4, "");
+
 constexpr int ignored() {
   I2;
   (int)I2;

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


[polly] [clang] [clang-format] Add AllowShortType and ExceptShortType options for AlwaysBreakAfterReturnType. (PR #78011)

2024-01-31 Thread Owen Pan via cfe-commits

owenca wrote:

> Now that we've got both options, should we keep them? Currently, `None` 
> sometimes forbids breaking after short return types and sometimes allows it 
> and just bases things off the penalty configuration. I feel like there will 
> be some people who use `None` who would want the behaviour to be consistent 
> one way and the other group wanting it consistent the opposite. With both, 
> they can decide for themselves. Especially since the implementation for both 
> is pretty simple and self-contained.

+1. In addition, we should deprecate `None` (in documentation only) and rename 
`AllowShortType` to `Automatic`, followed by `ExceptShortType` which means 
"`Automatic` except for short return types". Then IMO `ExceptShortType` is 
unambiguous. If you still think `NeverShortType` is clearer, I would change it 
to `NotShortType`.

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


[clang] [clang-format] Update FormatToken::isSimpleTypeSpecifier() (PR #79115)

2024-01-31 Thread Owen Pan via cfe-commits

owenca wrote:

See #80241.

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


[clang] [clang-format] Update FormatToken::isSimpleTypeSpecifier() (PR #79115)

2024-01-31 Thread Owen Pan via cfe-commits

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


[clang] [clang-format] Update FormatToken::isSimpleTypeSpecifier() (PR #80241)

2024-01-31 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Now with a8279a8bc541, we can make the update.

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


4 Files Affected:

- (modified) clang/include/clang/Format/Format.h (+2) 
- (modified) clang/lib/Format/FormatToken.cpp (+1-34) 
- (modified) clang/lib/Format/FormatTokenLexer.cpp (+4-3) 
- (modified) clang/lib/Format/FormatTokenLexer.h (-1) 


``diff
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index efcb4e1d87ea4..361fde1ffece6 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5141,6 +5141,8 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
 ArrayRef Ranges,
 StringRef FileName = "");
 
+extern LangOptions LangOpts;
+
 /// Returns the ``LangOpts`` that the formatter expects you to set.
 ///
 /// \param Style determines specific settings for lexing mode.
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index b791c5a26bbe3..69f751db89630 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,41 +34,8 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy from Sema. Put it in a common place and remove
-// duplication.
 bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
+  return Tok.isSimpleTypeSpecifier(LangOpts);
 }
 
 bool FormatToken::isTypeOrIdentifier() const {
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index d7de09ef0e12a..53fe8a19b2fba 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -22,18 +22,20 @@
 namespace clang {
 namespace format {
 
+LangOptions LangOpts;
+
 FormatTokenLexer::FormatTokenLexer(
 const SourceManager , FileID ID, unsigned Column,
 const FormatStyle , encoding::Encoding Encoding,
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0),
-  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
+  LangOpts = getFormattingLangOpts(Style);
   Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
@@ -1442,7 +1444,6 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
 
 void FormatTokenLexer::resetLexer(unsigned Offset) {
   StringRef Buffer = SourceMgr.getBufferData(ID);
-  LangOpts = getFormattingLangOpts(Style);
   Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), LangOpts,
   Buffer.begin(), Buffer.begin() + Offset, Buffer.end()));
   Lex->SetKeepWhitespaceMode(true);
diff --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 65dd733bd5335..52838f1d8a17f 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -120,7 +120,6 @@ class FormatTokenLexer {
   unsigned Column;
   unsigned TrailingWhitespace;
   std::unique_ptr Lex;
-  LangOptions LangOpts;
   const SourceManager 
   FileID ID;
   const FormatStyle 

``




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


[clang] [clang-format] Update FormatToken::isSimpleTypeSpecifier() (PR #80241)

2024-01-31 Thread Owen Pan via cfe-commits

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

Now with a8279a8bc541, we can make the update.

>From fda19165bc1195be01159c7d071839822ff3f929 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Wed, 31 Jan 2024 20:43:29 -0800
Subject: [PATCH] [clang-format] Update FormatToken::isSimpleTypeSpecifier()

---
 clang/include/clang/Format/Format.h   |  2 ++
 clang/lib/Format/FormatToken.cpp  | 35 +--
 clang/lib/Format/FormatTokenLexer.cpp |  7 +++---
 clang/lib/Format/FormatTokenLexer.h   |  1 -
 4 files changed, 7 insertions(+), 38 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index efcb4e1d87ea4..361fde1ffece6 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -5141,6 +5141,8 @@ tooling::Replacements sortUsingDeclarations(const 
FormatStyle ,
 ArrayRef Ranges,
 StringRef FileName = "");
 
+extern LangOptions LangOpts;
+
 /// Returns the ``LangOpts`` that the formatter expects you to set.
 ///
 /// \param Style determines specific settings for lexing mode.
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index b791c5a26bbe3..69f751db89630 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -34,41 +34,8 @@ const char *getTokenTypeName(TokenType Type) {
   return nullptr;
 }
 
-// FIXME: This is copy from Sema. Put it in a common place and remove
-// duplication.
 bool FormatToken::isSimpleTypeSpecifier() const {
-  switch (Tok.getKind()) {
-  case tok::kw_short:
-  case tok::kw_long:
-  case tok::kw___int64:
-  case tok::kw___int128:
-  case tok::kw_signed:
-  case tok::kw_unsigned:
-  case tok::kw_void:
-  case tok::kw_char:
-  case tok::kw_int:
-  case tok::kw_half:
-  case tok::kw_float:
-  case tok::kw_double:
-  case tok::kw___bf16:
-  case tok::kw__Float16:
-  case tok::kw___float128:
-  case tok::kw___ibm128:
-  case tok::kw_wchar_t:
-  case tok::kw_bool:
-#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
-#include "clang/Basic/TransformTypeTraits.def"
-  case tok::annot_typename:
-  case tok::kw_char8_t:
-  case tok::kw_char16_t:
-  case tok::kw_char32_t:
-  case tok::kw_typeof:
-  case tok::kw_decltype:
-  case tok::kw__Atomic:
-return true;
-  default:
-return false;
-  }
+  return Tok.isSimpleTypeSpecifier(LangOpts);
 }
 
 bool FormatToken::isTypeOrIdentifier() const {
diff --git a/clang/lib/Format/FormatTokenLexer.cpp 
b/clang/lib/Format/FormatTokenLexer.cpp
index d7de09ef0e12a..53fe8a19b2fba 100644
--- a/clang/lib/Format/FormatTokenLexer.cpp
+++ b/clang/lib/Format/FormatTokenLexer.cpp
@@ -22,18 +22,20 @@
 namespace clang {
 namespace format {
 
+LangOptions LangOpts;
+
 FormatTokenLexer::FormatTokenLexer(
 const SourceManager , FileID ID, unsigned Column,
 const FormatStyle , encoding::Encoding Encoding,
 llvm::SpecificBumpPtrAllocator ,
 IdentifierTable )
 : FormatTok(nullptr), IsFirstToken(true), StateStack({LexerState::NORMAL}),
-  Column(Column), TrailingWhitespace(0),
-  LangOpts(getFormattingLangOpts(Style)), SourceMgr(SourceMgr), ID(ID),
+  Column(Column), TrailingWhitespace(0), SourceMgr(SourceMgr), ID(ID),
   Style(Style), IdentTable(IdentTable), Keywords(IdentTable),
   Encoding(Encoding), Allocator(Allocator), FirstInLineIndex(0),
   FormattingDisabled(false), MacroBlockBeginRegex(Style.MacroBlockBegin),
   MacroBlockEndRegex(Style.MacroBlockEnd) {
+  LangOpts = getFormattingLangOpts(Style);
   Lex.reset(new Lexer(ID, SourceMgr.getBufferOrFake(ID), SourceMgr, LangOpts));
   Lex->SetKeepWhitespaceMode(true);
 
@@ -1442,7 +1444,6 @@ void FormatTokenLexer::readRawToken(FormatToken ) {
 
 void FormatTokenLexer::resetLexer(unsigned Offset) {
   StringRef Buffer = SourceMgr.getBufferData(ID);
-  LangOpts = getFormattingLangOpts(Style);
   Lex.reset(new Lexer(SourceMgr.getLocForStartOfFile(ID), LangOpts,
   Buffer.begin(), Buffer.begin() + Offset, Buffer.end()));
   Lex->SetKeepWhitespaceMode(true);
diff --git a/clang/lib/Format/FormatTokenLexer.h 
b/clang/lib/Format/FormatTokenLexer.h
index 65dd733bd5335..52838f1d8a17f 100644
--- a/clang/lib/Format/FormatTokenLexer.h
+++ b/clang/lib/Format/FormatTokenLexer.h
@@ -120,7 +120,6 @@ class FormatTokenLexer {
   unsigned Column;
   unsigned TrailingWhitespace;
   std::unique_ptr Lex;
-  LangOptions LangOpts;
   const SourceManager 
   FileID ID;
   const FormatStyle 

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


[clang] [Clang][RISCV] Add assumptions to vsetvli/vsetvlimax (PR #79975)

2024-01-31 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

> I'm concerned that llvm.assume is handled differently than a branch to 
> unreachable in the middle end. 

Actually the CodeGen part is written by referring to the LLVM IR generated by 
unreachable way (https://godbolt.org/z/vf1v7f744).

> Have you tested that these assumes have the intended effect?

Yes, the end-to-end tests show that we can generate the same assemblies. I will 
add a test later.

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


[clang] [llvm] [RISCV][MC] MC layer support for the experimental zalasr extension (PR #79911)

2024-01-31 Thread Brendan Sweeney via cfe-commits

mehnadnerd wrote:

It has been approved to be pursued as a fast track extension 
(https://lists.riscv.org/g/tech-unprivileged/topic/arc_architecture_review/101951698).
 It has not yet been approved by the chairs.

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


[clang] [clang][dataflow] Display line numbers in the HTML logger timeline. (PR #80130)

2024-01-31 Thread via cfe-commits

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


[clang] 0c36127 - [clang][dataflow] Display line numbers in the HTML logger timeline. (#80130)

2024-01-31 Thread via cfe-commits

Author: martinboehme
Date: 2024-02-01T05:33:03+01:00
New Revision: 0c361270afff83cd6433cf865ed5a410dadfb33f

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

LOG: [clang][dataflow] Display line numbers in the HTML logger timeline. 
(#80130)

This makes it easier to count how many iterations an analysis takes to
complete.
It also makes it easier to compare how a change to the analysis code
affects
the timeline.

Here's a sample screenshot:


![image](https://github.com/llvm/llvm-project/assets/29098113/b3f44b4d-7037-4f28-9532-5418663250e1)

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/HTMLLogger.css
clang/lib/Analysis/FlowSensitive/HTMLLogger.html

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.css 
b/clang/lib/Analysis/FlowSensitive/HTMLLogger.css
index 5da8db8fa87bf..e25270430efc2 100644
--- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.css
+++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.css
@@ -29,6 +29,16 @@ section h2 {
 }
 #timeline {
   min-width: max-content;
+  counter-reset: entry_counter;
+}
+#timeline .entry .counter::before {
+  counter-increment: entry_counter;
+  content: counter(entry_counter) ":";
+}
+#timeline .entry .counter {
+  display: inline-block;
+  min-width: 2em; /* Enough space for two digits and a colon */
+  text-align: right;
 }
 #timeline .entry.hover {
   background-color: #aaa;

diff  --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.html 
b/clang/lib/Analysis/FlowSensitive/HTMLLogger.html
index b9f76c5074c75..be173e8b2854d 100644
--- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.html
+++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.html
@@ -42,6 +42,7 @@
 Timeline
 
   
+
 {{entry.block}}
 (post-visit)
 ({{entry.iter}})



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


[clang] [clang][dataflow] Display line numbers in the HTML logger timeline. (PR #80130)

2024-01-31 Thread via cfe-commits

martinboehme wrote:

Failing check is a clang-format check for clang/docs/HIPSupport.rst, which this 
PR does not modify.

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


[clang] [clang][dataflow][NFC] Rename a confusingly named variable. (PR #80182)

2024-01-31 Thread via cfe-commits

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


[clang] 994493c - [clang][dataflow][NFC] Rename a confusingly named variable. (#80182)

2024-01-31 Thread via cfe-commits

Author: martinboehme
Date: 2024-02-01T05:31:32+01:00
New Revision: 994493ce05ab7351cd92d30fb1bd23985b292851

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

LOG: [clang][dataflow][NFC] Rename a confusingly named variable. (#80182)

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp 
b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
index 1e098d8d23c42..ff4e18de2c70f 100644
--- a/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
+++ b/clang/lib/Analysis/FlowSensitive/HTMLLogger.cpp
@@ -162,7 +162,7 @@ class HTMLLogger : public Logger {
   llvm::raw_string_ostream JStringStream{JSON};
   llvm::json::OStream JOS{JStringStream, /*Indent=*/2};
 
-  const ControlFlowContext *CFG;
+  const ControlFlowContext *CFC;
   // Timeline of iterations of CFG block visitation.
   std::vector Iters;
   // Indexes  in `Iters` of the iterations for each block.
@@ -176,15 +176,15 @@ class HTMLLogger : public Logger {
 
 public:
   explicit HTMLLogger(StreamFactory Streams) : Streams(std::move(Streams)) {}
-  void beginAnalysis(const ControlFlowContext ,
+  void beginAnalysis(const ControlFlowContext ,
  TypeErasedDataflowAnalysis ) override {
 OS = Streams();
-this->CFG = 
+this->CFC = 
 *OS << llvm::StringRef(HTMLLogger_html).split("").first;
 
-BlockConverged.resize(CFG.getCFG().getNumBlockIDs());
+BlockConverged.resize(CFC.getCFG().getNumBlockIDs());
 
-const auto  = CFG.getDecl();
+const auto  = CFC.getDecl();
 const auto  = A.getASTContext().getSourceManager();
 *OS << "";
 if (const auto *ND = dyn_cast())
@@ -345,7 +345,7 @@ class HTMLLogger : public Logger {
   // tokens are associated with, and even which BB element (so that clicking
   // can select the right element).
   void writeCode() {
-const auto  = CFG->getDecl().getASTContext();
+const auto  = CFC->getDecl().getASTContext();
 bool Invalid = false;
 
 // Extract the source code from the original file.
@@ -353,7 +353,7 @@ class HTMLLogger : public Logger {
 // indentation to worry about), but we need the boundaries of particular
 // AST nodes and the printer doesn't provide this.
 auto Range = clang::Lexer::makeFileCharRange(
-CharSourceRange::getTokenRange(CFG->getDecl().getSourceRange()),
+CharSourceRange::getTokenRange(CFC->getDecl().getSourceRange()),
 AST.getSourceManager(), AST.getLangOpts());
 if (Range.isInvalid())
   return;
@@ -419,7 +419,7 @@ class HTMLLogger : public Logger {
 // Construct one TokenInfo per character in a flat array.
 // This is inefficient (chars in a token all have the same info) but 
simple.
 std::vector State(Code.size());
-for (const auto *Block : CFG->getCFG()) {
+for (const auto *Block : CFC->getCFG()) {
   unsigned EltIndex = 0;
   for (const auto& Elt : *Block) {
 ++EltIndex;
@@ -480,7 +480,7 @@ class HTMLLogger : public Logger {
   // out to `dot` to turn it into an SVG.
   void writeCFG() {
 *OS << "\n";
-if (auto SVG = renderSVG(buildCFGDot(CFG->getCFG(
+if (auto SVG = renderSVG(buildCFGDot(CFC->getCFG(
   *OS << *SVG;
 else
   *OS << "Can't draw CFG: " << toString(SVG.takeError());



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


[clang] [clang-format] Simplify the AfterPlacementOperator option (PR #79796)

2024-01-31 Thread Owen Pan via cfe-commits

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


[clang] 908fd09 - [clang-format] Simplify the AfterPlacementOperator option (#79796)

2024-01-31 Thread via cfe-commits

Author: Owen Pan
Date: 2024-01-31T20:20:26-08:00
New Revision: 908fd09a13b2e89a52282478544f7f70cf0a887f

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

LOG: [clang-format] Simplify the AfterPlacementOperator option (#79796)

Change AfterPlacementOperator to a boolean and deprecate SBPO_Never,
which meant never inserting a space except when after new/delete.

Fixes #78892.

Added: 


Modified: 
clang/docs/ClangFormatStyleOptions.rst
clang/include/clang/Format/Format.h
clang/lib/Format/Format.cpp
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/ConfigParseTest.cpp
clang/unittests/Format/FormatTest.cpp

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 4dc0de3a90f26..0b887288fe2cb 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -5277,15 +5277,9 @@ the configuration (without a prefix: ``Auto``).
   Possible values:
 
   * ``SBPO_Never`` (in configuration: ``Never``)
-Never put a space before opening parentheses.
-
-.. code-block:: c++
-
-   void f() {
- if(true) {
-   f();
- }
-   }
+This is **deprecated** and replaced by ``Custom`` below, with all
+``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
+``false``.
 
   * ``SBPO_ControlStatements`` (in configuration: ``ControlStatements``)
 Put a space before opening parentheses only after control statement
@@ -5425,32 +5419,14 @@ the configuration (without a prefix: ``Auto``).
void operator++ (int a);vs.void operator++(int a);
object.operator++ (10);object.operator++(10);
 
-  * ``AfterPlacementOperatorStyle AfterPlacementOperator`` 
:versionbadge:`clang-format 18`
-
-Defines in which cases to put a space between ``new/delete`` operators
-and opening parentheses.
-
-Possible values:
-
-* ``APO_Never`` (in configuration: ``Never``)
-  Remove space after ``new/delete`` operators and before ``(``.
-
-  .. code-block:: c++
-
- new(buf) T;
- delete(buf) T;
-
-* ``APO_Always`` (in configuration: ``Always``)
-  Always add space after ``new/delete`` operators and before ``(``.
+  * ``bool AfterPlacementOperator`` If ``true``, put a space between operator 
``new``/``delete`` and opening
+parenthesis.
 
-  .. code-block:: c++
-
- new (buf) T;
- delete (buf) T;
-
-* ``APO_Leave`` (in configuration: ``Leave``)
-  Leave placement ``new/delete`` expressions as they are.
+.. code-block:: c++
 
+   true:  false:
+   new (buf) T;vs.new(buf) T;
+   delete (buf) T;delete(buf) T;
 
   * ``bool AfterRequiresInClause`` If ``true``, put space between requires 
keyword in a requires clause and
 opening parentheses, if there is one.

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index bc9eecd42f9eb..efcb4e1d87ea4 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4157,14 +4157,9 @@ struct FormatStyle {
 
   /// Different ways to put a space before opening parentheses.
   enum SpaceBeforeParensStyle : int8_t {
-/// Never put a space before opening parentheses.
-/// \code
-///void f() {
-///  if(true) {
-///f();
-///  }
-///}
-/// \endcode
+/// This is **deprecated** and replaced by ``Custom`` below, with all
+/// ``SpaceBeforeParensOptions`` but ``AfterPlacementOperator`` set to
+/// ``false``.
 SBPO_Never,
 /// Put a space before opening parentheses only after control statement
 /// keywords (``for/if/while...``).
@@ -4273,28 +4268,14 @@ struct FormatStyle {
 ///object.operator++ (10);object.operator++(10);
 /// \endcode
 bool AfterOverloadedOperator;
-/// Styles for adding spacing between ``new/delete`` operators and opening
-/// parentheses.
-enum AfterPlacementOperatorStyle : int8_t {
-  /// Remove space after ``new/delete`` operators and before ``(``.
-  /// \code
-  ///new(buf) T;
-  ///delete(buf) T;
-  /// \endcode
-  APO_Never,
-  /// Always add space after ``new/delete`` operators and before ``(``.
-  /// \code
-  ///new (buf) T;
-  ///delete (buf) T;
-  /// \endcode
-  APO_Always,
-  /// Leave placement ``new/delete`` expressions as they are.
-  APO_Leave,
-};
-/// Defines in which cases to put a space between ``new/delete`` operators
-/// and opening parentheses.
-/// \version 18
-AfterPlacementOperatorStyle 

[clang] [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (PR #80101)

2024-01-31 Thread Owen Pan via cfe-commits

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


[clang] a8279a8 - [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (#80101)

2024-01-31 Thread via cfe-commits

Author: Owen Pan
Date: 2024-01-31T20:16:18-08:00
New Revision: a8279a8bc541b6027087dd497daa63b6602b7f4b

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

LOG: [clang][NFC] Move isSimpleTypeSpecifier() from Sema to Token (#80101)

So that it can be used by clang-format.

Added: 


Modified: 
clang/include/clang/Lex/Token.h
clang/include/clang/Sema/Sema.h
clang/lib/Lex/Lexer.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseObjc.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Lex/Token.h b/clang/include/clang/Lex/Token.h
index 1409e2c58b550..36ec5ddaa29ad 100644
--- a/clang/include/clang/Lex/Token.h
+++ b/clang/include/clang/Lex/Token.h
@@ -22,6 +22,7 @@
 namespace clang {
 
 class IdentifierInfo;
+class LangOptions;
 
 /// Token - This structure provides full information about a lexed token.
 /// It is not intended to be space efficient, it is intended to return as much
@@ -288,6 +289,8 @@ class Token {
   /// Return the ObjC keyword kind.
   tok::ObjCKeywordKind getObjCKeywordID() const;
 
+  bool isSimpleTypeSpecifier(const LangOptions ) const;
+
   /// Return true if this token has trigraphs or escaped newlines in it.
   bool needsCleaning() const { return getFlag(NeedsCleaning); }
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1ac2a465a0d59..b780cee86c3c3 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2683,8 +2683,6 @@ class Sema final {
 
   void DiagnoseUseOfUnimplementedSelectors();
 
-  bool isSimpleTypeSpecifier(const Token ) const;
-
   ParsedType getTypeName(const IdentifierInfo , SourceLocation NameLoc,
  Scope *S, CXXScopeSpec *SS = nullptr,
  bool isClassName = false, bool HasTrailingDot = false,

diff  --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 50b56265f6e16..d927f28b47c27 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -74,6 +74,51 @@ tok::ObjCKeywordKind Token::getObjCKeywordID() const {
   return specId ? specId->getObjCKeywordID() : tok::objc_not_keyword;
 }
 
+/// Determine whether the token kind starts a simple-type-specifier.
+bool Token::isSimpleTypeSpecifier(const LangOptions ) const {
+  switch (getKind()) {
+  case tok::annot_typename:
+  case tok::annot_decltype:
+  case tok::annot_pack_indexing_type:
+return true;
+
+  case tok::kw_short:
+  case tok::kw_long:
+  case tok::kw___int64:
+  case tok::kw___int128:
+  case tok::kw_signed:
+  case tok::kw_unsigned:
+  case tok::kw_void:
+  case tok::kw_char:
+  case tok::kw_int:
+  case tok::kw_half:
+  case tok::kw_float:
+  case tok::kw_double:
+  case tok::kw___bf16:
+  case tok::kw__Float16:
+  case tok::kw___float128:
+  case tok::kw___ibm128:
+  case tok::kw_wchar_t:
+  case tok::kw_bool:
+  case tok::kw__Bool:
+  case tok::kw__Accum:
+  case tok::kw__Fract:
+  case tok::kw__Sat:
+#define TRANSFORM_TYPE_TRAIT_DEF(_, Trait) case tok::kw___##Trait:
+#include "clang/Basic/TransformTypeTraits.def"
+  case tok::kw___auto_type:
+  case tok::kw_char16_t:
+  case tok::kw_char32_t:
+  case tok::kw_typeof:
+  case tok::kw_decltype:
+  case tok::kw_char8_t:
+return getIdentifierInfo()->isKeyword(LangOpts);
+
+  default:
+return false;
+  }
+}
+
 
//===--===//
 // Lexer Class Implementation
 
//===--===//

diff  --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index e5d4285b99183..52cebdb6f64ba 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -1609,7 +1609,7 @@ ExprResult Parser::ParseCastExpression(CastParseKind 
ParseKind,
   if (TryAnnotateTypeOrScopeToken())
 return ExprError();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok))
+  if (!Tok.isSimpleTypeSpecifier(getLangOpts()))
 // We are trying to parse a simple-type-specifier but might not get 
such
 // a token after error recovery.
 return ExprError();

diff  --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 4771b69eadb34..88bab0eb27a3e 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -2971,7 +2971,7 @@ bool Parser::ParseObjCXXMessageReceiver(bool , 
void *) {
   tok::annot_cxxscope))
 TryAnnotateTypeOrScopeToken();
 
-  if (!Actions.isSimpleTypeSpecifier(Tok)) {
+  if (!Tok.isSimpleTypeSpecifier(getLangOpts())) {
 //   objc-receiver:
 // expression
 // Make sure any typos in the receiver are corrected or diagnosed, so that

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp

  1   2   3   4   5   >