[PATCH] D149119: [CMake] Use LLVM own tools in extract_symbols.py

2023-05-08 Thread Igor Kudrin via Phabricator via cfe-commits
ikudrin updated this revision to Diff 520277.
ikudrin retitled this revision from "[CMake] Use llvm-nm to extract symbols for 
staged LTO builds on Windows" to "[CMake] Use LLVM own tools in 
extract_symbols.py".
ikudrin edited the summary of this revision.
ikudrin added reviewers: chandlerc, beanz, rnk, stevewan, 
hubert.reinterpretcast, DavidSpickett.
ikudrin added a comment.
Herald added a subscriber: MaskRay.
Herald added a reviewer: jhenderson.

- Reworked the patch to always use `llvm-nm` to extract symbols and 
`llvm-readobj` to detect targeting 32-bit Windows.


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

https://reviews.llvm.org/D149119

Files:
  llvm/CMakeLists.txt
  llvm/cmake/modules/AddLLVM.cmake
  llvm/cmake/modules/CrossCompile.cmake
  llvm/tools/llvm-nm/CMakeLists.txt
  llvm/tools/llvm-readobj/CMakeLists.txt
  llvm/tools/llvm-shlib/CMakeLists.txt
  llvm/utils/extract_symbols.py

Index: llvm/utils/extract_symbols.py
===
--- llvm/utils/extract_symbols.py
+++ llvm/utils/extract_symbols.py
@@ -23,30 +23,20 @@
 import multiprocessing
 import argparse
 
-# Define functions which extract a list of pairs of (symbols, is_def) from a
-# library using several different tools. We use subprocess.Popen and yield a
-# symbol at a time instead of using subprocess.check_output and returning a list
-# as, especially on Windows, waiting for the entire output to be ready can take
-# a significant amount of time.
-
-def dumpbin_get_symbols(lib):
-process = subprocess.Popen(['dumpbin','/symbols',lib], bufsize=1,
-   stdout=subprocess.PIPE, stdin=subprocess.PIPE,
-   universal_newlines=True)
-process.stdin.close()
-for line in process.stdout:
-# Look for external symbols
-match = re.match("^.+(SECT|UNDEF).+External\s+\|\s+(\S+).*$", line)
-if match:
-yield (match.group(2), match.group(1) != "UNDEF")
-process.wait()
-
-def nm_get_symbols(lib):
-# -P means the output is in portable format, and -g means we only get global
-# symbols.
-cmd = ['nm','-P','-g']
-if sys.platform.startswith('aix'):
-cmd += ['-Xany','-C','-p']
+# Define a function which extracts a list of pairs of (symbols, is_def) from a
+# library using llvm-nm becuase it can work both with regular and bitcode files.
+# We use subprocess.Popen and yield a symbol at a time instead of using
+# subprocess.check_output and returning a list as, especially on Windows, waiting
+# for the entire output to be ready can take a significant amount of time.
+def nm_get_symbols(tool, lib):
+# '-P' means the output is in portable format,
+# '-g' means we only get global symbols,
+# '-Xany' enforce handling both 32- and 64-bit objects on AIX,
+# '--no-demangle' ensure that C++ symbol names are not demangled; note
+#   that llvm-nm do not demangle by default, but the system nm on AIX does
+#   that, so the behavior may change in the future,
+# '-p' do not waste time sorting the symbols.
+cmd = [tool,'-P','-g','-Xany','--no-demangle','-p']
 process = subprocess.Popen(cmd+[lib], bufsize=1,
stdout=subprocess.PIPE, stdin=subprocess.PIPE,
universal_newlines=True)
@@ -68,61 +58,10 @@
 yield (match.group(1), False)
 process.wait()
 
-def readobj_get_symbols(lib):
-process = subprocess.Popen(['llvm-readobj','--symbols',lib], bufsize=1,
-   stdout=subprocess.PIPE, stdin=subprocess.PIPE,
-   universal_newlines=True)
-process.stdin.close()
-for line in process.stdout:
-# When looking through the output of llvm-readobj we expect to see Name,
-# Section, then StorageClass, so record Name and Section when we see
-# them and decide if this is an external symbol when we see
-# StorageClass.
-match = re.search('Name: (\S+)', line)
-if match:
-name = match.group(1)
-match = re.search('Section: (\S+)', line)
-if match:
-section = match.group(1)
-match = re.search('StorageClass: (\S+)', line)
-if match:
-storageclass = match.group(1)
-if section != 'IMAGE_SYM_ABSOLUTE' and \
-   storageclass == 'External':
-yield (name, section != 'IMAGE_SYM_UNDEFINED')
-process.wait()
-
-# Define functions which determine if the target is 32-bit Windows (as that's
+# Define a function which determines if the target is 32-bit Windows (as that's
 # where calling convention name decoration happens).
-
-def dumpbin_is_32bit_windows(lib):
-# dumpbin /headers can output a huge amount of data (>100MB in a debug
-# build) so we read only up to the 'machine' line then close the output.
-process = subprocess.Popen(['dumpbin','/headers',lib], bufsize=1,

cfe-commits@lists.llvm.org

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

Author: Martin Braenne
Date: 2023-05-08T07:10:44Z
New Revision: 9940fac7539597c08f03381527011e1280cd7489

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

LOG: [clang][dataflow][NFC] Remove `SkipPast` parameter from 
`getStorageLocation(const ValueDecl &).

This parameter was already a no-op, so removing it doesn't change behavior.

Depends On D149144

Reviewed By: ymandel, xazax.hun, gribozavr2

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
clang/lib/Analysis/FlowSensitive/Transfer.cpp
clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index cd1703be0507b..58b1d8b172b3d 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -281,12 +281,7 @@ class Environment {
   ///
   /// Note that if `D` has reference type, the storage location that is 
returned
   /// refers directly to the referenced object, not a `ReferenceValue`.
-  ///
-  /// The `SP` parameter is deprecated and has no effect. In addition, it is
-  /// not permitted to pass `SkipPast::ReferenceThenPointer` for this 
parameter.
-  /// New uses of this function should use the default argument for `SP`.
-  StorageLocation *getStorageLocation(const ValueDecl &D,
-  SkipPast SP = SkipPast::None) const;
+  StorageLocation *getStorageLocation(const ValueDecl &D) const;
 
   /// Assigns `Loc` as the storage location of `E` in the environment.
   ///

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index a4d3768b8b189..479aa12d191ee 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -245,7 +245,7 @@ void Environment::initFieldsGlobalsAndFuncs(const 
FunctionDecl *FuncDecl) {
   DACtx->addModeledFields(Fields);
 
   for (const VarDecl *D : Vars) {
-if (getStorageLocation(*D, SkipPast::None) != nullptr)
+if (getStorageLocation(*D) != nullptr)
   continue;
 auto &Loc = createStorageLocation(D->getType().getNonReferenceType());
 setStorageLocation(*D, Loc);
@@ -254,7 +254,7 @@ void Environment::initFieldsGlobalsAndFuncs(const 
FunctionDecl *FuncDecl) {
   }
 
   for (const FunctionDecl *FD : Funcs) {
-if (getStorageLocation(*FD, SkipPast::None) != nullptr)
+if (getStorageLocation(*FD) != nullptr)
   continue;
 auto &Loc = createStorageLocation(FD->getType());
 setStorageLocation(*FD, Loc);
@@ -605,10 +605,7 @@ void Environment::setStorageLocation(const ValueDecl &D, 
StorageLocation &Loc) {
   DeclToLoc[&D] = &Loc;
 }
 
-StorageLocation *Environment::getStorageLocation(const ValueDecl &D,
- SkipPast SP) const {
-  assert(SP != SkipPast::ReferenceThenPointer);
-
+StorageLocation *Environment::getStorageLocation(const ValueDecl &D) const {
   auto It = DeclToLoc.find(&D);
   if (It == DeclToLoc.end())
 return nullptr;
@@ -686,7 +683,7 @@ Value *Environment::getValue(const StorageLocation &Loc) 
const {
 Value *Environment::getValue(const ValueDecl &D, SkipPast SP) const {
   assert(SP != SkipPast::ReferenceThenPointer);
 
-  auto *Loc = getStorageLocation(D, SP);
+  auto *Loc = getStorageLocation(D);
   if (Loc == nullptr)
 return nullptr;
   return getValue(*Loc);

diff  --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index ddabf352fd111..50eb7e9011bda 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -219,7 +219,7 @@ class TransferVisitor : public 
ConstStmtVisitor {
   void VisitDeclRefExpr(const DeclRefExpr *S) {
 const ValueDecl *VD = S->getDecl();
 assert(VD != nullptr);
-auto *DeclLoc = Env.getStorageLocation(*VD, SkipPast::None);
+auto *DeclLoc = Env.getStorageLocation(*VD);
 if (DeclLoc == nullptr)
   return;
 
@@ -533,7 +533,7 @@ class TransferVisitor : public 
ConstStmtVisitor {
 
 if (auto *D = dyn_cast(Member)) {
   if (D->hasGlobalStorage()) {
-auto *VarDeclLoc = Env.getStorageLocation(*D, SkipPast::None);
+auto *VarDeclLoc = Env.

cfe-commits@lists.llvm.org

2023-05-08 Thread Martin Böhme via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9940fac75395: [clang][dataflow][NFC] Remove `SkipPast` 
parameter from `getStorageLocation… (authored by mboehme).

Changed prior to commit:
  https://reviews.llvm.org/D149151?vs=516770&id=520281#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149151

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
  clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
  clang/lib/Analysis/FlowSensitive/Transfer.cpp
  clang/unittests/Analysis/FlowSensitive/DataflowEnvironmentTest.cpp
  clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
  clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -723,8 +723,8 @@
 const ValueDecl *BarDecl = findValueDecl(ASTCtx, "Bar");
 ASSERT_THAT(BarDecl, NotNull());
 
-const auto *FooLoc = cast(
-Env.getStorageLocation(*FooDecl, SkipPast::None));
+const auto *FooLoc =
+cast(Env.getStorageLocation(*FooDecl));
 const auto *BarVal =
 cast(Env.getValue(*BarDecl, SkipPast::None));
 EXPECT_EQ(&BarVal->getPointeeLoc(), FooLoc);
Index: clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -99,7 +99,7 @@
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-EXPECT_EQ(Env.getStorageLocation(*FooDecl, SkipPast::None), nullptr);
+EXPECT_EQ(Env.getStorageLocation(*FooDecl), nullptr);
   },
   LangStandard::lang_cxx17,
   /*ApplyBuiltinTransfer=*/false);
@@ -122,8 +122,7 @@
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-const StorageLocation *FooLoc =
-Env.getStorageLocation(*FooDecl, SkipPast::None);
+const StorageLocation *FooLoc = Env.getStorageLocation(*FooDecl);
 ASSERT_TRUE(isa_and_nonnull(FooLoc));
 
 const Value *FooVal = Env.getValue(*FooLoc);
@@ -148,8 +147,7 @@
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-const StorageLocation *FooLoc =
-Env.getStorageLocation(*FooDecl, SkipPast::None);
+const StorageLocation *FooLoc = Env.getStorageLocation(*FooDecl);
 ASSERT_TRUE(isa_and_nonnull(FooLoc));
 
 const Value *FooVal = Env.getValue(*FooLoc);
@@ -228,8 +226,8 @@
 }
 ASSERT_THAT(UnmodeledDecl, NotNull());
 
-const auto *FooLoc = cast(
-Env.getStorageLocation(*FooDecl, SkipPast::None));
+const auto *FooLoc =
+cast(Env.getStorageLocation(*FooDecl));
 const auto *UnmodeledLoc = &FooLoc->getChild(*UnmodeledDecl);
 ASSERT_TRUE(isa(UnmodeledLoc));
 ASSERT_THAT(Env.getValue(*UnmodeledLoc), IsNull());
@@ -275,8 +273,8 @@
 }
 ASSERT_THAT(BarDecl, NotNull());
 
-const auto *FooLoc = cast(
-Env.getStorageLocation(*FooDecl, SkipPast::None));
+const auto *FooLoc =
+cast(Env.getStorageLocation(*FooDecl));
 const auto *BarLoc =
 cast(&FooLoc->getChild(*BarDecl));
 
@@ -323,8 +321,8 @@
 }
 ASSERT_THAT(BarDecl, NotNull());
 
-const auto *FooLoc = cast(
-Env.getStorageLocation(*FooDecl, SkipPast::None));
+const auto *FooLoc =
+cast(Env.getStorageLocation(*FooDecl));
 const auto *BarLoc =
 cast(&FooLoc->getChild(*BarDecl));
 
@@ -370,8 +368,8 @@
 }
 ASSERT_THAT(BarDecl, NotNull());
 
-const auto *FooLoc = cast(
-Env.getStorageLocation(*FooDecl, SkipPast::None));
+const auto *FooLoc =
+cast(Env.getStorageLocation(*FooDecl));
 const auto *BarLoc =
 cast(&FooLoc->getChild(*BarDecl));
 
@@ -402,8 +400,7 @@
 const ValueDecl *FooDecl = findValueDecl(ASTCtx, "Foo");
 ASSERT_THAT(FooDecl, NotNull());
 
-const StorageLocation *FooLoc =
-Env.getStorageLocation(*FooDecl, SkipPast::None);
+const StorageLocation *FooLoc = Env.getStorageLocation(*FooDecl);
 ASSERT_TRUE(isa_and_nonnull(FooLoc));
 
 const Value *FooReferentVal = Env.getValue(*FooLoc);
@@ -490,8 +487,8 @@
 ASSERT_THAT(BazRefDecl, NotNull()

[PATCH] D148435: [clang-repl] Do not assert if we have weak references left.

2023-05-08 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 520286.
v.g.vassilev added a comment.

Provide a better test case.


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

https://reviews.llvm.org/D148435

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/execute-weak.cpp


Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -9,4 +9,8 @@
 auto r4 = printf("bar() = %d\n", bar());
 // CHECK: bar() = 42
 
+int a = 12;
+static __typeof(a) b __attribute__((__weakref__("a")));
+int c = b;
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7230,7 +7230,6 @@
  "Newly created module should not have manglings");
   NewBuilder->Manglings = std::move(Manglings);
 
-  assert(WeakRefReferences.empty() && "Not all WeakRefRefs have been applied");
   NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
   NewBuilder->TBAA = std::move(TBAA);


Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -9,4 +9,8 @@
 auto r4 = printf("bar() = %d\n", bar());
 // CHECK: bar() = 42
 
+int a = 12;
+static __typeof(a) b __attribute__((__weakref__("a")));
+int c = b;
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7230,7 +7230,6 @@
  "Newly created module should not have manglings");
   NewBuilder->Manglings = std::move(Manglings);
 
-  assert(WeakRefReferences.empty() && "Not all WeakRefRefs have been applied");
   NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
   NewBuilder->TBAA = std::move(TBAA);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D146188: [Clang][DOC] Add documentation in for __builtin_flt_rounds and __builtin_set_flt_rounds

2023-05-08 Thread xiongji90 via Phabricator via cfe-commits
xiongji90 updated this revision to Diff 520288.
xiongji90 added a comment.

Address previous comments


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146188

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/UsersManual.rst


Index: clang/docs/UsersManual.rst
===
--- clang/docs/UsersManual.rst
+++ clang/docs/UsersManual.rst
@@ -1787,6 +1787,48 @@
* ``16`` - Forces ``_Float16`` operations to be emitted without using excess
  precision arithmetic.
 
+.. _floating-point-environment:
+
+Accessing the floating point environment
+
+Many targets allow floating point operations to be configured to control things
+such as how inexact results should be rounded and how exceptional conditions
+should be handled. This configuration is called the floating point environment.
+C and C++ restrict access to the floating point environment by default, and the
+compiler is allowed to assume that all operations are performed in the default
+environment. When code is compiled in this default mode, operations that depend
+on the environment (such as floating-point arithmetic and `FLT_ROUNDS`) may 
have
+undefined behavior if the dynamic environment is not the default environment; 
for
+example, `FLT_ROUNDS` may or may not simply return its default value for the 
target
+instead of reading the dynamic environment, and floating-point operations may 
be
+optimized as if the dynamic environment were the default.  Similarly, it is 
undefined
+behavior to change the floating point environment in this default mode, for 
example
+by calling the `fesetround` function.
+C provides two pragmas to allow code to dynamically modify the floating point 
environment:
+
+- ``#pragma STDC FENV_ACCESS ON`` allows dynamic changes to the entire floating
+  point environment.
+
+- ``#pragma STDC FENV_ROUND FE_DYNAMIC`` allows dynamic changes to just the 
floating
+  point rounding mode.  This may be more optimizable than ``FENV_ACCESS ON`` 
because
+  the compiler can still ignore the possibility of floating-point exceptions 
by default.
+
+Both of these can be used either at the start of a block scope, in which case
+they cover all code in that scope (unless they're turned off in a child scope),
+or at the top level in a file, in which case they cover all subsequent function
+bodies until they're turned off.  Note that it is undefined behavior to enter
+code that is *not* covered by one of these pragmas from code that *is* covered
+by one of these pragmas unless the floating point environment has been restored
+to its default state.  See the C standard for more information about these 
pragmas.
+
+The command line option ``-frounding-math`` behaves as if the translation unit
+began with ``#pragma STDC FENV_ROUND FE_DYNAMIC``. The command line option
+``-ffp-model=strict`` behaves as if the translation unit began with ``#pragma 
STDC FENV_ACCESS ON``.
+
+Code that just wants to use a specific rounding mode for specific floating 
point
+operations can avoid most of the hazards of the dynamic floating point 
environment
+by using ``#pragma STDC FENV_ROUND`` with a value other than ``FE_DYNAMIC``.
+
 .. _crtfastmath.o:
 
 A note about ``crtfastmath.o``
Index: clang/docs/LanguageExtensions.rst
===
--- clang/docs/LanguageExtensions.rst
+++ clang/docs/LanguageExtensions.rst
@@ -3289,7 +3289,7 @@
 
double __builtin_canonicalize(double);
float __builtin_canonicalizef(float);
-   long double__builtin_canonicalizel(long double);
+   long double __builtin_canonicalizel(long double);
 
 Returns the platform specific canonical encoding of a floating point
 number. This canonicalization is useful for implementing certain
@@ -3297,6 +3297,28 @@
 `_ for
 more information on the semantics.
 
+``__builtin_flt_rounds`` and ``__builtin_set_flt_rounds``
+-
+
+.. code-block:: c
+
+   int __builtin_flt_rounds();
+   void __builtin_set_flt_rounds(int);
+
+Returns and sets current floating point rounding mode. The encoding of returned
+values and input parameters is same as the result of FLT_ROUNDS, specified by C
+standard:
+- ``0``  - toward zero
+- ``1``  - to nearest, ties to even
+- ``2``  - toward positive infinity
+- ``3``  - toward negative infinity
+- ``4``  - to nearest, ties away from zero
+The effect of passing some other value to ``__builtin_flt_rounds`` is
+implementation-defined. ``__builtin_set_flt_rounds`` is currently only 
supported
+to work on x86, x86_64, Arm and AArch64 targets. These builtins read and modify
+the floating-point environment, which is not always allowed and may have 
unexpected
+behavior. Please see the section on `Accessing the floating point environ

[PATCH] D146188: [Clang][DOC] Add documentation in for __builtin_flt_rounds and __builtin_set_flt_rounds

2023-05-08 Thread xiongji90 via Phabricator via cfe-commits
xiongji90 marked an inline comment as done.
xiongji90 added a comment.

Hi, @rjmccall 
I updated the patch to address your previous comments, could you help review 
again?
Thanks very much.




Comment at: clang/docs/LanguageExtensions.rst:3272
+3  - toward negative infinity
+4  - to nearest, ties away from zero
+The effect of passing some other value to ``__builtin_flt_rounds`` is

rjmccall wrote:
> I suspect this won't end up being formatted as a list; you should do 
> something like:
> 
> ```
> - ``0`` - toward zero
> - ``1`` - to nearest, ties to even
> ...
> ```
Done.
Thanks very much.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146188

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


[PATCH] D150001: [clang] Fix initializer_list matching failures with modules

2023-05-08 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Nice!




Comment at: clang/lib/Sema/SemaDeclCXX.cpp:11570
 getStdNamespace()->setImplicit(true);
+Context.getTranslationUnitDecl()->addDecl(getStdNamespace());
+getStdNamespace()->clearIdentifierNamespace();

This could use an explanatory comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150001

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


[PATCH] D150043: [InferAddressSpaces] Handle vector of pointers type

2023-05-08 Thread CaprYang via Phabricator via cfe-commits
CaprYang updated this revision to Diff 520296.
CaprYang removed reviewers: bollu, ldionne, nicolasvasilache, rafauler, Amir, 
maksfb, NoQ, njames93, libc++, libc++abi, libunwind, rymiel, 
HazardyKnusperkeks, owenpan, MyDeveloperDay.
CaprYang removed projects: clang-format, Flang, clang-tools-extra, MLIR, 
libunwind, libc++abi, libc-project, OpenMP, libc++, LLDB, Sanitizers, clang.

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

https://reviews.llvm.org/D150043

Files:
  llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
  llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
  llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll

Index: llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
===
--- /dev/null
+++ llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
@@ -0,0 +1,25 @@
+; RUN: opt -S -passes=infer-address-spaces -assume-default-is-flat-addrspace %s | FileCheck %s
+
+; CHECK-LABEL: @masked_gather_inferas(
+; CHECK: tail call <4 x i32> @llvm.masked.gather.v4i32.v4p1
+define <4 x i32> @masked_gather_inferas(ptr addrspace(1) %out, <4 x i64> %index) {
+entry:
+  %out.1 = addrspacecast ptr addrspace(1) %out to ptr
+  %ptrs = getelementptr inbounds i32, ptr %out.1, <4 x i64> %index
+  %value = tail call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> %ptrs, i32 4, <4 x i1> , <4 x i32> poison)
+  ret <4 x i32> %value
+}
+
+; CHECK-LABEL: @masked_scatter_inferas(
+; CHECK: tail call void @llvm.masked.scatter.v4i32.v4p1
+define void @masked_scatter_inferas(ptr addrspace(1) %out, <4 x i64> %index, <4 x i32> %value) {
+entry:
+  %out.1 = addrspacecast ptr addrspace(1) %out to ptr
+  %ptrs = getelementptr inbounds i32, ptr %out.1, <4 x i64> %index
+  tail call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> %value, <4 x ptr> %ptrs, i32 4, <4 x i1> )
+  ret void
+}
+
+declare <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr>, i32 immarg, <4 x i1>, <4 x i32>)
+
+declare void @llvm.masked.scatter.v4i32.v4p0(<4 x i32>, <4 x ptr>, i32 immarg, <4 x i1>)
\ No newline at end of file
Index: llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
===
--- llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
+++ llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
@@ -147,9 +147,8 @@
   ret i1 %cmp
 }
 
-; TODO: Should be handled
 ; CHECK-LABEL: @icmp_flat_flat_from_group_vector(
-; CHECK: %cmp = icmp eq <2 x ptr> %cast0, %cast1
+; CHECK: %cmp = icmp eq <2 x ptr addrspace(3)> %group.ptr.0, %group.ptr.1
 define <2 x i1> @icmp_flat_flat_from_group_vector(<2 x ptr addrspace(3)> %group.ptr.0, <2 x ptr addrspace(3)> %group.ptr.1) #0 {
   %cast0 = addrspacecast <2 x ptr addrspace(3)> %group.ptr.0 to <2 x ptr>
   %cast1 = addrspacecast <2 x ptr addrspace(3)> %group.ptr.1 to <2 x ptr>
Index: llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
===
--- llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -256,6 +256,48 @@
 INITIALIZE_PASS_END(InferAddressSpaces, DEBUG_TYPE, "Infer address spaces",
 false, false)
 
+static unsigned getPtrOrVecOfPtrsAddressSpace(Type *Ty) {
+  if (Ty->isVectorTy()) {
+Ty = cast(Ty)->getElementType();
+  }
+  assert(Ty->isPointerTy());
+  return Ty->getPointerAddressSpace();
+}
+
+static bool isPtrOrVecOfPtrsType(Type *Ty) {
+  if (Ty->isVectorTy()) {
+Ty = cast(Ty)->getElementType();
+  }
+  return Ty->isPointerTy();
+}
+
+static Type *getPtrOrVecOfPtrsWithNewAS(Type *Ty, unsigned NewAddrSpace) {
+  if (!Ty->isVectorTy()) {
+assert(Ty->isPointerTy());
+return PointerType::getWithSamePointeeType(cast(Ty),
+   NewAddrSpace);
+  }
+
+  Type *PT = cast(Ty)->getElementType();
+  assert(PT->isPointerTy());
+
+  Type *NPT =
+  PointerType::getWithSamePointeeType(cast(PT), NewAddrSpace);
+  return VectorType::get(NPT, cast(Ty)->getElementCount());
+}
+
+static bool hasSameElementOfPtrOrVecPtrs(Type *Ty1, Type *Ty2) {
+  assert(isPtrOrVecOfPtrsType(Ty1) && isPtrOrVecOfPtrsType(Ty2));
+  assert(Ty1->isVectorTy() == Ty2->isVectorTy());
+  if (Ty1->isVectorTy()) {
+Ty1 = cast(Ty1)->getElementType();
+Ty2 = cast(Ty2)->getElementType();
+  }
+
+  assert(Ty1->isPointerTy() && Ty2->isPointerTy());
+  return cast(Ty1)->hasSameElementTypeAs(cast(Ty2));
+}
+
 // Check whether that's no-op pointer bicast using a pair of
 // `ptrtoint`/`inttoptr` due to the missing no-op pointer bitcast over
 // different address spaces.
@@ -279,8 +321,9 @@
   // arithmetic may also be undefined after invalid pointer reinterpret cast.
   // However, as we confirm through the target hooks that it's a no-op
   // addrspacecast, it doesn't matter since the bits should be the same.
-  unsigned P2IOp0AS = P2I->getOperand(0)->getType()->getPointerAddre

[PATCH] D150036: [Clang] Correctly handle allocation in template arguments

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



Comment at: clang/docs/ReleaseNotes.rst:385
+- Fix handling of constexpr dynamic memory allocations in template
+  arguments. (`#62462 `)
 

Not an expert in this, but I assume `_` after link is needed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150036

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


[PATCH] D150043: [InferAddressSpaces] Handle vector of pointers type & Support intrinsic masked gather/scatter

2023-05-08 Thread CaprYang via Phabricator via cfe-commits
CaprYang updated this revision to Diff 520302.
CaprYang retitled this revision from "[InferAddressSpaces] Handle vector of 
pointers type" to "[InferAddressSpaces] Handle vector of pointers type & 
Support intrinsic masked gather/scatter".

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

https://reviews.llvm.org/D150043

Files:
  llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
  llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
  llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll

Index: llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
===
--- /dev/null
+++ llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
@@ -0,0 +1,25 @@
+; RUN: opt -S -passes=infer-address-spaces -assume-default-is-flat-addrspace %s | FileCheck %s
+
+; CHECK-LABEL: @masked_gather_inferas(
+; CHECK: tail call <4 x i32> @llvm.masked.gather.v4i32.v4p1
+define <4 x i32> @masked_gather_inferas(ptr addrspace(1) %out, <4 x i64> %index) {
+entry:
+  %out.1 = addrspacecast ptr addrspace(1) %out to ptr
+  %ptrs = getelementptr inbounds i32, ptr %out.1, <4 x i64> %index
+  %value = tail call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> %ptrs, i32 4, <4 x i1> , <4 x i32> poison)
+  ret <4 x i32> %value
+}
+
+; CHECK-LABEL: @masked_scatter_inferas(
+; CHECK: tail call void @llvm.masked.scatter.v4i32.v4p1
+define void @masked_scatter_inferas(ptr addrspace(1) %out, <4 x i64> %index, <4 x i32> %value) {
+entry:
+  %out.1 = addrspacecast ptr addrspace(1) %out to ptr
+  %ptrs = getelementptr inbounds i32, ptr %out.1, <4 x i64> %index
+  tail call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> %value, <4 x ptr> %ptrs, i32 4, <4 x i1> )
+  ret void
+}
+
+declare <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr>, i32 immarg, <4 x i1>, <4 x i32>)
+
+declare void @llvm.masked.scatter.v4i32.v4p0(<4 x i32>, <4 x ptr>, i32 immarg, <4 x i1>)
\ No newline at end of file
Index: llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
===
--- llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
+++ llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
@@ -147,9 +147,8 @@
   ret i1 %cmp
 }
 
