[PATCH] D136532: [clang][Interp] Implement left and right shifts

2022-10-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/Interp.h:1246-1256
   if (V.isSigned() && !S.getLangOpts().CPlusPlus20) {
 // C++11 [expr.shift]p2: A signed left shift must have a non-negative
 // operand, and must not overflow the corresponding unsigned type.
 // C++2a [expr.shift]p2: E1 << E2 is the unique value congruent to
 // E1 x 2^E2 module 2^N.
 if (V.isNegative()) {
   const Expr *E = S.Current->getExpr(OpPC);

aaron.ballman wrote:
> Why do `Shr` and `Shl` check for a negative shift amount to issue a 
> diagnostic but we check for signed in `ShiftLeft` to issue a diagnostic? (I 
> would have expected the checks to all live in the same place.)
This was already implemented and I tried to keep as much code as possible, but 
I'll change that strategy ;)



Comment at: clang/test/AST/Interp/shifts.cpp:57
+//c >>= 99; // expected-warning {{shift count >= width of type}}
+//c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+//c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}}

shafik wrote:
> This is not correct, the operands go through integral promotions first and 
> the result is the promoted type of the left operand see [dcl.shift 
> p1](https://eel.is/c++draft/expr.shift#1).
> 
> Also see godbolt: https://godbolt.org/z/7qzKjojMb
Hmm, this is copy-pasted from `test/SemaCXX/shift.cpp`.



Comment at: clang/test/AST/Interp/shifts.cpp:70
+i = 1 << (WORD_BIT - 1); // cxx17-warning-not {{sets the sign bit of the 
shift expression}}
+i = -1 << (WORD_BIT - 1); // cxx17-warning {{shifting a negative signed 
value is undefined}} \
+  // ref-cxx17-warning {{shifting a negative 
signed value is undefined}}

shafik wrote:
> shafik wrote:
> > A negative left operand was made well-formed in C++20 I believe see 
> > godbolt: https://godbolt.org/z/7qzKjojMb
> > 
> > My reference from above for `expr.shift/p1` also applies. 
> > 
> > Although a negative right operand is still UB.
> > 
> > Also note shifting into the sign bit was made well-formed in C++11: 
> > https://stackoverflow.com/questions/19593938/is-left-shifting-a-negative-integer-undefined-behavior-in-c11#comment29091986_19593938
> Typo, shifting into the sign bit was made well-formed after C++11
This is in line with the test, isn't it? The warning is only for `cxx17`, the 
c++20 tests don't expect any output.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136532

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


[PATCH] D136660: [clang] Replace BACKEND_PACKAGE_STRING with LLVM_VERSION_STRING

2022-10-25 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D136660#3881647 , @mgorny wrote:

> In D136660#3881617 , @MaskRay wrote:
>
>> In D136660#3881602 , @mgorny wrote:
>>
>>> I suppose you want to remove it from `clang/CMakeLists.txt` as well. I see 
>>> Flang has copied the same logic too, so might be worthwhile to remove it 
>>> there as well.
>>
>> `set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")` and another set 
>> in `clang/CMakeLists.txt` is used by `clang/cmake/modules/AddClang.cmake`. 
>> Perhaps just simplify `VERSION_STRING "${CLANG_VERSION} 
>> (${BACKEND_PACKAGE_STRING})"` to `VERSION_STRING "${CLANG_VERSION}"` ? The 
>> backend package string is probably not useful.
>
> Perhaps it was used to account for LLVM and Clang minor version mismatch — 
> though I don't know if anyone is actually building a configuration like that.

Yes, and that's used in a minor place for a Windows build... The LLVM version 
should really not matter.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136660

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


[PATCH] D136660: [clang] Replace BACKEND_PACKAGE_STRING with LLVM_VERSION_STRING

2022-10-25 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3a3603ff99ff: [clang] Replace BACKEND_PACKAGE_STRING with 
LLVM_VERSION_STRING (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136660

Files:
  clang/CMakeLists.txt
  clang/cmake/modules/AddClang.cmake
  clang/include/clang/Config/config.h.cmake
  clang/lib/Frontend/CompilerInstance.cpp
  llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
  llvm/utils/release/bump-version.py
  utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h

Index: utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
===
--- utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
+++ utils/bazel/llvm-project-overlay/clang/include/clang/Config/config.h
@@ -74,9 +74,6 @@
 /* Define if we have sys/resource.h (rlimits) */
 /* CLANG_HAVE_RLIMITS defined conditionally below */
 
-/* The LLVM product name and version */
-#define BACKEND_PACKAGE_STRING "LLVM 16.0.0git"
-
 /* Linker version detected at compile time. */
 /* #undef HOST_LINK_VERSION */
 
Index: llvm/utils/release/bump-version.py
===
--- llvm/utils/release/bump-version.py
+++ llvm/utils/release/bump-version.py
@@ -121,13 +121,6 @@
 )
 if nline != line:
 break
-# Match the BACKEND_PACKAGE_STRING in clang/config.h
-elif "BACKEND_PACKAGE_STRING" in line:
-nline = re.sub(
-r'#define BACKEND_PACKAGE_STRING "LLVM ([0-9\.rcgit-]+)"',
-f'#define BACKEND_PACKAGE_STRING "LLVM {self.version_str()}"',
-line,
-)
 
 return nline
 
Index: llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
===
--- llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
+++ llvm/utils/gn/secondary/clang/include/clang/Config/BUILD.gn
@@ -25,7 +25,6 @@
 "CLANG_SPAWN_CC1=",
 "DEFAULT_SYSROOT=",
 "GCC_INSTALL_PREFIX=",
-"BACKEND_PACKAGE_STRING=LLVM ${llvm_version}git",
 "ENABLE_LINKER_BUILD_ID=",
 "ENABLE_X86_RELAX_RELOCATIONS=1",
 "CLANG_ENABLE_OBJC_REWRITER=1",  # FIXME: flag?
Index: clang/lib/Frontend/CompilerInstance.cpp
===
--- clang/lib/Frontend/CompilerInstance.cpp
+++ clang/lib/Frontend/CompilerInstance.cpp
@@ -41,6 +41,7 @@
 #include "clang/Serialization/InMemoryModuleCache.h"
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/Config/llvm-config.h"
 #include "llvm/Support/BuryPointer.h"
 #include "llvm/Support/CrashRecoveryContext.h"
 #include "llvm/Support/Errc.h"
@@ -1023,9 +1024,9 @@
 
   // Validate/process some options.
   if (getHeaderSearchOpts().Verbose)
-OS << "clang -cc1 version " CLANG_VERSION_STRING
-   << " based upon " << BACKEND_PACKAGE_STRING
-   << " default target " << llvm::sys::getDefaultTargetTriple() << "\n";
+OS << "clang -cc1 version " CLANG_VERSION_STRING << " based upon LLVM "
+   << LLVM_VERSION_STRING << " default target "
+   << llvm::sys::getDefaultTargetTriple() << "\n";
 
   if (getCodeGenOpts().TimePasses)
 createFrontendTimer();
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -60,9 +60,6 @@
 /* Define if we have sys/resource.h (rlimits) */
 #cmakedefine CLANG_HAVE_RLIMITS ${CLANG_HAVE_RLIMITS}
 
-/* The LLVM product name and version */
-#define BACKEND_PACKAGE_STRING "${BACKEND_PACKAGE_STRING}"
-
 /* Linker version detected at compile time. */
 #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}"
 
Index: clang/cmake/modules/AddClang.cmake
===
--- clang/cmake/modules/AddClang.cmake
+++ clang/cmake/modules/AddClang.cmake
@@ -37,7 +37,7 @@
   VERSION_MAJOR ${CLANG_VERSION_MAJOR}
   VERSION_MINOR ${CLANG_VERSION_MINOR}
   VERSION_PATCHLEVEL ${CLANG_VERSION_PATCHLEVEL}
-  VERSION_STRING "${CLANG_VERSION} (${BACKEND_PACKAGE_STRING})"
+  VERSION_STRING "${CLANG_VERSION}"
   PRODUCT_NAME "clang")
   endif()
 endmacro()
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -134,10 +134,6 @@
 
 umbrella_lit_testsuite_begin(check-all)
   endif() # LLVM_INCLUDE_TESTS
-
-  set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
-else()
-  set(BACKEND_PACKAGE_STRING "${PACKAGE_STRING}")
 endif() # standalone
 
 if(NOT DEFINED LLVM_COMMON_CMAKE_UTILS)
_

[PATCH] D136154: [clang-format] Fix the continuation indenter

2022-10-25 Thread Henrik Lafrenz via Phabricator via cfe-commits
hel-ableton marked an inline comment as done.
hel-ableton added a comment.

> After you write a New Inline Comment, click the Save Draft button. Then click 
> the Submit button near the bottom of the screen.

Makes sense, only I see no "Save Draft" button...




Comment at: clang/lib/Format/ContinuationIndenter.cpp:814
+if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None ||
+Style.BreakBeforeBinaryOperators == FormatStyle::BOS_NonAssignment) {
   CurrentState.LastSpace = State.Column;

MyDeveloperDay wrote:
> ok so now you don't actually have a test for this, so I don't know if this is 
> needed any more.
Yes, this test can probably be ditched once we find a more fitting one. 
Assuming that there is agreement on your side about the proposed other fix with 
the `TT_...` tokens.


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

https://reviews.llvm.org/D136154

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


[PATCH] D136435: [clang][Driver] Add gcc-toolset-12 and devtoolset-12 prefixes

2022-10-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 470390.

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

https://reviews.llvm.org/D136435

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

Index: clang/unittests/Driver/ToolChainTest.cpp
===
--- clang/unittests/Driver/ToolChainTest.cpp
+++ clang/unittests/Driver/ToolChainTest.cpp
@@ -20,7 +20,6 @@
 #include "clang/Frontend/CompilerInstance.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/MC/TargetRegistry.h"
-#include "llvm/Support/Host.h"
 #include "llvm/Support/TargetSelect.h"
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/raw_ostream.h"
@@ -394,96 +393,6 @@
   std::vector> Errors;
 };
 
-TEST(ToolChainTest, Toolsets) {
-  // Ignore this test on Windows hosts.
-  llvm::Triple Host(llvm::sys::getProcessTriple());
-  if (Host.isOSWindows())
-GTEST_SKIP();
-
-  IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
-  IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
-
-  // Check (newer) GCC toolset installation.
-  {
-IntrusiveRefCntPtr InMemoryFileSystem(
-new llvm::vfs::InMemoryFileSystem);
-
-// These should be ignored.
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-2", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset--1", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-
-// File needed for GCC installation detection.
-InMemoryFileSystem->addFile("/opt/rh/gcc-toolset-12/root/usr/lib/gcc/"
-"x86_64-redhat-linux/11/crtbegin.o",
-0, llvm::MemoryBuffer::getMemBuffer("\n"));
-
-DiagnosticsEngine Diags(DiagID, &*DiagOpts, new SimpleDiagnosticConsumer);
-Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
- "clang LLVM compiler", InMemoryFileSystem);
-std::unique_ptr C(
-TheDriver.BuildCompilation({"clang", "--gcc-toolchain="}));
-ASSERT_TRUE(C);
-std::string S;
-{
-  llvm::raw_string_ostream OS(S);
-  C->getDefaultToolChain().printVerboseInfo(OS);
-}
-EXPECT_EQ("Found candidate GCC installation: "
-  "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
-  "Selected GCC installation: "
-  "/opt/rh/gcc-toolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
-  "Candidate multilib: .;@m64\n"
-  "Selected multilib: .;@m64\n",
-  S);
-  }
-
-  // And older devtoolset.
-  {
-IntrusiveRefCntPtr InMemoryFileSystem(
-new llvm::vfs::InMemoryFileSystem);
-
-// These should be ignored.
-InMemoryFileSystem->addFile("/opt/rh/devtoolset-2", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/devtoolset-", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/devtoolset--", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-InMemoryFileSystem->addFile("/opt/rh/devtoolset--1", 0,
-llvm::MemoryBuffer::getMemBuffer("\n"));
-
-// File needed for GCC installation detection.
-InMemoryFileSystem->addFile("/opt/rh/devtoolset-12/root/usr/lib/gcc/"
-"x86_64-redhat-linux/11/crtbegin.o",
-0, llvm::MemoryBuffer::getMemBuffer("\n"));
-
-DiagnosticsEngine Diags(DiagID, &*DiagOpts, new SimpleDiagnosticConsumer);
-Driver TheDriver("/bin/clang", "x86_64-redhat-linux", Diags,
- "clang LLVM compiler", InMemoryFileSystem);
-std::unique_ptr C(
-TheDriver.BuildCompilation({"clang", "--gcc-toolchain="}));
-ASSERT_TRUE(C);
-std::string S;
-{
-  llvm::raw_string_ostream OS(S);
-  C->getDefaultToolChain().printVerboseInfo(OS);
-}
-EXPECT_EQ("Found candidate GCC installation: "
-  "/opt/rh/devtoolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
-  "Selected GCC installation: "
-  "/opt/rh/devtoolset-12/root/usr/lib/gcc/x86_64-redhat-linux/11\n"
-  "Candidate multilib: .;@m64\n"
-  "Selected multilib: .;@m64\n",
-  S);
-  }
-}
-
 TEST(ToolChainTest, ConfigFileSearch) {
   IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions();
   IntrusiveRefCntPtr DiagID(new DiagnosticIDs());
Index: clang/lib/Driver/ToolChains/Gnu.cpp
===
--- clang/lib/Driver/ToolChains/Gnu.cpp

[PATCH] D136532: [clang][Interp] Implement left and right shifts

2022-10-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 470391.
tbaeder added a comment.

Excuse the code duplication here, I'll get rid of it as soon as we all agree 
that the functionality is correct.


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

https://reviews.llvm.org/D136532

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/test/AST/Interp/shifts.cpp

Index: clang/test/AST/Interp/shifts.cpp
===
--- /dev/null
+++ clang/test/AST/Interp/shifts.cpp
@@ -0,0 +1,103 @@
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++20 -verify %s
+// RUN: %clang_cc1 -fexperimental-new-constant-interpreter -std=c++17 -verify=cxx17 %s
+// RUN: %clang_cc1 -std=c++20 -verify=ref %s
+// RUN: %clang_cc1 -std=c++17 -verify=ref-cxx17 %s
+
+#define CHAR_BIT (sizeof(char) * 8)
+#define WORD_BIT (sizeof(int) * 8)
+#define INT_MAX (__INT_MAX__)
+#define INT_MIN (~__INT_MAX__)
+
+
+namespace shifts {
+  constexpr void test() { // ref-error {{constexpr function never produces a constant expression}} \
+  // ref-cxx17-error {{constexpr function never produces a constant expression}}
+
+char c; // cxx17-warning {{uninitialized variable}} \
+// ref-cxx17-warning {{uninitialized variable}}
+
+c = 0 << 0;
+c = 0 << 1;
+c = 1 << 0;
+c = 1 << -0;
+c = 1 >> -0;
+c = 1 << -1; // expected-warning {{shift count is negative}} \
+ // cxx17-warning {{shift count is negative}} \
+ // ref-warning {{shift count is negative}} \
+ // ref-note {{negative shift count -1}} \
+ // ref-cxx17-warning {{shift count is negative}} \
+ // ref-cxx17-note {{negative shift count -1}}
+
+c = 1 >> -1; // expected-warning {{shift count is negative}} \
+ // cxx17-warning {{shift count is negative}} \
+ // ref-warning {{shift count is negative}} \
+ // ref-cxx17-warning {{shift count is negative}}
+c = 1 << (unsigned)-1; // expected-warning {{shift count >= width of type}} \
+   // FIXME: 'implicit conversion' warning missing in the new interpreter. \
+   // cxx17-warning {{shift count >= width of type}} \
+   // ref-warning {{shift count >= width of type}} \
+   // ref-warning {{implicit conversion}} \
+   // ref-cxx17-warning {{shift count >= width of type}} \
+   // ref-cxx17-warning {{implicit conversion}}
+c = 1 >> (unsigned)-1; // expected-warning {{shift count >= width of type}} \
+   // cxx17-warning {{shift count >= width of type}} \
+   // ref-warning {{shift count >= width of type}} \
+   // ref-cxx17-warning {{shift count >= width of type}}
+c = 1 << c;
+// FIXME: Enable this.
+#if 0
+//c <<= 0;
+//c >>= 0;
+//c <<= 1;
+//c >>= 1;
+//c <<= -1; // expected-warning {{shift count is negative}}
+//c >>= -1; // expected-warning {{shift count is negative}}
+//c <<= 99; // expected-warning {{shift count >= width of type}}
+//c >>= 99; // expected-warning {{shift count >= width of type}}
+//c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+//c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+//c <<= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
+//c >>= CHAR_BIT+1; // expected-warning {{shift count >= width of type}}
+#endif
+(void)((long)c << CHAR_BIT);
+
+int i; // cxx17-warning {{uninitialized variable}} \
+   // ref-cxx17-warning {{uninitialized variable}}
+i = 1 << (WORD_BIT - 2);
+i = 2 << (WORD_BIT - 1); // cxx17-warning {{bits to represent, but 'int' only has}} \
+ // ref-cxx17-warning {{bits to represent, but 'int' only has}}
+i = 1 << (WORD_BIT - 1); // cxx17-warning-not {{sets the sign bit of the shift expression}}
+i = -1 << (WORD_BIT - 1); // cxx17-warning {{shifting a negative signed value is undefined}} \
+  // ref-cxx17-warning {{shifting a negative signed value is undefined}}
+i = -1 << 0; // cxx17-warning {{shifting a negative signed value is undefined}} \
+ // ref-cxx17-warning {{shifting a negative signed value is undefined}}
+i = 0 << (WORD_BIT - 1);
+i = (char)1 << (WORD_BIT - 2);
+
+unsigned u; // cxx17-warning {{uninitialized variable}} \
+// ref-cxx17-warning {{uninitialized variable}}
+u = 1U << (WORD_BIT - 1);
+u = 5U << (WORD_BIT - 1);
+
+long long int lli; // cxx17-warning {{uninitialized variable}} \
+   // ref-cxx17-warning {{uninitialized variable}}
+lli = INT_MIN << 2; // cxx1

[PATCH] D136457: [clang][Interp] Fix discarding non-primitive function call return values

2022-10-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder marked an inline comment as done.
tbaeder added inline comments.



Comment at: clang/lib/AST/Interp/ByteCodeExprGen.cpp:1158
+
+if (DiscardResult && !T) {
+  // If we need to discard the return value but the function returns its

shafik wrote:
> Could you alternatively use `Func->hasRVO()`? 
I don't have to, but now that you mentioned it, that's much better since we 
won' t allocate the local for void return types... thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136457

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


[PATCH] D136457: [clang][Interp] Fix discarding non-primitive function call return values

2022-10-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 470392.
tbaeder marked an inline comment as done.

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

https://reviews.llvm.org/D136457

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  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
@@ -214,6 +214,10 @@
 this->a; // expected-warning {{expression result unused}} \
  // ref-warning {{expression result unused}}
 get5();
+#if __cplusplus >= 201703L
+// FIXME: Enable once we support MaterializeConstantExpr properly.
+getInts();
+#endif
   }
 
   constexpr int m() const {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1151,6 +1151,19 @@
 if (Func->isFullyCompiled() && !Func->isConstexpr())
   return false;
 
+QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
+Optional T = classify(ReturnType);
+
+if (Func->hasRVO() && DiscardResult) {
+  // If we need to discard the return value but the function returns its
+  // value via an RVO pointer, we need to create one such pointer just
+  // for this call.
+  if (Optional LocalIndex = allocateLocal(E)) {
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+  }
+}
+
 // Put arguments on the stack.
 for (const auto *Arg : E->arguments()) {
   if (!this->visit(Arg))
@@ -1163,13 +1176,8 @@
 if (!this->emitCall(Func, E))
   return false;
 
-QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
-if (DiscardResult && !ReturnType->isVoidType()) {
-  Optional T = classify(ReturnType);
-  if (T)
-return this->emitPop(*T, E);
-  // TODO: This is a RVO function and we need to ignore the return value.
-}
+if (DiscardResult && !ReturnType->isVoidType() && T)
+  return this->emitPop(*T, E);
 
 return true;
   } else {


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -214,6 +214,10 @@
 this->a; // expected-warning {{expression result unused}} \
  // ref-warning {{expression result unused}}
 get5();
+#if __cplusplus >= 201703L
+// FIXME: Enable once we support MaterializeConstantExpr properly.
+getInts();
+#endif
   }
 
   constexpr int m() const {
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1151,6 +1151,19 @@
 if (Func->isFullyCompiled() && !Func->isConstexpr())
   return false;
 
+QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
+Optional T = classify(ReturnType);
+
+if (Func->hasRVO() && DiscardResult) {
+  // If we need to discard the return value but the function returns its
+  // value via an RVO pointer, we need to create one such pointer just
+  // for this call.
+  if (Optional LocalIndex = allocateLocal(E)) {
+if (!this->emitGetPtrLocal(*LocalIndex, E))
+  return false;
+  }
+}
+
 // Put arguments on the stack.
 for (const auto *Arg : E->arguments()) {
   if (!this->visit(Arg))
@@ -1163,13 +1176,8 @@
 if (!this->emitCall(Func, E))
   return false;
 
-QualType ReturnType = E->getCallReturnType(Ctx.getASTContext());
-if (DiscardResult && !ReturnType->isVoidType()) {
-  Optional T = classify(ReturnType);
-  if (T)
-return this->emitPop(*T, E);
-  // TODO: This is a RVO function and we need to ignore the return value.
-}
+if (DiscardResult && !ReturnType->isVoidType() && T)
+  return this->emitPop(*T, E);
 
 return true;
   } else {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D132110: [IncludeCleaner] Handle more C++ constructs

2022-10-25 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet updated this revision to Diff 470393.
kadircet marked 4 inline comments as done.
kadircet added a comment.

- Rebase
- Add FIXMEs


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132110

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -38,6 +38,7 @@
   Inputs.ExtraFiles["target.h"] = Target.code().str();
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("target.h");
+  Inputs.ExtraArgs.push_back("-std=c++17");
   TestAST AST(Inputs);
   const auto &SM = AST.sourceManager();
 
@@ -97,6 +98,8 @@
   testWalk("struct S { static int ^x; };", "int y = S::^x;");
   // Canonical declaration only.
   testWalk("extern int ^x; int x;", "int y = ^x;");
+  // Return type of `foo` isn't used.
+  testWalk("struct S{}; S ^foo();", "auto bar() { return ^foo(); }");
 }
 
 TEST(WalkAST, TagType) {
@@ -111,11 +114,66 @@
 using ns::^x;
   )cpp",
"int y = ^x;");
+  testWalk("using ^foo = int;", "^foo x;");
+  testWalk("struct S {}; using ^foo = S;", "^foo x;");
+}
+
+TEST(WalkAST, Using) {
+  testWalk("namespace ns { void ^x(); void ^x(int); }", "using ns::^x;");
+  testWalk("namespace ns { struct S; } using ns::^S;", "^S *s;");
+}
+
+TEST(WalkAST, Namespaces) {
+  testWalk("namespace ns { void x(); }", "using namespace ^ns;");
+}
+
+TEST(WalkAST, TemplateNames) {
+  testWalk("template struct ^S {};", "^S s;");
+  // FIXME: Template decl has the wrong primary location for type-alias template
+  // decls.
   testWalk(R"cpp(
-namespace ns { struct S; } // Not used
-using ns::S; // FIXME: S should be used
-  )cpp",
-   "^S *x;");
+  template  struct S {};
+  template  ^using foo = S;)cpp",
+   "^foo x;");
+  testWalk(R"cpp(
+  namespace ns {template  struct S {}; }
+  using ns::^S;)cpp",
+   "^S x;");
+  testWalk("template struct ^S {};",
+   R"cpp(
+  template  typename> struct X {};
+  X<^S> x;)cpp");
+  testWalk("template struct ^S { S(T); };", "^S s(42);");
+  // Should we mark the specialization instead?
+  testWalk("template struct ^S {}; template <> struct S {};",
+   "^S s;");
+}
+
+TEST(WalkAST, MemberExprs) {
+  testWalk("struct S { void ^foo(); };", "void foo() { S{}.^foo(); }");
+  testWalk("struct S { void foo(); }; struct X : S { using S::^foo; };",
+   "void foo() { X{}.^foo(); }");
+}
+
+TEST(WalkAST, ConstructExprs) {
+  testWalk("struct ^S {};", "S ^t;");
+  testWalk("struct S { ^S(int); };", "S ^t(42);");
+}
+
+TEST(WalkAST, Functions) {
+  // Definition uses declaration, not the other way around.
+  testWalk("void ^foo();", "void ^foo() {}");
+  testWalk("void foo() {}", "void ^foo();");
+
+  // Unresolved calls marks all the overloads.
+  testWalk("void ^foo(int); void ^foo(char);",
+   "template  void bar() { ^foo(T{}); }");
+}
+
+TEST(WalkAST, Enums) {
+  testWalk("enum E { ^A = 42, B = 43 };", "int e = ^A;");
+  testWalk("enum class ^E : int;", "enum class ^E : int {};");
+  testWalk("enum class E : int {};", "enum class ^E : int ;");
 }
 
 } // namespace
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -31,9 +31,9 @@
   void foo();
   namespace std { class vector {}; })cpp");
   llvm::Annotations Code(R"cpp(
-  void bar() {
+  void $bar^bar() {
 $foo^foo();
-std::$vector^vector v;
+std::$vector^vector $vconstructor^v;
   }
   )cpp");
   TestInputs Inputs(Code.code());
@@ -55,14 +55,16 @@
 EXPECT_EQ(FID, SM.getMainFileID());
 OffsetToProviders.try_emplace(Offset, Providers.vec());
   });
