[PATCH] D154396: [clang] Add support for SerenityOS

2023-07-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:85
+  auto linkerIs = [Exec](const char *name) {
+return llvm::sys::path::filename(Exec).equals_insensitive(name) ||
+   llvm::sys::path::stem(Exec).equals_insensitive(name);

ADKaster wrote:
> MaskRay wrote:
> > Avoid `equals_insensitive`. It's only recommended in some places for 
> > Windows.
> What is the recommendation for this use case instead? This is the same 
> pattern that is used by the Fuchsia driver. 
> https://github.com/llvm/llvm-project/blob/01e3393b94d194ee99e57f23f9c08160cef94753/clang/lib/Driver/ToolChains/Fuchsia.cpp#L59-L61
> 
> though it looks like Fuchsia used that pattern back when it was called 
> `equals_lower()`. 
> https://github.com/llvm/llvm-project/commit/3e199ecdadf7b546054c5a5820d1678f1e83c821
I think Fuchsia should not use `equals_lower`. There is never a case that we'd 
use something like `ld.LLD`.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:127
+  Args.AddAllArgs(CmdArgs, options::OPT_T_Group);
+  Args.AddAllArgs(CmdArgs, options::OPT_e);
+  Args.AddAllArgs(CmdArgs, options::OPT_s);

`OPT_e` has the LinkerInput flag and is rendered by AddLinkerInputs. Remove 
`Args.AddAllArgs(CmdArgs, options::OPT_e);` to avoid duplicate `-e`.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:130
+  Args.AddAllArgs(CmdArgs, options::OPT_t);
+  Args.AddAllArgs(CmdArgs, options::OPT_Z_Flag);
+  Args.AddAllArgs(CmdArgs, options::OPT_r);

gcc doesn't recognize `-Z`. I think it is an early (200x) mistake that some 
targets render `-Z`. Drop it.



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:143
+const SanitizerArgs &Sanitize = TC.getSanitizerArgs(Args);
+if (Sanitize.needsUbsanRt())
+  CmdArgs.push_back("-lubsan");

I wonder why you don't use the common `addSanitizerRuntimes`. ubsan runtime is 
normally `libclang_rt.ubsan_standalone*`



Comment at: clang/lib/Driver/ToolChains/Serenity.cpp:195
+getProgramPaths().push_back(getDriver().Dir);
+  getFilePaths().push_back(getDriver().SysRoot + "/usr/local/lib");
+  getFilePaths().push_back(getDriver().SysRoot + "/usr/lib");

`/usr/local/lib` should not be in the default search path.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154396

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


[PATCH] D154758: [clang][Interp] Emit correct diagnostic for uninitialized reads

2023-07-08 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin accepted this revision.
cor3ntin added a comment.
This revision is now accepted and ready to land.

LGTM but please make sure to run clang-format before commiting.


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

https://reviews.llvm.org/D154758

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


[PATCH] D153738: Add LibClang guide

2023-07-08 Thread Manuel via Phabricator via cfe-commits
manuel5975p updated this revision to Diff 538333.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153738

Files:
  clang/docs/LibClang.rst

Index: clang/docs/LibClang.rst
===
--- /dev/null
+++ clang/docs/LibClang.rst
@@ -0,0 +1,364 @@
+.. role:: raw-html(raw)
+:format: html
+
+Libclang tutorial
+=
+The C Interface to Clang provides a relatively small API that exposes facilities for parsing source code into an abstract syntax tree (AST), loading already-parsed ASTs, traversing the AST, associating physical source locations with elements within the AST, and other facilities that support Clang-based development tools.
+This C interface to Clang will never provide all of the information representation stored in Clang's C++ AST, nor should it: the intent is to maintain an API that is relatively stable from one release to the next, providing only the basic functionality needed to support development tools.
+The entire C interface of libclang is available in the file `Index.h`_
+
+Essential types overview
+-
+
+All types of libclang are prefixed with ``CX``
+
+CXIndex
+~~~
+An Index that consists of a set of translation units that would typically be linked together into an executable or library.
+
+CXTranslationUnit
+~
+A single translation unit, which resides in an index.
+
+CXCursor
+
+A cursor representing a pointer to some element in the abstract syntax tree of a translation unit.
+
+
+Code example
+
+
+.. code-block:: cpp
+  
+  // file.cpp
+  struct foo{
+int bar;
+int* bar_pointer;
+  };
+
+.. code-block:: cpp
+  
+  #include 
+  #include 
+
+  int main(){
+CXIndex index = clang_createIndex(0, 0); //Create index
+CXTranslationUnit unit = clang_parseTranslationUnit(
+  index,
+  "file.cpp", nullptr, 0,
+  nullptr, 0,
+  CXTranslationUnit_None); //Parse "file.cpp"
+
+
+if (unit == nullptr){
+  std::cerr << "Unable to parse translation unit. Quitting.\n";
+  return 0;
+}
+CXCursor cursor = clang_getTranslationUnitCursor(unit); //Obtain a cursor at the root of the translation unit
+  }
+
+Visiting elements of an AST
+~~~
+The elements of an AST can be recursively visited with pre-order traversal with ``clang_visitChildren``.
+
+.. code-block:: cpp
+
+  clang_visitChildren(
+cursor, //Root cursor
+[](CXCursor current_cursor, CXCursor parent, CXClientData client_data){
+
+  CXString current_display_name = clang_getCursorDisplayName(current_cursor); 
+  //Allocate a CXString representing the name of the current cursor
+  
+  std::cout << "Visiting element " << clang_getCString(current_display_name) << "\n";
+  //Print the char* value of current_display_name
+
+  clang_disposeString(current_display_name);
+  //Since clang_getCursorDisplayName allocates a new CXString, it must be freed. This applies
+  //to all functions returning a CXString
+
+  return CXChildVisit_Recurse;
+
+
+}, //CXCursorVisitor: a function pointer
+nullptr //client_data
+);
+
+The return value of ``CXCursorVisitor``, the callable argument of ``clang_visitChildren``, can return one of the three:
+
+#. ``CXChildVisit_Break``: Terminates the cursor traversal
+
+#. ``CXChildVisit_Continue``: Continues the cursor traversal with the next sibling of the cursor just visited, without visiting its children.
+
+#. ``CXChildVisit_Recurse``: Recursively traverse the children of this cursor, using the same visitor and client data
+
+The expected output of that program is
+
+.. code-block:: 
+
+  Visiting element foo
+  Visiting element bar
+  Visiting element bar_pointer
+
+
+Extracting information from a Cursor
+
+.. The following functions take a ``CXCursor`` as an argument and return associated information.
+
+
+
+Extracting the Cursor kind
+""
+
+``CXCursorKind clang_getCursorKind(CXCursor)`` Describes the kind of entity that a cursor refers to. Example values:
+  
+- ``CXCursor_StructDecl``: A C or C++ struct.
+- ``CXCursor_FieldDecl``: A field in a struct, union, or C++ class.
+- ``CXCursor_CallExpr``: An expression that calls a function.
+
+
+Extracting the Cursor type
+""
+``CXType clang_getCursorType(CXCursor)``: Retrieve the type of a CXCursor (if any).
+
+A ``CXType`` represents a complete C++ type, including qualifiers and pointers. It has a member field ``CXTypeKind kind`` and additional opaque data.
+
+Example values for ``CXTypeKind kind``
+
+- ``CXType_Invalid``: Represents an invalid type (e.g., where no type is available)
+- ``CXType_Pointer``: A pointer to another type
+- ``CXType_Int``: Regular ``int``
+- ``CXType_Elaborated``: Represents a type that was referred to using an elaborated type k

[PATCH] D154761: [clang][Interp] Diagnose callsite for implicit functions

2023-07-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, shafik, cor3ntin.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

  We don't have any code to point at here, so the diagnostics would just
  point to the record declaration. Make them point to the call site
  intead.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154761

Files:
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/test/AST/Interp/cxx20.cpp


Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -623,3 +623,26 @@
   constexpr C c = {1,2,3};
   static_assert(c.a == 1 && c.b == 2 && c.c == 3);
 }
+
+namespace ImplicitFunction {
+  struct A {
+int a; // ref-note {{subobject declared here}}
+  };
+
+  constexpr int callMe() {
+   A a;
+   A b{12};
+
+   /// The operator= call here will fail and the diagnostics should be fine.
+   b = a; // ref-note {{subobject 'a' is not initialized}} \
+  // ref-note {{in call to}} \
+  // expected-note {{read of uninitialized object}} \
+  // expected-note {{in call to}}
+
+   return 1;
+  }
+  static_assert(callMe() == 1, ""); // ref-error {{not an integral constant 
expression}} \
+// ref-note {{in call to 'callMe()'}} \
+// expected-error {{not an integral 
constant expression}} \
+// expected-note {{in call to 'callMe()'}}
+}
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -213,6 +213,11 @@
 }
 
 SourceInfo InterpFrame::getSource(CodePtr PC) const {
+  // Implicitly created functions don't have any code we could point at,
+  // so return the call site.
+  if (Func && Func->getDecl()->isImplicit() && Caller)
+return Caller->getSource(RetPC);
+
   return S.getSource(Func, PC);
 }
 


Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -623,3 +623,26 @@
   constexpr C c = {1,2,3};
   static_assert(c.a == 1 && c.b == 2 && c.c == 3);
 }