-; TODO: Should be handled
 ; CHECK-LABEL: @icmp_flat_flat_from_group_vector(
-; CHECK: %cmp = icmp eq <2 x ptr> %cast0, %cast1
+; CHECK: %cmp = icmp eq <2 x ptr addrspace(3)> %group.ptr.0, %group.ptr.1
 define <2 x i1> @icmp_flat_flat_from_group_vector(<2 x ptr addrspace(3)> %group.ptr.0, <2 x ptr addrspace(3)> %group.ptr.1) #0 {
   %cast0 = addrspacecast <2 x ptr addrspace(3)> %group.ptr.0 to <2 x ptr>
   %cast1 = addrspacecast <2 x ptr addrspace(3)> %group.ptr.1 to <2 x ptr>
Index: llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
===
--- llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -256,6 +256,33 @@
 INITIALIZE_PASS_END(InferAddressSpaces, DEBUG_TYPE, "Infer address spaces",
 false, false)
 
+static Type *getPtrOrVecOfPtrsWithNewAS(Type *Ty, unsigned NewAddrSpace) {
+  if (!Ty->isVectorTy()) {
+assert(Ty->isPointerTy());
+return PointerType::getWithSamePointeeType(cast(Ty),
+   NewAddrSpace);
+  }
+
+  Type *PT = cast(Ty)->getElementType();
+  assert(PT->isPointerTy());
+
+  Type *NPT =
+  PointerType::getWithSamePointeeType(cast(PT), NewAddrSpace);
+  return VectorType::get(NPT, cast(Ty)->getElementCount());
+}
+
+static bool hasSameElementOfPtrOrVecPtrs(Type *Ty1, Type *Ty2) {
+  assert(Ty1->isPtrOrPtrVectorTy() && Ty2->isPtrOrPtrVectorTy());
+  assert(Ty1->isVectorTy() == Ty2->isVectorTy());
+  if (Ty1->isVectorTy()) {
+Ty1 = cast(Ty1)->getElementType();
+Ty2 = cast(Ty2)->getElementType();
+  }
+
+  assert(Ty1->isPointerTy() && Ty2->isPointerTy());
+  return cast(Ty1)->hasSameElementTypeAs(cast(Ty2));
+}
+
 // Check whether that's no-op pointer bicast using a pair of
 // `ptrtoint`/`inttoptr` due to the missing no-op pointer bitcast over
 // different address spaces.
@@ -301,14 +328,14 @@
 
   switch (Op->getOpcode()) {
   case Instruction::PHI:
-assert(Op->getType()->isPointerTy());
+assert(Op->getType()->isPtrOrPtrVectorTy());
 return true;
   case Instruction::BitCast:
   case Instruction::AddrSpaceCast:
   case Instruction::GetElementPtr:
 return true;
   case Instruction::Select:
-return Op->getType()->isPointerTy();
+return Op->getType()->isPtrOrPtrVectorTy();
   case Instruction::Call: {
 const IntrinsicInst *II = dyn_cast(&V);
 return II && II->getIntrinsicID() == Intrinsic::ptrmask;
@@ -373,6 +400,24 @@
   case Intrinsic::ptrmask:
 // This is handled as an address expression, not as a use memory operation.
 return false;
+  case Intrinsic::masked_gather: {
+Type *RetTy = II->getType();
+Type *NewPtrTy = NewV

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-05-08 Thread Stefan Gränitz via Phabricator via cfe-commits
sgraenitz added a comment.

In D141215#4272538 , @lhames wrote:

> using regular global variable instances to manage the storage on the executor 
> side, an extended `MemoryAccess` interface to read/write the value from the 
> REPL side when needed (e.g. for printing), and emitting glue functions to 
> pass the variable's value in to callers.

Agree, that's probably the better solution. Just for the record: Values 
couldn't be temporaries and access must be synchronized with execution to avoid 
races. I guess both is easily acceptable.




Comment at: clang/include/clang/Interpreter/Value.h:160-162
+  // Interpreter, QualType are stored as void* to reduce dependencies.
+  void *Interp = nullptr;
+  void *OpaqueType = nullptr;

v.g.vassilev wrote:
> aaron.ballman wrote:
> > junaire wrote:
> > > aaron.ballman wrote:
> > > > v.g.vassilev wrote:
> > > > > aaron.ballman wrote:
> > > > > > v.g.vassilev wrote:
> > > > > > > aaron.ballman wrote:
> > > > > > > > Why don't forward declares suffice if we're storing the 
> > > > > > > > information by pointer?
> > > > > > > This is a performance-critical class. We literally measure the 
> > > > > > > instruction count for it. We practically cannot include anything 
> > > > > > > in this header file because the class needs to included as part 
> > > > > > > of the interpreter runtime. For example:
> > > > > > > 
> > > > > > > ```
> > > > > > > #include 
> > > > > > > Value ResultV;
> > > > > > > gInterpreter->evaluate("float i = 12.3; i++", &V);
> > > > > > > printf("Value is %d\n", ResultV.castAs());
> > > > > > > ```
> > > > > > > 
> > > > > > > This is how you can do things in Cling. This not yet there but 
> > > > > > > that's our next step.
> > > > > > > 
> > > > > > > For performance reasons we have the `ValueKind` optimization 
> > > > > > > which allows us to perform most of the operations we need very 
> > > > > > > fast. There are some operations such as printing the concrete 
> > > > > > > type which need the actual `QualType` and so on but they are 
> > > > > > > outside of the performance critical paths and it is okay to 
> > > > > > > resort back to the real types providing the level of accuracy we 
> > > > > > > need.
> > > > > > > 
> > > > > > That sounds like it's going to lead to maintenance problems in the 
> > > > > > long term, right? I can't think of another header file we say 
> > > > > > "don't touch this because it may impact runtime performance", and 
> > > > > > so I can easily imagine someone breaking your expectation that this 
> > > > > > file can't include anything else.
> > > > > > 
> > > > > > Is there a long-term plan for addressing this?
> > > > > We have a few components like the Lexer that are extremely prone to 
> > > > > performance regressions.
> > > > > 
> > > > > In terms for a longer-term plan in addressing this there are some 
> > > > > steps could help IMO. First, this component is relatively standalone 
> > > > > and very few changes will be required over time, for these I am 
> > > > > hoping to be listed as a reviewer. Second, we can add a comment in 
> > > > > the include area, making a note that including anything here will 
> > > > > degrade the performance of almost all interpreted code. Third, we 
> > > > > will find out about this in our downstream use-cases as the things 
> > > > > get significantly slower.
> > > > > 
> > > > > Neither is silver bullet but that's probably the best we could do at 
> > > > > that time. Btw, we might be able to add a test that's part of LLVM's 
> > > > > performance analysis infrastructure.
> > > > > Neither is silver bullet but that's probably the best we could do at 
> > > > > that time. Btw, we might be able to add a test that's part of LLVM's 
> > > > > performance analysis infrastructure.
> > > > 
> > > > Yeah, we should probably consider doing that. But to make sure I 
> > > > understand the performance concerns... when we change functionality in 
> > > > the lexer, we (potentially) slow down the lexing phase of compilation. 
> > > > That's straightforward and unsurprising. But in this case, it sounds 
> > > > like the act of including another header file in this header file will 
> > > > cause a runtime performance concern, even if no other changes are made. 
> > > > If I'm correct, I can't think of anything else in the compiler that 
> > > > works like that.
> > > I believe what @v.g.vassilev means is that the repl itself might include 
> > > `Value.h` as a part of *runtime*, so if the header is heavy, you can 
> > > notice the repl is slowed down. (That's obvious) So keep in mind we're 
> > > breaking the boundary between the compiled code and interpreted code 
> > > (It's kinda confusing) here it actually impacts interpreted code.
> > > I believe what @v.g.vassilev means is that the repl itself might include 
> > > Value.h as a part of *runtime*, so if the header is heavy, you can notice 
> > > the rep

[PATCH] D146030: [clang][Interp] Handle LambdaExprs

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/lambda.cpp:92
+  static_assert(foo() == 1); // expected-error {{not an integral constant 
expression}}
+}
+

tbaeder wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > How about some tests like:
> > > ```
> > > constexpr int call_thru_func_ptr(int i) {
> > >   auto l = [](int i) { return i; };
> > >   int (*fp)(int) = l;
> > >   return fp(i);  
> > > }
> > > static_assert(call_thru_func_ptr(12) == 12);
> > > 
> > > constexpr int call_through_copied_lambda(auto lam, int i) {
> > >   auto copy = lam;
> > >   return copy(i);
> > > }
> > > 
> > > constexpr int call_through_copied_lambda(auto lam) {
> > >   auto copy = lam;
> > >   return copy();
> > > }
> > > 
> > > void func() {
> > >   constexpr int i = 12;
> > >   static_assert(call_through_copied_lambda([i]() { return i; }) == 12);
> > > }
> > > ```
> > Heh:
> > ```
> > array.cpp:1245:15: error: static assertion expression is not an integral 
> > constant expression
> >  1245 | static_assert(call_thru_func_ptr(12) == 12);
> >   |   ^~~~
> > array.cpp:1243:10: note: non-constexpr function '__invoke' cannot be used 
> > in a constant expression
> >  1243 |   return fp(i);
> >   |  ^
> > array.cpp:1245:15: note: in call to 'call_thru_func_ptr(12)'
> >  1245 | static_assert(call_thru_func_ptr(12) == 12);
> >   |   ^
> > array.cpp:1239:12: note: declared here
> >  1239 |   auto l = [](int i) { return i; };
> >   |^
> > 
> > ```
> Ah, I didn't know there is something like a "lambda static invoker". I see 
> the current interpreter basically checks for that and then calls the lambda 
> call operator instead. Doing that is hard for me though, because the call 
> operator requires different arguments and I can't just itnogre the static 
> invoker either because it has an empty body.
Okay, I think I figured it out, I'm just special-casing the static invoker and 
emitting byte code for its body manually. This will make the patch larger 
though.


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

https://reviews.llvm.org/D146030

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


[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

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



Comment at: clang/include/clang/Interpreter/Value.h:160-162
+  // Interpreter, QualType are stored as void* to reduce dependencies.
+  void *Interp = nullptr;
+  void *OpaqueType = nullptr;

sgraenitz wrote:
> v.g.vassilev wrote:
> > aaron.ballman wrote:
> > > junaire wrote:
> > > > aaron.ballman wrote:
> > > > > v.g.vassilev wrote:
> > > > > > aaron.ballman wrote:
> > > > > > > v.g.vassilev wrote:
> > > > > > > > aaron.ballman wrote:
> > > > > > > > > Why don't forward declares suffice if we're storing the 
> > > > > > > > > information by pointer?
> > > > > > > > This is a performance-critical class. We literally measure the 
> > > > > > > > instruction count for it. We practically cannot include 
> > > > > > > > anything in this header file because the class needs to 
> > > > > > > > included as part of the interpreter runtime. For example:
> > > > > > > > 
> > > > > > > > ```
> > > > > > > > #include 
> > > > > > > > Value ResultV;
> > > > > > > > gInterpreter->evaluate("float i = 12.3; i++", &V);
> > > > > > > > printf("Value is %d\n", ResultV.castAs());
> > > > > > > > ```
> > > > > > > > 
> > > > > > > > This is how you can do things in Cling. This not yet there but 
> > > > > > > > that's our next step.
> > > > > > > > 
> > > > > > > > For performance reasons we have the `ValueKind` optimization 
> > > > > > > > which allows us to perform most of the operations we need very 
> > > > > > > > fast. There are some operations such as printing the concrete 
> > > > > > > > type which need the actual `QualType` and so on but they are 
> > > > > > > > outside of the performance critical paths and it is okay to 
> > > > > > > > resort back to the real types providing the level of accuracy 
> > > > > > > > we need.
> > > > > > > > 
> > > > > > > That sounds like it's going to lead to maintenance problems in 
> > > > > > > the long term, right? I can't think of another header file we say 
> > > > > > > "don't touch this because it may impact runtime performance", and 
> > > > > > > so I can easily imagine someone breaking your expectation that 
> > > > > > > this file can't include anything else.
> > > > > > > 
> > > > > > > Is there a long-term plan for addressing this?
> > > > > > We have a few components like the Lexer that are extremely prone to 
> > > > > > performance regressions.
> > > > > > 
> > > > > > In terms for a longer-term plan in addressing this there are some 
> > > > > > steps could help IMO. First, this component is relatively 
> > > > > > standalone and very few changes will be required over time, for 
> > > > > > these I am hoping to be listed as a reviewer. Second, we can add a 
> > > > > > comment in the include area, making a note that including anything 
> > > > > > here will degrade the performance of almost all interpreted code. 
> > > > > > Third, we will find out about this in our downstream use-cases as 
> > > > > > the things get significantly slower.
> > > > > > 
> > > > > > Neither is silver bullet but that's probably the best we could do 
> > > > > > at that time. Btw, we might be able to add a test that's part of 
> > > > > > LLVM's performance analysis infrastructure.
> > > > > > Neither is silver bullet but that's probably the best we could do 
> > > > > > at that time. Btw, we might be able to add a test that's part of 
> > > > > > LLVM's performance analysis infrastructure.
> > > > > 
> > > > > Yeah, we should probably consider doing that. But to make sure I 
> > > > > understand the performance concerns... when we change functionality 
> > > > > in the lexer, we (potentially) slow down the lexing phase of 
> > > > > compilation. That's straightforward and unsurprising. But in this 
> > > > > case, it sounds like the act of including another header file in this 
> > > > > header file will cause a runtime performance concern, even if no 
> > > > > other changes are made. If I'm correct, I can't think of anything 
> > > > > else in the compiler that works like that.
> > > > I believe what @v.g.vassilev means is that the repl itself might 
> > > > include `Value.h` as a part of *runtime*, so if the header is heavy, 
> > > > you can notice the repl is slowed down. (That's obvious) So keep in 
> > > > mind we're breaking the boundary between the compiled code and 
> > > > interpreted code (It's kinda confusing) here it actually impacts 
> > > > interpreted code.
> > > > I believe what @v.g.vassilev means is that the repl itself might 
> > > > include Value.h as a part of *runtime*, so if the header is heavy, you 
> > > > can notice the repl is slowed down. (That's obvious) So keep in mind 
> > > > we're breaking the boundary between the compiled code and interpreted 
> > > > code (It's kinda confusing) here it actually impacts interpreted code.
> > > 
> > > I'm not certain that's a reasonable design choice to make. Or, stated 
> > > somewhat differently, I'm really uncomfortable with having header files 

[clang] 743ff9c - [clang-repl] Do not assert if we have weak references left.

2023-05-08 Thread Vassil Vassilev via cfe-commits

Author: Vassil Vassilev
Date: 2023-05-08T09:13:00Z
New Revision: 743ff9c8bad375d4cea0c44a89cdcc117ffc9bf3

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

LOG: [clang-repl] Do not assert if we have weak references left.

Non-incremental Clang can also exit with the WeakRefReferences not empty upon
such example. This patch makes clang-repl consistent to what Clang does.

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

Added: 


Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/Interpreter/execute-weak.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 367f802253e01..7534304b1878f 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -7230,7 +7230,6 @@ void CodeGenModule::moveLazyEmissionStates(CodeGenModule 
*NewBuilder) {
  "Newly created module should not have manglings");
   NewBuilder->Manglings = std::move(Manglings);
 
-  assert(WeakRefReferences.empty() && "Not all WeakRefRefs have been applied");
   NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
   NewBuilder->TBAA = std::move(TBAA);

diff  --git a/clang/test/Interpreter/execute-weak.cpp 
b/clang/test/Interpreter/execute-weak.cpp
index 5b343512c5456..66f2214ab03c0 100644
--- a/clang/test/Interpreter/execute-weak.cpp
+++ b/clang/test/Interpreter/execute-weak.cpp
@@ -2,11 +2,17 @@
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // CHECK-DRIVER: i = 10
+//
 // UNSUPPORTED: system-aix, system-windows
 // RUN: cat %s | clang-repl | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 int __attribute__((weak)) bar() { return 42; }
 auto r4 = printf("bar() = %d\n", bar());
 // CHECK: bar() = 42
 
+int a = 12;
+static __typeof(a) b __attribute__((__weakref__("a")));
+int c = b;
+
 %quit



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


[PATCH] D148435: [clang-repl] Do not assert if we have weak references left.

2023-05-08 Thread Vassil Vassilev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG743ff9c8bad3: [clang-repl] Do not assert if we have weak 
references left. (authored by v.g.vassilev).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D148435?vs=520286&id=520305#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148435

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/Interpreter/execute-weak.cpp


Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -2,11 +2,17 @@
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck 
--check-prefix=CHECK-DRIVER %s
 // CHECK-DRIVER: i = 10
+//
 // UNSUPPORTED: system-aix, system-windows
 // RUN: cat %s | clang-repl | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 int __attribute__((weak)) bar() { return 42; }
 auto r4 = printf("bar() = %d\n", bar());
 // CHECK: bar() = 42
 
+int a = 12;
+static __typeof(a) b __attribute__((__weakref__("a")));
+int c = b;
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7230,7 +7230,6 @@
  "Newly created module should not have manglings");
   NewBuilder->Manglings = std::move(Manglings);
 
-  assert(WeakRefReferences.empty() && "Not all WeakRefRefs have been applied");
   NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
   NewBuilder->TBAA = std::move(TBAA);


Index: clang/test/Interpreter/execute-weak.cpp
===
--- clang/test/Interpreter/execute-weak.cpp
+++ clang/test/Interpreter/execute-weak.cpp
@@ -2,11 +2,17 @@
 // RUN: clang-repl "int i = 10;" 'extern "C" int printf(const char*,...);' \
 // RUN:'auto r1 = printf("i = %d\n", i);' | FileCheck --check-prefix=CHECK-DRIVER %s
 // CHECK-DRIVER: i = 10
+//
 // UNSUPPORTED: system-aix, system-windows
 // RUN: cat %s | clang-repl | FileCheck %s
+
 extern "C" int printf(const char *, ...);
 int __attribute__((weak)) bar() { return 42; }
 auto r4 = printf("bar() = %d\n", bar());
 // CHECK: bar() = 42
 
+int a = 12;
+static __typeof(a) b __attribute__((__weakref__("a")));
+int c = b;
+
 %quit
Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -7230,7 +7230,6 @@
  "Newly created module should not have manglings");
   NewBuilder->Manglings = std::move(Manglings);
 
-  assert(WeakRefReferences.empty() && "Not all WeakRefRefs have been applied");
   NewBuilder->WeakRefReferences = std::move(WeakRefReferences);
 
   NewBuilder->TBAA = std::move(TBAA);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

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



Comment at: clang/include/clang/AST/Decl.h:4345
+  }
+  bool isValuePrinting() const { return IsSemiMissing; }
+  void setValuePrinting(bool Missing = true) { IsSemiMissing = Missing; }

We should change the accessors to the new field name accordingly.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

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

@rsmith, any ideas how to support value printing of constructs such as `int i = 
12`, eg, that's not a top-level statement declaration but worth printing its 
value? It is the shorthand of `int i = 12; i`.




Comment at: clang/lib/CodeGen/CodeGenModule.cpp:7219
 void CodeGenModule::moveLazyEmissionStates(CodeGenModule *NewBuilder) {
-  assert(DeferredDeclsToEmit.empty() &&
- "Should have emitted all decls deferred to emit.");
+  // FIXME: Re-enable the assertions once we fix regular codegen to not leave
+  // weak references behind.

junaire wrote:
> I'll removed the change after https://reviews.llvm.org/D148435 landed.
That can probably go away now.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

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


[PATCH] D148793: [WIP][clang-tidy] Implement an include-cleaner check.

2023-05-08 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 520307.
VitaNuo marked 2 inline comments as done.
VitaNuo added a comment.
Herald added a subscriber: arphaman.

Move the check from "google" to "misc".


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

Files:
  clang-tools-extra/clang-tidy/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/CMakeLists.txt
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
  clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
  clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
  clang-tools-extra/clangd/TidyProvider.cpp
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
  clang-tools-extra/include-cleaner/lib/Record.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
  clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
  clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
  clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
  clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
  clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
  clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,116 @@
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "gtest/gtest.h"
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+)";
+  const char *PostCode = "\n\n\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, &Errors, "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SystemMissingIncludes) {
+  const char *PreCode = R"(
+#include 
+
+std::string HelloString;
+std::vector Vec;
+)";
+  const char *PostCode = R"(
+#include 
+#include 
+
+std::string HelloString;
+std::vector Vec;
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"string", R"(#pragma once
+  namespace std { class string {}; }
+)"},
+ {"vector", R"(#pragma once
+  #include 
+  namespace std { class vector {}; }
+)"}}));
+}
+
+TEST(IncludeCleanerCheckTest, PragmaMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int FooBarResult = foobar();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "public.h"
+
+int BarResult = bar();
+int FooBarResult = foobar();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "private.h"
+  int bar();
+   )"},
+ {"private.h", R"(#pragma once
+// IWYU pragma: private, include "public.h"
+int foobar();
+   )"}}));
+}
+
+} // namespace test
+} // namespace tidy
+} // namespace clang
Index: clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
===
--- clang-tools-extra/unittests/clang-tidy/CMakeLists.txt
+++ clang-too

[PATCH] D150043: [InferAddressSpaces] Handle vector of pointers type & Support intrinsic masked gather/scatter

2023-05-08 Thread CaprYang via Phabricator via cfe-commits
CaprYang updated this revision to Diff 520308.

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

https://reviews.llvm.org/D150043

Files:
  llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
  llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
  llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll

Index: llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
===
--- /dev/null
+++ llvm/test/Transforms/InferAddressSpaces/masked-gather-scatter.ll
@@ -0,0 +1,25 @@
+; RUN: opt -S -passes=infer-address-spaces -assume-default-is-flat-addrspace %s | FileCheck %s
+
+; CHECK-LABEL: @masked_gather_inferas(
+; CHECK: tail call <4 x i32> @llvm.masked.gather.v4i32.v4p1
+define <4 x i32> @masked_gather_inferas(ptr addrspace(1) %out, <4 x i64> %index) {
+entry:
+  %out.1 = addrspacecast ptr addrspace(1) %out to ptr
+  %ptrs = getelementptr inbounds i32, ptr %out.1, <4 x i64> %index
+  %value = tail call <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr> %ptrs, i32 4, <4 x i1> , <4 x i32> poison)
+  ret <4 x i32> %value
+}
+
+; CHECK-LABEL: @masked_scatter_inferas(
+; CHECK: tail call void @llvm.masked.scatter.v4i32.v4p1
+define void @masked_scatter_inferas(ptr addrspace(1) %out, <4 x i64> %index, <4 x i32> %value) {
+entry:
+  %out.1 = addrspacecast ptr addrspace(1) %out to ptr
+  %ptrs = getelementptr inbounds i32, ptr %out.1, <4 x i64> %index
+  tail call void @llvm.masked.scatter.v4i32.v4p0(<4 x i32> %value, <4 x ptr> %ptrs, i32 4, <4 x i1> )
+  ret void
+}
+
+declare <4 x i32> @llvm.masked.gather.v4i32.v4p0(<4 x ptr>, i32 immarg, <4 x i1>, <4 x i32>)
+
+declare void @llvm.masked.scatter.v4i32.v4p0(<4 x i32>, <4 x ptr>, i32 immarg, <4 x i1>)
\ No newline at end of file
Index: llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
===
--- llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
+++ llvm/test/Transforms/InferAddressSpaces/AMDGPU/icmp.ll
@@ -147,9 +147,8 @@
   ret i1 %cmp
 }
 