-  auto HeaderFile = AST.fileManager().getFile("header.h").get();
+  auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
+  auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
+  auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
   OffsetToProviders,
   UnorderedElementsAre(
-  Pair(Code.point("foo"), UnorderedElementsAre(Header(HeaderFile))),
-  Pair(Code.point("vector"),
-   UnorderedElementsAre(Header(
-   tooling::stdlib::Header::named("").value());
+  Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
+  Pair(Code.point("foo"), UnorderedElementsAre(HeaderFile)),
+  Pair(Code.point("vector"), UnorderedElementsAre(VectorST

[clang-tools-extra] 772fc63 - [IncludeCleaner] Handle more C++ constructs

2022-10-25 Thread Kadir Cetinkaya via cfe-commits

Author: Kadir Cetinkaya
Date: 2022-10-25T09:58:49+02:00
New Revision: 772fc63f5bb50996370797e55682dd65960d921a

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

LOG: [IncludeCleaner] Handle more C++ constructs

Summary:
This brings IncludeCleaner's reference discovery from AST to the parity
with current implementation in clangd. Some highlights:
- Handling of MemberExprs, only the member declaration is marked as
  referenced and not the container, unlike clangd.
- Constructor calls, only the constructor and not the container, unlike
  clangd.
- All the possible candidates for unresolved overloads, same as clangd.
- All the shadow decls for using-decls, same as clangd.
- Declarations for definitions of enums with an underlying type and
  functions, same as clangd.
- Using typelocs, using templatenames and typedefs only reference the
  found decl, same as clangd.
- Template specializations only reference the primary template, not the
  explicit specializations, to be fixed.
- Expr types aren't marked as used, unlike clangd.

Going forward, we can consider having signals to indicate type of a
reference (e.g. `implicit` signal for type of an expr) so that the
applications can perform a filtering based on their needs.
At the moment the biggest discrepancy is around type of exprs, i.e. not
marking containers for member/constructor accesses. I believe this is
the right model since the declaration of the member and the container
should be available in a single file (modulo macros).

Reviewers: sammccall

Subscribers:

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

Added: 


Modified: 
clang-tools-extra/include-cleaner/lib/WalkAST.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Removed: 




diff  --git a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp 
b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
index a86534337c273..9d16751a9e83c 100644
--- a/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
+++ b/clang-tools-extra/include-cleaner/lib/WalkAST.cpp
@@ -7,7 +7,17 @@
 
//===--===//
 
 #include "AnalysisInternal.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/ExprCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TemplateName.h"
+#include "clang/AST/Type.h"
+#include "clang/AST/TypeLoc.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Support/Casting.h"
 
 namespace clang::include_cleaner {
 namespace {
@@ -16,6 +26,16 @@ using DeclCallback = llvm::function_ref;
 class ASTWalker : public RecursiveASTVisitor {
   DeclCallback Callback;
 
+  bool handleTemplateName(SourceLocation Loc, TemplateName TN) {
+// For using-templates, only mark the alias.
+if (auto *USD = TN.getAsUsingShadowDecl()) {
+  report(Loc, USD);
+  return true;
+}
+report(Loc, TN.getAsTemplateDecl());
+return true;
+  }
+
   void report(SourceLocation Loc, NamedDecl *ND) {
 if (!ND || Loc.isInvalid())
   return;
@@ -25,15 +45,91 @@ class ASTWalker : public RecursiveASTVisitor {
 public:
   ASTWalker(DeclCallback Callback) : Callback(Callback) {}
 
+  bool VisitDeclRefExpr(DeclRefExpr *DRE) {
+report(DRE->getLocation(), DRE->getFoundDecl());
+return true;
+  }
+
+  bool VisitMemberExpr(MemberExpr *E) {
+report(E->getMemberLoc(), E->getFoundDecl().getDecl());
+return true;
+  }
+
+  bool VisitCXXConstructExpr(CXXConstructExpr *E) {
+report(E->getLocation(), E->getConstructor());
+return true;
+  }
+
+  bool VisitOverloadExpr(OverloadExpr *E) {
+// Since we can't prove which overloads are used, report all of them.
+// FIXME: Provide caller with the ability to make a decision for such uses.
+llvm::for_each(E->decls(),
+   [this, E](NamedDecl *D) { report(E->getNameLoc(), D); });
+return true;
+  }
+
+  bool VisitUsingDecl(UsingDecl *UD) {
+// FIXME: Provide caller with the ability to tell apart used/non-used
+// targets.
+for (const auto *Shadow : UD->shadows())
+  report(UD->getLocation(), Shadow->getTargetDecl());
+return true;
+  }
+
+  bool VisitFunctionDecl(FunctionDecl *FD) {
+// Mark declaration from definition as it needs type-checking.
+if (FD->isThisDeclarationADefinition())
+  report(FD->getLocation(), FD);
+return true;
+  }
+
+  bool VisitEnumDecl(EnumDecl *D) {
+// Definition of an enum with an underlying type references declaration for
+// type-checking purposes.
+if (D->isThisDeclarationADefinition() && D->getIntegerTypeSourceInfo())
+  report(D->getLocation(), D);
+re

[PATCH] D132110: [IncludeCleaner] Handle more C++ constructs

2022-10-25 Thread Kadir Cetinkaya 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 rG772fc63f5bb5: [IncludeCleaner] Handle more C++ constructs 
(authored by kadircet).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132110

Files:
  clang-tools-extra/include-cleaner/lib/WalkAST.cpp
  clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
  clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/WalkASTTest.cpp
@@ -38,6 +38,7 @@
   Inputs.ExtraFiles["target.h"] = Target.code().str();
   Inputs.ExtraArgs.push_back("-include");
   Inputs.ExtraArgs.push_back("target.h");
+  Inputs.ExtraArgs.push_back("-std=c++17");
   TestAST AST(Inputs);
   const auto &SM = AST.sourceManager();
 
@@ -97,6 +98,8 @@
   testWalk("struct S { static int ^x; };", "int y = S::^x;");
   // Canonical declaration only.
   testWalk("extern int ^x; int x;", "int y = ^x;");
+  // Return type of `foo` isn't used.
+  testWalk("struct S{}; S ^foo();", "auto bar() { return ^foo(); }");
 }
 
 TEST(WalkAST, TagType) {
@@ -111,11 +114,66 @@
 using ns::^x;
   )cpp",
"int y = ^x;");
+  testWalk("using ^foo = int;", "^foo x;");
+  testWalk("struct S {}; using ^foo = S;", "^foo x;");
+}
+
+TEST(WalkAST, Using) {
+  testWalk("namespace ns { void ^x(); void ^x(int); }", "using ns::^x;");
+  testWalk("namespace ns { struct S; } using ns::^S;", "^S *s;");
+}
+
+TEST(WalkAST, Namespaces) {
+  testWalk("namespace ns { void x(); }", "using namespace ^ns;");
+}
+
+TEST(WalkAST, TemplateNames) {
+  testWalk("template struct ^S {};", "^S s;");
+  // FIXME: Template decl has the wrong primary location for type-alias template
+  // decls.
   testWalk(R"cpp(
-namespace ns { struct S; } // Not used
-using ns::S; // FIXME: S should be used
-  )cpp",
-   "^S *x;");
+  template  struct S {};
+  template  ^using foo = S;)cpp",
+   "^foo x;");
+  testWalk(R"cpp(
+  namespace ns {template  struct S {}; }
+  using ns::^S;)cpp",
+   "^S x;");
+  testWalk("template struct ^S {};",
+   R"cpp(
+  template  typename> struct X {};
+  X<^S> x;)cpp");
+  testWalk("template struct ^S { S(T); };", "^S s(42);");
+  // Should we mark the specialization instead?
+  testWalk("template struct ^S {}; template <> struct S {};",
+   "^S s;");
+}
+
+TEST(WalkAST, MemberExprs) {
+  testWalk("struct S { void ^foo(); };", "void foo() { S{}.^foo(); }");
+  testWalk("struct S { void foo(); }; struct X : S { using S::^foo; };",
+   "void foo() { X{}.^foo(); }");
+}
+
+TEST(WalkAST, ConstructExprs) {
+  testWalk("struct ^S {};", "S ^t;");
+  testWalk("struct S { ^S(int); };", "S ^t(42);");
+}
+
+TEST(WalkAST, Functions) {
+  // Definition uses declaration, not the other way around.
+  testWalk("void ^foo();", "void ^foo() {}");
+  testWalk("void foo() {}", "void ^foo();");
+
+  // Unresolved calls marks all the overloads.
+  testWalk("void ^foo(int); void ^foo(char);",
+   "template  void bar() { ^foo(T{}); }");
+}
+
+TEST(WalkAST, Enums) {
+  testWalk("enum E { ^A = 42, B = 43 };", "int e = ^A;");
+  testWalk("enum class ^E : int;", "enum class ^E : int {};");
+  testWalk("enum class E : int {};", "enum class ^E : int ;");
 }
 
 } // namespace
Index: clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
===
--- clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
+++ clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp
@@ -31,9 +31,9 @@
   void foo();
   namespace std { class vector {}; })cpp");
   llvm::Annotations Code(R"cpp(
-  void bar() {
+  void $bar^bar() {
 $foo^foo();
-std::$vector^vector v;
+std::$vector^vector $vconstructor^v;
   }
   )cpp");
   TestInputs Inputs(Code.code());
@@ -55,14 +55,16 @@
 EXPECT_EQ(FID, SM.getMainFileID());
 OffsetToProviders.try_emplace(Offset, Providers.vec());
   });
-  auto HeaderFile = AST.fileManager().getFile("header.h").get();
+  auto HeaderFile = Header(AST.fileManager().getFile("header.h").get());
+  auto MainFile = Header(SM.getFileEntryForID(SM.getMainFileID()));
+  auto VectorSTL = Header(tooling::stdlib::Header::named("").value());
   EXPECT_THAT(
   OffsetToProviders,
   UnorderedElementsAre(
-  Pair(Code.point("foo"), UnorderedElementsAre(Header(HeaderFile))),
-  Pair(Code.point("vector"),
-   UnorderedElementsAre(Header(
-   tooling::stdlib::Header::named("").value());
+  Pair(Code.point("bar"), UnorderedElementsAre(MainFile)),
+  Pair(Code.point("foo"), UnorderedE

[clang] fd1d93d - [clang-format] Mark pragma region lines as StringLiterals

2022-10-25 Thread Tobias Hieta via cfe-commits

Author: Tobias Hieta
Date: 2022-10-25T09:59:39+02:00
New Revision: fd1d93db71066bedc11944bd32f3540b8084b060

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

LOG: [clang-format] Mark pragma region lines as StringLiterals

In our code-base we auto-generate pragma regions the regions
look like method signatures like:

`#pragma region MYREGION(Foo: bar)`

The problem here was that the rest of the line after region
was not marked as stringliteral as in the case of pragma mark
so clang-format tried to change the formatting based on the
method signature.

Added test and mark it similar as pragma mark.

Reviewed By: owenpan

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index f226e8ffa61c1..fba1a125dc57e 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1337,14 +1337,15 @@ class AnnotatingParser {
 if (CurrentToken &&
 CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option,
   Keywords.kw_region)) {
-  bool IsMark = CurrentToken->is(Keywords.kw_mark);
+  bool IsMarkOrRegion =
+  CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_region);
   next();
   next(); // Consume first token (so we fix leading whitespace).
   while (CurrentToken) {
-if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator))
+if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator)) {
   CurrentToken->setType(TT_ImplicitStringLiteral);
 next();
-  }
+}
 }
   }
 

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index d7aca687ab40d..00803cd3a230f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -19965,9 +19965,7 @@ TEST_F(FormatTest, UnderstandPragmaOption) {
 TEST_F(FormatTest, UnderstandPragmaRegion) {
   auto Style = getLLVMStyleWithColumns(0);
   verifyFormat("#pragma region TEST(FOO : BAR)", Style);
-
-  EXPECT_EQ("#pragma region TEST(FOO : BAR)",
-format("#pragma region TEST(FOO : BAR)", Style));
+  verifyFormat("#pragma region TEST(FOO: NOSPACE)", Style);
 }
 
 TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) {

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 14918c7e6ff96..999feca0913d6 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -649,6 +649,22 @@ TEST_F(TokenAnnotatorTest, UnderstandsRequiresExpressions) 
{
   EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_RequiresExpressionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsPragmaRegion) {
+  // Everything after #pragma region should be ImplicitStringLiteral
+  auto Tokens = annotate("#pragma region Foo(Bar: Hello)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[7], tok::identifier, TT_ImplicitStringLiteral);
+
+  // Make sure it's annotated correctly inside a function as well
+  Tokens = annotate("void test(){\n#pragma region Foo(Bar: Hello)\n}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[11], tok::colon, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[12], tok::identifier, TT_ImplicitStringLiteral);
+}
+
 TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) {
   const char *BaseCode = nullptr;
   const char *ConstrainedCode = nullptr;



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


[PATCH] D136336: [clang-format] Mark pragma region lines as StringLiterals

2022-10-25 Thread Tobias Hieta 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 rGfd1d93db7106: [clang-format] Mark pragma region lines as 
StringLiterals (authored by thieta).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136336

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


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -649,6 +649,22 @@
   EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_RequiresExpressionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsPragmaRegion) {
+  // Everything after #pragma region should be ImplicitStringLiteral
+  auto Tokens = annotate("#pragma region Foo(Bar: Hello)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[7], tok::identifier, TT_ImplicitStringLiteral);
+
+  // Make sure it's annotated correctly inside a function as well
+  Tokens = annotate("void test(){\n#pragma region Foo(Bar: Hello)\n}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[11], tok::colon, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[12], tok::identifier, TT_ImplicitStringLiteral);
+}
+
 TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) {
   const char *BaseCode = nullptr;
   const char *ConstrainedCode = nullptr;
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19965,9 +19965,7 @@
 TEST_F(FormatTest, UnderstandPragmaRegion) {
   auto Style = getLLVMStyleWithColumns(0);
   verifyFormat("#pragma region TEST(FOO : BAR)", Style);
-
-  EXPECT_EQ("#pragma region TEST(FOO : BAR)",
-format("#pragma region TEST(FOO : BAR)", Style));
+  verifyFormat("#pragma region TEST(FOO: NOSPACE)", Style);
 }
 
 TEST_F(FormatTest, OptimizeBreakPenaltyVsExcess) {
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1337,14 +1337,15 @@
 if (CurrentToken &&
 CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_option,
   Keywords.kw_region)) {
-  bool IsMark = CurrentToken->is(Keywords.kw_mark);
+  bool IsMarkOrRegion =
+  CurrentToken->isOneOf(Keywords.kw_mark, Keywords.kw_region);
   next();
   next(); // Consume first token (so we fix leading whitespace).
   while (CurrentToken) {
-if (IsMark || CurrentToken->Previous->is(TT_BinaryOperator))
+if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator)) {
   CurrentToken->setType(TT_ImplicitStringLiteral);
 next();
-  }
+}
 }
   }
 


Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -649,6 +649,22 @@
   EXPECT_TOKEN(Tokens[14], tok::l_brace, TT_RequiresExpressionLBrace);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsPragmaRegion) {
+  // Everything after #pragma region should be ImplicitStringLiteral
+  auto Tokens = annotate("#pragma region Foo(Bar: Hello)");
+  ASSERT_EQ(Tokens.size(), 10u) << Tokens;
+  EXPECT_TOKEN(Tokens[5], tok::identifier, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[6], tok::colon, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[7], tok::identifier, TT_ImplicitStringLiteral);
+
+  // Make sure it's annotated correctly inside a function as well
+  Tokens = annotate("void test(){\n#pragma region Foo(Bar: Hello)\n}");
+  ASSERT_EQ(Tokens.size(), 16u) << Tokens;
+  EXPECT_TOKEN(Tokens[10], tok::identifier, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[11], tok::colon, TT_ImplicitStringLiteral);
+  EXPECT_TOKEN(Tokens[12], tok::identifier, TT_ImplicitStringLiteral);
+}
+
 TEST_F(TokenAnnotatorTest, RequiresDoesNotChangeParsingOfTheRest) {
   const char *BaseCode = nullptr;
   const char *ConstrainedCode = nullptr;
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19965,9 +19965,7 @@
 TEST_F(FormatTest, UnderstandPragmaRegion) {
   auto Style = getLLVMStyleWithColumns(0);
   verifyFormat("#pragma region TEST(FOO : BAR)", Style);
-

[clang] 9c48b7f - [AArch64][ARM] Alter v8.1a neon intrinsics to be target-based, not preprocessor based

2022-10-25 Thread David Green via cfe-commits

Author: David Green
Date: 2022-10-25T09:02:52+01:00
New Revision: 9c48b7f0e7a96e126a369d6036eff1bb259116c8

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

LOG: [AArch64][ARM] Alter v8.1a neon intrinsics to be target-based, not 
preprocessor based

As a continuation of D132034, this switches the QRDMX v8.1a neon
intrinsics over from preprocessor defines to be target-gated. As there
is no "rdma" or "qrdmx" target feature, they use the "v8.1a"
architecture feature directly.

This works well for AArch64, but something needs to be done for Arm at
the same time, as they both use the same header and tablegen emitter.
This patch opts for adding "v8.1a" and all dependant target features to
the Arm TargetParser, similar to what was recently done for AArch64 but
through initFeatureMap when the Architecture is parsed. I attempted to
make the code similar to the AArch64 backend.

Otherwise this is similar to the changes made in D132034.

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

Added: 


Modified: 
clang/include/clang/Basic/arm_neon.td
clang/lib/Basic/Targets/ARM.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/arm-target-features.c
clang/test/Sema/aarch64-neon-target.c
clang/test/Sema/arm-neon-target.c
llvm/include/llvm/Support/ARMTargetParser.h
llvm/lib/Support/ARMTargetParser.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index a7737a5f81e06..d6b6c429a21b2 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -323,7 +323,7 @@ def VMLSL: SOpInst<"vmlsl", "(>Q)(>Q)..", "csiUcUsUi", 
OP_MLSL>;
 def VQDMULH  : SInst<"vqdmulh", "...", "siQsQi">;
 def VQRDMULH : SInst<"vqrdmulh", "...", "siQsQi">;
 
-let ArchGuard = "defined(__ARM_FEATURE_QRDMX)" in {
+let TargetGuard = "v8.1a" in {
 def VQRDMLAH : SInst<"vqrdmlah", "", "siQsQi">;
 def VQRDMLSH : SInst<"vqrdmlsh", "", "siQsQi">;
 }
@@ -614,7 +614,7 @@ def A64_VQDMULH_LANE  : SInst<"vqdmulh_lane", "..(!q)I", 
"siQsQi">;
 def A64_VQRDMULH_LANE : SInst<"vqrdmulh_lane", "..(!q)I", "siQsQi">;
 }
 
-let ArchGuard = "defined(__ARM_FEATURE_QRDMX)" in {
+let TargetGuard = "v8.1a" in {
 def VQRDMLAH_LANE : SOpInst<"vqrdmlah_lane", "...qI", "siQsQi", OP_QRDMLAH_LN>;
 def VQRDMLSH_LANE : SOpInst<"vqrdmlsh_lane", "...qI", "siQsQi", OP_QRDMLSH_LN>;
 }
@@ -1089,14 +1089,14 @@ let isLaneQ = 1 in {
 def VQDMULH_LANEQ  : SInst<"vqdmulh_laneq", "..QI", "siQsQi">;
 def VQRDMULH_LANEQ : SInst<"vqrdmulh_laneq", "..QI", "siQsQi">;
 }
-let ArchGuard = "defined(__ARM_FEATURE_QRDMX) && defined(__aarch64__)" in {
+let ArchGuard = "defined(__aarch64__)", TargetGuard = "v8.1a" in {
 def VQRDMLAH_LANEQ : SOpInst<"vqrdmlah_laneq", "...QI", "siQsQi", 
OP_QRDMLAH_LN> {
   let isLaneQ = 1;
 }
 def VQRDMLSH_LANEQ : SOpInst<"vqrdmlsh_laneq", "...QI", "siQsQi", 
OP_QRDMLSH_LN> {
   let isLaneQ = 1;
 }
-}
+} // ArchGuard = "defined(__aarch64__)", TargetGuard = "v8.1a"
 
 // Note: d type implemented by SCALAR_VMULX_LANE
 def VMULX_LANE : IOpInst<"vmulx_lane", "..qI", "fQfQd", OP_MULX_LN>;
@@ -1394,7 +1394,7 @@ def SCALAR_SQDMULH : SInst<"vqdmulh", "111", "SsSi">;
 // Scalar Integer Saturating Rounding Doubling Multiply Half High
 def SCALAR_SQRDMULH : SInst<"vqrdmulh", "111", "SsSi">;
 
-let ArchGuard = "defined(__ARM_FEATURE_QRDMX) && defined(__aarch64__)" in {
+let ArchGuard = "defined(__aarch64__)", TargetGuard = "v8.1a" in {
 

 // Signed Saturating Rounding Doubling Multiply Accumulate Returning High Half
 def SCALAR_SQRDMLAH : SInst<"vqrdmlah", "", "SsSi">;
@@ -1402,7 +1402,7 @@ def SCALAR_SQRDMLAH : SInst<"vqrdmlah", "", "SsSi">;
 

 // Signed Saturating Rounding Doubling Multiply Subtract Returning High Half
 def SCALAR_SQRDMLSH : SInst<"vqrdmlsh", "", "SsSi">;
-}
+} // ArchGuard = "defined(__aarch64__)", TargetGuard = "v8.1a"
 
 

 // Scalar Floating-point Multiply Extended
@@ -1625,7 +1625,7 @@ def SCALAR_SQRDMULH_LANEQ : SOpInst<"vqrdmulh_laneq", 
"11QI", "SsSi", OP_SCALAR_
   let isLaneQ = 1;
 }
 
-let ArchGuard = "defined(__ARM_FEATURE_QRDMX) && defined(__aarch64__)" in {
+let TargetGuard = "v8.1a" in {
 // Signed Saturating Rounding Doubling Multiply Accumulate Returning High Half
 def SCALAR_SQRDMLAH_LANE : SOpInst<"vqrdmlah_lane", "111.I", "SsSi", 
OP_SCALAR_QRDMLAH_LN>;
 def SCALAR_SQRDMLAH_LANEQ : SOpInst<"vqrdmlah_laneq", "111QI", "SsSi", 
OP_SCALAR_QRDMLAH_LN> {
@@ -1637,7 +1637,7 @@ def SCALAR_SQRDMLSH_LANE : SOpInst<"vqrdmlsh_lane", 
"111.I", 

[PATCH] D135615: [AArch64][ARM] Alter v8.1a neon intrinsics to be target-based, not preprocessor based

2022-10-25 Thread Dave Green 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 rG9c48b7f0e7a9: [AArch64][ARM] Alter v8.1a neon intrinsics to 
be target-based, not preprocessor… (authored by dmgreen).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D135615?vs=466594&id=470396#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135615

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/Basic/Targets/ARM.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/arm-target-features.c
  clang/test/Sema/aarch64-neon-target.c
  clang/test/Sema/arm-neon-target.c
  llvm/include/llvm/Support/ARMTargetParser.h
  llvm/lib/Support/ARMTargetParser.cpp

Index: llvm/lib/Support/ARMTargetParser.cpp
===
--- llvm/lib/Support/ARMTargetParser.cpp
+++ llvm/lib/Support/ARMTargetParser.cpp
@@ -88,54 +88,58 @@
   llvm_unreachable("Unhandled architecture");
 }
 
+static ARM::ProfileKind getProfileKind(ARM::ArchKind AK) {
+  switch (AK) {
+  case ARM::ArchKind::ARMV6M:
+  case ARM::ArchKind::ARMV7M:
+  case ARM::ArchKind::ARMV7EM:
+  case ARM::ArchKind::ARMV8MMainline:
+  case ARM::ArchKind::ARMV8MBaseline:
+  case ARM::ArchKind::ARMV8_1MMainline:
+return ARM::ProfileKind::M;
+  case ARM::ArchKind::ARMV7R:
+  case ARM::ArchKind::ARMV8R:
+return ARM::ProfileKind::R;
+  case ARM::ArchKind::ARMV7A:
+  case ARM::ArchKind::ARMV7VE:
+  case ARM::ArchKind::ARMV7K:
+  case ARM::ArchKind::ARMV8A:
+  case ARM::ArchKind::ARMV8_1A:
+  case ARM::ArchKind::ARMV8_2A:
+  case ARM::ArchKind::ARMV8_3A:
+  case ARM::ArchKind::ARMV8_4A:
+  case ARM::ArchKind::ARMV8_5A:
+  case ARM::ArchKind::ARMV8_6A:
+  case ARM::ArchKind::ARMV8_7A:
+  case ARM::ArchKind::ARMV8_8A:
+  case ARM::ArchKind::ARMV9A:
+  case ARM::ArchKind::ARMV9_1A:
+  case ARM::ArchKind::ARMV9_2A:
+  case ARM::ArchKind::ARMV9_3A:
+return ARM::ProfileKind::A;
+  case ARM::ArchKind::ARMV4:
+  case ARM::ArchKind::ARMV4T:
+  case ARM::ArchKind::ARMV5T:
+  case ARM::ArchKind::ARMV5TE:
+  case ARM::ArchKind::ARMV5TEJ:
+  case ARM::ArchKind::ARMV6:
+  case ARM::ArchKind::ARMV6K:
+  case ARM::ArchKind::ARMV6T2:
+  case ARM::ArchKind::ARMV6KZ:
+  case ARM::ArchKind::ARMV7S:
+  case ARM::ArchKind::IWMMXT:
+  case ARM::ArchKind::IWMMXT2:
+  case ARM::ArchKind::XSCALE:
+  case ARM::ArchKind::INVALID:
+return ARM::ProfileKind::INVALID;
+  }
+  llvm_unreachable("Unhandled architecture");
+}
+
 // Profile A/R/M
 ARM::ProfileKind ARM::parseArchProfile(StringRef Arch) {
   Arch = getCanonicalArchName(Arch);
-  switch (parseArch(Arch)) {
-  case ArchKind::ARMV6M:
-  case ArchKind::ARMV7M:
-  case ArchKind::ARMV7EM:
-  case ArchKind::ARMV8MMainline:
-  case ArchKind::ARMV8MBaseline:
-  case ArchKind::ARMV8_1MMainline:
-return ProfileKind::M;
-  case ArchKind::ARMV7R:
-  case ArchKind::ARMV8R:
-return ProfileKind::R;
-  case ArchKind::ARMV7A:
-  case ArchKind::ARMV7VE:
-  case ArchKind::ARMV7K:
-  case ArchKind::ARMV8A:
-  case ArchKind::ARMV8_1A:
-  case ArchKind::ARMV8_2A:
-  case ArchKind::ARMV8_3A:
-  case ArchKind::ARMV8_4A:
-  case ArchKind::ARMV8_5A:
-  case ArchKind::ARMV8_6A:
-  case ArchKind::ARMV8_7A:
-  case ArchKind::ARMV8_8A:
-  case ArchKind::ARMV9A:
-  case ArchKind::ARMV9_1A:
-  case ArchKind::ARMV9_2A:
-  case ArchKind::ARMV9_3A:
-return ProfileKind::A;
-  case ArchKind::ARMV4:
-  case ArchKind::ARMV4T:
-  case ArchKind::ARMV5T:
-  case ArchKind::ARMV5TE:
-  case ArchKind::ARMV5TEJ:
-  case ArchKind::ARMV6:
-  case ArchKind::ARMV6K:
-  case ArchKind::ARMV6T2:
-  case ArchKind::ARMV6KZ:
-  case ArchKind::ARMV7S:
-  case ArchKind::IWMMXT:
-  case ArchKind::IWMMXT2:
-  case ArchKind::XSCALE:
-  case ArchKind::INVALID:
-return ProfileKind::INVALID;
-  }
-  llvm_unreachable("Unhandled architecture");
+  return getProfileKind(parseArch(Arch));
 }
 
 StringRef ARM::getArchSynonym(StringRef Arch) {
@@ -546,6 +550,17 @@
   return StartingNumFeatures != Features.size();
 }
 
+ARM::ArchKind ARM::convertV9toV8(ARM::ArchKind AK) {
+  if (getProfileKind(AK) != ProfileKind::A)
+return ARM::ArchKind::INVALID;
+  if (AK < ARM::ArchKind::ARMV9A || AK > ARM::ArchKind::ARMV9_3A)
+return ARM::ArchKind::INVALID;
+  unsigned AK_v8 = static_cast(ARM::ArchKind::ARMV8_5A);
+  AK_v8 += static_cast(AK) -
+   static_cast(ARM::ArchKind::ARMV9A);
+  return static_cast(AK_v8);
+}
+
 StringRef ARM::getDefaultCPU(StringRef Arch) {
   ArchKind AK = parseArch(Arch);
   if (AK == ArchKind::INVALID)
Index: llvm/include/llvm/Support/ARMTargetParser.h
===
--- llvm/include/llvm/Support/ARMTargetParser.h
+++ llvm/include/llvm/Support/ARMTargetParser.h
@@ -237,6 +237,20 @@
 #include "llvm/Support/ARMTargetParser.def"
 };
 
+in

[clang] 885dadf - [NFC] Fix merge mistake in TokenAnnotator.cpp

2022-10-25 Thread Tobias Hieta via cfe-commits

Author: Tobias Hieta
Date: 2022-10-25T10:08:51+02:00
New Revision: 885dadf648fc5b174e21175f726917e1528df218

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

LOG: [NFC] Fix merge mistake in TokenAnnotator.cpp

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index fba1a125dc57..0b613c95110f 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1346,6 +1346,7 @@ class AnnotatingParser {
   CurrentToken->setType(TT_ImplicitStringLiteral);
 next();
 }
+  }
 }
   }
 



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


[PATCH] D135858: [clang][Interp] Support pointer arithmetic in binary operators

2022-10-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder updated this revision to Diff 470400.
tbaeder marked 5 inline comments as done.

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

https://reviews.llvm.org/D135858

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp
  clang/lib/AST/Interp/ByteCodeExprGen.h
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/Opcodes.td
  clang/lib/AST/Interp/Pointer.cpp
  clang/test/AST/Interp/arrays.cpp

Index: clang/test/AST/Interp/arrays.cpp
===
--- clang/test/AST/Interp/arrays.cpp
+++ clang/test/AST/Interp/arrays.cpp
@@ -37,6 +37,56 @@
 static_assert(getElement(1) == 4, "");
 static_assert(getElement(5) == 36, "");
 
+constexpr int data[] = {5, 4, 3, 2, 1};
+constexpr int getElement(const int *Arr, int index) {
+  return *(Arr + index);
+}
+
+static_assert(getElement(data, 1) == 4, "");
+static_assert(getElement(data, 4) == 1, "");
+
+constexpr int getElementFromEnd(const int *Arr, int size, int index) {
+  return *(Arr + size - index - 1);
+}
+static_assert(getElementFromEnd(data, 5, 0) == 1, "");
+static_assert(getElementFromEnd(data, 5, 4) == 5, "");
+
+
+constexpr static int arr[2] = {1,2};
+constexpr static int arr2[2] = {3,4};
+constexpr int *p1 = nullptr;
+constexpr int *p2 = p1 + 1; // expected-error {{must be initialized by a constant expression}} \
+// expected-note {{cannot perform pointer arithmetic on null pointer}} \
+// ref-error {{must be initialized by a constant expression}} \
+// ref-note {{cannot perform pointer arithmetic on null pointer}}
+constexpr int *p3 = p1 + 0;
+constexpr int *p4 = p1 - 0;
+constexpr int *p5 =  0 + p1;
+constexpr int *p6 =  0 - p1; // expected-error {{invalid operands to binary expression}} \
+ // ref-error {{invalid operands to binary expression}}
+
+constexpr int const * ap1 = &arr[0];
+constexpr int const * ap2 = ap1 + 3; // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{cannot refer to element 3 of array of 2}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{cannot refer to element 3 of array of 2}}
+
+constexpr auto ap3 = arr - 1; // expected-error {{must be initialized by a constant expression}} \
+  // expected-note {{cannot refer to element -1}} \
+  // ref-error {{must be initialized by a constant expression}} \
+  // ref-note {{cannot refer to element -1}}
+constexpr int k1 = &arr[1] - &arr[0];
+static_assert(k1 == 1, "");
+static_assert((&arr[0] - &arr[1]) == -1, "");
+
+constexpr int k2 = &arr2[1] - &arr[0]; // expected-error {{must be initialized by a constant expression}} \
+   // ref-error {{must be initialized by a constant expression}}
+
+static_assert((arr + 0) == arr, "");
+static_assert(&arr[0] == arr, "");
+static_assert(*(&arr[0]) == 1, "");
+static_assert(*(&arr[1]) == 2, "");
+
 
 template
 constexpr T getElementOf(T* array, int i) {
@@ -52,7 +102,6 @@
 static_assert(getElementOfArray(foo[2], 3) == &m, "");
 
 
-constexpr int data[] = {5, 4, 3, 2, 1};
 static_assert(data[0] == 4, ""); // expected-error{{failed}} \
  // expected-note{{5 == 4}} \
  // ref-error{{failed}} \
Index: clang/lib/AST/Interp/Pointer.cpp
===
--- clang/lib/AST/Interp/Pointer.cpp
+++ clang/lib/AST/Interp/Pointer.cpp
@@ -201,5 +201,5 @@
 }
 
 bool Pointer::hasSameArray(const Pointer &A, const Pointer &B) {
-  return A.Base == B.Base && A.getFieldDesc()->IsArray;
+  return hasSameBase(A, B) && A.Base == B.Base && A.getFieldDesc()->IsArray;
 }
Index: clang/lib/AST/Interp/Opcodes.td
===
--- clang/lib/AST/Interp/Opcodes.td
+++ clang/lib/AST/Interp/Opcodes.td
@@ -390,6 +390,12 @@
 // [Pointer, Integral] -> [Pointer]
 def SubOffset : AluOpcode;
 
+// Pointer, Pointer] - [Integral]
+def SubPtr : Opcode {
+  let Types = [IntegerTypeClass];
+  let HasGroup = 1;
+}
+
 //===--===//
 // Binary operators.
 //===--===//
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -350,6 +350,16 @@
   } else {
 unsigned VL = LHS.getByteOffset();
 unsigned VR = RHS.getByteOffset();
+
+// In our Pointer class, a pointer to an array and a pointer to the first
+// element in the same array are NOT equal. They have the same Base value,
+// but a diffe

[PATCH] D136533: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a subscriber: kcc.
mizvekov added a comment.

pinging @kcc for LibFuzzer, I believe this needs to be fixed there, if we don't 
want to bump the MacOs minimum version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D136668: [clang][dataflow] Add initial sign analysis

2022-10-25 Thread Gabor Marton via Phabricator via cfe-commits
martong created this revision.
martong added reviewers: xazax.hun, gribozavr2, sgatev, ymandel.
Herald added subscribers: steakhal, rnkovacs.
Herald added a reviewer: Szelethus.
Herald added a project: All.
martong requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch adds an initial implementation for sign analysis, with the
following lattice (T: top, N: negative, Z: zero, P: positive, B: bottom):

  T

/ | \
N Z P
\ | /

  B

The lattice is implemented with `BoolValue` properties attached to other
`Value`s.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136668

Files:
  clang/unittests/Analysis/FlowSensitive/CMakeLists.txt
  clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
===
--- /dev/null
+++ clang/unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp
@@ -0,0 +1,963 @@
+//===- unittests/Analysis/FlowSensitive/SignAnalysisTest.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+//  This file defines a simplistic version of Sign Analysis as an example
+//  of a forward, monotonic dataflow analysis.
+//
+//===--===//
+
+#include "TestingSupport.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
+#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
+#include "clang/Analysis/FlowSensitive/NoopLattice.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Testing/Support/Annotations.h"
+#include "llvm/Testing/Support/Error.h"
+#include "gtest/gtest.h"
+#include 
+
+namespace {
+
+using namespace clang;
+using namespace dataflow;
+using namespace ast_matchers;
+using namespace test;
+using ::testing::UnorderedElementsAre;
+
+enum class Sign : int { Negative, Zero, Positive };
+
+Sign getSign(int64_t V) {
+  return V == 0 ? Sign::Zero : (V < 0 ? Sign::Negative : Sign::Positive);
+}
+
+using LatticeTransferState = TransferState;
+
+constexpr char kVar[] = "var";
+
+void initNegative(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(true));
+  Val.setProperty("zero", Env.getBoolLiteralValue(false));
+  Val.setProperty("pos", Env.getBoolLiteralValue(false));
+}
+void initPositive(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(false));
+  Val.setProperty("zero", Env.getBoolLiteralValue(false));
+  Val.setProperty("pos", Env.getBoolLiteralValue(true));
+}
+void initZero(Value &Val, Environment &Env) {
+  Val.setProperty("neg", Env.getBoolLiteralValue(false));
+  Val.setProperty("zero", Env.getBoolLiteralValue(true));
+  Val.setProperty("pos", Env.getBoolLiteralValue(false));
+}
+
+struct SignProperties {
+  BoolValue *Neg, *Zero, *Pos;
+};
+void setSignProperties(Value &Val, const SignProperties &Ps) {
+  Val.setProperty("neg", *Ps.Neg);
+  Val.setProperty("zero", *Ps.Zero);
+  Val.setProperty("pos", *Ps.Pos);
+}
+SignProperties initUnknown(Value &Val, Environment &Env) {
+  SignProperties Ps{&Env.makeAtomicBoolValue(), &Env.makeAtomicBoolValue(),
+&Env.makeAtomicBoolValue()};
+  setSignProperties(Val, Ps);
+  return Ps;
+}
+SignProperties getSignProperties(const Value &Val, const Environment &Env) {
+  return {dyn_cast_or_null(Val.getProperty("neg")),
+  dyn_cast_or_null(Val.getProperty("zero")),
+  dyn_cast_or_null(Val.getProperty("pos"))};
+}
+
+void transferUninitializedInt(const DeclStmt *D,
+  const MatchFinder::MatchResult &M,
+  LatticeTransferState &State) {
+  const auto *Var = M.Nodes.getNodeAs(kVar);
+  assert(Var != nullptr);
+  const StorageLocation *Loc =
+  State.Env.getStorageLocation(*Var, SkipPast::None);
+  Value *Val = State.Env.getValue(*Loc);
+  initUnknown(*Val, State.Env);
+}
+
+std::tuple
+getValueAndSignProperties(const UnaryOperator *UO,
+  const MatchFinder::MatchResult &M,
+  LatticeTransferState &State) {
+  // The DeclRefExpr refers to this variable in the operand.
+  const auto *OpdVar = M.Nodes.getNodeAs(kVar);
+  assert(OpdVar != nullptr);
+  const auto *OperandVal = State.Env.getValue(*OpdVar, SkipPast::None);
+  if (!OperandVal)
+return {nullptr, {}, {}};
+
+  // Value of the unary op.
+  auto *UOVal = State.Env.getValue(*UO, SkipPast::None);
+  if (!UOVal) {
+auto &Loc = State.Env.createStorageLocation(*UO);
+State.Env.setStorageLocation(*UO, Loc);
+UOVal = &State.Env.makeAtomic

[clang] d0d9d1e - [clang-format] Move bracket to correct line.

2022-10-25 Thread Adrian Kuegel via cfe-commits

Author: Adrian Kuegel
Date: 2022-10-25T11:06:02+02:00
New Revision: d0d9d1e3d232d4025bcb776117dc6a0df71da23c

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

LOG: [clang-format] Move bracket to correct line.

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 0b613c95110f..da6e21c48814 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1344,8 +1344,8 @@ class AnnotatingParser {
   while (CurrentToken) {
 if (IsMarkOrRegion || CurrentToken->Previous->is(TT_BinaryOperator)) {
   CurrentToken->setType(TT_ImplicitStringLiteral);
-next();
 }
+next();
   }
 }
   }



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


[PATCH] D136670: [clang][Interp] Fix InterpFrame::describe() for This pointers

2022-10-25 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.

  Since we pass this via the stack, we need to account for it when
  desribing the stack frame (parameters). This fixes a previously
  commented-out test case.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136670

Files:
  clang/lib/AST/Interp/InterpFrame.cpp
  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
@@ -281,11 +281,6 @@
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant 
expression}} \
  // ref-note {{initializer of 'D' is not a 