+
+namespace ImplicitFunction {
+  struct A {
+int a; // ref-note {{subobject declared here}}
+  };
+
+  constexpr int callMe() {
+   A a;
+   A b{12};
+
+   /// The operator= call here will fail and the diagnostics should be fine.
+   b = a; // ref-note {{subobject 'a' is not initialized}} \
+  // ref-note {{in call to}} \
+  // expected-note {{read of uninitialized object}} \
+  // expected-note {{in call to}}
+
+   return 1;
+  }
+  static_assert(callMe() == 1, ""); // ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'callMe()'}} \
+// expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'callMe()'}}
+}
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -213,6 +213,11 @@
 }
 
 SourceInfo InterpFrame::getSource(CodePtr PC) const {
+  // Implicitly created functions don't have any code we could point at,
+  // so return the call site.
+  if (Func && Func->getDecl()->isImplicit() && Caller)
+return Caller->getSource(RetPC);
+
   return S.getSource(Func, PC);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D105759: Implement P2361 Unevaluated string literals

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

In D105759#4482543 , @barannikov88 
wrote:

> @cor3ntin 
> I've been working on pretty much the same functionality in our downstream 
> fork. I was not aware of the paper, nor of the ongoing work in this 
> direction, and so I unfortunately missed the review.
> Thanks for this patch, it significantly reduces the number of changes 
> downstream and makes it easier to merge with upstream in the future.
>
> I have a couple of questions about future work:
>
> - IIUC the paper initially addressed this issue with `#line` directive, but 
> the changes were reverted(?). Is there any chance they can get back?

There is a core issue tracking that, ie the c++ committee was concerned about 
escape sequences in header names
https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2693

I'd be happy to bring that back to clang though, as the concerned is unlikely 
to be warranted for us.

> - Are there any plans for making similar changes to asm statement parsing?

The direction of the c++ committee is that what's in `asm()` is now strictly 
implementation-defined, so we could but last time there were concerns about 
escape sequences in there too.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D105759

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


[PATCH] D151047: [clang-format] Fix indentation for selective formatting.

2023-07-08 Thread Sedenion via Phabricator via cfe-commits
Sedeniono added a comment.

If everyone is ok with the changes, could someone commit it for me since I do 
not have commit rights? Thanks!
`Sedenion <39583823+sedeni...@users.noreply.github.com>`

Note: I cannot really make sense of the error reported by the pre merge checks 
. I suspect a problem in 
the build system. I can apply the patch locally on the latest main branch 
without any conflicts.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151047

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


[clang] 39d8e6e - Add missing StringExtras.h includes

2023-07-08 Thread Elliot Goodrich via cfe-commits

Author: Elliot Goodrich
Date: 2023-07-08T10:19:07+01:00
New Revision: 39d8e6e22cd192db6ace37a4c842265058dcddb8

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

LOG: Add missing StringExtras.h includes

In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.

This is fixing all files missed in b0abd4893fa1.

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

Added: 


Modified: 
clang/lib/Driver/ToolChain.cpp
clang/lib/Driver/ToolChains/BareMetal.cpp
llvm/lib/Analysis/VectorUtils.cpp
llvm/lib/Transforms/IPO/Internalize.cpp
llvm/lib/Transforms/Scalar/MergeICmps.cpp
llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
llvm/lib/Transforms/Utils/ModuleUtils.cpp
llvm/tools/llvm-objdump/XCOFFDump.cpp
llvm/unittests/Support/CompressionTest.cpp

Removed: 




diff  --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 425045801dc217..d60fdbc179683b 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -26,6 +26,7 @@
 #include "clang/Driver/XRayArgs.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/ADT/Twine.h"
 #include "llvm/Config/llvm-config.h"

diff  --git a/clang/lib/Driver/ToolChains/BareMetal.cpp 
b/clang/lib/Driver/ToolChains/BareMetal.cpp
index 470b477a181d01..850d7c59c3474a 100644
--- a/clang/lib/Driver/ToolChains/BareMetal.cpp
+++ b/clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -18,6 +18,7 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/MultilibBuilder.h"
 #include "clang/Driver/Options.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VirtualFileSystem.h"

diff  --git a/llvm/lib/Analysis/VectorUtils.cpp 
b/llvm/lib/Analysis/VectorUtils.cpp
index 04387221cf8e01..f350c6088b6f20 100644
--- a/llvm/lib/Analysis/VectorUtils.cpp
+++ b/llvm/lib/Analysis/VectorUtils.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Analysis/VectorUtils.h"
 #include "llvm/ADT/EquivalenceClasses.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/DemandedBits.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/LoopIterator.h"

diff  --git a/llvm/lib/Transforms/IPO/Internalize.cpp 
b/llvm/lib/Transforms/IPO/Internalize.cpp
index 1181886494caa0..0b8fde6489f8e7 100644
--- a/llvm/lib/Transforms/IPO/Internalize.cpp
+++ b/llvm/lib/Transforms/IPO/Internalize.cpp
@@ -19,6 +19,7 @@
 
//===--===//
 
 #include "llvm/Transforms/IPO/Internalize.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Analysis/CallGraph.h"

diff  --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp 
b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
index 9e41d5500d801a..311a6435ba7c57 100644
--- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -42,6 +42,7 @@
 
//===--===//
 
 #include "llvm/Transforms/Scalar/MergeICmps.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/Loads.h"

diff  --git a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp 
b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
index a1992d2d63bf4f..531b0a624dafab 100644
--- a/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
+++ b/llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
@@ -11,6 +11,7 @@
 
//===--===//
 
 #include "llvm/Transforms/Utils/MemoryOpRemark.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/IR/DebugInfo.h"

diff  --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp 
b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
index adc2fc0610f3bf..ecd64d8ca4a413 100644
--- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include "llvm/Analysis/VectorUtils.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
@@ -19,6 +20,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/xxhash.h"
+
 using namespace llvm;
 
 #define DEBUG_TYPE "moduleutils"

diff  --git a/llvm/tools/llvm-objdump/XCOFFDump

[PATCH] D154543: [Support] Move StringExtras.h include from Error.h to Error.cpp

2023-07-08 Thread Elliot Goodrich via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG39d8e6e22cd1: Add missing StringExtras.h includes (authored 
by IncludeGuardian).

Changed prior to commit:
  https://reviews.llvm.org/D154543?vs=538238&id=538337#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154543

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/lib/Driver/ToolChains/BareMetal.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/Transforms/IPO/Internalize.cpp
  llvm/lib/Transforms/Scalar/MergeICmps.cpp
  llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
  llvm/lib/Transforms/Utils/ModuleUtils.cpp
  llvm/tools/llvm-objdump/XCOFFDump.cpp
  llvm/unittests/Support/CompressionTest.cpp

Index: llvm/unittests/Support/CompressionTest.cpp
===
--- llvm/unittests/Support/CompressionTest.cpp
+++ llvm/unittests/Support/CompressionTest.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Support/Compression.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/Error.h"
Index: llvm/tools/llvm-objdump/XCOFFDump.cpp
===
--- llvm/tools/llvm-objdump/XCOFFDump.cpp
+++ llvm/tools/llvm-objdump/XCOFFDump.cpp
@@ -14,6 +14,7 @@
 #include "XCOFFDump.h"
 
 #include "llvm-objdump.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Demangle/Demangle.h"
 #include "llvm/MC/MCInstPrinter.h"
 #include "llvm/MC/MCSubtargetInfo.h"
Index: llvm/lib/Transforms/Utils/ModuleUtils.cpp
===
--- llvm/lib/Transforms/Utils/ModuleUtils.cpp
+++ llvm/lib/Transforms/Utils/ModuleUtils.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 #include "llvm/Analysis/VectorUtils.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/IR/DerivedTypes.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/IRBuilder.h"
@@ -19,6 +20,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/xxhash.h"
+
 using namespace llvm;
 
 #define DEBUG_TYPE "moduleutils"
Index: llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
===
--- llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
+++ llvm/lib/Transforms/Utils/MemoryOpRemark.cpp
@@ -11,6 +11,7 @@
 //===--===//
 
 #include "llvm/Transforms/Utils/MemoryOpRemark.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/IR/DebugInfo.h"
Index: llvm/lib/Transforms/Scalar/MergeICmps.cpp
===
--- llvm/lib/Transforms/Scalar/MergeICmps.cpp
+++ llvm/lib/Transforms/Scalar/MergeICmps.cpp
@@ -42,6 +42,7 @@
 //===--===//
 
 #include "llvm/Transforms/Scalar/MergeICmps.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/GlobalsModRef.h"
 #include "llvm/Analysis/Loads.h"
Index: llvm/lib/Transforms/IPO/Internalize.cpp
===
--- llvm/lib/Transforms/IPO/Internalize.cpp
+++ llvm/lib/Transforms/IPO/Internalize.cpp
@@ -19,6 +19,7 @@
 //===--===//
 
 #include "llvm/Transforms/IPO/Internalize.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Analysis/CallGraph.h"
Index: llvm/lib/Analysis/VectorUtils.cpp
===
--- llvm/lib/Analysis/VectorUtils.cpp
+++ llvm/lib/Analysis/VectorUtils.cpp
@@ -12,6 +12,7 @@
 
 #include "llvm/Analysis/VectorUtils.h"
 #include "llvm/ADT/EquivalenceClasses.h"
+#include "llvm/ADT/SmallString.h"
 #include "llvm/Analysis/DemandedBits.h"
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/Analysis/LoopIterator.h"
Index: clang/lib/Driver/ToolChains/BareMetal.cpp
===
--- clang/lib/Driver/ToolChains/BareMetal.cpp
+++ clang/lib/Driver/ToolChains/BareMetal.cpp
@@ -18,6 +18,7 @@
 #include "clang/Driver/DriverDiagnostic.h"
 #include "clang/Driver/MultilibBuilder.h"
 #include "clang/Driver/Options.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/VirtualFileSystem.h"
Index: clang/lib/Driver/ToolChain.cpp
===
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -26,6 +26,7 @@
 #in

[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2023-07-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

Out of curiosity, not sure if it's worth fixing because it's easy enough to 
work around: I think after this change, it's not possible anymore to call 
`printName(raw_ostream &OS)` on a (statically typed) `TagDecl` / `EnumDecl` 
because it's hidden by `TagDecl::printName(raw_ostream &OS, const 
PrintingPolicy &Policy)` while it works perfectly for a `NamedDecl`. Is this 
intentional?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D154290: [Clang] Implement P2741R3 - user-generated static_assert messages

2023-07-08 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 538350.
cor3ntin marked 4 inline comments as done.
cor3ntin added a comment.

Address Timm's feedback


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ODRDiagsEmitter.cpp
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/SemaCXX/static-assert-cxx26.cpp
  clang/tools/libclang/CIndex.cpp
  clang/www/cxx_status.html

Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -145,7 +145,7 @@
  
   User-generated static_assert messages
   https://wg21.link/P2741R3";>P2741R3
-  No
+  Clang 17
  
  
   Placeholder variables with no name
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1294,7 +1294,7 @@
 bool CursorVisitor::VisitStaticAssertDecl(StaticAssertDecl *D) {
   if (Visit(MakeCXCursor(D->getAssertExpr(), StmtParent, TU, RegionOfInterest)))
 return true;
-  if (StringLiteral *Message = D->getMessage())
+  if (auto *Message = dyn_cast(D->getMessage()))
 if (Visit(MakeCXCursor(Message, StmtParent, TU, RegionOfInterest)))
   return true;
   return false;
Index: clang/test/SemaCXX/static-assert-cxx26.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/static-assert-cxx26.cpp
@@ -0,0 +1,127 @@
+// RUN: %clang_cc1 -std=c++2c -fsyntax-only %s -verify
+
+static_assert(true, "");
+static_assert(true, 0); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+struct Empty{};
+static_assert(true, Empty{}); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+struct NoData {
+unsigned long size() const;
+};
+struct NoSize {
+const char* data() const;
+};
+static_assert(true, NoData{}); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+static_assert(true, NoSize{}); // expected-error {{the message in a static_assert declaration must be a string literal or an object with data() and size() member functions}}
+
+struct InvalidSize {
+const char* size() const;
+const char* data() const;
+};
+static_assert(true, InvalidSize{}); // expected-error {{the message in a static_assert declaration must have a size() member function returning an object convertible to std::size_t}} \
+// expected-error {{value of type 'const char *' is not implicitly convertible to 'unsigned long'}}
+struct InvalidData {
+unsigned long size() const;
+unsigned long data() const;
+};
+static_assert(true, InvalidData{}); // expected-error {{the message in a static_assert declaration must have a data() member function returning an object convertible to const char*}} \
+// expected-error {{value of type 'unsigned long' is not implicitly convertible to 'const char *'}}
+
+struct NonConstexprSize {
+unsigned long size() const; // expected-note {{declared here}}
+constexpr const char* data() const;
+};
+
+static_assert(true, NonConstexprSize{});
+static_assert(false, NonConstexprSize{}); // expected-error {{the message in a static_assert declaration must be produced by constant expression}} \
+  // expected-error {{static assertion failed}} \
+  // expected-note  {{non-constexpr function 'size' cannot be used in a constant expression}}
+
+struct NonConstexprData {
+constexpr unsigned long size() const {
+return 32;
+}
+const char* data() const;  // expected-note {{declared here}}
+};
+
+static_assert(true, NonConstexprData{});
+static_assert(false, NonConstexprData{}); // expected-error {{the message in a static_assert declaration must be produced by constant expression}} \
+  // expected-error {{static assertion failed}} \
+  // expected-note  {{non-constexpr function 'data' cannot be used in a constant expression}}
+
+struct string_view {
+int S;
+const char* D;
+constexpr string_vi

[PATCH] D154290: [Clang] Implement P2741R3 - user-generated static_assert messages

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



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16898
+  }
+
+  QualType T = Message->getType().getNonReferenceType();

tbaeder wrote:
> What if the message is ` StringLiteral` but `getCharByteWidth()` doesn't 
> return `1`? We would get the `err_static_assert_invalid_message` because` 
> !RD` is true, right?
I forgot to change that while merging. StringLiteral are guaranteed to be 
unevaluated there



Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16900
+  QualType T = Message->getType().getNonReferenceType();
+  auto *RD = T->getAsCXXRecordDecl();
+  if (!RD) {

tbaeder wrote:
> 
Alas, `LookupQualifiedName` takes a non-const argument


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

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


[PATCH] D154764: [clang] ASTImport: force recomputing ASTRecordLayout when importing

2023-07-08 Thread Ding Fei via Phabricator via cfe-commits
danix800 created this revision.
danix800 added a project: clang.
Herald added a subscriber: martong.
Herald added a project: All.
danix800 requested review of this revision.
Herald added a subscriber: cfe-commits.

RecordLayout is cached for RecordDecl. Force recomputing in case staled one is 
returned when importing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154764

Files:
  clang/include/clang/AST/ASTContext.h
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/RecordLayoutBuilder.cpp
  clang/test/Analysis/astimport-force-relayout/Inputs/api.cc
  clang/test/Analysis/astimport-force-relayout/Inputs/externalDefMap.txt
  clang/test/Analysis/astimport-force-relayout/Inputs/v8.h
  clang/test/Analysis/astimport-force-relayout/date.cpp

Index: clang/test/Analysis/astimport-force-relayout/date.cpp
===
--- /dev/null
+++ clang/test/Analysis/astimport-force-relayout/date.cpp
@@ -0,0 +1,20 @@
+// RUN: rm -rf %t && mkdir %t
+// RUN: mkdir -p %t/ctudir
+
+// RUN: %clang -c -mthumb --target=armv7a-linux-androideabi1 -x c++ \
+// RUN:   -std=gnu++17 %p/Inputs/api.cc -emit-ast -o %t/ctudir/api.cc.ast
+
+// RUN: cp %p/Inputs/externalDefMap.txt %t/ctudir/externalDefMap.txt
+
+// RUN: %clang_analyze_cc1 -triple thumbv7-unknown-linux-android1 \
+// RUN:   -std=gnu++17 \
+// RUN:   -analyzer-checker=core.DivideZero \
+// RUN:   -analyzer-opt-analyze-headers \
+// RUN:   -analyzer-config experimental-enable-naive-ctu-analysis=true \
+// RUN:   -analyzer-config ctu-dir=%t/ctudir \
+// RUN:   -analyzer-config display-ctu-progress=true \
+// RUN:   -fno-signed-char %s
+
+// expected-no-diagnostics
+
+#include "Inputs/v8.h"
Index: clang/test/Analysis/astimport-force-relayout/Inputs/v8.h
===
--- /dev/null
+++ clang/test/Analysis/astimport-force-relayout/Inputs/v8.h
@@ -0,0 +1,28 @@
+#ifndef INCLUDE_V8_H_
+#define INCLUDE_V8_H_
+
+namespace v8 {
+
+class Context;
+class Object;
+class Value;
+
+template 
+class Local {};
+
+class Function {
+ public:
+  Local NewInstance(Local context, int argc,
+Local argv[]) const;
+
+  Local NewInstance(Local context) const {
+return NewInstance(context, 0, nullptr);
+  }
+
+  Local NewInstanceWithSideEffectType(Local context, int argc,
+  Local argv[]) const;
+};
+
+}  // namespace v8
+
+#endif  // INCLUDE_V8_H_
Index: clang/test/Analysis/astimport-force-relayout/Inputs/externalDefMap.txt
===
--- /dev/null
+++ clang/test/Analysis/astimport-force-relayout/Inputs/externalDefMap.txt
@@ -0,0 +1,3 @@
+45:c:@N@v8@S@Deoptimizer@F@output_count_offset#S api.cc.ast
+38:c:@N@v8@S@Deoptimizer@F@input_offset#S api.cc.ast
+101:c:@N@v8@S@Function@F@NewInstance#$@N@v8@S@Local>#$@N@v8@S@Context#I#*$@N@v8@S@Local>#$@N@v8@S@Value#1 api.cc.ast
Index: clang/test/Analysis/astimport-force-relayout/Inputs/api.cc
===
--- /dev/null
+++ clang/test/Analysis/astimport-force-relayout/Inputs/api.cc
@@ -0,0 +1,31 @@
+#include "v8.h"
+
+typedef long int intptr_t;
+
+namespace v8 {
+
+class Deoptimizer {
+public:
+  static int input_offset() {
+return (reinterpret_cast(
+&(reinterpret_cast(16)->input_)) -
+16);
+  }
+
+  static int output_count_offset() {
+return (reinterpret_cast(
+&(reinterpret_cast(16)->output_count_)) -
+16);
+  }
+
+private:
+  int input_;
+  int output_count_;
+};
+
+Local Function::NewInstance(Local context, int argc,
+Local argv[]) const {
+  return NewInstanceWithSideEffectType(context, argc, argv);
+}
+
+} // namespace v8
Index: clang/lib/AST/RecordLayoutBuilder.cpp
===
--- clang/lib/AST/RecordLayoutBuilder.cpp
+++ clang/lib/AST/RecordLayoutBuilder.cpp
@@ -3279,7 +3279,7 @@
 /// specified record (struct/union/class), which indicates its size and field
 /// position information.
 const ASTRecordLayout &
-ASTContext::getASTRecordLayout(const RecordDecl *D) const {
+ASTContext::getASTRecordLayout(const RecordDecl *D, bool NoCache) const {
   // These asserts test different things.  A record has a definition
   // as soon as we begin to parse the definition.  That definition is
   // not a complete definition (which is what isDefinition() tests)
@@ -3298,8 +3298,10 @@
   // Look up this layout, if already laid out, return what we have.
   // Note that we can't save a reference to the entry because this function
   // is recursive.
-  const ASTRecordLayout *Entry = ASTRecordLayouts[D];
-  if (Entry) return *Entry;
+  if (!NoCache) {
+const ASTRecordLayout *Entry = ASTRecordLayouts[D];
+if (Entry) return *Entry;
+  }
 
   const ASTRecordLayout *NewEntry = nullptr;
 
Index: clang/lib/A

[PATCH] D154588: [CSKY] Optimize implementation of intrinsic 'llvm.cttz.i32'

2023-07-08 Thread Ben Shi via Phabricator via cfe-commits
benshi001 updated this revision to Diff 538356.
benshi001 set the repository for this revision to rG LLVM Github Monorepo.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154588

Files:
  clang/test/CodeGen/CSKY/csky-builtins.c
  llvm/lib/Target/CSKY/CSKYISelLowering.cpp
  llvm/lib/Target/CSKY/CSKYInstrInfo.td
  llvm/test/CodeGen/CSKY/intrinsic.ll

Index: llvm/test/CodeGen/CSKY/intrinsic.ll
===
--- llvm/test/CodeGen/CSKY/intrinsic.ll
+++ llvm/test/CodeGen/CSKY/intrinsic.ll
@@ -11,6 +11,17 @@
   ret i32 %nlz
 }
 
+define i32 @cttz(i32 %x) {
+; CHECK-LABEL: cttz:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:brev32 a0, a0
+; CHECK-NEXT:ff1.32 a0, a0
+; CHECK-NEXT:rts16
+entry:
+  %ntz = call i32 @llvm.cttz.i32(i32 %x, i1 1)
+  ret i32 %ntz
+}
+
 define i32 @bswap(i32 %x) {
 ; CHECK-LABEL: bswap:
 ; CHECK:   # %bb.0: # %entry
@@ -21,8 +32,19 @@
   ret i32 %revb32
 }
 
-define i32 @bitreverse(i32 %x) {
-; CHECK-LABEL: bitreverse:
+define i16 @bswap16(i16 %x) {
+; CHECK-LABEL: bswap16:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:revb16 a0, a0
+; CHECK-NEXT:lsri16 a0, a0, 16
+; CHECK-NEXT:rts16
+entry:
+  %revb16 = call i16 @llvm.bswap.i16(i16 %x)
+  ret i16 %revb16
+}
+
+define i32 @bitreverse_32(i32 %x) {
+; CHECK-LABEL: bitreverse_32:
 ; CHECK:   # %bb.0: # %entry
 ; CHECK-NEXT:brev32 a0, a0
 ; CHECK-NEXT:rts16
@@ -31,6 +53,20 @@
   ret i32 %brev32
 }
 
+define i16 @bitreverse_16(i16 %x) {
+; CHECK-LABEL: bitreverse_16:
+; CHECK:   # %bb.0: # %entry
+; CHECK-NEXT:brev32 a0, a0
+; CHECK-NEXT:lsri16 a0, a0, 16
+; CHECK-NEXT:rts16
+entry:
+  %brev = call i16 @llvm.bitreverse.i16(i16 %x)
+  ret i16 %brev
+}
+
 declare i32 @llvm.bswap.i32(i32)
+declare i16 @llvm.bswap.i16(i16)
 declare i32 @llvm.ctlz.i32 (i32, i1)
+declare i32 @llvm.cttz.i32 (i32, i1)
 declare i32 @llvm.bitreverse.i32(i32)
+declare i16 @llvm.bitreverse.i16(i16)
Index: llvm/lib/Target/CSKY/CSKYInstrInfo.td
===
--- llvm/lib/Target/CSKY/CSKYInstrInfo.td
+++ llvm/lib/Target/CSKY/CSKYInstrInfo.td
@@ -1429,6 +1429,7 @@
   let Predicates = [iHas2E3] in {
 def : Pat<(bitreverse GPR:$rx), (BREV32 GPR:$rx)>;
 def : Pat<(bswap GPR:$rx), (REVB32 GPR:$rx)>;
+def : Pat<(i32 (cttz GPR:$rx)), (FF1 (BREV32 GPR:$rx))>;
   }
   def : Pat<(i32 (ctlz GPR:$rx)), (FF1 GPR:$rx)>;
 }
Index: llvm/lib/Target/CSKY/CSKYISelLowering.cpp
===
--- llvm/lib/Target/CSKY/CSKYISelLowering.cpp
+++ llvm/lib/Target/CSKY/CSKYISelLowering.cpp
@@ -59,7 +59,6 @@
   setOperationAction(ISD::UREM, MVT::i32, Expand);
   setOperationAction(ISD::UDIVREM, MVT::i32, Expand);
   setOperationAction(ISD::SDIVREM, MVT::i32, Expand);
-  setOperationAction(ISD::CTTZ, MVT::i32, Expand);
   setOperationAction(ISD::CTPOP, MVT::i32, Expand);
   setOperationAction(ISD::ROTR, MVT::i32, Expand);
   setOperationAction(ISD::SHL_PARTS, MVT::i32, Expand);
@@ -103,6 +102,7 @@
   if (!Subtarget.has2E3()) {
 setOperationAction(ISD::ABS, MVT::i32, Expand);
 setOperationAction(ISD::BITREVERSE, MVT::i32, Expand);
+setOperationAction(ISD::CTTZ, MVT::i32, Expand);
 setOperationAction(ISD::SDIV, MVT::i32, Expand);
 setOperationAction(ISD::UDIV, MVT::i32, Expand);
   }
Index: clang/test/CodeGen/CSKY/csky-builtins.c
===
--- /dev/null
+++ clang/test/CodeGen/CSKY/csky-builtins.c
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -triple csky -emit-llvm -o - %s | FileCheck %s
+
+unsigned char bitrev8(unsigned char data) {
+  // CHECK: define{{.*}} i8 @bitrev8
+  // CHECK: i8 @llvm.bitreverse.i8(i8
+  return __builtin_bitreverse8(data);
+}
+
+unsigned short bitrev16(unsigned short data) {
+  // CHECK: define{{.*}} i16 @bitrev16
+  // CHECK: i16 @llvm.bitreverse.i16(i16
+  return __builtin_bitreverse16(data);
+}
+
+unsigned long bitrev32(unsigned long data) {
+  // CHECK: define{{.*}} i32 @bitrev32
+  // CHECK: i32 @llvm.bitreverse.i32(i32
+  return __builtin_bitreverse32(data);
+}
+
+unsigned long long bitrev64(unsigned long long data) {
+  // CHECK: define{{.*}} i64 @bitrev64
+  // CHECK: i64 @llvm.bitreverse.i64(i64
+  return __builtin_bitreverse64(data);
+}
+
+unsigned char rotleft8(unsigned char x, unsigned char y) {
+  // CHECK: define{{.*}} i8 @rotleft8
+  // CHECK: i8 @llvm.fshl.i8(i8
+  return __builtin_rotateleft8(x, y);
+}
+
+unsigned short rotleft16(unsigned short x, unsigned short y) {
+  // CHECK: define{{.*}} i16 @rotleft16
+  // CHECK: i16 @llvm.fshl.i16(i16
+  return __builtin_rotateleft16(x, y);
+}
+
+unsigned long rotleft32(unsigned long x, unsigned long y) {
+  // CHECK: define{{.*}} i32 @rotleft32
+  // CHECK: i32 @llvm.fshl.i3

[PATCH] D154588: [CSKY] Optimize implementation of intrinsic 'llvm.cttz.i32'

2023-07-08 Thread Ben Shi via Phabricator via cfe-commits
benshi001 added inline comments.



Comment at: clang/test/CodeGen/CSKY/csky-builtins.c:1
+// RUN: %clang_cc1 -triple csky -emit-llvm -o - %s | FileCheck %s
+

This file is pure test, has nothing to do with `llvm.cttz`, just to avoid 
another patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154588

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


[PATCH] D153738: Add LibClang guide

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

LGTM, thank you! Do you need me to commit this on your behalf? If so, what name 
and email address would you like me to use for patch attribution? (I'll build 
the docs locally and correct any remaining formatting mistakes before landing.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153738

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


cfe-commits@lists.llvm.org

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

Author: Aaron Ballman
Date: 2023-07-08T08:30:58-04:00
New Revision: 0566791ab28b5b842c3befea63d7d47fe9ba1a59

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

LOG: Restore TagDecl::printName(raw_ostream &)

Changes in 19e984ef8f49bc3ccced15621989fa9703b2cd5b accidentally hid
the raw_ostream& declaration from NamedDecl, so this brings back access
to that function through a TagDecl.

Added: 


Modified: 
clang/include/clang/AST/Decl.h

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index b9c3bb03c9fb31..788f6ab97b1bbf 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -3725,6 +3725,7 @@ class TagDecl : public TypeDecl,
 return getExtInfo()->TemplParamLists[i];
   }
 
+  using TypeDecl::printName;
   void printName(raw_ostream &OS, const PrintingPolicy &Policy) const override;
 
   void setTemplateParameterListsInfo(ASTContext &Context,



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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

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

In D134813#4482674 , @Hahnfeld wrote:

> Out of curiosity, not sure if it's worth fixing because it's easy enough to 
> work around: I think after this change, it's not possible anymore to call 
> `printName(raw_ostream &OS)` on a (statically typed) `TagDecl` / `EnumDecl` 
> because it's hidden by `TagDecl::printName(raw_ostream &OS, const 
> PrintingPolicy &Policy)` while it works perfectly for a `NamedDecl`. Is this 
> intentional?

That's not intentional, thank you for pointing it out! This should be corrected 
in 0566791ab28b5b842c3befea63d7d47fe9ba1a59 



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D154295: [Driver][MSVC] Support DWARF fission when using LTO on Windows

2023-07-08 Thread Haohai, Wen via Phabricator via cfe-commits
HaohaiWen added a comment.

In D154295#4477203 , @hans wrote:

> In D154295#4477165 , @HaohaiWen 
> wrote:
>
>>> It would be nice to have some documentation for this feature though.
>>
>> This feature is same as Linux -gsplit-dwarf.
>
> Right, but it would be nice to document that clang-cl supports it (which is 
> not obvious since it's mostly trying to be cl.exe compatible).

Do you know which doc file should be updated? I haven't found a doc describe 
-gdwarf for Windows.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154295

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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2023-07-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In D134813#4482808 , @aaron.ballman 
wrote:

> In D134813#4482674 , @Hahnfeld 
> wrote:
>
>> Out of curiosity, not sure if it's worth fixing because it's easy enough to 
>> work around: I think after this change, it's not possible anymore to call 
>> `printName(raw_ostream &OS)` on a (statically typed) `TagDecl` / `EnumDecl` 
>> because it's hidden by `TagDecl::printName(raw_ostream &OS, const 
>> PrintingPolicy &Policy)` while it works perfectly for a `NamedDecl`. Is this 
>> intentional?
>
> That's not intentional, thank you for pointing it out! This should be 
> corrected in 0566791ab28b5b842c3befea63d7d47fe9ba1a59 
> 

Thanks! Note that the same probably holds true (but I didn't test) for all 
other classes that override `printName(raw_ostream &OS, const PrintingPolicy 
&Policy)`, ie `DecompositionDecl`, `MSGuidDecl`, `UnnamedGlobalConstantDecl`, 
and `TemplateParamObjectDecl`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

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

In D134813#4482819 , @Hahnfeld wrote:

> In D134813#4482808 , @aaron.ballman 
> wrote:
>
>> In D134813#4482674 , @Hahnfeld 
>> wrote:
>>
>>> Out of curiosity, not sure if it's worth fixing because it's easy enough to 
>>> work around: I think after this change, it's not possible anymore to call 
>>> `printName(raw_ostream &OS)` on a (statically typed) `TagDecl` / `EnumDecl` 
>>> because it's hidden by `TagDecl::printName(raw_ostream &OS, const 
>>> PrintingPolicy &Policy)` while it works perfectly for a `NamedDecl`. Is 
>>> this intentional?
>>
>> That's not intentional, thank you for pointing it out! This should be 
>> corrected in 0566791ab28b5b842c3befea63d7d47fe9ba1a59 
>> 
>
> Thanks! Note that the same probably holds true (but I didn't test) for all 
> other classes that override `printName(raw_ostream &OS, const PrintingPolicy 
> &Policy)`, ie `DecompositionDecl`, `MSGuidDecl`, `UnnamedGlobalConstantDecl`, 
> and `TemplateParamObjectDecl`.

You're correct, but I figured those are somewhat uncommon AST nodes, so we can 
probably expose those APIs as-needed rather than doing all of them. However, if 
you prefer they all get handled, it's easy enough!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

2023-07-08 Thread Jonas Hahnfeld via Phabricator via cfe-commits
Hahnfeld added a comment.

In D134813#4482822 , @aaron.ballman 
wrote:

> In D134813#4482819 , @Hahnfeld 
> wrote:
>
>> Thanks! Note that the same probably holds true (but I didn't test) for all 
>> other classes that override `printName(raw_ostream &OS, const PrintingPolicy 
>> &Policy)`, ie `DecompositionDecl`, `MSGuidDecl`, 
>> `UnnamedGlobalConstantDecl`, and `TemplateParamObjectDecl`.
>
> You're correct, but I figured those are somewhat uncommon AST nodes, so we 
> can probably expose those APIs as-needed rather than doing all of them.

Oh, alright.

> However, if you prefer they all get handled, it's easy enough!

No, not needed. I was only running into it with an `EnumDecl` while going to 
LLVM 16. But as I said, it's easy enough to work around.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D154130: [lit] Avoid os.path.realpath on Windows due to MAX_PATH limitations

2023-07-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added subscribers: ChuanqiXu, tahonermann, Bigcheese.
aaron.ballman added a comment.

In D154130#4481763 , @MrTrillian 
wrote:

> In D154130#4481673 , @aaron.ballman 
> wrote:
>
>> Adding a few more folks who are interested in lit changes to try to get the 
>> review unstuck.
>>
>> FWIW, I worry about the subtlety of the `>` change because it's not entirely 
>> clear to me when I'd need to use `%>t` in a test. I worry code reviewers 
>> will miss this sort of thing and we'll only find out there's an issue when 
>> the test fails for someone with a problematic path. Is there a rule of thumb 
>> we should be following for its use?
>
> Thanks for the extra reviewers!
>
> 95% of the `%>t` are around clang modulemap files, because that code resolves 
> real paths in C++ by design, so I can't avoid it. In fact I should rename 
> `PREFIX_EXPANDED` to `MODULEMAP_PREFIX` so it would be much clearer.

Okay, if this is mostly specific to module maps, that may resolve most of my 
concern (we don't add a lot of new tests there, so it's less of a burden for 
reviewers). CC @ChuanqiXu @Bigcheese @tahonermann to see if there are modules 
concerns with this.

> There are three cases where I didn't expect to need the expanded paths: 
> `relative_include.m`, `case-insensitive-include-win.c` and 
> `module-header-mismatches.m`. There may be a way to change the clang 
> implementation so it does not need to have expanded paths, but that felt like 
> a different investigation.
>
> I'm happy to consider alternative syntaxes to `%>t` too.

I think the syntax is reasonable enough (at least, I don't have arguably better 
suggestions), it was more just the "how will I know when to use it?" concerns.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154130

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


[PATCH] D134813: Properly print unnamed TagDecl objects in diagnostics

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

In D134813#4482852 , @Hahnfeld wrote:

> In D134813#4482822 , @aaron.ballman 
> wrote:
>
>> In D134813#4482819 , @Hahnfeld 
>> wrote:
>>
>>> Thanks! Note that the same probably holds true (but I didn't test) for all 
>>> other classes that override `printName(raw_ostream &OS, const 
>>> PrintingPolicy &Policy)`, ie `DecompositionDecl`, `MSGuidDecl`, 
>>> `UnnamedGlobalConstantDecl`, and `TemplateParamObjectDecl`.
>>
>> You're correct, but I figured those are somewhat uncommon AST nodes, so we 
>> can probably expose those APIs as-needed rather than doing all of them.
>
> Oh, alright.
>
>> However, if you prefer they all get handled, it's easy enough!
>
> No, not needed. I was only running into it with an `EnumDecl` while going to 
> LLVM 16. But as I said, it's easy enough to work around.

In general, I think we want to encourage callers to use the variant with a 
`PrintingPolicy` so that user-controlled options are properly handled (e.g., 
spelling it `_Bool` instead of `bool` older C modes, that sort of thing), so I 
figure the extra work is a subtle encouragement. :-)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134813

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


[PATCH] D154290: [Clang] Implement P2741R3 - user-generated static_assert messages

2023-07-08 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:3883
+  ///< message.
+CCEK_StaticAssertMessageData, ///< Call to data() in a static assert
+  ///< message.

Appears unused.



Comment at: clang/lib/AST/ExprConstant.cpp:16413
+APSInt C = Char.getInt();
+Result.push_back(static_cast(C.getExtValue()));
+if (!HandleLValueArrayAdjustment(Info, PtrExpression, String, CharTy, 1))

This relies on host's CHAR_BIT >= target's CHAR_BIT, which isn't true for my 
target. Could you add an assertion?




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:16960
+  ExprResult EvaluatedData = BuildConvertedConstantExpression(
+  DataE.get(), ConstCharPtr, CCEK_StaticAssertMessageSize);
+  if (EvaluatedData.isInvalid()) {





Comment at: clang/test/SemaCXX/static-assert-cxx26.cpp:127
+};
+static_assert(false, RAII{}); // expected-error {{static assertion failed: ok}}

Should there be (negative?) tests with non-const data/size members and 
incorrect number of parameters? These conditions are checked in FindMember.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

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


[PATCH] D134544: [clang-cl] Implement /ZH: flag

2023-07-08 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: clang/include/clang/Driver/Options.td:3220
   Values<"simple,mangled">, Flags<[CC1Option, NoDriverOption]>;
+def gsrc_hash_EQ : Joined<["-"], "gsrc-hash=">,
+  Group, Flags<[CC1Option, NoDriverOption]>,

dblaikie wrote:
> This is a driver flag, yeah? Might be worth documenting/emitting a warning 
> that it's not compatible with DWARF emission? (looks like the DWARF code in 
> LLVM ignores any hash that's not MD5, because DWARF doesn't have a way to 
> encode other hash algorithms currently - though maybe there's some extension 
> space available to add it, I haven't checked/looked)
belated: this is `Flags<[CC1Option, NoDriverOption]>,` in the line below, so I 
think this isn't a driver flag. (It's what the CLFlags added below expand to – 
those are driver flags, but only for clang-cl.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134544

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


[PATCH] D154675: [Clang] Fix crash when emitting diagnostic for out of order designated initializers in C++

2023-07-08 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

I can't really see any details on the libcxx failure :-(


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

https://reviews.llvm.org/D154675

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


[PATCH] D154675: [Clang] Fix crash when emitting diagnostic for out of order designated initializers in C++

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



Comment at: clang/test/SemaCXX/cxx2a-initializer-aggregates.cpp:182
+namespace GH63605 {
+struct {
+  unsigned : 2;

cor3ntin wrote:
> Should we add bases?
Good catch b/c of course bases would cause problems 🤣


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

https://reviews.llvm.org/D154675

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


[PATCH] D154290: [Clang] Implement P2741R3 - user-generated static_assert messages

2023-07-08 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

According to the current wording, the static_assert-message is either 
unevaluated string or an expression evaluated at compile time.
Unevaluated strings don't allow certain escape sequences, but if I wrap the 
string in a string_view-like class, I'm allowed to use any escape sequeces, 
including '\x'.
Moreover, wrapping a string in a class would change its encoding. Unevaluated 
strings are displayed as written in the source (that is, UTF-8), while wrapped 
strings undergo conversion to execution encoding (e.g. EBCDIC) and then printed 
in system locale, leading to mojibake.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

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


[clang] 3f370a2 - [test] Add more instantiation cases to visibility.cpp

2023-07-08 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-08T12:30:49-07:00
New Revision: 3f370a2af59f83134cf1de405358506be9280251

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

LOG: [test] Add more instantiation cases to visibility.cpp

Added: 


Modified: 
clang/test/CodeGenCXX/visibility.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/visibility.cpp 
b/clang/test/CodeGenCXX/visibility.cpp
index a55f0061a53056..167a13c3ecb6d7 100644
--- a/clang/test/CodeGenCXX/visibility.cpp
+++ b/clang/test/CodeGenCXX/visibility.cpp
@@ -101,6 +101,28 @@ namespace test48 {
   // CHECK-HIDDEN: _ZN6test481yE = hidden global
 }
 
+namespace test72 {
+  template 
+  struct foo {
+HIDDEN static int var1;
+template  HIDDEN static U var2;
+  };
+  template  template 
+  U foo::var2;
+
+  extern template struct DEFAULT foo;
+
+  int use() {
+foo o;
+foo p;
+return o.var1 + o.var2 + p.var1 + p.var2;
+  }
+  // CHECK:  @_ZN6test723fooIiE4var1E = external hidden global i32
+  // CHECK-NEXT: @_ZN6test723fooIiE4var2IiEE = linkonce_odr global i32 0
+  // CHECK-NEXT: @_ZN6test723fooIlE4var1E = external hidden global i32
+  // CHECK-NEXT: @_ZN6test723fooIlE4var2IiEE = linkonce_odr global i32 0
+}
+
 // CHECK: @_ZN5Test425VariableInHiddenNamespaceE = hidden global i32 10
 // CHECK: @_ZN5Test71aE = hidden global
 // CHECK: @_ZN5Test71bE = global
@@ -953,7 +975,7 @@ namespace test51 {
 
   struct HIDDEN foo {
   };
-  DEFAULT foo x, y;
+  DEFAULT foo x, y, z;
   template
   void DEFAULT zed() {
   }
@@ -964,6 +986,12 @@ namespace test51 {
   template void HIDDEN zed<&y>();
   // CHECK-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1yEvv(
   // CHECK-HIDDEN-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1yEvv(
+
+  void use() {
+zed<&z>();
+  }
+  // CHECK-LABEL: define linkonce_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1zEvv(
+  // CHECK-HIDDEN-LABEL: define linkonce_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1zEvv(
 }
 
 namespace test52 {
@@ -1349,11 +1377,16 @@ namespace test71 {
 
   int use() {
 foo o;
-return o.zed() + o.bar();
+foo p;
+return o.zed() + o.bar() + p.zed() + p.bar();
   }
   /// FIXME: foo::bar is hidden in GCC w/ or w/o -fvisibility=hidden.
   // CHECK-LABEL: declare hidden noundef i32 @_ZN6test713fooIiE3zedEv(
   // CHECK-LABEL: define linkonce_odr noundef i32 
@_ZN6test713fooIiE3barIiEET_v(
+  // CHECK-LABEL: define linkonce_odr hidden noundef i64 
@_ZN6test713fooIlE3zedEv(
+  // CHECK-LABEL: define linkonce_odr noundef i32 
@_ZN6test713fooIlE3barIiEET_v(
   // CHECK-HIDDEN-LABEL: declare hidden noundef i32 @_ZN6test713fooIiE3zedEv(
   // CHECK-HIDDEN-LABEL: define linkonce_odr noundef i32 
@_ZN6test713fooIiE3barIiEET_v(
+  // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i64 
@_ZN6test713fooIlE3zedEv(
+  // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i32 
@_ZN6test713fooIlE3barIiEET_v(
 }



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


[PATCH] D154773: [AST] Use correct APSInt width when evaluating string literals

2023-07-08 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 created this revision.
barannikov88 added a reviewer: cor3ntin.
Herald added a project: All.
barannikov88 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The width of the APSInt values should be the width of an element.
getCharByteWidth returns the size of an element in _host_ bytes, which
makes the width N times greater, where N is the ratio between target's
CHAR_BIT and host's CHAR_BIT.
This is NFC for in-tree targets because all of them have CHAR_BIT == 8.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154773

Files:
  clang/lib/AST/ExprConstant.cpp


Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -3420,8 +3420,7 @@
   assert(CAT && "string literal isn't an array");
   QualType CharType = CAT->getElementType();
   assert(CharType->isIntegerType() && "unexpected character type");
-
-  APSInt Value(S->getCharByteWidth() * Info.Ctx.getCharWidth(),
+  APSInt Value(Info.Ctx.getTypeSize(CharType),
CharType->isUnsignedIntegerType());
   if (Index < S->getLength())
 Value = S->getCodeUnit(Index);
@@ -3444,7 +3443,7 @@
   unsigned Elts = CAT->getSize().getZExtValue();
   Result = APValue(APValue::UninitArray(),
std::min(S->getLength(), Elts), Elts);
-  APSInt Value(S->getCharByteWidth() * Info.Ctx.getCharWidth(),
+  APSInt Value(Info.Ctx.getTypeSize(CharType),
CharType->isUnsignedIntegerType());
   if (Result.hasArrayFiller())
 Result.getArrayFiller() = APValue(Value);


Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -3420,8 +3420,7 @@
   assert(CAT && "string literal isn't an array");
   QualType CharType = CAT->getElementType();
   assert(CharType->isIntegerType() && "unexpected character type");
-
-  APSInt Value(S->getCharByteWidth() * Info.Ctx.getCharWidth(),
+  APSInt Value(Info.Ctx.getTypeSize(CharType),
CharType->isUnsignedIntegerType());
   if (Index < S->getLength())
 Value = S->getCodeUnit(Index);
@@ -3444,7 +3443,7 @@
   unsigned Elts = CAT->getSize().getZExtValue();
   Result = APValue(APValue::UninitArray(),
std::min(S->getLength(), Elts), Elts);
-  APSInt Value(S->getCharByteWidth() * Info.Ctx.getCharWidth(),
+  APSInt Value(Info.Ctx.getTypeSize(CharType),
CharType->isUnsignedIntegerType());
   if (Result.hasArrayFiller())
 Result.getArrayFiller() = APValue(Value);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D154774: [Sema] Respect instantiated-from template's VisibilityAttr for two implicit/explicit instantiation cases

2023-07-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay created this revision.
MaskRay added reviewers: clang, aaron.ballman, efriedma, rjmccall, smeenai.
Herald added a project: All.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In CodeGenCXX/visibility.cpp,

Match GCC for part of test51: Change explicit instantiation of a function
template to respect the instantiated-from template's VisibilityAttr.

Match GCC for test71: For an implicit or explicit instantiation of a class
template, change its member template instantiation to respect the
instantiated-from member template's VisibilityAttr.
Fix https://github.com/llvm/llvm-project/issues/31462


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154774

Files:
  clang/lib/AST/Decl.cpp
  clang/test/CodeGenCXX/visibility.cpp


Index: clang/test/CodeGenCXX/visibility.cpp
===
--- clang/test/CodeGenCXX/visibility.cpp
+++ clang/test/CodeGenCXX/visibility.cpp
@@ -969,10 +969,6 @@
 }
 
 namespace test51 {
-  // Test that we use the visibility of struct foo when instantiating the
-  // template. Note that is a case where we disagree with gcc, it produces
-  // a default symbol.
-
   struct HIDDEN foo {
   };
   DEFAULT foo x, y, z;
@@ -980,8 +976,8 @@
   void DEFAULT zed() {
   }
   template void zed<&x>();
-  // CHECK-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1xEvv
-  // CHECK-HIDDEN-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1xEvv
+  // CHECK-LABEL: define weak_odr void @_ZN6test513zedIXadL_ZNS_1xEvv
+  // CHECK-HIDDEN-LABEL: define weak_odr void 
@_ZN6test513zedIXadL_ZNS_1xEvv
 
   template void HIDDEN zed<&y>();
   // CHECK-LABEL: define weak_odr hidden void 
@_ZN6test513zedIXadL_ZNS_1yEvv(
@@ -1373,6 +1369,7 @@
   template  template 
   U foo::bar() { return {}; }
 
+  /// foo::{zed,bar} get the instantiated-from member's HIDDEN, 
overriding DEFAULT.
   extern template struct DEFAULT foo;
 
   int use() {
@@ -1380,13 +1377,12 @@
 foo p;
 return o.zed() + o.bar() + p.zed() + p.bar();
   }
-  /// FIXME: foo::bar is hidden in GCC w/ or w/o -fvisibility=hidden.
   // CHECK-LABEL: declare hidden noundef i32 @_ZN6test713fooIiE3zedEv(
-  // CHECK-LABEL: define linkonce_odr noundef i32 
@_ZN6test713fooIiE3barIiEET_v(
+  // CHECK-LABEL: define linkonce_odr hidden noundef i32 
@_ZN6test713fooIiE3barIiEET_v(
   // CHECK-LABEL: define linkonce_odr hidden noundef i64 
@_ZN6test713fooIlE3zedEv(
-  // CHECK-LABEL: define linkonce_odr noundef i32 
@_ZN6test713fooIlE3barIiEET_v(
+  // CHECK-LABEL: define linkonce_odr hidden noundef i32 
@_ZN6test713fooIlE3barIiEET_v(
   // CHECK-HIDDEN-LABEL: declare hidden noundef i32 @_ZN6test713fooIiE3zedEv(
-  // CHECK-HIDDEN-LABEL: define linkonce_odr noundef i32 
@_ZN6test713fooIiE3barIiEET_v(
+  // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i32 
@_ZN6test713fooIiE3barIiEET_v(
   // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i64 
@_ZN6test713fooIlE3zedEv(
   // CHECK-HIDDEN-LABEL: define linkonce_odr hidden noundef i32 
@_ZN6test713fooIlE3barIiEET_v(
 }
Index: clang/lib/AST/Decl.cpp
===
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -375,7 +375,9 @@
   if (!specInfo->isExplicitInstantiationOrSpecialization())
 return true;
 
-  return !fn->hasAttr();
+  return !fn->hasAttr() && !specInfo->getTemplate()
+->getTemplatedDecl()
+->hasAttr();
 }
 
 /// Merge in template-related linkage and visibility for the given
@@ -1240,12 +1242,20 @@
   }
   // Also handle function template specializations.
   if (const auto *fn = dyn_cast(ND)) {
-// If the function is a specialization of a template with an
-// explicit visibility attribute, use that.
-if (FunctionTemplateSpecializationInfo *templateInfo
-  = fn->getTemplateSpecializationInfo())
-  return getVisibilityOf(templateInfo->getTemplate()->getTemplatedDecl(),
- kind);
+// If the function is a specialization of a template,
+if (FunctionTemplateSpecializationInfo *templateInfo =
+fn->getTemplateSpecializationInfo()) {
+  // ... If the template has an explicit visibility attribute, use that.
+  if (auto Vis = getVisibilityOf(
+  templateInfo->getTemplate()->getTemplatedDecl(), kind))
+return Vis;
+  // ... If the template instantiates from a member template with an
+  // explicit visibility attribute, use that.
+  if (auto *A =
+  templateInfo->getTemplate()->getInstantiatedFromMemberTemplate())
+return getVisibilityOf(A->getTemplatedDecl(), kind);
+  return std::nullopt;
+}
 
 // If the function is a member of a specialization of a class template
 // and the corresponding decl has explicit visibil

[PATCH] D153835: [Sema] Clone VisibilityAttr for functions in template instantiations

2023-07-08 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D153835#4481816 , @rjmccall wrote:

> I agree that the change to test51 is the right result, yes.  The explicit 
> visibility attribute on the template declaration should take precedence over 
> the visibility of the types in the template parameter list, and then the 
> explicit visibility attribute on the variables should take precedence over 
> the visibility of the variable types, and then the instantiation should be a 
> specialization of a default-visibility template with default-visibility 
> arguments.  But I think that logic ought to be fixed in `getLVFor...`, not by 
> changing the basic propagation of attributes.
>
>> I actually think that the patch makes VisibilityAttr behave in a more normal 
>> way as the majority of attributes are cloned by instantiateTemplateAttribute 
>> in the tablegen-generated 
>> tools/clang/include/clang/Sema/AttrTemplateInstantiate.inc.
>
> You're not really just cloning it, because making the cloned attribute 
> implicit (i.e. giving it the effect of a visibility pragma instead of an 
> attribute) is a huge difference.

OK, created D154774  as an alternative. I 
added more cases to test51 and test71. D154774 
 will change the tests in the same way that 
this VisibilityAttr cloning patch changes the tests.

I did not know that implicit VisibilityAttr is for `#pragma GCC visibility 
push(...)`. I agree that reusing `IsImplicit` for an instantiated 
`FunctionTemplateDecl/CXXMethodDecl` has unclear interaction.

However, I am not fully convinced that avoiding cloning `VisibilityAttr` is the 
most clean way forward. That said, since D154774 
 will have the same effect as far as 
`CodeGenCXX/visibility.cpp` is concerned, I am fine not pursing this patch 
forward.
I wonder whether using another bit that is not `IsImplicit` will be better.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153835

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


[PATCH] D151761: clang-format: Add AlignConsecutiveShortCaseStatements

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

Thanks for the patience, I'm really looking forward to use this.

But please wait for other opinions.


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

https://reviews.llvm.org/D151761

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


[PATCH] D154290: [Clang] Implement P2741R3 - user-generated static_assert messages

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

In D154290#4482975 , @barannikov88 
wrote:

> According to the current wording, the static_assert-message is either 
> unevaluated string or an expression evaluated at compile time.
> Unevaluated strings don't allow certain escape sequences, but if I wrap the 
> string in a string_view-like class, I'm allowed to use any escape sequeces, 
> including '\x'.
> Moreover, wrapping a string in a class would change its encoding. Unevaluated 
> strings are displayed as written in the source (that is, UTF-8), while 
> wrapped strings undergo conversion to execution encoding (e.g. EBCDIC) and 
> then printed in system locale, leading to mojibake.

Not quite.
Unevaluated strings are always UTF-8 ( regardless of source file encoding). 
Evaluated strings are in the literal encoding which is always UTF-8 for clang. 
This will change whenever we allow for different kinds of literal encodings per 
 this RFC 
https://discourse.llvm.org/t/rfc-enabling-fexec-charset-support-to-llvm-and-clang-reposting/71512/1

If and when that is the case we will have to convert back to UTF-8 before 
displaying - and then maybe convert back to the system locale depending on host.
Numeric escape sequences can then occur in evaluated strings and produce 
mojibake if the evaluated strings is not valid in the string literal encoding.
I don't believe that we would want to output static messages without conversion 
on any system as the diagnostics framework is very much geared towards UTF-8 
and we want to keep supporting cross compilation.

So the process will be
source -> utf8 -> literal encoding -> utf8 -> terminal encoding.

By the same account, casting 0-extended utf-8 to char is fine until such time 
clang support more than UTF-8. (which is one of the reasons we need to make 
sure clang conversions utilities can convert from and to utf-8)

Unevaluated strings were introduced in part to help identify what gets 
converted and what does not.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

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


[PATCH] D149236: [clangd] Bail gracefully if given an assembly or IR source file

2023-07-08 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Review ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149236

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


[PATCH] D154471: [clang] Add serialization support for the DynamicAllocLValue variant of APValue::LValueBase::Ptr

2023-07-08 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
Herald added a project: All.
nridge updated this revision to Diff 537970.
nridge added a comment.
nridge edited the summary of this revision.
Herald added a subscriber: kadircet.
nridge published this revision for review.
Herald added subscribers: cfe-commits, ilya-biryukov.
Herald added a project: clang.

Add missing check for isDynamicAlloc


nridge added a comment.

Requesting review.

The patch does not include an automated test because this is fixing a bug 
report with no test case (I spotted the issue by inspection based on the stack 
trace). The bug reporter did try the patch locally and confirm that it fixes 
the crash on their codebase.


Fixes https://github.com/clangd/clangd/issues/1672


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154471

Files:
  clang/include/clang/AST/PropertiesBase.td


Index: clang/include/clang/AST/PropertiesBase.td
===
--- clang/include/clang/AST/PropertiesBase.td
+++ clang/include/clang/AST/PropertiesBase.td
@@ -450,10 +450,13 @@
 lvalueBase ? lvalueBase.dyn_cast() : nullptr;
 bool lvalueBaseIsExpr = (bool) expr;
 bool lvalueBaseIsTypeInfo = lvalueBase.is();
+bool lvalueBaseIsDynamicAlloc = lvalueBase.is();
 QualType elemTy;
 if (lvalueBase) {
   if (lvalueBaseIsTypeInfo) {
 elemTy = lvalueBase.getTypeInfoType();
+  } else if (lvalueBaseIsDynamicAlloc) {
+elemTy = lvalueBase.getDynamicAllocType();
   } else if (lvalueBaseIsExpr) {
 elemTy = expr->getType();
   } else {
@@ -473,6 +476,9 @@
   def : Property<"isTypeInfo", Bool> {
 let Read = [{ lvalueBaseIsTypeInfo }];
   }
+  def : Property<"isDynamicAlloc", Bool> {
+let Read = [{ lvalueBaseIsDynamicAlloc }];
+  }
   def : Property<"hasBase", Bool> {
 let Read = [{ static_cast(lvalueBase) }];
   }
@@ -485,9 +491,17 @@
   QualType(node.getLValueBase().get().getType(), 0)
 }];
   }
+  def : Property<"dynamicAlloc", UInt32> {
+let Conditional = [{ hasBase && isDynamicAlloc }];
+let Read = [{ node.getLValueBase().get().getIndex() }];
+  }
   def : Property<"type", QualType> {
-let Conditional = [{ hasBase && isTypeInfo }];
-let Read = [{ node.getLValueBase().getTypeInfoType() }];
+let Conditional = [{ hasBase && (isTypeInfo || isDynamicAlloc) }];
+let Read = [{ 
+  isTypeInfo
+? node.getLValueBase().getTypeInfoType()
+: node.getLValueBase().getDynamicAllocType()
+}];
   }
   def : Property<"callIndex", UInt32> {
 let Conditional = [{ hasBase && !isTypeInfo }];
@@ -502,7 +516,7 @@
 let Read = [{ const_cast(expr) }];
   }
   def : Property<"decl", DeclRef> {
-let Conditional = [{ hasBase && !isTypeInfo && !isExpr }];
+let Conditional = [{ hasBase && !isTypeInfo && !isDynamicAlloc && !isExpr 
}];
 let Read = [{ lvalueBase.get() }];
   }
   def : Property<"offsetQuantity", UInt32> {
@@ -521,6 +535,9 @@
   if (isTypeInfo) {
 base = APValue::LValueBase::getTypeInfo(
 TypeInfoLValue(typeInfo->getTypePtr()), *type);
+  } else if (isDynamicAlloc) {
+base = APValue::LValueBase::getDynamicAlloc(
+DynamicAllocLValue(*dynamicAlloc), *type);
   } else if (isExpr) {
 base = APValue::LValueBase(cast(*stmt),
*callIndex, *version);


Index: clang/include/clang/AST/PropertiesBase.td
===
--- clang/include/clang/AST/PropertiesBase.td
+++ clang/include/clang/AST/PropertiesBase.td
@@ -450,10 +450,13 @@
 lvalueBase ? lvalueBase.dyn_cast() : nullptr;
 bool lvalueBaseIsExpr = (bool) expr;
 bool lvalueBaseIsTypeInfo = lvalueBase.is();
+bool lvalueBaseIsDynamicAlloc = lvalueBase.is();
 QualType elemTy;
 if (lvalueBase) {
   if (lvalueBaseIsTypeInfo) {
 elemTy = lvalueBase.getTypeInfoType();
+  } else if (lvalueBaseIsDynamicAlloc) {
+elemTy = lvalueBase.getDynamicAllocType();
   } else if (lvalueBaseIsExpr) {
 elemTy = expr->getType();
   } else {
@@ -473,6 +476,9 @@
   def : Property<"isTypeInfo", Bool> {
 let Read = [{ lvalueBaseIsTypeInfo }];
   }
+  def : Property<"isDynamicAlloc", Bool> {
+let Read = [{ lvalueBaseIsDynamicAlloc }];
+  }
   def : Property<"hasBase", Bool> {
 let Read = [{ static_cast(lvalueBase) }];
   }
@@ -485,9 +491,17 @@
   QualType(node.getLValueBase().get().getType(), 0)
 }];
   }
+  def : Property<"dynamicAlloc", UInt32> {
+let Conditional = [{ hasBase && isDynamicAlloc }];
+let Read = [{ node.getLValueBase().get().getIndex() }];
+  }
   def : Property<"type", QualType> {
-let Conditional = [{ hasBase && isTypeInfo }];
-let Read = [{ node.getLValueBase().getTypeInfoType() }];
+let Conditional = [{ hasBase && (isTypeInfo || isDynamicAlloc) }];
+let Read = [{ 
+  isTypeInfo
+? node.g

[PATCH] D154778: [clang] Fix __is_trivially_equality_comparable for classes which contain arrays of non-trivially equality comparable types

2023-07-08 Thread Nikolas Klauser via Phabricator via cfe-commits
philnik created this revision.
philnik added reviewers: aaron.ballman, cor3ntin, erichkeane.
Herald added a project: All.
philnik requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes #63656


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154778

Files:
  clang/lib/AST/Type.cpp
  clang/test/SemaCXX/type-traits.cpp


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -3141,6 +3141,13 @@
 };
 
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsArray));
 
+struct TriviallyEqualityComparableContainsMultiDimensionArray {
+  int a[4][4];
+
+  bool operator==(const 
TriviallyEqualityComparableContainsMultiDimensionArray&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const 
TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();
@@ -3277,6 +3284,20 @@
 };
 
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasEnum));
 
+struct NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs {
+  E e[1];
+
+  bool operator==(const 
NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs));
+
+struct NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2 {
+  E e[1][1];
+
+  bool operator==(const 
NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2&) const = 
default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2));
+
 namespace hidden_friend {
 
 struct TriviallyEqualityComparable {
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2672,6 +2672,9 @@
   }) &&
  llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
auto Type = FD->getType();
+   if (Type->isArrayType())
+Type = 
Type->getBaseElementTypeUnsafe()->getCanonicalTypeUnqualified();
+
if (Type->isReferenceType() || Type->isEnumeralType())
  return false;
if (const auto *RD = Type->getAsCXXRecordDecl())


Index: clang/test/SemaCXX/type-traits.cpp
===
--- clang/test/SemaCXX/type-traits.cpp
+++ clang/test/SemaCXX/type-traits.cpp
@@ -3141,6 +3141,13 @@
 };
 static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsArray));
 
+struct TriviallyEqualityComparableContainsMultiDimensionArray {
+  int a[4][4];
+
+  bool operator==(const TriviallyEqualityComparableContainsMultiDimensionArray&) const = default;
+};
+static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray));
+
 struct TriviallyEqualityComparableNonTriviallyCopyable {
   TriviallyEqualityComparableNonTriviallyCopyable(const TriviallyEqualityComparableNonTriviallyCopyable&);
   ~TriviallyEqualityComparableNonTriviallyCopyable();
@@ -3277,6 +3284,20 @@
 };
 static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasEnum));
 
+struct NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs {
+  E e[1];
+
+  bool operator==(const NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs));
+
+struct NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2 {
+  E e[1][1];
+
+  bool operator==(const NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2&) const = default;
+};
+static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2));
+
 namespace hidden_friend {
 
 struct TriviallyEqualityComparable {
Index: clang/lib/AST/Type.cpp
===
--- clang/lib/AST/Type.cpp
+++ clang/lib/AST/Type.cpp
@@ -2672,6 +2672,9 @@
   }) &&
  llvm::all_of(Decl->fields(), [](const FieldDecl *FD) {
auto Type = FD->getType();
+   if (Type->isArrayType())
+Type = Type->getBaseElementTypeUnsafe()->getCanonicalTypeUnqualified();
+
if (Type->isReferenceType() || Type->isEnumeralType())
  return false;
if (const auto *RD = Type->getAsCXXRecordDecl())
___
cfe-commits mailing list
cfe-commits@l

[PATCH] D154290: [Clang] Implement P2741R3 - user-generated static_assert messages

2023-07-08 Thread Sergei Barannikov via Phabricator via cfe-commits
barannikov88 added a comment.

In D154290#4483055 , @cor3ntin wrote:

> In D154290#4482975 , @barannikov88 
> wrote:
>
>> According to the current wording, the static_assert-message is either 
>> unevaluated string or an expression evaluated at compile time.
>> Unevaluated strings don't allow certain escape sequences, but if I wrap the 
>> string in a string_view-like class, I'm allowed to use any escape sequeces, 
>> including '\x'.
>> Moreover, wrapping a string in a class would change its encoding. 
>> Unevaluated strings are displayed as written in the source (that is, UTF-8), 
>> while wrapped strings undergo conversion to execution encoding (e.g. EBCDIC) 
>> and then printed in system locale, leading to mojibake.
>
> Not quite.
> Unevaluated strings are always UTF-8 ( regardless of source file encoding). 
> Evaluated strings are in the literal encoding which is always UTF-8 for 
> clang. 
> This will change whenever we allow for different kinds of literal encodings 
> per  this RFC 
> https://discourse.llvm.org/t/rfc-enabling-fexec-charset-support-to-llvm-and-clang-reposting/71512/1
>
> If and when that is the case we will have to convert back to UTF-8 before 
> displaying - and then maybe convert back to the system locale depending on 
> host.
> Numeric escape sequences can then occur in evaluated strings and produce 
> mojibake if the evaluated strings is not valid in the string literal encoding.
> I don't believe that we would want to output static messages without 
> conversion on any system as the diagnostics framework is very much geared 
> towards UTF-8 and we want to keep supporting cross compilation.
>
> So the process will be
> source -> utf8 -> literal encoding -> utf8 -> terminal encoding.

Thanks for your reply, I think I see the idea.

> By the same account, casting 0-extended utf-8 to char is fine until such time 
> clang support more than UTF-8. (which is one of the reasons we need to make 
> sure clang conversions utilities can convert from and to utf-8)
>
> Unevaluated strings were introduced in part to help identify what gets 
> converted and what does not.

It is a bit strange that the string in `static_assert(false, "й")` is not 
converted, while it is converted in `static_assert(false, 
std::string_view("й"))`.
It might be possible to achieve identical diagnostic output even with 
-fexec-charset supported (which would only affect the second form),
but right now I'm confused by the distinction… Why don't always evaluate the 
message?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154290

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


[clang] cfbe86c - Remove getInternalLinkageFor

2023-07-08 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-07-08T17:26:36-07:00
New Revision: cfbe86cc28310be0c95a645cde7443cf6625ce1a

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

LOG: Remove getInternalLinkageFor

Commit 1283e9868d2c1cbf31a834bb5151af6d046c1cb3 added getInternalLinkageFor for
ModuleInternalLinkage used by -fmodules-ts. Now that -fmodules-ts is removed, we
can simplify the call sites to use LinkageInfo::internal().

Added: 


Modified: 
clang/lib/AST/Decl.cpp

Removed: 




diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index d19616d4368524..6e88bf8df5c540 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -606,10 +606,6 @@ static bool isDeclaredInModuleInterfaceOrPartition(const 
NamedDecl *D) {
   return false;
 }
 
-static LinkageInfo getInternalLinkageFor(const NamedDecl *D) {
-  return LinkageInfo::internal();
-}
-
 static LinkageInfo getExternalLinkageFor(const NamedDecl *D) {
   return LinkageInfo::external();
 }
@@ -642,7 +638,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl 
*D,
 // - a variable, variable template, function, or function template
 //   that is explicitly declared static; or
 // (This bullet corresponds to C99 6.2.2p3.)
-return getInternalLinkageFor(D);
+return LinkageInfo::internal();
   }
 
   if (const auto *Var = dyn_cast(D)) {
@@ -666,7 +662,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl 
*D,
   if (Var->getStorageClass() != SC_Extern &&
   Var->getStorageClass() != SC_PrivateExtern &&
   !isSingleLineLanguageLinkage(*Var))
-return getInternalLinkageFor(Var);
+return LinkageInfo::internal();
 }
 
 for (const VarDecl *PrevVar = Var->getPreviousDecl(); PrevVar;
@@ -676,7 +672,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl 
*D,
 return getDeclLinkageAndVisibility(PrevVar);
   // Explicitly declared static.
   if (PrevVar->getStorageClass() == SC_Static)
-return getInternalLinkageFor(Var);
+return LinkageInfo::internal();
 }
   } else if (const auto *IFD = dyn_cast(D)) {
 //   - a data member of an anonymous union.
@@ -700,7 +696,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl 
*D,
 //   within an unnamed namespace has internal linkage.
 if ((!Var || !isFirstInExternCContext(Var)) &&
 (!Func || !isFirstInExternCContext(Func)))
-  return getInternalLinkageFor(D);
+  return LinkageInfo::internal();
   }
 
   // Set up the defaults.
@@ -1312,11 +1308,11 @@ LinkageInfo LinkageComputer::getLVForLocalDecl(const 
NamedDecl *D,
   if (const auto *Function = dyn_cast(D)) {
 if (Function->isInAnonymousNamespace() &&
 !isFirstInExternCContext(Function))
-  return getInternalLinkageFor(Function);
+  return LinkageInfo::internal();
 
 // This is a "void f();" which got merged with a file static.
 if (Function->getCanonicalDecl()->getStorageClass() == SC_Static)
-  return getInternalLinkageFor(Function);
+  return LinkageInfo::internal();
 
 LinkageInfo LV;
 if (!hasExplicitVisibilityAlready(computation)) {
@@ -1335,7 +1331,7 @@ LinkageInfo LinkageComputer::getLVForLocalDecl(const 
NamedDecl *D,
   if (const auto *Var = dyn_cast(D)) {
 if (Var->hasExternalStorage()) {
   if (Var->isInAnonymousNamespace() && !isFirstInExternCContext(Var))
-return getInternalLinkageFor(Var);
+return LinkageInfo::internal();
 
   LinkageInfo LV;
   if (Var->getStorageClass() == SC_PrivateExtern)
@@ -1415,7 +1411,7 @@ LinkageInfo LinkageComputer::computeLVForDecl(const 
NamedDecl *D,
   bool IgnoreVarTypeLinkage) {
   // Internal_linkage attribute overrides other considerations.
   if (D->hasAttr())
-return getInternalLinkageFor(D);
+return LinkageInfo::internal();
 
   // Objective-C: treat all Objective-C declarations as having external
   // linkage.
@@ -1473,7 +1469,7 @@ LinkageInfo LinkageComputer::computeLVForDecl(const 
NamedDecl *D,
 if (Record->hasKnownLambdaInternalLinkage() ||
 !Record->getLambdaManglingNumber()) {
   // This lambda has no mangling number, so it's internal.
-  return getInternalLinkageFor(D);
+  return LinkageInfo::internal();
 }
 
 return getLVForClosure(
@@ -1532,7 +1528,7 @@ LinkageInfo LinkageComputer::getLVForDecl(const NamedDecl 
*D,
   LVComputationKind computation) {
   // Internal_linkage attribute overrides other considerations.
   if (D->hasAttr())
-return getInternalLinkageFor(D);
+return LinkageInfo::internal();
 
   if (computation.IgnoreAllVisibility && D->hasCachedLinkage())
 return Linkag

[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-08 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D153536#4479275 , 
@hubert.reinterpretcast wrote:

> It seems the class member case trips up debuggers.

If `llvm-dwarfdump` is to be believed, it looks like a compiler bug (two 
members reported at the same offset).

  0x00a3:   DW_TAG_member [4]   (0x009d)
  DW_AT_name [DW_FORM_string] ("_")
  DW_AT_type [DW_FORM_ref4]   (cu + 0x00de => {0x00de} 
"int")
  DW_AT_decl_file [DW_FORM_data1] 
("/terrannew/hstong/.Lpcoral03/llvmbld/placeholderDbg.cc")
  DW_AT_decl_line [DW_FORM_data1] (2)
  DW_AT_data_member_location [DW_FORM_data1]  (0x00)
  
  0x00ad:   DW_TAG_member [4]   (0x009d)
  DW_AT_name [DW_FORM_string] ("_")
  DW_AT_type [DW_FORM_ref4]   (cu + 0x00de => {0x00de} 
"int")
  DW_AT_decl_file [DW_FORM_data1] 
("/terrannew/hstong/.Lpcoral03/llvmbld/placeholderDbg.cc")
  DW_AT_decl_line [DW_FORM_data1] (2)
  DW_AT_data_member_location [DW_FORM_data1]  (0x00)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-08 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added inline comments.



Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:46
+int arr[2] = {0, 1};
+static auto [_, _] = arr; // expected-error {{redefinition of '_'}} \
+// expected-note  {{previous definition is here}}

Just noting: This case is allowed by the wording, and I suspect it requires 
extended discussion.




Comment at: clang/test/SemaCXX/cxx2c-placeholder-vars.cpp:2
+// RUN: %clang -cc1 -fsyntax-only -verify -std=c++2c -Wunused-parameter 
-Wunused %s
+
+void static_var() {

hubert.reinterpretcast wrote:
> hubert.reinterpretcast wrote:
> > cor3ntin wrote:
> > > cor3ntin wrote:
> > > > cor3ntin wrote:
> > > > > hubert.reinterpretcast wrote:
> > > > > > hubert.reinterpretcast wrote:
> > > > > > > hubert.reinterpretcast wrote:
> > > > > > > > hubert.reinterpretcast wrote:
> > > > > > > > > Can we have tests for:
> > > > > > > > > ```
> > > > > > > > > struct { int _, _; } a = { ._ = 0 };
> > > > > > > > > ```
> > > > > > > > > 
> > > > > > > > > and
> > > > > > > > > 
> > > > > > > > > ```
> > > > > > > > > struct A {
> > > > > > > > >   A();
> > > > > > > > >   int _, _;
> > > > > > > > > };
> > > > > > > > > 
> > > > > > > > > A::A() : _(0) {}
> > > > > > > > > ```
> > > > > > > > Codegen test for
> > > > > > > > ```
> > > > > > > > static union { int _ = 42; };
> > > > > > > > int &ref = _;
> > > > > > > > int foo() { return 13; }
> > > > > > > > static union { int _ = foo(); };
> > > > > > > > int main(void) { return ref; }
> > > > > > > > ```
> > > > > > > > might be interesting.
> > > > > > > > 
> > > > > > > > I suspect that this case was missed in the committee discussion 
> > > > > > > > of the paper @cor3ntin.
> > > > > > > Less controversial tests to consider:
> > > > > > > ```
> > > > > > > struct A {
> > > > > > >   int _;
> > > > > > >   union { int _; };
> > > > > > > };
> > > > > > > struct B { union { int _, _; }; };
> > > > > > > ```
> > > > > > > 
> > > > > > In a similar vein, a codegen test for:
> > > > > > ```
> > > > > > struct A { A(); };
> > > > > > inline void f [[gnu::used]]() {
> > > > > >   static union { A _{}; };
> > > > > >   static union { A _{}; };
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > Perhaps not intended to be allowed though (premise was no symbols 
> > > > > > with "linkage"?)
> > > > > What's interesting about 
> > > > > 
> > > > > ```
> > > > > static union { int _ = 42; };
> > > > > int &ref = _;
> > > > > int foo() { return 13; }
> > > > > static union { int _ = foo(); };
> > > > > int main(void) { return ref; }
> > > > > ```
> > > > > ?
> > > > > It's already supported by clang https://godbolt.org/z/6j89EdnEo
> > > > > 
> > > > > 
> > > > > I'm adding the other tests (and fixing the associated bugs, of which 
> > > > > there were a few...)
> > > > > 
> > > > > Perhaps not intended to be allowed though (premise was no symbols 
> > > > > with "linkage"?)
> > > > 
> > > > 
> > > > Yes, this should be ill-formed, anything where we would have to mangle  
> > > > multiple `_` should be ill-formed.
> > > > I do believe that's covered though, `_` does not have storage duration.
> > > > What's interesting about 
> > > > 
> > > > ```
> > > > static union { int _ = 42; };
> > > > int &ref = _;
> > > > int foo() { return 13; }
> > > > static union { int _ = foo(); };
> > > > int main(void) { return ref; }
> > > > ```
> > > > ?
> > > > It's already supported by clang https://godbolt.org/z/6j89EdnEo
> > > > 
> > > > 
> > > > I'm adding the other tests (and fixing the associated bugs, of which 
> > > > there were a few...)
> > > > 
> > > 
> > > I see it now. Thanks, I hate it. There is apparently a preexisting bug.
> > > And yes, i think we should say something about members of anonymous union 
> > > declared at namespace scope in the standard I realize now this is 
> > > missing
> > > Thanks for catching that.
> > > Thanks for catching that.
> > 
> > Glad to be of help!
> > I do believe that's covered though, `_` does not have storage duration.
> 
> It's not covered by the wording: `_` //is// a non-static data member.
> 
> 
@cor3ntin, it seems the designated initializer case has not been added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D153536: [Clang] Implement P2169 A nice placeholder with no name