-; TODO: Should be handled
 ; CHECK-LABEL: @icmp_flat_flat_from_group_vector(
-; CHECK: %cmp = icmp eq <2 x ptr> %cast0, %cast1
+; CHECK: %cmp = icmp eq <2 x ptr addrspace(3)> %group.ptr.0, %group.ptr.1
 define <2 x i1> @icmp_flat_flat_from_group_vector(<2 x ptr addrspace(3)> %group.ptr.0, <2 x ptr addrspace(3)> %group.ptr.1) #0 {
   %cast0 = addrspacecast <2 x ptr addrspace(3)> %group.ptr.0 to <2 x ptr>
   %cast1 = addrspacecast <2 x ptr addrspace(3)> %group.ptr.1 to <2 x ptr>
Index: llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
===
--- llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
+++ llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
@@ -256,6 +256,21 @@
 INITIALIZE_PASS_END(InferAddressSpaces, DEBUG_TYPE, "Infer address spaces",
 false, false)
 
+static Type *getPtrOrVecOfPtrsWithNewAS(Type *Ty, unsigned NewAddrSpace) {
+  if (!Ty->isVectorTy()) {
+assert(Ty->isPointerTy());
+return PointerType::getWithSamePointeeType(cast(Ty),
+   NewAddrSpace);
+  }
+
+  Type *PT = cast(Ty)->getElementType();
+  assert(PT->isPointerTy());
+
+  Type *NPT =
+  PointerType::getWithSamePointeeType(cast(PT), NewAddrSpace);
+  return VectorType::get(NPT, cast(Ty)->getElementCount());
+}
+
 // Check whether that's no-op pointer bicast using a pair of
 // `ptrtoint`/`inttoptr` due to the missing no-op pointer bitcast over
 // different address spaces.
@@ -301,14 +316,14 @@
 
   switch (Op->getOpcode()) {
   case Instruction::PHI:
-assert(Op->getType()->isPointerTy());
+assert(Op->getType()->isPtrOrPtrVectorTy());
 return true;
   case Instruction::BitCast:
   case Instruction::AddrSpaceCast:
   case Instruction::GetElementPtr:
 return true;
   case Instruction::Select:
-return Op->getType()->isPointerTy();
+return Op->getType()->isPtrOrPtrVectorTy();
   case Instruction::Call: {
 const IntrinsicInst *II = dyn_cast(&V);
 return II && II->getIntrinsicID() == Intrinsic::ptrmask;
@@ -373,6 +388,24 @@
   case Intrinsic::ptrmask:
 // This is handled as an address expression, not as a use memory operation.
 return false;
+  case Intrinsic::masked_gather: {
+Type *RetTy = II->getType();
+Type *NewPtrTy = NewV->getType();
+Function *NewDecl =
+Intrinsic::getDeclaration(M, II->getIntrinsicID(), {RetTy, NewPtrTy});
+II->setArgOperand(0, NewV);
+II->setCalledFunction(NewDecl);
+return true;
+  }
+  case Intrinsic::masked_scatter: {
+Type *ValueTy = II->getOperand(0)->getType();
+Type *NewPtrTy = NewV->getType();
+Function *NewDecl =
+Intrinsic::getDeclaration(M, II->getIntrinsicID(), {ValueTy, NewPtrTy});
+II->setArgOperand(1, NewV);
+II->setCalledFunction(NewDecl);
+return true;
+  }
   default: {
 Value *Rewrite = TTI->rewriteIntrinsicWithAddre

[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

2023-05-08 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

Another friendly ping for review.
@erichkeane let me know if you feel that exposing the incorrect lambda 
instantiation behavior is a blocker here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

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


[PATCH] D149642: [RISCV] Support vreinterpret intrinsics between vector boolean type and m1 vector integer type

2023-05-08 Thread Yueh-Ting (eop) Chen via Phabricator via cfe-commits
eopXD added inline comments.



Comment at: 
clang/test/CodeGen/RISCV/rvv-intrinsics-autogenerated/non-policy/non-overloaded/vreinterpret.c:1
-// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
 // REQUIRES: riscv-registered-target

kito-cheng wrote:
> ` UTC_ARGS: --version 2`?
Cleared the diff with an NFC commit.



Comment at: llvm/include/llvm/IR/IntrinsicsRISCV.td:1418
 
+  def int_riscv_vreinterpret_v
+: DefaultAttrsIntrinsic<[llvm_anyvector_ty],

craig.topper wrote:
> craig.topper wrote:
> > Do we need an intrinsic?
> > 
> > m1 -> mask  is bitcast m1 vscale type to  and a 
> > llvm.experimental.vector.extract
> > mask -> m1 is llvm.experimental.vector.insert to  and a 
> > bitcast.
> oops there's no experimental in the insert/extract names.
Replacing with insert/extract here with `index = 0`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149642

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


[PATCH] D148997: [clang] Add a new annotation token: annot_repl_input_end

2023-05-08 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 520313.
junaire added a comment.

Update + Rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148997

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp

Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_repl_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -614,11 +615,6 @@
Sema::ModuleImportState &ImportState) {
   DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
 
-  // Skip over the EOF token, flagging end of previous input for incremental
-  // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
-
   Result = nullptr;
   switch (Tok.getKind()) {
   case tok::annot_pragma_unused:
@@ -697,6 +693,7 @@
 return false;
 
   case tok::eof:
+  case tok::annot_repl_input_end:
 // Check whether -fmax-tokens= was reached.
 if (PP.getMaxTokens() != 0 && PP.getTokenCount() > PP.getMaxTokens()) {
   PP.Diag(Tok.getLocation(), diag::warn_max_tokens_total)
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -544,9 +544,22 @@
 return ParseCaseStatement(StmtCtx, /*MissingCase=*/true, Expr);
   }
 
-  // Otherwise, eat the semicolon.
-  ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
-  return handleExprStmt(Expr, StmtCtx);
+  Token *CurTok = nullptr;
+  // If the semicolon is missing at the end of REPL input, consider if
+  // we want to do value printing. Note this is only enabled in C++ mode
+  // since part of the implementation requires C++ language features.
+  // Note we shouldn't eat the token since the callback needs it.
+  if (Tok.is(tok::annot_repl_input_end) && Actions.getLangOpts().CPlusPlus)
+CurTok = &Tok;
+  else
+// Otherwise, eat the semicolon.
+ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
+
+  StmtResult R = handleExprStmt(Expr, StmtCtx);
+  if (CurTok && !R.isInvalid())
+CurTok->setAnnotationValue(R.get());
+
+  return R;
 }
 
 /// ParseSEHTryBlockCommon
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2070,6 +2070,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_repl_input_end:
   return;
 
 default:
@@ -5454,6 +5455,13 @@
 
   SmallVector DeclsInGroup;
   DeclsInGroup.push_back(Actions.ActOnTopLevelStmtDecl(R.get()));
+
+  if (Tok.is(tok::annot_repl_input_end) &&
+  Tok.getAnnotationValue() != nullptr) {
+ConsumeAnnotationToken();
+cast(DeclsInGroup.back())->setSemiMissing();
+  }
+
   // Currently happens for things like  -fms-extensions and use `__if_exists`.
   for (Stmt *S : Stmts)
 DeclsInGroup.push_back(Actions.ActOnTopLevelStmtDecl(S));
Index: clang/lib/Parse/ParseCXXInlineMethods.cpp
===
--- clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -838,6 +838,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_repl_input_end:
   // Ran out of tokens.
   return false;
 
@@ -1244,6 +1245,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_repl_input_end:
   // Ran out of tokens.
   return false;
 
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -535,13 +535,19 @@
   return LeavingSubmodule;
 }
   }
-
   // If this is the end of the main file, form an EOF token.
   assert(CurLexer && "Got EOF but no current lexer set!");
   const char *EndPos = getCurLexerEndPos();
   Result.startToken();
   CurLexer->BufferPtr = EndPos;
-  CurLexer->FormTokenWithChars(Result, EndPos, tok::eof);
+
+  if (isIncrementalProcessingEnabled()) {
+CurLex

[PATCH] D150036: [Clang] Correctly handle allocation in template arguments

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

Fix release notes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150036

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


Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
===
--- clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
@@ -215,3 +215,27 @@
   }
   static_assert(h());
 }
+
+namespace GH62462 {
+
+class string {
+public:
+  char *mem;
+  constexpr string() {
+this->mem = new char(1);
+  }
+  constexpr ~string() {
+delete this->mem;
+  }
+  constexpr unsigned size() const { return 4; }
+};
+
+
+template 
+void test() {};
+
+void f() {
+test();
+}
+
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15354,8 +15354,15 @@
   LValue LVal;
   LVal.set(Base);
 
-  if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || 
Result.HasSideEffects)
-return false;
+  {
+// C++23 [intro.execution]/p5
+// A full-expression is [...] a constant-expression
+// So we need to make sure temporary objects are destroyed after having 
evaluating
+// the expression (per C++23 [class.temporary]/p4).
+FullExpressionRAII Scope(Info);
+if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || 
Result.HasSideEffects  || !Scope.destroy())
+  return false;
+  }
 
   if (!Info.discardCleanups())
 llvm_unreachable("Unhandled cleanup; missing full expression marker?");
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -381,6 +381,8 @@
 - Fix overly aggressive lifetime checks for parenthesized aggregate
   initialization.
   (`#61567 `_)
+- Fix handling of constexpr dynamic memory allocations in template
+  arguments. (`#62462 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
===
--- clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
@@ -215,3 +215,27 @@
   }
   static_assert(h());
 }
+
+namespace GH62462 {
+
+class string {
+public:
+  char *mem;
+  constexpr string() {
+this->mem = new char(1);
+  }
+  constexpr ~string() {
+delete this->mem;
+  }
+  constexpr unsigned size() const { return 4; }
+};
+
+
+template 
+void test() {};
+
+void f() {
+test();
+}
+
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15354,8 +15354,15 @@
   LValue LVal;
   LVal.set(Base);
 
-  if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || Result.HasSideEffects)
-return false;
+  {
+// C++23 [intro.execution]/p5
+// A full-expression is [...] a constant-expression
+// So we need to make sure temporary objects are destroyed after having evaluating
+// the expression (per C++23 [class.temporary]/p4).
+FullExpressionRAII Scope(Info);
+if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || Result.HasSideEffects  || !Scope.destroy())
+  return false;
+  }
 
   if (!Info.discardCleanups())
 llvm_unreachable("Unhandled cleanup; missing full expression marker?");
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -381,6 +381,8 @@
 - Fix overly aggressive lifetime checks for parenthesized aggregate
   initialization.
   (`#61567 `_)
+- Fix handling of constexpr dynamic memory allocations in template
+  arguments. (`#62462 `_)
 
 Bug Fixes to AST Handling
 ^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147319: [clang-repl] Consider the scope spec in template lookups for deduction guides

2023-05-08 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 520322.
v.g.vassilev added a comment.

Rebase.


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

https://reviews.llvm.org/D147319

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/Interpreter/disambiguate-decl-stmt.cpp


Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -7,6 +7,10 @@
 
 // Decls which are hard to disambiguate
 
+// Templates
+namespace ns1 { template void tmplt(T &) {}}
+int arg_tmplt = 12; ns1::tmplt(arg_tmplt);
+
 // ParseStatementOrDeclaration returns multiple statements.
 #ifdef MS
 int g_bFlag = 1;
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -316,9 +316,8 @@
 }
 
 bool Sema::isDeductionGuideName(Scope *S, const IdentifierInfo &Name,
-SourceLocation NameLoc,
-ParsedTemplateTy *Template) {
-  CXXScopeSpec SS;
+SourceLocation NameLoc, CXXScopeSpec &SS,
+ParsedTemplateTy *Template/*=nullptr*/) {
   bool MemberOfUnknownSpecialization = false;
 
   // We could use redeclaration lookup here, but we don't need to: the
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -76,7 +76,7 @@
 IdentifierInfo *II = Tok.getIdentifierInfo();
 bool isDeductionGuide =
 Actions.isDeductionGuideName(getCurScope(), *II, Tok.getLocation(),
- /*Template=*/nullptr);
+ SS, /*Template=*/nullptr);
 if (Actions.isCurrentClassName(*II, getCurScope(), &SS) ||
 isDeductionGuide) {
   if (isConstructorDeclarator(/*Unqualified=*/SS.isEmpty(),
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2913,7 +2913,7 @@
   Result.setConstructorName(Ty, IdLoc, IdLoc);
 } else if (getLangOpts().CPlusPlus17 &&
AllowDeductionGuide && SS.isEmpty() &&
-   Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc,
+   Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc, SS,
 &TemplateName)) {
   // We have parsed a template-name naming a deduction guide.
   Result.setDeductionGuideName(TemplateName, IdLoc);
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3696,11 +3696,12 @@
 
   // Likewise, if this is a context where the identifier could be a 
template
   // name, check whether this is a deduction guide declaration.
+  CXXScopeSpec SS;
   if (getLangOpts().CPlusPlus17 &&
   (DSContext == DeclSpecContext::DSC_class ||
DSContext == DeclSpecContext::DSC_top_level) &&
   Actions.isDeductionGuideName(getCurScope(), *Tok.getIdentifierInfo(),
-   Tok.getLocation()) &&
+   Tok.getLocation(), SS) &&
   isConstructorDeclarator(/*Unqualified*/ true,
   /*DeductionGuide*/ true))
 goto DoneWithDeclSpec;
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -8078,7 +8078,7 @@
   /// Determine whether a particular identifier might be the name in a C++1z
   /// deduction-guide declaration.
   bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name,
-SourceLocation NameLoc,
+SourceLocation NameLoc, CXXScopeSpec &SS,
 ParsedTemplateTy *Template = nullptr);
 
   bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,


Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -7,6 +7,10 @@
 
 // Decls which are hard to disambiguate
 
+// Templates
+namespace ns1 { template void tmplt(T &) {}}
+int arg_tmplt = 12; ns1::tmplt(arg_tmplt);
+
 // ParseStatementOrDeclaration returns multiple statements.
 #ifdef MS
 int g_bFlag = 1;
Index

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-05-08 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 520324.
junaire added a comment.

Rebase + Update


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Lex/PPLexerChange.cpp
  clang/lib/Parse/ParseCXXInlineMethods.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/lib/Parse/Parser.cpp

Index: clang/lib/Parse/Parser.cpp
===
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -320,6 +320,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_repl_input_end:
   // Stop before we change submodules. They generally indicate a "good"
   // place to pick up parsing again (except in the special case where
   // we're trying to skip to EOF).
@@ -614,11 +615,6 @@
Sema::ModuleImportState &ImportState) {
   DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
 
-  // Skip over the EOF token, flagging end of previous input for incremental
-  // processing
-  if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
-ConsumeToken();
-
   Result = nullptr;
   switch (Tok.getKind()) {
   case tok::annot_pragma_unused:
@@ -697,6 +693,7 @@
 return false;
 
   case tok::eof:
+  case tok::annot_repl_input_end:
 // Check whether -fmax-tokens= was reached.
 if (PP.getMaxTokens() != 0 && PP.getTokenCount() > PP.getMaxTokens()) {
   PP.Diag(Tok.getLocation(), diag::warn_max_tokens_total)
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -544,9 +544,22 @@
 return ParseCaseStatement(StmtCtx, /*MissingCase=*/true, Expr);
   }
 
-  // Otherwise, eat the semicolon.
-  ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
-  return handleExprStmt(Expr, StmtCtx);
+  Token *CurTok = nullptr;
+  // If the semicolon is missing at the end of REPL input, consider if
+  // we want to do value printing. Note this is only enabled in C++ mode
+  // since part of the implementation requires C++ language features.
+  // Note we shouldn't eat the token since the callback needs it.
+  if (Tok.is(tok::annot_repl_input_end) && Actions.getLangOpts().CPlusPlus)
+CurTok = &Tok;
+  else
+// Otherwise, eat the semicolon.
+ExpectAndConsumeSemi(diag::err_expected_semi_after_expr);
+
+  StmtResult R = handleExprStmt(Expr, StmtCtx);
+  if (CurTok && !R.isInvalid())
+CurTok->setAnnotationValue(R.get());
+
+  return R;
 }
 
 /// ParseSEHTryBlockCommon
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -2070,6 +2070,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_repl_input_end:
   return;
 
 default:
@@ -5454,6 +5455,13 @@
 
   SmallVector DeclsInGroup;
   DeclsInGroup.push_back(Actions.ActOnTopLevelStmtDecl(R.get()));
+
+  if (Tok.is(tok::annot_repl_input_end) &&
+  Tok.getAnnotationValue() != nullptr) {
+ConsumeAnnotationToken();
+cast(DeclsInGroup.back())->setSemiMissing();
+  }
+
   // Currently happens for things like  -fms-extensions and use `__if_exists`.
   for (Stmt *S : Stmts)
 DeclsInGroup.push_back(Actions.ActOnTopLevelStmtDecl(S));
Index: clang/lib/Parse/ParseCXXInlineMethods.cpp
===
--- clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -838,6 +838,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_repl_input_end:
   // Ran out of tokens.
   return false;
 
@@ -1244,6 +1245,7 @@
 case tok::annot_module_begin:
 case tok::annot_module_end:
 case tok::annot_module_include:
+case tok::annot_repl_input_end:
   // Ran out of tokens.
   return false;
 
Index: clang/lib/Lex/PPLexerChange.cpp
===
--- clang/lib/Lex/PPLexerChange.cpp
+++ clang/lib/Lex/PPLexerChange.cpp
@@ -535,13 +535,19 @@
   return LeavingSubmodule;
 }
   }
-
   // If this is the end of the main file, form an EOF token.
   assert(CurLexer && "Got EOF but no current lexer set!");
   const char *EndPos = getCurLexerEndPos();
   Result.startToken();
   CurLexer->BufferPtr = EndPos;
-  CurLexer->FormTokenWithChars(Result, EndPos, tok::eof);
+
+  if (isIncrementalProcessingEnabled()) {
+CurLex

[PATCH] D150108: [clang] Evaluate non-type default template argument when it is required

2023-05-08 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a subscriber: arphaman.
Herald added a reviewer: shafik.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Before this change a default template argument for a non-type template
parameter was evaluated and checked immediately after it is met by
parser. In some cases it is too early.

Fixes https://github.com/llvm/llvm-project/issues/62224
Fixes https://github.com/llvm/llvm-project/issues/62596


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150108

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/AST/ast-dump-decl.cpp
  clang/test/CXX/expr/expr.const/p3-0x.cpp
  clang/test/Index/Core/index-source.cpp
  clang/test/SemaCXX/GH62596.cpp
  clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
  clang/test/SemaTemplate/deduction-guide.cpp
  clang/test/SemaTemplate/temp_arg_nontype.cpp
  clang/unittests/AST/ASTImporterTest.cpp

Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -1156,8 +1156,6 @@
   NonTypeTemplateParmDecl *To = Import(From, Lang_CXX03);
   ASSERT_TRUE(To->hasDefaultArgument());
   Stmt *ToArg = To->getDefaultArgument();
-  ASSERT_TRUE(isa(ToArg));
-  ToArg = *ToArg->child_begin();
   ASSERT_TRUE(isa(ToArg));
   ASSERT_EQ(cast(ToArg)->getValue().getLimitedValue(), 1U);
 }
Index: clang/test/SemaTemplate/temp_arg_nontype.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype.cpp
@@ -204,8 +204,8 @@
 }
 
 namespace PR6964 {
-  template  // expected-warning 2{{non-type template argument value '9223372036854775807' truncated to '-1' for template parameter of type 'int'}} \
-  // expected-note 2{{template parameter is declared here}}
+  template  // expected-warning {{non-type template argument value '9223372036854775807' truncated to '-1' for template parameter of type 'int'}} \
+  // expected-note {{template parameter is declared here}}
   struct as_nview { };
 
   template  
Index: clang/test/SemaTemplate/deduction-guide.cpp
===
--- clang/test/SemaTemplate/deduction-guide.cpp
+++ clang/test/SemaTemplate/deduction-guide.cpp
@@ -224,9 +224,7 @@
 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0
 // CHECK:   `-TemplateArgument expr
 // CHECK: |   |-inherited from NonTypeTemplateParm {{.*}} '' 'char'
-// CHECK: |   `-ConstantExpr {{.*}} 'char'
-// CHECK: | |-value: Int 120
-// CHECK: | `-CharacterLiteral {{.*}} 'char' 120
+// CHECK: |   `-CharacterLiteral {{.*}} 'char' 120
 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U
 // CHECK: |-ParenExpr {{.*}} 'bool'
 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
Index: clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
===
--- clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
+++ clang/test/SemaCXX/cxx2a-consteval-default-params.cpp
@@ -79,3 +79,16 @@
 };
 void f(A a = A()) { }
 }
+
+namespace GH62224 {
+  consteval int fwd();
+  template 
+  struct C {
+consteval C(int = fwd()) { }
+consteval int get() { return i; }
+  };
+
+  consteval int fwd() { return 42; }
+  C<> Val; // No error since fwd is defined already.
+  static_assert(Val.get() == 42);
+}
Index: clang/test/SemaCXX/GH62596.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/GH62596.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+struct foo {
+  static constexpr bool bar() {
+  return true;
+  }
+
+  template
+  static constexpr bool baz() {
+  return B;
+  }
+};
+static_assert(foo::baz(), "");
+
+// expected-no-diagnostics
Index: clang/test/Index/Core/index-source.cpp
===
--- clang/test/Index/Core/index-source.cpp
+++ clang/test/Index/Core/index-source.cpp
@@ -405,7 +405,7 @@
 // CHECK: [[@LINE-1]]:23 | class/C++ | Cls | c:@S@Cls |  | Ref,RelCont | rel: 1
 // CHECK-NEXT: RelCont | TemplateDefaultValues | c:@ST>3#T#NI#t>1#T@TemplateDefaultValues
  int x = Record::C,
-// CHECK: [[@LINE-1]]:26 | static-property/C++ | C | c:@S@Record@C | __ZN6Record1CE | Ref,Read,RelCont | rel: 1
+// CHECK: [[@LINE-1]]:26 | static-property/C++ | C | c:@S@Record@C | __ZN6Record1CE | Ref,RelCont | rel: 1
 // CHECK-NEXT: RelCont | TemplateDefaultValues | c:@ST>3#T#NI#t>1#T@TemplateDefaultValues
 // CHECK: [[@LINE-3]]:18 | struct/C++ | Record | c:@S@Record |  | Ref,RelCont | rel: 1
  templa

[PATCH] D141215: [clang-repl] Introduce Value to capture expression results

2023-05-08 Thread Jun Zhang via Phabricator via cfe-commits
junaire updated this revision to Diff 520326.
junaire marked an inline comment as done.
junaire added a comment.

.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D141215

Files:
  clang/include/clang/Interpreter/Interpreter.h
  clang/include/clang/Interpreter/Value.h
  clang/lib/Interpreter/CMakeLists.txt
  clang/lib/Interpreter/IncrementalParser.cpp
  clang/lib/Interpreter/IncrementalParser.h
  clang/lib/Interpreter/Interpreter.cpp
  clang/lib/Interpreter/InterpreterUtils.cpp
  clang/lib/Interpreter/InterpreterUtils.h
  clang/lib/Interpreter/Value.cpp
  clang/tools/clang-repl/CMakeLists.txt
  clang/unittests/Interpreter/CMakeLists.txt
  clang/unittests/Interpreter/InterpreterTest.cpp

Index: clang/unittests/Interpreter/InterpreterTest.cpp
===
--- clang/unittests/Interpreter/InterpreterTest.cpp
+++ clang/unittests/Interpreter/InterpreterTest.cpp
@@ -17,6 +17,7 @@
 #include "clang/AST/Mangle.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Interpreter/Value.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
 
@@ -33,6 +34,11 @@
 #define CLANG_INTERPRETER_NO_SUPPORT_EXEC
 #endif
 
+int Global = 42;
+// JIT reports symbol not found on Windows without the visibility attribute.
+REPL_EXTERNAL_VISIBILITY int getGlobal() { return Global; }
+REPL_EXTERNAL_VISIBILITY void setGlobal(int val) { Global = val; }
+
 namespace {
 using Args = std::vector;
 static std::unique_ptr
@@ -276,8 +282,7 @@
   std::vector Args = {"-fno-delayed-template-parsing"};
   std::unique_ptr Interp = createInterpreter(Args);
 
-  llvm::cantFail(Interp->Parse("void* operator new(__SIZE_TYPE__, void* __p);"
-   "extern \"C\" int printf(const char*,...);"
+  llvm::cantFail(Interp->Parse("extern \"C\" int printf(const char*,...);"
"class A {};"
"struct B {"
"  template"
@@ -315,4 +320,95 @@
   free(NewA);
 }
 
+TEST(InterpreterTest, Value) {
+  std::unique_ptr Interp = createInterpreter();
+
+  Value V1;
+  llvm::cantFail(Interp->ParseAndExecute("int x = 42;"));
+  llvm::cantFail(Interp->ParseAndExecute("x", &V1));
+  EXPECT_TRUE(V1.isValid());
+  EXPECT_TRUE(V1.hasValue());
+  EXPECT_EQ(V1.getInt(), 42);
+  EXPECT_EQ(V1.convertTo(), 42);
+  EXPECT_TRUE(V1.getType()->isIntegerType());
+  EXPECT_EQ(V1.getKind(), Value::K_Int);
+  EXPECT_FALSE(V1.isManuallyAlloc());
+
+  Value V2;
+  llvm::cantFail(Interp->ParseAndExecute("double y = 3.14;"));
+  llvm::cantFail(Interp->ParseAndExecute("y", &V2));
+  EXPECT_TRUE(V2.isValid());
+  EXPECT_TRUE(V2.hasValue());
+  EXPECT_EQ(V2.getDouble(), 3.14);
+  EXPECT_EQ(V2.convertTo(), 3.14);
+  EXPECT_TRUE(V2.getType()->isFloatingType());
+  EXPECT_EQ(V2.getKind(), Value::K_Double);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+
+  Value V3;
+  llvm::cantFail(Interp->ParseAndExecute(
+  "struct S { int* p; S() { p = new int(42); } ~S() { delete p; }};"));
+  llvm::cantFail(Interp->ParseAndExecute("S{}", &V3));
+  EXPECT_TRUE(V3.isValid());
+  EXPECT_TRUE(V3.hasValue());
+  EXPECT_TRUE(V3.getType()->isRecordType());
+  EXPECT_EQ(V3.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V3.isManuallyAlloc());
+
+  Value V4;
+  llvm::cantFail(Interp->ParseAndExecute("int getGlobal();"));
+  llvm::cantFail(Interp->ParseAndExecute("void setGlobal(int);"));
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V4));
+  EXPECT_EQ(V4.getInt(), 42);
+  EXPECT_TRUE(V4.getType()->isIntegerType());
+
+  Value V5;
+  // Change the global from the compiled code.
+  setGlobal(43);
+  llvm::cantFail(Interp->ParseAndExecute("getGlobal()", &V5));
+  EXPECT_EQ(V5.getInt(), 43);
+  EXPECT_TRUE(V5.getType()->isIntegerType());
+
+  // Change the global from the interpreted code.
+  llvm::cantFail(Interp->ParseAndExecute("setGlobal(44);"));
+  EXPECT_EQ(getGlobal(), 44);
+
+  Value V6;
+  llvm::cantFail(Interp->ParseAndExecute("void foo() {}"));
+  llvm::cantFail(Interp->ParseAndExecute("foo()", &V6));
+  EXPECT_TRUE(V6.isValid());
+  EXPECT_FALSE(V6.hasValue());
+  EXPECT_TRUE(V6.getType()->isVoidType());
+  EXPECT_EQ(V6.getKind(), Value::K_Void);
+  EXPECT_FALSE(V2.isManuallyAlloc());
+
+  Value V7;
+  llvm::cantFail(Interp->ParseAndExecute("foo", &V7));
+  EXPECT_TRUE(V7.isValid());
+  EXPECT_TRUE(V7.hasValue());
+  EXPECT_TRUE(V7.getType()->isFunctionProtoType());
+  EXPECT_EQ(V7.getKind(), Value::K_PtrOrObj);
+  EXPECT_FALSE(V7.isManuallyAlloc());
+
+  Value V8;
+  llvm::cantFail(Interp->ParseAndExecute("struct SS{ void f() {} };"));
+  llvm::cantFail(Interp->ParseAndExecute("&SS::f", &V8));
+  EXPECT_TRUE(V8.isValid());
+  EXPECT_TRUE(V8.hasValue());
+  EXPECT_TRUE(V8.getType()->isMemberFunctionPointerType());
+  EXPECT_EQ(V8.getKind(), Value::K_PtrOrObj);
+  EXPECT_TRUE(V8.isManuall

[clang] 14f0776 - Reland "Give NullabilityKind a printing operator<<"

2023-05-08 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2023-05-08T13:07:11+02:00
New Revision: 14f0776550b5a49e1c42f49a00213f7f3fa047bf

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

LOG: Reland "Give NullabilityKind a printing operator<<"

This reverts commit 5326c9e480d70e16c2504cb5143524aff3ee2605.

The problem that caused the revert was downstream
(missing dep in user of clang).

Added: 


Modified: 
clang/include/clang/Basic/Specifiers.h
clang/lib/Basic/Diagnostic.cpp
clang/lib/Basic/IdentifierTable.cpp
clang/test/SemaObjC/nullable-result.m

Removed: 




diff  --git a/clang/include/clang/Basic/Specifiers.h 
b/clang/include/clang/Basic/Specifiers.h
index a8c35fed9997e..06279a016a507 100644
--- a/clang/include/clang/Basic/Specifiers.h
+++ b/clang/include/clang/Basic/Specifiers.h
@@ -19,6 +19,9 @@
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/ErrorHandling.h"
 
+namespace llvm {
+class raw_ostream;
+} // namespace llvm
 namespace clang {
 
   /// Define the meaning of possible values of the kind in ExplicitSpecifier.
@@ -333,6 +336,8 @@ namespace clang {
 // parameters are assumed to only get null on error.
 NullableResult,
   };
+  /// Prints human-readable debug representation.
+  llvm::raw_ostream &operator<<(llvm::raw_ostream&, NullabilityKind);
 
   /// Return true if \p L has a weaker nullability annotation than \p R. The
   /// ordering is: Unspecified < Nullable < NonNull.

diff  --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 3474acbced195..b2106b0eb6611 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -43,28 +43,12 @@ using namespace clang;
 
 const StreamingDiagnostic &clang::operator<<(const StreamingDiagnostic &DB,
  DiagNullabilityKind nullability) {
-  StringRef string;
-  switch (nullability.first) {
-  case NullabilityKind::NonNull:
-string = nullability.second ? "'nonnull'" : "'_Nonnull'";
-break;
-
-  case NullabilityKind::Nullable:
-string = nullability.second ? "'nullable'" : "'_Nullable'";
-break;
-
-  case NullabilityKind::Unspecified:
-string = nullability.second ? "'null_unspecified'" : "'_Null_unspecified'";
-break;
-
-  case NullabilityKind::NullableResult:
-assert(!nullability.second &&
-   "_Nullable_result isn't supported as context-sensitive keyword");
-string = "_Nullable_result";
-break;
-  }
-
-  DB.AddString(string);
+  DB.AddString(
+  ("'" +
+   getNullabilitySpelling(nullability.first,
+  /*isContextSensitive=*/nullability.second) +
+   "'")
+  .str());
   return DB;
 }
 

diff  --git a/clang/lib/Basic/IdentifierTable.cpp 
b/clang/lib/Basic/IdentifierTable.cpp
index 97dc5cd2d9a6d..9be42c0f95ddc 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -849,6 +849,20 @@ StringRef clang::getNullabilitySpelling(NullabilityKind 
kind,
   llvm_unreachable("Unknown nullability kind.");
 }
 
+llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, NullabilityKind NK) {
+  switch (NK) {
+  case NullabilityKind::NonNull:
+return OS << "NonNull";
+  case NullabilityKind::Nullable:
+return OS << "Nullable";
+  case NullabilityKind::NullableResult:
+return OS << "NullableResult";
+  case NullabilityKind::Unspecified:
+return OS << "Unspecified";
+  }
+  llvm_unreachable("Unknown nullability kind.");
+}
+
 diag::kind
 IdentifierTable::getFutureCompatDiagKind(const IdentifierInfo &II,
  const LangOptions &LangOpts) {

diff  --git a/clang/test/SemaObjC/nullable-result.m 
b/clang/test/SemaObjC/nullable-result.m
index 6125141e8c261..17cc1dd63810a 100644
--- a/clang/test/SemaObjC/nullable-result.m
+++ b/clang/test/SemaObjC/nullable-result.m
@@ -25,9 +25,9 @@ void test_conversion(void) {
 }
 
 void test_dup(void) {
-  id _Nullable_result _Nullable_result a; // expected-warning {{duplicate 
nullability specifier _Nullable_result}}
-  id _Nullable _Nullable_result b; // expected-error{{nullability specifier 
_Nullable_result conflicts with existing specifier '_Nullable'}}
-  id _Nullable_result _Nonnull c; // expected-error{{nullability specifier 
'_Nonnull' conflicts with existing specifier _Nullable_result}}
+  id _Nullable_result _Nullable_result a; // expected-warning {{duplicate 
nullability specifier '_Nullable_result'}}
+  id _Nullable _Nullable_result b; // expected-error{{nullability specifier 
'_Nullable_result' conflicts with existing specifier '_Nullable'}}
+  id _Nullable_result _Nonnull c; // expected-error{{nullability specifier 
'_Nonnull' conflicts with existing specifier '_Nullable_result'}}
 }
 
 @interface NoContextSensitive



__

[PATCH] D150108: [clang] Evaluate non-type default template argument when it is required

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/docs/ReleaseNotes.rst:375
+- A default argument for a non-type template parameter is evaluated and checked
+  at the point where is is required. This fixes:
+  (`#62224 `_) and




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150108

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


[PATCH] D146030: [clang][Interp] Handle LambdaExprs

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



Comment at: clang/test/AST/Interp/lambda.cpp:92
+  static_assert(foo() == 1); // expected-error {{not an integral constant 
expression}}
+}
+

tbaeder wrote:
> tbaeder wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > How about some tests like:
> > > > ```
> > > > constexpr int call_thru_func_ptr(int i) {
> > > >   auto l = [](int i) { return i; };
> > > >   int (*fp)(int) = l;
> > > >   return fp(i);  
> > > > }
> > > > static_assert(call_thru_func_ptr(12) == 12);
> > > > 
> > > > constexpr int call_through_copied_lambda(auto lam, int i) {
> > > >   auto copy = lam;
> > > >   return copy(i);
> > > > }
> > > > 
> > > > constexpr int call_through_copied_lambda(auto lam) {
> > > >   auto copy = lam;
> > > >   return copy();
> > > > }
> > > > 
> > > > void func() {
> > > >   constexpr int i = 12;
> > > >   static_assert(call_through_copied_lambda([i]() { return i; }) == 12);
> > > > }
> > > > ```
> > > Heh:
> > > ```
> > > array.cpp:1245:15: error: static assertion expression is not an integral 
> > > constant expression
> > >  1245 | static_assert(call_thru_func_ptr(12) == 12);
> > >   |   ^~~~
> > > array.cpp:1243:10: note: non-constexpr function '__invoke' cannot be used 
> > > in a constant expression
> > >  1243 |   return fp(i);
> > >   |  ^
> > > array.cpp:1245:15: note: in call to 'call_thru_func_ptr(12)'
> > >  1245 | static_assert(call_thru_func_ptr(12) == 12);
> > >   |   ^
> > > array.cpp:1239:12: note: declared here
> > >  1239 |   auto l = [](int i) { return i; };
> > >   |^
> > > 
> > > ```
> > Ah, I didn't know there is something like a "lambda static invoker". I see 
> > the current interpreter basically checks for that and then calls the lambda 
> > call operator instead. Doing that is hard for me though, because the call 
> > operator requires different arguments and I can't just itnogre the static 
> > invoker either because it has an empty body.
> Okay, I think I figured it out, I'm just special-casing the static invoker 
> and emitting byte code for its body manually. This will make the patch larger 
> though.
Hmmm, aren't you going to need to emit a body for the static invoker for 
calling through a function pointer to it (the `call_thru_func_ptr` example)? I 
would imagine you'd need to emit both the static invoker and the call operator 
and have the static invoker call the call operator.


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

https://reviews.llvm.org/D146030

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


[PATCH] D150111: [clang][Interp] Implement lambda static invokers

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

Emit custom byte code for the static invoker function.

Unfortunately, there are a few (RVO-related) cases we can't handle yet. There's 
a bigger refactoring for the initialization stuff coming that will hopefully 
take care of that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150111

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/lambda.cpp

Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -91,3 +91,58 @@
   static_assert(foo() == 1); // expected-error {{not an integral constant expression}}
 }
 
+namespace StaticInvoker {
+  constexpr int sv1(int i) {
+auto l = []() { return 12; };
+int (*fp)() = l;
+return fp();
+  }
+  static_assert(sv1(12) == 12);
+
+  constexpr int sv2(int i) {
+auto l = [](int m, float f, void *A) { return m; };
+int (*fp)(int, float, void*) = l;
+return fp(i, 4.0f, nullptr);
+  }
+  static_assert(sv2(12) == 12);
+
+  constexpr int sv3(int i) {
+auto l = [](int m, const int &n) { return m; };
+int (*fp)(int, const int &) = l;
+return fp(i, 3);
+  }
+  static_assert(sv3(12) == 12);
+
+  constexpr int sv4(int i) {
+auto l = [](int &m) { return m; };
+int (*fp)(int&) = l;
+return fp(i);
+  }
+  static_assert(sv4(12) == 12);
+
+
+
+  /// FIXME: This is broken for lambda-unrelated reasons.
+#if 0
+  constexpr int sv5(int i) {
+struct F { int a; float f; };
+auto l = [](int m, F f) { return m; };
+int (*fp)(int, F) = l;
+return fp(i, F{12, 14.0});
+  }
+  static_assert(sv5(12) == 12);
+#endif
+
+  constexpr int sv6(int i) {
+struct F { int a;
+  constexpr F(int a) : a(a) {}
+};
+
+auto l = [](int m) { return F(12); };
+F (*fp)(int) = l;
+F f = fp(i);
+
+return fp(i).a;
+  }
+  static_assert(sv6(12) == 12);
+}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1706,8 +1706,16 @@
 
 const Pointer &ThisPtr = S.Stk.peek(ThisOffset);
 
-if (!CheckInvoke(S, OpPC, ThisPtr))
-  return false;
+// If the current function is a lambda static invoker and
+// the function we're about to call is a lambda call operator,
+// skip the CheckInvoke, since the ThisPtr is a null pointer
+// anyway.
+if (!(S.Current->getFunction() &&
+  S.Current->getFunction()->isLambdaStaticInvoker() &&
+  Func->isLambdaCallOperator())) {
+  if (!CheckInvoke(S, OpPC, ThisPtr))
+return false;
+}
 
 if (S.checkingPotentialConstantExpression())
   return false;
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -17,6 +17,7 @@
 
 #include "Pointer.h"
 #include "Source.h"
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/Decl.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -65,7 +66,7 @@
 /// the argument values need to be preceeded by a Pointer for the This object.
 ///
 /// If the function uses Return Value Optimization, the arguments (and
-/// potentially the This pointer) need to be proceeded by a Pointer pointing
+/// potentially the This pointer) need to be preceeded by a Pointer pointing
 /// to the location to construct the returned value.
 ///
 /// After the function has been called, it will remove all arguments,
@@ -127,7 +128,7 @@
   SourceInfo getSource(CodePtr PC) const;
 
   /// Checks if the function is valid to call in constexpr.
-  bool isConstexpr() const { return IsValid; }
+  bool isConstexpr() const { return IsValid || isLambdaStaticInvoker(); }
 
   /// Checks if the function is virtual.
   bool isVirtual() const;
@@ -144,6 +145,22 @@
 return nullptr;
   }
 
+  /// Returns whether this function is a lambda static invoker,
+  /// which we generate custom byte code for.
+  bool isLambdaStaticInvoker() const {
+if (const auto *MD = dyn_cast(F))
+  return MD->isLambdaStaticInvoker();
+return false;
+  }
+
+  /// Returns whether this function is the call operator
+  /// of a lambda record decl.
+  bool isLambdaCallOperator() const {
+if (const auto *MD = dyn_cast(F))
+  return clang::isLambdaCallOperator(MD);
+return false;
+  }
+
   /// Checks if the function is fully done compiling.
   bool isFullyCompiled() const { return IsFullyCompiled; }
 
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
==

[PATCH] D150111: [clang][Interp] Implement lambda static invokers

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 520330.

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

https://reviews.llvm.org/D150111

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/lambda.cpp

Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -91,3 +91,58 @@
   static_assert(foo() == 1); // expected-error {{not an integral constant expression}}
 }
 
+namespace StaticInvoker {
+  constexpr int sv1(int i) {
+auto l = []() { return 12; };
+int (*fp)() = l;
+return fp();
+  }
+  static_assert(sv1(12) == 12);
+
+  constexpr int sv2(int i) {
+auto l = [](int m, float f, void *A) { return m; };
+int (*fp)(int, float, void*) = l;
+return fp(i, 4.0f, nullptr);
+  }
+  static_assert(sv2(12) == 12);
+
+  constexpr int sv3(int i) {
+auto l = [](int m, const int &n) { return m; };
+int (*fp)(int, const int &) = l;
+return fp(i, 3);
+  }
+  static_assert(sv3(12) == 12);
+
+  constexpr int sv4(int i) {
+auto l = [](int &m) { return m; };
+int (*fp)(int&) = l;
+return fp(i);
+  }
+  static_assert(sv4(12) == 12);
+
+
+
+  /// FIXME: This is broken for lambda-unrelated reasons.
+#if 0
+  constexpr int sv5(int i) {
+struct F { int a; float f; };
+auto l = [](int m, F f) { return m; };
+int (*fp)(int, F) = l;
+return fp(i, F{12, 14.0});
+  }
+  static_assert(sv5(12) == 12);
+#endif
+
+  constexpr int sv6(int i) {
+struct F { int a;
+  constexpr F(int a) : a(a) {}
+};
+
+auto l = [](int m) { return F(12); };
+F (*fp)(int) = l;
+F f = fp(i);
+
+return fp(i).a;
+  }
+  static_assert(sv6(12) == 12);
+}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1706,8 +1706,16 @@
 
 const Pointer &ThisPtr = S.Stk.peek(ThisOffset);
 
-if (!CheckInvoke(S, OpPC, ThisPtr))
-  return false;
+// If the current function is a lambda static invoker and
+// the function we're about to call is a lambda call operator,
+// skip the CheckInvoke, since the ThisPtr is a null pointer
+// anyway.
+if (!(S.Current->getFunction() &&
+  S.Current->getFunction()->isLambdaStaticInvoker() &&
+  Func->isLambdaCallOperator())) {
+  if (!CheckInvoke(S, OpPC, ThisPtr))
+return false;
+}
 
 if (S.checkingPotentialConstantExpression())
   return false;
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -17,6 +17,7 @@
 
 #include "Pointer.h"
 #include "Source.h"
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/Decl.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -65,7 +66,7 @@
 /// the argument values need to be preceeded by a Pointer for the This object.
 ///
 /// If the function uses Return Value Optimization, the arguments (and
-/// potentially the This pointer) need to be proceeded by a Pointer pointing
+/// potentially the This pointer) need to be preceeded by a Pointer pointing
 /// to the location to construct the returned value.
 ///
 /// After the function has been called, it will remove all arguments,
@@ -127,7 +128,7 @@
   SourceInfo getSource(CodePtr PC) const;
 
   /// Checks if the function is valid to call in constexpr.
-  bool isConstexpr() const { return IsValid; }
+  bool isConstexpr() const { return IsValid || isLambdaStaticInvoker(); }
 
   /// Checks if the function is virtual.
   bool isVirtual() const;
@@ -144,6 +145,22 @@
 return nullptr;
   }
 
+  /// Returns whether this function is a lambda static invoker,
+  /// which we generate custom byte code for.
+  bool isLambdaStaticInvoker() const {
+if (const auto *MD = dyn_cast(F))
+  return MD->isLambdaStaticInvoker();
+return false;
+  }
+
+  /// Returns whether this function is the call operator
+  /// of a lambda record decl.
+  bool isLambdaCallOperator() const {
+if (const auto *MD = dyn_cast(F))
+  return clang::isLambdaCallOperator(MD);
+return false;
+  }
+
   /// Checks if the function is fully done compiling.
   bool isFullyCompiled() const { return IsFullyCompiled; }
 
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -68,6 +68,8 @@
   bool visitCaseStmt(const CaseStmt *S);
   bool visitDefaultStmt(const DefaultStmt *S);
 
+  bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);
+
   /// Type of the expression returned by the function.
   std::optional ReturnType;
 

[PATCH] D150111: [clang][Interp] Implement lambda static invokers

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 520331.

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

https://reviews.llvm.org/D150111

Files:
  clang/lib/AST/Interp/ByteCodeEmitter.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.cpp
  clang/lib/AST/Interp/ByteCodeStmtGen.h
  clang/lib/AST/Interp/Function.h
  clang/lib/AST/Interp/Interp.h
  clang/test/AST/Interp/lambda.cpp

Index: clang/test/AST/Interp/lambda.cpp
===
--- clang/test/AST/Interp/lambda.cpp
+++ clang/test/AST/Interp/lambda.cpp
@@ -91,3 +91,58 @@
   static_assert(foo() == 1); // expected-error {{not an integral constant expression}}
 }
 
+namespace StaticInvoker {
+  constexpr int sv1(int i) {
+auto l = []() { return 12; };
+int (*fp)() = l;
+return fp();
+  }
+  static_assert(sv1(12) == 12);
+
+  constexpr int sv2(int i) {
+auto l = [](int m, float f, void *A) { return m; };
+int (*fp)(int, float, void*) = l;
+return fp(i, 4.0f, nullptr);
+  }
+  static_assert(sv2(12) == 12);
+
+  constexpr int sv3(int i) {
+auto l = [](int m, const int &n) { return m; };
+int (*fp)(int, const int &) = l;
+return fp(i, 3);
+  }
+  static_assert(sv3(12) == 12);
+
+  constexpr int sv4(int i) {
+auto l = [](int &m) { return m; };
+int (*fp)(int&) = l;
+return fp(i);
+  }
+  static_assert(sv4(12) == 12);
+
+
+
+  /// FIXME: This is broken for lambda-unrelated reasons.
+#if 0
+  constexpr int sv5(int i) {
+struct F { int a; float f; };
+auto l = [](int m, F f) { return m; };
+int (*fp)(int, F) = l;
+return fp(i, F{12, 14.0});
+  }
+  static_assert(sv5(12) == 12);
+#endif
+
+  constexpr int sv6(int i) {
+struct F { int a;
+  constexpr F(int a) : a(a) {}
+};
+
+auto l = [](int m) { return F(12); };
+F (*fp)(int) = l;
+F f = fp(i);
+
+return fp(i).a;
+  }
+  static_assert(sv6(12) == 12);
+}
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -1706,8 +1706,16 @@
 
 const Pointer &ThisPtr = S.Stk.peek(ThisOffset);
 
-if (!CheckInvoke(S, OpPC, ThisPtr))
-  return false;
+// If the current function is a lambda static invoker and
+// the function we're about to call is a lambda call operator,
+// skip the CheckInvoke, since the ThisPtr is a null pointer
+// anyway.
+if (!(S.Current->getFunction() &&
+  S.Current->getFunction()->isLambdaStaticInvoker() &&
+  Func->isLambdaCallOperator())) {
+  if (!CheckInvoke(S, OpPC, ThisPtr))
+return false;
+}
 
 if (S.checkingPotentialConstantExpression())
   return false;
Index: clang/lib/AST/Interp/Function.h
===
--- clang/lib/AST/Interp/Function.h
+++ clang/lib/AST/Interp/Function.h
@@ -17,6 +17,7 @@
 
 #include "Pointer.h"
 #include "Source.h"
+#include "clang/AST/ASTLambda.h"
 #include "clang/AST/Decl.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -65,7 +66,7 @@
 /// the argument values need to be preceeded by a Pointer for the This object.
 ///
 /// If the function uses Return Value Optimization, the arguments (and
-/// potentially the This pointer) need to be proceeded by a Pointer pointing
+/// potentially the This pointer) need to be preceeded by a Pointer pointing
 /// to the location to construct the returned value.
 ///
 /// After the function has been called, it will remove all arguments,
@@ -127,7 +128,7 @@
   SourceInfo getSource(CodePtr PC) const;
 
   /// Checks if the function is valid to call in constexpr.
-  bool isConstexpr() const { return IsValid; }
+  bool isConstexpr() const { return IsValid || isLambdaStaticInvoker(); }
 
   /// Checks if the function is virtual.
   bool isVirtual() const;
@@ -144,6 +145,22 @@
 return nullptr;
   }
 
+  /// Returns whether this function is a lambda static invoker,
+  /// which we generate custom byte code for.
+  bool isLambdaStaticInvoker() const {
+if (const auto *MD = dyn_cast(F))
+  return MD->isLambdaStaticInvoker();
+return false;
+  }
+
+  /// Returns whether this function is the call operator
+  /// of a lambda record decl.
+  bool isLambdaCallOperator() const {
+if (const auto *MD = dyn_cast(F))
+  return clang::isLambdaCallOperator(MD);
+return false;
+  }
+
   /// Checks if the function is fully done compiling.
   bool isFullyCompiled() const { return IsFullyCompiled; }
 
Index: clang/lib/AST/Interp/ByteCodeStmtGen.h
===
--- clang/lib/AST/Interp/ByteCodeStmtGen.h
+++ clang/lib/AST/Interp/ByteCodeStmtGen.h
@@ -68,6 +68,8 @@
   bool visitCaseStmt(const CaseStmt *S);
   bool visitDefaultStmt(const DefaultStmt *S);
 
+  bool emitLambdaStaticInvokerBody(const CXXMethodDecl *MD);
+
   /// Type of the expression returned by the function.
   std::optional ReturnType;
 

[PATCH] D150063: [clang] Restores some -std=c++2b tests.

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

LGTM, good catch!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150063

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


[PATCH] D150108: [clang] Evaluate non-type default template argument when it is required

2023-05-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. I love it when remove it code fixes a bug!
Thanks for the PR


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150108

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


[PATCH] D139837: [Clang] Implements CTAD for aggregates P1816R0 and P2082R1

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

@erichkeane @aaron.ballman I think we should determine how much works remains 
there and if the author is not responsive maybe one of us can push this up the 
finishing line.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139837

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


[PATCH] D149834: [clang][Interp] Fix ignoring TypeTraitExprs

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



Comment at: clang/test/AST/Interp/literals.cpp:875
 1 ? 0 : 1;
+sizeof(A);
+alignof(A);

tbaeder wrote:
> aaron.ballman wrote:
> > Let's make sure we still reject this:
> > ```
> > constexpr int oh_my() {
> >   int x = 0;
> >   sizeof(int[x++]); // This would usually be evaluated because VLAs are 
> > terrible
> >   return x;
> > }
> > ```
> > https://godbolt.org/z/E3jx6co46
> Hm, no, doesn't get rejected:
> ```
> array.cpp:1240:3: warning: expression result unused [-Wunused-value]
>  1240 |   sizeof(int[x++]); // This would usually be evaluated because VLAs 
> are terrible
>   |   ^~~~
> array.cpp:1243:15: error: static assertion failed due to requirement 'oh_my() 
> == 1'
>  1243 | static_assert(oh_my() == 1);
>   |   ^~~~
> array.cpp:1243:23: note: expression evaluates to '0 == 1'
>  1243 | static_assert(oh_my() == 1);
>   |   ^~~~
> ```
It looks to me like we're not modelling the side effects properly (we would 
return `1` if we were, so the `static_assert` would have passed), which might 
explain why we're failing to reject the code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149834

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


[PATCH] D149837: [clang][Interp] Fix ignoring CompoundLiteralExprs

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

LGTM!


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

https://reviews.llvm.org/D149837

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


[PATCH] D150072: [clang] Fix __is_trivially_equality_comparable for non-trivially-copyable types

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

LGTM!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150072

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


[PATCH] D149834: [clang][Interp] Fix ignoring TypeTraitExprs

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/literals.cpp:875
 1 ? 0 : 1;
+sizeof(A);
+alignof(A);

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > Let's make sure we still reject this:
> > > ```
> > > constexpr int oh_my() {
> > >   int x = 0;
> > >   sizeof(int[x++]); // This would usually be evaluated because VLAs are 
> > > terrible
> > >   return x;
> > > }
> > > ```
> > > https://godbolt.org/z/E3jx6co46
> > Hm, no, doesn't get rejected:
> > ```
> > array.cpp:1240:3: warning: expression result unused [-Wunused-value]
> >  1240 |   sizeof(int[x++]); // This would usually be evaluated because VLAs 
> > are terrible
> >   |   ^~~~
> > array.cpp:1243:15: error: static assertion failed due to requirement 
> > 'oh_my() == 1'
> >  1243 | static_assert(oh_my() == 1);
> >   |   ^~~~
> > array.cpp:1243:23: note: expression evaluates to '0 == 1'
> >  1243 | static_assert(oh_my() == 1);
> >   |   ^~~~
> > ```
> It looks to me like we're not modelling the side effects properly (we would 
> return `1` if we were, so the `static_assert` would have passed), which might 
> explain why we're failing to reject the code.
Right, I understand, I was just showing the current state. From looking at it 
though, this is not something to be fixed here, the `x++` is passed stand-alone 
to `evaluateAsRValue()`. Not sure yet what the exact problem is, I guess this 
is called before we even registered a local variable for `x`. I'll look into it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149834

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


[PATCH] D150075: Fix PR#62594 : static lambda call operator is not convertible to function pointer on win32

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

Can you also add a release note for the fix? The changes generally LGTM




Comment at: clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp:12
+  
+  auto lstatic = []() static consteval  //expected-note {{declared here}} 
expected-error{{cannot take address of consteval call}}
+  { return 3; };   





Comment at: clang/test/SemaCXX/cxx23-static-callop-lambda-expression.cpp:33
+}
\ No newline at end of file

Please add the newline to the file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150075

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


[PATCH] D150038: [Clang] Improve compile times when forming a DeclRef outside of a capturing scope.

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

Do you have some performance measurement numbers for how much benefit we get 
from the changes?




Comment at: clang/lib/Sema/SemaExpr.cpp:19195
+
+  // tryCaptureVariable is called ever ytime a DeclRef is formed,
+  // it can therefore have non-negigible impact on performances.





Comment at: clang/lib/Sema/SemaExpr.cpp:19199
+  // we can bailout early.
+  if(CapturingFunctionScopes == 0 && (!BuildAndDiagnose || VarDC == DC))
+return true;




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150038

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


[PATCH] D150038: [Clang] Improve compile times when forming a DeclRef outside of a capturing scope.

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

In D150038#4326549 , @aaron.ballman 
wrote:

> Do you have some performance measurement numbers for how much benefit we get 
> from the changes?

Not really.
The PR that changed the scope of trailing return type had a 0.35% regression, I 
expect this to be in the same ballpark in the other direction
http://llvm-compile-time-tracker.com/compare.php?from=cd173cbd7cca69c29df42cd4b42e60433435c29b&to=d708a186b6a9b050d09558163dd353d9f738c82d&stat=instructions%3Au


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150038

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


[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-05-08 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 520337.
skatrak added a comment.

Remove handling of `atomic_default_mem_order`, as it's now done in semantics. 
Fix conflicts with changes to parent patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

Files:
  flang/include/flang/Lower/OpenMP.h
  flang/lib/Lower/Bridge.cpp
  flang/lib/Lower/OpenMP.cpp
  flang/test/Lower/OpenMP/requires-notarget.f90
  flang/test/Lower/OpenMP/requires.f90
  mlir/lib/Dialect/OpenMP/CMakeLists.txt

Index: mlir/lib/Dialect/OpenMP/CMakeLists.txt
===
--- mlir/lib/Dialect/OpenMP/CMakeLists.txt
+++ mlir/lib/Dialect/OpenMP/CMakeLists.txt
@@ -12,4 +12,5 @@
   LINK_LIBS PUBLIC
   MLIRIR
   MLIRLLVMDialect
+  MLIRFuncDialect
   )
Index: flang/test/Lower/OpenMP/requires.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires.f90
@@ -0,0 +1,13 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks the lowering of requires into MLIR
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.requires = #omp
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f
+  !$omp declare target
+end subroutine f
Index: flang/test/Lower/OpenMP/requires-notarget.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-notarget.f90
@@ -0,0 +1,11 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  module attributes {
+!CHECK-NOT:  omp.requires
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
Index: flang/lib/Lower/OpenMP.cpp
===
--- flang/lib/Lower/OpenMP.cpp
+++ flang/lib/Lower/OpenMP.cpp
@@ -24,7 +24,9 @@
 #include "flang/Semantics/tools.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
 #include "mlir/Dialect/SCF/IR/SCF.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
 
 using namespace mlir;
 
@@ -2262,14 +2264,14 @@
   converter.bindSymbol(sym, symThreadprivateExv);
 }
 
-void handleDeclareTarget(Fortran::lower::AbstractConverter &converter,
- Fortran::lower::pft::Evaluation &eval,
- const Fortran::parser::OpenMPDeclareTargetConstruct
- &declareTargetConstruct) {
-  llvm::SmallVector,
-0>
-  symbolAndClause;
+/// Extract the list of function and variable symbols affected by the given
+/// 'declare target' directive and return the intended device type for them.
+static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo(
+Fortran::lower::pft::Evaluation &eval,
+const Fortran::parser::OpenMPDeclareTargetConstruct &declareTargetConstruct,
+SmallVectorImpl> &symbolAndClause) {
+  // Gather the symbols and clauses
   auto findFuncAndVarSyms = [&](const Fortran::parser::OmpObjectList &objList,
 mlir::omp::DeclareTargetCaptureClause clause) {
 for (const auto &ompObject : objList.v) {
@@ -2289,12 +2291,11 @@
 }
   };
 
+  // The default capture type
+  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   const auto &spec{std::get(
   declareTargetConstruct.t)};
-  auto mod = converter.getFirOpBuilder().getModule();
 
-  // The default capture type
-  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   if (const auto *objectList{
   Fortran::parser::Unwrap(spec.u)}) {
 // Case: declare target(func, var1, var2)
@@ -2330,6 +2331,28 @@
 }
   }
 
+  switch (deviceType) {
+  case Fortran::parser::OmpDeviceTypeClause::Type::Any:
+return mlir::omp::DeclareTargetDeviceType::any;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Host:
+return mlir::omp::DeclareTargetDeviceType::host;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Nohost:
+return mlir::omp::DeclareTargetDeviceType::nohost;
+  }
+}
+
+void handleDeclareTarget(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ const Fortran::parser::OpenMPDeclareTargetConstruct
+ &declareTargetConstruct) {
+  llvm::SmallVector,
+0>
+  symbolAndClause;
+  auto deviceType =
+  getDeclareTargetInfo(eval, declareTargetConstruct, symbolAndClause);
+
+  auto mod = converter.getFirOpBuilder().getModule();
   for (auto sym : symbolAndClause) {
 auto *op = mod.look

[PATCH] D149834: [clang][Interp] Fix ignoring TypeTraitExprs

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/literals.cpp:875
 1 ? 0 : 1;
+sizeof(A);
+alignof(A);

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > Let's make sure we still reject this:
> > > > ```
> > > > constexpr int oh_my() {
> > > >   int x = 0;
> > > >   sizeof(int[x++]); // This would usually be evaluated because VLAs are 
> > > > terrible
> > > >   return x;
> > > > }
> > > > ```
> > > > https://godbolt.org/z/E3jx6co46
> > > Hm, no, doesn't get rejected:
> > > ```
> > > array.cpp:1240:3: warning: expression result unused [-Wunused-value]
> > >  1240 |   sizeof(int[x++]); // This would usually be evaluated because 
> > > VLAs are terrible
> > >   |   ^~~~
> > > array.cpp:1243:15: error: static assertion failed due to requirement 
> > > 'oh_my() == 1'
> > >  1243 | static_assert(oh_my() == 1);
> > >   |   ^~~~
> > > array.cpp:1243:23: note: expression evaluates to '0 == 1'
> > >  1243 | static_assert(oh_my() == 1);
> > >   |   ^~~~
> > > ```
> > It looks to me like we're not modelling the side effects properly (we would 
> > return `1` if we were, so the `static_assert` would have passed), which 
> > might explain why we're failing to reject the code.
> Right, I understand, I was just showing the current state. From looking at it 
> though, this is not something to be fixed here, the `x++` is passed 
> stand-alone to `evaluateAsRValue()`. Not sure yet what the exact problem is, 
> I guess this is called before we even registered a local variable for `x`. 
> I'll look into it.
Fun, the `ArgumentExpr` is just `x++`:
```
  |-UnaryExprOrTypeTraitExpr 0x62172430  'unsigned 
long' sizeof 'int[x++]'
  | `-UnaryOperator 0x62172378  'int' postfix '++'
  |   `-DeclRefExpr 0x62172350  'int' lvalue Var 0x621721a0 'x' 
'int'
```
it's simple to implement just rejecting it by just doing 
`discard(ArgumentExpr)`, but that doesn't emit any diagnostics.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149834

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


[PATCH] D149834: [clang][Interp] Fix ignoring TypeTraitExprs

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/literals.cpp:875
 1 ? 0 : 1;
+sizeof(A);
+alignof(A);

tbaeder wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > tbaeder wrote:
> > > > aaron.ballman wrote:
> > > > > Let's make sure we still reject this:
> > > > > ```
> > > > > constexpr int oh_my() {
> > > > >   int x = 0;
> > > > >   sizeof(int[x++]); // This would usually be evaluated because VLAs 
> > > > > are terrible
> > > > >   return x;
> > > > > }
> > > > > ```
> > > > > https://godbolt.org/z/E3jx6co46
> > > > Hm, no, doesn't get rejected:
> > > > ```
> > > > array.cpp:1240:3: warning: expression result unused [-Wunused-value]
> > > >  1240 |   sizeof(int[x++]); // This would usually be evaluated because 
> > > > VLAs are terrible
> > > >   |   ^~~~
> > > > array.cpp:1243:15: error: static assertion failed due to requirement 
> > > > 'oh_my() == 1'
> > > >  1243 | static_assert(oh_my() == 1);
> > > >   |   ^~~~
> > > > array.cpp:1243:23: note: expression evaluates to '0 == 1'
> > > >  1243 | static_assert(oh_my() == 1);
> > > >   |   ^~~~
> > > > ```
> > > It looks to me like we're not modelling the side effects properly (we 
> > > would return `1` if we were, so the `static_assert` would have passed), 
> > > which might explain why we're failing to reject the code.
> > Right, I understand, I was just showing the current state. From looking at 
> > it though, this is not something to be fixed here, the `x++` is passed 
> > stand-alone to `evaluateAsRValue()`. Not sure yet what the exact problem 
> > is, I guess this is called before we even registered a local variable for 
> > `x`. I'll look into it.
> Fun, the `ArgumentExpr` is just `x++`:
> ```
>   |-UnaryExprOrTypeTraitExpr 0x62172430  'unsigned 
> long' sizeof 'int[x++]'
>   | `-UnaryOperator 0x62172378  'int' postfix '++'
>   |   `-DeclRefExpr 0x62172350  'int' lvalue Var 0x621721a0 
> 'x' 'int'
> ```
> it's simple to implement just rejecting it by just doing 
> `discard(ArgumentExpr)`, but that doesn't emit any diagnostics.
... and now I just realized that the tests for this patch don't even fit with 
the changes themselves. `TypeTraitExpr` is not for `sizeof` and `alignof`...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149834

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


[PATCH] D149904: Generic selection expressions that accept a type operand

2023-05-08 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 520338.
aaron.ballman marked 2 inline comments as done.
aaron.ballman added a comment.

Added a test case for packs based on review feedback.


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

https://reviews.llvm.org/D149904

Files:
  clang/docs/LanguageExtensions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/Features.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ComputeDependence.cpp
  clang/lib/AST/Expr.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/Analysis/ExprMutationAnalyzer.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaExprObjC.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaPseudoObject.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/test/Lexer/has_extension.c
  clang/test/Parser/generic-selection-type-extension-pedantic.c
  clang/test/Parser/generic-selection-type-extension.c
  clang/test/Sema/generic-selection-type-extension.c
  clang/test/SemaCXX/generic-selection.cpp

Index: clang/test/SemaCXX/generic-selection.cpp
===
--- clang/test/SemaCXX/generic-selection.cpp
+++ clang/test/SemaCXX/generic-selection.cpp
@@ -3,7 +3,7 @@
 template 
 struct A {
   enum {
-id = _Generic(T(), // expected-error {{controlling expression type 'char' not compatible with any generic association type}}
+id = _Generic(T{}, // expected-error {{controlling expression type 'char' not compatible with any generic association type}}
 int: 1, // expected-note {{compatible type 'int' specified here}}
 float: 2,
 U: 3) // expected-error {{type 'int' in generic association compatible with previously specified type 'int'}}
@@ -20,7 +20,7 @@
 template 
 struct B {
   enum {
-id = _Generic(T(),
+id = _Generic(T{},
 int: 1, // expected-note {{compatible type 'int' specified here}}
 int: 2, // expected-error {{type 'int' in generic association compatible with previously specified type 'int'}}
 U: 3)
@@ -37,7 +37,7 @@
 
 template  struct TypeMask {
   enum {
-   result = Or<_Generic(Args(), int: 1, long: 2, short: 4, float: 8)...>::result
+   result = Or<_Generic(Args{}, int: 1, long: 2, short: 4, float: 8)...>::result
   };
 };
 
Index: clang/test/Sema/generic-selection-type-extension.c
===
--- /dev/null
+++ clang/test/Sema/generic-selection-type-extension.c
@@ -0,0 +1,136 @@
+// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify -Wno-unused %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wno-unused -x c++ %s
+
+// Test that the semantic behavior of the extension allowing the user to pass a
+// type as the first argument to _Generic.
+
+// Test that we match on basic types.
+static_assert(_Generic(int, int : 1, default : 0) == 1);
+static_assert(_Generic(_BitInt(12), int : 1, _BitInt(10) : 2, _BitInt(12) : 3) == 3);
+
+// Test that we correctly fall back to the default association appropriately.
+static_assert(_Generic(int, long : 1, default : 0) == 0);
+
+// Ensure we correctly match constant arrays by their extent.
+static_assert(_Generic(int[12], int[0] : 0, int * : 0, int[12] : 1, default : 0) == 1);
+
+// Ensure we correctly match function types by their signature.
+static_assert(_Generic(int(int), void(void) : 0, int(void) : 0, void(int) : 0, int(int) : 1, default : 0) == 1);
+
+// Test that we still diagnose when no associations match and that the
+// diagnostic includes qualifiers.
+static_assert(_Generic(const int, long : 1)); // expected-error {{controlling expression type 'const int' not compatible with any generic association type}}
+
+// Test that qualifiers work as expected and do not issue a diagnostic when
+// using the type form.
+static_assert(_Generic(const int, int : 0, const int : 1) == 1);
+static_assert(_Generic(int volatile _Atomic const, int : 0, const int : 0, volatile int : 0, _Atomic int : 0, _Atomic const volatile int : 1) == 1);
+
+// Test that inferred qualifiers also work as expected.
+const int ci = 0;
+static_assert(_Generic(__typeof__(ci), int : 0, const int : 1) == 1);
+// And that the expression form still complains about qualified associations
+// and matches the correct association.
+static_assert(_Generic(ci, int : 1, const int : 0) == 1); // expected-warning {{due to lvalue conversion of the controlling expression, association of type 'const int' will never be selected because it is qualified}}
+
+// The type operand form of _Generic allows incomplete and non-object types,
+// but the expression operand form sti

[PATCH] D150038: [Clang] Improve compile times when forming a DeclRef outside of a capturing scope.

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

In D150038#4326554 , @cor3ntin wrote:

> In D150038#4326549 , @aaron.ballman 
> wrote:
>
>> Do you have some performance measurement numbers for how much benefit we get 
>> from the changes?
>
> Not really.
> The PR that changed the scope of trailing return type had a 0.35% regression, 
> I expect this to be in the same ballpark in the other direction
> http://llvm-compile-time-tracker.com/compare.php?from=cd173cbd7cca69c29df42cd4b42e60433435c29b&to=d708a186b6a9b050d09558163dd353d9f738c82d&stat=instructions%3Au

We usually want performance-related changes to come with some hard measurements 
because of how painfully easy it is to think something will result in a 
positive performance change that ends up being a wash. Would you mind putting a 
branch up on the compile time tracker page to validate your expectations? .35% 
better performance would be nice to see!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150038

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


[PATCH] D149834: [clang][Interp] Fix ignoring TypeTraitExprs

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 520340.

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

https://reviews.llvm.org/D149834

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -872,6 +872,7 @@
 (void)5, (void)6;
 
 1 ? 0 : 1;
+__is_trivial(int);
 
 return 0;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1038,6 +1038,8 @@
 
 template 
 bool ByteCodeExprGen::VisitTypeTraitExpr(const TypeTraitExpr *E) {
+  if (DiscardResult)
+return true;
   return this->emitConstBool(E->getValue(), E);
 }
 


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -872,6 +872,7 @@
 (void)5, (void)6;
 
 1 ? 0 : 1;
+__is_trivial(int);
 
 return 0;
   }
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1038,6 +1038,8 @@
 
 template 
 bool ByteCodeExprGen::VisitTypeTraitExpr(const TypeTraitExpr *E) {
+  if (DiscardResult)
+return true;
   return this->emitConstBool(E->getValue(), E);
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D148506: [C++] Don't filter using declaration when we perform qualified look up

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

Give folks another 48 hrs to disagree, but this seems fine to me/consistent 
with other comments.




Comment at: clang/lib/Sema/SemaDecl.cpp:1824
 
-static bool isUsingDecl(NamedDecl *D) {
+static bool isUsingDeclAtClassScope(NamedDecl *D) {
+  if (D->getDeclContext()->isFileContext())

ChuanqiXu wrote:
> This is the ad-hoc change. Look at the following comment.
So this name isn't really what you're doing. 


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

https://reviews.llvm.org/D148506

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


[PATCH] D150040: [clang][Interp] Call invalid destructors

2023-05-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/test/AST/Interp/records.cpp:606
+S{}; // ref-note {{in call to '&S{}->~S()'}}
+return 1; // expected-note {{in call to '&S{}->~S()'}}
+  // FIXME: ^ Wrong line

Which DTOR is happening here that changes behavior in this patch?  You removed 
the `isConstexpr` test, but it seems to me that the `S` destructor is 
constexpr, right?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150040

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


[PATCH] D144999: [RFC][MC][MachO]Only emits compact-unwind format for "canonical" personality symbols. For the rest, use DWARFs.

2023-05-08 Thread Vy Nguyen via Phabricator via cfe-commits
oontvoo updated this revision to Diff 520344.
oontvoo added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144999

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/femit-dwarf-unwind.c
  clang/test/Driver/femit-dwarf-unwind.s
  clang/tools/driver/cc1as_main.cpp
  lld/MachO/UnwindInfoSection.cpp
  lld/test/MachO/Inputs/eh-frame-x86_64-r.o
  lld/test/MachO/compact-unwind-both-local-and-dylib-personality.s
  lld/test/MachO/compact-unwind-generated.test
  lld/test/MachO/compact-unwind-lsda-folding.s
  lld/test/MachO/compact-unwind-stack-ind.s
  lld/test/MachO/compact-unwind.s
  lld/test/MachO/eh-frame-personality-dedup.s
  lld/test/MachO/eh-frame.s
  lld/test/MachO/icf-only-lsda-folded.s
  lld/test/MachO/icf.s
  lld/test/MachO/invalid/compact-unwind-bad-reloc.s
  lld/test/MachO/invalid/compact-unwind-personalities.s
  llvm/include/llvm/MC/MCAsmBackend.h
  llvm/include/llvm/MC/MCContext.h
  llvm/include/llvm/MC/MCTargetOptions.h
  llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h
  llvm/lib/MC/MCAsmBackend.cpp
  llvm/lib/MC/MCContext.cpp
  llvm/lib/MC/MCStreamer.cpp
  llvm/lib/MC/MCTargetOptionsCommandFlags.cpp
  llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
  llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackendDarwin.h
  llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
  llvm/test/CodeGen/X86/2014-08-29-CompactUnwind.ll
  llvm/test/CodeGen/X86/compact-unwind.ll
  llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
  llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s
  llvm/test/MC/MachO/ARM/compact-unwind-armv7k.s
  llvm/test/MC/X86/compact-unwind.s

Index: llvm/test/MC/X86/compact-unwind.s
===
--- llvm/test/MC/X86/compact-unwind.s
+++ llvm/test/MC/X86/compact-unwind.s
@@ -1,4 +1,4 @@
-# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin10.0 %s | llvm-objdump --unwind-info - | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin10.0 %s -emit-compact-unwind-non-canonical=true | llvm-objdump --unwind-info - | FileCheck %s
 
 	.section	__TEXT,__text,regular,pure_instructions
 	.macosx_version_min 10, 10
Index: llvm/test/MC/MachO/ARM/compact-unwind-armv7k.s
===
--- llvm/test/MC/MachO/ARM/compact-unwind-armv7k.s
+++ llvm/test/MC/MachO/ARM/compact-unwind-armv7k.s
@@ -1,4 +1,4 @@
-@ RUN: llvm-mc -triple=thumbv7k-apple-watchos2.0.0 -filetype=obj -o %t < %s && llvm-objdump --unwind-info %t | FileCheck %s
+@ RUN: llvm-mc -triple=thumbv7k-apple-watchos2.0.0 -emit-compact-unwind-non-canonical=true -filetype=obj -o %t < %s && llvm-objdump --unwind-info %t | FileCheck %s
 
 @ CHECK: Contents of __compact_unwind section:
 
Index: llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s
===
--- llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s
+++ llvm/test/MC/MachO/AArch64/emit-dwarf-unwind.s
@@ -1,11 +1,11 @@
 // RUN: rm -rf %t; mkdir %t
-// RUN: llvm-mc -triple x86_64-apple-macos11.0 %s -filetype=obj -o %t/x86_64.o
+// RUN: llvm-mc -triple x86_64-apple-macos11.0 %s -filetype=obj -o %t/x86_64.o -emit-compact-unwind-non-canonical=true
 // RUN: llvm-objdump --macho --dwarf=frames %t/x86_64.o | FileCheck %s --check-prefix TWO-FDES
-// RUN: llvm-mc -triple arm64-apple-macos11.0 %s -filetype=obj -o %t/arm64.o
+// RUN: llvm-mc -triple arm64-apple-macos11.0 %s -filetype=obj -o %t/arm64.o -emit-compact-unwind-non-canonical=true
 // RUN: llvm-objdump --macho --dwarf=frames %t/arm64.o | FileCheck %s --check-prefix ONE-FDE
-// RUN: llvm-mc -triple x86_64-apple-macos11.0 %s -filetype=obj --emit-dwarf-unwind no-compact-unwind -o %t/x86_64-no-dwarf.o
+// RUN: llvm-mc -triple x86_64-apple-macos11.0 %s -filetype=obj --emit-dwarf-unwind no-compact-unwind -o %t/x86_64-no-dwarf.o -emit-compact-unwind-non-canonical=true
 // RUN: llvm-objdump --macho --dwarf=frames %t/x86_64-no-dwarf.o | FileCheck %s --check-prefix ONE-FDE
-// RUN: llvm-mc -triple arm64-apple-macos11.0 %s -filetype=obj --emit-dwarf-unwind always -o %t/arm64-dwarf.o
+// RUN: llvm-mc -triple arm64-apple-macos11.0 %s -filetype=obj --emit-dwarf-unwind always -o %t/arm64-dwarf.o -emit-compact-unwind-non-canonical=true
 // RUN: llvm-objdump --macho --dwarf=frames %t/arm64-dwarf.o | FileCheck %s --check-prefix TWO-FDES
 
 // TWO-FDES: FDE
Index: llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
===
--- llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
+++ llvm/test/MC/AArch64/arm64-leaf-compact-unwind.s
@@ -1,4 +1,4 @@
-// RUN: llvm-mc -triple=arm64-apple-ios -filetype=obj < %s | \
+// RUN: llvm-mc -triple=arm64-apple-ios -filety

[PATCH] D150040: [clang][Interp] Call invalid destructors

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/records.cpp:606
+S{}; // ref-note {{in call to '&S{}->~S()'}}
+return 1; // expected-note {{in call to '&S{}->~S()'}}
+  // FIXME: ^ Wrong line

erichkeane wrote:
> Which DTOR is happening here that changes behavior in this patch?  You 
> removed the `isConstexpr` test, but it seems to me that the `S` destructor is 
> constexpr, right?
`Function::isConstexpr()` doesn't return the same as 
`FunctionDecl::isConstexpr()` - it's just `return IsValid` right now, so if the 
compilation of the function aborts at any point, `Function::isConstexpr()` 
returns `false` (even if the function that was compiled is `constexpr`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150040

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


[PATCH] D150114: [Headers][doc] Add "add/sub/mul" intrinsic descriptions to avx2intrin.h

2023-05-08 Thread Paul Robinson via Phabricator via cfe-commits
probinson created this revision.
probinson added reviewers: pengfei, RKSimon, goldstein.w.n, craig.topper.
Herald added a project: All.
probinson requested review of this revision.

https://reviews.llvm.org/D150114

Files:
  clang/lib/Headers/avx2intrin.h

Index: clang/lib/Headers/avx2intrin.h
===
--- clang/lib/Headers/avx2intrin.h
+++ clang/lib/Headers/avx2intrin.h
@@ -65,48 +65,150 @@
   return (__m256i) __builtin_ia32_packusdw256((__v8si)__V1, (__v8si)__V2);
 }
 
+/// Adds 8-bit integers from corresponding bytes of two 256-bit integer
+///vectors and returns the lower 8 bits of each sum in the corresponding
+///byte of the 256-bit integer vector result (overflow is ignored).
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPADDB instruction.
+///
+/// \param __a
+///A 256-bit vector containing one of the source operands.
+/// \param __b
+///A 256-bit vector containing one of the source operands.
+/// \returns A 256-bit vector containing the sums.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_add_epi8(__m256i __a, __m256i __b)
 {
   return (__m256i)((__v32qu)__a + (__v32qu)__b);
 }
 
+/// Adds 16-bit integers from corresponding elements of two 256-bit vectors of
+///[16 x i16] and returns the lower 16 bits of each sum in the
+///corresponding element of the [16 x i16] result (overflow is ignored).
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPADDW instruction.
+///
+/// \param __a
+///A 256-bit vector of [16 x i16] containing one of the source operands.
+/// \param __b
+///A 256-bit vector of [16 x i16] containing one of the source operands.
+/// \returns A 256-bit vector of [16 x i16] containing the sums.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_add_epi16(__m256i __a, __m256i __b)
 {
   return (__m256i)((__v16hu)__a + (__v16hu)__b);
 }
 
+/// Adds 32-bit integers from corresponding elements of two 256-bit vectors of
+///[8 x i32] and returns the lower 32 bits of each sum in the corresponding
+///element of the [8 x i32] result (overflow is ignored).
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPADDD instruction.
+///
+/// \param __a
+///A 256-bit vector of [8 x i32] containing one of the source operands.
+/// \param __b
+///A 256-bit vector of [8 x i32] containing one of the source operands.
+/// \returns A 256-bit vector of [8 x i32] containing the sums.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_add_epi32(__m256i __a, __m256i __b)
 {
   return (__m256i)((__v8su)__a + (__v8su)__b);
 }
 
+/// Adds 64-bit integers from corresponding elements of two 256-bit vectors of
+///[4 x i64] and returns the lower 64 bits of each sum in the corresponding
+///element of the [4 x i64] result (overflow is ignored).
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPADDQ instruction.
+///
+/// \param __a
+///A 256-bit vector of [4 x i64] containing one of the source operands.
+/// \param __b
+///A 256-bit vector of [4 x i64] containing one of the source operands.
+/// \returns A 256-bit vector of [4 x i64] containing the sums.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_add_epi64(__m256i __a, __m256i __b)
 {
   return (__m256i)((__v4du)__a + (__v4du)__b);
 }
 
+/// Adds 8-bit integers from corresponding bytes of two 256-bit integer
+///vectors using signed saturation, and returns each sum in the
+///corresponding byte of the 256-bit integer vector result.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPADDSB instruction.
+///
+/// \param __a
+///A 256-bit vector containing one of the source operands.
+/// \param __b
+///A 256-bit vector containing one of the source operands.
+/// \returns A 256-bit vector containing the sums.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_adds_epi8(__m256i __a, __m256i __b)
 {
   return (__m256i)__builtin_elementwise_add_sat((__v32qs)__a, (__v32qs)__b);
 }
 
+/// Adds 16-bit integers from corresponding elements of two 256-bit vectors of
+///[16 x i16] using signed saturation, and returns the [16 x i16] result.
+///
+/// \headerfile 
+///
+/// This intrinsic corresponds to the \c VPADDSW instruction.
+///
+/// \param __a
+///A 256-bit vector of [16 x i16] containing one of the source operands.
+/// \param __b
+///A 256-bit vector of [16 x i16] containing one of the source operands.
+/// \returns A 256-bit vector of [16 x i16] containing the sums.
 static __inline__ __m256i __DEFAULT_FN_ATTRS256
 _mm256_adds_epi16(__m256i __a, __m256i __b)
 {
   return (__m256i)__builtin_elementwise_add_sat((__v16hi)__a, (__v16hi)__b);
 }
 
+/// Adds 8-bit integers from corresponding bytes of two 256-bit integer
+///vectors using unsigned saturation, and returns each sum in the
+///corresponding byte of the 256-bit integer vector result.
+///
+/// \headerfile 
+///

[PATCH] D149965: [clang][Interp] Fix tests for ignored expressions

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 520352.
tbaeder added a comment.

@aaron.ballman This is where the sizeof/alignof tests were actually broken.


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

https://reviews.llvm.org/D149965

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/test/AST/Interp/literals.cpp


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -196,6 +196,21 @@
 // ref-error {{must be initialized 
by a constant expression}}
   }
 
+#if __cplusplus >= 201402L
+  constexpr int IgnoredRejected() { // ref-error {{never produces a constant 
expression}}
+int n = 0;
+sizeof(int[n++]); // expected-warning {{expression result unused}} \
+  // ref-warning {{expression result unused}} \
+  // ref-note 2{{subexpression not valid in a constant 
expression}}
+return n;
+  }
+  /// FIXME: This is rejected because the parameter so sizeof() is not 
constant.
+  ///   produce a proper diagnostic.
+  static_assert(IgnoredRejected() == 0, ""); // expected-error {{not an 
integral constant expression}} \
+ // ref-error {{not an integral 
constant expression}} \
+ // ref-note {{in call to 
'IgnoredRejected()'}}
+#endif
+
 
 #if __cplusplus >= 202002L
   /// FIXME: The following code should be accepted.
@@ -886,7 +901,7 @@
   struct A{ int a; };
   constexpr int ignoredExprs() {
 (void)(1 / 2);
-A a;
+A a{12};
 a;
 (void)a;
 (a);
@@ -902,9 +917,12 @@
 arr[0];
 "a";
 'b';
+sizeof(int);
+alignof(int);
 
 return 0;
   }
+  static_assert(ignoredExprs() == 0, "");
 
   constexpr int oh_my(int x) {
 (int){ x++ };
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -200,6 +200,8 @@
   case CK_NoOp:
   case CK_UserDefinedConversion:
   case CK_BitCast:
+if (DiscardResult)
+  return this->discard(SubExpr);
 return this->visit(SubExpr);
 
   case CK_IntegralToBoolean:
@@ -588,6 +590,9 @@
   Size = ASTCtx.getTypeSizeInChars(ArgType);
 }
 
+if (DiscardResult)
+  return true;
+
 return this->emitConst(Size.getQuantity(), E);
   }
 
@@ -618,6 +623,9 @@
 Size = AlignOfType(Arg->getType(), ASTCtx, Kind);
 }
 
+if (DiscardResult)
+  return true;
+
 return this->emitConst(Size.getQuantity(), E);
   }
 


Index: clang/test/AST/Interp/literals.cpp
===
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -196,6 +196,21 @@
 // ref-error {{must be initialized by a constant expression}}
   }
 
+#if __cplusplus >= 201402L
+  constexpr int IgnoredRejected() { // ref-error {{never produces a constant expression}}
+int n = 0;
+sizeof(int[n++]); // expected-warning {{expression result unused}} \
+  // ref-warning {{expression result unused}} \
+  // ref-note 2{{subexpression not valid in a constant expression}}
+return n;
+  }
+  /// FIXME: This is rejected because the parameter so sizeof() is not constant.
+  ///   produce a proper diagnostic.
+  static_assert(IgnoredRejected() == 0, ""); // expected-error {{not an integral constant expression}} \
+ // ref-error {{not an integral constant expression}} \
+ // ref-note {{in call to 'IgnoredRejected()'}}
+#endif
+
 
 #if __cplusplus >= 202002L
   /// FIXME: The following code should be accepted.
@@ -886,7 +901,7 @@
   struct A{ int a; };
   constexpr int ignoredExprs() {
 (void)(1 / 2);
-A a;
+A a{12};
 a;
 (void)a;
 (a);
@@ -902,9 +917,12 @@
 arr[0];
 "a";
 'b';
+sizeof(int);
+alignof(int);
 
 return 0;
   }
+  static_assert(ignoredExprs() == 0, "");
 
   constexpr int oh_my(int x) {
 (int){ x++ };
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -200,6 +200,8 @@
   case CK_NoOp:
   case CK_UserDefinedConversion:
   case CK_BitCast:
+if (DiscardResult)
+  return this->discard(SubExpr);
 return this->visit(SubExpr);
 
   case CK_IntegralToBoolean:
@@ -588,6 +590,9 @@
   Size = ASTCtx.getTypeSizeInChars(ArgType);
 }
 
+if (DiscardResult)
+  return true;
+
 return this->emitConst(Size.getQuantity(), E);
   }
 
@@ -618,6 +623,9 @@
 Size = AlignOfType(Arg->getType(), ASTCt

[PATCH] D150116: clang-format: [JS] support import/export type

2023-05-08 Thread Jan Kühle via Phabricator via cfe-commits
jankuehle created this revision.
jankuehle added a project: clang-format.
Herald added projects: All, clang.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
jankuehle requested review of this revision.

Users can choose to only import/export the type of the symbol (not value nor 
namespace) by adding a `type` keyword, e.g.:

  import type {x} from 'y';
  import {type x} from 'y';
  export type {x};
  export {type x};

Previously, this was not handled and would:

- Terminate import sorting
- Remove the space before the curly bracket in `export type {`

With this change, both formatting and import sorting work as expected.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150116

Files:
  clang/lib/Format/SortJavaScriptImports.cpp
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/unittests/Format/FormatTestJS.cpp
  clang/unittests/Format/SortImportsTestJS.cpp

Index: clang/unittests/Format/SortImportsTestJS.cpp
===
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -465,6 +465,46 @@
  "console.log(Z);\n");
 }
 
+TEST_F(SortImportsTestJS, ImportExportType) {
+  verifySort("import type {sym} from 'a';\n"
+ "import {type sym} from 'b';\n"
+ "import {sym} from 'c';\n"
+ "import type sym from 'd';\n"
+ "import type * as sym from 'e';\n"
+ "\n"
+ "let x = 1;",
+ "import {sym} from 'c';\n"
+ "import type {sym} from 'a';\n"
+ "import type * as sym from 'e';\n"
+ "import type sym from 'd';\n"
+ "import {type sym} from 'b';\n"
+ "let x = 1;");
+
+  // Symbols within import statement
+  verifySort("import {type sym1, type sym2 as a, sym3} from 'b';\n",
+ "import {type sym2 as a, type sym1, sym3} from 'b';\n");
+
+  // Merging
+  verifySort("import {X, type Z} from 'a';\n"
+ "import type {Y} from 'a';\n"
+ "\n"
+ "X + Y + Z;\n",
+ "import {X} from 'a';\n"
+ "import {type Z} from 'a';\n"
+ "import type {Y} from 'a';\n"
+ "\n"
+ "X + Y + Z;\n");
+
+  // Merging: empty imports
+  verifySort("import type {A} from 'foo';\n", "import type {} from 'foo';\n"
+  "import type {A} from 'foo';");
+
+  // Merging: exports
+  verifySort("export {A, type B} from 'foo';\n",
+ "export {A} from 'foo';\n"
+ "export   {type B} from 'foo';");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/unittests/Format/FormatTestJS.cpp
===
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -1476,6 +1476,17 @@
" export class Y {}");
 }
 
+TEST_F(FormatTestJS, ImportExportType) {
+  verifyFormat("import type {x, y} from 'y';\n"
+   "import type * as x from 'y';\n"
+   "import type x from 'y';\n"
+   "import {x, type yu, z} from 'y';\n");
+  verifyFormat("export type {x, y} from 'y';\n"
+   "export {x, type yu, z} from 'y';\n"
+   "export type {x, y};\n"
+   "export {x, type yu, z};\n");
+}
+
 TEST_F(FormatTestJS, ClosureStyleCasts) {
   verifyFormat("var x = /** @type {foo} */ (bar);");
 }
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -4068,7 +4068,9 @@
   // parsing the structural element, i.e. the declaration or expression for
   // `export default`.
   if (!IsImport && !FormatTok->isOneOf(tok::l_brace, tok::star) &&
-  !FormatTok->isStringLiteral()) {
+  !FormatTok->isStringLiteral() &&
+  !(FormatTok->is(Keywords.kw_type) &&
+Tokens->peekNextToken()->isOneOf(tok::l_brace, tok::star))) {
 return;
   }
 
Index: clang/lib/Format/SortJavaScriptImports.cpp
===
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -72,6 +72,7 @@
 struct JsModuleReference {
   bool FormattingOff = false;
   bool IsExport = false;
+  bool IsTypeOnly = false;
   // Module references are sorted into these categories, in order.
   enum ReferenceCategory {
 SIDE_EFFECT, // "import 'something';"
@@ -306,6 +307,7 @@
   if (Reference->Category == JsModuleReference::SIDE_EFFECT ||
   PreviousReference->Category == JsModuleReference::SIDE_EFFECT ||
   Reference->IsExport != PreviousReference->IsExport ||
+  Reference->IsTypeOnly != PreviousReference->IsTypeOnly ||
   !PreviousReference->Prefix.empty(

[PATCH] D147591: [clang][Interp] Handle CXXTemporaryObjectExprs

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



Comment at: clang/test/AST/Interp/records.cpp:317-318
 {
-  auto T = Test(Arr, Pos);
+  Test(Arr, Pos);
   // End of scope, should destroy Test.
 }

tbaeder wrote:
> aaron.ballman wrote:
> > Nit: nothing actually tests that this object is destroyed correctly. Here's 
> > an interesting test to consider:
> > ```
> > struct S {
> >   constexpr S() {}
> >   constexpr ~S() noexcept(false) { throw 12; }
> > };
> > 
> > constexpr int f() {
> >   S{};
> >   return 12;
> > }
> > 
> > static_assert(f() == 12);
> > ```
> > That should fail because `~S()` would hit the `throw` expression and thus 
> > is not valid. Note, you'll need to add `-Wno-invalid-constexpr` to your 
> > test to avoid the warning-defaults-to-error about the destructor never 
> > producing a constant expression.
> There are multiple reasons why that sample is not rejected right now, one I 
> can easily fix in a follow-up patch, the other one would actually require us 
> to recognize the `throw` and reject it with a proper diagnostic.
We should definitely fix the `throw` at some point, but any of the dynamically 
reachable problematic constructs would work (`dynamic_cast` whose type would 
throw, invocation of the `va_arg` macro, `reinterpret_cast`, etc)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147591

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


[PATCH] D150017: [Clang][BPF] Type print btf_type_tag properly

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

LGTM, but please also add a release note about the fix.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150017

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


[PATCH] D147591: [clang][Interp] Handle CXXTemporaryObjectExprs

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/records.cpp:317-318
 {
-  auto T = Test(Arr, Pos);
+  Test(Arr, Pos);
   // End of scope, should destroy Test.
 }

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > Nit: nothing actually tests that this object is destroyed correctly. 
> > > Here's an interesting test to consider:
> > > ```
> > > struct S {
> > >   constexpr S() {}
> > >   constexpr ~S() noexcept(false) { throw 12; }
> > > };
> > > 
> > > constexpr int f() {
> > >   S{};
> > >   return 12;
> > > }
> > > 
> > > static_assert(f() == 12);
> > > ```
> > > That should fail because `~S()` would hit the `throw` expression and thus 
> > > is not valid. Note, you'll need to add `-Wno-invalid-constexpr` to your 
> > > test to avoid the warning-defaults-to-error about the destructor never 
> > > producing a constant expression.
> > There are multiple reasons why that sample is not rejected right now, one I 
> > can easily fix in a follow-up patch, the other one would actually require 
> > us to recognize the `throw` and reject it with a proper diagnostic.
> We should definitely fix the `throw` at some point, but any of the 
> dynamically reachable problematic constructs would work (`dynamic_cast` whose 
> type would throw, invocation of the `va_arg` macro, `reinterpret_cast`, etc)
Yes, I think we need a new opcode for that so we only emit the diagnostic when 
such a construct is actually executed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147591

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


[PATCH] D147591: [clang][Interp] Handle CXXTemporaryObjectExprs

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



Comment at: clang/test/AST/Interp/records.cpp:317-318
 {
-  auto T = Test(Arr, Pos);
+  Test(Arr, Pos);
   // End of scope, should destroy Test.
 }

tbaeder wrote:
> aaron.ballman wrote:
> > tbaeder wrote:
> > > aaron.ballman wrote:
> > > > Nit: nothing actually tests that this object is destroyed correctly. 
> > > > Here's an interesting test to consider:
> > > > ```
> > > > struct S {
> > > >   constexpr S() {}
> > > >   constexpr ~S() noexcept(false) { throw 12; }
> > > > };
> > > > 
> > > > constexpr int f() {
> > > >   S{};
> > > >   return 12;
> > > > }
> > > > 
> > > > static_assert(f() == 12);
> > > > ```
> > > > That should fail because `~S()` would hit the `throw` expression and 
> > > > thus is not valid. Note, you'll need to add `-Wno-invalid-constexpr` to 
> > > > your test to avoid the warning-defaults-to-error about the destructor 
> > > > never producing a constant expression.
> > > There are multiple reasons why that sample is not rejected right now, one 
> > > I can easily fix in a follow-up patch, the other one would actually 
> > > require us to recognize the `throw` and reject it with a proper 
> > > diagnostic.
> > We should definitely fix the `throw` at some point, but any of the 
> > dynamically reachable problematic constructs would work (`dynamic_cast` 
> > whose type would throw, invocation of the `va_arg` macro, 
> > `reinterpret_cast`, etc)
> Yes, I think we need a new opcode for that so we only emit the diagnostic 
> when such a construct is actually executed.
Oh yeah, you'll definitely need that, a whole pile of the constexpr rules are 
based around code reachability.

Are you saying you've got no way to test this until you implement that opcode?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147591

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


[PATCH] D150087: [Clang] Support more stdio builtins

2023-05-08 Thread Tulio Magno Quites Machado Filho via Phabricator via cfe-commits
tuliom requested changes to this revision.
tuliom added inline comments.
This revision now requires changes to proceed.



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:109
+  {Builtin::BI__builtin___vsnprintf_chk, "__vsnprintfieee128"},
+  {Builtin::BI__builtin___vsprintf_chk, "__vsprintfieee128"},
+  {Builtin::BI__builtin_fprintf, "__fprintfieee128"},

Any reasons to not map these built-ins to their respective `_chkieee128` 
counterparts? e.g. `__fprintf_chkieee128`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150087

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


[PATCH] D147591: [clang][Interp] Handle CXXTemporaryObjectExprs

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/test/AST/Interp/records.cpp:317-318
 {
-  auto T = Test(Arr, Pos);
+  Test(Arr, Pos);
   // End of scope, should destroy Test.
 }

aaron.ballman wrote:
> tbaeder wrote:
> > aaron.ballman wrote:
> > > tbaeder wrote:
> > > > aaron.ballman wrote:
> > > > > Nit: nothing actually tests that this object is destroyed correctly. 
> > > > > Here's an interesting test to consider:
> > > > > ```
> > > > > struct S {
> > > > >   constexpr S() {}
> > > > >   constexpr ~S() noexcept(false) { throw 12; }
> > > > > };
> > > > > 
> > > > > constexpr int f() {
> > > > >   S{};
> > > > >   return 12;
> > > > > }
> > > > > 
> > > > > static_assert(f() == 12);
> > > > > ```
> > > > > That should fail because `~S()` would hit the `throw` expression and 
> > > > > thus is not valid. Note, you'll need to add `-Wno-invalid-constexpr` 
> > > > > to your test to avoid the warning-defaults-to-error about the 
> > > > > destructor never producing a constant expression.
> > > > There are multiple reasons why that sample is not rejected right now, 
> > > > one I can easily fix in a follow-up patch, the other one would actually 
> > > > require us to recognize the `throw` and reject it with a proper 
> > > > diagnostic.
> > > We should definitely fix the `throw` at some point, but any of the 
> > > dynamically reachable problematic constructs would work (`dynamic_cast` 
> > > whose type would throw, invocation of the `va_arg` macro, 
> > > `reinterpret_cast`, etc)
> > Yes, I think we need a new opcode for that so we only emit the diagnostic 
> > when such a construct is actually executed.
> Oh yeah, you'll definitely need that, a whole pile of the constexpr rules are 
> based around code reachability.
> 
> Are you saying you've got no way to test this until you implement that opcode?
With https://reviews.llvm.org/D150040 applied, it gets properly rejected, just 
the diagnostics are off. I can add the test and reorder the commits.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147591

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


[PATCH] D148802: [Sema] Lambdas are not part of immediate context for deduction

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

In D148802#4326268 , @ilya-biryukov 
wrote:

> Another friendly ping for review.
> @erichkeane let me know if you feel that exposing the incorrect lambda 
> instantiation behavior is a blocker here.

I don't... we're up to ~4 active bugs on that, so its not like it is 
'unexposed' now.  I think this looks good enough to accept;




Comment at: clang/test/SemaCXX/warn-unused-lambda-capture.cpp:192
 void test_use_template() {
-  test_templated(); // expected-note{{in instantiation of function 
template specialization 'test_templated' requested here}}
+  test_templated(); // expected-note 13{{in instantiation of function 
template specialization 'test_templated' requested here}}
 }

ilya-biryukov wrote:
> shafik wrote:
> > Why the 12 extra notes here, I feel I am missing something but not sure 
> > what. I see the increase in notes in other cases as well.
> I'm not entirely sure, but it seems there is some deduplication of notes 
> that's happening when the stacks of code-synthesis-contexts for subsequent 
> errors are the same.
> However, this patch introduces a different code synthesis context for lambda 
> substitutions, forcing the notes to be added.
> In the new version of the patch, the added context actually shows up in the 
> notes as well.
Note that this test is organized poorly, and the 12 additions are likely the 
levels added above, and it is 1 per error, so its just 1 more level of 'in 
instantiation...' in each of those cases above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148802

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


[PATCH] D150036: [Clang] Correctly handle allocation in template arguments

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

Formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150036

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


Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
===
--- clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
@@ -215,3 +215,27 @@
   }
   static_assert(h());
 }
+
+namespace GH62462 {
+
+class string {
+public:
+  char *mem;
+  constexpr string() {
+this->mem = new char(1);
+  }
+  constexpr ~string() {
+delete this->mem;
+  }
+  constexpr unsigned size() const { return 4; }
+};
+
+
+template 
+void test() {};
+
+void f() {
+test();
+}
+
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15354,8 +15354,16 @@
   LValue LVal;
   LVal.set(Base);
 
-  if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || 
Result.HasSideEffects)
-return false;
+  {
+// C++23 [intro.execution]/p5
+// A full-expression is [...] a constant-expression
+// So we need to make sure temporary objects are destroyed after having
+// evaluating the expression (per C++23 [class.temporary]/p4).
+FullExpressionRAII Scope(Info);
+if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
+Result.HasSideEffects || !Scope.destroy())
+  return false;
+  }
 
   if (!Info.discardCleanups())
 llvm_unreachable("Unhandled cleanup; missing full expression marker?");
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -381,6 +381,8 @@
 - Fix overly aggressive lifetime checks for parenthesized aggregate
   initialization.
   (`#61567 `_)
+- Fix handling of constexpr dynamic memory allocations in template
+  arguments. (`#62462 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
===
--- clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
@@ -215,3 +215,27 @@
   }
   static_assert(h());
 }
+
+namespace GH62462 {
+
+class string {
+public:
+  char *mem;
+  constexpr string() {
+this->mem = new char(1);
+  }
+  constexpr ~string() {
+delete this->mem;
+  }
+  constexpr unsigned size() const { return 4; }
+};
+
+
+template 
+void test() {};
+
+void f() {
+test();
+}
+
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15354,8 +15354,16 @@
   LValue LVal;
   LVal.set(Base);
 
-  if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || Result.HasSideEffects)
-return false;
+  {
+// C++23 [intro.execution]/p5
+// A full-expression is [...] a constant-expression
+// So we need to make sure temporary objects are destroyed after having
+// evaluating the expression (per C++23 [class.temporary]/p4).
+FullExpressionRAII Scope(Info);
+if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
+Result.HasSideEffects || !Scope.destroy())
+  return false;
+  }
 
   if (!Info.discardCleanups())
 llvm_unreachable("Unhandled cleanup; missing full expression marker?");
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -381,6 +381,8 @@
 - Fix overly aggressive lifetime checks for parenthesized aggregate
   initialization.
   (`#61567 `_)
+- Fix handling of constexpr dynamic memory allocations in template
+  arguments. (`#62462 `_)
 
 Bug Fixes to AST Handling
 ^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150013: [Clang] Respect `-L` options when compiling directly for AMDGPU

2023-05-08 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added inline comments.



Comment at: clang/lib/Driver/ToolChains/AMDGPU.cpp:546
   addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+  Args.AddAllArgs(CmdArgs, options::OPT_L);

jhuber6 wrote:
> yaxunl wrote:
> > AddLinkerInputs has code doing that, and it handles env var LIBRARY_PATH. 
> > However that code is disabled for AMDGPU because AMDGPU returns true for 
> > isCrossCompiling.
> > 
> > https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/CommonArgs.cpp#L236
> > 
> > It seems isCrossCompiling is solely for controlling whether to consume 
> > `-L`. If we want amdgpu toolchain to accept `-L`, we can simply let 
> > isCrossCompiling return false.
> Good catch, we could maybe set `isCrossCompiling` to false if targeted 
> directly by the user, e.g. `--target=amdgcn-amd-amdhsa` vs `--offload-arch`.
That would be better. Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150013

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


[PATCH] D150013: [Clang] Respect `-L` options when compiling directly for AMDGPU

2023-05-08 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 added inline comments.



Comment at: clang/lib/Driver/ToolChains/AMDGPU.cpp:546
   addLinkerCompressDebugSectionsOption(getToolChain(), Args, CmdArgs);
   AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
+  Args.AddAllArgs(CmdArgs, options::OPT_L);

yaxunl wrote:
> jhuber6 wrote:
> > yaxunl wrote:
> > > AddLinkerInputs has code doing that, and it handles env var LIBRARY_PATH. 
> > > However that code is disabled for AMDGPU because AMDGPU returns true for 
> > > isCrossCompiling.
> > > 
> > > https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/CommonArgs.cpp#L236
> > > 
> > > It seems isCrossCompiling is solely for controlling whether to consume 
> > > `-L`. If we want amdgpu toolchain to accept `-L`, we can simply let 
> > > isCrossCompiling return false.
> > Good catch, we could maybe set `isCrossCompiling` to false if targeted 
> > directly by the user, e.g. `--target=amdgcn-amd-amdhsa` vs `--offload-arch`.
> That would be better. Thanks.
It still is technically cross compiling, since we are building for a target 
that does not match the system's architecture. The original code that prevents 
passing `-L` was contributed by @MaskRay. I understand that we may not want to 
pass `LIBRARY_PATH` defines, but what's the rationale for not passing any `-L` 
options manually specified by the user?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150013

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


[clang] e875de2 - [clang][dataflow] Remove deprecated pass-through APIs for DataflowAnalysisContext.

2023-05-08 Thread Yitzhak Mandelbaum via cfe-commits

Author: Samira Bazuzi
Date: 2023-05-08T13:59:40Z
New Revision: e875de2a3e8e814265c7cb09b908a444df1a498d

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

LOG: [clang][dataflow] Remove deprecated pass-through APIs for 
DataflowAnalysisContext.

These were recently deprecated in https://reviews.llvm.org/D149464.

Reviewed By: ymandel, gribozavr2, xazax.hun

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index 58b1d8b172b3..7f24755d9923 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -179,18 +179,6 @@ class Environment {
   /// with a symbolic representation of the `this` pointee.
   Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
 
-  LLVM_DEPRECATED("Use getDataflowAnalysisContext().getOptions() instead.", "")
-  const DataflowAnalysisContext::Options &getAnalysisOptions() const {
-return DACtx->getOptions();
-  }
-
-  LLVM_DEPRECATED("Use getDataflowAnalysisContext().arena() instead.", "")
-  Arena &arena() const { return DACtx->arena(); }
-
-  LLVM_DEPRECATED("Use getDataflowAnalysisContext().getOptions().Log instead.",
-  "")
-  Logger &logger() const { return *DACtx->getOptions().Log; }
-
   /// Creates and returns an environment to use for an inline analysis  of the
   /// callee. Uses the storage location from each argument in the `Call` as the
   /// storage location for the corresponding parameter in the callee.
@@ -422,14 +410,6 @@ class Environment {
   /// given `MaxDepth`.
   bool canDescend(unsigned MaxDepth, const DeclContext *Callee) const;
 
-  /// Returns the `ControlFlowContext` registered for `F`, if any. Otherwise,
-  /// returns null.
-  LLVM_DEPRECATED(
-  "Use getDataflowAnalysisContext().getControlFlowContext(F) instead.", "")
-  const ControlFlowContext *getControlFlowContext(const FunctionDecl *F) {
-return DACtx->getControlFlowContext(F);
-  }
-
   /// Returns the `DataflowAnalysisContext` used by the environment.
   DataflowAnalysisContext &getDataflowAnalysisContext() const { return *DACtx; 
}
 



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


[PATCH] D149869: [clang][dataflow] Remove deprecated pass-through APIs for DataflowAnalysisContext.

2023-05-08 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe875de2a3e8e: [clang][dataflow] Remove deprecated 
pass-through APIs for… (authored by bazuzi, committed by ymandel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149869

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h


Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -179,18 +179,6 @@
   /// with a symbolic representation of the `this` pointee.
   Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
 
-  LLVM_DEPRECATED("Use getDataflowAnalysisContext().getOptions() instead.", "")
-  const DataflowAnalysisContext::Options &getAnalysisOptions() const {
-return DACtx->getOptions();
-  }
-
-  LLVM_DEPRECATED("Use getDataflowAnalysisContext().arena() instead.", "")
-  Arena &arena() const { return DACtx->arena(); }
-
-  LLVM_DEPRECATED("Use getDataflowAnalysisContext().getOptions().Log instead.",
-  "")
-  Logger &logger() const { return *DACtx->getOptions().Log; }
-
   /// Creates and returns an environment to use for an inline analysis  of the
   /// callee. Uses the storage location from each argument in the `Call` as the
   /// storage location for the corresponding parameter in the callee.
@@ -422,14 +410,6 @@
   /// given `MaxDepth`.
   bool canDescend(unsigned MaxDepth, const DeclContext *Callee) const;
 
-  /// Returns the `ControlFlowContext` registered for `F`, if any. Otherwise,
-  /// returns null.
-  LLVM_DEPRECATED(
-  "Use getDataflowAnalysisContext().getControlFlowContext(F) instead.", "")
-  const ControlFlowContext *getControlFlowContext(const FunctionDecl *F) {
-return DACtx->getControlFlowContext(F);
-  }
-
   /// Returns the `DataflowAnalysisContext` used by the environment.
   DataflowAnalysisContext &getDataflowAnalysisContext() const { return *DACtx; 
}
 


Index: clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -179,18 +179,6 @@
   /// with a symbolic representation of the `this` pointee.
   Environment(DataflowAnalysisContext &DACtx, const DeclContext &DeclCtx);
 
-  LLVM_DEPRECATED("Use getDataflowAnalysisContext().getOptions() instead.", "")
-  const DataflowAnalysisContext::Options &getAnalysisOptions() const {
-return DACtx->getOptions();
-  }
-
-  LLVM_DEPRECATED("Use getDataflowAnalysisContext().arena() instead.", "")
-  Arena &arena() const { return DACtx->arena(); }
-
-  LLVM_DEPRECATED("Use getDataflowAnalysisContext().getOptions().Log instead.",
-  "")
-  Logger &logger() const { return *DACtx->getOptions().Log; }
-
   /// Creates and returns an environment to use for an inline analysis  of the
   /// callee. Uses the storage location from each argument in the `Call` as the
   /// storage location for the corresponding parameter in the callee.
@@ -422,14 +410,6 @@
   /// given `MaxDepth`.
   bool canDescend(unsigned MaxDepth, const DeclContext *Callee) const;
 
-  /// Returns the `ControlFlowContext` registered for `F`, if any. Otherwise,
-  /// returns null.
-  LLVM_DEPRECATED(
-  "Use getDataflowAnalysisContext().getControlFlowContext(F) instead.", "")
-  const ControlFlowContext *getControlFlowContext(const FunctionDecl *F) {
-return DACtx->getControlFlowContext(F);
-  }
-
   /// Returns the `DataflowAnalysisContext` used by the environment.
   DataflowAnalysisContext &getDataflowAnalysisContext() const { return *DACtx; }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D147591: [clang][Interp] Handle CXXTemporaryObjectExprs

2023-05-08 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 520361.

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

https://reviews.llvm.org/D147591

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/test/AST/Interp/records.cpp


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -314,16 +314,36 @@
 int Pos = 0;
 
 {
-  auto T = Test(Arr, Pos);
+  Test(Arr, Pos);
   // End of scope, should destroy Test.
 }
 
 return Arr[Index];
   }
-
   static_assert(T(0) == 1);
   static_assert(T(1) == 2);
   static_assert(T(2) == 3);
+
+  // Invalid destructor.
+  struct S {
+constexpr S() {}
+constexpr ~S() noexcept(false) { throw 12; } // expected-error {{cannot 
use 'throw'}} \
+ // expected-note {{declared 
here}} \
+ // ref-error {{cannot use 
'throw'}} \
+ // ref-error {{never produces 
a constant expression}} \
+ // ref-note 2{{subexpression 
not valid}}
+  };
+
+  constexpr int f() {
+S{}; // ref-note {{in call to '&S{}->~S()'}}
+return 12; // expected-note {{undefined function '~S'}}
+  }
+  static_assert(f() == 12); // expected-error {{not an integral constant 
expression}} \
+// expected-note {{in call to 'f()'}} \
+// ref-error {{not an integral constant 
expression}} \
+// ref-note {{in call to 'f()'}}
+
+
 #endif
 }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -91,6 +91,8 @@
   bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E);
   bool VisitExprWithCleanups(const ExprWithCleanups *E);
   bool VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *E);
+  bool VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *E);
+  bool VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *E);
   bool VisitCompoundLiteralExpr(const CompoundLiteralExpr *E);
   bool VisitTypeTraitExpr(const TypeTraitExpr *E);
   bool VisitLambdaExpr(const LambdaExpr *E);
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -914,6 +914,24 @@
   return false;
 }
 
+template 
+bool ByteCodeExprGen::VisitCXXBindTemporaryExpr(
+const CXXBindTemporaryExpr *E) {
+
+  return this->visit(E->getSubExpr());
+}
+
+template 
+bool ByteCodeExprGen::VisitCXXTemporaryObjectExpr(
+const CXXTemporaryObjectExpr *E) {
+
+  if (std::optional LocalIndex =
+  allocateLocal(E, /*IsExtended=*/false)) {
+return this->visitLocalInitializer(E, *LocalIndex);
+  }
+  return false;
+}
+
 template 
 bool ByteCodeExprGen::VisitCompoundLiteralExpr(
 const CompoundLiteralExpr *E) {


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -314,16 +314,36 @@
 int Pos = 0;
 
 {
-  auto T = Test(Arr, Pos);
+  Test(Arr, Pos);
   // End of scope, should destroy Test.
 }
 
 return Arr[Index];
   }
-
   static_assert(T(0) == 1);
   static_assert(T(1) == 2);
   static_assert(T(2) == 3);
+
+  // Invalid destructor.
+  struct S {
+constexpr S() {}
+constexpr ~S() noexcept(false) { throw 12; } // expected-error {{cannot use 'throw'}} \
+ // expected-note {{declared here}} \
+ // ref-error {{cannot use 'throw'}} \
+ // ref-error {{never produces a constant expression}} \
+ // ref-note 2{{subexpression not valid}}
+  };
+
+  constexpr int f() {
+S{}; // ref-note {{in call to '&S{}->~S()'}}
+return 12; // expected-note {{undefined function '~S'}}
+  }
+  static_assert(f() == 12); // expected-error {{not an integral constant expression}} \
+// expected-note {{in call to 'f()'}} \
+// ref-error {{not an integral constant expression}} \
+// ref-note {{in call to 'f()'}}
+
+
 #endif
 }
 
Index: clang/lib/AST/Interp/ByteCodeExprGen.h
===
--- clang/lib/AST/Interp/ByteCodeExprGen.h
+++ clang/lib/AST/Interp/ByteCodeExprGen.h
@@ -91,6 +91,8 @@
   bool VisitPointerCompoundAssignOperator(const CompoundAssignOperator *E);
   bool V

[PATCH] D150036: [Clang] Correctly handle allocation in template arguments

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

I think this looks right, and you've satisfied all the other reviewers.  LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150036

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


[PATCH] D146358: [clang][AST] Print name instead of type when diagnosing uninitialized subobject in constexpr variables

2023-05-08 Thread Takuya Shimizu via Phabricator via cfe-commits
hazohelet added a comment.

Ping


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

https://reviews.llvm.org/D146358

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


[PATCH] D150017: [Clang][BPF] Type print btf_type_tag properly

2023-05-08 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song added a comment.

In D150017#4326665 , @aaron.ballman 
wrote:

> LGTM, but please also add a release note about the fix.

Thanks @aaron.ballman. I intend to backport this patch to llvm16 and adding a 
release note about the fix will have backport conflict with llvm16, so I will 
add a release note separately after this is patch is merged into llvm17.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150017

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


[clang] 9857caf - [Clang] Correctly handle allocation in template arguments

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

Author: Corentin Jabot
Date: 2023-05-08T16:28:06+02:00
New Revision: 9857caf9d14f70767035d821313045b56dbe3b10

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

LOG: [Clang] Correctly handle allocation in template arguments

Fixes #62462

Reviewed By: #clang-language-wg, erichkeane

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

Added: 


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

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 910a853eafc81..4f8165bbc8ee5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -370,7 +370,7 @@ Bug Fixes in This Version
   (`#62192 `_)
 - Fix crash when attempting to pass a non-pointer type as first argument of
   ``__builtin_assume_aligned``.
-  (`#62305 `_) 
+  (`#62305 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
@@ -416,6 +416,8 @@ Bug Fixes to C++ Support
   initialization.
   (`#61567 `_)
 - Fix a crash when expanding a pack as the index of a subscript expression.
+- Fix handling of constexpr dynamic memory allocations in template
+  arguments. (`#62462 `_)
 
 Bug Fixes to AST Handling
 ^

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 03eb5dfe6ff60..ce3c5257e7114 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -15354,8 +15354,16 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, 
const ASTContext &Ctx,
   LValue LVal;
   LVal.set(Base);
 
-  if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || 
Result.HasSideEffects)
-return false;
+  {
+// C++23 [intro.execution]/p5
+// A full-expression is [...] a constant-expression
+// So we need to make sure temporary objects are destroyed after having
+// evaluating the expression (per C++23 [class.temporary]/p4).
+FullExpressionRAII Scope(Info);
+if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
+Result.HasSideEffects || !Scope.destroy())
+  return false;
+  }
 
   if (!Info.discardCleanups())
 llvm_unreachable("Unhandled cleanup; missing full expression marker?");

diff  --git a/clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp 
b/clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
index f37ebc9f63655..357dc67bd5ad2 100644
--- a/clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
+++ b/clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
@@ -215,3 +215,27 @@ namespace PR48606 {
   }
   static_assert(h());
 }
+
+namespace GH62462 {
+
+class string {
+public:
+  char *mem;
+  constexpr string() {
+this->mem = new char(1);
+  }
+  constexpr ~string() {
+delete this->mem;
+  }
+  constexpr unsigned size() const { return 4; }
+};
+
+
+template 
+void test() {};
+
+void f() {
+test();
+}
+
+}



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


[PATCH] D150036: [Clang] Correctly handle allocation in template arguments

2023-05-08 Thread Corentin Jabot via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG9857caf9d14f: [Clang] Correctly handle allocation in 
template arguments (authored by cor3ntin).

Changed prior to commit:
  https://reviews.llvm.org/D150036?vs=520356&id=520369#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150036

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


Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
===
--- clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
@@ -215,3 +215,27 @@
   }
   static_assert(h());
 }
+
+namespace GH62462 {
+
+class string {
+public:
+  char *mem;
+  constexpr string() {
+this->mem = new char(1);
+  }
+  constexpr ~string() {
+delete this->mem;
+  }
+  constexpr unsigned size() const { return 4; }
+};
+
+
+template 
+void test() {};
+
+void f() {
+test();
+}
+
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15354,8 +15354,16 @@
   LValue LVal;
   LVal.set(Base);
 
-  if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || 
Result.HasSideEffects)
-return false;
+  {
+// C++23 [intro.execution]/p5
+// A full-expression is [...] a constant-expression
+// So we need to make sure temporary objects are destroyed after having
+// evaluating the expression (per C++23 [class.temporary]/p4).
+FullExpressionRAII Scope(Info);
+if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
+Result.HasSideEffects || !Scope.destroy())
+  return false;
+  }
 
   if (!Info.discardCleanups())
 llvm_unreachable("Unhandled cleanup; missing full expression marker?");
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -370,7 +370,7 @@
   (`#62192 `_)
 - Fix crash when attempting to pass a non-pointer type as first argument of
   ``__builtin_assume_aligned``.