constant expression}}
 
-#if 0
-  // FIXME: This test is currently disabled because the failing constructor 
call
-  //   causes us to run into an assertion later on in the new interpreter.
-  //   Once that is fixed, we fail successfully but the diagnostic uses the
-  //   wrong value.
   struct AnotherBase {
 int Val;
 constexpr AnotherBase(int i) : Val(12 / i) {} //ref-note {{division by 
zero}} \
@@ -298,9 +293,7 @@
   constexpr AnotherBase Derp(0); // ref-error {{must be initialized by a 
constant expression}} \
  // ref-note {{in call to 'AnotherBase(0)'}} \
  // expected-error {{must be initialized by a 
constant expression}} \
- // expected-note {{in call to 'AnotherBase(}}
- // FIXME Previous note uses the wrong value
-#endif
+ // expected-note {{in call to 
'AnotherBase(0)'}}
 
   struct YetAnotherBase {
 int Val;
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -142,7 +142,11 @@
 OS << "->";
   }
   OS << *F << "(";
-  unsigned Off = Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  unsigned Off = 0;
+
+  Off += Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  Off += Func->hasThisPointer() ? primSize(PT_Ptr) : 0;
+
   for (unsigned I = 0, N = F->getNumParams(); I < N; ++I) {
 QualType Ty = F->getParamDecl(I)->getType();
 


Index: clang/test/AST/Interp/records.cpp
===
--- clang/test/AST/Interp/records.cpp
+++ clang/test/AST/Interp/records.cpp
@@ -281,11 +281,6 @@
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
  // ref-note {{initializer of 'D' is not a constant expression}}
 
-#if 0
-  // FIXME: This test is currently disabled because the failing constructor call
-  //   causes us to run into an assertion later on in the new interpreter.
-  //   Once that is fixed, we fail successfully but the diagnostic uses the
-  //   wrong value.
   struct AnotherBase {
 int Val;
 constexpr AnotherBase(int i) : Val(12 / i) {} //ref-note {{division by zero}} \
@@ -298,9 +293,7 @@
   constexpr AnotherBase Derp(0); // ref-error {{must be initialized by a constant expression}} \
  // ref-note {{in call to 'AnotherBase(0)'}} \
  // expected-error {{must be initialized by a constant expression}} \
- // expected-note {{in call to 'AnotherBase(}}
- // FIXME Previous note uses the wrong value
-#endif
+ // expected-note {{in call to 'AnotherBase(0)'}}
 
   struct YetAnotherBase {
 int Val;
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -142,7 +142,11 @@
 OS << "->";
   }
   OS << *F << "(";
-  unsigned Off = Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  unsigned Off = 0;
+
+  Off += Func->hasRVO() ? primSize(PT_Ptr) : 0;
+  Off += Func->hasThisPointer() ? primSize(PT_Ptr) : 0;
+
   for (unsigned I = 0, N = F->getNumParams(); I < N; ++I) {
 QualType Ty = F->getParamDecl(I)->getType();
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136604: Add clang_CXXMethod_isCopyAssignmentOperator to libclang

2022-10-25 Thread Luca Di sera via Phabricator via cfe-commits
diseraluca added a comment.

In D136604#3879928 , @aaron.ballman 
wrote:

> LGTM!
>
> Would you like to obtain commit access to land this one on your own 
> (https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access)? If not, 
> that's fine, I can also land it on your behalf.

That seems like a nice idea, especially if it can save other people's time by 
having me finalize the commit. I've sent an email as detailed in the link you 
posted. I'll wait for an answer and, if it is positive, I'll try to do the 
landing myself.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136604

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


[PATCH] D136671: [analyzer] Fix crash for array-delete of UnknownVal values.

2022-10-25 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource created this revision.
Herald added subscribers: steakhal, manas, ASDenysPetrov, martong, dkrupp, 
donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, 
xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
tomasz-kaminski-sonarsource requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We now skip the destruction of array elements for `delete[] p`,
if the value of `p` is UnknownVal and does not have corresponding region.
This eliminate the crash in `getDynamicElementCount` on that
region and matches the behavior for deleting the array of
non-constant range.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136671

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/Analysis/dtor-array.cpp


Index: clang/test/Analysis/dtor-array.cpp
===
--- clang/test/Analysis/dtor-array.cpp
+++ clang/test/Analysis/dtor-array.cpp
@@ -344,3 +344,36 @@
   // region to a conjured symbol.
   clang_analyzer_eval(InlineDtor::dtorCalled == 0); // expected-warning 
{{TRUE}} expected-warning {{FALSE}}
 }
+
+namespace crash6 {
+
+struct NonTrivialItem {
+  ~NonTrivialItem();
+};
+
+struct WeirdVec {
+  void clear() {
+delete[] data;
+size = 0;
+  }
+  NonTrivialItem *data;
+  unsigned size;
+};
+
+void top(int j) {
+  WeirdVec *p = new WeirdVec;
+
+  p[j].size = 0;
+  delete[] p->data; // no-crash
+}
+
+template 
+T make_unknown() {
+  return reinterpret_cast(static_cast(0.404));
+}
+
+void directUnknownSymbol() {
+  delete[] make_unknown(); // no-crash
+}
+
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1420,31 +1420,32 @@
   const MemRegion *ArgR = ArgVal.getAsRegion();
 
   if (DE->isArrayForm()) {
-SVal ElementCount;
-std::tie(State, Idx) =
-prepareStateForArrayDestruction(State, ArgR, DTy, LCtx, &ElementCount);
-
 CallOpts.IsArrayCtorOrDtor = true;
 // Yes, it may even be a multi-dimensional array.
 while (const auto *AT = getContext().getAsArrayType(DTy))
   DTy = AT->getElementType();
 
-// If we're about to destruct a 0 length array, don't run any of the
-// destructors.
-if (ElementCount.isConstant() &&
-ElementCount.getAsInteger()->getLimitedValue() == 0) {
+if (ArgR) {
+  SVal ElementCount;
+  std::tie(State, Idx) = prepareStateForArrayDestruction(
+  State, ArgR, DTy, LCtx, &ElementCount);
 
-  static SimpleProgramPointTag PT(
-  "ExprEngine", "Skipping 0 length array delete destruction");
-  PostImplicitCall PP(getDtorDecl(DTy), DE->getBeginLoc(), LCtx, &PT);
-  NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
-  Bldr.generateNode(PP, Pred->getState(), Pred);
-  return;
-}
+  // If we're about to destruct a 0 length array, don't run any of the
+  // destructors.
+  if (ElementCount.isConstant() &&
+  ElementCount.getAsInteger()->getLimitedValue() == 0) {
+
+static SimpleProgramPointTag PT(
+"ExprEngine", "Skipping 0 length array delete destruction");
+PostImplicitCall PP(getDtorDecl(DTy), DE->getBeginLoc(), LCtx, &PT);
+NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
+Bldr.generateNode(PP, Pred->getState(), Pred);
+return;
+  }
 
-if (ArgR)
   ArgR = State->getLValue(DTy, svalBuilder.makeArrayIndex(Idx), ArgVal)
  .getAsRegion();
+}
   }
 
   NodeBuilder Bldr(Pred, Dst, getBuilderContext());


Index: clang/test/Analysis/dtor-array.cpp
===
--- clang/test/Analysis/dtor-array.cpp
+++ clang/test/Analysis/dtor-array.cpp
@@ -344,3 +344,36 @@
   // region to a conjured symbol.
   clang_analyzer_eval(InlineDtor::dtorCalled == 0); // expected-warning {{TRUE}} expected-warning {{FALSE}}
 }
+
+namespace crash6 {
+
+struct NonTrivialItem {
+  ~NonTrivialItem();
+};
+
+struct WeirdVec {
+  void clear() {
+delete[] data;
+size = 0;
+  }
+  NonTrivialItem *data;
+  unsigned size;
+};
+
+void top(int j) {
+  WeirdVec *p = new WeirdVec;
+
+  p[j].size = 0;
+  delete[] p->data; // no-crash
+}
+
+template 
+T make_unknown() {
+  return reinterpret_cast(static_cast(0.404));
+}
+
+void directUnknownSymbol() {
+  delete[] make_unknown(); // no-crash
+}
+
+}
\ No newline at end of file
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1420,31 +1420,32 @@
   const MemRegion *ArgR = ArgVal.getAsRegion();
 
   if (DE->isArrayForm()) {
-SVal ElementCount;
-std::tie(State, Idx) =
-

[PATCH] D136455: [clang][ExtractAPI] Add targetFallback to relationships in symbol graph

2022-10-25 Thread Daniel Grumberg via Phabricator via cfe-commits
dang added a comment.

However, I am not sure it's worthwhile and we might run into edge cases doing 
it this way with explicitly ignored symbols.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136455

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


[PATCH] D129531: [clang][C++20] P0960R3: Allow initializing aggregates from a parenthesized list of values

2022-10-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added inline comments.



Comment at: clang/lib/Serialization/ASTReaderStmt.cpp:2179
+  for (unsigned I = 0; I < E->NumExprs; I++)
+E->getTrailingObjects()[I] = Record.readSubExpr();
+}

FYI: I think this is where the crash comes from.
We should allocate the trailing objects first.
E.g. see how `PragmaCommentDecl::CreateDeserialized` does this.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129531

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


[PATCH] D136571: [RISCV] add svinval extension

2022-10-25 Thread Piyou Chen via Phabricator via cfe-commits
BeMg updated this revision to Diff 470428.
BeMg added a comment.

Update RISCVUsage.html


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136571

Files:
  clang/test/Preprocessor/riscv-target-features.c
  llvm/docs/RISCVUsage.rst
  llvm/lib/Support/RISCVISAInfo.cpp
  llvm/lib/Target/RISCV/RISCV.td
  llvm/lib/Target/RISCV/RISCVInstrInfo.td
  llvm/lib/Target/RISCV/RISCVSubtarget.h
  llvm/test/CodeGen/RISCV/attributes.ll
  llvm/test/MC/RISCV/priv-valid.s

Index: llvm/test/MC/RISCV/priv-valid.s
===
--- llvm/test/MC/RISCV/priv-valid.s
+++ llvm/test/MC/RISCV/priv-valid.s
@@ -1,12 +1,12 @@
-# RUN: llvm-mc %s -triple=riscv32 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv32 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc %s -triple=riscv64 -riscv-no-aliases -show-encoding \
+# RUN: llvm-mc %s -triple=riscv64 -mattr=+svinval -riscv-no-aliases -show-encoding \
 # RUN: | FileCheck -check-prefixes=CHECK,CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv32 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
-# RUN: llvm-mc -filetype=obj -triple riscv64 < %s \
-# RUN: | llvm-objdump -M no-aliases -d - \
+# RUN: llvm-mc -filetype=obj -triple riscv64 -mattr=+svinval < %s \
+# RUN: | llvm-objdump --mattr=+svinval -M no-aliases -d - \
 # RUN: | FileCheck -check-prefix=CHECK-INST %s
 
 # CHECK-INST: uret
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -36,6 +36,7 @@
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV32ZICBOM %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV32ZICBOZ %s
 ; RUN: llc -mtriple=riscv32 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV32ZICBOP %s
+; RUN: llc -mtriple=riscv32 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV32SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m %s -o - | FileCheck --check-prefix=RV64M %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zmmul %s -o - | FileCheck --check-prefix=RV64ZMMUL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+m,+zmmul %s -o - | FileCheck --check-prefix=RV64MZMMUL %s
@@ -72,6 +73,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+svinval %s -o - | FileCheck --check-prefix=RV64SVINVAL %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
@@ -111,6 +113,7 @@
 ; RV32ZICBOM: .attribute 5, "rv32i2p0_zicbom1p0"
 ; RV32ZICBOZ: .attribute 5, "rv32i2p0_zicboz1p0"
 ; RV32ZICBOP: .attribute 5, "rv32i2p0_zicbop1p0"
+; RV32SVINVAL: .attribute 5, "rv32i2p0_svinval1p0"
 
 ; RV64M: .attribute 5, "rv64i2p0_m2p0"
 ; RV64ZMMUL: .attribute 5, "rv64i2p0_zmmul1p0"
@@ -149,6 +152,7 @@
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
 ; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
+; RV64SVINVAL: .attribute 5, "rv64i2p0_svinval1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
 define i32 @addi(i32 %a) {
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -85,6 +85,7 @@
   bool HasStdExtZicbom = false;
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
+  bool HasStdExtSvinval = false;
   bool HasStdExtZmmul = false;
   bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;
@@ -182,6 +183,7 @@
   bool hasStdExtZicbom() const { return HasStdExtZicbom; }
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
+  bool hasStdExtSvinval() const { return HasStdExtSvinval; }
   bool hasStdExtZawrs() const { return HasStdExtZawrs; }
   bool hasStdExtZmmul() const { return HasStdExtZmmul; }
   bool hasStdExtZtso() const { return HasStdExtZtso; }
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -796,6 +796,7 @@
   let rs2 = 0b00101;
 }
 
+let Predicates = [HasStdExtSvinval]

[clang] 9bd2730 - [Clang][AArch64] Add TargetParser support for defining CPU aliases

2022-10-25 Thread Sjoerd Meijer via cfe-commits

Author: Sjoerd Meijer
Date: 2022-10-25T15:08:15+05:30
New Revision: 9bd273047d4f66e3f36416acb295a3fd75bc6af4

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

LOG: [Clang][AArch64] Add TargetParser support for defining CPU aliases

This adds AArch64 TargetParser support to define CPU aliases, and
ports the definition of Grace over to that. This is following up
on D136425.

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

Added: 


Modified: 
clang/test/Misc/target-invalid-cpu-note.c
llvm/include/llvm/Support/AArch64TargetParser.def
llvm/include/llvm/Support/AArch64TargetParser.h
llvm/lib/Support/AArch64TargetParser.cpp
llvm/unittests/Support/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/Misc/target-invalid-cpu-note.c 
b/clang/test/Misc/target-invalid-cpu-note.c
index 7857e72eca06..f2071c866956 100644
--- a/clang/test/Misc/target-invalid-cpu-note.c
+++ b/clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, cortex-x1c, 
cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1{{$}}
+// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, cortex-a35, 
cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, cortex-a65ae, 
cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, cortex-a77, 
cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, cortex-x1c, 
cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, neoverse-v1, 
neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, apple-a11, 
apple-a12, apple-a13, apple-a14, apple-a15, apple-a16, apple-m1, apple-m2, 
apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, kryo, 
thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, thunderxt83, 
tsv110, a64fx, carmel, ampere1, grace{{$}}
 
 // RUN: not %clang_cc1 -triple arm64--- -tune-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix TUNE_AARCH64
 // TUNE_AARCH64: error: unknown target CPU 'not-a-cpu'
-// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, 
neoverse-v1, neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, 
apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, apple-a16,  apple-m1, 
apple-m2, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, 
kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, 
thunderxt83, tsv110, a64fx, carmel, ampere1{{$}}
+// TUNE_AARCH64-NEXT: note: valid target CPU values are: cortex-a34, 
cortex-a35, cortex-a53, cortex-a55, cortex-a510, cortex-a57, cortex-a65, 
cortex-a65ae, cortex-a72, cortex-a73, cortex-a75, cortex-a76, cortex-a76ae, 
cortex-a77, cortex-a78, cortex-a78c, cortex-a710, cortex-r82, cortex-x1, 
cortex-x1c, cortex-x2, neoverse-e1, neoverse-n1, neoverse-n2, neoverse-512tvb, 
neoverse-v1, neoverse-v2, cyclone, apple-a7, apple-a8, apple-a9, apple-a10, 
apple-a11, apple-a12, apple-a13, apple-a14, apple-a15, apple-a16,  apple-m1, 
apple-m2, apple-s4, apple-s5, exynos-m3, exynos-m4, exynos-m5, falkor, saphira, 
kryo, thunderx2t99, thunderx3t110, thunderx, thunderxt88, thunderxt81, 
thunderxt83, tsv110, a64fx, carmel, ampere1, grace{{$}}
 
 // RUN: not %clang_cc1 -triple i386--- -target-cpu not-a-cpu -fsyntax-only %s 
2>&1 | FileCheck %s --check-prefix X86
 // X86: error: unknown target CPU 'not-a-cpu'

diff  --git a/llvm/include/llvm/Support/AArch64TargetParser.def 
b/llvm/include/llvm/Support/AArch64TargetParser.def
index 49ed806b1d56..2005638e38c3 100644
--- a/llvm/include/llvm/Support/AArch64TargetParser.def
+++ b/llvm/include/llvm/Support/AArch64TargetParser.def
@@ -315,3 +315,9 @@ AARCH64_CPU_NAME("ampere1", ARMV8_6A, 
FK_CRYPT

[PATCH] D136611: [Clang][AArch64] Add TargetParser support for defining CPU aliases

2022-10-25 Thread Sjoerd Meijer 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 rG9bd273047d4f: [Clang][AArch64] Add TargetParser support for 
defining CPU aliases (authored by SjoerdMeijer).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136611

Files:
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/include/llvm/Support/AArch64TargetParser.h
  llvm/lib/Support/AArch64TargetParser.cpp
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1295,7 +1295,8 @@
  AArch64::AEK_LSE | AArch64::AEK_RDM,
  "8.2-A")));
 
-static constexpr unsigned NumAArch64CPUArchs = 58;
+// Note: number of CPUs includes aliases.
+static constexpr unsigned NumAArch64CPUArchs = 59;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Support/AArch64TargetParser.cpp
===
--- llvm/lib/Support/AArch64TargetParser.cpp
+++ llvm/lib/Support/AArch64TargetParser.cpp
@@ -85,6 +85,14 @@
   return true;
 }
 
+StringRef AArch64::resolveCPUAlias(StringRef CPU) {
+  return StringSwitch(CPU)
+#define AARCH64_CPU_ALIAS(ALIAS,NAME)  \
+  .Case(ALIAS, NAME)
+#include "../../include/llvm/Support/AArch64TargetParser.def"
+  .Default(CPU);
+}
+
 bool AArch64::getArchFeatures(AArch64::ArchKind AK,
   std::vector &Features) {
   if (AK == ArchKind::INVALID)
@@ -164,6 +172,9 @@
 if (Arch.ArchID != ArchKind::INVALID)
   Values.push_back(Arch.getName());
   }
+
+  for (const auto &Alias: AArch64CPUAliases)
+Values.push_back(Alias.getAlias());
 }
 
 bool AArch64::isX18ReservedByDefault(const Triple &TT) {
@@ -194,9 +205,17 @@
 }
 
 AArch64::ArchKind AArch64::parseCPUArch(StringRef CPU) {
-  for (const auto &C : AArch64CPUNames) {
+  // Resolve aliases first.
+  for (const auto &Alias : AArch64CPUAliases) {
+if (CPU == Alias.getAlias()) {
+  CPU = Alias.getName();
+  break;
+}
+  }
+  // Then find the CPU name.
+  for (const auto &C : AArch64CPUNames)
 if (CPU == C.getName())
   return C.ArchID;
-  }
+
   return ArchKind::INVALID;
 }
Index: llvm/include/llvm/Support/AArch64TargetParser.h
===
--- llvm/include/llvm/Support/AArch64TargetParser.h
+++ llvm/include/llvm/Support/AArch64TargetParser.h
@@ -109,6 +109,20 @@
 #include "AArch64TargetParser.def"
 };
 
+const struct {
+  const char *Alias;
+  size_t AliasLength;
+  const char *Name;
+  size_t NameLength;
+
+  StringRef getAlias() const { return StringRef(Alias, AliasLength); }
+  StringRef getName() const { return StringRef(Name, NameLength); }
+} AArch64CPUAliases[] = {
+#define AARCH64_CPU_ALIAS(ALIAS,NAME)  \
+  {ALIAS, sizeof(ALIAS) - 1, NAME, sizeof(NAME) - 1},
+#include "AArch64TargetParser.def"
+};
+
 const ArchKind ArchKinds[] = {
 #define AARCH64_ARCH(NAME, ID, CPU_ATTR, SUB_ARCH, ARCH_ATTR, ARCH_FPU, ARCH_BASE_EXT) \
 ArchKind::ID,
@@ -138,13 +152,7 @@
 StringRef getArchExtName(unsigned ArchExtKind);
 StringRef getArchExtFeature(StringRef ArchExt);
 ArchKind convertV9toV8(ArchKind AK);
-
-// FIXME: We should be able to define CPU aliases in TargetParser.
-inline StringRef resolveCPUAlias(StringRef CPU) {
-  if (CPU == "grace")
-return "neoverse-v2";
-  return CPU;
-}
+StringRef resolveCPUAlias(StringRef CPU);
 
 // Information by Name
 unsigned getDefaultFPU(StringRef CPU, ArchKind AK);
Index: llvm/include/llvm/Support/AArch64TargetParser.def
===
--- llvm/include/llvm/Support/AArch64TargetParser.def
+++ llvm/include/llvm/Support/AArch64TargetParser.def
@@ -315,3 +315,9 @@
 // Invalid CPU
 AARCH64_CPU_NAME("invalid", INVALID, FK_INVALID, true, AArch64::AEK_INVALID)
 #undef AARCH64_CPU_NAME
+
+#ifndef AARCH64_CPU_ALIAS
+#define AARCH64_CPU_ALIAS(ALIAS,NAME)
+#endif
+AARCH64_CPU_ALIAS("grace", "neoverse-v2")
+#undef AARCH64_CPU_ALIAS
Index: clang/test/Misc/target-invalid-cpu-note.c
===
--- clang/test/Misc/target-invalid-cpu-note.c
+++ clang/test/Misc/target-invalid-cpu-note.c
@@ -5,11 +5,11 @@
 
 // RUN: not %clang_cc1 -triple arm64--- -target-cpu not-a-cpu -fsyntax-only %s 2>&1 | FileCheck %s --check-prefix AARCH64
 // AARCH64: error: unknown target CPU 'not-a-cpu'
-// AARCH64-NEXT: note: valid target CPU values are: cortex-a34, corte

[PATCH] D136440: [clang] Do not hide base member using-decls with different template head.

2022-10-25 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

My only ask is to add a few more tests (see the relevant comment), otherwise LG.




Comment at: clang/lib/Sema/SemaOverload.cpp:1293
+// templates first; the remaining checks follow.
+bool SameTemplateParameterList = TemplateParameterListsAreEqual(
+NewTemplate->getTemplateParameters(),

Hopefully this does not regress performance too much now that we keep matching 
template even if we don't need the result.
No need to take any action (the code looks simpler this way), just something to 
keep in mind in case it backfires.



Comment at: clang/test/SemaTemplate/concepts-using-decl.cpp:3
+
+namespace heads_without_concepts {
+struct base {

NIT: maybe move this to the end of the file?
I would expect concept-specific tests to go first given the name of the file.
It's still useful to capture the discovered corner-cases, obviously, just not 
as the first thing, maybe.



Comment at: clang/test/SemaTemplate/concepts-using-decl.cpp:112
+  expect<1>(baz{}.foo()); // expected-error {{call to member function 
'foo' is ambiguous}}
+}
+}