2023-07-08 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

In D153536#4483182 , 
@hubert.reinterpretcast wrote:

> If `llvm-dwarfdump` is to be believed, it looks like a compiler bug (two 
> members reported at the same offset).

Similarly, only one local variable out of two in the same line reported:

  $ cat placeholderDbg2.cc
  extern "C" int printf(const char *, ...);
  struct A {
A(int x) : x(x) { }
~A() { printf("%d\n", x); }
int x;
  };
  int main() {
A _ = 0, _ = 1;
return 0;
  }
  Return:  0x00:0   Sat Jul  8 23:52:46 2023 EDT



  (lldb) target create "a.out"
  Current executable set to '/terrannew/hstong/.Lpcoral03/llvmbld/a.out' 
(powerpc64le).
  (lldb) b 9
  Breakpoint 1: where = a.out`main + 68 at placeholderDbg2.cc:9:3, address = 
0x00010ab4
  (lldb) r
  Process 2951717 launched: '/terrannew/hstong/.Lpcoral03/llvmbld/a.out' 
(powerpc64le)
  Process 2951717 stopped
  * thread #1, name = 'a.out', stop reason = breakpoint 1.1
  frame #0: 0x000100010ab4 a.out`main at placeholderDbg2.cc:9:3
 6};
 7int main() {
 8  A _ = 0, _ = 1;
  -> 9  return 0;
 10   }
  (lldb) var
  (A) _ = (x = 0)
  (lldb) c
  Process 2951717 resuming
  1
  0
  Process 2951717 exited with status = 0 (0x)
  (lldb) q



  0x009b:   DW_TAG_subprogram [14] * (0x000b)
  DW_AT_low_pc [DW_FORM_addr] (0x00010a70)
  DW_AT_high_pc [DW_FORM_data4]   (0x00b4)
  DW_AT_frame_base [DW_FORM_exprloc]  (DW_OP_reg31 X31)
  DW_AT_name [DW_FORM_strp]   ( .debug_str[0x0086] = 
"main")
  DW_AT_decl_file [DW_FORM_data1] 