-  (`#62305 `_) 
+  (`#62305 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
@@ -416,6 +416,8 @@
   initialization.
   (`#61567 `_)
 - Fix a crash when expanding a pack as the index of a subscript expression.
+- Fix handling of constexpr dynamic memory allocations in template
+  arguments. (`#62462 `_)
 
 Bug Fixes to AST Handling
 ^


Index: clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
===
--- clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
+++ clang/test/SemaCXX/cxx2a-constexpr-dynalloc.cpp
@@ -215,3 +215,27 @@
   }
   static_assert(h());
 }
+
+namespace GH62462 {
+
+class string {
+public:
+  char *mem;
+  constexpr string() {
+this->mem = new char(1);
+  }
+  constexpr ~string() {
+delete this->mem;
+  }
+  constexpr unsigned size() const { return 4; }
+};
+
+
+template 
+void test() {};
+
+void f() {
+test();
+}
+
+}
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15354,8 +15354,16 @@
   LValue LVal;
   LVal.set(Base);
 
-  if (!::EvaluateInPlace(Result.Val, Info, LVal, this) || Result.HasSideEffects)
-return false;
+  {
+// C++23 [intro.execution]/p5
+// A full-expression is [...] a constant-expression
+// So we need to make sure temporary objects are destroyed after having
+// evaluating the expression (per C++23 [class.temporary]/p4).
+FullExpressionRAII Scope(Info);
+if (!::EvaluateInPlace(Result.Val, Info, LVal, this) ||
+Result.HasSideEffects || !Scope.destroy())
+  return false;
+  }
 
   if (!Info.discardCleanups())
 llvm_unreachable("Unhandled cleanup; missing full expression marker?");
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -370,7 +370,7 @@
   (`#62192 `_)
 - Fix crash when attempting to pass a non-pointer type as first argument of
   ``__builtin_assume_aligned``.
-  (`#62305 `_) 
+  (`#62305 `_)
 
 Bug Fixes to Compiler Builtins
 ^^
@

[PATCH] D147319: [clang-repl] Consider the scope spec in template lookups for deduction guides

2023-05-08 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev updated this revision to Diff 520368.
v.g.vassilev added a comment.

clang-format


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

https://reviews.llvm.org/D147319

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/Interpreter/disambiguate-decl-stmt.cpp


Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ clang/test/Interpreter/disambiguate-decl-stmt.cpp
@@ -7,6 +7,10 @@
 
 // Decls which are hard to disambiguate
 
+// Templates
+namespace ns1 { template void tmplt(T &) {}}
+int arg_tmplt = 12; ns1::tmplt(arg_tmplt);
+
 // ParseStatementOrDeclaration returns multiple statements.
 #ifdef MS
 int g_bFlag = 1;
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -316,9 +316,8 @@
 }
 
 bool Sema::isDeductionGuideName(Scope *S, const IdentifierInfo &Name,
-SourceLocation NameLoc,
-ParsedTemplateTy *Template) {
-  CXXScopeSpec SS;
+SourceLocation NameLoc, CXXScopeSpec &SS,
+ParsedTemplateTy *Template /*=nullptr*/) {
   bool MemberOfUnknownSpecialization = false;
 
   // We could use redeclaration lookup here, but we don't need to: the
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -74,9 +74,8 @@
   switch (Tok.getKind()) {
   case tok::identifier: {
 IdentifierInfo *II = Tok.getIdentifierInfo();
-bool isDeductionGuide =
-Actions.isDeductionGuideName(getCurScope(), *II, Tok.getLocation(),
- /*Template=*/nullptr);
+bool isDeductionGuide = Actions.isDeductionGuideName(
+getCurScope(), *II, Tok.getLocation(), SS, /*Template=*/nullptr);
 if (Actions.isCurrentClassName(*II, getCurScope(), &SS) ||
 isDeductionGuide) {
   if (isConstructorDeclarator(/*Unqualified=*/SS.isEmpty(),
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2911,9 +2911,9 @@
   if (!Ty)
 return true;
   Result.setConstructorName(Ty, IdLoc, IdLoc);
-} else if (getLangOpts().CPlusPlus17 &&
-   AllowDeductionGuide && SS.isEmpty() &&
-   Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc,
+} else if (getLangOpts().CPlusPlus17 && AllowDeductionGuide &&
+   SS.isEmpty() &&
+   Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc, SS,
 &TemplateName)) {
   // We have parsed a template-name naming a deduction guide.
   Result.setDeductionGuideName(TemplateName, IdLoc);
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -3696,11 +3696,12 @@
 
   // Likewise, if this is a context where the identifier could be a 
template
   // name, check whether this is a deduction guide declaration.
+  CXXScopeSpec SS;
   if (getLangOpts().CPlusPlus17 &&
   (DSContext == DeclSpecContext::DSC_class ||
DSContext == DeclSpecContext::DSC_top_level) &&
   Actions.isDeductionGuideName(getCurScope(), *Tok.getIdentifierInfo(),
-   Tok.getLocation()) &&
+   Tok.getLocation(), SS) &&
   isConstructorDeclarator(/*Unqualified*/ true,
   /*DeductionGuide*/ true))
 goto DoneWithDeclSpec;
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -8078,7 +8078,7 @@
   /// Determine whether a particular identifier might be the name in a C++1z
   /// deduction-guide declaration.
   bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name,
-SourceLocation NameLoc,
+SourceLocation NameLoc, CXXScopeSpec &SS,
 ParsedTemplateTy *Template = nullptr);
 
   bool DiagnoseUnknownTemplateName(const IdentifierInfo &II,


Index: clang/test/Interpreter/disambiguate-decl-stmt.cpp
===
--- clang/test/Interpreter/disambiguate-decl-stmt.cpp
+++ clang/test/Interpreter/disambigua

[PATCH] D149997: [clang] [test] Narrow down MSVC specific behaviours from "any windows" to only MSVC/clang-cl

2023-05-08 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149997

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


[PATCH] D149999: [clang-tidy] [test] Narrow down a special case to MSVC mode

2023-05-08 Thread Hans Wennborg via Phabricator via cfe-commits
hans accepted this revision.
hans added a comment.
This revision is now accepted and ready to land.

lgtm


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D14

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


[clang] 3060304 - [Clang][BPF] Type print btf_type_tag properly

2023-05-08 Thread Yonghong Song via cfe-commits

Author: Yonghong Song
Date: 2023-05-08T07:41:27-07:00
New Revision: 3060304906f08f933672f0a30cc57d5f09766444

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

LOG: [Clang][BPF] Type print btf_type_tag properly

When running bcc tool execsnoop ([1]) which is built with latest llvm,
I hit the following error:
  $ sudo ./execsnoop.py
  /virtual/main.c:99:157: error: expected ')'
data.ppid = ({ typeof(pid_t) _val; __builtin_memset(&_val, 0, 
sizeof(_val)); bpf_probe_read(&_val, sizeof(_val),
   (void *)&({ typeof(struct task_struct  btf_type_tag(rcu)*) _val; 
__builtin_memset(&_val, 0, sizeof(_val));
  ^
bpf_probe_read(&_val, sizeof(_val), (void *)&task->real_parent); _val; 
})->tgid); _val; });

The failure reason is due to that the bcc rewriter printed type like
  struct task_struct  btf_type_tag(rcu)*
where the compiler cannot recognize what 'btf_type_tag(rcu)' is.

The above type is printed in [2] by UnaryOperator->getType().getAsString() 
(from clang)
in function ProbeVisitor::VisitUnaryOperator.

The original source type looks like ([3])
  struct task_struct {
...
struct task_struct __rcu*real_parent;
...
  }
  where '__rcu' is a macro expanding to '__attribute__((btf_type_tag("rcu")))'.

Let us print btf_type_tag properly in clang so bcc tools and broader type 
printing
will work properly.

With this patch, the above rewrited source code looks like
data.ppid = ({ typeof(pid_t) _val; __builtin_memset(&_val, 0, 
sizeof(_val)); bpf_probe_read(&_val, sizeof(_val),
   (void *)&({ typeof(struct task_struct  
__attribute__((btf_type_tag("rcu")))*) _val; __builtin_memset(&_val, 0, 
sizeof(_val));
bpf_probe_read(&_val, sizeof(_val), (void *)&task->real_parent); _val; 
})->tgid); _val; });

and execsnoop.py tool can run properly.

  [1] https://github.com/iovisor/bcc/blob/master/tools/exitsnoop.py
  [2] 
https://github.com/iovisor/bcc/blob/master/src/cc/frontends/clang/b_frontend_action.cc
  [3] https://github.com/torvalds/linux/blob/master/include/linux/sched.h

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

Added: 
clang/test/AST/ast-dump-bpf-attr.c

Modified: 
clang/lib/AST/TypePrinter.cpp
clang/test/Sema/attr-btf_type_tag.c
clang/test/SemaCXX/sugar-common-types.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index 408c7caa16c93..02e0793f5cb16 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -1845,7 +1845,7 @@ void TypePrinter::printAttributedAfter(const 
AttributedType *T,
 void TypePrinter::printBTFTagAttributedBefore(const BTFTagAttributedType *T,
   raw_ostream &OS) {
   printBefore(T->getWrappedType(), OS);
-  OS << " btf_type_tag(" << T->getAttr()->getBTFTypeTag() << ")";
+  OS << " __attribute__((btf_type_tag(\"" << T->getAttr()->getBTFTypeTag() << 
"\")))";
 }
 
 void TypePrinter::printBTFTagAttributedAfter(const BTFTagAttributedType *T,

diff  --git a/clang/test/AST/ast-dump-bpf-attr.c 
b/clang/test/AST/ast-dump-bpf-attr.c
new file mode 100644
index 0..8899cecbb6e9f
--- /dev/null
+++ b/clang/test/AST/ast-dump-bpf-attr.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple bpf-pc-linux-gnu -ast-dump  %s \
+// RUN: | FileCheck --strict-whitespace %s
+
+int __attribute__((btf_type_tag("rcu"))) * g;
+// CHECK: VarDecl{{.*}}g 'int  __attribute__((btf_type_tag("rcu")))*'

diff  --git a/clang/test/Sema/attr-btf_type_tag.c 
b/clang/test/Sema/attr-btf_type_tag.c
index f7ba29b0aa657..a3ef404f38238 100644
--- a/clang/test/Sema/attr-btf_type_tag.c
+++ b/clang/test/Sema/attr-btf_type_tag.c
@@ -28,8 +28,8 @@ int __tag4 * __tag5 * __tag6 *foo1(struct t __tag1 * __tag2 * 
__tag3 *a1) {
 int g1 = _Generic((int *)0, int __tag1 *: 0);
 int g2 = _Generic((int __tag1 *)0, int *: 0);
 int g3 = _Generic(0,
-  int __tag1 * : 0, // expected-note {{compatible type 'int  
btf_type_tag(tag1)*' (aka 'int *') specified here}}
-  int * : 0, // expected-error {{type 'int *' in generic 
association compatible with previously specified type 'int  
btf_type_tag(tag1)*' (aka 'int *')}}
+  int __tag1 * : 0, // expected-note {{compatible type 'int  
__attribute__((btf_type_tag("tag1")))*' (aka 'int *') specified here}}
+  int * : 0, // expected-error {{type 'int *' in generic 
association compatible with previously specified type 'int  
__attribute__((btf_type_tag("tag1")))*' (aka 'int *')}}
   default : 0);
 
 // The btf_type_tag attribute will be ignored during overloadable type matching

diff  --git a/clang/test/SemaCXX/sugar-common-types.cpp 
b/clang/test/SemaCXX/sugar-common-types.cpp
index f4e

[PATCH] D150017: [Clang][BPF] Type print btf_type_tag properly

2023-05-08 Thread Yonghong Song via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3060304906f0: [Clang][BPF] Type print btf_type_tag properly 
(authored by yonghong-song).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150017

Files:
  clang/lib/AST/TypePrinter.cpp
  clang/test/AST/ast-dump-bpf-attr.c
  clang/test/Sema/attr-btf_type_tag.c
  clang/test/SemaCXX/sugar-common-types.cpp


Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -95,7 +95,7 @@
 using SBTF3 = ::SS1 [[clang::btf_type_tag("2")]];
 
 N t21 = 0 ? (SBTF1){} : (SBTF3){}; // expected-error {{from 'SS1'}}
-N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 
btf_type_tag(1)' (aka 'SS1')}}
+N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 
__attribute__((btf_type_tag("1")))' (aka 'SS1')}}
 
 using QX = const SB1 *;
 using QY = const ::SB1 *;
Index: clang/test/Sema/attr-btf_type_tag.c
===
--- clang/test/Sema/attr-btf_type_tag.c
+++ clang/test/Sema/attr-btf_type_tag.c
@@ -28,8 +28,8 @@
 int g1 = _Generic((int *)0, int __tag1 *: 0);
 int g2 = _Generic((int __tag1 *)0, int *: 0);
 int g3 = _Generic(0,
-  int __tag1 * : 0, // expected-note {{compatible type 'int  
btf_type_tag(tag1)*' (aka 'int *') specified here}}
-  int * : 0, // expected-error {{type 'int *' in generic 
association compatible with previously specified type 'int  
btf_type_tag(tag1)*' (aka 'int *')}}
+  int __tag1 * : 0, // expected-note {{compatible type 'int  
__attribute__((btf_type_tag("tag1")))*' (aka 'int *') specified here}}
+  int * : 0, // expected-error {{type 'int *' in generic 
association compatible with previously specified type 'int  
__attribute__((btf_type_tag("tag1")))*' (aka 'int *')}}
   default : 0);
 
 // The btf_type_tag attribute will be ignored during overloadable type matching
Index: clang/test/AST/ast-dump-bpf-attr.c
===
--- /dev/null
+++ clang/test/AST/ast-dump-bpf-attr.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -triple bpf-pc-linux-gnu -ast-dump  %s \
+// RUN: | FileCheck --strict-whitespace %s
+
+int __attribute__((btf_type_tag("rcu"))) * g;
+// CHECK: VarDecl{{.*}}g 'int  __attribute__((btf_type_tag("rcu")))*'
Index: clang/lib/AST/TypePrinter.cpp
===
--- clang/lib/AST/TypePrinter.cpp
+++ clang/lib/AST/TypePrinter.cpp
@@ -1845,7 +1845,7 @@
 void TypePrinter::printBTFTagAttributedBefore(const BTFTagAttributedType *T,
   raw_ostream &OS) {
   printBefore(T->getWrappedType(), OS);
-  OS << " btf_type_tag(" << T->getAttr()->getBTFTypeTag() << ")";
+  OS << " __attribute__((btf_type_tag(\"" << T->getAttr()->getBTFTypeTag() << 
"\")))";
 }
 
 void TypePrinter::printBTFTagAttributedAfter(const BTFTagAttributedType *T,


Index: clang/test/SemaCXX/sugar-common-types.cpp
===
--- clang/test/SemaCXX/sugar-common-types.cpp
+++ clang/test/SemaCXX/sugar-common-types.cpp
@@ -95,7 +95,7 @@
 using SBTF3 = ::SS1 [[clang::btf_type_tag("2")]];
 
 N t21 = 0 ? (SBTF1){} : (SBTF3){}; // expected-error {{from 'SS1'}}
-N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 btf_type_tag(1)' (aka 'SS1')}}
+N t22 = 0 ? (SBTF1){} : (SBTF2){}; // expected-error {{from 'SS1 __attribute__((btf_type_tag("1")))' (aka 'SS1')}}
 
 using QX = const SB1 *;
 using QY = const ::SB1 *;
Index: clang/test/Sema/attr-btf_type_tag.c
===
--- clang/test/Sema/attr-btf_type_tag.c
+++ clang/test/Sema/attr-btf_type_tag.c
@@ -28,8 +28,8 @@
 int g1 = _Generic((int *)0, int __tag1 *: 0);
 int g2 = _Generic((int __tag1 *)0, int *: 0);
 int g3 = _Generic(0,
-  int __tag1 * : 0, // expected-note {{compatible type 'int  btf_type_tag(tag1)*' (aka 'int *') specified here}}
-  int * : 0, // expected-error {{type 'int *' in generic association compatible with previously specified type 'int  btf_type_tag(tag1)*' (aka 'int *')}}
+  int __tag1 * : 0, // expected-note {{compatible type 'int  __attribute__((btf_type_tag("tag1")))*' (aka 'int *') specified here}}
+  int * : 0, // expected-error {{type 'int *' in generic association compatible with previously specified type 'int  __attribute__((btf_type_tag("tag1")))*' (aka 'int *')}}
   default : 0);
 
 // The btf_type_tag attribute will be ignored during overloadable type matching
Index: clang/test/AST/ast-dump-bp

[PATCH] D147217: [OpenMP][OMPIRBuilder] OpenMPIRBuilder support for requires directive

2023-05-08 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 520374.
skatrak added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147217

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1269,8 +1269,11 @@
 // TODO: set the flags when available
 llvm::OpenMPIRBuilderConfig Config(
 isDevice, /* IsTargetCodegen */ false,
+/* OpenMPOffloadMandatory */ false,
+/* HasRequiresReverseOffload */ false,
+/* HasRequiresUnifiedAddress */ false,
 /* HasRequiresUnifiedSharedMemory */ false,
-/* OpenMPOffloadMandatory */ false);
+/* HasRequiresDynamicAllocators */ false);
 ompBuilder->setConfig(Config);
   }
   return ompBuilder.get();
Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -9,12 +9,14 @@
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
 #include "llvm/Frontend/OpenMP/OMPIRBuilder.h"
 #include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
 #include "llvm/IR/DIBuilder.h"
 #include "llvm/IR/Function.h"
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/Type.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Support/Casting.h"
@@ -5123,7 +5125,7 @@
   using InsertPointTy = OpenMPIRBuilder::InsertPointTy;
   OpenMPIRBuilder OMPBuilder(*M);
   OMPBuilder.initialize();
-  OpenMPIRBuilderConfig Config(false, false, false, false);
+  OpenMPIRBuilderConfig Config(false, false, false, false, false, false, false);
   OMPBuilder.setConfig(Config);
   F->setName("func");
   IRBuilder<> Builder(BB);
@@ -5751,7 +5753,8 @@
 
 TEST_F(OpenMPIRBuilderTest, OffloadEntriesInfoManager) {
   OpenMPIRBuilder OMPBuilder(*M);
-  OMPBuilder.setConfig(OpenMPIRBuilderConfig(true, false, false, false));
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(true, false, false, false, false, false, false));
   OffloadEntriesInfoManager &InfoManager = OMPBuilder.OffloadInfoManager;
   TargetRegionEntryInfo EntryInfo("parent", 1, 2, 4, 0);
   InfoManager.initializeTargetRegionEntryInfo(EntryInfo, 0);
@@ -5766,4 +5769,44 @@
   GlobalValue::WeakAnyLinkage);
   EXPECT_TRUE(InfoManager.hasDeviceGlobalVarEntryInfo("gvar"));
 }
+
+TEST_F(OpenMPIRBuilderTest, CreateRegisterRequires) {
+  OpenMPIRBuilder OMPBuilder(*M);
+  OMPBuilder.initialize();
+
+  OMPBuilder.setConfig(
+  OpenMPIRBuilderConfig(/*IsEmbedded=*/false,
+/*IsTargetCodegen=*/false,
+/*OpenMPOffloadMandatory=*/false,
+/*HasRequiresReverseOffload=*/true,
+/*HasRequiresUnifiedAddress=*/false,
+/*HasRequiresUnifiedSharedMemory=*/true,
+/*HasRequiresDynamicAllocators=*/false));
+
+  auto FName =
+  OMPBuilder.createPlatformSpecificName({"omp_offloading", "requires_reg"});
+  EXPECT_EQ(FName, ".omp_offloading.requires_reg");
+
+  Function *Fn = OMPBuilder.createRegisterRequires(FName);
+  EXPECT_NE(Fn, nullptr);
+  EXPECT_EQ(FName, Fn->getName());
+
+  EXPECT_EQ(Fn->getSection(), ".text.startup");
+  EXPECT_TRUE(Fn->hasInternalLinkage());
+  EXPECT_TRUE(Fn->hasFnAttribute(Attribute::NoInline));
+  EXPECT_TRUE(Fn->hasFnAttribute(Attribute::NoUnwind));
+  EXPECT_EQ(Fn->size(), 1u);
+
+  BasicBlock *Entry = &Fn->getEntryBlock();
+  EXPECT_FALSE(Entry->empty());
+  EXPECT_EQ(Fn->getReturnType()->getTypeID(), Type::VoidTyID);
+
+  CallInst *Call = &cast(*Entry->begin());
+  EXPECT_EQ(Call->getCalledFunction()->getName(), "__tgt_register_requires");
+  EXPECT_EQ(Call->getNumOperands(), 2u);
+
+  Value *Flags = Call->getArgOperand(0);
+  EXPECT_EQ(cast(Flags)->getSExtValue(),
+OMPBuilder.Config.getRequiresFlags());
+}
 } // namespace
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -21,10 +21,12 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
 #i

[PATCH] D144190: [AIX][clang] Storage Locations for Constant Pointers

2023-05-08 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 updated this revision to Diff 520375.
qiongsiwu1 added a comment.

Rebase. Ping for review @hubert.reinterpretcast . Thanks so much!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144190

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/AIX.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/PowerPC/aix-roptr.c
  clang/test/Driver/ppc-roptr.c

Index: clang/test/Driver/ppc-roptr.c
===
--- /dev/null
+++ clang/test/Driver/ppc-roptr.c
@@ -0,0 +1,46 @@
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -c -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff -mxcoff-roptr -mno-xcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=NO_ROPTR
+
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -S -mxcoff-roptr %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=ROPTR
+// RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
+// RUN: FileCheck %s --check-prefix=NO_ROPTR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \
+// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: touch %t.o
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \
+// RUN: FileCheck %s --check-prefix=LINK
+
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mxcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
+// RUN: touch %t.o
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -shared \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=SHARED_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mxcoff-roptr -flto \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto -fno-data-sections \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mno-xcoff-roptr -flto -fno-data-sections \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=NO_DATA_SECTION_ERR
+// RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \
+// RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: "-bforceimprw"
+
+// DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections
+// NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections
+// TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
+// TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
+// SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
Index: clang/test/CodeGen/PowerPC/aix-roptr.c
===
--- /dev/null
+++ clang/test/CodeGen/PowerPC/aix-roptr.c
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK32
+// RUN: %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr -fdata-sections \
+// RUN: -S <%s | FileCheck %s --check-prefix=CHECK64
+// RUN: not %clang_cc1 -triple=powerpc-ibm-aix-xcoff -mxcoff-roptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64-ibm-aix-xcoff -mxcoff-roptr \
+// RUN: -S <%s 2>&1 | FileCheck %s --check-prefix=DATA_SECTION_ERR
+// RUN: not %clang_cc1 -triple=powerpc64le-unknown-linux-gnu -mxcoff-roptr \
+// RUN: %s 2>&1 | FileCheck %s --check-prefix=TARGET_ROPTR_ERR
+
+char c1 = 10;
+char c2 = 20;
+char* const c1_ptr = &c1;
+// CHECK32: .csect c1_ptr[RO],2
+// CHECK32-NEXT:	.globl	c1_ptr[RO]
+// CHECK32-NEXT:	.align	2
+// CHECK32-NEXT:	.vbyte	4, c1[RW]
+
+// CHECK64: .csect c1_ptr[RO],3
+// CHECK64-NEXT:	.globl	c1_ptr[RO]
+// CHECK64-NEXT:	.align	3
+// CHECK64-NEXT:	.vbyte	8, c1[RW]
+
+// DATA_SECTION_ERR: error: -mxcoff-

[PATCH] D146188: [Clang][DOC] Add documentation in for __builtin_flt_rounds and __builtin_set_flt_rounds

2023-05-08 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146188

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


[PATCH] D149215: [MemProf] Control availability of hot/cold operator new from LTO link

2023-05-08 Thread Teresa Johnson 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 rG176889868024: [MemProf] Control availability of hot/cold 
operator new from LTO link (authored by tejohnson).

Changed prior to commit:
  https://reviews.llvm.org/D149215?vs=518721&id=520379#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149215

Files:
  clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
  llvm/include/llvm/IR/ModuleSummaryIndex.h
  llvm/include/llvm/LTO/LTO.h
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/lib/IR/ModuleSummaryIndex.cpp
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
  llvm/test/LTO/X86/memprof-supports-hot-cold-new.ll
  llvm/test/ThinLTO/X86/memprof-basic.ll
  llvm/test/ThinLTO/X86/memprof-duplicate-context-ids.ll
  llvm/test/ThinLTO/X86/memprof-duplicate-context-ids2.ll
  llvm/test/ThinLTO/X86/memprof-funcassigncloning.ll
  llvm/test/ThinLTO/X86/memprof-indirectcall.ll
  llvm/test/ThinLTO/X86/memprof-inlined.ll
  llvm/test/ThinLTO/X86/memprof-inlined2.ll
  llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll
  llvm/test/Transforms/MemProfContextDisambiguation/basic.ll
  llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids.ll
  llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll
  llvm/test/Transforms/MemProfContextDisambiguation/funcassigncloning.ll
  llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll
  llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll
  llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll

Index: llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll
@@ -42,7 +42,7 @@
 ;;
 ;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:	-memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
 ; RUN:	%s -S 2>&1 | FileCheck %s --check-prefix=DUMP
 
Index: llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll
@@ -44,7 +44,7 @@
 ;; -stats requires asserts
 ; REQUIRES: asserts
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:	-memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
 ; RUN:	-memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
 ; RUN:  -stats -pass-remarks=memprof-context-disambiguation \
Index: llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll
@@ -54,7 +54,7 @@
 ;; -stats requires asserts
 ; REQUIRES: asserts
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:  -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
 ; RUN:  -memprof-export-to-dot -memprof-dot-file-path-prefix=%t. \
 ; RUN:  -stats -pass-remarks=memprof-context-disambiguation \
Index: llvm/test/Transforms/MemProfContextDisambiguation/funcassigncloning.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/funcassigncloning.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/funcassigncloning.ll
@@ -48,7 +48,7 @@
 ;; -stats requires asserts
 ; REQUIRES: asserts
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:  -memprof-verify-ccg -memprof-verify-nodes -memprof-dump-ccg \
 ; RUN:  -stats -pass-remarks=memprof-context-disambiguation \
 ; RUN:  %s -S 2>&1 | FileCheck %s --check-prefix=DUMP --check-prefix=IR \
Index: llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll
===
--- llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll
+++ llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll
@@ -93,7 +93,7 @@
 ;;
 ;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
 
-; RUN: opt -passes=memprof-context-disambiguation \
+; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
 ; RUN:  -mem

[clang] 1768898 - [MemProf] Control availability of hot/cold operator new from LTO link

2023-05-08 Thread Teresa Johnson via cfe-commits

Author: Teresa Johnson
Date: 2023-05-08T08:02:21-07:00
New Revision: 176889868024d98db032842bc47b416997d9e349

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

LOG: [MemProf] Control availability of hot/cold operator new from LTO link

Adds an LTO option to indicate that whether we are linking with an
allocator that supports hot/cold operator new interfaces. If not,
at the start of the LTO backends any existing memprof hot/cold
attributes are removed from the IR, and we also remove memprof metadata
so that post-LTO inlining doesn't add any new attributes.

This is done via setting a new flag in the module summary index. It is
important to communicate via the index to the LTO backends so that
distributed ThinLTO handles this correctly, as they are invoked by
separate clang processes and the combined index is how we communicate
information from the LTO link. Specifically, for distributed ThinLTO the
LTO related processes look like:
```
   # Thin link:
   $ lld --thinlto-index-only obj1.o ... objN.o -llib ...
   # ThinLTO backends:
   $ clang -x ir obj1.o -fthinlto-index=obj1.o.thinlto.bc -c -O2
   ...
   $ clang -x ir objN.o -fthinlto-index=objN.o.thinlto.bc -c -O2
```

It is during the thin link (lld --thinlto-index-only) that we have
visibility into linker dependences and want to be able to pass the new
option via -Wl,-supports-hot-cold-new. This will be recorded in the
summary indexes created for the distributed backend processes
(*.thinlto.bc) and queried from there, so that we don't need to know
during those individual clang backends what allocation library was
linked. Since in-process ThinLTO and regular LTO also use a combined
index, for consistency we query the flag out of the index in all LTO
backends.

Additionally, when the LTO option is disabled, exit early from the
MemProfContextDisambiguation handling performed during LTO, as this is
unnecessary.

Depends on D149117 and D149192.

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

Added: 
clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
llvm/test/LTO/X86/memprof-supports-hot-cold-new.ll
llvm/test/ThinLTO/X86/memprof-supports-hot-cold-new.ll

Modified: 
llvm/include/llvm/IR/ModuleSummaryIndex.h
llvm/include/llvm/LTO/LTO.h
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/ModuleSummaryIndex.cpp
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
llvm/test/ThinLTO/X86/memprof-basic.ll
llvm/test/ThinLTO/X86/memprof-duplicate-context-ids.ll
llvm/test/ThinLTO/X86/memprof-duplicate-context-ids2.ll
llvm/test/ThinLTO/X86/memprof-funcassigncloning.ll
llvm/test/ThinLTO/X86/memprof-indirectcall.ll
llvm/test/ThinLTO/X86/memprof-inlined.ll
llvm/test/ThinLTO/X86/memprof-inlined2.ll
llvm/test/Transforms/MemProfContextDisambiguation/basic.ll
llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids.ll
llvm/test/Transforms/MemProfContextDisambiguation/duplicate-context-ids2.ll
llvm/test/Transforms/MemProfContextDisambiguation/funcassigncloning.ll
llvm/test/Transforms/MemProfContextDisambiguation/indirectcall.ll
llvm/test/Transforms/MemProfContextDisambiguation/inlined.ll
llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll 
b/clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
new file mode 100644
index ..e213fbaf3fa1
--- /dev/null
+++ b/clang/test/CodeGen/thinlto-distributed-supports-hot-cold-new.ll
@@ -0,0 +1,70 @@
+; REQUIRES: x86-registered-target
+
+;; Test that passing -supports-hot-cold-new to the thin link prevents memprof
+;; metadata and attributes from being removed from the distributed ThinLTO
+;; backend, and vice versa without passing -supports-hot-cold-new.
+
+;; First check with -supports-hot-cold-new.
+; RUN: opt -thinlto-bc %s >%t.o
+; RUN: llvm-lto2 run %t.o -save-temps \
+; RUN:  -supports-hot-cold-new \
+; RUN:  -thinlto-distributed-indexes \
+; RUN:  -r=%t.o,main,plx \
+; RUN:  -r=%t.o,_Znam, \
+; RUN:  -o %t.out
+
+;; Ensure that the index file reflects the -supports-hot-cold-new, as that is
+;; how the ThinLTO backend behavior is controlled.
+; RUN: llvm-dis %t.out.index.bc -o - | FileCheck %s 
--check-prefix=CHECK-INDEX-ON
+;; Flags are printed in decimal, but this corresponds to 0x161, and 0x100 is
+;; the value indicating -supports-hot-cold-new was enabled.
+; CHECK-INDEX-ON: flags: 353
+
+; RUN: %clang -target x86_64-unknown-linux-gnu -O2 -o %t1.o -x ir %t.o -c 
-fthinlto-index=%t.o.thinlto.bc -save-temps=obj
+
+; RUN: llvm-dis %t.s.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
+; CHECK-IR: !memp

[PATCH] D150108: [clang] Evaluate non-type default template argument when it is required

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



Comment at: clang/lib/Sema/SemaTemplate.cpp:1614
 
-TemplateArgument SugaredConverted, CanonicalConverted;
-ExprResult DefaultRes = CheckTemplateArgument(

Out of curiosity where is the template argument being checked now and why does 
checking it early cause the failure?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150108

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


[PATCH] D146399: [AIX][Clang][K] Create `-K` Option for AIX.

2023-05-08 Thread David Tenty via Phabricator via cfe-commits
daltenty added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6331
 
+  if (Arg *A = Args.getLastArg(options::OPT_K); A && !TC.getTriple().isOSAIX())
+D.Diag(diag::err_drv_unsupported_opt_for_target)

Let's not claim here, just in case this isn't a link step invocation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146399

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


[PATCH] D149718: [NFC][Clang] Fix Coverity issues of copy without assign

2023-05-08 Thread Soumi Manna via Phabricator via cfe-commits
Manna updated this revision to Diff 520384.
Manna added a comment.

Thanks @tahonermann for reviews. I have addressed review comments and updated 
patches.


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

https://reviews.llvm.org/D149718

Files:
  clang/include/clang/Analysis/BodyFarm.h
  clang/include/clang/Sema/ParsedAttr.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Analysis/UnsafeBufferUsage.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp


Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -42,6 +42,7 @@
   Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
 
 ASTStmtWriter(const ASTStmtWriter&) = delete;
+ASTStmtWriter &operator=(const ASTStmtWriter &) = delete;
 
 uint64_t Emit() {
   assert(Code != serialization::STMT_NULL_PTR &&
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -762,7 +762,9 @@
 public:
   Strategy() = default;
   Strategy(const Strategy &) = delete; // Let's avoid copies.
+  Strategy &operator=(const Strategy &) = delete;
   Strategy(Strategy &&) = default;
+  Strategy &operator=(Strategy &&) = default;
 
   void set(const VarDecl *VD, Kind K) { Map[VD] = K; }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1783,7 +1783,9 @@
 SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID,
   const FunctionDecl *Fn, Sema &S);
 SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D);
+SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&D);
 SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;
+SemaDiagnosticBuilder &operator=(const SemaDiagnosticBuilder &) = default;
 ~SemaDiagnosticBuilder();
 
 bool isImmediate() const { return ImmediateDiag.has_value(); }
Index: clang/include/clang/Sema/ParsedAttr.h
===
--- clang/include/clang/Sema/ParsedAttr.h
+++ clang/include/clang/Sema/ParsedAttr.h
@@ -696,11 +696,13 @@
   AttributePool(AttributeFactory &factory) : Factory(factory) {}
 
   AttributePool(const AttributePool &) = delete;
+  AttributePool &operator=(const AttributePool &) = delete;
 
   ~AttributePool() { Factory.reclaimPool(*this); }
 
   /// Move the given pool's allocations to this pool.
   AttributePool(AttributePool &&pool) = default;
+  AttributePool &operator=(AttributePool &&pool) = default;
 
   AttributeFactory &getFactory() const { return Factory; }
 
@@ -912,6 +914,7 @@
 public:
   ParsedAttributes(AttributeFactory &factory) : pool(factory) {}
   ParsedAttributes(const ParsedAttributes &) = delete;
+  ParsedAttributes &operator=(const ParsedAttributes &) = delete;
 
   AttributePool &getPool() const { return pool; }
 
Index: clang/include/clang/Analysis/BodyFarm.h
===
--- clang/include/clang/Analysis/BodyFarm.h
+++ clang/include/clang/Analysis/BodyFarm.h
@@ -40,6 +40,9 @@
   /// Remove copy constructor to avoid accidental copying.
   BodyFarm(const BodyFarm &other) = delete;
 
+  /// Delete copy assignment operator.
+  BodyFarm &operator=(const BodyFarm &other) = delete;
+
 private:
   typedef llvm::DenseMap> BodyMap;
 


Index: clang/lib/Serialization/ASTWriterStmt.cpp
===
--- clang/lib/Serialization/ASTWriterStmt.cpp
+++ clang/lib/Serialization/ASTWriterStmt.cpp
@@ -42,6 +42,7 @@
   Code(serialization::STMT_NULL_PTR), AbbrevToUse(0) {}
 
 ASTStmtWriter(const ASTStmtWriter&) = delete;
+ASTStmtWriter &operator=(const ASTStmtWriter &) = delete;
 
 uint64_t Emit() {
   assert(Code != serialization::STMT_NULL_PTR &&
Index: clang/lib/Analysis/UnsafeBufferUsage.cpp
===
--- clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -762,7 +762,9 @@
 public:
   Strategy() = default;
   Strategy(const Strategy &) = delete; // Let's avoid copies.
+  Strategy &operator=(const Strategy &) = delete;
   Strategy(Strategy &&) = default;
+  Strategy &operator=(Strategy &&) = default;
 
   void set(const VarDecl *VD, Kind K) { Map[VD] = K; }
 
Index: clang/include/clang/Sema/Sema.h
===
--- clang/include/clang/Sema/Sema.h
+++ clang/include/clang/Sema/Sema.h
@@ -1783,7 +1783,9 @@
 SemaDiagnosticBuilder(Kind K, SourceLocation Loc, unsigned DiagID,
   const FunctionDecl *Fn, Sema &S);
 SemaDiagnosticBuilder(SemaDiagnosticBuilder

[PATCH] D143467: [PowerPC] Add target feature requirement to builtins

2023-05-08 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added a comment.

Breaks these bots?
https://lab.llvm.org/buildbot/#/builders/18/builds/8898
https://lab.llvm.org/buildbot/#/builders/19/builds/16412


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D143467

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


[PATCH] D150108: [clang] Evaluate non-type default template argument when it is required

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



Comment at: clang/lib/Sema/SemaTemplate.cpp:1614
 
-TemplateArgument SugaredConverted, CanonicalConverted;
-ExprResult DefaultRes = CheckTemplateArgument(

shafik wrote:
> Out of curiosity where is the template argument being checked now and why 
> does checking it early cause the failure?
After the patch template argument is checked when the template is instantiated, 
i.e. the check now happens together for the whole provided template argument 
list.
Early checking causes reject-valid problems when for example a function is 
forward declared, used in default template argument and then defined later but 
before the point of instantiation. With early check the error also would be 
emitted if default template argument was never used.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150108

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


[PATCH] D150122: [Clang] Fix status of P0960

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

P0960R3 and P1975R0 were marked not implemented because
of #61145,

This issue has been fixed and backported to LLVM 16,
the status page should reflect that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150122

Files:
  clang/www/cxx_status.html


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1163,7 +1163,7 @@
 
   Parenthesized initialization of aggregates
   https://wg21.link/p0960r3";>P0960R3
-  No
+  Clang 16
 

 https://wg21.link/p1975r0";>P1975R0


Index: clang/www/cxx_status.html
===
--- clang/www/cxx_status.html
+++ clang/www/cxx_status.html
@@ -1163,7 +1163,7 @@
 
   Parenthesized initialization of aggregates
   https://wg21.link/p0960r3";>P0960R3
-  No
+  Clang 16
 

 https://wg21.link/p1975r0";>P1975R0
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D150122: [Clang] Fix status of P0960

2023-05-08 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added subscribers: erichkeane, aaron.ballman.
cor3ntin added a comment.

@aaron.ballman @erichkeane I'll merge that later today unless you see a reason 
not to.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150122

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


[PATCH] D149718: [NFC][Clang] Fix Coverity issues of copy without assign

2023-05-08 Thread Soumi Manna via Phabricator via cfe-commits
Manna marked 6 inline comments as done.
Manna added inline comments.



Comment at: clang/include/clang/Sema/ParsedAttr.h:704
   /// Move the given pool's allocations to this pool.
   AttributePool(AttributePool &&pool) = default;
 

tahonermann wrote:
> This class has a move constructor, but the implicit declaration of a move 
> assignment operator will be inhibited due to the presence of this and other 
> special member functions. That means that an attempted move assignment will 
> find the deleted copy assignment. That is ok; if support for move assignment 
> is desired some day, it can be added then.
I have added defaulted move assignment operator which seems needed based on 
analysis with other bugs.  



Comment at: clang/include/clang/Sema/Sema.h:1786
 SemaDiagnosticBuilder(SemaDiagnosticBuilder &&D);
+SemaDiagnosticBuilder &operator=(SemaDiagnosticBuilder &&D);
 SemaDiagnosticBuilder(const SemaDiagnosticBuilder &) = default;

tahonermann wrote:
> Since this class declares a move constructor, the declaration of the implicit 
> move assignment operator is inhibited and the implicitly declared assignment 
> operator is defined as deleted. This change declares a move assignment 
> operator but doesn't define it (perhaps `= delete` was intended?). If support 
> for assignment is not desired, then I think a declaration of a deleted copy 
> assignment operator is all that is needed (matching the change made for 
> `Strategy` below). Otherwise, I think a defaulted copy assignment operator 
> should be declared and a move assignment operator should be defined that 
> implements the same behavior as the move constructor.
Thanks @tahonermann for the comments. 

>> think a defaulted copy assignment operator should be declared and a move 
>> assignment operator should be defined that implements the same behavior as 
>> the move constructor.

I have updated patch based on further analysis and my understanding. This seems 
reasonable to me.


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

https://reviews.llvm.org/D149718

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


[PATCH] D150122: [Clang] Fix status of P0960

2023-05-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I've got no problems with this.  I'm a little suspicious of marking this done 
in clang-16 if this was done only at the end of the branch though?  And do we 
know there is going to be another Clang 16 release?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150122

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


[PATCH] D150122: [Clang] Fix status of P0960

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

In D150122#4326935 , @erichkeane 
wrote:

> I've got no problems with this.  I'm a little suspicious of marking this done 
> in clang-16 if this was done only at the end of the branch though?  And do we 
> know there is going to be another Clang 16 release?

Yes, I was asking myself the same question,  I have no issue being conservative 
and saying 17 instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150122

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


[PATCH] D150122: [Clang] Fix status of P0960

2023-05-08 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D150122#4326941 , @cor3ntin wrote:

> In D150122#4326935 , @erichkeane 
> wrote:
>
>> I've got no problems with this.  I'm a little suspicious of marking this 
>> done in clang-16 if this was done only at the end of the branch though?  And 
>> do we know there is going to be another Clang 16 release?
>
> Yes, I was asking myself the same question,  I have no issue being 
> conservative and saying 17 instead.

Perhaps worth making Aaron make the decision :D


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150122

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


[PATCH] D150038: [Clang] Improve compile times when forming a DeclRef outside of a capturing scope.

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

In D150038#4326576 , @aaron.ballman 
wrote:

> In D150038#4326554 , @cor3ntin 
> wrote:
>
>> In D150038#4326549 , 
>> @aaron.ballman wrote:
>>
>>> Do you have some performance measurement numbers for how much benefit we 
>>> get from the changes?
>>
>> Not really.
>> The PR that changed the scope of trailing return type had a 0.35% 
>> regression, I expect this to be in the same ballpark in the other direction
>> http://llvm-compile-time-tracker.com/compare.php?from=cd173cbd7cca69c29df42cd4b42e60433435c29b&to=d708a186b6a9b050d09558163dd353d9f738c82d&stat=instructions%3Au
>
> We usually want performance-related changes to come with some hard 
> measurements because of how painfully easy it is to think something will 
> result in a positive performance change that ends up being a wash. Would you 
> mind putting a branch up on the compile time tracker page to validate your 
> expectations? .35% better performance would be nice to see!

Ask and you shall receive http://llvm-compile-time-tracker.com/?remote=cor3ntin


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150038

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


[PATCH] D147218: [OpenMP][Flang][MLIR] Lowering of OpenMP requires directive from parse tree to MLIR

2023-05-08 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 520398.
skatrak added a comment.

Rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

Files:
  flang/include/flang/Lower/OpenMP.h
  flang/lib/Lower/Bridge.cpp
  flang/lib/Lower/OpenMP.cpp
  flang/test/Lower/OpenMP/requires-notarget.f90
  flang/test/Lower/OpenMP/requires.f90
  mlir/lib/Dialect/OpenMP/CMakeLists.txt

Index: mlir/lib/Dialect/OpenMP/CMakeLists.txt
===
--- mlir/lib/Dialect/OpenMP/CMakeLists.txt
+++ mlir/lib/Dialect/OpenMP/CMakeLists.txt
@@ -12,4 +12,5 @@
   LINK_LIBS PUBLIC
   MLIRIR
   MLIRLLVMDialect
+  MLIRFuncDialect
   )
Index: flang/test/Lower/OpenMP/requires.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires.f90
@@ -0,0 +1,13 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks the lowering of requires into MLIR
+
+!CHECK:  module attributes {
+!CHECK-SAME: omp.requires = #omp
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
+
+subroutine f
+  !$omp declare target
+end subroutine f
Index: flang/test/Lower/OpenMP/requires-notarget.f90
===
--- /dev/null
+++ flang/test/Lower/OpenMP/requires-notarget.f90
@@ -0,0 +1,11 @@
+! RUN: %flang_fc1 -emit-fir -fopenmp %s -o - | FileCheck %s
+
+! This test checks that requires lowering into MLIR skips creating the
+! omp.requires attribute with target-related clauses if there are no device
+! functions in the compilation unit
+
+!CHECK:  module attributes {
+!CHECK-NOT:  omp.requires
+program requires
+  !$omp requires unified_shared_memory reverse_offload atomic_default_mem_order(seq_cst)
+end program requires
Index: flang/lib/Lower/OpenMP.cpp
===
--- flang/lib/Lower/OpenMP.cpp
+++ flang/lib/Lower/OpenMP.cpp
@@ -23,7 +23,10 @@
 #include "flang/Parser/parse-tree.h"
 #include "flang/Semantics/tools.h"
 #include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/Dialect/SCF/IR/SCF.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
 
 using namespace mlir;
 
@@ -2469,14 +2472,14 @@
   converter.bindSymbol(sym, symThreadprivateExv);
 }
 
-void handleDeclareTarget(Fortran::lower::AbstractConverter &converter,
- Fortran::lower::pft::Evaluation &eval,
- const Fortran::parser::OpenMPDeclareTargetConstruct
- &declareTargetConstruct) {
-  llvm::SmallVector,
-0>
-  symbolAndClause;
+/// Extract the list of function and variable symbols affected by the given
+/// 'declare target' directive and return the intended device type for them.
+static mlir::omp::DeclareTargetDeviceType getDeclareTargetInfo(
+Fortran::lower::pft::Evaluation &eval,
+const Fortran::parser::OpenMPDeclareTargetConstruct &declareTargetConstruct,
+SmallVectorImpl> &symbolAndClause) {
+  // Gather the symbols and clauses
   auto findFuncAndVarSyms = [&](const Fortran::parser::OmpObjectList &objList,
 mlir::omp::DeclareTargetCaptureClause clause) {
 for (const auto &ompObject : objList.v) {
@@ -2496,12 +2499,11 @@
 }
   };
 
+  // The default capture type
+  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   const auto &spec{std::get(
   declareTargetConstruct.t)};
-  auto mod = converter.getFirOpBuilder().getModule();
 
-  // The default capture type
-  auto deviceType = Fortran::parser::OmpDeviceTypeClause::Type::Any;
   if (const auto *objectList{
   Fortran::parser::Unwrap(spec.u)}) {
 // Case: declare target(func, var1, var2)
@@ -2537,6 +2539,28 @@
 }
   }
 
+  switch (deviceType) {
+  case Fortran::parser::OmpDeviceTypeClause::Type::Any:
+return mlir::omp::DeclareTargetDeviceType::any;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Host:
+return mlir::omp::DeclareTargetDeviceType::host;
+  case Fortran::parser::OmpDeviceTypeClause::Type::Nohost:
+return mlir::omp::DeclareTargetDeviceType::nohost;
+  }
+}
+
+void handleDeclareTarget(Fortran::lower::AbstractConverter &converter,
+ Fortran::lower::pft::Evaluation &eval,
+ const Fortran::parser::OpenMPDeclareTargetConstruct
+ &declareTargetConstruct) {
+  llvm::SmallVector,
+0>
+  symbolAndClause;
+  auto deviceType =
+  getDeclareTargetInfo(eval, declareTargetConstruct, symbolAndClause);
+
+  auto mod = converter.getFirOpBuilder().getModule();
   for (auto sym : symbolAndClause) {
 auto *op = mod.lookupSymbol(converter.mangleName(std::get<1>(sym)));
 
@@ -2546,32 +2570,19 @@

[PATCH] D150124: [index][clangd] Consider labels when indexing function bodies

2023-05-08 Thread Christian Kandeler via Phabricator via cfe-commits
ckandeler created this revision.
ckandeler added a reviewer: ilya-biryukov.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
ckandeler requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added projects: clang, clang-tools-extra.

It's valuable to have document highlights for labels and be able to find
references to them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150124

Files:
  clang-tools-extra/clangd/unittests/XRefsTests.cpp
  clang/lib/Index/IndexBody.cpp


Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -144,6 +144,23 @@
 Parent, ParentDC, Roles, Relations, E);
   }
 
+  bool VisitGotoStmt(GotoStmt *S) {
+if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+  return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,
+  ParentDC,
+  unsigned(SymbolRole::NameReference));
+}
+return true;
+  }
+
+  bool VisitLabelStmt(LabelStmt *S) {
+if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+  return IndexCtx.handleReference(S->getDecl(), S->getIdentLoc(), Parent,
+  ParentDC, {});
+}
+return true;
+  }
+
   bool VisitMemberExpr(MemberExpr *E) {
 SourceLocation Loc = E->getMemberLoc();
 if (Loc.isInvalid())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -127,6 +127,13 @@
   [Foo [[x]]:2 [[^y]]:4];
 }
   )cpp",
+  R"cpp( // Label
+int main() {
+  goto [[^theLabel]];
+  [[theLabel]]:
+return 1;
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);


Index: clang/lib/Index/IndexBody.cpp
===
--- clang/lib/Index/IndexBody.cpp
+++ clang/lib/Index/IndexBody.cpp
@@ -144,6 +144,23 @@
 Parent, ParentDC, Roles, Relations, E);
   }
 
+  bool VisitGotoStmt(GotoStmt *S) {
+if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+  return IndexCtx.handleReference(S->getLabel(), S->getLabelLoc(), Parent,
+  ParentDC,
+  unsigned(SymbolRole::NameReference));
+}
+return true;
+  }
+
+  bool VisitLabelStmt(LabelStmt *S) {
+if (IndexCtx.shouldIndexFunctionLocalSymbols()) {
+  return IndexCtx.handleReference(S->getDecl(), S->getIdentLoc(), Parent,
+  ParentDC, {});
+}
+return true;
+  }
+
   bool VisitMemberExpr(MemberExpr *E) {
 SourceLocation Loc = E->getMemberLoc();
 if (Loc.isInvalid())
Index: clang-tools-extra/clangd/unittests/XRefsTests.cpp
===
--- clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -127,6 +127,13 @@
   [Foo [[x]]:2 [[^y]]:4];
 }
   )cpp",
+  R"cpp( // Label
+int main() {
+  goto [[^theLabel]];
+  [[theLabel]]:
+return 1;
+}
+  )cpp",
   };
   for (const char *Test : Tests) {
 Annotations T(Test);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149280: [clang-tidy] Add modernize-printf-to-std-print check

2023-05-08 Thread Mike Crowe via Phabricator via cfe-commits
mikecrowe marked 3 inline comments as done.
mikecrowe added inline comments.



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp:124-126
+  printf("Integer %d from bool\n", b);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::print' instead of 
'printf' [modernize-use-std-print]
+  // CHECK-FIXES: std::print("Integer {:d} from bool\n", b);

njames93 wrote:
> It would be nice if the there was support for changing this to 
> `std::println("Integer {:d} from bool", b);`
Yes. That was item 2 on the plans for the future in my first comment. Would you 
prefer that everything is completed in this single commit, or would you be 
happy to the core functionality first with future enhancements in separate 
commits afterwards?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149280

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


[PATCH] D149579: [X86][MC] Fix parsing Intel syntax indirect branch with symbol only

2023-05-08 Thread Alvin Wong via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG8cd90fd1a823: [X86][MC] Fix parsing Intel syntax indirect 
branch with symbol only (authored by alvinhochun).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149579

Files:
  clang/test/CodeGen/ms-inline-asm-functions.c
  llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
  llvm/test/MC/X86/intel-syntax-branch.s

Index: llvm/test/MC/X86/intel-syntax-branch.s
===
--- /dev/null
+++ llvm/test/MC/X86/intel-syntax-branch.s
@@ -0,0 +1,71 @@
+// RUN: llvm-mc -triple i686-unknown-unknown -x86-asm-syntax=intel %s | FileCheck %s --check-prefixes=CHECK-32,CHECK
+// RUN: llvm-mc -triple x86_64-unknown-unknown --defsym X64=1 -x86-asm-syntax=intel %s | FileCheck %s --check-prefixes=CHECK-64,CHECK
+
+// RUN: not llvm-mc -triple i686-unknown-unknown --defsym ERR=1 -x86-asm-syntax=intel %s 2>&1 | FileCheck %s --check-prefixes=ERR-32
+
+t0:
+call direct_branch
+jmp direct_branch
+// CHECK-LABEL: t0:
+// CHECK-64: callq direct_branch
+// CHECK-32: calll direct_branch
+// CHECK:jmp direct_branch
+
+t1:
+call [fn_ref]
+jmp [fn_ref]
+// CHECK-LABEL: t1:
+// CHECK-64: callq *fn_ref
+// CHECK-64: jmpq *fn_ref
+// CHECK-32: calll *fn_ref
+// CHECK-32: jmpl *fn_ref
+
+.ifdef X64
+
+  t2:
+  call qword ptr [fn_ref]
+  jmp qword ptr [fn_ref]
+  // CHECK-64-LABEL: t2:
+  // CHECK-64: callq *fn_ref
+  // CHECK-64: jmpq *fn_ref
+
+  t3:
+  call qword ptr [rip + fn_ref]
+  jmp qword ptr [rip + fn_ref]
+  // CHECK-64-LABEL: t3:
+  // CHECK-64: callq *fn_ref(%rip)
+  // CHECK-64: jmpq *fn_ref(%rip)
+
+.else
+
+  t4:
+  call dword ptr [fn_ref]
+  jmp dword ptr [fn_ref]
+  // CHECK-32-LABEL: t4:
+  // CHECK-32: calll *fn_ref
+  // CHECK-32: jmpl *fn_ref
+
+  t5:
+  call dword ptr fn_ref
+  jmp dword ptr fn_ref
+  // CHECK-32-LABEL: t5:
+  // CHECK-32: calll *fn_ref
+  // CHECK-32: jmpl *fn_ref
+
+  t6:
+  call dword ptr [offset fn_ref]
+  jmp dword ptr [offset fn_ref]
+  // CHECK-32-LABEL: t6:
+  // CHECK-32: calll *fn_ref
+  // CHECK-32: jmpl *fn_ref
+
+.ifdef ERR
+
+  call offset fn_ref
+  // ERR-32: {{.*}}.s:[[#@LINE-1]]:3: error: invalid operand for instruction
+  jmp offset fn_ref
+  // ERR-32: {{.*}}.s:[[#@LINE-1]]:3: error: invalid operand for instruction
+
+.endif
+
+.endif
Index: llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
===
--- llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -433,6 +433,7 @@
 InlineAsmIdentifierInfo Info;
 short BracCount = 0;
 bool MemExpr = false;
+bool BracketUsed = false;
 bool OffsetOperator = false;
 bool AttachToOperandIdx = false;
 bool IsPIC = false;
@@ -455,6 +456,7 @@
 void addImm(int64_t imm) { Imm += imm; }
 short getBracCount() const { return BracCount; }
 bool isMemExpr() const { return MemExpr; }
+bool isBracketUsed() const { return BracketUsed; }
 bool isOffsetOperator() const { return OffsetOperator; }
 SMLoc getOffsetLoc() const { return OffsetOperatorLoc; }
 unsigned getBaseReg() const { return BaseReg; }
@@ -955,6 +957,7 @@
 break;
   }
   MemExpr = true;
+  BracketUsed = true;
   BracCount++;
   return false;
 }
@@ -2628,9 +2631,9 @@
   unsigned DefaultBaseReg = X86::NoRegister;
   bool MaybeDirectBranchDest = true;
 
+  bool IsUnconditionalBranch =
+  Name.equals_insensitive("jmp") || Name.equals_insensitive("call");
   if (Parser.isParsingMasm()) {
-bool IsUnconditionalBranch =
-Name.equals_insensitive("jmp") || Name.equals_insensitive("call");
 if (is64BitMode() && SM.getElementSize() > 0) {
   DefaultBaseReg = X86::RIP;
 }
@@ -2652,6 +2655,9 @@
 }
   }
 }
+  } else if (IsUnconditionalBranch) {
+if (PtrInOperand || SM.isBracketUsed())
+  MaybeDirectBranchDest = false;
   }
 
   if ((BaseReg || IndexReg || RegNo || DefaultBaseReg != X86::NoRegister))
Index: clang/test/CodeGen/ms-inline-asm-functions.c
===
--- clang/test/CodeGen/ms-inline-asm-functions.c
+++ clang/test/CodeGen/ms-inline-asm-functions.c
@@ -24,10 +24,9 @@
   __asm call kimport;
   // CHECK: calll   *({{.*}})
 
-  // Broken case: Call through a global function pointer.
+  // Call through a global function pointer.
   __asm call kptr;
-  // CHECK: calll   _kptr
-  // CHECK-FIXME: calll   *_kptr
+  // CHECK: calll   *_kptr
 }
 
 int bar(void) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   3   >