Could you also check that `requires` clauses and constraints in template 
parameters do not hide each other?
```
template  ...
// vs
template  requires IsEmpty ...
// vs
template  void foo() requires IsEmpty ...
```
Should not hide each other.

Another interesting case (that probably does not yet work):
```
struct base { template  void foo(); };
struct derived : base { 
  using base::foo; 
  template  void foo();
};
```
^^ `derived().foo()` will probably produce an ambiguity now (as we don't 
have an explicit requires clause here). I don't think it's worth fixing now, 
but keeping a test for it with a FIXME seems reasonable.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136440

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


[clang] 791fe26 - [clang][ExtractAPI] Allow users to specify a list of symbols to ignore

2022-10-25 Thread Daniel Grumberg via cfe-commits

Author: Daniel Grumberg
Date: 2022-10-25T11:46:04+01:00
New Revision: 791fe26d758173e569d26d831b36ee8527e1a766

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

LOG: [clang][ExtractAPI] Allow users to specify a list of symbols to ignore

Adds a `--extract-api-ignores=` command line option that allows users to
provide a file containing a new line separated list of symbols to
unconditionally ignore when extracting API information.

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

Added: 
clang/include/clang/ExtractAPI/APIIgnoresList.h
clang/lib/ExtractAPI/APIIgnoresList.cpp
clang/test/Driver/extract-api-unknown-ignore-diag.h
clang/test/ExtractAPI/ignored-symbols.c

Modified: 
clang/include/clang/Basic/DiagnosticFrontendKinds.td
clang/include/clang/Driver/Options.td
clang/include/clang/ExtractAPI/FrontendActions.h
clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
clang/include/clang/Frontend/FrontendOptions.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/ExtractAPI/CMakeLists.txt
clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticFrontendKinds.td 
b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
index 3e87f6256e0aa..07ecbe332f8b3 100644
--- a/clang/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/clang/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -331,4 +331,7 @@ def warn_profile_data_misexpect : Warning<
   InGroup;
 } // end of instrumentation issue category
 
+def err_extract_api_ignores_file_not_found :
+  Error<"file '%0' specified by '--extract-api-ignores=' not found">, 
DefaultFatal;
+
 }

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2ab40ac6c9639..0f5b6d83330e1 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1121,6 +1121,9 @@ def extract_api : Flag<["-"], "extract-api">, 
Flags<[CC1Option]>, Group;
 def product_name_EQ: Joined<["--"], "product-name=">, Flags<[CC1Option]>,
   MarshallingInfoString>;
+def extract_api_ignores_EQ: Joined<["--"], "extract-api-ignores=">, 
Flags<[CC1Option]>,
+HelpText<"File containing a new line separated list of API symbols to 
ignore when extracting API information.">,
+MarshallingInfoString>;
 def e : JoinedOrSeparate<["-"], "e">, Flags<[LinkerInput]>, Group;
 def fmax_tokens_EQ : Joined<["-"], "fmax-tokens=">, Group, 
Flags<[CC1Option]>,
   HelpText<"Max total number of preprocessed tokens for -Wmax-tokens.">,

diff  --git a/clang/include/clang/ExtractAPI/APIIgnoresList.h 
b/clang/include/clang/ExtractAPI/APIIgnoresList.h
new file mode 100644
index 0..43c546102a2d6
--- /dev/null
+++ b/clang/include/clang/ExtractAPI/APIIgnoresList.h
@@ -0,0 +1,74 @@
+//===- ExtractAPI/APIIgnoresList.h ---*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+///
+/// \file This file defines APIIgnoresList which is a type that allows querying
+/// a file containing symbols to ignore when extracting API information.
+///
+//===--===//
+
+#ifndef LLVM_CLANG_API_IGNORES_LIST_H
+#define LLVM_CLANG_API_IGNORES_LIST_H
+
+#include "clang/Basic/FileManager.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+#include 
+
+namespace llvm {
+class MemoryBuffer;
+} // namespace llvm
+
+namespace clang {
+namespace extractapi {
+
+struct IgnoresFileNotFound : public llvm::ErrorInfo {
+  std::string Path;
+  static char ID;
+
+  explicit IgnoresFileNotFound(StringRef Path) : Path(Path) {}
+
+  virtual void log(llvm::raw_ostream &os) const override;
+
+  virtual std::error_code convertToErrorCode() const override;
+};
+
+/// A type that provides access to a new line separated list of symbol names to
+/// ignore when extracting API information.
+struct APIIgnoresList {
+  /// The API to use for generating from the file at \p IgnoresFilePath.
+  ///
+  /// \returns an initialized APIIgnoresList or an Error.
+  static llvm::Expected create(llvm::StringRef IgnoresFilePath,
+   FileManager &FM);
+
+  APIIgnoresList() = default;
+
+  /// Check if \p SymbolName is specified in the APIIgnoresList and if it 
should

[PATCH] D136450: [clang][ExtractAPI] Allow users to specify a list of symbols to ignore

2022-10-25 Thread Daniel Grumberg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG791fe26d7581: [clang][ExtractAPI] Allow users to specify a 
list of symbols to ignore (authored by dang).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136450

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/ExtractAPI/APIIgnoresList.h
  clang/include/clang/ExtractAPI/FrontendActions.h
  clang/include/clang/ExtractAPI/Serialization/SerializerBase.h
  clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/ExtractAPI/APIIgnoresList.cpp
  clang/lib/ExtractAPI/CMakeLists.txt
  clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
  clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
  clang/test/Driver/extract-api-unknown-ignore-diag.h
  clang/test/ExtractAPI/ignored-symbols.c

Index: clang/test/ExtractAPI/ignored-symbols.c
===
--- /dev/null
+++ clang/test/ExtractAPI/ignored-symbols.c
@@ -0,0 +1,27 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: %clang_cc1 -extract-api -triple arm64-apple-macosx \
+// RUN:   --extract-api-ignores=%t/ignores-list\
+// RUN:   -x c-header %t/input.h -verify -o - | FileCheck %t/input.h
+
+//--- input.h
+#define IGNORED_1 1
+#define IGNORED_2 2
+#define IGNORED_3 3
+#define IGNORED_4 4
+typedef int Ignored;
+typedef float NonIgnored;
+
+// CHECK-NOT: IGNORED_1
+// CHECK-NOT: IGNORED_2
+// CHECK-NOT: IGNORED_3
+// CHECK: NonIgnored
+
+// expected-no-diagnostics
+
+//--- ignores-list
+Ignored
+IGNORED_4
+IGNORED_3   
+IGNORED_2
+IGNORED_1
Index: clang/test/Driver/extract-api-unknown-ignore-diag.h
===
--- /dev/null
+++ clang/test/Driver/extract-api-unknown-ignore-diag.h
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: not %clang -target x86_64-unknown-unknown -extract-api --extract-api-ignores=does-not-exist %s 2>&1 | FileCheck %s
+
+// CHECK: fatal error: file 'does-not-exist' specified by '--extract-api-ignores=' not found
+
+void dummy_function(void);
Index: clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
===
--- clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -14,6 +14,7 @@
 #include "clang/ExtractAPI/Serialization/SymbolGraphSerializer.h"
 #include "clang/Basic/Version.h"
 #include "clang/ExtractAPI/API.h"
+#include "clang/ExtractAPI/APIIgnoresList.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "llvm/Support/JSON.h"
 #include "llvm/Support/Path.h"
@@ -480,6 +481,10 @@
 }
 
 bool SymbolGraphSerializer::shouldSkip(const APIRecord &Record) const {
+  // Skip explicitly ignored symbols.
+  if (IgnoresList.shouldIgnore(Record.Name))
+return true;
+
   // Skip unconditionally unavailable symbols
   if (Record.Availabilities.isUnconditionallyUnavailable())
 return true;
Index: clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
===
--- clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
+++ clang/lib/ExtractAPI/ExtractAPIConsumer.cpp
@@ -20,10 +20,12 @@
 #include "clang/AST/ParentMapContext.h"
 #include "clang/AST/RawCommentList.h"
 #include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Basic/DiagnosticFrontend.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/ExtractAPI/API.h"
+#include "clang/ExtractAPI/APIIgnoresList.h"
 #include "clang/ExtractAPI/AvailabilityInfo.h"
 #include "clang/ExtractAPI/DeclarationFragments.h"
 #include "clang/ExtractAPI/FrontendActions.h"
@@ -38,6 +40,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
@@ -858,6 +861,18 @@
   Policy.AnonymousTagLocations = false;
   CI.getASTContext().setPrintingPolicy(Policy);
 
+  if (!CI.getFrontendOpts().ExtractAPIIgnoresFile.empty()) {
+llvm::handleAllErrors(
+APIIgnoresList::create(CI.getFrontendOpts().ExtractAPIIgnoresFile,
+   CI.getFileManager())
+.moveInto(IgnoresList),
+[&CI](const IgnoresFileNotFound &Err) {
+  CI.getDiagnostics().Report(
+  diag::err_extract_api_ignores_file_not_found)
+  << Err.Path;
+});
+  }
+
   return std::make_unique(CI.getASTContext(),
   std::move(LCF), *API);
 }
@@ -926,7 +941,7 @@
   // Setup a SymbolGraphSerializer to write out 

[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a reviewer: erichkeane.
mizvekov added a subscriber: erichkeane.
mizvekov added a comment.

@erichkeane since you reviewed and approved 5 patches that depend on this one, 
can you also have a look at this please?

Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[PATCH] D136154: [clang-format] Fix the continuation indenter

2022-10-25 Thread Henrik Lafrenz via Phabricator via cfe-commits
hel-ableton marked an inline comment as done.
hel-ableton added a comment.

I filed an issue now in the llvm repo, it just describes how the formatting in 
our case changes, and what _might_ be done to keep it from doing so. I have 
consciously left out any proposed unit tests, because at this point I'm 
honestly too confused as to what would be the best approach there. I hope we 
can somewhat start from square 1 again with this. Sorry if I'm not submitting 
an ideal solution here, but I'm afraid I just know too little about how the 
code and the tests work exactly.

https://github.com/llvm/llvm-project/issues/58592


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

https://reviews.llvm.org/D136154

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


[PATCH] D136671: [analyzer] Fix crash for array-delete of UnknownVal values.

2022-10-25 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs added a comment.

> This eliminate the crash in `getDynamicElementCount` on that region

I think that if the crash comes from `getDynamicElementCount`, we should 
address it there too, so 
when the function is called elsewhere under the same circumstances it won't 
crash again.

What do you think?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136671

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


[PATCH] D127462: [Clang] Begin implementing Plan 9 C extensions

2022-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: aaron.ballman.
aaron.ballman added a comment.

In D127462#3877815 , @ksaunders wrote:

> Ping.

Sorry for not noticing this patch was languishing! As far as the patch itself 
goes, I don't see any major concerns.

Because this is the first of quite a few patches adding various extensions to 
Clang, I think the idea as a whole should get an RFC on Discourse 
(https://discourse.llvm.org/c/clang/6) to ensure that the community agrees we 
should adopt and maintain Plan 9 compatibility. It'd be helpful to focus on the 
criteria we have for adding extensions to the project 
(https://clang.llvm.org/get_involved.html#criteria) to the extent you can, but 
having details like you've got in the summary is also very helpful. That said, 
I have some questions:

I'm wondering if you could go into a bit more detail about what `Automatic 
embedded structure type decay` and `Embedded structure type name accesses` mean 
in practice (some code examples would be helpful).

Are you planning to add a new driver for Clang to emulate the Plan 9 compiler 
driver (similar to how we have a driver for MSVC compatibility)?
Are there other extensions planned, or is the list in the summary pretty 
complete?
Do I understand correctly that plan 9 compatibility mode forces C89 as the 
language standard mode, or is it expected that users can do things like 
`-std=c2x -fplan9-extensions`?

You can feel free to answer my questions in the Discourse RFC if you don't want 
to fork the discussion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D127462

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


[PATCH] D136671: [analyzer] Fix crash for array-delete of UnknownVal values.

2022-10-25 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource added a comment.

In D136671#3882166 , @isuckatcs wrote:

>> This eliminate the crash in `getDynamicElementCount` on that region
>
> I think that if the crash comes from `getDynamicElementCount`, we should 
> address it there too, so 
> when the function is called elsewhere under the same circumstances it won't 
> crash again.
>
> What do you think?

Good point .
I was also wondering about it and went for the current approach or preserving 
the precondition that the passed region cannot be null, because:

- For other uses of `prepareStateForArrayDestruction` in case of automatic 
variables or members, the destroyed should be always known, so this 
precondition makes sense. In this context `delete[] p` of unknown pointer is 
special case, so localized handling made sense.
- This case of `ArgR` being null was already handled in the code, so extending 
it seemed to be more consistent.

Does it make sense to you?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136671

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


[PATCH] D136604: Add clang_CXXMethod_isCopyAssignmentOperator to libclang

2022-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D136604#3881949 , @diseraluca 
wrote:

> In D136604#3879928 , @aaron.ballman 
> wrote:
>
>> LGTM!
>>
>> Would you like to obtain commit access to land this one on your own 
>> (https://llvm.org/docs/DeveloperPolicy.html#obtaining-commit-access)? If 
>> not, that's fine, I can also land it on your behalf.
>
> That seems like a nice idea, especially if it can save other people's time by 
> having me finalize the commit. I've sent an email as detailed in the link you 
> posted. I'll wait for an answer and, if it is positive, I'll try to do the 
> landing myself.

Sounds great! If you run into problems or have questions, let me know and I'm 
happy to help. Thanks again for the improvements!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136604

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


[PATCH] D136532: [clang][Interp] Implement left and right shifts

2022-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang/test/AST/Interp/shifts.cpp:57
+//c >>= 99; // expected-warning {{shift count >= width of type}}
+//c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+//c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}}

tbaeder wrote:
> shafik wrote:
> > This is not correct, the operands go through integral promotions first and 
> > the result is the promoted type of the left operand see [dcl.shift 
> > p1](https://eel.is/c++draft/expr.shift#1).
> > 
> > Also see godbolt: https://godbolt.org/z/7qzKjojMb
> Hmm, this is copy-pasted from `test/SemaCXX/shift.cpp`.
FWIW, I agree with Shafik -- you can also see the casts in the AST: 
https://godbolt.org/z/97dqr1TEs



Comment at: clang/test/AST/Interp/shifts.cpp:70
+i = 1 << (WORD_BIT - 1); // cxx17-warning-not {{sets the sign bit of the 
shift expression}}
+i = -1 << (WORD_BIT - 1); // cxx17-warning {{shifting a negative signed 
value is undefined}} \
+  // ref-cxx17-warning {{shifting a negative 
signed value is undefined}}

tbaeder wrote:
> shafik wrote:
> > shafik wrote:
> > > A negative left operand was made well-formed in C++20 I believe see 
> > > godbolt: https://godbolt.org/z/7qzKjojMb
> > > 
> > > My reference from above for `expr.shift/p1` also applies. 
> > > 
> > > Although a negative right operand is still UB.
> > > 
> > > Also note shifting into the sign bit was made well-formed in C++11: 
> > > https://stackoverflow.com/questions/19593938/is-left-shifting-a-negative-integer-undefined-behavior-in-c11#comment29091986_19593938
> > Typo, shifting into the sign bit was made well-formed after C++11
> This is in line with the test, isn't it? The warning is only for `cxx17`, the 
> c++20 tests don't expect any output.
Also worth keeping in mind: C and C++ differ here.

C2x 6.5.7p4: "... If E1 has a signed type and nonnegative value, and E1 × 2E2 
is representable in the result type, then that is the resulting value; 
otherwise, the behavior is undefined."


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

https://reviews.llvm.org/D136532

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


[PATCH] D136670: [clang][Interp] Fix InterpFrame::describe() for This pointers

2022-10-25 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/D136670/new/

https://reviews.llvm.org/D136670

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


[PATCH] D136589: [AArch64] Add support for the Cortex-X3 CPU

2022-10-25 Thread Victor Campos via Phabricator via cfe-commits
vhscampos updated this revision to Diff 470449.
vhscampos marked 2 inline comments as done.
vhscampos added a comment.

Comments addressed


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136589

Files:
  clang/docs/ReleaseNotes.rst
  clang/test/Driver/aarch64-mcpu.c
  clang/test/Misc/target-invalid-cpu-note.c
  llvm/docs/ReleaseNotes.rst
  llvm/include/llvm/Support/AArch64TargetParser.def
  llvm/lib/Support/Host.cpp
  llvm/lib/Target/AArch64/AArch64.td
  llvm/lib/Target/AArch64/AArch64Subtarget.cpp
  llvm/lib/Target/AArch64/AArch64Subtarget.h
  llvm/unittests/Support/TargetParserTest.cpp

Index: llvm/unittests/Support/TargetParserTest.cpp
===
--- llvm/unittests/Support/TargetParserTest.cpp
+++ llvm/unittests/Support/TargetParserTest.cpp
@@ -1073,6 +1073,18 @@
  AArch64::AEK_SVE2BITPERM | AArch64::AEK_SSBS |
  AArch64::AEK_SB | AArch64::AEK_FP16FML,
  "9-A"),
+ARMCPUTestParams("cortex-x3", "armv9-a", "neon-fp-armv8",
+ AArch64::AEK_CRC | AArch64::AEK_FP | AArch64::AEK_BF16 |
+ AArch64::AEK_SIMD | AArch64::AEK_RAS |
+ AArch64::AEK_LSE | AArch64::AEK_RDM |
+ AArch64::AEK_RCPC | AArch64::AEK_DOTPROD |
+ AArch64::AEK_MTE | AArch64::AEK_PAUTH |
+ AArch64::AEK_SVE | AArch64::AEK_SVE2 |
+ AArch64::AEK_SVE2BITPERM | AArch64::AEK_SB |
+ AArch64::AEK_PROFILE | AArch64::AEK_PERFMON |
+ AArch64::AEK_I8MM | AArch64::AEK_FP16 |
+ AArch64::AEK_FP16FML | AArch64::AEK_PREDRES,
+ "9-A"),
 ARMCPUTestParams("cyclone", "armv8-a", "crypto-neon-fp-armv8",
  AArch64::AEK_NONE | AArch64::AEK_CRYPTO |
  AArch64::AEK_FP | AArch64::AEK_SIMD,
@@ -1296,7 +1308,7 @@
  "8.2-A")));
 
 // Note: number of CPUs includes aliases.
-static constexpr unsigned NumAArch64CPUArchs = 59;
+static constexpr unsigned NumAArch64CPUArchs = 60;
 
 TEST(TargetParserTest, testAArch64CPUArchList) {
   SmallVector List;
Index: llvm/lib/Target/AArch64/AArch64Subtarget.h
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.h
+++ llvm/lib/Target/AArch64/AArch64Subtarget.h
@@ -68,6 +68,7 @@
 CortexX1,
 CortexX1C,
 CortexX2,
+CortexX3,
 ExynosM3,
 Falkor,
 Kryo,
Index: llvm/lib/Target/AArch64/AArch64Subtarget.cpp
===
--- llvm/lib/Target/AArch64/AArch64Subtarget.cpp
+++ llvm/lib/Target/AArch64/AArch64Subtarget.cpp
@@ -143,6 +143,7 @@
 break;
   case CortexA710:
   case CortexX2:
+  case CortexX3:
 PrefFunctionLogAlignment = 4;
 VScaleForTuning = 1;
 PrefLoopLogAlignment = 5;
Index: llvm/lib/Target/AArch64/AArch64.td
===
--- llvm/lib/Target/AArch64/AArch64.td
+++ llvm/lib/Target/AArch64/AArch64.td
@@ -785,6 +785,13 @@
   FeatureLSLFast,
   FeaturePostRAScheduler]>;
 
+def TuneX3 : SubtargetFeature<"cortex-x3", "ARMProcFamily", "CortexX3",
+  "Cortex-X3 ARM processors", [
+   FeatureLSLFast,
+   FeatureFuseAdrpAdd,
+   FeatureFuseAES,
+   FeaturePostRAScheduler]>;
+
 def TuneA64FX : SubtargetFeature<"a64fx", "ARMProcFamily", "A64FX",
  "Fujitsu A64FX processors", [
  FeaturePostRAScheduler,
@@ -1109,6 +1116,11 @@
  FeatureMatMulInt8, FeatureBF16, FeatureAM,
  FeatureMTE, FeatureETE, FeatureSVE2BitPerm,
  FeatureFP16FML];
+  list X3 =   [HasV9_0aOps, FeatureSVE, FeatureNEON,
+ FeaturePerfMon, FeatureETE, FeatureTRBE,
+ FeatureSPE, FeatureBF16, FeatureMatMulInt8,
+ FeatureMTE, FeatureSVE2BitPerm, FeatureFullFP16,
+ FeatureFP16FML];
   list A64FX= [HasV8_2aOps, FeatureFPARMv8, FeatureNEON,
  FeatureSHA2, FeaturePerfMon, FeatureFullFP16,
  FeatureSVE, FeatureComplxNum];
@@ -1239,6 +1251,8 @@
  [TuneX1]>;
 def : ProcessorModel<"cortex-x2", NeoverseN2Model, ProcessorFeatures.X2,
  [TuneX2]>;
+def : ProcessorModel<"cortex-x3", CortexA57Model

[PATCH] D136589: [AArch64] Add support for the Cortex-X3 CPU

2022-10-25 Thread Victor Campos via Phabricator via cfe-commits
vhscampos added inline comments.



Comment at: llvm/docs/ReleaseNotes.rst:84
 
+* Added support for the Cortex-X3 CPU.
+

dmgreen wrote:
> Can you add a reference to neoverse-v2 too.
I could do this in another patch, but I prefer to restrict this one to X3.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136589

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


[PATCH] D136589: [AArch64] Add support for the Cortex-X3 CPU

2022-10-25 Thread Victor Campos via Phabricator via cfe-commits
vhscampos added inline comments.



Comment at: llvm/docs/ReleaseNotes.rst:84
 
+* Added support for the Cortex-X3 CPU.
+

vhscampos wrote:
> dmgreen wrote:
> > Can you add a reference to neoverse-v2 too.
> I could do this in another patch, but I prefer to restrict this one to X3.
I meant I prefer to restrict this patch to X3 only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136589

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


[PATCH] D136602: NFC: [clang] Template argument cleanups.

2022-10-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added inline comments.



Comment at: 
clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp:101
+const TemplateArgument &Arg =
+FunctorParentType->template_arguments()[ArgNum];
 if (Arg.getKind() != TemplateArgument::Type)

This is overall a nice change, but here (and a few other places), the RHS looks 
strictly uglier to me. Maybe it makes sense to keep the getNumArgs() / getArg() 
functions (and make them call template_arguments() internally), for the cases 
where the code doesn't iterate over everything?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136602

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


[PATCH] D134902: [clang] Implement -fstrict-flex-arrays=3

2022-10-25 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D134902#3848616 , @kees wrote:

> In D134902#3848595 , 
> @serge-sans-paille wrote:
>
>> I second the opinion here. C99 says nothing about flexible array member for 
>> unions, that's already a "language extension". (and so not be considered as 
>> FAM by `-fstrict-flex-arrays=3`)
>
> To be super pedantic, C99 implies a FAM in a union is illegal. 6.7.2.1.16 
> says "As a special case, the last element of a structure with more than one 
> named member may have an incomplete array type; this is called a flexible 
> array member." The implication is that such a state ("more than one named 
> member") isn't possible in a union.

The C standard says "structure" when it means `struct` and "union" when it 
means `union`, and "structure and/or union" when it means both/either, so this 
constraint is not implied -- it's explicitly stated. A FAM in a union is a 
constraint violation per 6.7.2.1. (Note: C compilers are not consistent about 
getting this constraint correct. Clang and GCC both get it right, ICC, MSVC, 
SDCC all get it wrong.)

> But in real-world usage, this definition isn't useful and flies in the face 
> of actual (fake) FAM usage. Having fake FAMs in unions is _very_ common in 
> the Linux kernel, and they even appear alone in structs. There is no 
> pragmatic reason for the C99 limitation, and it's needlessly enforced only 
> for "real" FAMs. But this is a separate issue we can solve separately.

A *fake* FAM is undefined behavior and thus fair game for implementations to 
define the behavior of in whatever way we'd like, so long as developers know 
it's not portable and it may explode on other compilers. A real FAM requires at 
least a diagnostic, but we're free to make it a pedantic warning diagnostic if 
we want. If we feel strongly about the limitation being needless, we could 
propose to standardize support for it if implementations that accept a real FAM 
in a union basically all agree on the behavior. (Agreed that this is a separate 
issue from this patch though.)

One thing I would appreciate is, once we're getting close to done with the work 
around flexible arrays, is to explicitly document our implementation-defined 
behaviors around flexible arrays in 
https://clang.llvm.org/docs/LanguageExtensions.html. Right now, what is and 
isn't a flexible array to Clang is really complex and not having the rules 
written down anywhere is not helpful to users. These cleanup efforts are 
fantastic and seem like a good opportunity for us to rectify the lack of docs.




Comment at: clang/docs/ReleaseNotes.rst:386
+- Added a new level to the ``-fstrict-flex-arrays=`` flag. The new level ``3``
+  recoginizes only "incomplete" arrays as flexible array members.
+

I think another way to phrase this is that level `3` only supports flexible 
array members as the feature is defined by the C standard, aka, this is 
standards-conforming mode. WDYT?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134902

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


[PATCH] D135340: [PGO] Make emitted symbols hidden

2022-10-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

This is still breaking `   Profile-x86_64 :: instrprof-darwin-dead-strip.c` on 
mac. I'm reverting this again for now.


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

https://reviews.llvm.org/D135340

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


[PATCH] D136671: [analyzer] Fix crash for array-delete of UnknownVal values.

2022-10-25 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D136671#3882166 , @isuckatcs wrote:

>> This eliminate the crash in `getDynamicElementCount` on that region
>
> I think that if the crash comes from `getDynamicElementCount`, we should 
> address it there too, so 
> when the function is called elsewhere under the same circumstances it won't 
> crash again.
>
> What do you think?

For me, it makes sense that `getDynamicElementCount()` is not intended to be 
called on a `null` MemRegion. So, from my point of view, the bug is at some 
callsite.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136671

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


[clang] 76745d2 - Revert "[PGO] Make emitted symbols hidden"

2022-10-25 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-10-25T08:54:47-04:00
New Revision: 76745d2b58b5931a2a591f3d876f08ddce7fec15

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

LOG: Revert "[PGO] Make emitted symbols hidden"

This reverts commit 04877284b4592e9286cab43467662c1b4ff81861.
Looks like this is still breaking the test
Profile-x86_64 :: instrprof-darwin-dead-strip.c
(see comment on https://reviews.llvm.org/D135340).

Added: 


Modified: 
clang/lib/Driver/ToolChains/Darwin.cpp
clang/test/Driver/darwin-ld.c
compiler-rt/lib/profile/InstrProfilingNameVar.c
compiler-rt/lib/profile/InstrProfilingVersionVar.c
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Transforms/PGOProfile/branch1.ll
llvm/test/Transforms/PGOProfile/branch2.ll
llvm/test/Transforms/PGOProfile/comdat_internal.ll
llvm/test/Transforms/PGOProfile/criticaledge.ll
llvm/test/Transforms/PGOProfile/instr_entry_bb.ll
llvm/test/Transforms/PGOProfile/landingpad.ll
llvm/test/Transforms/PGOProfile/loop1.ll
llvm/test/Transforms/PGOProfile/loop2.ll
llvm/test/Transforms/PGOProfile/lto_cspgo_gen.ll
llvm/test/Transforms/PGOProfile/single_bb.ll
llvm/test/Transforms/PGOProfile/switch.ll
llvm/test/Transforms/PGOProfile/thinlto_cspgo_gen.ll

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 39f459e9ef652..1a02d3cfbac7c 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1353,11 +1353,16 @@ void Darwin::addProfileRTLibs(const ArgList &Args,
   // If we have a symbol export directive and we're linking in the profile
   // runtime, automatically export symbols necessary to implement some of the
   // runtime's functionality.
-  if (hasExportSymbolDirective(Args) && ForGCOV) {
-addExportedSymbol(CmdArgs, "___gcov_dump");
-addExportedSymbol(CmdArgs, "___gcov_reset");
-addExportedSymbol(CmdArgs, "_writeout_fn_list");
-addExportedSymbol(CmdArgs, "_reset_fn_list");
+  if (hasExportSymbolDirective(Args)) {
+if (ForGCOV) {
+  addExportedSymbol(CmdArgs, "___gcov_dump");
+  addExportedSymbol(CmdArgs, "___gcov_reset");
+  addExportedSymbol(CmdArgs, "_writeout_fn_list");
+  addExportedSymbol(CmdArgs, "_reset_fn_list");
+} else {
+  addExportedSymbol(CmdArgs, "___llvm_profile_filename");
+  addExportedSymbol(CmdArgs, "___llvm_profile_raw_version");
+}
   }
 
   // Align __llvm_prf_{cnts,data} sections to the maximum expected page

diff  --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c
index 13ec69b2db1ab..5be119a545a63 100644
--- a/clang/test/Driver/darwin-ld.c
+++ b/clang/test/Driver/darwin-ld.c
@@ -338,6 +338,18 @@
 // RUN: FileCheck -check-prefix=PROFILE_SECTALIGN %s < %t.log
 // PROFILE_SECTALIGN: "-sectalign" "__DATA" "__llvm_prf_cnts" "0x4000" 
"-sectalign" "__DATA" "__llvm_prf_data" "0x4000"
 
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate 
-exported_symbols_list /dev/null -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate 
-Wl,-exported_symbols_list,/dev/null -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate 
-Wl,-exported_symbol,foo -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Xlinker 
-exported_symbol -Xlinker foo -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate -Xlinker 
-exported_symbols_list -Xlinker /dev/null -### %t.o 2> %t.log
+// RUN: FileCheck -check-prefix=PROFILE_EXPORT %s < %t.log
+// PROFILE_EXPORT: "-exported_symbol" "___llvm_profile_filename" 
"-exported_symbol" "___llvm_profile_raw_version"
+//
 // RUN: %clang -target x86_64-apple-darwin12 -fprofile-instr-generate 
--coverage -### %t.o 2> %t.log
 // RUN: FileCheck -check-prefix=NO_PROFILE_EXPORT %s < %t.log
 // NO_PROFILE_EXPORT-NOT: "-exported_symbol"

diff  --git a/compiler-rt/lib/profile/InstrProfilingNameVar.c 
b/compiler-rt/lib/profile/InstrProfilingNameVar.c
index 407272806ba3c..2d67a55b985cf 100644
--- a/compiler-rt/lib/profile/InstrProfilingNameVar.c
+++ b/compiler-rt/lib/profile/InstrProfilingNameVar.c
@@ -14,4 +14,4 @@
  * user has not specified one. Set this up by moving the runtime's copy of this
  * symbol to an object file within the archive.
  */
-COMPILER_RT_WEAK COMPILER_RT_VISIBILITY char INSTR_PROF_PROFILE_NAME_VAR[1] = 
{0};
+COMPILER_RT_

[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D133874#3882101 , @mizvekov wrote:

> @erichkeane since you reviewed and approved 5 patches that depend on this 
> one, can you also have a look at this please?
>
> Thanks!

Thanks for the ping, I missed this is in the massive influx of emails I got!  
I'll take a look when i get a chance.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 470457.
hokein marked 4 inline comments as done.
hokein added a comment.

address comments and add a stress test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

Files:
  clang/lib/Lex/TokenLexer.cpp
  clang/test/Lexer/Inputs/inc3.h
  clang/test/Lexer/update_consecutive_macro_address_space.c

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-25 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

> This is a subtle change that needs careful review, and honestly should have a 
> test.

I agree, and thanks for the nice review comments!

I'd like to add a unittest, but I don't see a straight way (I manually test it 
by comparing the number of allocated SLocEntries and the used SourceLocation 
address space in `clang --print-stats` with/out this patch), some options:

1. construct a large TU that will make clang fails to compile without the 50 
trick patch;
2. create a small test, and verify the the source location is split when the 
two consecutive tokens distance > 50, and verify the number of  in `clang 
print-stats`;

1 feels better to reflect the real behavior, the only concern is that this is a 
stress test, running it is expensive (we also have a similar 
`SourceLocationsOverlow.c`, I guess it is ok to add it).




Comment at: clang/lib/Lex/TokenLexer.cpp:1010
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();

sammccall wrote:
> sammccall wrote:
> > This seems to be missing the same-sloc-address-space check: it can create a 
> > single file ID spanning a local and loaded sloc entry, which will be 
> > corrupted by saving+loading
> > 
> (getOffset() would be much clearly correct than getRawEncoding())
> missing the same-sloc-address-space check

oops, good spot. Indeed this is another behavior change in the 
previous-rewriting patch :( -- the original behavior was that if two 
consecutive tokens are not in the same address space, it split to two expansion 
SLocEntries.

Fixed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


[PATCH] D134445: [PR57881][OpenCL] Fix incorrect diagnostics with templated types in kernel arguments

2022-10-25 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia updated this revision to Diff 470458.
Anastasia added a comment.

Addressed review comments


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

https://reviews.llvm.org/D134445

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/SemaOpenCLCXX/invalid-kernel.clcpp


Index: clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
===
--- clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
+++ clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
@@ -93,3 +93,24 @@
 #ifndef UNSAFEKERNELPARAMETER
 //expected-error@-2{{'__global Trivial &__private' cannot be used as the type 
of a kernel parameter}}
 #endif
+
+// Nested types and templates
+struct Outer {
+  struct Inner{
+int i;
+  };
+};
+template
+struct OuterTempl {
+  struct Inner{
+int i;
+  };
+};
+// FIXME: (PR58590) Use of template parameter dependent types doesn't
+// work yet due to lazy instantiation of reference types.
+//template
+//struct Templ {
+//T i;
+//};
+
+extern kernel void nested(constant Outer::Inner& r1, constant 
OuterTempl::Inner& r2/*, constant Templ& r3*/);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9245,10 +9245,23 @@
 // reference if an implementation supports them in kernel parameters.
 if (S.getLangOpts().OpenCLCPlusPlus &&
 !S.getOpenCLOptions().isAvailableOption(
-"__cl_clang_non_portable_kernel_param_types", S.getLangOpts()) &&
-!PointeeType->isAtomicType() && !PointeeType->isVoidType() &&
-!PointeeType->isStandardLayoutType())
+"__cl_clang_non_portable_kernel_param_types", S.getLangOpts())) {
+ auto CXXRec = PointeeType.getCanonicalType()->getAsCXXRecordDecl();
+ bool IsStandardLayoutType = true;
+ if (CXXRec) {
+   // If template type is non-ODR used its definition is only available
+   // in the template definition not its instantiation.
+   // FIXME: This logic doesn't work for types that depend on template
+   // parameter (PR58590).
+   if (!CXXRec->hasDefinition())
+ CXXRec = CXXRec->getTemplateInstantiationPattern();
+   if (!CXXRec || !CXXRec->hasDefinition() || !CXXRec->isStandardLayout())
+ IsStandardLayoutType = false;
+ }
+ if (!PointeeType->isAtomicType() && !PointeeType->isVoidType() &&
+!IsStandardLayoutType)
   return InvalidKernelParam;
+}
 
 return PtrKernelParam;
   }


Index: clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
===
--- clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
+++ clang/test/SemaOpenCLCXX/invalid-kernel.clcpp
@@ -93,3 +93,24 @@
 #ifndef UNSAFEKERNELPARAMETER
 //expected-error@-2{{'__global Trivial &__private' cannot be used as the type of a kernel parameter}}
 #endif
+
+// Nested types and templates
+struct Outer {
+  struct Inner{
+int i;
+  };
+};
+template
+struct OuterTempl {
+  struct Inner{
+int i;
+  };
+};
+// FIXME: (PR58590) Use of template parameter dependent types doesn't
+// work yet due to lazy instantiation of reference types.
+//template
+//struct Templ {
+//T i;
+//};
+
+extern kernel void nested(constant Outer::Inner& r1, constant OuterTempl::Inner& r2/*, constant Templ& r3*/);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -9245,10 +9245,23 @@
 // reference if an implementation supports them in kernel parameters.
 if (S.getLangOpts().OpenCLCPlusPlus &&
 !S.getOpenCLOptions().isAvailableOption(
-"__cl_clang_non_portable_kernel_param_types", S.getLangOpts()) &&
-!PointeeType->isAtomicType() && !PointeeType->isVoidType() &&
-!PointeeType->isStandardLayoutType())
+"__cl_clang_non_portable_kernel_param_types", S.getLangOpts())) {
+ auto CXXRec = PointeeType.getCanonicalType()->getAsCXXRecordDecl();
+ bool IsStandardLayoutType = true;
+ if (CXXRec) {
+   // If template type is non-ODR used its definition is only available
+   // in the template definition not its instantiation.
+   // FIXME: This logic doesn't work for types that depend on template
+   // parameter (PR58590).
+   if (!CXXRec->hasDefinition())
+ CXXRec = CXXRec->getTemplateInstantiationPattern();
+   if (!CXXRec || !CXXRec->hasDefinition() || !CXXRec->isStandardLayout())
+ IsStandardLayoutType = false;
+ }
+ if (!PointeeType->isAtomicType() && !PointeeType->isVoidType() &&
+!IsStandardLayoutType)
   return InvalidKernelParam;
+}
 
 return PtrKernelParam;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

The test changes are a little bizarre, are there any better tests you can write 
that shows this behavior?

Also, at the 'end' of this patch set, we should make sure we have a detailed 
release note.




Comment at: clang/include/clang/Sema/Sema.h:8285
+   TemplateArgument &SugaredConverted,
+   TemplateArgument &CanonicalConverted,
+   CheckTemplateArgumentKind CTAK);

I find myself wondering if we should just be passing around the 'Sugared' 
version, and canonicalizing when we need it?  Is there a good reason not to?



Comment at: clang/include/clang/Sema/TemplateDeduction.h:94
 
-  /// Take ownership of the deduced template argument list.
-  TemplateArgumentList *take() {
-TemplateArgumentList *Result = Deduced;
-Deduced = nullptr;
+  /// Take ownership of the deduced template argument lists.
+  TemplateArgumentList *takeSugared() {

Not your fault at all but that seems to be about the absolute opposite of 
what it looks like this function is doing...



Comment at: clang/lib/Sema/SemaTemplate.cpp:4876
   Context, NamedConcept->getDeclContext(), NamedConcept->getLocation(),
-  Converted);
+  CanonicalConverted);
   ConstraintSatisfaction Satisfaction;

At one point I wonder if there is value to storing the sugared version here 
instead.  We currently just create these every time we need them, so the 
side-effect would be possibly a nicer looking AST dump.  BUT we don't really 
canonizalize these Specialization Decls/Specialization Exprs.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[clang] af1bb28 - [AArch64][ARM] Alter v8.3a complex neon intrinsics to be target-based, not preprocessor based

2022-10-25 Thread David Green via cfe-commits

Author: David Green
Date: 2022-10-25T14:35:11+01:00
New Revision: af1bb287b4de3c5a5d82679ceb001c7d70f09c82

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

LOG: [AArch64][ARM] Alter v8.3a complex neon intrinsics to be target-based, not 
preprocessor based

This alters the 8.3 complex intrinsics to be target-gated, as opposed to
hidden behind preprocessor macros. This is the last of arm_neon.h, and
follows the same formula as before.

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

Added: 


Modified: 
clang/include/clang/Basic/arm_neon.td
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/Sema/aarch64-neon-target.c
clang/test/Sema/arm-neon-target.c

Removed: 




diff  --git a/clang/include/clang/Basic/arm_neon.td 
b/clang/include/clang/Basic/arm_neon.td
index d6b6c429a21b2..4288e9eb69d07 100644
--- a/clang/include/clang/Basic/arm_neon.td
+++ b/clang/include/clang/Basic/arm_neon.td
@@ -1964,7 +1964,7 @@ multiclass VCMLA_ROTS {
 }
 
 // v8.3-A Vector complex addition intrinsics
-let ArchGuard = "defined(__ARM_FEATURE_COMPLEX)", TargetGuard = "fullfp16" in {
+let TargetGuard = "v8.3a,fullfp16" in {
   def VCADD_ROT90_FP16   : SInst<"vcadd_rot90", "...", "h">;
   def VCADD_ROT270_FP16  : SInst<"vcadd_rot270", "...", "h">;
   def VCADDQ_ROT90_FP16  : SInst<"vcaddq_rot90", "QQQ", "h">;
@@ -1972,7 +1972,7 @@ let ArchGuard = "defined(__ARM_FEATURE_COMPLEX)", 
TargetGuard = "fullfp16" in {
 
   defm VCMLA_FP16  : VCMLA_ROTS<"h", "uint32x2_t", "uint32x4_t">;
 }
-let ArchGuard = "defined(__ARM_FEATURE_COMPLEX)" in {
+let TargetGuard = "v8.3a" in {
   def VCADD_ROT90   : SInst<"vcadd_rot90", "...", "f">;
   def VCADD_ROT270  : SInst<"vcadd_rot270", "...", "f">;
   def VCADDQ_ROT90  : SInst<"vcaddq_rot90", "QQQ", "f">;
@@ -1980,7 +1980,7 @@ let ArchGuard = "defined(__ARM_FEATURE_COMPLEX)" in {
 
   defm VCMLA_F32: VCMLA_ROTS<"f", "uint64x1_t", "uint64x2_t">;
 }
-let ArchGuard = "defined(__ARM_FEATURE_COMPLEX) && defined(__aarch64__)" in {
+let ArchGuard = "defined(__aarch64__)", TargetGuard = "v8.3a" in {
   def VCADDQ_ROT90_FP64  : SInst<"vcaddq_rot90", "QQQ", "d">;
   def VCADDQ_ROT270_FP64 : SInst<"vcaddq_rot270", "QQQ", "d">;
 

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index f67798000444c..0ca664bfed9e9 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5667,10 +5667,16 @@ static const ARMVectorIntrinsicInfo ARMSIMDIntrinsicMap 
[] = {
   NEONMAP1(vbfmmlaq_f32, arm_neon_bfmmla, 0),
   NEONMAP1(vbsl_v, arm_neon_vbsl, AddRetType),
   NEONMAP1(vbslq_v, arm_neon_vbsl, AddRetType),
-  NEONMAP1(vcadd_rot270_v, arm_neon_vcadd_rot270, Add1ArgType),
-  NEONMAP1(vcadd_rot90_v, arm_neon_vcadd_rot90, Add1ArgType),
-  NEONMAP1(vcaddq_rot270_v, arm_neon_vcadd_rot270, Add1ArgType),
-  NEONMAP1(vcaddq_rot90_v, arm_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcadd_rot270_f16, arm_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcadd_rot270_f32, arm_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcadd_rot90_f16, arm_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcadd_rot90_f32, arm_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcaddq_rot270_f16, arm_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcaddq_rot270_f32, arm_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcaddq_rot270_f64, arm_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcaddq_rot90_f16, arm_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcaddq_rot90_f32, arm_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcaddq_rot90_f64, arm_neon_vcadd_rot90, Add1ArgType),
   NEONMAP1(vcage_v, arm_neon_vacge, 0),
   NEONMAP1(vcageq_v, arm_neon_vacge, 0),
   NEONMAP1(vcagt_v, arm_neon_vacgt, 0),
@@ -5985,10 +5991,16 @@ static const ARMVectorIntrinsicInfo 
AArch64SIMDIntrinsicMap[] = {
   NEONMAP1(vbfmlalbq_f32, aarch64_neon_bfmlalb, 0),
   NEONMAP1(vbfmlaltq_f32, aarch64_neon_bfmlalt, 0),
   NEONMAP1(vbfmmlaq_f32, aarch64_neon_bfmmla, 0),
-  NEONMAP1(vcadd_rot270_v, aarch64_neon_vcadd_rot270, Add1ArgType),
-  NEONMAP1(vcadd_rot90_v, aarch64_neon_vcadd_rot90, Add1ArgType),
-  NEONMAP1(vcaddq_rot270_v, aarch64_neon_vcadd_rot270, Add1ArgType),
-  NEONMAP1(vcaddq_rot90_v, aarch64_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcadd_rot270_f16, aarch64_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcadd_rot270_f32, aarch64_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcadd_rot90_f16, aarch64_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcadd_rot90_f32, aarch64_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcaddq_rot270_f16, aarch64_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcaddq_rot270_f32, aarch64_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcaddq_rot270_f64, aarch64_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcaddq_rot90_f16, aarch64_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcaddq_

[PATCH] D135647: [AArch64][ARM] Alter v8.3a complex neon intrinsics to be target-based, not preprocessor based

2022-10-25 Thread Dave Green 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 rGaf1bb287b4de: [AArch64][ARM] Alter v8.3a complex neon 
intrinsics to be target-based, not… (authored by dmgreen).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135647

Files:
  clang/include/clang/Basic/arm_neon.td
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/Sema/aarch64-neon-target.c
  clang/test/Sema/arm-neon-target.c

Index: clang/test/Sema/arm-neon-target.c
===
--- clang/test/Sema/arm-neon-target.c
+++ clang/test/Sema/arm-neon-target.c
@@ -38,6 +38,12 @@
   vqrdmlahq_s32(v, v, v);
 }
 
+__attribute__((target("v8.3a,fullfp16")))
+void test_v83(float32x4_t v4f32, float16x4_t v4f16) {
+  vcaddq_rot90_f32(v4f32, v4f32);
+  vcmla_rot90_f16(v4f16, v4f16, v4f16);
+}
+
 void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, bfloat16x4_t v4bf16, __bf16 bf16) {
   // dotprod
   vdot_u32(v2i32, v8i8, v8i8); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
@@ -57,4 +63,7 @@
   vcvt_bf16_f32(v4f32); // expected-error {{always_inline function 'vcvt_bf16_f32' requires target feature 'bf16'}}
   // v8.1 - qrdmla
   vqrdmlahq_s32(v4i32, v4i32, v4i32); // expected-error {{always_inline function 'vqrdmlahq_s32' requires target feature 'v8.1a'}}
+  // 8.3 - complex
+  vcaddq_rot90_f32(v4f32, v4f32); // expected-error {{always_inline function 'vcaddq_rot90_f32' requires target feature 'v8.3a'}}
+  vcmla_rot90_f16(v4f16, v4f16, v4f16); // expected-error {{always_inline function 'vcmla_rot90_f16' requires target feature 'v8.3a'}}
 }
Index: clang/test/Sema/aarch64-neon-target.c
===
--- clang/test/Sema/aarch64-neon-target.c
+++ clang/test/Sema/aarch64-neon-target.c
@@ -48,12 +48,19 @@
   vqrdmlahh_s16(1, 1, 1);
 }
 
+__attribute__((target("arch=armv8.3-a+fp16")))
+void test_v83(float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64) {
+  vcaddq_rot90_f32(v4f32, v4f32);
+  vcmla_rot90_f16(v4f16, v4f16, v4f16);
+  vcmlaq_rot270_laneq_f64(v2f64, v2f64, v2f64, 1);
+}
+
 __attribute__((target("arch=armv8.5-a")))
 void test_v85(float32x4_t v4f32) {
   vrnd32xq_f32(v4f32);
 }
 
-void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, bfloat16x4_t v4bf16, __bf16 bf16) {
+void undefined(uint32x2_t v2i32, uint32x4_t v4i32, uint16x8_t v8i16, uint8x16_t v16i8, uint8x8_t v8i8, float32x2_t v2f32, float32x4_t v4f32, float16x4_t v4f16, float64x2_t v2f64, bfloat16x4_t v4bf16, __bf16 bf16) {
   // dotprod
   vdot_u32(v2i32, v8i8, v8i8); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
   vdot_laneq_u32(v2i32, v8i8, v16i8, 1); // expected-error {{always_inline function 'vdot_u32' requires target feature 'dotprod'}}
@@ -79,6 +86,10 @@
   vqrdmlahq_s32(v4i32, v4i32, v4i32); // expected-error {{always_inline function 'vqrdmlahq_s32' requires target feature 'v8.1a'}}
   vqrdmlah_laneq_s32(v2i32, v2i32, v4i32, 1); // expected-error {{always_inline function 'vqrdmlah_s32' requires target feature 'v8.1a'}}
   vqrdmlahh_s16(1, 1, 1); // expected-error {{always_inline function 'vqrdmlahh_s16' requires target feature 'v8.1a'}}
+  // 8.3 - complex
+  vcaddq_rot90_f32(v4f32, v4f32); // expected-error {{always_inline function 'vcaddq_rot90_f32' requires target feature 'v8.3a'}}
+  vcmla_rot90_f16(v4f16, v4f16, v4f16); // expected-error {{always_inline function 'vcmla_rot90_f16' requires target feature 'v8.3a'}}
+  vcmlaq_rot270_laneq_f64(v2f64, v2f64, v2f64, 1); // expected-error {{always_inline function 'vcmlaq_rot270_f64' requires target feature 'v8.3a'}}
   // 8.5 - frint
   vrnd32xq_f32(v4f32); // expected-error {{always_inline function 'vrnd32xq_f32' requires target feature 'v8.5a'}}
 }
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -5667,10 +5667,16 @@
   NEONMAP1(vbfmmlaq_f32, arm_neon_bfmmla, 0),
   NEONMAP1(vbsl_v, arm_neon_vbsl, AddRetType),
   NEONMAP1(vbslq_v, arm_neon_vbsl, AddRetType),
-  NEONMAP1(vcadd_rot270_v, arm_neon_vcadd_rot270, Add1ArgType),
-  NEONMAP1(vcadd_rot90_v, arm_neon_vcadd_rot90, Add1ArgType),
-  NEONMAP1(vcaddq_rot270_v, arm_neon_vcadd_rot270, Add1ArgType),
-  NEONMAP1(vcaddq_rot90_v, arm_neon_vcadd_rot90, Add1ArgType),
+  NEONMAP1(vcadd_rot270_f16, arm_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcadd_rot270_f32, arm_neon_vcadd_rot270, Add1ArgType),
+  NEONMAP1(vcadd_rot90_f1

[PATCH] D136671: [analyzer] Fix crash for array-delete of UnknownVal values.

2022-10-25 Thread Domján Dániel via Phabricator via cfe-commits
isuckatcs added a comment.

> For me, it makes sense that getDynamicElementCount() is not intended to be 
> called on a null MemRegion.

It would still be helpful to have an assertion on that inside 
`getDynamicElementCount()`, so the caller will know it right away.

What I want to say is that it seems there are multiple error prone snippets 
involved in this crash and I think we should address all 
of them, because some might cause another crash somewhere else.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136671

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


[PATCH] D136684: [clang][ASTImporter] Remove use of ParentMapContext.

2022-10-25 Thread Balázs Kéri via Phabricator via cfe-commits
balazske created this revision.
Herald added subscribers: steakhal, martong, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Function 'isAncestorDeclContextOf' was using 'ParentMapContext' for
looking up parent of statement nodes. There may be cases (bugs?) with
ParentMapContext when parents of specific statements are not found.
This leads to 'ASTImporter' infinite import loops when function
'hasAutoReturnTypeDeclaredInside' returns false incorrectly.
A real case was found but could not be reproduced with test code.
Use of 'ParentMapContext' is now removed and changed to a more safe
(currently) method by searching for declarations in statements
and find parent of these declarations. The new code was tested on
a number of projects and no related crash was found.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136684

Files:
  clang/lib/AST/ASTImporter.cpp


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -34,7 +34,6 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
-#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -3237,16 +3236,19 @@
   return false;
 }
 
-// Returns true if the statement S has a parent declaration that has a
-// DeclContext that is inside (or equal to) DC. In a specific use case if DC is
-// a FunctionDecl, check if statement S resides in the body of the function.
+// Check if there is a declaration that has 'DC' as parent context and is
+// referenced from statement 'S' or one of its children. The search is done in
+// BFS order through children of 'S'.
 static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
-  ParentMapContext &ParentC = DC->getParentASTContext().getParentMapContext();
-  DynTypedNodeList Parents = ParentC.getParents(*S);
-  while (!Parents.empty()) {
-if (const Decl *PD = Parents.begin()->get())
-  return isAncestorDeclContextOf(DC, PD);
-Parents = ParentC.getParents(*Parents.begin());
+  SmallVector ToProcess;
+  ToProcess.push_back(S);
+  while (!ToProcess.empty()) {
+const Stmt *CurrentS = ToProcess.pop_back_val();
+ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
+if (const auto *DeclRef = dyn_cast(CurrentS))
+  if (const Decl *D = DeclRef->getDecl())
+if (isAncestorDeclContextOf(DC, D))
+  return true;
   }
   return false;
 }


Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -34,7 +34,6 @@
 #include "clang/AST/LambdaCapture.h"
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
-#include "clang/AST/ParentMapContext.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/StmtObjC.h"
@@ -3237,16 +3236,19 @@
   return false;
 }
 
-// Returns true if the statement S has a parent declaration that has a
-// DeclContext that is inside (or equal to) DC. In a specific use case if DC is
-// a FunctionDecl, check if statement S resides in the body of the function.
+// Check if there is a declaration that has 'DC' as parent context and is
+// referenced from statement 'S' or one of its children. The search is done in
+// BFS order through children of 'S'.
 static bool isAncestorDeclContextOf(const DeclContext *DC, const Stmt *S) {
-  ParentMapContext &ParentC = DC->getParentASTContext().getParentMapContext();
-  DynTypedNodeList Parents = ParentC.getParents(*S);
-  while (!Parents.empty()) {
-if (const Decl *PD = Parents.begin()->get())
-  return isAncestorDeclContextOf(DC, PD);
-Parents = ParentC.getParents(*Parents.begin());
+  SmallVector ToProcess;
+  ToProcess.push_back(S);
+  while (!ToProcess.empty()) {
+const Stmt *CurrentS = ToProcess.pop_back_val();
+ToProcess.append(CurrentS->child_begin(), CurrentS->child_end());
+if (const auto *DeclRef = dyn_cast(CurrentS))
+  if (const Decl *D = DeclRef->getDecl())
+if (isAncestorDeclContextOf(DC, D))
+  return true;
   }
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D135375: [analyzer] Initialize regions returned by CXXNew to undefined

2022-10-25 Thread Kristóf Umann via Phabricator via cfe-commits
Szelethus added a comment.

Seems like the issues mentioned above are real, but orthogonal to this patch. 
Would it be okay to address them in followup patches? @martong @NoQ




Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp:927
 SVal RetVal = State->getSVal(CNE, LCtx);
+State = State->bindDefaultInitial(RetVal, UndefinedVal{}, LCtx);
 

steakhal wrote:
> Yeey, finally we will have this :D
> 
> I wonder if we could query from the `ASTContext` if we have a trivially 
> constructible class typeor something as a first approximation.
And a result skip the rest of this function?



Comment at: clang/test/Analysis/NewDelete-checker-test.cpp:388-392
+  ~DerefClass() {
+int i = 0;
+x = &i;
+*x = 1;
+  }

steakhal wrote:
> This change seems unrelated.
> Could you elaborate on that?
The test case in its original version would have emitted an uninitialized use 
report, which is fine, but the intention is to test double deletes, not 
uninitialized use, hence the seemingly unrelated change.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135375

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


[PATCH] D135375: [analyzer] Initialize regions returned by CXXNew to undefined

2022-10-25 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.

In D135375#3882491 , @Szelethus wrote:

> Seems like the issues mentioned above are real, but orthogonal to this patch. 
> Would it be okay to address them in followup patches? @martong @NoQ

I am okay with it. Thanks!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135375

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


[PATCH] D131915: [MLIR][OpenMP] Added target data, exit data, and enter data operation definition for MLIR.

2022-10-25 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis requested changes to this revision.
TIFitis added inline comments.
This revision now requires changes to proceed.



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:817-818
+ Variadic:$use_device_addr,
+ MapTypeModifierAttr:$map_type_modifier_val,
+ MapTypeAttr:$map_type_val,
+ Variadic:$map_operands);

I think these should be Variadic to allow multiple map clauses.



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:871-872
+ UnitAttr:$nowait,
+ MapTypeModifierAttr:$map_type_modifier_val,
+ MapTypeAttr:$map_type_val,
+ Variadic:$map_operands);

I think these should be Variadic to allow multiple map clauses.



Comment at: mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td:922-923
+ UnitAttr:$nowait,
+ MapTypeModifierAttr:$map_type_modifier_val,
+ MapTypeAttr:$map_type_val,
+ Variadic:$map_operands);

I think these should be Variadic to allow multiple map clauses.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131915

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


[PATCH] D136671: [analyzer] Fix crash for array-delete of UnknownVal values.

2022-10-25 Thread Tomasz Kamiński via Phabricator via cfe-commits
tomasz-kaminski-sonarsource updated this revision to Diff 470489.
tomasz-kaminski-sonarsource added a comment.

Added assertion.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136671

Files:
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/test/Analysis/dtor-array.cpp

Index: clang/test/Analysis/dtor-array.cpp
===
--- clang/test/Analysis/dtor-array.cpp
+++ clang/test/Analysis/dtor-array.cpp
@@ -344,3 +344,36 @@
   // region to a conjured symbol.
   clang_analyzer_eval(InlineDtor::dtorCalled == 0); // expected-warning {{TRUE}} expected-warning {{FALSE}}
 }
+
+namespace crash6 {
+
+struct NonTrivialItem {
+  ~NonTrivialItem();
+};
+
+struct WeirdVec {
+  void clear() {
+delete[] data;
+size = 0;
+  }
+  NonTrivialItem *data;
+  unsigned size;
+};
+
+void top(int j) {
+  WeirdVec *p = new WeirdVec;
+
+  p[j].size = 0;
+  delete[] p->data; // no-crash
+}
+
+template 
+T make_unknown() {
+  return reinterpret_cast(static_cast(0.404));
+}
+
+void directUnknownSymbol() {
+  delete[] make_unknown(); // no-crash
+}
+
+}
Index: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -1241,6 +1241,7 @@
 const QualType &ElementTy,
 const LocationContext *LCtx,
 SVal *ElementCountVal) {
+  assert(Region != nullptr && "Null-regions passed to prepareStateForArrayDestruction.");
 
   QualType Ty = ElementTy.getDesugaredType(getContext());
   while (const auto *NTy = dyn_cast(Ty))
@@ -1420,31 +1421,32 @@
   const MemRegion *ArgR = ArgVal.getAsRegion();
 
   if (DE->isArrayForm()) {
-SVal ElementCount;
-std::tie(State, Idx) =
-prepareStateForArrayDestruction(State, ArgR, DTy, LCtx, &ElementCount);
-
 CallOpts.IsArrayCtorOrDtor = true;
 // Yes, it may even be a multi-dimensional array.
 while (const auto *AT = getContext().getAsArrayType(DTy))
   DTy = AT->getElementType();
 
-// If we're about to destruct a 0 length array, don't run any of the
-// destructors.
-if (ElementCount.isConstant() &&
-ElementCount.getAsInteger()->getLimitedValue() == 0) {
+if (ArgR) {
+  SVal ElementCount;
+  std::tie(State, Idx) = prepareStateForArrayDestruction(
+  State, ArgR, DTy, LCtx, &ElementCount);
 
-  static SimpleProgramPointTag PT(
-  "ExprEngine", "Skipping 0 length array delete destruction");
-  PostImplicitCall PP(getDtorDecl(DTy), DE->getBeginLoc(), LCtx, &PT);
-  NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
-  Bldr.generateNode(PP, Pred->getState(), Pred);
-  return;
-}
+  // If we're about to destruct a 0 length array, don't run any of the
+  // destructors.
+  if (ElementCount.isConstant() &&
+  ElementCount.getAsInteger()->getLimitedValue() == 0) {
+
+static SimpleProgramPointTag PT(
+"ExprEngine", "Skipping 0 length array delete destruction");
+PostImplicitCall PP(getDtorDecl(DTy), DE->getBeginLoc(), LCtx, &PT);
+NodeBuilder Bldr(Pred, Dst, *currBldrCtx);
+Bldr.generateNode(PP, Pred->getState(), Pred);
+return;
+  }
 
-if (ArgR)
   ArgR = State->getLValue(DTy, svalBuilder.makeArrayIndex(Idx), ArgVal)
  .getAsRegion();
+}
   }
 
   NodeBuilder Bldr(Pred, Dst, getBuilderContext());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D136080: [flang] Add -ffp-contract option processing

2022-10-25 Thread Tom Eccles via Phabricator via cfe-commits
tblah updated this revision to Diff 470496.

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

https://reviews.llvm.org/D136080

Files:
  clang/include/clang/Basic/DiagnosticDriverKinds.td
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/Flang.cpp
  flang/include/flang/Frontend/CompilerInvocation.h
  flang/include/flang/Frontend/LangOptions.def
  flang/include/flang/Frontend/LangOptions.h
  flang/lib/Frontend/CMakeLists.txt
  flang/lib/Frontend/CompilerInvocation.cpp
  flang/lib/Frontend/LangOptions.cpp
  flang/test/Driver/driver-help-hidden.f90
  flang/test/Driver/driver-help.f90
  flang/test/Driver/flang_f_opts.f90
  flang/test/Driver/flang_fp_opts.f90
  flang/test/Driver/frontend-forwarding.f90

Index: flang/test/Driver/frontend-forwarding.f90
===
--- flang/test/Driver/frontend-forwarding.f90
+++ flang/test/Driver/frontend-forwarding.f90
@@ -8,6 +8,7 @@
 ! RUN: -fdefault-real-8 \
 ! RUN: -flarge-sizes \
 ! RUN: -fconvert=little-endian \
+! RUN: -ffp-contract=fast \
 ! RUN: -mllvm -print-before-all\
 ! RUN: -P \
 ! RUN:   | FileCheck %s
@@ -18,5 +19,6 @@
 ! CHECK: "-fdefault-integer-8"
 ! CHECK: "-fdefault-real-8"
 ! CHECK: "-flarge-sizes"
+! CHECK: "-ffp-contract=fast"
 ! CHECK: "-fconvert=little-endian"
 ! CHECK:  "-mllvm" "-print-before-all"
Index: flang/test/Driver/flang_fp_opts.f90
===
--- /dev/null
+++ flang/test/Driver/flang_fp_opts.f90
@@ -0,0 +1,4 @@
+! Test for handling of floating point options within the frontend driver
+
+! RUN: %flang_fc1 -ffp-contract=fast %s 2>&1 | FileCheck %s
+! CHECK: ffp-contract= is not currently implemented
Index: flang/test/Driver/flang_f_opts.f90
===
--- flang/test/Driver/flang_f_opts.f90
+++ flang/test/Driver/flang_f_opts.f90
@@ -1,8 +1,10 @@
 ! Test for warnings generated when parsing driver options. You can use this file for relatively small tests and to avoid creating
 ! new test files.
 
-! RUN: %flang -### -S -O4 %s 2>&1 | FileCheck %s
+! RUN: %flang -### -S -O4 -ffp-contract=on %s 2>&1 | FileCheck %s
 
+! CHECK: warning: the argument 'on' is not supported for option 'ffp-contract='. Mapping to 'ffp-contract=off'
 ! CHECK: warning: -O4 is equivalent to -O3
 ! CHECK-LABEL: "-fc1"
+! CHECK: -ffp-contract=off
 ! CHECK: -O3
Index: flang/test/Driver/driver-help.f90
===
--- flang/test/Driver/driver-help.f90
+++ flang/test/Driver/driver-help.f90
@@ -31,6 +31,7 @@
 ! HELP-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-NEXT: -ffixed-line-length=
 ! HELP-NEXT: Use  as character line width in fixed mode
+! HELP-NEXT: -ffp-contract= Form fused FP ops (e.g. FMAs)
 ! HELP-NEXT: -ffree-formProcess source files in free form
 ! HELP-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! HELP-NEXT: -finput-charset= Specify the default character set for source files
@@ -105,6 +106,7 @@
 ! HELP-FC1-NEXT: -ffixed-form   Process source files in fixed form
 ! HELP-FC1-NEXT: -ffixed-line-length=
 ! HELP-FC1-NEXT: Use  as character line width in fixed mode
+! HELP-FC1-NEXT: -ffp-contract= Form fused FP ops (e.g. FMAs)
 ! HELP-FC1-NEXT: -ffree-formProcess source files in free form
 ! HELP-FC1-NEXT: -fget-definition   
 ! HELP-FC1-NEXT:Get the symbol definition from   
Index: flang/test/Driver/driver-help-hidden.f90
===
--- flang/test/Driver/driver-help-hidden.f90
+++ flang/test/Driver/driver-help-hidden.f90
@@ -31,6 +31,7 @@
 ! CHECK-NEXT: -ffixed-form   Process source files in fixed form
 ! CHECK-NEXT: -ffixed-line-length=
 ! CHECK-NEXT: Use  as character line width in fixed mode
+! CHECK-NEXT: -ffp-contract= Form fused FP ops (e.g. FMAs)
 ! CHECK-NEXT: -ffree-formProcess source files in free form
 ! CHECK-NEXT: -fimplicit-noneNo implicit typing allowed unless overridden by IMPLICIT statements
 ! CHECK-NEXT: -finput-charset= Specify the default character set for source files
Index: flang/lib/Frontend/LangOptions.cpp
===
--- /dev/null
+++ flang/lib/Frontend/LangOptions.cpp
@@ -0,0 +1,24 @@
+//===-- LangOptions.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
+//
+//===-

[PATCH] D136440: [clang] Do not hide base member using-decls with different template head.

2022-10-25 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 updated this revision to Diff 470505.
usaxena95 marked 3 inline comments as done.
usaxena95 added a comment.

Added more tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136440

Files:
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOverload.cpp
  clang/test/SemaTemplate/concepts-using-decl.cpp

Index: clang/test/SemaTemplate/concepts-using-decl.cpp
===
--- /dev/null
+++ clang/test/SemaTemplate/concepts-using-decl.cpp
@@ -0,0 +1,173 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+
+namespace static_methods {
+template concept False = false;
+
+struct Base {
+static void foo(auto);
+};
+struct Derived : public Base {
+using Base::foo;
+static void foo(False auto);
+};
+void func() {
+Derived::foo(42);
+}
+} // namespace static_methods
+
+namespace constrained_members {
+template  struct Opaque {};
+template  void expect(Opaque _) {}
+
+struct Empty{};
+constexpr int EmptySize = sizeof(Empty);
+
+template concept IsEmpty = sizeof(T) == EmptySize;
+
+namespace base_members_not_hidden {
+struct base {
+  template 
+  Opaque<0> foo() { return Opaque<0>(); };
+};
+
+struct bar1 : public base {
+  using base::foo;
+  template  requires IsEmpty 
+  Opaque<1> foo() { return Opaque<1>(); };
+};
+
+struct bar2 : public base {
+  using base::foo;
+  template 
+  Opaque<1> foo() { return Opaque<1>(); };
+};
+
+struct bar3 : public base {
+  using base::foo;
+  template 
+  Opaque<1> foo() requires IsEmpty { return Opaque<1>(); };
+};
+
+void func() {
+  expect<0>(base{}.foo());
+  expect<0>(base{}.foo());
+  expect<1>(bar1{}.foo());
+  expect<0>(bar1{}.foo());
+  expect<1>(bar2{}.foo());
+  expect<0>(bar2{}.foo());
+  expect<1>(bar3{}.foo());
+  expect<0>(bar3{}.foo());
+}
+}namespace base_members_hidden {
+struct base1 {
+  template  requires IsEmpty
+  Opaque<0> foo() { return Opaque<0>(); }; // expected-note {{candidate function [with T = constrained_members::Empty]}}
+};
+struct bar1 : public base1 {
+  using base1::foo;
+  template  requires IsEmpty
+  Opaque<1> foo() { return Opaque<1>(); };
+};
+struct base2 {
+  template 
+  Opaque<0> foo() { return Opaque<0>(); };
+};
+struct bar2 : public base2 {
+  using base2::foo;
+  template 
+  Opaque<1> foo() { return Opaque<1>(); };
+};
+struct baz : public base1 {
+  using base1::foo;
+  template  requires IsEmpty && IsEmpty
+  Opaque<1> foo() { return Opaque<1>(); };  // expected-note {{candidate function [with T = constrained_members::Empty]}}
+};
+void func() { 
+  expect<0>(base1{}.foo());
+  expect<1>(bar1{}.foo());
+  expect<0>(base2{}.foo());
+  expect<1>(bar2{}.foo());
+  baz{}.foo(); // expected-error {{call to member function 'foo' is ambiguous}}
+}
+}
+namespace same_contraint_at_different_place {
+struct base {
+  template 
+  Opaque<0> foo1() { return Opaque<0>(); }; // expected-note 2 {{candidate function}}
+  template  requires IsEmpty
+  Opaque<0> foo2() { return Opaque<0>(); }; // expected-note 2 {{candidate function}}
+  template 
+  Opaque<0> foo3() requires IsEmpty { return Opaque<0>(); }; // expected-note 2 {{candidate function}}
+};
+struct bar1 : public base {
+  using base::foo1;
+  using base::foo2;
+  using base::foo3;
+  template  requires IsEmpty
+  Opaque<1> foo1() { return Opaque<1>(); }; // expected-note {{candidate function}}
+  template 
+  Opaque<1> foo2() { return Opaque<1>(); }; // expected-note {{candidate function}}
+  template 
+  Opaque<1> foo3() { return Opaque<1>(); }; // expected-note {{candidate function}}
+};
+struct bar2 : public base {
+  using base::foo1;
+  using base::foo2;
+  using base::foo3;
+  template 
+  Opaque<2> foo1() requires IsEmpty { return Opaque<2>(); }; // expected-note {{candidate function}}
+  template 
+  Opaque<2> foo2() requires IsEmpty { return Opaque<2>(); }; // expected-note {{candidate function}}
+  template  requires IsEmpty
+  Opaque<2> foo3() { return Opaque<2>(); }; // expected-note {{candidate function}}
+};void func() {
+  bar1{}.foo1(); // expected-error {{call to member function 'foo1' is ambiguous}}
+  bar1{}.foo2(); // expected-error {{call to member function 'foo2' is ambiguous}}
+  bar1{}.foo3(); // expected-error {{call to member function 'foo3' is ambiguous}}
+  bar2{}.foo1(); // expected-error {{call to member function 'foo1' is ambiguous}}
+  bar2{}.foo2(); // expected-error {{call to member function 'foo2' is ambiguous}}
+  bar2{}.foo3(); // expected-error {{call to member function 'foo3' is ambiguous}}
+}
+} // namespace same_contraint_at_different_place
+
+namespace more_contrained {
+struct base1 { 
+  template  Opaque<0> foo() { return Opaque<0>(); }
+};
+struct derived1 : base1 { 
+  using base1::foo;
+  template  Opaque<1> foo() { return Opaque<1>(); }
+};
+struct base2 { 
+  template  Opaque<0> foo() { return Opaque<0>(); }
+};
+struct derived2 : base2 { 
+  using base2::foo;
+  template 

[PATCH] D136440: [clang] Do not hide base member using-decls with different template head.

2022-10-25 Thread Utkarsh Saxena via Phabricator via cfe-commits
usaxena95 added inline comments.



Comment at: clang/test/SemaTemplate/concepts-using-decl.cpp:112
+  expect<1>(baz{}.foo()); // expected-error {{call to member function 
'foo' is ambiguous}}
+}
+}

ilya-biryukov wrote:
> Could you also check that `requires` clauses and constraints in template 
> parameters do not hide each other?
> ```
> template  ...
> // vs
> template  requires IsEmpty ...
> // vs
> template  void foo() requires IsEmpty ...
> ```
> Should not hide each other.
> 
> Another interesting case (that probably does not yet work):
> ```
> struct base { template  void foo(); };
> struct derived : base { 
>   using base::foo; 
>   template  void foo();
> };
> ```
> ^^ `derived().foo()` will probably produce an ambiguity now (as we 
> don't have an explicit requires clause here). I don't think it's worth fixing 
> now, but keeping a test for it with a FIXME seems reasonable.
The last test case would work though since we perform template head check if 
any template head is contrained. This is not ambiguous as overloading chooses 
the "most contrained" version.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136440

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


[PATCH] D136532: [clang][Interp] Implement left and right shifts

2022-10-25 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/test/AST/Interp/shifts.cpp:57
+//c >>= 99; // expected-warning {{shift count >= width of type}}
+//c <<= CHAR_BIT; // expected-warning {{shift count >= width of type}}
+//c >>= CHAR_BIT; // expected-warning {{shift count >= width of type}}

aaron.ballman wrote:
> tbaeder wrote:
> > shafik wrote:
> > > This is not correct, the operands go through integral promotions first 
> > > and the result is the promoted type of the left operand see [dcl.shift 
> > > p1](https://eel.is/c++draft/expr.shift#1).
> > > 
> > > Also see godbolt: https://godbolt.org/z/7qzKjojMb
> > Hmm, this is copy-pasted from `test/SemaCXX/shift.cpp`.
> FWIW, I agree with Shafik -- you can also see the casts in the AST: 
> https://godbolt.org/z/97dqr1TEs
This weird, you can see this is indeed valid in a constant expression: 
https://godbolt.org/z/W33janMxv

but we do obtain that diagnostic and I think I see what it is saying, that the 
result type is 8bit but the shift is larger than that type even though the 
operation is being done on the promoted type. I feel like the diagnostic is not 
great but could be improved to make it better.

wdyt @aaron.ballman 



Comment at: clang/test/AST/Interp/shifts.cpp:70
+i = 1 << (WORD_BIT - 1); // cxx17-warning-not {{sets the sign bit of the 
shift expression}}
+i = -1 << (WORD_BIT - 1); // cxx17-warning {{shifting a negative signed 
value is undefined}} \
+  // ref-cxx17-warning {{shifting a negative 
signed value is undefined}}

aaron.ballman wrote:
> tbaeder wrote:
> > shafik wrote:
> > > shafik wrote:
> > > > A negative left operand was made well-formed in C++20 I believe see 
> > > > godbolt: https://godbolt.org/z/7qzKjojMb
> > > > 
> > > > My reference from above for `expr.shift/p1` also applies. 
> > > > 
> > > > Although a negative right operand is still UB.
> > > > 
> > > > Also note shifting into the sign bit was made well-formed in C++11: 
> > > > https://stackoverflow.com/questions/19593938/is-left-shifting-a-negative-integer-undefined-behavior-in-c11#comment29091986_19593938
> > > Typo, shifting into the sign bit was made well-formed after C++11
> > This is in line with the test, isn't it? The warning is only for `cxx17`, 
> > the c++20 tests don't expect any output.
> Also worth keeping in mind: C and C++ differ here.
> 
> C2x 6.5.7p4: "... If E1 has a signed type and nonnegative value, and E1 × 2E2 
> is representable in the result type, then that is the resulting value; 
> otherwise, the behavior is undefined."
Apologies, I missed the diagnostic was only firing for C++17.


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

https://reviews.llvm.org/D136532

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


[clang] cb088e8 - Add more C99 DR test cases and update the status page

2022-10-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-10-25T11:14:52-04:00
New Revision: cb088e8c3abf30456e2891f90b5194d0070c387a

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

LOG: Add more C99 DR test cases and update the status page

This mostly completes the C99 set of DRs, though there are a few still
marked as "unknown".

Added: 
clang/test/C/drs/dr324.c

Modified: 
clang/test/C/drs/dr3xx.c
clang/www/c_dr_status.html

Removed: 




diff  --git a/clang/test/C/drs/dr324.c b/clang/test/C/drs/dr324.c
new file mode 100644
index 0..a76e185c53020
--- /dev/null
+++ b/clang/test/C/drs/dr324.c
@@ -0,0 +1,36 @@
+/* RUN: %clang_cc1 -std=c89 -fsyntax-only -pedantic -verify %s
+   RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic -verify %s
+   RUN: %clang_cc1 -std=c11 -fsyntax-only -pedantic -verify %s
+   RUN: %clang_cc1 -std=c17 -fsyntax-only -pedantic -verify %s
+   RUN: %clang_cc1 -std=c2x -fsyntax-only -pedantic -verify %s
+ */
+
+/* WG14 DR324: yes
+ * Tokenization obscurities
+ */
+
+/* We need to diagnose an unknown escape sequence in a string or character
+ * literal, but not within a header-name terminal.
+ */
+const char *lit_str = "\y"; /* expected-warning {{unknown escape sequence 
'\y'}} */
+char lit_char = '\y';   /* expected-warning {{unknown escape sequence 
'\y'}} */
+
+/* This gets trickier in a pragma where there are implementation-defined
+ * locations that may use a header-name production. The first pragma below
+ * is using \d but it's in a header-name use rather than a string-literal use.
+ * The second pragma is a string-literal and so the \d is invalid there.
+ */
+#pragma GCC dependency "oops\..\dr0xx.c"
+#pragma message("this has a \t tab escape and an invalid \d escape") /* 
expected-warning {{this has a   tab escape and an invalid d escape}}
+
expected-warning {{unknown escape sequence '\d'}}
+  */
+
+/*
+ * Note, this tests the behavior of a non-empty source file that ends with a
+ * partial preprocessing token such as an unterminated string or character
+ * literal. Thus, it is important that no code be added after this test case.
+ */
+/* expected-error@+3 {{expected identifier or '('}}
+   expected-warning@+3 {{missing terminating ' character}}
+ */
+'t

diff  --git a/clang/test/C/drs/dr3xx.c b/clang/test/C/drs/dr3xx.c
index 61b8a163f0c0b..34ed95d9418d5 100644
--- a/clang/test/C/drs/dr3xx.c
+++ b/clang/test/C/drs/dr3xx.c
@@ -31,6 +31,9 @@
  *
  * WG14 DR333: yes
  * Missing Predefined Macro Name
+ *
+ * WG14 DR342: dup 340
+ * VLAs and conditional expressions
  */
 
 
@@ -217,7 +220,7 @@ void dr335(void) {
   };
 }
 
-/* WG14 DR339: partial
+/* WG14 DR339: dup 328
  * Variably modified compound literals
  *
  * This DR is marked as a duplicate of DR328, see that DR for further
@@ -231,3 +234,61 @@ void *dr339 = &(int (*)[dr339_v]){ 0 }; /* c89only-warning 
{{variable length arr
c99andup-warning {{variable length 
array used}}
c89only-warning {{compound literals 
are a C99-specific feature}}
  */
+
+/* WG14 DR340: yes
+ * Composite types for variable-length arrays
+ *
+ * The DR made this behavior undefined because implementations disagreed on the
+ * behavior. For this DR, Clang accepts the code and GCC rejects it. It's
+ * unclear whether the Clang behavior is intentional, but because the code is
+ * UB, any behavior is acceptable.
+ */
+#if __STDC_VERSION__ < 202000L
+void dr340(int x, int y) {
+  typedef void (*T1)(int);
+  typedef void (*T2)(); /* expected-warning {{a function declaration without a 
prototype is deprecated in all versions of C}} */
+
+  T1 (*a)[] = 0;
+  T2 (*b)[x] = 0;   /* c89only-warning {{variable length arrays are a C99 
feature}}
+   c99andup-warning {{variable length array used}}
+ */
+  (y ? a : b)[0][0]();
+}
+#endif /* __STDC_VERSION__ < 202000L */
+
+/* WG14 DR341: yes
+ * [*] in abstract declarators
+ */
+void dr341_1(int (*)[*]);  /* c89only-warning {{variable 
length arrays are a C99 feature}}
+  c99andup-warning {{variable 
length array used}}
+*/
+void dr341_2(int (*)[sizeof(int (*)[*])]); /* expected-error {{star modifier 
used outside of function prototype}} */
+
+/* WG14 DR343: yes
+ * Initializing qualified wchar_t arrays
+ */
+void dr343(void) {
+  const __WCHAR_TYPE__ x[] = L"foo";
+}
+
+/* WG14 DR344: yes
+ * Casts in preprocessor conditional expressions
+ *
+ * Note: this DR removed a c

[clang] 3d0e9ed - [OpenMP] [OMPIRBuilder] Create a new datatype to hold the unique target region info

2022-10-25 Thread Jan Sjodin via cfe-commits

Author: Jan Sjodin
Date: 2022-10-25T11:15:36-04:00
New Revision: 3d0e9edd8e53fb72e85084f4170513159212839a

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

LOG: [OpenMP] [OMPIRBuilder] Create a new datatype to hold the unique target 
region info

This patch puts the individual target region information attributes into a
struct so that the nested mappings are not needed and passing the information
around is simplified.

Reviewed By: jdoerfert, mikerice

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

Added: 


Modified: 
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/test/OpenMP/declare_target_codegen.cpp
clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 75709740e39ce..f0adf807c6bbc 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1595,9 +1595,9 @@ CGOpenMPRuntime::createDispatchNextFunction(unsigned 
IVSize, bool IVSigned) {
 /// Obtain information that uniquely identifies a target entry. This
 /// consists of the file and device IDs as well as line number associated with
 /// the relevant entry source location.
-static void getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc,
- unsigned &DeviceID, unsigned &FileID,
- unsigned &LineNum) {
+static llvm::TargetRegionEntryInfo
+getTargetEntryUniqueInfo(ASTContext &C, SourceLocation Loc,
+ StringRef ParentName = "") {
   SourceManager &SM = C.getSourceManager();
 
   // The loc should be always valid and have a file ID (the user cannot use
@@ -1617,9 +1617,8 @@ static void getTargetEntryUniqueInfo(ASTContext &C, 
SourceLocation Loc,
   << PLoc.getFilename() << EC.message();
   }
 
-  DeviceID = ID.getDevice();
-  FileID = ID.getFile();
-  LineNum = PLoc.getLine();
+  return llvm::TargetRegionEntryInfo(ParentName, ID.getDevice(), ID.getFile(),
+ PLoc.getLine());
 }
 
 Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const VarDecl *VD) {
@@ -1635,11 +1634,9 @@ Address CGOpenMPRuntime::getAddrOfDeclareTargetVar(const 
VarDecl *VD) {
   llvm::raw_svector_ostream OS(PtrName);
   OS << CGM.getMangledName(GlobalDecl(VD));
   if (!VD->isExternallyVisible()) {
-unsigned DeviceID, FileID, Line;
-getTargetEntryUniqueInfo(CGM.getContext(),
- VD->getCanonicalDecl()->getBeginLoc(),
- DeviceID, FileID, Line);
-OS << llvm::format("_%x", FileID);
+auto EntryInfo = getTargetEntryUniqueInfo(
+CGM.getContext(), VD->getCanonicalDecl()->getBeginLoc());
+OS << llvm::format("_%x", EntryInfo.FileID);
   }
   OS << "_decl_tgt_ref_ptr";
 }
@@ -1858,16 +1855,10 @@ bool 
CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
   // Produce the unique prefix to identify the new target regions. We use
   // the source location of the variable declaration which we know to not
   // conflict with any target region.
-  unsigned DeviceID;
-  unsigned FileID;
-  unsigned Line;
-  getTargetEntryUniqueInfo(CGM.getContext(), Loc, DeviceID, FileID, Line);
+  auto EntryInfo =
+  getTargetEntryUniqueInfo(CGM.getContext(), Loc, VD->getName());
   SmallString<128> Buffer, Out;
-  {
-llvm::raw_svector_ostream OS(Buffer);
-OS << "__omp_offloading_" << llvm::format("_%x", DeviceID)
-   << llvm::format("_%x_", FileID) << VD->getName() << "_l" << Line;
-  }
+  EntryInfo.getTargetRegionEntryFnName(Buffer);
 
   const Expr *Init = VD->getAnyInitializer();
   if (CGM.getLangOpts().CPlusPlus && PerformInit) {
@@ -1913,9 +1904,12 @@ bool 
CGOpenMPRuntime::emitDeclareTargetVarDefinition(const VarDecl *VD,
 
 // Register the information for the entry associated with the constructor.
 Out.clear();
+auto CtorEntryInfo = EntryInfo;
+CtorEntryInfo.ParentName = Twine(Buffer, "_ctor").toStringRef(Out);
+llvm::errs() << "Registering var ctor: " << Twine(Buffer, "_ctor") << "\n";
 OffloadEntriesInfoManager.registerTargetRegionEntryInfo(
-DeviceID, FileID, Twine(Buffer, "_ctor").toStringRef(Out), Line, Ctor,
-ID, llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryCtor,
+CtorEntryInfo, Ctor, ID,
+llvm::OffloadEntriesInfoManager::OMPTargetRegionEntryCtor,
 CGM.getLangOpts().OpenMPIsDevice);
   }
   if (VD->getType().isDestructedType() != QualType::DK_none) {
@@ -1961,9 +1955,11 @@ bool

[PATCH] D136601: [OpenMP] [OMPIRBuilder] Create a new datatype to hold the unique target region info

2022-10-25 Thread Jan Sjödin 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 rG3d0e9edd8e53: [OpenMP] [OMPIRBuilder] Create a new datatype 
to hold the unique target region… (authored by jsjodin).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136601

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/declare_target_codegen.cpp
  clang/test/OpenMP/nvptx_declare_target_var_ctor_dtor_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp

Index: llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
===
--- llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
+++ llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp
@@ -5504,16 +5504,17 @@
 
 TEST_F(OpenMPIRBuilderTest, OffloadEntriesInfoManager) {
   OffloadEntriesInfoManager InfoManager;
-  InfoManager.initializeTargetRegionEntryInfo(1, 2, "parent", 4, 0);
+  TargetRegionEntryInfo EntryInfo("parent", 1, 2, 4);
+  InfoManager.initializeTargetRegionEntryInfo(EntryInfo, 0);
   InfoManager.initializeDeviceGlobalVarEntryInfo(
   "gvar", OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo, 0);
   InfoManager.registerTargetRegionEntryInfo(
-  1, 2, "parent", 4, nullptr, nullptr,
+  EntryInfo, nullptr, nullptr,
   OffloadEntriesInfoManager::OMPTargetRegionEntryTargetRegion, true);
   InfoManager.registerDeviceGlobalVarEntryInfo(
   "gvar", 0x0, 8, OffloadEntriesInfoManager::OMPTargetGlobalVarEntryTo,
   GlobalValue::WeakAnyLinkage, true);
-  EXPECT_TRUE(InfoManager.hasTargetRegionEntryInfo(1, 2, "parent", 4, true));
+  EXPECT_TRUE(InfoManager.hasTargetRegionEntryInfo(EntryInfo, true));
   EXPECT_TRUE(InfoManager.hasDeviceGlobalVarEntryInfo("gvar"));
 }
 } // namespace
Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4692,6 +4692,19 @@
   }
 }
 
+void TargetRegionEntryInfo::getTargetRegionEntryFnName(
+SmallVectorImpl &Name, StringRef ParentName, unsigned DeviceID,
+unsigned FileID, unsigned Line) {
+  raw_svector_ostream OS(Name);
+  OS << "__omp_offloading" << llvm::format("_%x", DeviceID)
+ << llvm::format("_%x_", FileID) << ParentName << "_l" << Line;
+}
+
+void TargetRegionEntryInfo::getTargetRegionEntryFnName(
+SmallVectorImpl &Name) {
+  getTargetRegionEntryFnName(Name, ParentName, DeviceID, FileID, Line);
+}
+
 bool OffloadEntriesInfoManager::empty() const {
   return OffloadEntriesTargetRegion.empty() &&
  OffloadEntriesDeviceGlobalVar.empty();
@@ -4699,60 +4712,47 @@
 
 /// Initialize target region entry.
 void OffloadEntriesInfoManager::initializeTargetRegionEntryInfo(
-unsigned DeviceID, unsigned FileID, StringRef ParentName, unsigned LineNum,
-unsigned Order) {
-  OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum] =
+const TargetRegionEntryInfo &EntryInfo, unsigned Order) {
+  OffloadEntriesTargetRegion[EntryInfo] =
   OffloadEntryInfoTargetRegion(Order, /*Addr=*/nullptr, /*ID=*/nullptr,
OMPTargetRegionEntryTargetRegion);
   ++OffloadingEntriesNum;
 }
 
 void OffloadEntriesInfoManager::registerTargetRegionEntryInfo(
-unsigned DeviceID, unsigned FileID, StringRef ParentName, unsigned LineNum,
-Constant *Addr, Constant *ID, OMPTargetRegionEntryKind Flags,
-bool IsDevice) {
+const TargetRegionEntryInfo &EntryInfo, Constant *Addr, Constant *ID,
+OMPTargetRegionEntryKind Flags, bool IsDevice) {
   // If we are emitting code for a target, the entry is already initialized,
   // only has to be registered.
   if (IsDevice) {
 // This could happen if the device compilation is invoked standalone.
-if (!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum))
+if (!hasTargetRegionEntryInfo(EntryInfo)) {
   return;
-auto &Entry =
-OffloadEntriesTargetRegion[DeviceID][FileID][ParentName][LineNum];
+}
+auto &Entry = OffloadEntriesTargetRegion[EntryInfo];
 Entry.setAddress(Addr);
 Entry.setID(ID);
 Entry.setFlags(Flags);
   } else {
 if (Flags == OffloadEntriesInfoManager::OMPTargetRegionEntryTargetRegion &&
-hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum,
- /*IgnoreAddressId*/ true))
+hasTargetRegionEntryInfo(EntryInfo, /*IgnoreAddressId*/ true))
   return;
-assert(!hasTargetRegionEntryInfo(DeviceID, FileID, ParentName, LineNum) &&
+assert(!hasTargetRegionEntryInfo(EntryInfo) &&
"Target region entry already registered!");
 OffloadEntryInfo

[PATCH] D136603: [analyzer] Model cast after LValueToRValueBitCasts

2022-10-25 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

I am not sure, if the `ExprEngine::VisitCast` is the proper place to add these 
new modifications and call SValBuilder's evalCast. I think it might be better 
positioned in `RegionStoreManager::getBinding`. Considering, we already do a 
cast evaluation for certain kind of memregions there before returning with the 
stored value. (Actually, this is again a legacy hack, which is needed because 
we do not emit all SymbolCasts and thus we store the SVals with an improper 
type).

  if (const FieldRegion* FR = dyn_cast(R))
return svalBuilder.evalCast(getBindingForField(B, FR), T, QualType{});
  
  if (const ElementRegion* ER = dyn_cast(R)) {
// FIXME: Here we actually perform an implicit conversion from the loaded
// value to the element type.  Eventually we want to compose these values
// more intelligently.  For example, an 'element' can encompass multiple
// bound regions (e.g., several bound bytes), or could be a subset of
// a larger value.
return svalBuilder.evalCast(getBindingForElement(B, ER), T, QualType{});
  }
  
  if (const ObjCIvarRegion *IVR = dyn_cast(R)) {
// FIXME: Here we actually perform an implicit conversion from the loaded
// value to the ivar type.  What we should model is stores to ivars
// that blow past the extent of the ivar.  If the address of the ivar is
// reinterpretted, it is possible we stored a different value that could
// fit within the ivar.  Either we need to cast these when storing them
// or reinterpret them lazily (as we do here).
return svalBuilder.evalCast(getBindingForObjCIvar(B, IVR), T, QualType{});
  }
  
  if (const VarRegion *VR = dyn_cast(R)) {
// FIXME: Here we actually perform an implicit conversion from the loaded
// value to the variable type.  What we should model is stores to variables
// that blow past the extent of the variable.  If the address of the
// variable is reinterpretted, it is possible we stored a different value
// that could fit within the variable.  Either we need to cast these when
// storing them or reinterpret them lazily (as we do here).
return svalBuilder.evalCast(getBindingForVar(B, VR), T, QualType{});
  }

I think a new if block for `SymRegion` should be put here to continue the hack.




Comment at: clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp:301-315
+  ExplodedNodeSet Tmp;
+  evalLocation(Tmp, CastE, CastE, subExprNode, state, *Location, true);
+  if (Tmp.empty())
+return;
+
+  // Proceed with the load.
+  StmtNodeBuilder Bldr(Tmp, Dst, *currBldrCtx);

I think it might be possible to refactor `evalLoad` by returning with a `tuple` 
or with a special `struct`. I guess you should return a vector of `SVal`s as 
one tuple member. Then you could reuse the function in both cases before 
calling `generateNode` on the result. But, this might be a code that is too 
complicated, I'll let you decide if this is worth the hassle to avoid the code 
repetition.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136603

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


[PATCH] D136603: [analyzer] Model cast after LValueToRValueBitCasts

2022-10-25 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.

> PS: I'm not sure how/when we should get rid of the LocAsInteger and
> represent this by a SymbolCast.
> Maybe @ASDenysPetrov or @martong could help me review this.

Whenever this https://reviews.llvm.org/D117229 gets accepted and when we emit 
all symbolCasts for all integers. (`-analyzer-config 
support-symbolic-integer-casts=true` should be default by then)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136603

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


[PATCH] D136311: [CUDA,NVPTX] Implement __bf16 support for NVPTX.

2022-10-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.

LGTM. Thanks.

Do you plan to support arithmetic operators for bf16 or implement the FMA 
instruction support?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136311

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


[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-25 Thread Yitzhak Mandelbaum via Phabricator via cfe-commits
ymandel requested changes to this revision.
ymandel added a comment.
This revision now requires changes to proceed.

Overall, looks quite good.




Comment at: 
clang/include/clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h:87-88
 
+  /// Applies the analysis transfer function for a given edge from a
+  /// CFG block of a conditional statement.
+  /// @param Stmt The condition which is responsible for the split in the CFG.





Comment at: 
clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:78-79
 public:
-  TerminatorVisitor(const StmtToEnvMap &StmtToEnv, Environment &Env,
+  // The return type of the visit functions.
+  using RetTy = std::pair;
+  TerminatorVisitor(TypeErasedDataflowAnalysis &Analysis,

please lift this out and define it as a struct. then, refer to it by name on 
line 76.  that will improve the readability of the code and provide a way to 
document explicitly the role of the two fields.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:258
+.Visit(PredTerminatorStmt);
+if (Cond)
+  // TODO Call transferBranchTypeErased even if BuiltinTransferOpts are

I generally prefer explicit comparison but it's particularly important here, 
given that `Cond` sounds like it could be a boolean.



Comment at: clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp:259
+if (Cond)
+  // TODO Call transferBranchTypeErased even if BuiltinTransferOpts are
+  // not set.





Comment at: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp:28
+using namespace ast_matchers;
+using namespace test;
+

feels odd to mix and match namespace handling here. I think that if you want to 
go with `namespace clang...` that's fine but then do the same for `test`. In 
fact, since we're now in C++17, maybe:
```
namespace clang::dataflow::test {
namespace {
```



Comment at: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp:31
+struct TestLattice {
+  enum class Branch : int { True, False };
+  llvm::Optional TheBranch;

bool? i understand that you don't want to use bool directly, but still seems 
like the better base type here.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp:86-88
+  [&Match](const llvm::StringMap>
+   &Results,
+   const AnalysisOutputs &AO) { Match(Results, AO.ASTCtx); }),

Can your test below use `AnalysisOutputs` directly, and thereby avoid this 
conversion lambda?



Comment at: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp:120
+const TestLattice &LP = getLatticeAtAnnotation(Results, "p");
+EXPECT_TRUE(LP.TheBranch == TestLattice::Branch::True);
+

Please be explicit about the optional, since this is an important detail of the 
test.   Same below.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp:123
+const TestLattice &LQ = getLatticeAtAnnotation(Results, "q");
+EXPECT_TRUE(LQ.TheBranch == TestLattice::Branch::False);
+  },

EXPECT_THAT...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

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


[clang] 5be51ac - Speculatively fix the test bots

2022-10-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-10-25T11:35:53-04:00
New Revision: 5be51acbf01a921a23c000c17c3ba4577fab967e

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

LOG: Speculatively fix the test bots

This should hopefully fix the issues found on Linux hosts like:
https://lab.llvm.org/buildbot#builders/109/builds/49321
https://lab.llvm.org/buildbot/#/builders/139/builds/30061

Added: 


Modified: 
clang/test/C/drs/dr324.c

Removed: 




diff  --git a/clang/test/C/drs/dr324.c b/clang/test/C/drs/dr324.c
index a76e185c5302..870232c2e86a 100644
--- a/clang/test/C/drs/dr324.c
+++ b/clang/test/C/drs/dr324.c
@@ -1,8 +1,8 @@
-/* RUN: %clang_cc1 -std=c89 -fsyntax-only -pedantic -verify %s
-   RUN: %clang_cc1 -std=c99 -fsyntax-only -pedantic -verify %s
-   RUN: %clang_cc1 -std=c11 -fsyntax-only -pedantic -verify %s
-   RUN: %clang_cc1 -std=c17 -fsyntax-only -pedantic -verify %s
-   RUN: %clang_cc1 -std=c2x -fsyntax-only -pedantic -verify %s
+/* RUN: %clang_cc1 -std=c89 -fsyntax-only -fms-extensions -pedantic -verify %s
+   RUN: %clang_cc1 -std=c99 -fsyntax-only -fms-extensions -pedantic -verify %s
+   RUN: %clang_cc1 -std=c11 -fsyntax-only -fms-extensions -pedantic -verify %s
+   RUN: %clang_cc1 -std=c17 -fsyntax-only -fms-extensions -pedantic -verify %s
+   RUN: %clang_cc1 -std=c2x -fsyntax-only -fms-extensions -pedantic -verify %s
  */
 
 /* WG14 DR324: yes
@@ -20,7 +20,12 @@ char lit_char = '\y';   /* expected-warning {{unknown 
escape sequence '\y'}}
  * is using \d but it's in a header-name use rather than a string-literal use.
  * The second pragma is a string-literal and so the \d is invalid there.
  */
+#ifdef _WIN32
+/* This test only makes sense on Windows targets where the backslash is a valid
+ * path separator.
+ */
 #pragma GCC dependency "oops\..\dr0xx.c"
+#endif
 #pragma message("this has a \t tab escape and an invalid \d escape") /* 
expected-warning {{this has a   tab escape and an invalid d escape}}
 
expected-warning {{unknown escape sequence '\d'}}
   */



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


[PATCH] D136684: [clang][ASTImporter] Remove use of ParentMapContext.

2022-10-25 Thread Gabor Marton via Phabricator via cfe-commits
martong accepted this revision.
martong added a comment.
This revision is now accepted and ready to land.
Herald added a subscriber: rnkovacs.

It is very good that we can get rid of the `ParentMapContext` because it was 
sub-optimal to build that up for **//all//** declaration contexts of the 
translation unit. Now we discover the parent-child relations for ourselves and 
only for the needed declaration contexts. This is the proper way to go.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136684

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


[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added inline comments.



Comment at: clang/include/clang/Sema/Sema.h:8285
+   TemplateArgument &SugaredConverted,
+   TemplateArgument &CanonicalConverted,
+   CheckTemplateArgumentKind CTAK);

erichkeane wrote:
> I find myself wondering if we should just be passing around the 'Sugared' 
> version, and canonicalizing when we need it?  Is there a good reason not to?
I think given the size of the patch, splitting things this way makes it way 
easier to not pass the wrong list somewhere, and then spend a long time looking 
for the problem.

I plan to make this better in a future patch, I am investigating the net 
benefits of tracking and uniquing template argument lists, much like how we do 
for types.

Then, I think we can get rid of this duplication in all places that are just 
passing the lists around.

Otherwise, llvm-compile-time-tracker shows no performance impact from this 
patch at all (and the same for all the others in the sugared substitution 
series), so I did not want to block everything on that extra work.



Comment at: clang/include/clang/Sema/TemplateDeduction.h:94
 
-  /// Take ownership of the deduced template argument list.
-  TemplateArgumentList *take() {
-TemplateArgumentList *Result = Deduced;
-Deduced = nullptr;
+  /// Take ownership of the deduced template argument lists.
+  TemplateArgumentList *takeSugared() {

erichkeane wrote:
> Not your fault at all but that seems to be about the absolute opposite of 
> what it looks like this function is doing...
Hah, it's written in the perspective of the user, not the provider.

The opposite of standard practice I guess.



Comment at: clang/lib/Sema/SemaTemplate.cpp:4876
   Context, NamedConcept->getDeclContext(), NamedConcept->getLocation(),
-  Converted);
+  CanonicalConverted);
   ConstraintSatisfaction Satisfaction;

erichkeane wrote:
> At one point I wonder if there is value to storing the sugared version here 
> instead.  We currently just create these every time we need them, so the 
> side-effect would be possibly a nicer looking AST dump.  BUT we don't really 
> canonizalize these Specialization Decls/Specialization Exprs.
That will happen in D136566, which you already reviewed.

If we did that before the changes in D134604, then this would lead to a crash 
for certain test cases involving partial substitutions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-25 Thread Erich Keane via Phabricator via cfe-commits
erichkeane accepted this revision.
erichkeane added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/include/clang/Sema/Sema.h:8285
+   TemplateArgument &SugaredConverted,
+   TemplateArgument &CanonicalConverted,
+   CheckTemplateArgumentKind CTAK);

mizvekov wrote:
> erichkeane wrote:
> > I find myself wondering if we should just be passing around the 'Sugared' 
> > version, and canonicalizing when we need it?  Is there a good reason not to?
> I think given the size of the patch, splitting things this way makes it way 
> easier to not pass the wrong list somewhere, and then spend a long time 
> looking for the problem.
> 
> I plan to make this better in a future patch, I am investigating the net 
> benefits of tracking and uniquing template argument lists, much like how we 
> do for types.
> 
> Then, I think we can get rid of this duplication in all places that are just 
> passing the lists around.
> 
> Otherwise, llvm-compile-time-tracker shows no performance impact from this 
> patch at all (and the same for all the others in the sugared substitution 
> series), so I did not want to block everything on that extra work.
SGTM.



Comment at: clang/lib/Sema/SemaTemplate.cpp:4876
   Context, NamedConcept->getDeclContext(), NamedConcept->getLocation(),
-  Converted);
+  CanonicalConverted);
   ConstraintSatisfaction Satisfaction;

mizvekov wrote:
> erichkeane wrote:
> > At one point I wonder if there is value to storing the sugared version here 
> > instead.  We currently just create these every time we need them, so the 
> > side-effect would be possibly a nicer looking AST dump.  BUT we don't 
> > really canonizalize these Specialization Decls/Specialization Exprs.
> That will happen in D136566, which you already reviewed.
> 
> If we did that before the changes in D134604, then this would lead to a crash 
> for certain test cases involving partial substitutions.
Ah! Hoisted by my own poor memory again!  Thanks.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[PATCH] D135097: Remove redundant option '-menable-unsafe-fp-math'.

2022-10-25 Thread Michele Scandale via Phabricator via cfe-commits
michele.scandale added inline comments.



Comment at: clang/lib/CodeGen/CGCall.cpp:1865-1869
+if ((LangOpts.FastMath ||
+ !LangOpts.FastMath && LangOpts.AllowFPReassoc && LangOpts.AllowRecip 
&&
+ !LangOpts.FiniteMathOnly && LangOpts.NoSignedZero &&
+ LangOpts.ApproxFunc) &&
+LangOpts.getDefaultFPContractMode() != 
LangOptions::FPModeKind::FPM_Off)

If I look at the clang driver code, `-funsafe-math-optimizations` is specified 
on the CC1 command line if
```
!MathErrno && AssociativeMath && ReciprocalMath && !SignedZeros && ApproxFunc 
&& !TrappingMath
```
is true.
This means that it shouldn't matter the value of the floating point 
contraction, or whether infs/nans are honored or not.

Was there another issue that this specific part of the change addresses?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D135097

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


[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-25 Thread Gabor Marton via Phabricator via cfe-commits
martong added inline comments.



Comment at: clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp:9-11
+//  This file defines a simplistic version of Sign Analysis as an example
+//  of a forward, monotonic dataflow analysis. The analysis tracks all
+//  variables in the scope, but lacks escape analysis.

I should update this comment as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

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


[PATCH] D133874: [clang] Changes to produce sugared converted template arguments

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

In D133874#3882350 , @erichkeane 
wrote:

> The test changes are a little bizarre, are there any better tests you can 
> write that shows this behavior?
>
> Also, at the 'end' of this patch set, we should make sure we have a detailed 
> release note.

Well, this is mostly just a pure enabler, the rest of the patch series 
implement the uses for the Sugared lists.

It's just that there were 3 places in SemaOverload where we are just diagnosing 
a deduction failure, and we could have just used the sugared lists there 
instead.
Otherwise, these changes would not fit too well with any of the other patches, 
and I thought it would have been a bit unnecessary to split that tiny patch off.

But I guess it's fair to say that the incidental testing is not covering those 
new uses very well, I will add some extra changes later.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133874

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


[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-10-25 Thread Paulo Matos via Phabricator via cfe-commits
pmatos updated this revision to Diff 470517.
pmatos added a comment.

Removed address space wasm_externref which is unnecessary with current design.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

Files:
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/Type.h
  clang/include/clang/AST/TypeProperties.td
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/WebAssemblyReferenceTypes.def
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTBitCodes.h
  clang/include/clang/module.modulemap
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/AST/NSAPI.cpp
  clang/lib/AST/PrintfFormatString.cpp
  clang/lib/AST/Type.cpp
  clang/lib/AST/TypeLoc.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/ItaniumCXXABI.cpp
  clang/lib/CodeGen/TargetInfo.cpp
  clang/lib/CodeGen/TargetInfo.h
  clang/lib/Index/USRGeneration.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaChecking.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaExpr.cpp
  clang/lib/Sema/SemaType.cpp
  clang/lib/Serialization/ASTCommon.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/test/CodeGen/WebAssembly/wasm-externref.c
  clang/test/CodeGen/builtins-wasm.c
  clang/test/CodeGenCXX/wasm-reftypes-mangle.cpp
  clang/test/CodeGenCXX/wasm-reftypes-typeinfo.cpp
  clang/test/Sema/wasm-refs-and-tables.c
  clang/test/SemaCXX/wasm-refs.cpp
  clang/test/SemaTemplate/address_space-dependent.cpp
  clang/tools/libclang/CIndex.cpp
  llvm/include/llvm/IR/Type.h
  llvm/lib/CodeGen/ValueTypes.cpp
  llvm/lib/IR/Type.cpp

Index: llvm/lib/IR/Type.cpp
===
--- llvm/lib/IR/Type.cpp
+++ llvm/lib/IR/Type.cpp
@@ -304,6 +304,18 @@
   return getInt64Ty(C)->getPointerTo(AS);
 }
 
+Type *Type::getWasm_ExternrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(10)
+  static PointerType *Ty = PointerType::get(C, 10);
+  return Ty;
+}
+
+Type *Type::getWasm_FuncrefTy(LLVMContext &C) {
+  // opaque pointer in addrspace(20)
+  static PointerType *Ty = PointerType::get(C, 20);
+  return Ty;
+}
+
 //===--===//
 //   IntegerType Implementation
 //===--===//
Index: llvm/lib/CodeGen/ValueTypes.cpp
===
--- llvm/lib/CodeGen/ValueTypes.cpp
+++ llvm/lib/CodeGen/ValueTypes.cpp
@@ -204,12 +204,8 @@
   case MVT::x86mmx:  return Type::getX86_MMXTy(Context);
   case MVT::x86amx:  return Type::getX86_AMXTy(Context);
   case MVT::i64x8:   return IntegerType::get(Context, 512);
-  case MVT::externref:
-// pointer to opaque struct in addrspace(10)
-return PointerType::get(StructType::create(Context), 10);
-  case MVT::funcref:
-// pointer to i8 addrspace(20)
-return PointerType::get(Type::getInt8Ty(Context), 20);
+  case MVT::externref: return Type::getWasm_ExternrefTy(Context);
+  case MVT::funcref: return Type::getWasm_FuncrefTy(Context);
   case MVT::v1i1:
 return FixedVectorType::get(Type::getInt1Ty(Context), 1);
   case MVT::v2i1:
Index: llvm/include/llvm/IR/Type.h
===
--- llvm/include/llvm/IR/Type.h
+++ llvm/include/llvm/IR/Type.h
@@ -473,6 +473,8 @@
   static PointerType *getInt16PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt32PtrTy(LLVMContext &C, unsigned AS = 0);
   static PointerType *getInt64PtrTy(LLVMContext &C, unsigned AS = 0);
+  static Type *getWasm_ExternrefTy(LLVMContext &C);
+  static Type *getWasm_FuncrefTy(LLVMContext &C);
 
   /// Return a pointer to the current type. This is equivalent to
   /// PointerType::get(Foo, AddrSpace).
Index: clang/tools/libclang/CIndex.cpp
===
--- clang/tools/libclang/CIndex.cpp
+++ clang/tools/libclang/CIndex.cpp
@@ -1627,6 +1627,8 @@
 #include "clang/Basic/PPCTypes.def"
 #define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/RISCVVTypes.def"
+#define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
+#include "clang/Basic/WebAssemblyReferenceTypes.def"
 #define BUILTIN_TYPE(Id, SingletonId)
 #define SIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
 #define UNSIGNED_TYPE(Id, SingletonId) case BuiltinType::Id:
Index: clang/test/SemaTemplate/address_space-dependent.cpp
===
--- clang/test/SemaTemplate/address_space-dependent.cpp
+++ clang/test/SemaTemplate/addre

[PATCH] D122215: [WebAssembly] Initial support for reference type externref in clang

2022-10-25 Thread Paulo Matos via Phabricator via cfe-commits
pmatos planned changes to this revision.
pmatos added a comment.

Whole integration plan still in the works, so marking as planning changes.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D122215

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


[PATCH] D133698: [clang][dataflow] Implement transferBranch

2022-10-25 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun accepted this revision.
xazax.hun added a comment.

With the rest of the comments addressed it looks good to me.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133698

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


[PATCH] D136311: [CUDA,NVPTX] Implement __bf16 support for NVPTX.

2022-10-25 Thread Allen zhong via Phabricator via cfe-commits
Allen added inline comments.



Comment at: llvm/lib/Target/NVPTX/NVPTXInstrInfo.td:186
+ !eq(name, "v2f16"): Float16x2Regs,
+ !eq(name, "bf16"): Float16Regs,
+ !eq(name, "v2bf16"): Float16x2Regs,

sorry for a basic question: what's the different between bf16 and f16 ?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136311

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


[PATCH] D136694: [clang][Interp] Check that constructor calls initialize all record fields

2022-10-25 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.

We need to do this, even for global variables (it seems).

The diagnostic output is slightly different than what we get from the current 
interpreter, but I'm not sure if it's worse or not or if that needs to be 
changed.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D136694

Files:
  clang/lib/AST/Interp/Descriptor.cpp
  clang/lib/AST/Interp/Interp.cpp
  clang/lib/AST/Interp/Interp.h
  clang/lib/AST/Interp/InterpFrame.cpp
  clang/test/AST/Interp/cxx20.cpp
  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
@@ -279,7 +279,9 @@
// ref-note {{declared here}} \
// expected-error {{must be initialized by a constant expression}}
   static_assert(D.Val == 0, ""); // ref-error {{not an integral constant expression}} \
- // ref-note {{initializer of 'D' is not a constant expression}}
+ // ref-note {{initializer of 'D' is not a constant expression}} \
+ // expected-error {{not an integral constant expression}} \
+ // expected-note {{read of object outside its lifetime}}
 
   struct AnotherBase {
 int Val;
Index: clang/test/AST/Interp/cxx20.cpp
===
--- clang/test/AST/Interp/cxx20.cpp
+++ clang/test/AST/Interp/cxx20.cpp
@@ -80,3 +80,42 @@
 }
 static_assert(f());
 #endif
+
+
+namespace UninitializedFields {
+  class A {
+  public:
+int a; // expected-note {{subobject declared here}} \
+   // ref-note {{subobject declared here}}
+constexpr A() {}
+  };
+  constexpr A a; // expected-error {{must be initialized by a constant expression}} \
+ // expected-note {{subobject of type 'int' is not initialized}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{subobject of type 'int' is not initialized}}
+
+
+  class Base {
+  public:
+bool b;
+int a; // expected-note {{subobject declared here}} \
+   // ref-note {{subobject declared here}}
+constexpr Base() : b(true) {}
+  };
+
+  class Derived : public Base {
+  public:
+constexpr Derived() : Base() {} // expected-note {{subobject of type 'int' is not initialized}}
+  };
+
+constexpr Derived D; // expected-error {{must be initialized by a constant expression}} \\
+ // expected-note {{in call to 'Derived()'}} \
+ // ref-error {{must be initialized by a constant expression}} \
+ // ref-note {{subobject of type 'int' is not initialized}}
+
+
+
+
+
+
+};
Index: clang/lib/AST/Interp/InterpFrame.cpp
===
--- clang/lib/AST/Interp/InterpFrame.cpp
+++ clang/lib/AST/Interp/InterpFrame.cpp
@@ -61,8 +61,6 @@
 }
 
 InterpFrame::~InterpFrame() {
-  if (Func && Func->isConstructor() && This.isBaseClass())
-This.initialize();
   for (auto &Param : Params)
 S.deallocate(reinterpret_cast(Param.second.get()));
 }
Index: clang/lib/AST/Interp/Interp.h
===
--- clang/lib/AST/Interp/Interp.h
+++ clang/lib/AST/Interp/Interp.h
@@ -96,6 +96,9 @@
 bool CheckFloatResult(InterpState &S, CodePtr OpPC, APFloat::opStatus Status,
   const Floating &Result);
 
+/// Checks that all fields are initialized after a constructor call.
+bool CheckCtorCall(InterpState &S, CodePtr OpPC, const Pointer &This);
+
 /// Checks if Div/Rem operation on LHS and RHS is valid.
 template 
 bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
@@ -1338,7 +1341,9 @@
 
 inline bool Call(InterpState &S, CodePtr &PC, const Function *Func) {
   auto NewFrame = std::make_unique(S, Func, PC);
+  Pointer ThisPtr;
   if (Func->hasThisPointer()) {
+ThisPtr = NewFrame->getThis();
 if (!CheckInvoke(S, PC, NewFrame->getThis())) {
   return false;
 }
@@ -1355,6 +1360,13 @@
   if (Interpret(S, CallResult)) {
 NewFrame.release(); // Frame was delete'd already.
 assert(S.Current == FrameBefore);
+
+// For constructors, check that all fields have been initialized.
+if (Func->isConstructor()) {
+  if (!CheckCtorCall(S, PC, ThisPtr))
+return false;
+}
+
 return true;
   }
 
Index: clang/lib/AST/Interp/Interp.cpp
===
--- clang/lib/AST/Interp/Interp.cpp
+++ clang/lib/AST/Interp/Interp.cpp
@@ -435,6 +435,38 @@

[PATCH] D136533: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-25 Thread Nico Weber via Phabricator via cfe-commits
thakis added a comment.

+1, this breaks building LLVM on macOS.

This isn't limited to libFuzzer. See the many hits for "error:" on 
https://logs.chromium.org/logs/chromium/buildbucket/cr-buildbucket/8799329305964156353/+/u/package_clang/stdout?format=raw

Let's revert this until LLVM can build again.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[clang] 60809cd - Revert "[clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access"

2022-10-25 Thread Nico Weber via cfe-commits

Author: Nico Weber
Date: 2022-10-25T12:23:10-04:00
New Revision: 60809cd29308e78d662375e6957a2b1b85415def

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

LOG: Revert "[clang] Fix missing diagnostic of declaration use when accessing 
TypeDecls through typename access"

This reverts commit dc170433137aeda5e5276bd292cac12aa93fee7c.
Breaks building LLVM on mac when targeting macOS before 10.15, see
comments on https://reviews.llvm.org/D136533

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp

libcxx/test/libcxx/depr/depr.default.allocator/allocator.members/allocate.depr_in_cxx17.verify.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index eb3f92cdf57bd..93462a16ef8fa 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -255,9 +255,6 @@ Bug Fixes
 - Reject non-type template arguments formed by casting a non-zero integer
   to a pointer in pre-C++17 modes, instead of treating them as null
   pointers.
-- Fix missing diagnostics for uses of declarations when performing typename 
access,
-  such as when performing member access on a '[[deprecated]]' type alias.
-  `Issue 58547 `
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 92c89e757c9d9..e84e6b22f2817 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2566,10 +2566,6 @@ class Sema final {
 
   bool isSimpleTypeSpecifier(tok::TokenKind Kind) const;
 
-  enum class DiagCtorKind { None, Implicit, Typename };
-  QualType getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
-   TypeDecl *TD, SourceLocation NameLoc);
-
   ParsedType getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
  Scope *S, CXXScopeSpec *SS = nullptr,
  bool isClassName = false, bool HasTrailingDot = false,

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e0605fea8e27f..19bd670e791bc 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -169,26 +169,6 @@ bool Sema::isSimpleTypeSpecifier(tok::TokenKind Kind) 
const {
   return false;
 }
 
-QualType Sema::getTypeDeclType(DeclContext *LookupCtx, DiagCtorKind DCK,
-   TypeDecl *TD, SourceLocation NameLoc) {
-  auto *LookupRD = dyn_cast_or_null(LookupCtx);
-  auto *FoundRD = dyn_cast(TD);
-  if (DCK != DiagCtorKind::None && LookupRD && FoundRD &&
-  FoundRD->isInjectedClassName() &&
-  declaresSameEntity(LookupRD, cast(FoundRD->getParent( {
-Diag(NameLoc,
- DCK == DiagCtorKind::Typename
- ? diag::ext_out_of_line_qualified_id_type_names_constructor
- : diag::err_out_of_line_qualified_id_type_names_constructor)
-<< TD->getIdentifier() << /*Type*/ 1
-<< 0 /*if any keyword was present, it was 'typename'*/;
-  }
-
-  DiagnoseUseOfDecl(TD, NameLoc);
-  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
-  return Context.getTypeDeclType(TD);
-}
-
 namespace {
 enum class UnqualifiedTypeNameLookupResult {
   NotFound,
@@ -352,11 +332,10 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
  bool IsClassTemplateDeductionContext,
  ImplicitTypenameContext AllowImplicitTypename,
  IdentifierInfo **CorrectedII) {
-  bool IsImplicitTypename = !isClassName && !IsCtorOrDtorName;
   // FIXME: Consider allowing this outside C++1z mode as an extension.
   bool AllowDeducedTemplate = IsClassTemplateDeductionContext &&
-  getLangOpts().CPlusPlus17 && IsImplicitTypename 
&&
-  !HasTrailingDot;
+  getLangOpts().CPlusPlus17 && !IsCtorOrDtorName &&
+  !isClassName && !HasTrailingDot;
 
   // Determine where we will perform name lookup.
   DeclContext *LookupCtx = nullptr;
@@ -380,9 +359,11 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, 
SourceLocation NameLoc,
 // refer to a member of an unknown specialization.
 // In C++2a, in several contexts a 'typename' is not required. Also
 // allow this as an extension.
+if (AllowImplicitTypename == ImplicitTypenameContext::No &&
+!isClassName && !IsCtorOrDtorName)
+  return nullptr;
+bool IsImplicitTypename = !isClassName && !IsCtorOrDto

[PATCH] D136571: [RISCV] add svinval extension

2022-10-25 Thread Philip Reames via Phabricator via cfe-commits
reames added inline comments.



Comment at: llvm/docs/RISCVUsage.rst:56
  ``V``Supported
+ ``Svinval``  Assembly Support
  ``Zba``  Supported

This table is sorted alphabetically, please move above V.  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136571

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


[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-10-25 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon added inline comments.



Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:46
+  auto SecondSemiPos = Line.find(';', FirstSemiPos + 1);
+  if (FirstSemiPos == std::string::npos)
+continue;

@cor3ntin Should this be SecondSemiPos ?

Report here: https://pvs-studio.com/en/blog/posts/cpp/1003/ (N39)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

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


[clang] 6fcaaf8 - Whitespace fix in a comment; NFC

2022-10-25 Thread Aaron Ballman via cfe-commits

Author: Aaron Ballman
Date: 2022-10-25T12:35:35-04:00
New Revision: 6fcaaf89fe83ebc821df0e5e774fd8a7f4b1dba3

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

LOG: Whitespace fix in a comment; NFC

Added: 


Modified: 
clang/test/C/drs/dr3xx.c

Removed: 




diff  --git a/clang/test/C/drs/dr3xx.c b/clang/test/C/drs/dr3xx.c
index 34ed95d9418d..96d809a4fe13 100644
--- a/clang/test/C/drs/dr3xx.c
+++ b/clang/test/C/drs/dr3xx.c
@@ -33,7 +33,7 @@
  * Missing Predefined Macro Name
  *
  * WG14 DR342: dup 340
- * VLAs and conditional expressions
+ * VLAs and conditional expressions
  */
 
 



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


[PATCH] D123064: [Clang][C++23] P2071 Named universal character escapes

2022-10-25 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin added inline comments.



Comment at: llvm/utils/UnicodeData/UnicodeNameMappingGenerator.cpp:46
+  auto SecondSemiPos = Line.find(';', FirstSemiPos + 1);
+  if (FirstSemiPos == std::string::npos)
+continue;

RKSimon wrote:
> @cor3ntin Should this be SecondSemiPos ?
> 
> Report here: https://pvs-studio.com/en/blog/posts/cpp/1003/ (N39)
Yes. Nice catch.
There is no case of that happening in the file so it never manifested.
I'll push a commit fixing it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D123064

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


[PATCH] D136539: [Lex] Bring back the magic number 50 in updateConsecutiveMacroArgTokens.

2022-10-25 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

In D136539#3882316 , @hokein wrote:

>> This is a subtle change that needs careful review, and honestly should have 
>> a test.
>
> I agree, and thanks for the nice review comments!
>
> I'd like to add a unittest, but I don't see a straight way (I manually test 
> it by comparing the number of allocated SLocEntries and the used 
> SourceLocation address space in `clang --print-stats` with/out this patch), 
> some options:
>
> 1. construct a large TU that will make clang fails to compile without the 50 
> trick patch;
> 2. create a small test, and verify the the source location is split when the 
> two consecutive tokens distance > 50, and verify the number of  in `clang 
> print-stats`;
>
> 1 feels better to reflect the real behavior, the only concern is that this is 
> a stress test, running it is expensive (we also have a similar 
> `SourceLocationsOverlow.c`, I guess it is ok to add it).

I was all ready to say that option 2 is the only practical one, and was 
surprised that you had an actual testcase.
I'm a bit nervous (it must be slow and eat tons of ram) but if we already have 
a similar test...




Comment at: clang/lib/Lex/TokenLexer.cpp:1010
+unsigned distance =
+T.getLocation().getRawEncoding() - LastLoc.getRawEncoding();
+LastLoc = T.getLocation();

hokein wrote:
> sammccall wrote:
> > sammccall wrote:
> > > This seems to be missing the same-sloc-address-space check: it can create 
> > > a single file ID spanning a local and loaded sloc entry, which will be 
> > > corrupted by saving+loading
> > > 
> > (getOffset() would be much clearly correct than getRawEncoding())
> > missing the same-sloc-address-space check
> 
> oops, good spot. Indeed this is another behavior change in the 
> previous-rewriting patch :( -- the original behavior was that if two 
> consecutive tokens are not in the same address space, it split to two 
> expansion SLocEntries.
> 
> Fixed.
> oops, good spot. Indeed this is another behavior change in the 
> previous-rewriting patch :( 

Argh, I'm so sorry, this prompted me to take another look and there is no 
bug/need for the check at all.

Before we do the NearLast check we've already established that the FileID is 
the same, which means the locations are necessarily in the same address space.

We can replace the isInSameSLocAddrSpace with a raw offset comparison again...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136539

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


[PATCH] D136311: [CUDA,NVPTX] Implement __bf16 support for NVPTX.

2022-10-25 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D136311#3882748 , @yaxunl wrote:

> LGTM. Thanks.
>
> Do you plan to support arithmetic operators for bf16 or implement the FMA 
> instruction support?

Yes. sm_90 has introduced a handful of new bf16 operations that will be 
eventually implemented.




Comment at: llvm/lib/Target/NVPTX/NVPTXInstrInfo.td:186
+ !eq(name, "v2f16"): Float16x2Regs,
+ !eq(name, "bf16"): Float16Regs,
+ !eq(name, "v2bf16"): Float16x2Regs,

Allen wrote:
> sorry for a basic question: what's the different between bf16 and f16 ?
https://en.wikipedia.org/wiki/Bfloat16_floating-point_format



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136311

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


[PATCH] D136311: [CUDA,NVPTX] Implement __bf16 support for NVPTX.

2022-10-25 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: llvm/lib/Target/NVPTX/NVPTXInstrInfo.td:186
+ !eq(name, "v2f16"): Float16x2Regs,
+ !eq(name, "bf16"): Float16Regs,
+ !eq(name, "v2bf16"): Float16x2Regs,

tra wrote:
> Allen wrote:
> > sorry for a basic question: what's the different between bf16 and f16 ?
> https://en.wikipedia.org/wiki/Bfloat16_floating-point_format
> 
If your question is why both bf16 and f16 use Float16Regs, then the answer is 
that both use 'untyped' 16-bit *integer * registers.
The difference from Int16Regs is that those are signed. PTX has some awkward 
restrictions on matching instructions and register kinds, even though under the 
hood it all boils down to everything using 32-bit registers.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136311

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


[clang-tools-extra] 3e067d4 - [include-cleaner] Move vocabulary types into separate header for layering. NFC

2022-10-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-10-25T19:01:59+02:00
New Revision: 3e067d4e59b73b0eaeda7c369d93a6e18f2cdde8

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

LOG: [include-cleaner] Move vocabulary types into separate header for layering. 
NFC

Added: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h

Modified: 
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
clang-tools-extra/include-cleaner/lib/Analysis.cpp
clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
index 0c28119831988..42e619ef4c9bd 100644
--- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
@@ -11,7 +11,8 @@
 #ifndef CLANG_INCLUDE_CLEANER_ANALYSIS_H
 #define CLANG_INCLUDE_CLEANER_ANALYSIS_H
 
-#include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include "clang-include-cleaner/Types.h"
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/STLFunctionalExtras.h"
 #include 
 
@@ -21,30 +22,6 @@ class Decl;
 class FileEntry;
 namespace include_cleaner {
 
-/// An entity that can be referenced in the code.
-struct Symbol {
-  Symbol(Decl &D) : Storage(&D) {}
-  Symbol(tooling::stdlib::Symbol S) : Storage(S) {}
-
-private:
-  // FIXME: Add support for macros.
-  std::variant Storage;
-};
-
-/// Represents a file that provides some symbol. Might not be includeable, e.g.
-/// built-in or main-file itself.
-struct Header {
-  /// A physical (or logical, in case of a builtin) file.
-  Header(const FileEntry *FE) : Storage(FE) {}
-  /// A logical file representing a stdlib header.
-  Header(tooling::stdlib::Header H) : Storage(H) {}
-
-  bool operator==(const Header &RHS) const { return Storage == RHS.Storage; }
-
-private:
-  // FIXME: Handle verbatim spellings.
-  std::variant Storage;
-};
 /// A UsedSymbolCB is a callback invoked for each symbol reference seen.
 ///
 /// References occur at a particular location, refer to a single symbol, and

diff  --git 
a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h 
b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
new file mode 100644
index 0..45c819a9e0736
--- /dev/null
+++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h
@@ -0,0 +1,63 @@
+//===--- Types.h - Data structures for used-symbol analysis  
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Find referenced files is mostly a matter of translating:
+//AST Node => declaration => source location => file
+//
+// clang has types for these (DynTypedNode, Decl, SourceLocation, FileID), but
+// there are special cases: macros are not declarations, the concrete file 
where
+// a standard library symbol was defined doesn't matter, etc.
+//
+// We define some slightly more abstract sum types to handle these cases while
+// keeping the API clean. For example, Symbol may be a Decl AST node, a macro,
+// or a recognized standard library symbol.
+//
+//===--===//
+
+#ifndef CLANG_INCLUDE_CLEANER_RECORD_H
+#define CLANG_INCLUDE_CLEANER_RECORD_H
+
+#include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include 
+#include 
+
+namespace clang {
+class Decl;
+class FileEntry;
+namespace include_cleaner {
+
+/// An entity that can be referenced in the code.
+struct Symbol {
+  Symbol(Decl &D) : Storage(&D) {}
+  Symbol(tooling::stdlib::Symbol S) : Storage(S) {}
+
+private:
+  // FIXME: Add support for macros.
+  std::variant Storage;
+};
+
+/// Represents a file that provides some symbol. Might not be includeable, e.g.
+/// built-in or main-file itself.
+struct Header {
+  /// A physical (or logical, in case of a builtin) file.
+  Header(const FileEntry *FE) : Storage(FE) {}
+  /// A logical file representing a stdlib header.
+  Header(tooling::stdlib::Header H) : Storage(H) {}
+
+  bool operator==(const Header &RHS) const { return Storage == RHS.Storage; }
+
+private:
+  // FIXME: Handle verbatim spellings.
+  std::variant Storage;
+};
+
+} // namespace include_cleaner
+} // namespace clang
+
+#endif
+

diff  --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp 
b/clang-tools-extra/include-cleaner/lib/Analysis.cpp
index 72fac3c9c0084..6b34f81384f15 100644
--- a/cl

[PATCH] D136533: [clang] Fix missing diagnostic of declaration use when accessing TypeDecls through typename access

2022-10-25 Thread Matheus Izvekov via Phabricator via cfe-commits
mizvekov added a comment.

I don't have access to a macOS machine, and I don't believe any of the 
pre-commit CI machines are running it either.
So I don't have much to go on here.

How do you think we shall proceed?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136533

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


[PATCH] D136474: [CodeView][clang] Add flag to disable emitting command line into CodeView

2022-10-25 Thread Nico Weber via Phabricator via cfe-commits
thakis accepted this revision.
thakis added a comment.
This revision is now accepted and ready to land.

Thanks!

Please mention the default value of the flag in the commit message.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136474

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


[PATCH] D136664: [CMake] Support building crt with the bootstrapping build

2022-10-25 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai added a comment.

I might be missing it, but I don't see `crt` depending on `builtins` (or vice 
versa). If there is actually no dep, could we build them together in a single 
configure, instead of needing to add another one for crt? If there is a dep and 
I missed it, then this LGTM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136664

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


[clang] dce5bb9 - [clang-format] Correctly annotate UDLs as OverloadedOperator

2022-10-25 Thread Emilia Dreamer via cfe-commits

Author: Emilia Dreamer
Date: 2022-10-25T20:11:52+03:00
New Revision: dce5bb9a6f89b18366c6f27aeb435a6e48e85639

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

LOG: [clang-format] Correctly annotate UDLs as OverloadedOperator

While the opening parenthesis of an user-defined literal operator was
correctly annotated as OverloadedOperatorLParen, the "" and its suffix
wasn't annotated as OverloadedOperator.

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

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index da6e21c488140..4901c5ce71066 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1177,13 +1177,17 @@ class AnnotatingParser {
 if (CurrentToken->isOneOf(tok::star, tok::amp))
   CurrentToken->setType(TT_PointerOrReference);
 consumeToken();
-if (CurrentToken && CurrentToken->is(tok::comma) &&
+if (!CurrentToken)
+  continue;
+if (CurrentToken->is(tok::comma) &&
 CurrentToken->Previous->isNot(tok::kw_operator)) {
   break;
 }
-if (CurrentToken && CurrentToken->Previous->isOneOf(
-TT_BinaryOperator, TT_UnaryOperator, 
tok::comma,
-tok::star, tok::arrow, tok::amp, tok::ampamp)) 
{
+if (CurrentToken->Previous->isOneOf(TT_BinaryOperator, 
TT_UnaryOperator,
+tok::comma, tok::star, tok::arrow,
+tok::amp, tok::ampamp) ||
+// User defined literal.
+CurrentToken->Previous->TokenText.startswith("\"\"")) {
   CurrentToken->Previous->setType(TT_OverloadedOperator);
 }
   }
@@ -2114,6 +2118,9 @@ class AnnotatingParser {
 if (Tok.Previous == Tok.MatchingParen || !Tok.Next || !Tok.MatchingParen)
   return false;
 
+if (Tok.MatchingParen->is(TT_OverloadedOperatorLParen))
+  return false;
+
 FormatToken *LeftOfParens = Tok.MatchingParen->getPreviousNonComment();
 if (LeftOfParens) {
   // If there is a closing parenthesis left of the current

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 00803cd3a230f..fa26ba0954026 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10153,6 +10153,14 @@ TEST_F(FormatTest, UnderstandsOverloadedOperators) {
   // verifyFormat("void f() { operator*(a & a); }");
   // verifyFormat("void f() { operator&(a, b * b); }");
 
+  verifyFormat("void f() { return operator()(x) * b; }");
+  verifyFormat("void f() { return operator[](x) * b; }");
+  verifyFormat("void f() { return operator\"\"_a(x) * b; }");
+  verifyFormat("void f() { return operator\"\" _a(x) * b; }");
+  verifyFormat("void f() { return operator\"\"s(x) * b; }");
+  verifyFormat("void f() { return operator\"\" s(x) * b; }");
+  verifyFormat("void f() { return operator\"\"if(x) * b; }");
+
   verifyFormat("::operator delete(foo);");
   verifyFormat("::operator new(n * sizeof(foo));");
   verifyFormat("foo() { ::operator delete(foo); }");

diff  --git a/clang/unittests/Format/TokenAnnotatorTest.cpp 
b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 999feca0913d6..b4e27d35bc369 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -390,6 +390,55 @@ TEST_F(TokenAnnotatorTest, 
UnderstandsFunctionRefQualifiers) {
   EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
+  auto Tokens = annotate("x.operator+()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator=()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator+=()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator,()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.opera

[PATCH] D134853: [clang-format] Correctly annotate UDLs as OverloadedOperator

2022-10-25 Thread Emilia Dreamer via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
rymiel marked an inline comment as done.
Closed by commit rGdce5bb9a6f89: [clang-format] Correctly annotate UDLs as 
OverloadedOperator (authored by rymiel).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134853

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

Index: clang/unittests/Format/TokenAnnotatorTest.cpp
===
--- clang/unittests/Format/TokenAnnotatorTest.cpp
+++ clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -390,6 +390,55 @@
   EXPECT_TOKEN(Tokens[11], tok::amp, TT_PointerOrReference);
 }
 
+TEST_F(TokenAnnotatorTest, UnderstandsOverloadedOperators) {
+  auto Tokens = annotate("x.operator+()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::plus, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator=()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::equal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator+=()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::plusequal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator,()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::comma, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator()()");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::l_paren, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::r_paren, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator[]()");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  // EXPECT_TOKEN(Tokens[3], tok::l_square, TT_OverloadedOperator);
+  // EXPECT_TOKEN(Tokens[4], tok::r_square, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator\"\"_a()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator\"\" _a()");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator\"\"if()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator\"\"s()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator\"\" s()");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
+}
+
 TEST_F(TokenAnnotatorTest, UnderstandsRequiresClausesAndConcepts) {
   auto Tokens = annotate("template \n"
  "concept C = (Foo && Bar) && (Bar && Baz);");
Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -10153,6 +10153,14 @@
   // verifyFormat("void f() { operator*(a & a); }");
   // verifyFormat("void f() { operator&(a, b * b); }");
 
+  verifyFormat("void f() { return operator()(x) * b; }");
+  verifyFormat("void f() { return operator[](x) * b; }");
+  verifyFormat("void f() { return operator\"\"_a(x) * b; }");
+  verifyFormat("void f() { return operator\"\" _a(x) * b; }");
+  verifyFormat("void f() { return operator\"\"s(x) * b; }");
+  verifyFormat("void f() { return operator\"\" s(x) * b; }");
+  verifyFormat("void f() { return operator\"\"if(x) * b; }");
+
   verifyFormat("::operator delete(foo);");
   verifyFormat("::operator new(n * sizeof(foo));");
   verifyFormat("foo() { ::operator delete(foo); }");
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -1177,13 +1177,17 @@
 if (CurrentToken->isOneOf(tok::star, tok::amp))
   CurrentToken->setType(TT_PointerOrReference);
 consumeToken();
-

[clang] d03ee70 - [Tooling] Avoid StandardLibrary.h including Decl. NFC

2022-10-25 Thread Sam McCall via cfe-commits

Author: Sam McCall
Date: 2022-10-25T19:12:45+02:00
New Revision: d03ee70de156d638ebb820cd6f578c19b14c6d2b

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

LOG: [Tooling] Avoid StandardLibrary.h including Decl. NFC

So you can use the enum in a header without pulling in half the AST.

Added: 


Modified: 
clang/include/clang/Tooling/Inclusions/StandardLibrary.h
clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp

Removed: 




diff  --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h 
b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
index c6ce2780dae6c..4b5ddbb704e37 100644
--- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
+++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
@@ -15,13 +15,16 @@
 #ifndef LLVM_CLANG_TOOLING_INCLUSIONS_STANDARDLIBRARY_H
 #define LLVM_CLANG_TOOLING_INCLUSIONS_STANDARDLIBRARY_H
 
-#include "clang/AST/Decl.h"
+#include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
 
 namespace clang {
+class Decl;
+class NamespaceDecl;
+class DeclContext;
 namespace tooling {
 namespace stdlib {
 

diff  --git a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp 
b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
index 8fb0c8474e640..f131ab663fc45 100644
--- a/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
+++ b/clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "clang/Tooling/Inclusions/StandardLibrary.h"
+#include "clang/AST/Decl.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/Casting.h"



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


[PATCH] D136311: [CUDA,NVPTX] Implement __bf16 support for NVPTX.

2022-10-25 Thread Artem Belevich via Phabricator via cfe-commits
tra updated this revision to Diff 470544.
tra added a comment.

whitespace fix


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D136311

Files:
  clang/lib/Basic/Targets/NVPTX.cpp
  clang/lib/Basic/Targets/NVPTX.h
  clang/test/CodeGenCUDA/bf16.cu
  clang/test/SemaCUDA/bf16.cu
  llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
  llvm/lib/Target/NVPTX/NVPTXISelDAGToDAG.cpp
  llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
  llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
  llvm/lib/Target/NVPTX/NVPTXProxyRegErasure.cpp
  llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td
  llvm/test/CodeGen/NVPTX/bf16.ll

Index: llvm/test/CodeGen/NVPTX/bf16.ll
===
--- /dev/null
+++ llvm/test/CodeGen/NVPTX/bf16.ll
@@ -0,0 +1,35 @@
+; RUN: llc < %s -march=nvptx | FileCheck %s
+; RUN: %if ptxas %{ llc < %s -march=nvptx | %ptxas-verify %}
+
+; LDST: .b8 bfloat_array[8] = {1, 2, 3, 4, 5, 6, 7, 8};
+@"bfloat_array" = addrspace(1) constant [4 x bfloat]
+[bfloat 0xR0201, bfloat 0xR0403, bfloat 0xR0605, bfloat 0xR0807]
+
+define void @test_load_store(bfloat addrspace(1)* %in, bfloat addrspace(1)* %out) {
+; CHECK-LABEL: @test_load_store
+; CHECK: ld.global.b16 [[TMP:%h[0-9]+]], [{{%r[0-9]+}}]
+; CHECK: st.global.b16 [{{%r[0-9]+}}], [[TMP]]
+  %val = load bfloat, bfloat addrspace(1)* %in
+  store bfloat %val, bfloat addrspace(1) * %out
+  ret void
+}
+
+define void @test_bitcast_from_bfloat(bfloat addrspace(1)* %in, i16 addrspace(1)* %out) {
+; CHECK-LABEL: @test_bitcast_from_bfloat
+; CHECK: ld.global.b16 [[TMP:%h[0-9]+]], [{{%r[0-9]+}}]
+; CHECK: st.global.b16 [{{%r[0-9]+}}], [[TMP]]
+  %val = load bfloat, bfloat addrspace(1) * %in
+  %val_int = bitcast bfloat %val to i16
+  store i16 %val_int, i16 addrspace(1)* %out
+  ret void
+}
+
+define void @test_bitcast_to_bfloat(bfloat addrspace(1)* %out, i16 addrspace(1)* %in) {
+; CHECK-LABEL: @test_bitcast_to_bfloat
+; CHECK: ld.global.u16 [[TMP:%rs[0-9]+]], [{{%r[0-9]+}}]
+; CHECK: st.global.u16 [{{%r[0-9]+}}], [[TMP]]
+  %val = load i16, i16 addrspace(1)* %in
+  %val_fp = bitcast i16 %val to bfloat
+  store bfloat %val_fp, bfloat addrspace(1)* %out
+  ret void
+}
Index: llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td
===
--- llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td
+++ llvm/lib/Target/NVPTX/NVPTXRegisterInfo.td
@@ -60,8 +60,8 @@
 def Int16Regs : NVPTXRegClass<[i16], 16, (add (sequence "RS%u", 0, 4))>;
 def Int32Regs : NVPTXRegClass<[i32], 32, (add (sequence "R%u", 0, 4), VRFrame32, VRFrameLocal32)>;
 def Int64Regs : NVPTXRegClass<[i64], 64, (add (sequence "RL%u", 0, 4), VRFrame64, VRFrameLocal64)>;
-def Float16Regs : NVPTXRegClass<[f16], 16, (add (sequence "H%u", 0, 4))>;
-def Float16x2Regs : NVPTXRegClass<[v2f16], 32, (add (sequence "HH%u", 0, 4))>;
+def Float16Regs : NVPTXRegClass<[f16,bf16], 16, (add (sequence "H%u", 0, 4))>;
+def Float16x2Regs : NVPTXRegClass<[v2f16,v2bf16], 32, (add (sequence "HH%u", 0, 4))>;
 def Float32Regs : NVPTXRegClass<[f32], 32, (add (sequence "F%u", 0, 4))>;
 def Float64Regs : NVPTXRegClass<[f64], 64, (add (sequence "FL%u", 0, 4))>;
 def Int32ArgRegs : NVPTXRegClass<[i32], 32, (add (sequence "ia%u", 0, 4))>;
Index: llvm/lib/Target/NVPTX/NVPTXProxyRegErasure.cpp
===
--- llvm/lib/Target/NVPTX/NVPTXProxyRegErasure.cpp
+++ llvm/lib/Target/NVPTX/NVPTXProxyRegErasure.cpp
@@ -75,6 +75,8 @@
   case NVPTX::ProxyRegI64:
   case NVPTX::ProxyRegF16:
   case NVPTX::ProxyRegF16x2:
+  case NVPTX::ProxyRegBF16:
+  case NVPTX::ProxyRegBF16x2:
   case NVPTX::ProxyRegF32:
   case NVPTX::ProxyRegF64:
 replaceMachineInstructionUsage(MF, MI);
Index: llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
===
--- llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
+++ llvm/lib/Target/NVPTX/NVPTXInstrInfo.td
@@ -172,6 +172,30 @@
 def useShortPtr : Predicate<"useShortPointers()">;
 def useFP16Math: Predicate<"Subtarget->allowFP16Math()">;
 
+// Helper class to aid conversion between ValueType and a matching RegisterClass.
+
+class ValueToRegClass {
+   string name = !cast(T);
+   NVPTXRegClass ret = !cond(
+ !eq(name, "i1"): Int1Regs,
+ !eq(name, "i16"): Int16Regs,
+ !eq(name, "i32"): Int32Regs,
+ !eq(name, "i64"): Int64Regs,
+ !eq(name, "f16"): Float16Regs,
+ !eq(name, "v2f16"): Float16x2Regs,
+ !eq(name, "bf16"): Float16Regs,
+ !eq(name, "v2bf16"): Float16x2Regs,
+ !eq(name, "f32"): Float32Regs,
+ !eq(name, "f64"): Float64Regs,
+ !eq(name, "ai32"): Int32ArgRegs,
+ !eq(name, "ai64"): Int64ArgRegs,
+ !eq(name, "af32"): Float32ArgRegs,
+ !eq(name, "if64"): Float64ArgRegs,
+);
+} 
+
+
+
 //===--===//
 // Some Common Instruction Cl

  1   2   3   >