("/terrannew/hstong/.Lpcoral03/llvmbld/placeholderDbg2.cc")
  DW_AT_decl_line [DW_FORM_data1] (7)
  DW_AT_type [DW_FORM_ref4]   (cu + 0x008f => {0x008f} 
"int")
  DW_AT_external [DW_FORM_flag_present]   (true)
  
  0x00b4: DW_TAG_variable [15]   (0x009b)
DW_AT_location [DW_FORM_exprloc]  (DW_OP_fbreg +128)
DW_AT_name [DW_FORM_strp] ( .debug_str[0x008b] = 
"_")
DW_AT_decl_file [DW_FORM_data1]   
("/terrannew/hstong/.Lpcoral03/llvmbld/placeholderDbg2.cc")
DW_AT_decl_line [DW_FORM_data1]   (8)
DW_AT_type [DW_FORM_ref4] (cu + 0x005a => {0x005a} 
"A")
  
  0x00c3: NULL


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D153536

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


[PATCH] D154664: [NFC] Add some missing header includes

2023-07-08 Thread Evan Wilde via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0f9f95146a7f: [NFC] Add optional include to Format.h 
(authored by etcwilde).

Changed prior to commit:
  https://reviews.llvm.org/D154664?vs=537916&id=538401#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D154664

Files:
  llvm/include/llvm/Support/Format.h


Index: llvm/include/llvm/Support/Format.h
===
--- llvm/include/llvm/Support/Format.h
+++ llvm/include/llvm/Support/Format.h
@@ -28,6 +28,7 @@
 #include "llvm/Support/DataTypes.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 


Index: llvm/include/llvm/Support/Format.h
===
--- llvm/include/llvm/Support/Format.h
+++ llvm/include/llvm/Support/Format.h
@@ -28,6 +28,7 @@
 #include "llvm/Support/DataTypes.h"
 #include 
 #include 
+#include 
 #include 
 #include 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits