[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

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



Comment at: clang/test/Frontend/absolute-paths.c:6
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 

charmitro wrote:
> tbaeder wrote:
> > charmitro wrote:
> > > tbaeder wrote:
> > > > This checks the same thing in both cases, but in the `NORMAL` case, it 
> > > > should //not// use the absolute path, shouldn't it?
> > > You're correct. I was constantly testing it from the same path.
> > > 
> > > Since the relative path is going to be different depending on where you 
> > > running from, would it be wise to accept a regular expression of any 
> > > string in the `NORMAL` case?
> > > 
> > > For example, 
> > > ```
> > > NORMAL: In file included from {{.*}}:
> > > ```
> > I wonder if it would make sense to just check for the filename in the 
> > `NORMAL` case and then do a `NORMAL-NOT: [[ROOT_ABSOLUTE]]`?
> Yes, that way we are testing if the warning contains the correct filename+LOC.
> 
> Something like: `// NORMAL: In file included from {{.*absolute-paths.c:4}}:`.
> 
> But why changefrom `ABSOLUTE:` to `NORMAL-NOT`?
Your regex checks if the path ends with the file name, right? That would be 
true in both cases.


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

https://reviews.llvm.org/D151833

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


[PATCH] D151761: clang-format: Add AlignConsecutiveShortCaseStatements

2023-06-02 Thread Galen Elias via Phabricator via cfe-commits
galenelias updated this revision to Diff 528072.
galenelias marked 3 inline comments as done.
galenelias retitled this revision from "clang-format: Add 
AlignConsecutiveShortCaseLabels" to "clang-format: Add 
AlignConsecutiveShortCaseStatements".
galenelias edited the summary of this revision.

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

https://reviews.llvm.org/D151761

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/WhitespaceManager.cpp
  clang/lib/Format/WhitespaceManager.h
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19192,6 +19192,148 @@
BracedAlign);
 }
 
+TEST_F(FormatTest, AlignConsecutiveShortCaseStatements) {
+  FormatStyle Alignment = getLLVMStyle();
+  Alignment.AllowShortCaseLabelsOnASingleLine = true;
+  Alignment.AlignConsecutiveShortCaseStatements.Enabled = true;
+  verifyFormat("switch (level) {\n"
+   "case log::info:return \"info\";\n"
+   "case log::warning: return \"warning\";\n"
+   "default:   return \"default\";\n"
+   "}",
+   Alignment);
+
+  verifyFormat("switch (level) {\n"
+   "case log::info:return \"info\";\n"
+   "case log::warning: return \"warning\";\n"
+   "}",
+   "switch (level) {\n"
+   "case log::info: return \"info\";\n"
+   "case log::warning:\n"
+   "  return \"warning\";\n"
+   "}",
+   Alignment);
+
+  // Verify comments and empty lines break the alignment
+  verifyFormat("switch (level) {\n"
+   "case log::info:return \"info\";\n"
+   "case log::warning: return \"warning\";\n"
+   "// comment\n"
+   "case log::critical: return \"critical\";\n"
+   "default:return \"default\";\n"
+   "\n"
+   "case log::severe: return \"severe\";\n"
+   "}",
+   "switch (level) {\n"
+   "case log::info:return \"info\";\n"
+   "case log::warning: return \"warning\";\n"
+   "// comment\n"
+   "case log::critical: return \"critical\";\n"
+   "default:return \"default\";\n"
+   "\n"
+   "case log::severe: return \"severe\";\n"
+   "}",
+   Alignment);
+
+  // Verify adjacent non-short case statements don't change the alignment, and
+  // properly break the set of consecutive statements.
+  verifyFormat("switch (level) {\n"
+   "case log::critical:\n"
+   "  // comment\n"
+   "  return \"critical\";\n"
+   "case log::info:return \"info\";\n"
+   "case log::warning: return \"warning\";\n"
+   "default:\n"
+   "  // comment\n"
+   "  return \"\";\n"
+   "case log::error:  return \"error\";\n"
+   "case log::severe: return \"severe\";\n"
+   "case log::extra_critical:\n"
+   "  // comment\n"
+   "  return \"extra critical\";\n"
+   "}",
+   Alignment);
+
+  Alignment.ColumnLimit = 80;
+  Alignment.SpaceBeforeCaseColon = true;
+  verifyFormat("switch (level) {\n"
+   "case log::info :return \"info\";\n"
+   "case log::warning : return \"warning\";\n"
+   "default :   return \"default\";\n"
+   "}",
+   Alignment);
+  Alignment.SpaceBeforeCaseColon = false;
+
+  // Make sure we don't incorrectly align correctly across nested switch cases.
+  verifyFormat("switch (level) {\n"
+   "case log::info:return \"info\";\n"
+   "case log::warning: return \"warning\";\n"
+   "case log::other:\n"
+   "  switch (sublevel) {\n"
+   "  case log::info:return \"info\";\n"
+   "  case log::warning: return \"warning\";\n"
+   "  }\n"
+   "  break;\n"
+   "case log::error: return \"error\";\n"
+   "default: return \"default\";\n"
+   "}",
+   "switch (level) {\n"
+   "case log::info:return \"info\";\n"
+   "case log::warning: return \"warning\";\n"
+   "case log::other: switch (sublevel) {\n"
+   "  case log::info:return \"info\";\n"
+   "  case log::warning: return \"warning\";\n"
+   "}\n"
+   "break;\n"
+   "case log::error: return \"error\";\n"
+   "default: 

[PATCH] D152051: libclang-cpp: Add external visibility attribute to all classes

2023-06-02 Thread Tom Stellard via Phabricator via cfe-commits
tstellar added a comment.

I was not sure what to do with inline functions and also functions that were 
implemented in the headers, so I did not add the LLVM_EXTERNAL_VISIBILITY macro 
to most of those functions.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152051

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


[PATCH] D152051: libclang-cpp: Add external visibility attribute to all classes

2023-06-02 Thread Tom Stellard via Phabricator via cfe-commits
tstellar created this revision.
Herald added subscribers: cfe-commits, PiotrZSL, luke, steakhal, carlosgalvezp, 
frasercrmck, wenlei, luismarques, apazos, sameer.abuasal, s.egerton, Jim, 
mstorsjo, jocewei, PkmX, arphaman, the_o, brucehoult, MartinMosbeck, rogfer01, 
edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, 
asb, kbarton, nemanjai.
Herald added a reviewer: sscalpone.
Herald added a reviewer: aaron.ballman.
Herald added a reviewer: NoQ.
Herald added a reviewer: ributzka.
Herald added a reviewer: njames93.
Herald added projects: All, clang, clang-format.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan, MyDeveloperDay.
tstellar requested review of this revision.
Herald added subscribers: pcwang-thead, MaskRay.
Herald added a reviewer: dang.
Herald added projects: LLVM, clang-tools-extra.
Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to clang/include/clang/Format/Format.h but does 
not contain an update to ClangFormatStyleOptions.rst

ClangFormatStyleOptions.rst is generated via 
clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

It looks like your clang-format review does not contain any unit tests, please 
try to ensure all code changes have a unit test (unless this is an `NFC` or 
refactoring, adding documentation etc..)

Add your unit tests in `clang/unittests/Format` and you can build with `ninja 
FormatTests`.  We recommend using the `verifyFormat(xxx)` format of unit tests 
rather than `EXPECT_EQ` as this will ensure you change is tolerant to random 
whitespace changes (see FormatTest.cpp as an example)

For situations where your change is altering the TokenAnnotator.cpp which can 
happen if you are trying to improve the annotation phase to ensure we are 
correctly identifying the type of a token, please add a token annotator test in 
`TokenAnnotatorTest.cpp`


Also compile with -fvisiblity=hidden.  This in theory should be NFC,
but it's possible I missed adding LLVM_EXTERNAL_VISIBILITY to some of
the symbols.  This is the first step towards reducing the amount of
public symbols exposed in libclang-cpp.so, so in the future we will
be dropping LLVM_EXTERNAL_VISIBILITY from classes and functions that
we don't want to make publicly available.

Before and after symbol counts:

$ nm -gD before/libclang-cpp.so | wc -l
30459
$ nm -gD after/libclang-cpp.so | wc -l
20875


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152051

Files:
  clang-tools-extra/clang-tidy/ClangTidyCheck.h
  clang-tools-extra/clang-tidy/ClangTidyModule.h
  clang/CMakeLists.txt
  clang/include/clang-c/FatalErrorHandler.h
  clang/include/clang/APINotes/APINotesYAMLCompiler.h
  clang/include/clang/APINotes/Types.h
  clang/include/clang/ARCMigrate/ARCMT.h
  clang/include/clang/ARCMigrate/ARCMTActions.h
  clang/include/clang/ARCMigrate/FileRemapper.h
  clang/include/clang/AST/APValue.h
  clang/include/clang/AST/ASTConcept.h
  clang/include/clang/AST/ASTConsumer.h
  clang/include/clang/AST/ASTContext.h
  clang/include/clang/AST/ASTContextAllocate.h
  clang/include/clang/AST/ASTDiagnostic.h
  clang/include/clang/AST/ASTDumper.h
  clang/include/clang/AST/ASTDumperUtils.h
  clang/include/clang/AST/ASTImportError.h
  clang/include/clang/AST/ASTImporter.h
  clang/include/clang/AST/ASTImporterLookupTable.h
  clang/include/clang/AST/ASTImporterSharedState.h
  clang/include/clang/AST/ASTMutationListener.h
  clang/include/clang/AST/ASTNodeTraverser.h
  clang/include/clang/AST/ASTStructuralEquivalence.h
  clang/include/clang/AST/ASTTypeTraits.h
  clang/include/clang/AST/ASTUnresolvedSet.h
  clang/include/clang/AST/ASTVector.h
  clang/include/clang/AST/AbstractBasicReader.h
  clang/include/clang/AST/AbstractBasicWriter.h
  clang/include/clang/AST/Attr.h
  clang/include/clang/AST/AttrIterator.h
  clang/include/clang/AST/AttrVisitor.h
  clang/include/clang/AST/Availability.h
  clang/include/clang/AST/BaseSubobject.h
  clang/include/clang/AST/CXXInheritance.h
  clang/include/clang/AST/CanonicalType.h
  clang/include/clang/AST/CharUnits.h
  clang/include/clang/AST/Comment.h
  clang/include/clang/AST/CommentBriefParser.h
  clang/include/clang/AST/CommentCommandTraits.h
  clang/include/clang/AST/CommentLexer.h
  clang/include/clang/AST/CommentParser.h
  clang/include/clang/AST/CommentSema.h
  clang/include/clang/AST/CommentVisitor.h
  clang/include/clang/AST/ComparisonCategories.h
  clang/include/clang/AST/ComputeDependence.h
  clang/include/clang/AST/CurrentSourceLocExprScope.h
  clang/include/clang/AST/DataCollection.h
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclAccessPair.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclCXX.h
  

[PATCH] D131594: WORK IN PROGRESS Add Clang UEFI target to support "x86_64-unknown-uefi" triple

2023-06-02 Thread Prabhu Karthikeyan Rajasekaran via Phabricator via cfe-commits
Prabhuk updated this revision to Diff 528064.
Prabhuk added a comment.

Simplifying the patch to include just the scaffolding for X86_64 platform.
Removing the predefines to be added as a separate patch.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D131594

Files:
  clang/lib/Basic/Targets.cpp
  clang/lib/Basic/Targets/OSTargets.h
  clang/lib/Basic/Targets/X86.h
  clang/lib/Driver/CMakeLists.txt
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/UEFI.cpp
  clang/lib/Driver/ToolChains/UEFI.h
  llvm/include/llvm/MC/TargetRegistry.h
  llvm/include/llvm/TargetParser/Triple.h
  llvm/lib/MC/MCContext.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
  llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/TargetParser/Triple.cpp
  llvm/test/ExecutionEngine/RuntimeDyld/X86/coff-alignment.ll
  llvm/test/Instrumentation/InstrProfiling/profiling.ll
  llvm/test/Transforms/PGOProfile/comdat_rename.ll

Index: llvm/test/Transforms/PGOProfile/comdat_rename.ll
===
--- llvm/test/Transforms/PGOProfile/comdat_rename.ll
+++ llvm/test/Transforms/PGOProfile/comdat_rename.ll
@@ -1,5 +1,6 @@
 ; RUN: opt < %s -mtriple=x86_64-unknown-linux -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
 ; RUN: opt < %s -mtriple=x86_64-pc-win32-coff -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
+; RUN: opt < %s -mtriple=x86_64-unknown-coff -passes=pgo-instr-gen -do-comdat-renaming=true -S | FileCheck %s
 
 ; Rename Comdat group and its function.
 $f = comdat any
Index: llvm/test/Instrumentation/InstrProfiling/profiling.ll
===
--- llvm/test/Instrumentation/InstrProfiling/profiling.ll
+++ llvm/test/Instrumentation/InstrProfiling/profiling.ll
@@ -7,6 +7,7 @@
 ; RUN: opt < %s -mtriple=x86_64-scei-ps4 -passes=instrprof -S | FileCheck %s --check-prefixes=ELF,PS
 ; RUN: opt < %s -mtriple=x86_64-sie-ps5 -passes=instrprof -S | FileCheck %s --check-prefixes=ELF,PS
 ; RUN: opt < %s  -mtriple=x86_64-pc-win32-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
+; RUN: opt < %s  -mtriple=x86_64-unknown-coff -passes=instrprof -S | FileCheck %s --check-prefixes=COFF
 ; RUN: opt < %s -mtriple=powerpc64-ibm-aix-xcoff -passes=instrprof -S | FileCheck %s --check-prefixes=XCOFF
 ; RUN: opt < %s -mtriple=x86_64-pc-freebsd13 -passes=instrprof -S | FileCheck %s --check-prefixes=ELF
 
Index: llvm/test/ExecutionEngine/RuntimeDyld/X86/coff-alignment.ll
===
--- llvm/test/ExecutionEngine/RuntimeDyld/X86/coff-alignment.ll
+++ llvm/test/ExecutionEngine/RuntimeDyld/X86/coff-alignment.ll
@@ -1,6 +1,7 @@
 ; XFAIL: target=aarch64-pc-windows-{{.*}}
 ; REQUIRES: system-windows
 ; RUN: opt -mtriple=x86_64-pc-win32-coff %s -o - | lli
+; RUN: opt -mtriple=x86_64-unknown-coff %s -o - | lli
 
 @o = common global i32 0, align 4
 
Index: llvm/lib/TargetParser/Triple.cpp
===
--- llvm/lib/TargetParser/Triple.cpp
+++ llvm/lib/TargetParser/Triple.cpp
@@ -238,6 +238,7 @@
   case RTEMS: return "rtems";
   case Solaris: return "solaris";
   case TvOS: return "tvos";
+  case UEFI: return "uefi";
   case WASI: return "wasi";
   case WatchOS: return "watchos";
   case Win32: return "windows";
@@ -588,6 +589,7 @@
 .StartsWith("netbsd", Triple::NetBSD)
 .StartsWith("openbsd", Triple::OpenBSD)
 .StartsWith("solaris", Triple::Solaris)
+.StartsWith("uefi", Triple::UEFI)
 .StartsWith("win32", Triple::Win32)
 .StartsWith("windows", Triple::Win32)
 .StartsWith("zos", Triple::ZOS)
Index: llvm/lib/Target/X86/X86MCInstLower.cpp
===
--- llvm/lib/Target/X86/X86MCInstLower.cpp
+++ llvm/lib/Target/X86/X86MCInstLower.cpp
@@ -1555,7 +1555,8 @@
 
 void X86AsmPrinter::EmitSEHInstruction(const MachineInstr *MI) {
   assert(MF->hasWinCFI() && "SEH_ instruction in function without WinCFI?");
-  assert(getSubtarget().isOSWindows() && "SEH_ instruction Windows only");
+  assert((getSubtarget().isOSWindows() || TM.getTargetTriple().isUEFI()) &&
+ "SEH_ instruction Windows and UEFI only");
 
   // Use the .cv_fpo directives if we're emitting CodeView on 32-bit x86.
   if (EmitFPOData) {
Index: llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
===
--- llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
+++ llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
@@ -441,6 +441,8 @@
   } else if (TheTriple.isOSCygMing() ||
  TheTriple.isWindowsItaniumEnvironment()) {
 MAI = new X86MCAsmInfoGNUCOFF(TheTriple);
+  } else if (TheTriple.isUEFI()) {
+

[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Taking a step back for a moment: what is the intended use case for this? My 
concern is that most of the time you're going to want to make O(N) such queries 
into a pack of N elements, resulting in O(N^2) compile time, much like we 
regrettably get from uses of `__type_pack_element`. If we can avoid the regret 
in this case by providing a different intrinsic, perhaps we should do so. (For 
example, we could take two packs of types, and produce a sequence of integers 
giving the indexes of each of the first types in the second list, in O(N) time. 
And similarly we could add a `__type_pack_elements` that takes a pack of types 
and a pack of indexes and performs N indexing operations at once, in O(N) time, 
rather than having the program do it in O(N^2) time.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D134334: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

2023-06-02 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: clang/lib/Parse/ParseTentative.cpp:1553-1554
 return TPResult::Error;
-  if (Tok.isNot(tok::identifier))
+  if (NextToken().isNot(tok::identifier))
 break;
 }

shafik wrote:
> cor3ntin wrote:
> > rsmith wrote:
> > > This doesn't seem correct to me. If we had `scope::foo bar`, and we 
> > > annotate `scope::foo` as a type, then this will get confused by the next 
> > > token now being an (unrelated) identifier. This code is trying to detect 
> > > if an annotation was performed, so I think it intended to check if the 
> > > current token's kind has changed, like is done on line 1295.
> > The confusing bit is that Tok is always an annotated scope already here 
> > (L1598), so TryAnnotateName should not modify that first token (unless 
> > TryAnnotateTypeOrScopeTokenAfterScopeSpec can somehow replace the current 
> > annot_cxxscope by another one, which i don't think can happen?) 
> Ok using `tok::annot_cxxscope` also works and I agree it makes sense as well, 
> `check-clang` also passes.
> 
> So then is the assert below wrong?
> 
> ```
>   // Annotated it, check again.
>   assert(Tok.isNot(tok::annot_cxxscope) ||
>  NextToken().isNot(tok::identifier));
> ```
> 
> It looks like it will work by accident for most cases b/c it checks 
> `tok::annot_cxxscope` first. 
> The confusing bit is that Tok is always an annotated scope already here 
> (L1598), so TryAnnotateName should not modify that first token (unless 
> TryAnnotateTypeOrScopeTokenAfterScopeSpec can somehow replace the current 
> annot_cxxscope by another one, which i don't think can happen?)

Yeah, I think `TryAnnotateTypeOrScopeToken` shouldn't ever replace an 
`annot_cxxscope` token with a different `annot_cxxscope` token representing a 
longer scope specifier -- an `annot_cxxscope` token should always be as long as 
it can be. But it might replace the `annot_cxxscope` token with an 
`annot_typename`, in which case we want to jump out to line 1671 and try again.

> So then is the assert below wrong?

I think it's right -- we either reach the assert if we replace the 
`annot_cxxscope` with something else (an `annot_typename`), in the 
`ANK_TemplateName` case, or if we've successfully annotated the name (as one of 
various non-identifier things), in the `ANK_Success` case. In either case, we 
only reach the assert if we successfully replaced the identifier with an 
annotation token, so the assert should succeed.

And the point of the assert, I think, is to ensure that the recursive call to 
`isCXXDeclarationSpecifier` cannot reach this same codepath again and recurse 
forever, so checking the same condition that we checked on entry seems 
appropriate.


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

https://reviews.llvm.org/D134334

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


[PATCH] D132275: [clang] Create alloca to pass into static lambda

2023-06-02 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added subscribers: jdoerfert, leonardchan.
leonardchan added a comment.

Hi. For an embedded device, prior to this patch, we used to be able to see a 
significant savings of 28kB when we enabled the attributor. But with this 
patch, we don't see these savings anymore when enabling the attributor. I don't 
suppose folks might have any ideas on how this might affect the attributor? I'm 
going to attempt to make a minimal reproducer. Just chiming in early in case 
anyone might happen to know off the top of their head.

cc @jdoerfert who owns the attributor


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132275

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


[clang] 14c44df - clang: Update tests after InstSimplify change

2023-06-02 Thread Matt Arsenault via cfe-commits

Author: Matt Arsenault
Date: 2023-06-02T18:47:58-04:00
New Revision: 14c44dfbcf1d6f81c1cdaa90ed243b3d53147903

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

LOG: clang: Update tests after InstSimplify change

Update tests after 1536e299e63d7788f38117b0212ca50eb76d7a3b

Added: 


Modified: 
clang/test/CodeGen/arm_acle.c
clang/test/Headers/__clang_hip_math.hip

Removed: 




diff  --git a/clang/test/CodeGen/arm_acle.c b/clang/test/CodeGen/arm_acle.c
index d3ea9ded6583d..742570d32789d 100644
--- a/clang/test/CodeGen/arm_acle.c
+++ b/clang/test/CodeGen/arm_acle.c
@@ -145,7 +145,7 @@ void test_dbg(void) {
 // AArch32-NEXT:[[LDREX_I:%.*]] = call i32 @llvm.arm.ldrex.p0(ptr 
elementtype(i32) [[P:%.*]])
 // AArch32-NEXT:[[STREX_I:%.*]] = call i32 @llvm.arm.strex.p0(i32 
[[X:%.*]], ptr elementtype(i32) [[P]])
 // AArch32-NEXT:[[TOBOOL_I:%.*]] = icmp ne i32 [[STREX_I]], 0
-// AArch32-NEXT:br i1 [[TOBOOL_I]], label [[DO_BODY_I]], label 
[[__SWP_EXIT:%.*]], !llvm.loop [[LOOP7:![0-9]+]]
+// AArch32-NEXT:br i1 [[TOBOOL_I]], label [[DO_BODY_I]], label 
[[__SWP_EXIT:%.*]], !llvm.loop [[LOOP3:![0-9]+]]
 // AArch32:   __swp.exit:
 // AArch32-NEXT:ret void
 //
@@ -154,11 +154,11 @@ void test_dbg(void) {
 // AArch64-NEXT:br label [[DO_BODY_I:%.*]]
 // AArch64:   do.body.i:
 // AArch64-NEXT:[[LDXR_I:%.*]] = call i64 @llvm.aarch64.ldxr.p0(ptr 
elementtype(i32) [[P:%.*]])
-// AArch64-NEXT:[[TMP1:%.*]] = trunc i64 [[LDXR_I]] to i32
-// AArch64-NEXT:[[TMP2:%.*]] = zext i32 [[X:%.*]] to i64
-// AArch64-NEXT:[[STXR_I:%.*]] = call i32 @llvm.aarch64.stxr.p0(i64 
[[TMP2]], ptr elementtype(i32) [[P]])
+// AArch64-NEXT:[[TMP0:%.*]] = trunc i64 [[LDXR_I]] to i32
+// AArch64-NEXT:[[TMP1:%.*]] = zext i32 [[X:%.*]] to i64
+// AArch64-NEXT:[[STXR_I:%.*]] = call i32 @llvm.aarch64.stxr.p0(i64 
[[TMP1]], ptr elementtype(i32) [[P]])
 // AArch64-NEXT:[[TOBOOL_I:%.*]] = icmp ne i32 [[STXR_I]], 0
-// AArch64-NEXT:br i1 [[TOBOOL_I]], label [[DO_BODY_I]], label 
[[__SWP_EXIT:%.*]], !llvm.loop [[LOOP6:![0-9]+]]
+// AArch64-NEXT:br i1 [[TOBOOL_I]], label [[DO_BODY_I]], label 
[[__SWP_EXIT:%.*]], !llvm.loop [[LOOP2:![0-9]+]]
 // AArch64:   __swp.exit:
 // AArch64-NEXT:ret void
 //
@@ -484,17 +484,17 @@ uint32_t test_rev16(uint32_t t) {
 // AArch64-NEXT:[[TMP0:%.*]] = call i32 @llvm.bswap.i32(i32 [[CONV_I]])
 // AArch64-NEXT:[[REM_I_I10_I:%.*]] = urem i32 16, 32
 // AArch64-NEXT:[[CMP_I_I11_I:%.*]] = icmp eq i32 [[REM_I_I10_I]], 0
-// AArch64-NEXT:br i1 [[CMP_I_I11_I]], label [[IF_THEN_I_I12_I:%.*]], 
label [[IF_END_I_I17_I:%.*]]
-// AArch64:   if.then.i.i12.i:
+// AArch64-NEXT:br i1 [[CMP_I_I11_I]], label [[IF_THEN_I_I17_I:%.*]], 
label [[IF_END_I_I12_I:%.*]]
+// AArch64:   if.then.i.i17.i:
 // AArch64-NEXT:br label [[__REV16_EXIT18_I:%.*]]
-// AArch64:   if.end.i.i17.i:
+// AArch64:   if.end.i.i12.i:
 // AArch64-NEXT:[[SHR_I_I13_I:%.*]] = lshr i32 [[TMP0]], [[REM_I_I10_I]]
 // AArch64-NEXT:[[SUB_I_I14_I:%.*]] = sub i32 32, [[REM_I_I10_I]]
 // AArch64-NEXT:[[SHL_I_I15_I:%.*]] = shl i32 [[TMP0]], [[SUB_I_I14_I]]
 // AArch64-NEXT:[[OR_I_I16_I:%.*]] = or i32 [[SHR_I_I13_I]], 
[[SHL_I_I15_I]]
 // AArch64-NEXT:br label [[__REV16_EXIT18_I]]
 // AArch64:   __rev16.exit18.i:
-// AArch64-NEXT:[[RETVAL_I_I6_I_0:%.*]] = phi i32 [ [[TMP0]], 
[[IF_THEN_I_I12_I]] ], [ [[OR_I_I16_I]], [[IF_END_I_I17_I]] ]
+// AArch64-NEXT:[[RETVAL_I_I6_I_0:%.*]] = phi i32 [ [[TMP0]], 
[[IF_THEN_I_I17_I]] ], [ [[OR_I_I16_I]], [[IF_END_I_I12_I]] ]
 // AArch64-NEXT:[[CONV1_I:%.*]] = zext i32 [[RETVAL_I_I6_I_0]] to i64
 // AArch64-NEXT:[[SHL_I:%.*]] = shl i64 [[CONV1_I]], 32
 // AArch64-NEXT:[[CONV2_I:%.*]] = trunc i64 [[T]] to i32
@@ -527,17 +527,17 @@ long test_rev16l(long t) {
 // ARM-NEXT:[[TMP0:%.*]] = call i32 @llvm.bswap.i32(i32 [[CONV_I]])
 // ARM-NEXT:[[REM_I_I10_I:%.*]] = urem i32 16, 32
 // ARM-NEXT:[[CMP_I_I11_I:%.*]] = icmp eq i32 [[REM_I_I10_I]], 0
-// ARM-NEXT:br i1 [[CMP_I_I11_I]], label [[IF_THEN_I_I12_I:%.*]], label 
[[IF_END_I_I17_I:%.*]]
-// ARM:   if.then.i.i12.i:
+// ARM-NEXT:br i1 [[CMP_I_I11_I]], label [[IF_THEN_I_I17_I:%.*]], label 
[[IF_END_I_I12_I:%.*]]
+// ARM:   if.then.i.i17.i:
 // ARM-NEXT:br label [[__REV16_EXIT18_I:%.*]]
-// ARM:   if.end.i.i17.i:
+// ARM:   if.end.i.i12.i:
 // ARM-NEXT:[[SHR_I_I13_I:%.*]] = lshr i32 [[TMP0]], [[REM_I_I10_I]]
 // ARM-NEXT:[[SUB_I_I14_I:%.*]] = sub i32 32, [[REM_I_I10_I]]
 // ARM-NEXT:[[SHL_I_I15_I:%.*]] = shl i32 [[TMP0]], [[SUB_I_I14_I]]
 // ARM-NEXT:[[OR_I_I16_I:%.*]] = or i32 [[SHR_I_I13_I]], [[SHL_I_I15_I]]
 // ARM-NEXT:br label [[__REV16_EXIT18_I]]
 // ARM:

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

2023-06-02 Thread Kiran Chandramohan via Phabricator via cfe-commits
kiranchandramohan added inline comments.



Comment at: flang/lib/Lower/Bridge.cpp:271
+bridge{bridge}, foldingContext{bridge.createFoldingContext()},
+ompRequiresFlags{mlir::omp::ClauseRequires::none} {}
   virtual ~FirConverter() = default;

Is this set anywhere? If not is it required? Can this be made available through 
the bridge?



Comment at: flang/lib/Lower/Bridge.cpp:2234
+  /// Extract information from OpenMP declarative constructs
+  void analyzeOpenMPDeclarative(
+  const Fortran::parser::OpenMPDeclarativeConstruct ) {

Can this function be moved to OpenMP.cpp?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147218

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


[PATCH] D152009: [clang] Fix assertion while parsing an invalid for loop

2023-06-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/lib/Parse/ParseStmt.cpp:2200
 Diag(Tok, diag::err_expected_semi_for);
-  else
-// Skip until semicolon or rparen, don't consume it.

Can you explain why you removed this?



Comment at: clang/test/Parser/cxx0x-for-range.cpp:67
+int a[] = {1, 2, 3, 4, 5};
+for (auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' 
statement specifier}} \
+  // expected-error {{expected expression}}

Did you try dropping the `;` at the end of this line to make sure it still does 
what we expect?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152009

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


[PATCH] D151834: Include math-errno with fast-math

2023-06-02 Thread Andy Kaylor via Phabricator via cfe-commits
andrew.w.kaylor added inline comments.



Comment at: clang/include/clang/Basic/FPOptions.def:30
 OPTION(BFloat16ExcessPrecision, LangOptions::ExcessPrecisionKind, 2, 
FPEvalMethod)
+OPTION(MathErrno, bool, 1, BFloat16ExcessPrecision)
 #undef OPTION

Does this mean MathErrno is tracked in both LangOpts and FPOptions?



Comment at: clang/lib/CodeGen/CGBuiltin.cpp:2248
   FD->hasAttr() ? 0 : BuiltinID;
+  bool MathErrnoOverrride = false;
+  if (E->hasStoredFPFeatures()) {

You should add a comment here explaining what this is doing. I don't think it's 
obvious apart from the description of this patch.



Comment at: clang/lib/CodeGen/CGCall.cpp:2384
 
+  if (HasOptnone && !getLangOpts().MathErrno)
+OptNone = false;

I don't understand what this is doing.



Comment at: clang/lib/CodeGen/CodeGenModule.h:611
   void clear();
+  bool OptNone = true;
 

Why is this a module level flag, and why does it default to true?



Comment at: clang/test/CodeGen/math-errno.c:2
+// Tests that at -O2 math-errno is taken into account. Same than MSVC.
+// RUN: %clang_cc1 -Wno-implicit-function-declaration -fmath-errno \
+// RUN: -O2 -emit-llvm -o - %s \

Isn't math-errno true by default when fast-math isn't used?



Comment at: clang/test/CodeGen/math-errno.c:33
+
+__attribute__((optnone))
+float f4(float x) { 

Can you add a runline with -O0. That should prevent all instances of the 
intrinsics, right?



Comment at: clang/test/CodeGen/math-errno.c:49
+// FAST-LABEL: define dso_local nofpclass(nan inf) float @f4(float noundef 
nofpclass(nan inf) {{.*}})
+// FAST: call reassoc nnan ninf nsz arcp afn nofpclass(nan inf) float 
@sqrtf(float noundef nofpclass(nan inf) %0) #[[ATTR0:[0-9]+]]
+

I think the 'afn' flag here is a problem. The backend has no concept of errno, 
so 'afn' will be treated as allowing the function to be replaced.


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

https://reviews.llvm.org/D151834

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


[PATCH] D134334: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

2023-06-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added a comment.

`clang/test/ClangScanDeps/modules-full.cpp ` passes locally for me and I don't 
see why my change would effect this test.


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

https://reviews.llvm.org/D134334

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


[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5620
 
+  if (Kind == clang::TT_TypePackIndex)
+return EvaluateIntegralTypeTrait(*this, Kind, KWLoc, Args, RParenLoc,

cjdb wrote:
> erichkeane wrote:
> > I realize this is the 1st, but this seems like it is going to be a 
> > maintenance pain.  Can you at least split this into a static-function of 
> > `IsIntegralTypeTrait` that we can use later with table-gen if this gets out 
> > of hand?
> Done, but in D152034. It's a change that should happen independently of this 
> one IMO.
Thanks! THat looks good.  


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 527978.
nickdesaulniers marked an inline comment as done.
nickdesaulniers added a comment.

- remove unnecessary Visit*CastExpr overrides


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
   // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
+  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
Index: clang/test/CodeGenCXX/const-init-cxx11.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -88,7 +88,7 @@
 
   struct E {};
   struct Test2 : X, X, X, X {};
-  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} undef
+  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} zeroinitializer, align 1
   extern constexpr Test2 t2 = Test2();
 
   struct __attribute((packed)) PackedD { double y = 2; };
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1216,8 +1216,10 @@
   }
 
   llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-QualType T) {
-return Visit(E->getSubExpr(), T);
+  QualType T) {
+if (E->isLValue() || E->isXValue())
+  return Visit(E->getSubExpr(), T);
+return nullptr;
   }
 
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
@@ -1276,6 +1278,9 @@
   }
 
   llvm::Constant *VisitInitListExpr(InitListExpr *ILE, QualType T) {
+if (ILE->getNumInits() && isa(ILE->getInit(0)))
+return nullptr;
+
 if (ILE->isTransparent())
   return Visit(ILE->getInit(0), T);
 
@@ -1655,27 +1660,27 @@
 
   QualType destType = D.getType();
 
-  // Try to emit the initializer.  Note that this can allow some things that
-  // are not allowed by tryEmitPrivateForMemory alone.
-  if (APValue *value = D.evaluateValue())
-return tryEmitPrivateForMemory(*value, destType);
-
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a temporary,
   // then constant initialization is performed. ConstExprEmitter will
   // incorrectly emit a prvalue constant in this case, and the calling code
   // interprets that as the (pointer) value of the reference, rather than the
   // desired value of the referee.
-  if (destType->isReferenceType())
-return nullptr;
 
   const Expr *E = D.getInit();
   assert(E && "No initializer to emit");
 
   QualType nonMemoryDestType = getNonMemoryType(CGM, destType);
-  if (llvm::Constant *C = ConstExprEmitter(*this).Visit(const_cast(E),
-nonMemoryDestType))
-return emitForMemory(C, destType);
+  if (!destType->isReferenceType())
+if (llvm::Constant *C = ConstExprEmitter(*this).Visit(const_cast(E),
+  nonMemoryDestType))
+  return emitForMemory(C, destType);
+
+  // Try to emit the initializer.  Note that this can allow some things that
+  // are not allowed by 

[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5620
 
+  if (Kind == clang::TT_TypePackIndex)
+return EvaluateIntegralTypeTrait(*this, Kind, KWLoc, Args, RParenLoc,

erichkeane wrote:
> I realize this is the 1st, but this seems like it is going to be a 
> maintenance pain.  Can you at least split this into a static-function of 
> `IsIntegralTypeTrait` that we can use later with table-gen if this gets out 
> of hand?
Done, but in D152034. It's a change that should happen independently of this 
one IMO.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D152034: [clang][NFC] refactors value type traits so we can have more than bools

2023-06-02 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb created this revision.
cjdb added reviewers: erichkeane, dblaikie.
Herald added a project: All.
cjdb requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Since all the type traits up until now have had Boolean vaules, we've
always been able to assume that the expressions are `bool`. This is
about to change (D151952  introduces a trait 
that returns `size_t`), so
we need to restructure the code so it doesn't become unwieldy.

This is achieved by giving traits a designated "return" type.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152034

Files:
  clang/lib/Sema/SemaExprCXX.cpp


Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -5378,9 +5378,14 @@
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
-static bool evaluateTypeTrait(Sema , TypeTrait Kind, SourceLocation KWLoc,
-  ArrayRef Args,
-  SourceLocation RParenLoc) {
+static bool EvaluateBooleanTypeTrait(Sema , TypeTrait Kind,
+ SourceLocation KWLoc,
+ ArrayRef Args,
+ SourceLocation RParenLoc,
+ bool IsDependent) {
+  if (IsDependent)
+return false;
+
   if (Kind <= UTT_Last)
 return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType());
 
@@ -5548,12 +5553,19 @@
   return true;
 }
 
+enum class TypeTraitReturnType {
+  Bool,
+};
+
+static TypeTraitReturnType GetReturnType(TypeTrait Kind) {
+  return TypeTraitReturnType::Bool;
+}
+
 ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
 ArrayRef Args,
 SourceLocation RParenLoc) {
   if (!CheckTypeTraitArity(getTypeTraitArity(Kind), KWLoc, Args.size()))
 return ExprError();
-  QualType ResultType = Context.getLogicalOperationType();
 
   if (Kind <= UTT_Last && !CheckUnaryTypeTraitTypeCompleteness(
*this, Kind, KWLoc, Args[0]->getType()))
@@ -5569,12 +5581,17 @@
 }
   }
 
-  bool Result = false;
-  if (!Dependent)
-Result = evaluateTypeTrait(*this, Kind, KWLoc, Args, RParenLoc);
-
-  return TypeTraitExpr::Create(Context, ResultType, KWLoc, Kind, Args,
-   RParenLoc, Result);
+  switch (GetReturnType(Kind)) {
+  case TypeTraitReturnType::Bool: {
+bool Result = EvaluateBooleanTypeTrait(*this, Kind, KWLoc, Args, RParenLoc,
+   Dependent);
+return TypeTraitExpr::Create(Context, Context.getLogicalOperationType(),
+ KWLoc, Kind, Args, RParenLoc, Result);
+  }
+  default:
+llvm_unreachable("reached the end of BuildTypeTrait because the type "
+ "trait's type is unaccounted for");
+  }
 }
 
 ExprResult Sema::ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc,


Index: clang/lib/Sema/SemaExprCXX.cpp
===
--- clang/lib/Sema/SemaExprCXX.cpp
+++ clang/lib/Sema/SemaExprCXX.cpp
@@ -5378,9 +5378,14 @@
 static bool EvaluateBinaryTypeTrait(Sema , TypeTrait BTT, QualType LhsT,
 QualType RhsT, SourceLocation KeyLoc);
 
-static bool evaluateTypeTrait(Sema , TypeTrait Kind, SourceLocation KWLoc,
-  ArrayRef Args,
-  SourceLocation RParenLoc) {
+static bool EvaluateBooleanTypeTrait(Sema , TypeTrait Kind,
+ SourceLocation KWLoc,
+ ArrayRef Args,
+ SourceLocation RParenLoc,
+ bool IsDependent) {
+  if (IsDependent)
+return false;
+
   if (Kind <= UTT_Last)
 return EvaluateUnaryTypeTrait(S, Kind, KWLoc, Args[0]->getType());
 
@@ -5548,12 +5553,19 @@
   return true;
 }
 
+enum class TypeTraitReturnType {
+  Bool,
+};
+
+static TypeTraitReturnType GetReturnType(TypeTrait Kind) {
+  return TypeTraitReturnType::Bool;
+}
+
 ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc,
 ArrayRef Args,
 SourceLocation RParenLoc) {
   if (!CheckTypeTraitArity(getTypeTraitArity(Kind), KWLoc, Args.size()))
 return ExprError();
-  QualType ResultType = Context.getLogicalOperationType();
 
   if (Kind <= UTT_Last && !CheckUnaryTypeTraitTypeCompleteness(
*this, Kind, KWLoc, Args[0]->getType()))
@@ -5569,12 +5581,17 @@
 }
   }
 
-  bool Result = false;
-  if (!Dependent)
-Result = evaluateTypeTrait(*this, Kind, KWLoc, Args, 

[PATCH] D152027: [CUDA] Update Kepler(sm_3*) support info.

2023-06-02 Thread Artem Belevich 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 rG0f49116e261c: [CUDA] Update Kepler(sm_3*) support info. 
(authored by tra).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152027

Files:
  clang/lib/Basic/Cuda.cpp


Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -222,7 +222,11 @@
   case CudaArch::SM_21:
 return CudaVersion::CUDA_80;
   case CudaArch::SM_30:
-return CudaVersion::CUDA_110;
+  case CudaArch::SM_32:
+return CudaVersion::CUDA_102;
+  case CudaArch::SM_35:
+  case CudaArch::SM_37:
+return CudaVersion::CUDA_118;
   default:
 return CudaVersion::NEW;
   }


Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -222,7 +222,11 @@
   case CudaArch::SM_21:
 return CudaVersion::CUDA_80;
   case CudaArch::SM_30:
-return CudaVersion::CUDA_110;
+  case CudaArch::SM_32:
+return CudaVersion::CUDA_102;
+  case CudaArch::SM_35:
+  case CudaArch::SM_37:
+return CudaVersion::CUDA_118;
   default:
 return CudaVersion::NEW;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 0f49116 - [CUDA] Update Kepler(sm_3*) support info.

2023-06-02 Thread Artem Belevich via cfe-commits

Author: Artem Belevich
Date: 2023-06-02T14:16:13-07:00
New Revision: 0f49116e261cf5a156221b006acb677e3565fd1a

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

LOG: [CUDA] Update Kepler(sm_3*) support info.

sm_30 and sm_32 were removed in cuda-11.0
sm_35 and sm_37 were removed in cuda-12.0

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

Added: 


Modified: 
clang/lib/Basic/Cuda.cpp

Removed: 




diff  --git a/clang/lib/Basic/Cuda.cpp b/clang/lib/Basic/Cuda.cpp
index 7299b9f485ec2..356bfd6bd784f 100644
--- a/clang/lib/Basic/Cuda.cpp
+++ b/clang/lib/Basic/Cuda.cpp
@@ -222,7 +222,11 @@ CudaVersion MaxVersionForCudaArch(CudaArch A) {
   case CudaArch::SM_21:
 return CudaVersion::CUDA_80;
   case CudaArch::SM_30:
-return CudaVersion::CUDA_110;
+  case CudaArch::SM_32:
+return CudaVersion::CUDA_102;
+  case CudaArch::SM_35:
+  case CudaArch::SM_37:
+return CudaVersion::CUDA_118;
   default:
 return CudaVersion::NEW;
   }



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


[PATCH] D151923: [APFloat] Add APFloat semantic support for TF32

2023-06-02 Thread Jeremy Furtek via Phabricator via cfe-commits
jfurtek added inline comments.



Comment at: llvm/include/llvm/ADT/APFloat.h:190
+// greater throughput than single precision (32-bit) formats.
+S_FloatTF32,
 

majnemer wrote:
> Hmm,  this says improved precision than half but the semantics you gave say 
> 11 digits? Does NVIDIA document how many bits we should expect?
This was a mistake on my part - the **range** is better than FP16, not the 
**precision**. Updated the comment to reflect this.

The blog post linked in the description provides details on the current format 
only - I agree that the PTX description seems intentionally vague.



Comment at: llvm/lib/Support/APFloat.cpp:141
 4, -10, 4, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloatTF32 = {127, -126, 11, 19};
 static constexpr fltSemantics semX87DoubleExtended = {16383, -16382, 64, 80};

majnemer wrote:
> NVIDIA's 
> [docs](https://docs.nvidia.com/cuda/parallel-thread-execution/#alternate-floating-point-data-formats)
>  say:
> > This data format is a special 32-bit floating point format supported by the 
> > matrix multiply-and-accumulate instructions, with the same range as .f32 
> > and reduced precision (>=10 bits). The internal layout of tf32 format is 
> > implementation defined. PTX facilitates conversion from single precision 
> > .f32 type to tf32 format. A register variable containing tf32 data must be 
> > declared with .b32 type.
> 
> As written, it's at least 11 bits but it can change over time. Will we need 
> corresponding flavors of this for future architectures over time?
If it changes, we would need to create a different float semantic to represent 
the new format (i.e. perhaps `TF32v2` or something like that).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151923

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1324
 // This is a string literal initializing an array in an initializer.
-return CGM.GetConstantArrayFromStringLiteral(E);
+return E->isLValue() ?
+  CGM.GetAddrOfConstantStringFromLiteral(E).getPointer() :

efriedma wrote:
> efriedma wrote:
> > nickdesaulniers wrote:
> > > efriedma wrote:
> > > > nickdesaulniers wrote:
> > > > > nickdesaulniers wrote:
> > > > > > efriedma wrote:
> > > > > > > nickdesaulniers wrote:
> > > > > > > > efriedma wrote:
> > > > > > > > > Maybe we should have a separate ConstExprEmitterLValue... 
> > > > > > > > > trying to handle both LValues and RValues on the same 
> > > > > > > > > codepath has been problematic in the past.  It's very easy 
> > > > > > > > > for code to get confused what it's actually trying to emit.
> > > > > > > > So we'd have a `ConstExprEmitterLValue` class with some visitor 
> > > > > > > > methods, and a `ConstExprEmitterRValue` with other methods 
> > > > > > > > implemented?
> > > > > > > Something like that.
> > > > > > > 
> > > > > > > Actually thinking about it a bit more, not sure you need to 
> > > > > > > actually implement ConstExprEmitterLValue for now.  You might 
> > > > > > > just be able to ensure we don't ever call ConstExprEmitter with 
> > > > > > > an lvalue.  The current ConstExprEmitter doesn't expect lvalues, 
> > > > > > > and shouldn't call itself with lvalues.  (We bail on explicit 
> > > > > > > LValueToRValue conversions.)  And Evaluate() shouldn't actually 
> > > > > > > evaluate the contents of an lvalue if it isn't dereferenced, so 
> > > > > > > there hopefully aren't any performance issues using that codepath.
> > > > > > > 
> > > > > > > In terms of implementation, I guess that's basically restoring 
> > > > > > > the destType->isReferenceType() that got removed?  (I know I 
> > > > > > > suggested it, but I wasn't really thinking about it...)
> > > > > > One thing I think we may need to add to `ConstExprEmitter` is the 
> > > > > > ability to evaluate `CallExpr`s based on certain test case 
> > > > > > failures...does that seem right?
> > > > > See also the calls to `constexpr f()` in 
> > > > > clang/test/CodeGenCXX/const-init-cxx1y.cpp
> > > > The only things I know of that Evaluate() can't handle are CK_ToUnion, 
> > > > CK_ReinterpretMemberPointer, and DesignatedInitUpdateExpr.  
> > > > DesignatedInitUpdateExpr is related to the failures in 
> > > > test/CodeGenCXX/designated-init.cpp; I don't think the others show up 
> > > > in any of the testcases you've mentioned.  (CK_ToUnion can't appear in 
> > > > C++ code. CK_ReinterpretMemberPointer is a `reinterpret_cast` where 
> > > > T is a member pointer type.)
> > > > 
> > > > Given none of those constructs show up in const-init-cxx1y.cpp, the 
> > > > only reason for it to fail is if we aren't correctly falling back for a 
> > > > construct the current code doesn't know how to handle.  You shouldn't 
> > > > need to implement any new constructs.
> > > in clang/test/CodeGenCXX/designated-init.cpp we have:
> > > ```
> > > >> 22 namespace ModifyStaticTemporary {   
> > > >> 
> > >23   struct A { int & int x; }; 
> > > 
> > >24   constexpr int f(int ) { r *= 9; return r - 12; }
> > > 
> > >25   A a = { 6, f(a.temporary) };
> > > ```
> > > In the AST, that looks like:
> > > ```
> > > | |-VarDecl 0x562b77df39b0  col:5 used a 
> > > 'A':'ModifyStaticTemporary::A' cinit
> > > | | `-ExprWithCleanups 0x562b77df3c68  
> > > 'A':'ModifyStaticTemporary::A'
> > > | |   `-InitListExpr 0x562b77df3bb8  
> > > 'A':'ModifyStaticTemporary::A'
> > > | | |-MaterializeTemporaryExpr 0x562b77df3c08  'int' xvalue 
> > > extended by Var 0x562b77df39b0 'a' 'A':'ModifyStaticTemporary::A'
> > > | | | `-IntegerLiteral 0x562b77df3a18  'int' 6
> > > | | `-CallExpr 0x562b77df3b30  'int'
> > > | |   |-ImplicitCastExpr 0x562b77df3b18  'int (*)(int &)' 
> > > 
> > > | |   | `-DeclRefExpr 0x562b77df3ad0  'int (int &)' lvalue 
> > > Function 0x562b77df37a0 'f' 'int (int &)'
> > > | |   `-MemberExpr 0x562b77df3aa0  'int' lvalue 
> > > .temporary 0x562b77df35c0
> > > | | `-DeclRefExpr 0x562b77df3a80  
> > > 'A':'ModifyStaticTemporary::A' lvalue Var 0x562b77df39b0 'a' 
> > > 'A':'ModifyStaticTemporary::A'
> > > ```
> > > (So, indeed no `DesignatedInitUpdateExpr`) but the call to the 
> > > `constexpr` `f()` updates the reference (to `54`).  If I remove the 
> > > visitor for `MaterializeTemporaryExpr`, we fail to evaluate `f` and end 
> > > up emitting `6` rather than `54`.  Doesn't that mean that the fast path 
> > > (`ConstExprEmitter`) needs to be able to evaluate `CallExpr`?
> > > 
> > > Or should `VisitInitListExpr` bail if any of the inits 
> > > `isa` (or perhaps `isa`)?
> > There are a few related cases here.
> > 

[PATCH] D151923: [APFloat] Add APFloat semantic support for TF32

2023-06-02 Thread Jeremy Furtek via Phabricator via cfe-commits
jfurtek updated this revision to Diff 527968.
jfurtek added a comment.

- Fix comment and clang-formatting


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151923

Files:
  clang/lib/AST/MicrosoftMangle.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp
  llvm/unittests/ADT/APFloatTest.cpp

Index: llvm/unittests/ADT/APFloatTest.cpp
===
--- llvm/unittests/ADT/APFloatTest.cpp
+++ llvm/unittests/ADT/APFloatTest.cpp
@@ -682,6 +682,27 @@
 EXPECT_TRUE(T.isDenormal());
 EXPECT_EQ(fcPosSubnormal, T.classify());
   }
+
+  // Test TF32
+  {
+const char *MinNormalStr = "1.17549435082228750797e-38";
+EXPECT_FALSE(APFloat(APFloat::FloatTF32(), MinNormalStr).isDenormal());
+EXPECT_FALSE(APFloat(APFloat::FloatTF32(), 0).isDenormal());
+
+APFloat Val2(APFloat::FloatTF32(), 2);
+APFloat T(APFloat::FloatTF32(), MinNormalStr);
+T.divide(Val2, rdmd);
+EXPECT_TRUE(T.isDenormal());
+EXPECT_EQ(fcPosSubnormal, T.classify());
+
+
+const char *NegMinNormalStr = "-1.17549435082228750797e-38";
+EXPECT_FALSE(APFloat(APFloat::FloatTF32(), NegMinNormalStr).isDenormal());
+APFloat NegT(APFloat::FloatTF32(), NegMinNormalStr);
+NegT.divide(Val2, rdmd);
+EXPECT_TRUE(NegT.isDenormal());
+EXPECT_EQ(fcNegSubnormal, NegT.classify());
+  }
 }
 
 TEST(APFloatTest, IsSmallestNormalized) {
@@ -1350,6 +1371,16 @@
 {   0x80ULL, APFloat::Float8E4M3B11FNUZ(), false, true, 0xaaULL },
 {   0x80ULL, APFloat::Float8E4M3B11FNUZ(), true, false, 0xaaULL },
 {   0x80ULL, APFloat::Float8E4M3B11FNUZ(), true, true,  0xaaULL },
+{0x3fe00ULL, APFloat::FloatTF32(), false, false,  0xULL },
+{0x7fe00ULL, APFloat::FloatTF32(), false,  true,  0xULL },
+{0x3feaaULL, APFloat::FloatTF32(), false, false,0xaaULL },
+{0x3ffaaULL, APFloat::FloatTF32(), false, false,   0xdaaULL },
+{0x3ffaaULL, APFloat::FloatTF32(), false, false,  0xfdaaULL },
+{0x3fd00ULL, APFloat::FloatTF32(),  true, false,  0xULL },
+{0x7fd00ULL, APFloat::FloatTF32(),  true,  true,  0xULL },
+{0x3fcaaULL, APFloat::FloatTF32(),  true, false,0xaaULL },
+{0x3fdaaULL, APFloat::FloatTF32(),  true, false,   0xfaaULL },
+{0x3fdaaULL, APFloat::FloatTF32(),  true, false,   0x1aaULL },
   // clang-format on
   };
 
@@ -1780,6 +1811,8 @@
 APFloat::getLargest(APFloat::Float8E5M2FNUZ()).convertToDouble());
   EXPECT_EQ(
   30, APFloat::getLargest(APFloat::Float8E4M3B11FNUZ()).convertToDouble());
+  EXPECT_EQ(3.40116213421e+38f,
+APFloat::getLargest(APFloat::FloatTF32()).convertToFloat());
 }
 
 TEST(APFloatTest, getSmallest) {
@@ -1831,6 +1864,14 @@
   EXPECT_TRUE(test.isFiniteNonZero());
   EXPECT_TRUE(test.isDenormal());
   EXPECT_TRUE(test.bitwiseIsEqual(expected));
+
+  test = APFloat::getSmallest(APFloat::FloatTF32(), true);
+  expected = APFloat(APFloat::FloatTF32(), "-0x0.004p-126");
+  EXPECT_TRUE(test.isNegative());
+  EXPECT_TRUE(test.isFiniteNonZero());
+  EXPECT_TRUE(test.isDenormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));
+
 }
 
 TEST(APFloatTest, getSmallestNormalized) {
@@ -1905,6 +1946,14 @@
   EXPECT_FALSE(test.isDenormal());
   EXPECT_TRUE(test.bitwiseIsEqual(expected));
   EXPECT_TRUE(test.isSmallestNormalized());
+
+  test = APFloat::getSmallestNormalized(APFloat::FloatTF32(), false);
+  expected = APFloat(APFloat::FloatTF32(), "0x1p-126");
+  EXPECT_FALSE(test.isNegative());
+  EXPECT_TRUE(test.isFiniteNonZero());
+  EXPECT_FALSE(test.isDenormal());
+  EXPECT_TRUE(test.bitwiseIsEqual(expected));
+  EXPECT_TRUE(test.isSmallestNormalized());
 }
 
 TEST(APFloatTest, getZero) {
@@ -1936,7 +1985,9 @@
   {::Float8E4M3FNUZ(), false, false, {0, 0}, 1},
   {::Float8E4M3FNUZ(), true, false, {0, 0}, 1},
   {::Float8E4M3B11FNUZ(), false, false, {0, 0}, 1},
-  {::Float8E4M3B11FNUZ(), true, false, {0, 0}, 1}};
+  {::Float8E4M3B11FNUZ(), true, false, {0, 0}, 1},
+  {::FloatTF32(), false, true, {0, 0}, 1},
+  {::FloatTF32(), true, true, {0x4ULL, 0}, 1}};
   const unsigned NumGetZeroTests = std::size(GetZeroTest);
   for (unsigned i = 0; i < NumGetZeroTests; ++i) {
 APFloat test = APFloat::getZero(*GetZeroTest[i].semantics,
@@ -6229,6 +6280,35 @@
   EXPECT_TRUE(std::isnan(QNaN.convertToDouble()));
 }
 
+TEST(APFloatTest, FloatTF32ToDouble) {
+  APFloat One(APFloat::FloatTF32(), "1.0");
+  EXPECT_EQ(1.0, One.convertToDouble());
+  APFloat PosLargest = APFloat::getLargest(APFloat::FloatTF32(), false);
+  EXPECT_EQ(3.401162134214653489792616e+38, 

[PATCH] D151964: [NFC][CLANG] Fix Static Code Analyzer Concerns with dereference null return value in applyObjCTypeArgs()

2023-06-02 Thread Soumi Manna via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG82659941ccb8: [NFC][CLANG] Fix Static Code Analyzer Concerns 
with dereference null return… (authored by Manna).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151964

Files:
  clang/lib/Sema/SemaType.cpp


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -950,7 +950,7 @@
 
   // Retrieve the bound.
   QualType bound = typeParam->getUnderlyingType();
-  const auto *boundObjC = bound->getAs();
+  const auto *boundObjC = bound->castAs();
 
   // Determine whether the type argument is substitutable for the bound.
   if (typeArgObjC->isObjCIdType()) {


Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -950,7 +950,7 @@
 
   // Retrieve the bound.
   QualType bound = typeParam->getUnderlyingType();
-  const auto *boundObjC = bound->getAs();
+  const auto *boundObjC = bound->castAs();
 
   // Determine whether the type argument is substitutable for the bound.
   if (typeArgObjC->isObjCIdType()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 8265994 - [NFC][CLANG] Fix Static Code Analyzer Concerns with dereference null return value in applyObjCTypeArgs()

2023-06-02 Thread via cfe-commits

Author: Manna, Soumi
Date: 2023-06-02T13:40:45-07:00
New Revision: 82659941ccb88605ae4288f7506ef11e5fe3fc17

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

LOG: [NFC][CLANG] Fix Static Code Analyzer Concerns with dereference null 
return value in applyObjCTypeArgs()

This patch uses castAs instead of getAs to resolve dereference issue with 
nullptr boundObjC when calling
canAssignObjCInterfaces() or isObjCIdType() in applyObjCTypeArgs() since getAs 
returns nullptr.

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1e4eecee21e5..f844048889b5 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -950,7 +950,7 @@ static QualType applyObjCTypeArgs(Sema , SourceLocation 
loc, QualType type,
 
   // Retrieve the bound.
   QualType bound = typeParam->getUnderlyingType();
-  const auto *boundObjC = bound->getAs();
+  const auto *boundObjC = bound->castAs();
 
   // Determine whether the type argument is substitutable for the bound.
   if (typeArgObjC->isObjCIdType()) {



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


[PATCH] D152017: [DebugInfo] Add flag to only emit referenced member functions

2023-06-02 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

This is pretty cool, even if it's just for data gathering. It's interesting 
that 29% of .debug_info and .debug_str is for describing class methods, that's 
pretty significant, even if it's only a 13% reduction across all debug info 
sections.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152017

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


[PATCH] D146148: Float_t and double_t types shouldn't be modified by #pragma clang fp eval_method

2023-06-02 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam added a comment.

ping.


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

https://reviews.llvm.org/D146148

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


[PATCH] D151834: Include math-errno with fast-math

2023-06-02 Thread Zahira Ammarguellat via Phabricator via cfe-commits
zahiraam updated this revision to Diff 527950.

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

https://reviews.llvm.org/D151834

Files:
  clang/include/clang/Basic/FPOptions.def
  clang/include/clang/Basic/LangOptions.h
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/math-errno.c

Index: clang/test/CodeGen/math-errno.c
===
--- /dev/null
+++ clang/test/CodeGen/math-errno.c
@@ -0,0 +1,52 @@
+// Tests that at -O2 math-errno is taken into account. Same than MSVC.
+// RUN: %clang_cc1 -Wno-implicit-function-declaration -fmath-errno \
+// RUN: -O2 -emit-llvm -o - %s \
+// RUN: | FileCheck %s
+
+// Tests that with -ffast-math math-errno is taken into account with
+// float_control(precise,on) and optnone.
+// RUN: %clang_cc1 -Wno-implicit-function-declaration  \
+// RUN: -ffast-math -emit-llvm -o - %s \
+// RUN: | FileCheck %s -check-prefix=FAST
+
+float f1(float x) { 
+#pragma float_control(precise,on)
+return sqrtf(x);
+}
+
+float f2(float x) { 
+#pragma float_control(precise,on)
+  {
+float y = sqrtf(x);
+return y;
+  }
+}
+
+float f3(float x) { 
+#pragma float_control(precise,off)
+  {
+float y = sqrtf(x);
+  return y;
+  }
+}
+
+__attribute__((optnone))
+float f4(float x) { 
+  x = sqrtf(x); 
+  return x;
+}
+
+// CHECK-LABEL: define dso_local float @f2(float noundef {{.*}})
+// CHECK:  tail call float @sqrtf(float noundef {{.*}})
+
+// CHECK-LABEL: define dso_local float @f3(float noundef {{.*}})
+// CHECK: call float @llvm.sqrt.f32(float {{.*}})
+
+// FAST-LABEL: define dso_local nofpclass(nan inf) float @f1(float noundef nofpclass(nan inf) {{.*}})
+// FAST: call reassoc nnan ninf nsz arcp afn nofpclass(nan inf) float @sqrtf(float noundef nofpclass(nan inf) {{.*}}) #[[ATTR0:[0-9]+]]
+
+// FAST-LABEL: define dso_local nofpclass(nan inf) float @f4(float noundef nofpclass(nan inf) {{.*}})
+// FAST: call reassoc nnan ninf nsz arcp afn nofpclass(nan inf) float @sqrtf(float noundef nofpclass(nan inf) %0) #[[ATTR0:[0-9]+]]
+
+// FAST: attributes #[[ATTR0]] = { {{.*}} memory(none) }
+
Index: clang/lib/CodeGen/CodeGenModule.h
===
--- clang/lib/CodeGen/CodeGenModule.h
+++ clang/lib/CodeGen/CodeGenModule.h
@@ -608,6 +608,7 @@
   ~CodeGenModule();
 
   void clear();
+  bool OptNone = true;
 
   /// Finalize LLVM code generation.
   void Release();
Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -2381,6 +2381,9 @@
   // Collect function IR attributes based on global settiings.
   getDefaultFunctionAttributes(Name, HasOptnone, AttrOnCallSite, FuncAttrs);
 
+  if (HasOptnone && !getLangOpts().MathErrno)
+OptNone = false;
+
   // Override some default IR attributes based on declaration-specific
   // information.
   if (TargetDecl) {
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -2245,6 +2245,13 @@
   // likely to get lowered to the renamed library functions.
   const unsigned BuiltinIDIfNoAsmLabel =
   FD->hasAttr() ? 0 : BuiltinID;
+  bool MathErrnoOverrride = false;
+  if (E->hasStoredFPFeatures()) {
+FPOptionsOverride OP = E->getFPFeatures();
+if (OP.hasMathErrnoOverride())
+  MathErrnoOverrride = OP.getMathErrnoOverride();
+  }
+  bool EmitIntrinsic = !MathErrnoOverrride && CGM.OptNone;
 
   // There are LLVM math intrinsics/instructions corresponding to math library
   // functions except the LLVM op will never set errno while the math library
@@ -2257,9 +2264,12 @@
   getContext().BuiltinInfo.isConstWithoutErrnoAndExceptions(BuiltinID);
   bool ConstWithoutExceptions =
   getContext().BuiltinInfo.isConstWithoutExceptions(BuiltinID);
-  if (FD->hasAttr() ||
-  ((ConstWithoutErrnoAndExceptions || ConstWithoutExceptions) &&
-   (!ConstWithoutErrnoAndExceptions || (!getLangOpts().MathErrno {
+
+  if ((FD->hasAttr() && EmitIntrinsic) ||
+  (EmitIntrinsic ||
+   ((ConstWithoutErrnoAndExceptions || ConstWithoutExceptions) &&
+ (!ConstWithoutErrnoAndExceptions ||
+ (!getLangOpts().MathErrno && EmitIntrinsic) {
 switch (BuiltinIDIfNoAsmLabel) {
 case Builtin::BIceil:
 case Builtin::BIceilf:
Index: clang/include/clang/Basic/LangOptions.h
===
--- clang/include/clang/Basic/LangOptions.h
+++ clang/include/clang/Basic/LangOptions.h
@@ -850,6 +850,7 @@
 setNoSignedZeroOverride(!Value);
 setAllowReciprocalOverride(!Value);
 setAllowApproxFuncOverride(!Value);
+setMathErrnoOverride(Value);
 if (Value)
   /* Precise mode implies fp_contract=on and disables ffast-math */
   

[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added reviewers: efriedma, rsmith.
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1324
 // This is a string literal initializing an array in an initializer.
-return CGM.GetConstantArrayFromStringLiteral(E);
+return E->isLValue() ?
+  CGM.GetAddrOfConstantStringFromLiteral(E).getPointer() :

efriedma wrote:
> nickdesaulniers wrote:
> > efriedma wrote:
> > > nickdesaulniers wrote:
> > > > nickdesaulniers wrote:
> > > > > efriedma wrote:
> > > > > > nickdesaulniers wrote:
> > > > > > > efriedma wrote:
> > > > > > > > Maybe we should have a separate ConstExprEmitterLValue... 
> > > > > > > > trying to handle both LValues and RValues on the same codepath 
> > > > > > > > has been problematic in the past.  It's very easy for code to 
> > > > > > > > get confused what it's actually trying to emit.
> > > > > > > So we'd have a `ConstExprEmitterLValue` class with some visitor 
> > > > > > > methods, and a `ConstExprEmitterRValue` with other methods 
> > > > > > > implemented?
> > > > > > Something like that.
> > > > > > 
> > > > > > Actually thinking about it a bit more, not sure you need to 
> > > > > > actually implement ConstExprEmitterLValue for now.  You might just 
> > > > > > be able to ensure we don't ever call ConstExprEmitter with an 
> > > > > > lvalue.  The current ConstExprEmitter doesn't expect lvalues, and 
> > > > > > shouldn't call itself with lvalues.  (We bail on explicit 
> > > > > > LValueToRValue conversions.)  And Evaluate() shouldn't actually 
> > > > > > evaluate the contents of an lvalue if it isn't dereferenced, so 
> > > > > > there hopefully aren't any performance issues using that codepath.
> > > > > > 
> > > > > > In terms of implementation, I guess that's basically restoring the 
> > > > > > destType->isReferenceType() that got removed?  (I know I suggested 
> > > > > > it, but I wasn't really thinking about it...)
> > > > > One thing I think we may need to add to `ConstExprEmitter` is the 
> > > > > ability to evaluate `CallExpr`s based on certain test case 
> > > > > failures...does that seem right?
> > > > See also the calls to `constexpr f()` in 
> > > > clang/test/CodeGenCXX/const-init-cxx1y.cpp
> > > The only things I know of that Evaluate() can't handle are CK_ToUnion, 
> > > CK_ReinterpretMemberPointer, and DesignatedInitUpdateExpr.  
> > > DesignatedInitUpdateExpr is related to the failures in 
> > > test/CodeGenCXX/designated-init.cpp; I don't think the others show up in 
> > > any of the testcases you've mentioned.  (CK_ToUnion can't appear in C++ 
> > > code. CK_ReinterpretMemberPointer is a `reinterpret_cast` where T is a 
> > > member pointer type.)
> > > 
> > > Given none of those constructs show up in const-init-cxx1y.cpp, the only 
> > > reason for it to fail is if we aren't correctly falling back for a 
> > > construct the current code doesn't know how to handle.  You shouldn't 
> > > need to implement any new constructs.
> > in clang/test/CodeGenCXX/designated-init.cpp we have:
> > ```
> > >> 22 namespace ModifyStaticTemporary { 
> > >>   
> >23   struct A { int & int x; };   
> >   
> >24   constexpr int f(int ) { r *= 9; return r - 12; }  
> >   
> >25   A a = { 6, f(a.temporary) };
> > ```
> > In the AST, that looks like:
> > ```
> > | |-VarDecl 0x562b77df39b0  col:5 used a 
> > 'A':'ModifyStaticTemporary::A' cinit
> > | | `-ExprWithCleanups 0x562b77df3c68  
> > 'A':'ModifyStaticTemporary::A'
> > | |   `-InitListExpr 0x562b77df3bb8  
> > 'A':'ModifyStaticTemporary::A'
> > | | |-MaterializeTemporaryExpr 0x562b77df3c08  'int' xvalue 
> > extended by Var 0x562b77df39b0 'a' 'A':'ModifyStaticTemporary::A'
> > | | | `-IntegerLiteral 0x562b77df3a18  'int' 6
> > | | `-CallExpr 0x562b77df3b30  'int'
> > | |   |-ImplicitCastExpr 0x562b77df3b18  'int (*)(int &)' 
> > 
> > | |   | `-DeclRefExpr 0x562b77df3ad0  'int (int &)' lvalue 
> > Function 0x562b77df37a0 'f' 'int (int &)'
> > | |   `-MemberExpr 0x562b77df3aa0  'int' lvalue 
> > .temporary 0x562b77df35c0
> > | | `-DeclRefExpr 0x562b77df3a80  
> > 'A':'ModifyStaticTemporary::A' lvalue Var 0x562b77df39b0 'a' 
> > 'A':'ModifyStaticTemporary::A'
> > ```
> > (So, indeed no `DesignatedInitUpdateExpr`) but the call to the `constexpr` 
> > `f()` updates the reference (to `54`).  If I remove the visitor for 
> > `MaterializeTemporaryExpr`, we fail to evaluate `f` and end up emitting `6` 
> > rather than `54`.  Doesn't that mean that the fast path 
> > (`ConstExprEmitter`) needs to be able to evaluate `CallExpr`?
> > 
> > Or should `VisitInitListExpr` bail if any of the inits 
> > `isa` (or perhaps `isa`)?
> There are a few related cases here.
> 
> Case number one is when you have something like `int z(); A a = { z(), z() 
> };`.  There's no constant evaluation going on: you just emit two 
> 

[PATCH] D152027: [CUDA] Update Kepler(sm_3*) support info.

2023-06-02 Thread Artem Belevich via Phabricator via cfe-commits
tra created this revision.
Herald added subscribers: mattd, carlosgalvezp, bixia, yaxunl.
Herald added a project: All.
tra published this revision for review.
tra added a reviewer: jlebar.
tra added a comment.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Kepler is gone! Long live Kepler!


sm_30 and sm_32 were removed in cuda-11.0
sm_35 and sm_37 were removed in cuda-12.0


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152027

Files:
  clang/lib/Basic/Cuda.cpp


Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -222,7 +222,11 @@
   case CudaArch::SM_21:
 return CudaVersion::CUDA_80;
   case CudaArch::SM_30:
-return CudaVersion::CUDA_110;
+  case CudaArch::SM_32:
+return CudaVersion::CUDA_102;
+  case CudaArch::SM_35:
+  case CudaArch::SM_37:
+return CudaVersion::CUDA_118;
   default:
 return CudaVersion::NEW;
   }


Index: clang/lib/Basic/Cuda.cpp
===
--- clang/lib/Basic/Cuda.cpp
+++ clang/lib/Basic/Cuda.cpp
@@ -222,7 +222,11 @@
   case CudaArch::SM_21:
 return CudaVersion::CUDA_80;
   case CudaArch::SM_30:
-return CudaVersion::CUDA_110;
+  case CudaArch::SM_32:
+return CudaVersion::CUDA_102;
+  case CudaArch::SM_35:
+  case CudaArch::SM_37:
+return CudaVersion::CUDA_118;
   default:
 return CudaVersion::NEW;
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151957: [NFC][CLANG] Fix bug with dereference null return value in GetFunctionTypeForVTable()

2023-06-02 Thread Soumi Manna via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG02ce49afb9a0: [NFC][CLANG] Fix bug with dereference null 
return value in… (authored by Manna).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151957

Files:
  clang/lib/CodeGen/CGCall.cpp


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1751,7 +1751,7 @@
 
 llvm::Type *CodeGenTypes::GetFunctionTypeForVTable(GlobalDecl GD) {
   const CXXMethodDecl *MD = cast(GD.getDecl());
-  const FunctionProtoType *FPT = MD->getType()->getAs();
+  const FunctionProtoType *FPT = MD->getType()->castAs();
 
   if (!isFuncTypeConvertible(FPT))
 return llvm::StructType::get(getLLVMContext());


Index: clang/lib/CodeGen/CGCall.cpp
===
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -1751,7 +1751,7 @@
 
 llvm::Type *CodeGenTypes::GetFunctionTypeForVTable(GlobalDecl GD) {
   const CXXMethodDecl *MD = cast(GD.getDecl());
-  const FunctionProtoType *FPT = MD->getType()->getAs();
+  const FunctionProtoType *FPT = MD->getType()->castAs();
 
   if (!isFuncTypeConvertible(FPT))
 return llvm::StructType::get(getLLVMContext());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 02ce49a - [NFC][CLANG] Fix bug with dereference null return value in GetFunctionTypeForVTable()

2023-06-02 Thread via cfe-commits

Author: Manna, Soumi
Date: 2023-06-02T13:28:06-07:00
New Revision: 02ce49afb9a078932c74f4d9b43189a5567e54e9

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

LOG: [NFC][CLANG] Fix bug with dereference null return value in 
GetFunctionTypeForVTable()

This patch uses castAs instead of getAs which will assert if the type doesn't 
match in 
clang::CodeGen::CodeGenTypes::GetFunctionTypeForVTable(clang::GlobalDecl).

Reviewed By: erichkeane

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

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 09ccb63dceeb..b6b04fca6682 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1751,7 +1751,7 @@ CodeGenTypes::GetFunctionType(const CGFunctionInfo ) {
 
 llvm::Type *CodeGenTypes::GetFunctionTypeForVTable(GlobalDecl GD) {
   const CXXMethodDecl *MD = cast(GD.getDecl());
-  const FunctionProtoType *FPT = MD->getType()->getAs();
+  const FunctionProtoType *FPT = MD->getType()->castAs();
 
   if (!isFuncTypeConvertible(FPT))
 return llvm::StructType::get(getLLVMContext());



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


[PATCH] D152023: [UBSan] Consider zero input to __builtin_clz/ctz to be undefined independent of the target.

2023-06-02 Thread Craig Topper 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 rG18ccca4da8de: [UBSan] Consider zero input to 
__builtin_clz/ctz to be undefined independent of… (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152023

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/ubsan-builtin-checks.c


Index: clang/test/CodeGen/ubsan-builtin-checks.c
===
--- clang/test/CodeGen/ubsan-builtin-checks.c
+++ clang/test/CodeGen/ubsan-builtin-checks.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s --check-prefix=NOT-UB
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,POISON
+// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,NOPOISON
 
-// NOT-UB-NOT: __ubsan_handle_invalid_builtin
+// A zero input to __bultin_ctz/clz is considered UB even if the target does 
not
+// want to optimize based on zero input being undefined.
 
 // CHECK: define{{.*}} void @check_ctz
 void check_ctz(int n) {
@@ -13,7 +14,8 @@
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 false)
   __builtin_ctz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin
@@ -33,7 +35,8 @@
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 false)
   __builtin_clz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1741,7 +1741,7 @@
   && "Unsupported builtin check kind");
 
   Value *ArgValue = EmitScalarExpr(E);
-  if (!SanOpts.has(SanitizerKind::Builtin) || !getTarget().isCLZForZeroUndef())
+  if (!SanOpts.has(SanitizerKind::Builtin))
 return ArgValue;
 
   SanitizerScope SanScope(this);


Index: clang/test/CodeGen/ubsan-builtin-checks.c
===
--- clang/test/CodeGen/ubsan-builtin-checks.c
+++ clang/test/CodeGen/ubsan-builtin-checks.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefix=NOT-UB
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,POISON
+// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,NOPOISON
 
-// NOT-UB-NOT: __ubsan_handle_invalid_builtin
+// A zero input to __bultin_ctz/clz is considered UB even if the target does not
+// want to optimize based on zero input being undefined.
 
 // CHECK: define{{.*}} void @check_ctz
 void check_ctz(int n) {
@@ -13,7 +14,8 @@
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 false)
   __builtin_ctz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin
@@ -33,7 +35,8 @@
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 false)
   __builtin_clz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1741,7 +1741,7 @@
   && "Unsupported builtin check kind");
 
   Value *ArgValue = EmitScalarExpr(E);
-  if (!SanOpts.has(SanitizerKind::Builtin) || !getTarget().isCLZForZeroUndef())
+  if (!SanOpts.has(SanitizerKind::Builtin))
 return ArgValue;
 
   SanitizerScope SanScope(this);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 18ccca4 - [UBSan] Consider zero input to __builtin_clz/ctz to be undefined independent of the target.

2023-06-02 Thread Craig Topper via cfe-commits

Author: Craig Topper
Date: 2023-06-02T13:01:05-07:00
New Revision: 18ccca4da8dec5fbfd1072a1c1544ce25f528627

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

LOG: [UBSan] Consider zero input to __builtin_clz/ctz to be undefined 
independent of the target.

Previously we checked isCLZForZeroUndef and only added UBSan checks
if it returned true.

The builtin should be considered undefined for 0 regardless of
the target so that code using it is portable. The isCLZForZeroUndef
was only intended to disable optimizations in the middle end and
backend.

See 
https://discourse.llvm.org/t/should-ubsan-detect-0-input-to-builtin-clz-ctz-regardless-of-target/71060

Reviewed By: nikic

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

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/ubsan-builtin-checks.c

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bfa6fd716c5e..c09e5b5319eb 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1741,7 +1741,7 @@ Value *CodeGenFunction::EmitCheckedArgForBuiltin(const 
Expr *E,
   && "Unsupported builtin check kind");
 
   Value *ArgValue = EmitScalarExpr(E);
-  if (!SanOpts.has(SanitizerKind::Builtin) || !getTarget().isCLZForZeroUndef())
+  if (!SanOpts.has(SanitizerKind::Builtin))
 return ArgValue;
 
   SanitizerScope SanScope(this);

diff  --git a/clang/test/CodeGen/ubsan-builtin-checks.c 
b/clang/test/CodeGen/ubsan-builtin-checks.c
index eb6ff11f4ceb..2bc32d8df485 100644
--- a/clang/test/CodeGen/ubsan-builtin-checks.c
+++ b/clang/test/CodeGen/ubsan-builtin-checks.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s --check-prefix=NOT-UB
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,POISON
+// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,NOPOISON
 
-// NOT-UB-NOT: __ubsan_handle_invalid_builtin
+// A zero input to __bultin_ctz/clz is considered UB even if the target does 
not
+// want to optimize based on zero input being undefined.
 
 // CHECK: define{{.*}} void @check_ctz
 void check_ctz(int n) {
@@ -13,7 +14,8 @@ void check_ctz(int n) {
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 false)
   __builtin_ctz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin
@@ -33,7 +35,8 @@ void check_clz(int n) {
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 false)
   __builtin_clz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin



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


[PATCH] D148490: [AIX] use system assembler for assembly files

2023-06-02 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added inline comments.



Comment at: clang/test/Driver/target-as.s:1
 // Make sure the -march is passed down to cc1as.
 // RUN: %clang -target i386-unknown-freebsd -### -c -integrated-as %s \

shchenz wrote:
> MaskRay wrote:
> > shchenz wrote:
> > > MaskRay wrote:
> > > > aix-as.c will be more appropriate.
> > > Do you mean we change this file to `aix-as.s` or we change back to 
> > > previous version? The file `target-as.s` can not be renamed to 
> > > `aix-as.s`, it also contains tests for i386, see the first run line.
> > You can add the new tests to the existing `aix-as.s`. The behavior is about 
> > assemblers on AIX. `aix-as.s` seems more appropriate than `target-as.s`.
> hmm, we want to use assembly file for test. There is aix-as.c but no aix-as.s.
You can use `-x assembler`. It's fairly common to use `-x c++ xxx.c` to test 
C++ with a C file.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148490

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


[PATCH] D152017: [DebugInfo] Add flag to only emit referenced member functions

2023-06-02 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a comment.

I'm traveling but will look at this on Monday.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152017

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1209
+return VisitCastExpr(I, T);
+  }
+  llvm::Constant *VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *C, 
QualType T) {

ConstExprEmitter should inherit an identical implementation of 
VisitImplicitCastExpr from StmtVisitor, I think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[PATCH] D134334: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

2023-06-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik marked an inline comment as done.
shafik added inline comments.



Comment at: clang/lib/Parse/ParseTentative.cpp:1553-1554
 return TPResult::Error;
-  if (Tok.isNot(tok::identifier))
+  if (NextToken().isNot(tok::identifier))
 break;
 }

cor3ntin wrote:
> rsmith wrote:
> > This doesn't seem correct to me. If we had `scope::foo bar`, and we 
> > annotate `scope::foo` as a type, then this will get confused by the next 
> > token now being an (unrelated) identifier. This code is trying to detect if 
> > an annotation was performed, so I think it intended to check if the current 
> > token's kind has changed, like is done on line 1295.
> The confusing bit is that Tok is always an annotated scope already here 
> (L1598), so TryAnnotateName should not modify that first token (unless 
> TryAnnotateTypeOrScopeTokenAfterScopeSpec can somehow replace the current 
> annot_cxxscope by another one, which i don't think can happen?) 
Ok using `tok::annot_cxxscope` also works and I agree it makes sense as well, 
`check-clang` also passes.

So then is the assert below wrong?

```
  // Annotated it, check again.
  assert(Tok.isNot(tok::annot_cxxscope) ||
 NextToken().isNot(tok::identifier));
```

It looks like it will work by accident for most cases b/c it checks 
`tok::annot_cxxscope` first. 


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

https://reviews.llvm.org/D134334

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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1324
 // This is a string literal initializing an array in an initializer.
-return CGM.GetConstantArrayFromStringLiteral(E);
+return E->isLValue() ?
+  CGM.GetAddrOfConstantStringFromLiteral(E).getPointer() :

nickdesaulniers wrote:
> efriedma wrote:
> > nickdesaulniers wrote:
> > > nickdesaulniers wrote:
> > > > efriedma wrote:
> > > > > nickdesaulniers wrote:
> > > > > > efriedma wrote:
> > > > > > > Maybe we should have a separate ConstExprEmitterLValue... trying 
> > > > > > > to handle both LValues and RValues on the same codepath has been 
> > > > > > > problematic in the past.  It's very easy for code to get confused 
> > > > > > > what it's actually trying to emit.
> > > > > > So we'd have a `ConstExprEmitterLValue` class with some visitor 
> > > > > > methods, and a `ConstExprEmitterRValue` with other methods 
> > > > > > implemented?
> > > > > Something like that.
> > > > > 
> > > > > Actually thinking about it a bit more, not sure you need to actually 
> > > > > implement ConstExprEmitterLValue for now.  You might just be able to 
> > > > > ensure we don't ever call ConstExprEmitter with an lvalue.  The 
> > > > > current ConstExprEmitter doesn't expect lvalues, and shouldn't call 
> > > > > itself with lvalues.  (We bail on explicit LValueToRValue 
> > > > > conversions.)  And Evaluate() shouldn't actually evaluate the 
> > > > > contents of an lvalue if it isn't dereferenced, so there hopefully 
> > > > > aren't any performance issues using that codepath.
> > > > > 
> > > > > In terms of implementation, I guess that's basically restoring the 
> > > > > destType->isReferenceType() that got removed?  (I know I suggested 
> > > > > it, but I wasn't really thinking about it...)
> > > > One thing I think we may need to add to `ConstExprEmitter` is the 
> > > > ability to evaluate `CallExpr`s based on certain test case 
> > > > failures...does that seem right?
> > > See also the calls to `constexpr f()` in 
> > > clang/test/CodeGenCXX/const-init-cxx1y.cpp
> > The only things I know of that Evaluate() can't handle are CK_ToUnion, 
> > CK_ReinterpretMemberPointer, and DesignatedInitUpdateExpr.  
> > DesignatedInitUpdateExpr is related to the failures in 
> > test/CodeGenCXX/designated-init.cpp; I don't think the others show up in 
> > any of the testcases you've mentioned.  (CK_ToUnion can't appear in C++ 
> > code. CK_ReinterpretMemberPointer is a `reinterpret_cast` where T is a 
> > member pointer type.)
> > 
> > Given none of those constructs show up in const-init-cxx1y.cpp, the only 
> > reason for it to fail is if we aren't correctly falling back for a 
> > construct the current code doesn't know how to handle.  You shouldn't need 
> > to implement any new constructs.
> in clang/test/CodeGenCXX/designated-init.cpp we have:
> ```
> >> 22 namespace ModifyStaticTemporary {   
> >> 
>23   struct A { int & int x; }; 
> 
>24   constexpr int f(int ) { r *= 9; return r - 12; }
> 
>25   A a = { 6, f(a.temporary) };
> ```
> In the AST, that looks like:
> ```
> | |-VarDecl 0x562b77df39b0  col:5 used a 
> 'A':'ModifyStaticTemporary::A' cinit
> | | `-ExprWithCleanups 0x562b77df3c68  
> 'A':'ModifyStaticTemporary::A'
> | |   `-InitListExpr 0x562b77df3bb8  
> 'A':'ModifyStaticTemporary::A'
> | | |-MaterializeTemporaryExpr 0x562b77df3c08  'int' xvalue 
> extended by Var 0x562b77df39b0 'a' 'A':'ModifyStaticTemporary::A'
> | | | `-IntegerLiteral 0x562b77df3a18  'int' 6
> | | `-CallExpr 0x562b77df3b30  'int'
> | |   |-ImplicitCastExpr 0x562b77df3b18  'int (*)(int &)' 
> 
> | |   | `-DeclRefExpr 0x562b77df3ad0  'int (int &)' lvalue 
> Function 0x562b77df37a0 'f' 'int (int &)'
> | |   `-MemberExpr 0x562b77df3aa0  'int' lvalue 
> .temporary 0x562b77df35c0
> | | `-DeclRefExpr 0x562b77df3a80  
> 'A':'ModifyStaticTemporary::A' lvalue Var 0x562b77df39b0 'a' 
> 'A':'ModifyStaticTemporary::A'
> ```
> (So, indeed no `DesignatedInitUpdateExpr`) but the call to the `constexpr` 
> `f()` updates the reference (to `54`).  If I remove the visitor for 
> `MaterializeTemporaryExpr`, we fail to evaluate `f` and end up emitting `6` 
> rather than `54`.  Doesn't that mean that the fast path (`ConstExprEmitter`) 
> needs to be able to evaluate `CallExpr`?
> 
> Or should `VisitInitListExpr` bail if any of the inits 
> `isa` (or perhaps `isa`)?
There are a few related cases here.

Case number one is when you have something like `int z(); A a = { z(), z() };`. 
 There's no constant evaluation going on: you just emit two zero-initialized 
variables, and the runtime init initializes both of them.

Case number two is when everything is obviously constant: something like `A a = 
{ 1, 2 };`

Case number three is when there are simple side-effects, and the 

[PATCH] D134334: [Clang] Fix crash in isCXXDeclarationSpecifier when attempting to annotate template name

2023-06-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik updated this revision to Diff 527937.
shafik added a comment.

- Update check to use tok::annot_cxxscope


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

https://reviews.llvm.org/D134334

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseTentative.cpp
  clang/test/Parser/cxx1z-class-template-argument-deduction.cpp


Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -247,3 +247,11 @@
 };
 
 }
+
+namespace GH57495 {
+template  struct vector{};
+
+void f() {
+  GH57495::vector.d; // expected-error {{cannot use dot operator on a type}}
+}
+}
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -1651,7 +1651,8 @@
 if (getLangOpts().CPlusPlus17) {
   if (TryAnnotateTypeOrScopeToken())
 return TPResult::Error;
-  if (Tok.isNot(tok::identifier))
+  // If we annotated then the current token should not still be ::
+  if (Tok.isNot(tok::annot_cxxscope))
 break;
 }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -463,6 +463,10 @@
 - Fix crash when passing a braced initializer list to a parentehsized aggregate
   initialization expression.
   (`#63008 `_).
+- Fix C++17 mode assert when parsing malformed code and the compiler is
+  attempting to see if it could be type template for class template argument
+  deduction. This fixes
+  (`Issue 57495 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
===
--- clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
+++ clang/test/Parser/cxx1z-class-template-argument-deduction.cpp
@@ -247,3 +247,11 @@
 };
 
 }
+
+namespace GH57495 {
+template  struct vector{};
+
+void f() {
+  GH57495::vector.d; // expected-error {{cannot use dot operator on a type}}
+}
+}
Index: clang/lib/Parse/ParseTentative.cpp
===
--- clang/lib/Parse/ParseTentative.cpp
+++ clang/lib/Parse/ParseTentative.cpp
@@ -1651,7 +1651,8 @@
 if (getLangOpts().CPlusPlus17) {
   if (TryAnnotateTypeOrScopeToken())
 return TPResult::Error;
-  if (Tok.isNot(tok::identifier))
+  // If we annotated then the current token should not still be ::
+  if (Tok.isNot(tok::annot_cxxscope))
 break;
 }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -463,6 +463,10 @@
 - Fix crash when passing a braced initializer list to a parentehsized aggregate
   initialization expression.
   (`#63008 `_).
+- Fix C++17 mode assert when parsing malformed code and the compiler is
+  attempting to see if it could be type template for class template argument
+  deduction. This fixes
+  (`Issue 57495 `_).
 
 Bug Fixes to Compiler Builtins
 ^^
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D152023: [UBSan] Consider zero input to __builtin_clz/ctz to be undefined independent of the target.

2023-06-02 Thread Nikita Popov via Phabricator via cfe-commits
nikic accepted this revision.
nikic 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/D152023/new/

https://reviews.llvm.org/D152023

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


[PATCH] D152023: [UBSan] Consider zero input to __builtin_clz/ctz to be undefined independent of the target.

2023-06-02 Thread Craig Topper via Phabricator via cfe-commits
craig.topper created this revision.
craig.topper added reviewers: efriedma, nikic, vsk.
Herald added a subscriber: StephenFan.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: clang.

Previously we checked isCLZForZeroUndef and only added UBSan checks
if it returned true.

The builtin should be considered undefined for 0 regardless of
the target so that code using it is portable. The isCLZForZeroUndef
was only intended to disable optimizations in the middle end and
backend.

See 
https://discourse.llvm.org/t/should-ubsan-detect-0-input-to-builtin-clz-ctz-regardless-of-target/71060


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152023

Files:
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/ubsan-builtin-checks.c


Index: clang/test/CodeGen/ubsan-builtin-checks.c
===
--- clang/test/CodeGen/ubsan-builtin-checks.c
+++ clang/test/CodeGen/ubsan-builtin-checks.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s --check-prefix=NOT-UB
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,POISON
+// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s 
-fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,NOPOISON
 
-// NOT-UB-NOT: __ubsan_handle_invalid_builtin
+// A zero input to __bultin_ctz/clz is considered UB even if the target does 
not
+// want to optimize based on zero input being undefined.
 
 // CHECK: define{{.*}} void @check_ctz
 void check_ctz(int n) {
@@ -13,7 +14,8 @@
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 false)
   __builtin_ctz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin
@@ -33,7 +35,8 @@
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 false)
   __builtin_clz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1741,7 +1741,7 @@
   && "Unsupported builtin check kind");
 
   Value *ArgValue = EmitScalarExpr(E);
-  if (!SanOpts.has(SanitizerKind::Builtin) || !getTarget().isCLZForZeroUndef())
+  if (!SanOpts.has(SanitizerKind::Builtin))
 return ArgValue;
 
   SanitizerScope SanScope(this);


Index: clang/test/CodeGen/ubsan-builtin-checks.c
===
--- clang/test/CodeGen/ubsan-builtin-checks.c
+++ clang/test/CodeGen/ubsan-builtin-checks.c
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s
-// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefix=NOT-UB
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,POISON
+// RUN: %clang_cc1 -triple arm64-none-linux-gnu -w -emit-llvm -o - %s -fsanitize=builtin | FileCheck %s --check-prefixes=CHECK,NOPOISON
 
-// NOT-UB-NOT: __ubsan_handle_invalid_builtin
+// A zero input to __bultin_ctz/clz is considered UB even if the target does not
+// want to optimize based on zero input being undefined.
 
 // CHECK: define{{.*}} void @check_ctz
 void check_ctz(int n) {
@@ -13,7 +14,8 @@
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.cttz.i32(i32 [[N]], i1 false)
   __builtin_ctz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin
@@ -33,7 +35,8 @@
   // CHECK-NEXT: unreachable
   //
   // Continuation block:
-  // CHECK: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // POISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 true)
+  // NOPOISON: call i32 @llvm.ctlz.i32(i32 [[N]], i1 false)
   __builtin_clz(n);
 
   // CHECK: call void @__ubsan_handle_invalid_builtin
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -1741,7 +1741,7 @@
   && "Unsupported builtin check kind");
 
   Value *ArgValue = EmitScalarExpr(E);
-  if (!SanOpts.has(SanitizerKind::Builtin) || !getTarget().isCLZForZeroUndef())
+  if 

[PATCH] D150860: [OpenMP] Change clang emitTargetDataCalls to use OMPIRBuilder

2023-06-02 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis updated this revision to Diff 527931.
TIFitis marked 2 inline comments as done.
TIFitis added a comment.

Addressed reviewer comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150860

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  clang/test/OpenMP/target_data_codegen.cpp
  clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Index: llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
===
--- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -4083,7 +4083,9 @@
 function_ref GenMapInfoCB,
 omp::RuntimeFunction *MapperFunc,
 function_ref
-BodyGenCB) {
+BodyGenCB,
+function_ref DeviceAddrCB,
+function_ref CustomMapperCB) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
 
@@ -4094,9 +4096,9 @@
   // arguments of the runtime call by reference because they are used in the
   // closing of the region.
   auto BeginThenGen = [&](InsertPointTy UnusedIP, InsertPointTy CodeGenIP) {
-emitOffloadingArrays(AllocaIP, Builder.saveIP(),
- GenMapInfoCB(Builder.saveIP()), Info,
- /*IsNonContiguous=*/true);
+emitOffloadingArrays(
+AllocaIP, Builder.saveIP(), GenMapInfoCB(Builder.saveIP()), Info,
+/*IsNonContiguous=*/true, DeviceAddrCB, CustomMapperCB);
 
 TargetDataRTArgs RTArgs;
 emitOffloadingArraysArgument(Builder, RTArgs, Info);
Index: llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
===
--- llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1897,6 +1897,10 @@
   /// \param Info Stores all information realted to the Target Data directive.
   /// \param GenMapInfoCB Callback that populates the MapInfos and returns.
   /// \param BodyGenCB Optional Callback to generate the region code.
+  /// \param DeviceAddrCB Optional callback to generate code related to
+  /// use_device_ptr and use_device_addr.
+  /// \param CustomMapperCB Optional callback to generate code related to
+  /// custom mappers.
   OpenMPIRBuilder::InsertPointTy createTargetData(
   const LocationDescription , InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, Value *DeviceID, Value *IfCond,
@@ -1904,7 +1908,9 @@
   function_ref GenMapInfoCB,
   omp::RuntimeFunction *MapperFunc = nullptr,
   function_ref
-  BodyGenCB = nullptr);
+  BodyGenCB = nullptr,
+  function_ref DeviceAddrCB = nullptr,
+  function_ref CustomMapperCB = nullptr);
 
   using TargetBodyGenCallbackTy = function_ref;
Index: clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
===
--- clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
+++ clang/test/OpenMP/target_data_use_device_ptr_codegen.cpp
@@ -131,7 +131,6 @@
 ++l;
   }
   // CK1: [[BEND]]:
-  // CK1: [[CMP:%.+]] = icmp ne ptr %{{.+}}, null
   // CK1: br i1 [[CMP]], label %[[BTHEN:.+]], label %[[BELSE:.+]]
 
   // CK1: [[BTHEN]]:
Index: clang/test/OpenMP/target_data_codegen.cpp
===
--- clang/test/OpenMP/target_data_codegen.cpp
+++ clang/test/OpenMP/target_data_codegen.cpp
@@ -63,9 +63,7 @@
 
   // CK1: %{{.+}} = add nsw i32 %{{[^,]+}}, 1
 
-  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
-  // CK1-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-  // CK1-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+  // CK1-DAG: call void @__tgt_target_data_end_mapper(ptr @{{.+}}, i64 [[DEV]], i32 1, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[SIZE00]], ptr [[MTYPE00]], ptr null, ptr null)
   // CK1-DAG: [[GEPBP]] = getelementptr inbounds {{.+}}[[BP]]
 // CK1-DAG: [[GEPP]] = getelementptr inbounds {{.+}}[[P]]
   #pragma omp target data if(1+3-5) device(arg) map(from: gc)
@@ -354,11 +352,11 @@
 }
 
 // Region 00
+// CK2-DAG: [[DEV:%[^,]+]] = sext i32 [[DEVi32:%[^,]+]] to i64
+// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
 // CK2: br i1 %{{[^,]+}}, label %[[IFTHEN:[^,]+]], label %[[IFELSE:[^,]+]]
 // CK2: [[IFTHEN]]
-// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV:%[^,]+]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr null)
-// CK2-DAG: [[DEV]] = sext i32 [[DEVi32:%[^,]+]] to i64
-// CK2-DAG: [[DEVi32]] = load i32, ptr %{{[^,]+}},
+// CK2-DAG: call void @__tgt_target_data_begin_mapper(ptr @{{.+}}, i64 [[DEV]], i32 2, ptr [[GEPBP:%.+]], ptr [[GEPP:%.+]], ptr [[GEPS:%[^,]+]], ptr [[MTYPE00]], ptr null, ptr 

[PATCH] D152021: [clang][AIX] Fix Overly Strick LTO Option Checking against `data-sections` when `mxcoff-roptr` is in Effect

2023-06-02 Thread Qiongsi Wu via Phabricator via cfe-commits
qiongsiwu1 created this revision.
qiongsiwu1 added reviewers: hubert.reinterpretcast, w2yehia.
qiongsiwu1 added a project: clang.
Herald added subscribers: kbarton, inglorion, nemanjai.
Herald added a project: All.
qiongsiwu1 requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.

The LTO `mxcoff-roptr` check 

 against data sections is overly strict and it ignores the fact that data 
sections is on by default on AIX 
,
 causing valid LTO compilation to fail when `fdata-sections` is not explicitly 
specified for LTO.

This patch revises the check so that an error is reported only if data sections 
is explicitly turned off for LTO.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152021

Files:
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/ppc-roptr.c


Index: clang/test/Driver/ppc-roptr.c
===
--- clang/test/Driver/ppc-roptr.c
+++ clang/test/Driver/ppc-roptr.c
@@ -12,7 +12,7 @@
 // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=NO_ROPTR
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 
2>&1 | \
-// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: FileCheck %s 
--check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR
 // RUN: touch %t.o
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | 
\
 // RUN: FileCheck %s --check-prefix=LINK
@@ -33,14 +33,14 @@
 // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr 
-flto \
 // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
 
-// ROPTR: "-mxcoff-roptr"
-// LINK: "-bforceimprw"
-// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
-// NO_ROPTR-NOT: "-mxcoff-roptr"
-// NO_ROPTR-NOT: "-bforceimprw"
-
 // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with 
-fdata-sections
 // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with 
-fdata-sections
 // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 
'powerpc64le-unknown-linux-gnu'
 // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 
'powerpc64le-unknown-linux-gnu'
 // SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: "-bforceimprw"
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -747,7 +747,8 @@
 
 if (HasRoptr) {
   if (!Args.hasFlag(options::OPT_fdata_sections,
-options::OPT_fno_data_sections, UseSeparateSections))
+options::OPT_fno_data_sections, UseSeparateSections) &&
+  Args.hasArg(options::OPT_fno_data_sections))
 D.Diag(diag::err_roptr_requires_data_sections);
 
   CmdArgs.push_back(


Index: clang/test/Driver/ppc-roptr.c
===
--- clang/test/Driver/ppc-roptr.c
+++ clang/test/Driver/ppc-roptr.c
@@ -12,7 +12,7 @@
 // RUN: %clang -### --target=powerpc-ibm-aix-xcoff %s 2>&1 | \
 // RUN: FileCheck %s --check-prefix=NO_ROPTR
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr -flto %s 2>&1 | \
-// RUN: FileCheck %s --check-prefixes=ROPTR,LINK,LTO_ROPTR
+// RUN: FileCheck %s --check-prefixes=NO_DATA_SECTION_ERR,ROPTR,LINK,LTO_ROPTR
 // RUN: touch %t.o
 // RUN: %clang -### --target=powerpc64-ibm-aix-xcoff -mxcoff-roptr %t.o 2>&1 | \
 // RUN: FileCheck %s --check-prefix=LINK
@@ -33,14 +33,14 @@
 // RUN: %clang -### --target=powerpc64le-unknown-linux-gnu -mno-xcoff-roptr -flto \
 // RUN: %t.o 2>&1 | FileCheck %s --check-prefix=TARGET_NOROPTR_ERR
 
-// ROPTR: "-mxcoff-roptr"
-// LINK: "-bforceimprw"
-// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
-// NO_ROPTR-NOT: "-mxcoff-roptr"
-// NO_ROPTR-NOT: "-bforceimprw"
-
 // DATA_SECTION_ERR: error: -mxcoff-roptr is supported only with -fdata-sections
 // NO_DATA_SECTION_ERR-NOT: error: -mxcoff-roptr is supported only with -fdata-sections
 // TARGET_ROPTR_ERR: error: unsupported option '-mxcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
 // TARGET_NOROPTR_ERR: error: unsupported option '-mno-xcoff-roptr' for target 'powerpc64le-unknown-linux-gnu'
 // SHARED_ERR: error: -mxcoff-roptr is not supported with -shared
+
+// ROPTR: "-mxcoff-roptr"
+// LINK: "-bforceimprw"
+// LTO_ROPTR: "-bplugin_opt:-mxcoff-roptr"
+// NO_ROPTR-NOT: "-mxcoff-roptr"
+// NO_ROPTR-NOT: 

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

2023-06-02 Thread Akash Banerjee via Phabricator via cfe-commits
TIFitis accepted this revision.
TIFitis 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/D147218/new/

https://reviews.llvm.org/D147218

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


[clang] 583e028 - [test] Add -Wno-msvc-not-found to fix linker-opts.c on *-windows-msvc

2023-06-02 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-06-02T11:59:23-07:00
New Revision: 583e02831c6d081f43f2d5c5b9be5d773b7ae8b8

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

LOG: [test] Add -Wno-msvc-not-found to fix linker-opts.c on *-windows-msvc

Added: 


Modified: 
clang/test/Driver/linker-opts.c

Removed: 




diff  --git a/clang/test/Driver/linker-opts.c b/clang/test/Driver/linker-opts.c
index 319cc591cc3c8..181aeadb8dc97 100644
--- a/clang/test/Driver/linker-opts.c
+++ b/clang/test/Driver/linker-opts.c
@@ -15,7 +15,7 @@
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
-// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ 
-nostdlibinc -nogpuinc %t/tmp.o -o /dev/null 2>&1 | FileCheck /dev/null 
--implicit-check-not=warning:
+// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ 
-nostdlibinc -nogpuinc %t/tmp.o -Wno-msvc-not-found -o /dev/null 2>&1 | 
FileCheck /dev/null --implicit-check-not=warning:
 
 // Make sure that we do warn in other cases.
 // RUN: %clang %s -lfoo -c -o %t/tmp2.o -### 2>&1 | FileCheck %s 
--check-prefix=UNUSED



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


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 527925.
nickdesaulniers added a comment.

- remove commented out code, still WIP


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
   // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
+  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
Index: clang/test/CodeGenCXX/const-init-cxx11.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -88,7 +88,7 @@
 
   struct E {};
   struct Test2 : X, X, X, X {};
-  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} undef
+  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} zeroinitializer, align 1
   extern constexpr Test2 t2 = Test2();
 
   struct __attribute((packed)) PackedD { double y = 2; };
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1204,6 +1204,15 @@
 }
 llvm_unreachable("Invalid CastKind");
   }
+  llvm::Constant *VisitImplicitCastExpr(ImplicitCastExpr *I, QualType T) {
+return VisitCastExpr(I, T);
+  }
+  llvm::Constant *VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *C, QualType T) {
+return VisitCastExpr(C, T);
+  }
+  llvm::Constant *VisitCStyleCastExpr(CStyleCastExpr *C, QualType T) {
+return VisitCastExpr(C, T);
+  }
 
   llvm::Constant *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE, QualType T) {
 // No need for a DefaultInitExprScope: we don't handle 'this' in a
@@ -1216,8 +1225,10 @@
   }
 
   llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-QualType T) {
-return Visit(E->getSubExpr(), T);
+  QualType T) {
+if (E->isLValue() || E->isXValue())
+  return Visit(E->getSubExpr(), T);
+return nullptr;
   }
 
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
@@ -1276,6 +1287,9 @@
   }
 
   llvm::Constant *VisitInitListExpr(InitListExpr *ILE, QualType T) {
+if (ILE->getNumInits() && isa(ILE->getInit(0)))
+return nullptr;
+
 if (ILE->isTransparent())
   return Visit(ILE->getInit(0), T);
 
@@ -1655,27 +1669,27 @@
 
   QualType destType = D.getType();
 
-  // Try to emit the initializer.  Note that this can allow some things that
-  // are not allowed by tryEmitPrivateForMemory alone.
-  if (APValue *value = D.evaluateValue())
-return tryEmitPrivateForMemory(*value, destType);
-
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a temporary,
   // then constant initialization is performed. ConstExprEmitter will
   // incorrectly emit a prvalue constant in this case, and the calling code
   // interprets that as the (pointer) value of the reference, rather than the
   // desired value of the referee.
-  if (destType->isReferenceType())
-return nullptr;
 
   const Expr *E = D.getInit();
   assert(E && "No initializer to emit");
 
   QualType nonMemoryDestType = getNonMemoryType(CGM, destType);
-  

[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers updated this revision to Diff 527924.
nickdesaulniers edited the summary of this revision.
nickdesaulniers added a comment.

- just failing clang/test/CodeGenCXX/atomicinit.cpp


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

Files:
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/test/CodeGenCXX/const-init-cxx11.cpp
  clang/test/CodeGenCXX/const-init-cxx1y.cpp
  clang/test/CodeGenOpenCL/amdgpu-nullptr.cl

Index: clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
===
--- clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
+++ clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
@@ -57,7 +57,7 @@
 // CHECK: @fold_generic ={{.*}} local_unnamed_addr addrspace(1) global ptr null, align 8
 generic int *fold_generic = (global int*)(generic float*)(private char*)0;
 
-// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr null to ptr addrspace(5)), align 4
+// CHECK: @fold_priv ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) addrspacecast (ptr addrspace(1) null to ptr addrspace(5)), align 4
 private short *fold_priv = (private short*)(generic int*)(global void*)0;
 
 // CHECK: @fold_priv_arith ={{.*}} local_unnamed_addr addrspace(1) global ptr addrspace(5) inttoptr (i32 9 to ptr addrspace(5)), align 4
Index: clang/test/CodeGenCXX/const-init-cxx1y.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx1y.cpp
+++ clang/test/CodeGenCXX/const-init-cxx1y.cpp
@@ -34,8 +34,8 @@
   // 'c.temporary', not the value as modified by the partial evaluation within
   // the initialization of 'c.x'.
   A c = { 10, (++c.temporary, b.x) };
-  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
   // CHECK: @_ZN21ModifyStaticTemporary1cE ={{.*}} global {{.*}} zeroinitializer
+  // CHECK: @_ZGRN21ModifyStaticTemporary1cE_ = internal global i32 10
 }
 
 // CHECK: @_ZGRN28VariableTemplateWithConstRef1iIvEE_ = linkonce_odr constant i32 5, align 4
Index: clang/test/CodeGenCXX/const-init-cxx11.cpp
===
--- clang/test/CodeGenCXX/const-init-cxx11.cpp
+++ clang/test/CodeGenCXX/const-init-cxx11.cpp
@@ -88,7 +88,7 @@
 
   struct E {};
   struct Test2 : X, X, X, X {};
-  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} undef
+  // CHECK: @_ZN9BaseClass2t2E ={{.*}} constant {{.*}} zeroinitializer, align 1
   extern constexpr Test2 t2 = Test2();
 
   struct __attribute((packed)) PackedD { double y = 2; };
Index: clang/lib/CodeGen/CGExprConstant.cpp
===
--- clang/lib/CodeGen/CGExprConstant.cpp
+++ clang/lib/CodeGen/CGExprConstant.cpp
@@ -1204,6 +1204,19 @@
 }
 llvm_unreachable("Invalid CastKind");
   }
+  llvm::Constant *VisitImplicitCastExpr(ImplicitCastExpr *I, QualType T) {
+//if (I->isLValue())
+  //return nullptr;
+return VisitCastExpr(I, T);
+  }
+  llvm::Constant *VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *C, QualType T) {
+//if (C->isLValue())
+  //return nullptr;
+return VisitCastExpr(C, T);
+  }
+  llvm::Constant *VisitCStyleCastExpr(CStyleCastExpr *C, QualType T) {
+return VisitCastExpr(C, T);
+  }
 
   llvm::Constant *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE, QualType T) {
 // No need for a DefaultInitExprScope: we don't handle 'this' in a
@@ -1216,8 +1229,10 @@
   }
 
   llvm::Constant *VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *E,
-QualType T) {
-return Visit(E->getSubExpr(), T);
+  QualType T) {
+if (E->isLValue() || E->isXValue())
+  return Visit(E->getSubExpr(), T);
+return nullptr;
   }
 
   llvm::Constant *EmitArrayInitialization(InitListExpr *ILE, QualType T) {
@@ -1276,6 +1291,9 @@
   }
 
   llvm::Constant *VisitInitListExpr(InitListExpr *ILE, QualType T) {
+if (ILE->getNumInits() && isa(ILE->getInit(0)))
+return nullptr;
+
 if (ILE->isTransparent())
   return Visit(ILE->getInit(0), T);
 
@@ -1655,27 +1673,30 @@
 
   QualType destType = D.getType();
 
-  // Try to emit the initializer.  Note that this can allow some things that
-  // are not allowed by tryEmitPrivateForMemory alone.
-  if (APValue *value = D.evaluateValue())
-return tryEmitPrivateForMemory(*value, destType);
-
   // FIXME: Implement C++11 [basic.start.init]p2: if the initializer of a
   // reference is a constant expression, and the reference binds to a temporary,
   // then constant initialization is performed. ConstExprEmitter will
   // incorrectly emit a prvalue constant in this case, and the calling code
   // interprets that as the (pointer) value of the reference, rather than the
   // desired value of the referee.
-  if (destType->isReferenceType())

[PATCH] D151601: [NVPTX] Coalesce register classes for {i16,f16,bf16}, {i32,v2f16,v2bf16}

2023-06-02 Thread Justin Lebar via Phabricator via cfe-commits
jlebar accepted this revision.
jlebar added a comment.
This revision is now accepted and ready to land.

I cannot say that I 100% looked over every line, but in principle this seems 
fine, and if it's passing TF tests then that's pretty strong evidence this is 
working.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151601

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


[PATCH] D151923: [APFloat] Add APFloat semantic support for TF32

2023-06-02 Thread David Majnemer via Phabricator via cfe-commits
majnemer added inline comments.



Comment at: llvm/include/llvm/ADT/APFloat.h:190
+// greater throughput than single precision (32-bit) formats.
+S_FloatTF32,
 

Hmm,  this says improved precision than half but the semantics you gave say 11 
digits? Does NVIDIA document how many bits we should expect?



Comment at: llvm/lib/Support/APFloat.cpp:141
 4, -10, 4, 8, fltNonfiniteBehavior::NanOnly, fltNanEncoding::NegativeZero};
+static constexpr fltSemantics semFloatTF32 = {127, -126, 11, 19};
 static constexpr fltSemantics semX87DoubleExtended = {16383, -16382, 64, 80};

NVIDIA's 
[docs](https://docs.nvidia.com/cuda/parallel-thread-execution/#alternate-floating-point-data-formats)
 say:
> This data format is a special 32-bit floating point format supported by the 
> matrix multiply-and-accumulate instructions, with the same range as .f32 and 
> reduced precision (>=10 bits). The internal layout of tf32 format is 
> implementation defined. PTX facilitates conversion from single precision .f32 
> type to tf32 format. A register variable containing tf32 data must be 
> declared with .b32 type.

As written, it's at least 11 bits but it can change over time. Will we need 
corresponding flavors of this for future architectures over time?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151923

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


[PATCH] D151601: [NVPTX] Coalesce register classes for {i16,f16,bf16}, {i32,v2f16,v2bf16}

2023-06-02 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

I've tested the change on a bunch of tensorflow tests and the patch didn't 
cause any apparent issues.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151601

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


[PATCH] D152017: [DebugInfo] Add flag to only emit referenced member functions

2023-06-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie updated this revision to Diff 527920.
dblaikie added a comment.

Updating commit message with extra details


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152017

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -259,6 +259,9 @@
 // RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
 // RUN: %clang -### -c -fdebug-ranges-base-address 
-fno-debug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
 //
+// RUN: %clang -### -c -gincomplete-types %s 2>&1 | FileCheck 
-check-prefix=INCTYPES %s
+// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOINCTYPES %s
+//
 // RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
 // RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 //
@@ -398,6 +401,9 @@
 // RNGBSE: -fdebug-ranges-base-address
 // NORNGBSE-NOT: -fdebug-ranges-base-address
 //
+// INCTYPES: -gincomplete-types
+// NOINCTYPES-NOT: -gincomplete-types
+//
 // GARANGE-DAG: -generate-arange-section
 //
 // FDTS: "-mllvm" "-generate-type-units"
Index: clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -gincomplete-types %s -emit-llvm 
-o - | FileCheck %s
+
+struct t1 {
+  void f1();
+  void f2();
+};
+
+void t1::f1() { }
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1"
+// CHECK-SAME: elements: [[ELEMENTS:![0-9]+]]
+// CHECK: [[ELEMENTS]] = !{}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4308,6 +4308,12 @@
  DebuggerTuning != llvm::DebuggerKind::DBX)))
 CmdArgs.push_back("-gno-column-info");
 
+  if (const Arg *A = Args.getLastArg(options::OPT_gincomplete_types))
+(void)checkDebugInfoOption(A, Args, D, TC);
+  if (Args.hasFlag(options::OPT_gincomplete_types,
+   options::OPT_gno_incomplete_types, false))
+CmdArgs.push_back("-gincomplete-types");
+
   // FIXME: Move backend command line options to the module.
   if (Args.hasFlag(options::OPT_gmodules, options::OPT_gno_modules, false)) {
 // If -gline-tables-only or -gline-directives-only is the last option it
Index: clang/lib/CodeGen/CGDebugInfo.cpp
===
--- clang/lib/CodeGen/CGDebugInfo.cpp
+++ clang/lib/CodeGen/CGDebugInfo.cpp
@@ -2740,7 +2740,7 @@
 
   // Collect data fields (including static variables and any initializers).
   CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
-  if (CXXDecl)
+  if (CXXDecl && !CGM.getCodeGenOpts().DebugIncompleteTypes)
 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
 
   LexicalBlockStack.pop_back();
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3346,6 +3346,10 @@
   CodeGenOpts<"DebugStrictDwarf">, DefaultFalse,
   PosFlag, NegFlag, BothFlags<[CoreOption]>>,
   Group;
+defm incomplete_types : BoolOption<"g", "incomplete-types",
+  CodeGenOpts<"DebugIncompleteTypes">, DefaultFalse,
+  PosFlag, NegFlag, BothFlags<[CoreOption]>>,
+  Group;
 defm column_info : BoolOption<"g", "column-info",
   CodeGenOpts<"DebugColumnInfo">, DefaultTrue,
   NegFlag, PosFlag, BothFlags<[CoreOption]>>,
Index: clang/include/clang/Basic/CodeGenOptions.def
===
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -333,6 +333,8 @@
 VALUE_CODEGENOPT(WarnStackSize , 32, UINT_MAX) ///< Set via 
-fwarn-stack-size.
 CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
 CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF 
info.
+/// Whether or not to include all members in a type in debug info.
+CODEGENOPT(DebugIncompleteTypes, 1, 0)
 
 /// Control the Assignment Tracking debug info feature.
 ENUM_CODEGENOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2, 
AssignmentTrackingOpts::Disabled)


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ 

[PATCH] D152016: Remove 3-byte characters causing clang-tblgen to get I/O error.

2023-06-02 Thread Abhina Sree via Phabricator via cfe-commits
abhina.sreeskantharajan accepted this revision.
abhina.sreeskantharajan 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/D152016/new/

https://reviews.llvm.org/D152016

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


[PATCH] D152017: [DebugInfo] Add flag to only emit referenced member functions

2023-06-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie created this revision.
dblaikie added a reviewer: probinson.
Herald added a project: All.
dblaikie requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Complete C++ type information can be quite expensive - and there's
limited value in representing every member function, even those that
can't be called (we don't do similarly for every non-member function
anyway). So add a flag to opt out of this behavior for experimenting
with this more terse behavior.

I think Sony already does this by default, so perhaps with a change to
the defaults, Sony can migrate to this rather than a downstream patch.

This breaks current debuggers in some expected ways - but those
breakages are visible without this feature too. Consider member function
template instantiations - they can't be consistently enumerated in every
translation unit:

a.h:
struct t1 {

  template 
  static int f1() {
return i;
  }

};
namespace ns {
template 
int f1() {

  return i;

}
}  // namespace ns
a.cpp:
#include "a.h"
void f1() {

  t1::f1<0>();
  ns::f1<0>();

}
b.cpp:
#include "a.h"
void f1();
int main() {

  f1();
  t1::f1<1>();
  ns::f1<1>();

}

(gdb) p ns::f1<0>()
$1 = 0
(gdb) p ns::f1<1>()
$2 = 1
(gdb) p t1::f1<0>()
Couldn't find method t1::f1<0>
(gdb) p t1::f1<1>()
$3 = 1
(gdb) s
f1 () at a.cpp:3
3 t1::f1<0>();
(gdb) p t1::f1<0>()
$4 = 0
(gdb) p t1::f1<1>()
Couldn't find method t1::f1<1>
(gdb)

(other similar non-canonical features are implicit special members
(copy/move ctor/assignment operator, default ctor) and nested types (eg:
pimpl idiom, where the nested type is declared-but-not-defined in one
TU, and defined in another TU))

lldb can't parse the template expressions above, so I'm not sure how to
test it there, but I'd guess it has similar problems. (
https://stackoverflow.com/questions/64602475/how-to-print-value-returned-by-template-member-function-in-gdb-lldb-debugging
so... I guess that's just totally not supported in lldb, how
unfortunate. And implicit special members are instantiated implicitly by
lldb, so missing those doesn't tickle the same issue)

@probinson - would this be an accurate upstreaming of your internal 
handling/would you use this functionality? If it wouldn't be useful to you, 
it's maybe not worth adding upstream yet - not sure we'll use it at Google, but 
if it was useful to you folks and meant other folks could test with it it 
seemed maybe useful.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152017

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
  clang/test/Driver/debug-options.c


Index: clang/test/Driver/debug-options.c
===
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -259,6 +259,9 @@
 // RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
 // RUN: %clang -### -c -fdebug-ranges-base-address 
-fno-debug-ranges-base-address %s 2>&1 | FileCheck -check-prefix=NORNGBSE %s
 //
+// RUN: %clang -### -c -gincomplete-types %s 2>&1 | FileCheck 
-check-prefix=INCTYPES %s
+// RUN: %clang -### -c %s 2>&1 | FileCheck -check-prefix=NOINCTYPES %s
+//
 // RUN: %clang -### -c -glldb %s 2>&1 | FileCheck -check-prefix=NOPUB %s
 // RUN: %clang -### -c -glldb -gno-pubnames %s 2>&1 | FileCheck 
-check-prefix=NOPUB %s
 //
@@ -398,6 +401,9 @@
 // RNGBSE: -fdebug-ranges-base-address
 // NORNGBSE-NOT: -fdebug-ranges-base-address
 //
+// INCTYPES: -gincomplete-types
+// NOINCTYPES-NOT: -gincomplete-types
+//
 // GARANGE-DAG: -generate-arange-section
 //
 // FDTS: "-mllvm" "-generate-type-units"
Index: clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
===
--- /dev/null
+++ clang/test/CodeGenCXX/debug-info-incomplete-types.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -debug-info-kind=limited -gincomplete-types %s -emit-llvm 
-o - | FileCheck %s
+
+struct t1 {
+  void f1();
+  void f2();
+};
+
+void t1::f1() { }
+
+// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "t1"
+// CHECK-SAME: elements: [[ELEMENTS:![0-9]+]]
+// CHECK: [[ELEMENTS]] = !{}
Index: clang/lib/Driver/ToolChains/Clang.cpp
===
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4308,6 +4308,12 @@
  DebuggerTuning != llvm::DebuggerKind::DBX)))
 CmdArgs.push_back("-gno-column-info");
 
+  if (const Arg *A = Args.getLastArg(options::OPT_gincomplete_types))
+(void)checkDebugInfoOption(A, Args, D, TC);
+  if 

[PATCH] D152016: Remove 3-byte characters causing clang-tblgen to get I/O error.

2023-06-02 Thread Zibi Sarbino via Phabricator via cfe-commits
zibi created this revision.
zibi added reviewers: Kai, fanbo-meng, abhina.sreeskantharajan.
Herald added a reviewer: aaron.ballman.
Herald added a project: All.
zibi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

[SystemZ} This revision fixes the following error caused by 
301eb6b68f30074ee3a90e2dfbd11dfd87076323 
.
LLVM ERROR: IO failure on output stream: EDC5122I Input/output error.

The characters seems to be 3-byte characters which cause the failure with auto 
conversion from EBCDIC to ASCII.
Credit to @Kai who found this issue.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152016

Files:
  clang/include/clang/Basic/AttrDocs.td


Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -6559,7 +6559,7 @@
 
 The ``__arm_streaming`` keyword is only available on AArch64 targets.
 It applies to function types and specifies that the function has a
-“streaming interface”.  This means that:
+"streaming interface".  This means that:
 
 * the function requires the Scalable Matrix Extension (SME)
 
@@ -6578,7 +6578,7 @@
 that switches into streaming mode before calling the function and
 switches back to non-streaming mode on return.
 
-``__arm_streaming`` can appear anywhere that a standard ``[[…]]`` type
+``__arm_streaming`` can appear anywhere that a standard ``[[...]]`` type
 attribute can appear.
 
 See `Arm C Language Extensions `_


Index: clang/include/clang/Basic/AttrDocs.td
===
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -6559,7 +6559,7 @@
 
 The ``__arm_streaming`` keyword is only available on AArch64 targets.
 It applies to function types and specifies that the function has a
-“streaming interface”.  This means that:
+"streaming interface".  This means that:
 
 * the function requires the Scalable Matrix Extension (SME)
 
@@ -6578,7 +6578,7 @@
 that switches into streaming mode before calling the function and
 switches back to non-streaming mode on return.
 
-``__arm_streaming`` can appear anywhere that a standard ``[[…]]`` type
+``__arm_streaming`` can appear anywhere that a standard ``[[...]]`` type
 attribute can appear.
 
 See `Arm C Language Extensions `_
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro updated this revision to Diff 527914.

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

https://reviews.llvm.org/D151833

Files:
  clang/lib/Frontend/TextDiagnostic.cpp
  clang/test/Frontend/absolute-paths-import.h
  clang/test/Frontend/absolute-paths.c


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | 
FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE 
-check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. 
-fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s 
-check-prefix=ABSOLUTE -check-prefix=CHECK %s
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from {{.*absolute-paths.c:4}}:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -868,10 +868,11 @@
 }
 
 void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
-  if (DiagOpts->ShowLocation && PLoc.isValid())
-OS << "In file included from " << PLoc.getFilename() << ':'
-   << PLoc.getLine() << ":\n";
-  else
+  if (DiagOpts->ShowLocation && PLoc.isValid()) {
+OS << "In file included from ";
+emitFilename(PLoc.getFilename(), Loc.getManager());
+OS << ':' << PLoc.getLine() << ":\n";
+  } else
 OS << "In included file:\n";
 }
 


Index: clang/test/Frontend/absolute-paths.c
===
--- clang/test/Frontend/absolute-paths.c
+++ clang/test/Frontend/absolute-paths.c
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. %s 2>&1 | FileCheck -check-prefix=NORMAL -check-prefix=CHECK %s
-// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+// RUN: %clang_cc1 -fsyntax-only -I %S/Inputs/SystemHeaderPrefix/.. -fdiagnostics-absolute-paths %s 2>&1 | FileCheck -DROOT_ABSOLUTE=%s -check-prefix=ABSOLUTE -check-prefix=CHECK %s
+
+#include "absolute-paths-import.h"
+// NORMAL: In file included from {{.*absolute-paths.c:4}}:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 
 #include "absolute-paths.h"
 
Index: clang/test/Frontend/absolute-paths-import.h
===
--- /dev/null
+++ clang/test/Frontend/absolute-paths-import.h
@@ -0,0 +1 @@
+#warning abc
Index: clang/lib/Frontend/TextDiagnostic.cpp
===
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -868,10 +868,11 @@
 }
 
 void TextDiagnostic::emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) {
-  if (DiagOpts->ShowLocation && PLoc.isValid())
-OS << "In file included from " << PLoc.getFilename() << ':'
-   << PLoc.getLine() << ":\n";
-  else
+  if (DiagOpts->ShowLocation && PLoc.isValid()) {
+OS << "In file included from ";
+emitFilename(PLoc.getFilename(), Loc.getManager());
+OS << ':' << PLoc.getLine() << ":\n";
+  } else
 OS << "In included file:\n";
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D151587: [clang][ConstantEmitter] have tryEmitPrivateForVarInit try ConstExprEmitter fast-path first

2023-06-02 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/CodeGen/CGExprConstant.cpp:1324
 // This is a string literal initializing an array in an initializer.
-return CGM.GetConstantArrayFromStringLiteral(E);
+return E->isLValue() ?
+  CGM.GetAddrOfConstantStringFromLiteral(E).getPointer() :

efriedma wrote:
> nickdesaulniers wrote:
> > nickdesaulniers wrote:
> > > efriedma wrote:
> > > > nickdesaulniers wrote:
> > > > > efriedma wrote:
> > > > > > Maybe we should have a separate ConstExprEmitterLValue... trying to 
> > > > > > handle both LValues and RValues on the same codepath has been 
> > > > > > problematic in the past.  It's very easy for code to get confused 
> > > > > > what it's actually trying to emit.
> > > > > So we'd have a `ConstExprEmitterLValue` class with some visitor 
> > > > > methods, and a `ConstExprEmitterRValue` with other methods 
> > > > > implemented?
> > > > Something like that.
> > > > 
> > > > Actually thinking about it a bit more, not sure you need to actually 
> > > > implement ConstExprEmitterLValue for now.  You might just be able to 
> > > > ensure we don't ever call ConstExprEmitter with an lvalue.  The current 
> > > > ConstExprEmitter doesn't expect lvalues, and shouldn't call itself with 
> > > > lvalues.  (We bail on explicit LValueToRValue conversions.)  And 
> > > > Evaluate() shouldn't actually evaluate the contents of an lvalue if it 
> > > > isn't dereferenced, so there hopefully aren't any performance issues 
> > > > using that codepath.
> > > > 
> > > > In terms of implementation, I guess that's basically restoring the 
> > > > destType->isReferenceType() that got removed?  (I know I suggested it, 
> > > > but I wasn't really thinking about it...)
> > > One thing I think we may need to add to `ConstExprEmitter` is the ability 
> > > to evaluate `CallExpr`s based on certain test case failures...does that 
> > > seem right?
> > See also the calls to `constexpr f()` in 
> > clang/test/CodeGenCXX/const-init-cxx1y.cpp
> The only things I know of that Evaluate() can't handle are CK_ToUnion, 
> CK_ReinterpretMemberPointer, and DesignatedInitUpdateExpr.  
> DesignatedInitUpdateExpr is related to the failures in 
> test/CodeGenCXX/designated-init.cpp; I don't think the others show up in any 
> of the testcases you've mentioned.  (CK_ToUnion can't appear in C++ code. 
> CK_ReinterpretMemberPointer is a `reinterpret_cast` where T is a member 
> pointer type.)
> 
> Given none of those constructs show up in const-init-cxx1y.cpp, the only 
> reason for it to fail is if we aren't correctly falling back for a construct 
> the current code doesn't know how to handle.  You shouldn't need to implement 
> any new constructs.
in clang/test/CodeGenCXX/designated-init.cpp we have:
```
>> 22 namespace ModifyStaticTemporary { 
>>   
   23   struct A { int & int x; };   
  
   24   constexpr int f(int ) { r *= 9; return r - 12; }  
  
   25   A a = { 6, f(a.temporary) };
```
In the AST, that looks like:
```
| |-VarDecl 0x562b77df39b0  col:5 used a 
'A':'ModifyStaticTemporary::A' cinit
| | `-ExprWithCleanups 0x562b77df3c68  
'A':'ModifyStaticTemporary::A'
| |   `-InitListExpr 0x562b77df3bb8  
'A':'ModifyStaticTemporary::A'
| | |-MaterializeTemporaryExpr 0x562b77df3c08  'int' xvalue 
extended by Var 0x562b77df39b0 'a' 'A':'ModifyStaticTemporary::A'
| | | `-IntegerLiteral 0x562b77df3a18  'int' 6
| | `-CallExpr 0x562b77df3b30  'int'
| |   |-ImplicitCastExpr 0x562b77df3b18  'int (*)(int &)' 

| |   | `-DeclRefExpr 0x562b77df3ad0  'int (int &)' lvalue Function 
0x562b77df37a0 'f' 'int (int &)'
| |   `-MemberExpr 0x562b77df3aa0  'int' lvalue .temporary 
0x562b77df35c0
| | `-DeclRefExpr 0x562b77df3a80  
'A':'ModifyStaticTemporary::A' lvalue Var 0x562b77df39b0 'a' 
'A':'ModifyStaticTemporary::A'
```
(So, indeed no `DesignatedInitUpdateExpr`) but the call to the `constexpr` 
`f()` updates the reference (to `54`).  If I remove the visitor for 
`MaterializeTemporaryExpr`, we fail to evaluate `f` and end up emitting `6` 
rather than `54`.  Doesn't that mean that the fast path (`ConstExprEmitter`) 
needs to be able to evaluate `CallExpr`?

Or should `VisitInitListExpr` bail if any of the inits 
`isa` (or perhaps `isa`)?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151587

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


[clang-tools-extra] 860e439 - [Clang] Fix missing libraries for the include cleaner check

2023-06-02 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2023-06-02T12:43:55-05:00
New Revision: 860e439fb27f86b97bfd9acce5e27f4337c471c7

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

LOG: [Clang] Fix missing libraries for the include cleaner check

Summary:
Recently, the changes in https://reviews.llvm.org/D148793 introduced
some extra dependencies that caused link failured on my machine. This
patch adds the necessary libraries to resolve the link failures and
allow me to build again.

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index 1703ff82b942d..fde72f6b25a54 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -55,8 +55,11 @@ clang_target_link_libraries(clangTidyMiscModule
   clangAST
   clangASTMatchers
   clangBasic
+  clangFormat
   clangIncludeCleaner
   clangLex
   clangSerialization
   clangTooling
+  clangToolingInclusions
+  clangToolingInclusionsStdlib
   )



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


[PATCH] D151634: [clang] Add test for CWG253

2023-06-02 Thread Vlad Serebrennikov via Phabricator via cfe-commits
Endill added inline comments.



Comment at: clang/test/CXX/drs/dr0xx.cpp:1022
 
-namespace dr78 { // dr78: sup 
+namespace dr78 { // dr78: no
   // Under DR78, this is valid, because 'k' has static storage duration, so is

shafik wrote:
> shafik wrote:
> > This is [issue 1380](https://github.com/cplusplus/papers/issues/1380) and 
> > the issue is whether we want static initialization to happen before 
> > constant initialization or whether constant initialization excludes 
> > zero-init. 
> > 
> > I think dr77 is now part of [cwg 
> > 2536](https://cplusplus.github.io/CWG/issues/2536.html) and we need to wait 
> > for the resolution of that in order to know what to do here. 
> I was mistaken and completely missed: 
> https://eel.is/c++draft/dcl.init#general-8.sentence-2
> 
> DR 78 is just repeating what we have in: 
> https://eel.is/c++draft/basic.start#static
> 
> The wording has changed a lot since DR 78.
Can you please elaborate how does your conclusion affect this patch? Because I 
feel a bit lost at this point.
Was my initial analysis correct, and we should say that this DR is not 
available in Clang?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151634

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


[PATCH] D152009: [clang] Fix assertion while parsing an invalid for loop

2023-06-02 Thread Corentin Jabot via Phabricator via cfe-commits
cor3ntin updated this revision to Diff 527902.
cor3ntin added a comment.

revert ws changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152009

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Parser/cxx0x-for-range.cpp
  clang/test/Parser/objc-foreach-syntax.m


Index: clang/test/Parser/objc-foreach-syntax.m
===
--- clang/test/Parser/objc-foreach-syntax.m
+++ clang/test/Parser/objc-foreach-syntax.m
@@ -21,8 +21,6 @@
 
 
 static int test7(id keys) {
-  // FIXME: would be nice to suppress the secondary diagnostics.
   for (id key; in keys) ;  // expected-error {{use of undeclared identifier 
'in'}} \
-   // expected-error {{expected ';' in 'for' statement 
specifier}} \
-   // expected-warning {{expression result unused}}
+   // expected-error {{expected ';' in 'for' statement 
specifier}}
 }
Index: clang/test/Parser/cxx0x-for-range.cpp
===
--- clang/test/Parser/cxx0x-for-range.cpp
+++ clang/test/Parser/cxx0x-for-range.cpp
@@ -60,3 +60,12 @@
   }
 }
 }
+
+namespace GH63010 {
+void foo(int n) {
+int a[] = {1, 2, 3, 4, 5};
+for (auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' 
statement specifier}} \
+  // expected-error {{expected expression}}
+for (int i = 1; auto x = n ? 1 : 2 : a); // expected-error {{expected ';' 
in 'for' statement specifier}}
+}
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2197,9 +2197,7 @@
 if (Tok.isNot(tok::semi)) {
   if (!SecondPart.isInvalid())
 Diag(Tok, diag::err_expected_semi_for);
-  else
-// Skip until semicolon or rparen, don't consume it.
-SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
+  SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
 }
 
 if (Tok.is(tok::semi)) {
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2138,8 +2138,6 @@
 DeclGroupPtrTy DG = ParseSimpleDeclaration(
 DeclaratorContext::ForInit, DeclEnd, attrs, DeclSpecAttrs, false, FRI);
 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
-assert((FRI->ColonLoc.isValid() || !DG) &&
-   "cannot find for range declaration");
 return Sema::ConditionResult();
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -455,6 +455,9 @@
 - Fix crash when diagnosing default comparison method.
   (`#62791 `_) and
   (`#62102 `_).
+- Fix assertion and quality of diagnostic messages in a for loop
+  containing multiple declarations and a range specifier
+  (`#63010 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Parser/objc-foreach-syntax.m
===
--- clang/test/Parser/objc-foreach-syntax.m
+++ clang/test/Parser/objc-foreach-syntax.m
@@ -21,8 +21,6 @@
 
 
 static int test7(id keys) {
-  // FIXME: would be nice to suppress the secondary diagnostics.
   for (id key; in keys) ;  // expected-error {{use of undeclared identifier 'in'}} \
-   // expected-error {{expected ';' in 'for' statement specifier}} \
-   // expected-warning {{expression result unused}}
+   // expected-error {{expected ';' in 'for' statement specifier}}
 }
Index: clang/test/Parser/cxx0x-for-range.cpp
===
--- clang/test/Parser/cxx0x-for-range.cpp
+++ clang/test/Parser/cxx0x-for-range.cpp
@@ -60,3 +60,12 @@
   }
 }
 }
+
+namespace GH63010 {
+void foo(int n) {
+int a[] = {1, 2, 3, 4, 5};
+for (auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' statement specifier}} \
+  // expected-error {{expected expression}}
+for (int i = 1; auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' statement specifier}}
+}
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2197,9 +2197,7 @@
 if (Tok.isNot(tok::semi)) {
   if (!SecondPart.isInvalid())
 Diag(Tok, 

[PATCH] D144911: adding bf16 support to NVPTX

2023-06-02 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D144911#4389187 , @manishucsd 
wrote:

> I fail to compile this patch. Please find the compilation error below:
>
>   [build] ./llvm-project/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td:1117:40: 
> error: Variable not defined: 'hasPTX70'
>   [build] Requires<[useFP16Math, hasPTX70, hasSM80, Pred]>;
>   [build]^

You need to update your patch. Recent LLVM changes have changed `hasPTXab` -> 
`hasPTX`, and similarly `hasSMab` > `hasSM`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144911

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


[PATCH] D152009: [clang] Fix assertion while parsing an invalid for loop

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

with multiple declarations followed by a colon.

Fixes #63010


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152009

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseStmt.cpp
  clang/test/Parser/cxx0x-for-range.cpp
  clang/test/Parser/objc-foreach-syntax.m


Index: clang/test/Parser/objc-foreach-syntax.m
===
--- clang/test/Parser/objc-foreach-syntax.m
+++ clang/test/Parser/objc-foreach-syntax.m
@@ -11,18 +11,16 @@
 
 int LOOP(void);
 
-@implementation MyList (BasicTest) 
+@implementation MyList (BasicTest)
 - (void)compilerTestAgainst {
-MyList * el; 
- for (el in @"foo") 
+MyList * el;
+ for (el in @"foo")
  { LOOP(); }
 }
 @end
 
 
 static int test7(id keys) {
-  // FIXME: would be nice to suppress the secondary diagnostics.
   for (id key; in keys) ;  // expected-error {{use of undeclared identifier 
'in'}} \
-   // expected-error {{expected ';' in 'for' statement 
specifier}} \
-   // expected-warning {{expression result unused}}
+   // expected-error {{expected ';' in 'for' statement 
specifier}}
 }
Index: clang/test/Parser/cxx0x-for-range.cpp
===
--- clang/test/Parser/cxx0x-for-range.cpp
+++ clang/test/Parser/cxx0x-for-range.cpp
@@ -60,3 +60,12 @@
   }
 }
 }
+
+namespace GH63010 {
+void foo(int n) {
+int a[] = {1, 2, 3, 4, 5};
+for (auto x = n ? 1 : 2 : a); // expected-error {{expected ';' in 'for' 
statement specifier}} \
+  // expected-error {{expected expression}}
+for (int i = 1; auto x = n ? 1 : 2 : a); // expected-error {{expected ';' 
in 'for' statement specifier}}
+}
+}
Index: clang/lib/Parse/ParseStmt.cpp
===
--- clang/lib/Parse/ParseStmt.cpp
+++ clang/lib/Parse/ParseStmt.cpp
@@ -2197,9 +2197,7 @@
 if (Tok.isNot(tok::semi)) {
   if (!SecondPart.isInvalid())
 Diag(Tok, diag::err_expected_semi_for);
-  else
-// Skip until semicolon or rparen, don't consume it.
-SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
+  SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch);
 }
 
 if (Tok.is(tok::semi)) {
Index: clang/lib/Parse/ParseExprCXX.cpp
===
--- clang/lib/Parse/ParseExprCXX.cpp
+++ clang/lib/Parse/ParseExprCXX.cpp
@@ -2138,8 +2138,6 @@
 DeclGroupPtrTy DG = ParseSimpleDeclaration(
 DeclaratorContext::ForInit, DeclEnd, attrs, DeclSpecAttrs, false, FRI);
 FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
-assert((FRI->ColonLoc.isValid() || !DG) &&
-   "cannot find for range declaration");
 return Sema::ConditionResult();
   }
 
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -455,6 +455,9 @@
 - Fix crash when diagnosing default comparison method.
   (`#62791 `_) and
   (`#62102 `_).
+- Fix assertion and quality of diagnostic messages in a for loop
+  containing multiple declarations and a range specifier
+  (`#63010 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/Parser/objc-foreach-syntax.m
===
--- clang/test/Parser/objc-foreach-syntax.m
+++ clang/test/Parser/objc-foreach-syntax.m
@@ -11,18 +11,16 @@
 
 int LOOP(void);
 
-@implementation MyList (BasicTest) 
+@implementation MyList (BasicTest)
 - (void)compilerTestAgainst {
-MyList * el; 
- for (el in @"foo") 
+MyList * el;
+ for (el in @"foo")
 	  { LOOP(); }
 }
 @end
 
 
 static int test7(id keys) {
-  // FIXME: would be nice to suppress the secondary diagnostics.
   for (id key; in keys) ;  // expected-error {{use of undeclared identifier 'in'}} \
-   // expected-error {{expected ';' in 'for' statement specifier}} \
-   // expected-warning {{expression result unused}}
+   // expected-error {{expected ';' in 'for' statement specifier}}
 }
Index: clang/test/Parser/cxx0x-for-range.cpp
===
--- clang/test/Parser/cxx0x-for-range.cpp
+++ clang/test/Parser/cxx0x-for-range.cpp
@@ -60,3 +60,12 @@
   }
 }
 }
+
+namespace GH63010 {
+void foo(int n) {
+int a[] = {1, 2, 3, 4, 5};
+for (auto x = n ? 1 : 2 : a); 

[PATCH] D148924: [clang] Show error if defaulted comparions operator function is volatile or has ref-qualifier &&.

2023-06-02 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

@massberg did we figure out if there is anything else left from P2002R1? Are 
there blockers to landing this?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148924

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


[PATCH] D151634: [clang] Add test for CWG253

2023-06-02 Thread Shafik Yaghmour via Phabricator via cfe-commits
shafik added inline comments.



Comment at: clang/test/CXX/drs/dr0xx.cpp:1022
 
-namespace dr78 { // dr78: sup 
+namespace dr78 { // dr78: no
   // Under DR78, this is valid, because 'k' has static storage duration, so is

shafik wrote:
> This is [issue 1380](https://github.com/cplusplus/papers/issues/1380) and the 
> issue is whether we want static initialization to happen before constant 
> initialization or whether constant initialization excludes zero-init. 
> 
> I think dr77 is now part of [cwg 
> 2536](https://cplusplus.github.io/CWG/issues/2536.html) and we need to wait 
> for the resolution of that in order to know what to do here. 
I was mistaken and completely missed: 
https://eel.is/c++draft/dcl.init#general-8.sentence-2

DR 78 is just repeating what we have in: 
https://eel.is/c++draft/basic.start#static

The wording has changed a lot since DR 78.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151634

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


[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/include/clang/AST/Stmt.h:796-802
+/// If this expression is not value-dependent, this stores the value.
+unsigned Value : 8;
 
 /// The number of arguments to this type trait. According to [implimits]
 /// 8 bits would be enough, but we require (and test for) at least 16 bits
 /// to mirror FunctionType.
+unsigned NumArgs : 16;

cjdb wrote:
> erichkeane wrote:
> > dblaikie wrote:
> > > cjdb wrote:
> > > > These numbers feel very low for how this modification is using them. 
> > > > Perhaps they should both be bumped to 32?
> > > clang does, I think, have specific implementation limits for this sort of 
> > > thing - 
> > > 
> > > Well, maybe we don't actually enforce a limit on number of template 
> > > arguments... https://godbolt.org/z/accncYson compiles successfully, and 
> > > has 2^18 parameters, beyond the 2^16 suggested here.
> > > 
> > > But maybe 2^16 is just what we test for/somewhat guarantee.
> > > 
> > > But if the `Value` is going to be the index into the args, shouldn't it 
> > > be the same size as `NumArgs`, at least? (& the comment says 16, so 16 
> > > for both Value and NumArgs would seem suitably symmetric, and no larger 
> > > than the current situation - since it'd just be splitting NumArgs in 
> > > half, while still meeting the comment's suggestion/requirements?)
> > > 
> > > An assert, at least, when populating NumArgs to ensure it's no larger 
> > > might not hurt... (which might be reachable from code/not checked prior - 
> > > so it could be a hard compilation error, I guess, but I wouldn't feel 
> > > super strongly about it)
> > Can you explain the math here of how you chose to change this to 16?  I see 
> > that you removed 7 bits, but took away 16.  I'm not sure what NumExprBits 
> > is doing though, I got lost a little in that, so if you can calculate that 
> > to make sure this needs to be done, it would be appreciated.
> > 
> > Additionally, a static_assert after this to ensure the size isn't changing 
> > would also be appreciated.
> > 
> > But if the Value is going to be the index into the args, shouldn't it be 
> > the same size as NumArgs, at least? (& the comment says 16, so 16 for both 
> > Value and NumArgs would seem suitably symmetric, and no larger than the 
> > current situation - since it'd just be splitting NumArgs in half, while 
> > still meeting the comment's suggestion/requirements?)
> 
> Someone independently confirmed that you can have 200k types in a template, 
> so we should probably be able to count at least that high (or alternatively, 
> we should possibly consider not allowing more than 2^16 template parameters).
> 
> > Can you explain the math here of how you chose to change this to 16? I see 
> > that you removed 7 bits, but took away 16. I'm not sure what NumExprBits is 
> > doing though, I got lost a little in that, so if you can calculate that to 
> > make sure this needs to be done, it would be appreciated.
> 
> The value of `NumArgs` hasn't changed: I've just codified it. I can't work 
> out why we need `NumExprBits`, but it's apparently required padding (when I 
> removed it, a bunch of tests failed). Its value is 18, courtesy of clangd in 
> VS Code.
> 
> > Additionally, a static_assert after this to ensure the size isn't changing 
> > would also be appreciated.
> 
> There's a static_assert in one of the `Stmt` constructors, which doesn't want 
> more than eight bytes (we apparently need 16 if we're to change this).
Got it, thanks!  We need the `NumExprBits` because this gets cast to that 
`ExprBitFields` (since this inherits from Expr).  So thats the 'base type' bits.

18 + 8 + 8 (for the `NumExprbits` and `Kind` and `Value` fields) is 34, so that 
leaves plenty of extra bits here, right?  Usually in these cases we leave 
things 'as big as we can without growing the thing', then comment where extra 
bits can be stolen in the future.

So I would just make this 'the rest' of our size, since we're already over 4 
bytes, mind as well use them as long as we can.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread Christopher Di Bella via Phabricator via cfe-commits
cjdb added inline comments.



Comment at: clang/include/clang/AST/Stmt.h:796-802
+/// If this expression is not value-dependent, this stores the value.
+unsigned Value : 8;
 
 /// The number of arguments to this type trait. According to [implimits]
 /// 8 bits would be enough, but we require (and test for) at least 16 bits
 /// to mirror FunctionType.
+unsigned NumArgs : 16;

erichkeane wrote:
> dblaikie wrote:
> > cjdb wrote:
> > > These numbers feel very low for how this modification is using them. 
> > > Perhaps they should both be bumped to 32?
> > clang does, I think, have specific implementation limits for this sort of 
> > thing - 
> > 
> > Well, maybe we don't actually enforce a limit on number of template 
> > arguments... https://godbolt.org/z/accncYson compiles successfully, and has 
> > 2^18 parameters, beyond the 2^16 suggested here.
> > 
> > But maybe 2^16 is just what we test for/somewhat guarantee.
> > 
> > But if the `Value` is going to be the index into the args, shouldn't it be 
> > the same size as `NumArgs`, at least? (& the comment says 16, so 16 for 
> > both Value and NumArgs would seem suitably symmetric, and no larger than 
> > the current situation - since it'd just be splitting NumArgs in half, while 
> > still meeting the comment's suggestion/requirements?)
> > 
> > An assert, at least, when populating NumArgs to ensure it's no larger might 
> > not hurt... (which might be reachable from code/not checked prior - so it 
> > could be a hard compilation error, I guess, but I wouldn't feel super 
> > strongly about it)
> Can you explain the math here of how you chose to change this to 16?  I see 
> that you removed 7 bits, but took away 16.  I'm not sure what NumExprBits is 
> doing though, I got lost a little in that, so if you can calculate that to 
> make sure this needs to be done, it would be appreciated.
> 
> Additionally, a static_assert after this to ensure the size isn't changing 
> would also be appreciated.
> 
> But if the Value is going to be the index into the args, shouldn't it be the 
> same size as NumArgs, at least? (& the comment says 16, so 16 for both Value 
> and NumArgs would seem suitably symmetric, and no larger than the current 
> situation - since it'd just be splitting NumArgs in half, while still meeting 
> the comment's suggestion/requirements?)

Someone independently confirmed that you can have 200k types in a template, so 
we should probably be able to count at least that high (or alternatively, we 
should possibly consider not allowing more than 2^16 template parameters).

> Can you explain the math here of how you chose to change this to 16? I see 
> that you removed 7 bits, but took away 16. I'm not sure what NumExprBits is 
> doing though, I got lost a little in that, so if you can calculate that to 
> make sure this needs to be done, it would be appreciated.

The value of `NumArgs` hasn't changed: I've just codified it. I can't work out 
why we need `NumExprBits`, but it's apparently required padding (when I removed 
it, a bunch of tests failed). Its value is 18, courtesy of clangd in VS Code.

> Additionally, a static_assert after this to ensure the size isn't changing 
> would also be appreciated.

There's a static_assert in one of the `Stmt` constructors, which doesn't want 
more than eight bytes (we apparently need 16 if we're to change this).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D149573#4391083 , @codemzs wrote:

> In D149573#4391013 , @erichkeane 
> wrote:
>
>> In D149573#4390895 , @codemzs 
>> wrote:
>>
>>> In D149573#4390863 , @stuij wrote:
>>>
 This is going to be a very unhelpful comment. After looking through the 
 changes, I don't have any comments to make, but I also don't feel 
 comfortable to accept this revision as I don't feel to know enough about 
 the front-end.
>>>
>>> @stuij, I sincerely appreciate you taking the time to review the changes. 
>>> Your hesitation due to unfamiliarity with the front-end elements is 
>>> completely understandable, and I respect your candid feedback.
>>>
>>> @erichkeane, given your extensive contributions to the core `Sema`* files, 
>>> I believe your expertise and experience would be particularly valuable in 
>>> reviewing the changes I've made. I recall your initial informal approval 
>>> for the change, and since then, I've further refined it after incorporating 
>>> the outcomes of D150913 . I'd be most 
>>> appreciative if you could please review this revision once again.
>>>
>>> My intention is to ensure this revision aligns with our shared vision for 
>>> LLVM/Clang, and your reviews will greatly contribute to this goal. If there 
>>> are any other changes or improvements required for the successful landing 
>>> of this revision, please feel free to let me know.
>>
>> I'll put you on my list to re-review for early next week, though Aaron 
>> probably needs to do a look through this as well.
>
> Thank you, @erichkeane that would be great, are you referring to 
> @aaron.ballman ?

Yes.


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

https://reviews.llvm.org/D149573

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


[PATCH] D151944: [Driver] Move -nostdinc like options into IncludePath_Group

2023-06-02 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5b77e752dcd0: [Driver] Move -nostdinc like options into 
IncludePath_Group (authored by MaskRay).

Changed prior to commit:
  https://reviews.llvm.org/D151944?vs=527645=527884#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151944

Files:
  clang/include/clang/Driver/Options.td
  clang/test/Driver/linker-opts.c


Index: clang/test/Driver/linker-opts.c
===
--- clang/test/Driver/linker-opts.c
+++ clang/test/Driver/linker-opts.c
@@ -15,9 +15,8 @@
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
-// RUN: %clang -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s 
--check-prefix=NO-UNUSED
-// NO-UNUSED-NOT: warning:{{.*}}unused
-//
+// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ 
-nostdlibinc -nogpuinc %t/tmp.o -o /dev/null 2>&1 | FileCheck /dev/null 
--implicit-check-not=warning:
+
 // Make sure that we do warn in other cases.
 // RUN: %clang %s -lfoo -c -o %t/tmp2.o -### 2>&1 | FileCheck %s 
--check-prefix=UNUSED
 // UNUSED: warning:{{.*}}unused
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3391,7 +3391,7 @@
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option,
 FlangOption]>, HelpText<"Display available options">,
 MarshallingInfoFlag>;
-def ibuiltininc : Flag<["-"], "ibuiltininc">,
+def ibuiltininc : Flag<["-"], "ibuiltininc">, Group,
   HelpText<"Enable builtin #include directories even when -nostdinc is used "
"before or after -ibuiltininc. "
"Using -nobuiltininc after the option disables it">;
@@ -4194,12 +4194,13 @@
 def no_integrated_cpp : Flag<["-", "--"], "no-integrated-cpp">, 
Flags<[NoXarchOption]>;
 def no_pedantic : Flag<["-", "--"], "no-pedantic">, Group;
 def no__dead__strip__inits__and__terms : Flag<["-"], 
"no_dead_strip_inits_and_terms">;
-def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, CoreOption]>,
+def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, 
CoreOption]>, Group,
   HelpText<"Disable builtin #include directories">,
   MarshallingInfoNegativeFlag>;
-def nogpuinc : Flag<["-"], "nogpuinc">, HelpText<"Do not add include paths for 
CUDA/HIP and"
+def nogpuinc : Flag<["-"], "nogpuinc">, Group,
+  HelpText<"Do not add include paths for CUDA/HIP and"
   " do not include the default CUDA/HIP wrapper headers">;
-def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">,
+def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">, Group,
   HelpText<"Do not include the default HIP wrapper headers and include paths">;
 def : Flag<["-"], "nocudainc">, Alias;
 def nogpulib : Flag<["-"], "nogpulib">, 
MarshallingInfoFlag>,
@@ -4216,9 +4217,9 @@
 def noprofilelib : Flag<["-"], "noprofilelib">;
 def noseglinkedit : Flag<["-"], "noseglinkedit">;
 def nostartfiles : Flag<["-"], "nostartfiles">, Group;
-def nostdinc : Flag<["-"], "nostdinc">, Flags<[CoreOption]>;
-def nostdlibinc : Flag<["-"], "nostdlibinc">;
-def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>,
+def nostdinc : Flag<["-"], "nostdinc">, Flags<[CoreOption]>, 
Group;
+def nostdlibinc : Flag<["-"], "nostdlibinc">, Group;
+def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>, 
Group,
   HelpText<"Disable standard #include directories for the C++ standard 
library">,
   MarshallingInfoNegativeFlag>;
 def nostdlib : Flag<["-"], "nostdlib">, Group;


Index: clang/test/Driver/linker-opts.c
===
--- clang/test/Driver/linker-opts.c
+++ clang/test/Driver/linker-opts.c
@@ -15,9 +15,8 @@
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
-// RUN: %clang -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s --check-prefix=NO-UNUSED
-// NO-UNUSED-NOT: warning:{{.*}}unused
-//
+// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ -nostdlibinc -nogpuinc %t/tmp.o -o /dev/null 2>&1 | FileCheck /dev/null --implicit-check-not=warning:
+
 // Make sure that we do warn in other cases.
 // RUN: %clang %s -lfoo -c -o %t/tmp2.o -### 2>&1 | FileCheck %s --check-prefix=UNUSED
 // UNUSED: warning:{{.*}}unused
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -3391,7 +3391,7 @@
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option,
 FlangOption]>, HelpText<"Display available options">,
 MarshallingInfoFlag>;
-def ibuiltininc : Flag<["-"], 

[clang] 5b77e75 - [Driver] Move -nostdinc like options into IncludePath_Group

2023-06-02 Thread Fangrui Song via cfe-commits

Author: Fangrui Song
Date: 2023-06-02T09:33:08-07:00
New Revision: 5b77e752dcd073846b89559d6c0e1a7699e58615

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

LOG: [Driver] Move -nostdinc like options into IncludePath_Group

With only a link action, we claim all CompileOnly_Group options (including -f*,
-m*, -i*, etc). It makes sense to claim -nostdinc family options as well.
We can achieve this by placing these options into IncludePath_Group, a 
derivative of
CompileOnly_Group.

Reviewed By: theuni

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td
clang/test/Driver/linker-opts.c

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b77fec6720792..29b41002cf37b 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3391,7 +3391,7 @@ def headerpad__max__install__names : Joined<["-"], 
"headerpad_max_install_names"
 def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, FC1Option,
 FlangOption]>, HelpText<"Display available options">,
 MarshallingInfoFlag>;
-def ibuiltininc : Flag<["-"], "ibuiltininc">,
+def ibuiltininc : Flag<["-"], "ibuiltininc">, Group,
   HelpText<"Enable builtin #include directories even when -nostdinc is used "
"before or after -ibuiltininc. "
"Using -nobuiltininc after the option disables it">;
@@ -4194,12 +4194,13 @@ def no_cpp_precomp : Flag<["-"], "no-cpp-precomp">, 
Group
 def no_integrated_cpp : Flag<["-", "--"], "no-integrated-cpp">, 
Flags<[NoXarchOption]>;
 def no_pedantic : Flag<["-", "--"], "no-pedantic">, Group;
 def no__dead__strip__inits__and__terms : Flag<["-"], 
"no_dead_strip_inits_and_terms">;
-def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, CoreOption]>,
+def nobuiltininc : Flag<["-"], "nobuiltininc">, Flags<[CC1Option, 
CoreOption]>, Group,
   HelpText<"Disable builtin #include directories">,
   MarshallingInfoNegativeFlag>;
-def nogpuinc : Flag<["-"], "nogpuinc">, HelpText<"Do not add include paths for 
CUDA/HIP and"
+def nogpuinc : Flag<["-"], "nogpuinc">, Group,
+  HelpText<"Do not add include paths for CUDA/HIP and"
   " do not include the default CUDA/HIP wrapper headers">;
-def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">,
+def nohipwrapperinc : Flag<["-"], "nohipwrapperinc">, Group,
   HelpText<"Do not include the default HIP wrapper headers and include paths">;
 def : Flag<["-"], "nocudainc">, Alias;
 def nogpulib : Flag<["-"], "nogpulib">, 
MarshallingInfoFlag>,
@@ -4216,9 +4217,9 @@ def noprebind : Flag<["-"], "noprebind">;
 def noprofilelib : Flag<["-"], "noprofilelib">;
 def noseglinkedit : Flag<["-"], "noseglinkedit">;
 def nostartfiles : Flag<["-"], "nostartfiles">, Group;
-def nostdinc : Flag<["-"], "nostdinc">, Flags<[CoreOption]>;
-def nostdlibinc : Flag<["-"], "nostdlibinc">;
-def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>,
+def nostdinc : Flag<["-"], "nostdinc">, Flags<[CoreOption]>, 
Group;
+def nostdlibinc : Flag<["-"], "nostdlibinc">, Group;
+def nostdincxx : Flag<["-"], "nostdinc++">, Flags<[CC1Option]>, 
Group,
   HelpText<"Disable standard #include directories for the C++ standard 
library">,
   MarshallingInfoNegativeFlag>;
 def nostdlib : Flag<["-"], "nostdlib">, Group;

diff  --git a/clang/test/Driver/linker-opts.c b/clang/test/Driver/linker-opts.c
index e3c4e00ea0c75..319cc591cc3c8 100644
--- a/clang/test/Driver/linker-opts.c
+++ b/clang/test/Driver/linker-opts.c
@@ -15,9 +15,8 @@
 //
 // Make sure that we don't warn on unused compiler arguments.
 // RUN: %clang -Xclang -I. -x c %s -c -o %t/tmp.o
-// RUN: %clang -Xclang -I. %t/tmp.o -o %t/tmp -### 2>&1 | FileCheck %s 
--check-prefix=NO-UNUSED
-// NO-UNUSED-NOT: warning:{{.*}}unused
-//
+// RUN: %clang -### -I. -ibuiltininc -nobuiltininc -nostdinc -nostdinc++ 
-nostdlibinc -nogpuinc %t/tmp.o -o /dev/null 2>&1 | FileCheck /dev/null 
--implicit-check-not=warning:
+
 // Make sure that we do warn in other cases.
 // RUN: %clang %s -lfoo -c -o %t/tmp2.o -### 2>&1 | FileCheck %s 
--check-prefix=UNUSED
 // UNUSED: warning:{{.*}}unused



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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs added a subscriber: aaron.ballman.
codemzs added a comment.

In D149573#4391013 , @erichkeane 
wrote:

> In D149573#4390895 , @codemzs wrote:
>
>> In D149573#4390863 , @stuij wrote:
>>
>>> This is going to be a very unhelpful comment. After looking through the 
>>> changes, I don't have any comments to make, but I also don't feel 
>>> comfortable to accept this revision as I don't feel to know enough about 
>>> the front-end.
>>
>> @stuij, I sincerely appreciate you taking the time to review the changes. 
>> Your hesitation due to unfamiliarity with the front-end elements is 
>> completely understandable, and I respect your candid feedback.
>>
>> @erichkeane, given your extensive contributions to the core `Sema`* files, I 
>> believe your expertise and experience would be particularly valuable in 
>> reviewing the changes I've made. I recall your initial informal approval for 
>> the change, and since then, I've further refined it after incorporating the 
>> outcomes of D150913 . I'd be most 
>> appreciative if you could please review this revision once again.
>>
>> My intention is to ensure this revision aligns with our shared vision for 
>> LLVM/Clang, and your reviews will greatly contribute to this goal. If there 
>> are any other changes or improvements required for the successful landing of 
>> this revision, please feel free to let me know.
>
> I'll put you on my list to re-review for early next week, though Aaron 
> probably needs to do a look through this as well.

Thank you, @erichkeane that would be great, are you referring to @aaron.ballman 
?


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

https://reviews.llvm.org/D149573

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


[clang] 8b5dbc3 - [CodeGen] Use llvm::LLVMContext::MD_invariant_load (NFC)

2023-06-02 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-06-02T09:25:00-07:00
New Revision: 8b5dbc37a899faf0d2cb842bcb1ebc66a319c394

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

LOG: [CodeGen] Use llvm::LLVMContext::MD_invariant_load (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CGObjC.cpp
clang/lib/CodeGen/CGObjCMac.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp
index 7df2088a81d79..c8f0070192dd6 100644
--- a/clang/lib/CodeGen/CGObjC.cpp
+++ b/clang/lib/CodeGen/CGObjC.cpp
@@ -140,7 +140,7 @@ llvm::Value 
*CodeGenFunction::EmitObjCCollectionLiteral(const Expr *E,
 LValue LV = MakeNaturalAlignAddrLValue(Constant, IdTy);
 llvm::Value *Ptr = EmitLoadOfScalar(LV, E->getBeginLoc());
 cast(Ptr)->setMetadata(
-CGM.getModule().getMDKindID("invariant.load"),
+llvm::LLVMContext::MD_invariant_load,
 llvm::MDNode::get(getLLVMContext(), std::nullopt));
 return Builder.CreateBitCast(Ptr, ConvertType(E->getType()));
   }

diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 5f4cdc6d91f1d..d52e560234bdf 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -7229,7 +7229,7 @@ 
CGObjCNonFragileABIMac::EmitIvarOffset(CodeGen::CodeGenFunction ,
   CGF.getSizeAlign(), "ivar");
 if (IsIvarOffsetKnownIdempotent(CGF, Ivar))
   cast(IvarOffsetValue)
-  ->setMetadata(CGM.getModule().getMDKindID("invariant.load"),
+  ->setMetadata(llvm::LLVMContext::MD_invariant_load,
 llvm::MDNode::get(VMContext, std::nullopt));
   }
 
@@ -7629,7 +7629,7 @@ llvm::Value 
*CGObjCNonFragileABIMac::EmitSelector(CodeGenFunction ,
   Address Addr = EmitSelectorAddr(Sel);
 
   llvm::LoadInst* LI = CGF.Builder.CreateLoad(Addr);
-  LI->setMetadata(CGM.getModule().getMDKindID("invariant.load"),
+  LI->setMetadata(llvm::LLVMContext::MD_invariant_load,
   llvm::MDNode::get(VMContext, std::nullopt));
   return LI;
 }



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


[PATCH] D151350: [OpenMP] Extend omp teams to permit nested omp tile

2023-06-02 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Ping.


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

https://reviews.llvm.org/D151350

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


[PATCH] D151356: [OpenMP] Fix transformed loop's var privacy

2023-06-02 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

Thanks for the review.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151356

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


[PATCH] D151356: [OpenMP] Fix transformed loop's var privacy

2023-06-02 Thread Joel E. Denny 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 rG19841e4dcaab: [OpenMP] Fix transformed loops var 
privacy (authored by jdenny).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151356

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
  openmp/libomptarget/test/offloading/target-tile.c

Index: openmp/libomptarget/test/offloading/target-tile.c
===
--- /dev/null
+++ openmp/libomptarget/test/offloading/target-tile.c
@@ -0,0 +1,62 @@
+// Check that omp tile (introduced in OpenMP 5.1) is permitted and behaves when
+// strictly nested within omp target.
+
+// RUN: %libomptarget-compile-generic -fopenmp-version=51
+// RUN: %libomptarget-run-generic 2>&1 | %fcheck-generic
+
+#include 
+
+#define I_NTILES 8
+#define J_NTILES 9
+#define I_NELEMS 2
+#define J_NELEMS 3
+
+int main() {
+  int order[I_NTILES][J_NTILES][I_NELEMS][J_NELEMS];
+  int i, j;
+  #pragma omp target map(tofrom: i, j)
+  {
+int next = 0;
+#pragma omp tile sizes(I_NELEMS, J_NELEMS)
+for (i = 0; i < I_NTILES * I_NELEMS; ++i) {
+  for (j = 0; j < J_NTILES * J_NELEMS; ++j) {
+int iTile = i / I_NELEMS;
+int jTile = j / J_NELEMS;
+int iElem = i % I_NELEMS;
+int jElem = j % J_NELEMS;
+order[iTile][jTile][iElem][jElem] = next++;
+  }
+}
+  }
+  int expected = 0;
+  for (int iTile = 0; iTile < I_NTILES; ++iTile) {
+for (int jTile = 0; jTile < J_NTILES; ++jTile) {
+  for (int iElem = 0; iElem < I_NELEMS; ++iElem) {
+for (int jElem = 0; jElem < J_NELEMS; ++jElem) {
+  int actual = order[iTile][jTile][iElem][jElem];
+  if (expected != actual) {
+printf("error: order[%d][%d][%d][%d] = %d, expected %d\n",
+   iTile, jTile, iElem, jElem, actual, expected);
+return 1;
+  }
+  ++expected;
+}
+  }
+}
+  }
+  // Tiling leaves the loop variables with their values from the final iteration
+  // rather than with the usual +1.
+  expected = I_NTILES * I_NELEMS - 1;
+  if (i != expected) {
+printf("error: i = %d, expected %d\n", i, expected);
+return 1;
+  }
+  expected = J_NTILES * J_NELEMS - 1;
+  if (j != expected) {
+printf("error: j = %d, expected %d\n", j, expected);
+return 1;
+  }
+  // CHECK: success
+  printf("success\n");
+  return 0;
+}
Index: clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
===
--- clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
+++ clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
@@ -21,7 +21,7 @@
 // IR-NEXT:store i32 %[[START:.+]], ptr %[[START_ADDR]], align 4
 // IR-NEXT:store i32 %[[END:.+]], ptr %[[END_ADDR]], align 4
 // IR-NEXT:store i32 %[[STEP:.+]], ptr %[[STEP_ADDR]], align 4
-// IR-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @2, i32 3, ptr @func.omp_outlined, ptr %[[END_ADDR]], ptr %[[STEP_ADDR]], ptr %[[START_ADDR]])
+// IR-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @2, i32 3, ptr @func.omp_outlined, ptr %[[START_ADDR]], ptr %[[END_ADDR]], ptr %[[STEP_ADDR]])
 // IR-NEXT:ret void
 // IR-NEXT:  }
 extern "C" void func(int start, int end, int step) {
@@ -36,9 +36,9 @@
 // IR-NEXT:  [[ENTRY:.*]]:
 // IR-NEXT:%[[DOTGLOBAL_TID__ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[DOTBOUND_TID__ADDR:.+]] = alloca ptr, align 8
+// IR-NEXT:%[[START_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[END_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[STEP_ADDR:.+]] = alloca ptr, align 8
-// IR-NEXT:%[[START_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[DOTOMP_IV:.+]] = alloca i32, align 4
 // IR-NEXT:%[[TMP:.+]] = alloca i32, align 4
 // IR-NEXT:%[[I:.+]] = alloca i32, align 4
@@ -57,12 +57,12 @@
 // IR-NEXT:%[[DOTUNROLL_INNER_IV_I:.+]] = alloca i32, align 4
 // IR-NEXT:store ptr %[[DOTGLOBAL_TID_:.+]], ptr %[[DOTGLOBAL_TID__ADDR]], align 8
 // IR-NEXT:store ptr %[[DOTBOUND_TID_:.+]], ptr %[[DOTBOUND_TID__ADDR]], align 8
+// IR-NEXT:store ptr %[[START:.+]], ptr %[[START_ADDR]], align 8
 // IR-NEXT:store ptr %[[END:.+]], ptr %[[END_ADDR]], align 8
 // IR-NEXT:store ptr %[[STEP:.+]], ptr %[[STEP_ADDR]], align 8
-// IR-NEXT:store ptr %[[START:.+]], ptr %[[START_ADDR]], align 8
+// IR-NEXT:%[[TMP2:.+]] = load ptr, ptr %[[START_ADDR]], align 8
 // IR-NEXT:%[[TMP0:.+]] = load ptr, ptr %[[END_ADDR]], align 8
 // IR-NEXT:%[[TMP1:.+]] = load ptr, ptr %[[STEP_ADDR]], align 8
-// IR-NEXT:%[[TMP2:.+]] = load ptr, ptr %[[START_ADDR]], align 8
 // IR-NEXT:%[[TMP3:.+]] = load i32, ptr %[[TMP2]], align 4
 // IR-NEXT:store i32 %[[TMP3]], ptr %[[I]], align 4
 // 

[clang] 19841e4 - [OpenMP] Fix transformed loop's var privacy

2023-06-02 Thread Joel E. Denny via cfe-commits

Author: Joel E. Denny
Date: 2023-06-02T12:18:13-04:00
New Revision: 19841e4dcaabe573d35eb88a130fc34d32ecd708

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

LOG: [OpenMP] Fix transformed loop's var privacy

Without this patch, the following example crashes Clang:

```
 #pragma omp target map(i)
 #pragma omp tile sizes(2)
 for (i = 0; i < N; ++i)
   ;
```

This patch fixes the crash by changing `Sema::isOpenMPPrivateDecl` not
to identify `i` as private just because it's the loop variable of a
`tile` construct.

While OpenMP TR11 and earlier do specify privacy for loop variables of
loops *generated* from a `tile` construct, I haven't found text
stating that the original loop variable must be private in the above
example, so this patch leaves it shared.  Even so, it is a bit
unexpected that value of `i` after the loop is `N - 1` instead of `N`.

Reviewed By: ABataev

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

Added: 
openmp/libomptarget/test/offloading/target-tile.c

Modified: 
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6e83e20d96d59..0b6f5be9f0447 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2551,7 +2551,8 @@ OpenMPClauseKind Sema::isOpenMPPrivateDecl(ValueDecl *D, 
unsigned Level,
   }
 }
   }
-  if (isOpenMPLoopDirective(DSAStack->getCurrentDirective())) {
+  if (isOpenMPLoopDirective(DSAStack->getCurrentDirective()) &&
+  !isOpenMPLoopTransformationDirective(DSAStack->getCurrentDirective())) {
 if (DSAStack->getAssociatedLoops() > 0 && !DSAStack->isLoopStarted()) {
   DSAStack->resetPossibleLoopCounter(D);
   DSAStack->loopStart();

diff  --git a/clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp 
b/clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
index 44127525b2527..a710d889a0b6d 100644
--- a/clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
+++ b/clang/test/OpenMP/unroll_codegen_parallel_for_factor.cpp
@@ -21,7 +21,7 @@ extern "C" void body(...) {}
 // IR-NEXT:store i32 %[[START:.+]], ptr %[[START_ADDR]], align 4
 // IR-NEXT:store i32 %[[END:.+]], ptr %[[END_ADDR]], align 4
 // IR-NEXT:store i32 %[[STEP:.+]], ptr %[[STEP_ADDR]], align 4
-// IR-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @2, i32 3, 
ptr @func.omp_outlined, ptr %[[END_ADDR]], ptr %[[STEP_ADDR]], ptr 
%[[START_ADDR]])
+// IR-NEXT:call void (ptr, i32, ptr, ...) @__kmpc_fork_call(ptr @2, i32 3, 
ptr @func.omp_outlined, ptr %[[START_ADDR]], ptr %[[END_ADDR]], ptr 
%[[STEP_ADDR]])
 // IR-NEXT:ret void
 // IR-NEXT:  }
 extern "C" void func(int start, int end, int step) {
@@ -36,9 +36,9 @@ extern "C" void func(int start, int end, int step) {
 // IR-NEXT:  [[ENTRY:.*]]:
 // IR-NEXT:%[[DOTGLOBAL_TID__ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[DOTBOUND_TID__ADDR:.+]] = alloca ptr, align 8
+// IR-NEXT:%[[START_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[END_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[STEP_ADDR:.+]] = alloca ptr, align 8
-// IR-NEXT:%[[START_ADDR:.+]] = alloca ptr, align 8
 // IR-NEXT:%[[DOTOMP_IV:.+]] = alloca i32, align 4
 // IR-NEXT:%[[TMP:.+]] = alloca i32, align 4
 // IR-NEXT:%[[I:.+]] = alloca i32, align 4
@@ -57,12 +57,12 @@ extern "C" void func(int start, int end, int step) {
 // IR-NEXT:%[[DOTUNROLL_INNER_IV_I:.+]] = alloca i32, align 4
 // IR-NEXT:store ptr %[[DOTGLOBAL_TID_:.+]], ptr %[[DOTGLOBAL_TID__ADDR]], 
align 8
 // IR-NEXT:store ptr %[[DOTBOUND_TID_:.+]], ptr %[[DOTBOUND_TID__ADDR]], 
align 8
+// IR-NEXT:store ptr %[[START:.+]], ptr %[[START_ADDR]], align 8
 // IR-NEXT:store ptr %[[END:.+]], ptr %[[END_ADDR]], align 8
 // IR-NEXT:store ptr %[[STEP:.+]], ptr %[[STEP_ADDR]], align 8
-// IR-NEXT:store ptr %[[START:.+]], ptr %[[START_ADDR]], align 8
+// IR-NEXT:%[[TMP2:.+]] = load ptr, ptr %[[START_ADDR]], align 8
 // IR-NEXT:%[[TMP0:.+]] = load ptr, ptr %[[END_ADDR]], align 8
 // IR-NEXT:%[[TMP1:.+]] = load ptr, ptr %[[STEP_ADDR]], align 8
-// IR-NEXT:%[[TMP2:.+]] = load ptr, ptr %[[START_ADDR]], align 8
 // IR-NEXT:%[[TMP3:.+]] = load i32, ptr %[[TMP2]], align 4
 // IR-NEXT:store i32 %[[TMP3]], ptr %[[I]], align 4
 // IR-NEXT:%[[TMP4:.+]] = load i32, ptr %[[TMP2]], align 4

diff  --git a/openmp/libomptarget/test/offloading/target-tile.c 
b/openmp/libomptarget/test/offloading/target-tile.c
new file mode 100644
index 0..8460b43b6f9c7
--- /dev/null
+++ b/openmp/libomptarget/test/offloading/target-tile.c
@@ -0,0 +1,62 @@
+// Check that omp tile (introduced in OpenMP 5.1) is permitted and behaves when

[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

In D149573#4390895 , @codemzs wrote:

> In D149573#4390863 , @stuij wrote:
>
>> This is going to be a very unhelpful comment. After looking through the 
>> changes, I don't have any comments to make, but I also don't feel 
>> comfortable to accept this revision as I don't feel to know enough about the 
>> front-end.
>
> @stuij, I sincerely appreciate you taking the time to review the changes. 
> Your hesitation due to unfamiliarity with the front-end elements is 
> completely understandable, and I respect your candid feedback.
>
> @erichkeane, given your extensive contributions to the core `Sema`* files, I 
> believe your expertise and experience would be particularly valuable in 
> reviewing the changes I've made. I recall your initial informal approval for 
> the change, and since then, I've further refined it after incorporating the 
> outcomes of D150913 . I'd be most 
> appreciative if you could please review this revision once again.
>
> My intention is to ensure this revision aligns with our shared vision for 
> LLVM/Clang, and your reviews will greatly contribute to this goal. If there 
> are any other changes or improvements required for the successful landing of 
> this revision, please feel free to let me know.

I'll put you on my list to re-review for early next week, though Aaron probably 
needs to do a look through this as well.


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

https://reviews.llvm.org/D149573

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


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:8824
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();

Fznamznon wrote:
> erichkeane wrote:
> > I am not really sure this is the right way about this.  You're supposed to 
> > be testing `T`, but this looks like it is checking the type of `E`, isn't 
> > it?  I think you just need to check `Cast->getType()`.
> For the case I'm trying to fix, `T` is array of unknown bound, it is already 
> checked before calling `completeExprArrayBound`. Right now when you write 
> something like
> ```
> int (&)[1] = static_cast(42);
> ```
> Clang actually is able to realize that parenthesized initialization is made, 
> so it actually generates `CXXParenListInitExpr` that has type int[1]. Here 
> I'm just paranoidally double-checking that is the case before switching the 
> type. Maybe I don't need this double-check at all then?
> 
That makes me wonder if this is the correct place for this?  Should when we 
generate this type when we do the `CXXParenListInitExpr` fixup?

Either way, I think making this depend on that behavior (which would possibly 
be fragile), we should just do it based on the type passed ot the `static_cast`.

Another question: is this something that needs to be done for other cast types? 
 Does similar behavior exist for the other casts?  Should it also happen with 
'clobber' casts (C-style) that are effectively static?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-06-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:8824
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();

erichkeane wrote:
> I am not really sure this is the right way about this.  You're supposed to be 
> testing `T`, but this looks like it is checking the type of `E`, isn't it?  I 
> think you just need to check `Cast->getType()`.
For the case I'm trying to fix, `T` is array of unknown bound, it is already 
checked before calling `completeExprArrayBound`. Right now when you write 
something like
```
int (&)[1] = static_cast(42);
```
Clang actually is able to realize that parenthesized initialization is made, so 
it actually generates `CXXParenListInitExpr` that has type int[1]. Here I'm 
just paranoidally double-checking that is the case before switching the type. 
Maybe I don't need this double-check at all then?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[PATCH] D151952: [clang] adds `__type_pack_index` so we can get a type's parameter pack index

2023-06-02 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added inline comments.



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5562
+  if (IsDependent)
+goto Return;
+

erichkeane wrote:
> Oh, please don't do this.
perhaps another way to do this if you want to avoid repeating the return 
expression would be a small lambda that contains the return expression and uses 
a simple name - so the returns can just be `return ret();` ? (or I guess nest 
the switch in an `if`, or in another function that uses ref parameters to 
populate the result)

Though in this case it's only twice, so I'd probably repeat the expression?



Comment at: clang/lib/Sema/SemaExprCXX.cpp:5591
+  default:
+llvm_unreachable("unhandled type trait (usualy deliberate)");
+  }

erichkeane wrote:
> What do you mean by `usually deliberate` here? This is a message users will 
> see, so telling them an assertion is deliberate seems incorrect? 
I second the question - though I'd push back on the "This is a message users 
will see" - unreachables won't be seen by users, they get lowered to UB in 
release builds - the text isn't in the program anymore. The text is only for 
Clang developers (and/or clang-as-library users).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151952

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


[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:8824
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();

I am not really sure this is the right way about this.  You're supposed to be 
testing `T`, but this looks like it is checking the type of `E`, isn't it?  I 
think you just need to check `Cast->getType()`.



Comment at: clang/lib/Sema/SemaType.cpp:8826
+  const Type *InnerType = SubInit->getType().getTypePtr();
+  if (const auto *AT = dyn_cast(InnerType);
+  AT && AT->getSize() == 1) {

Not supposed to have curleys here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152003

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


[clang-tools-extra] 5c2072e - [clang-tidy] Fix docs.

2023-06-02 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-06-02T15:31:55Z
New Revision: 5c2072e74b42d55e8bf7a9c8fee8800bad591f12

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

LOG: [clang-tidy] Fix docs.

Added: 


Modified: 
clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst

Removed: 




diff  --git a/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst 
b/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
index 30865680ac023..3246fea78cd42 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
@@ -10,6 +10,7 @@ Findings correspond to 
https://clangd.llvm.org/design/include-cleaner.
 Example:
 
 .. code-block:: c++
+   
// foo.h
class Foo{};
// bar.h



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


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

2023-06-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc28506ba4b69: [clang-tidy] Implement an include-cleaner 
check. (authored by VitaNuo).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D148793

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

Index: clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp
@@ -0,0 +1,236 @@
+//===--- IncludeCleanerTest.cpp - clang-tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "ClangTidyDiagnosticConsumer.h"
+#include "ClangTidyOptions.h"
+#include "ClangTidyTest.h"
+#include "misc/IncludeCleanerCheck.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Regex.h"
+#include "gtest/gtest.h"
+#include 
+
+#include 
+#include 
+
+using namespace clang::tidy::misc;
+
+namespace clang {
+namespace tidy {
+namespace test {
+namespace {
+
+std::string
+appendPathFileSystemIndependent(std::initializer_list Segments) {
+  llvm::SmallString<32> Result;
+  for (const auto  : Segments)
+llvm::sys::path::append(Result, llvm::sys::path::Style::native, Segment);
+  return std::string(Result.str());
+}
+
+TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include 
+#include "bar.h"
+)";
+  const char *PostCode = "\n";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode, runCheckOnCode(
+  PreCode, , "file.cpp", std::nullopt,
+  ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include "baz/qux/qux.h"
+#include 
+)";
+
+  const char *PostCode = R"(
+#include "bar.h"
+#include "foo/qux.h"
+#include 
+)";
+
+  std::vector Errors;
+  ClangTidyOptions Opts;
+  Opts.CheckOptions["IgnoreHeaders"] = llvm::StringRef{llvm::formatv(
+  "bar.h;{0};{1};vector",
+  llvm::Regex::escape(appendPathFileSystemIndependent({"foo", "qux.h"})),
+  llvm::Regex::escape(appendPathFileSystemIndependent({"baz", "qux"})))};
+  EXPECT_EQ(
+  PostCode,
+  runCheckOnCode(
+  PreCode, , "file.cpp", std::nullopt, Opts,
+  {{"bar.h", ""},
+   {"vector", ""},
+   {appendPathFileSystemIndependent({"foo", "qux.h"}), ""},
+   {appendPathFileSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
+}
+
+TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+  const char *PostCode = R"(
+#include "bar.h"
+#include "baz.h"
+
+int BarResult = bar();
+int BazResult = baz();
+)";
+
+  std::vector Errors;
+  EXPECT_EQ(PostCode,
+runCheckOnCode(
+PreCode, , "file.cpp", std::nullopt, ClangTidyOptions(),
+{{"bar.h", R"(#pragma once
+  #include "baz.h"
+  int bar();
+   )"},
+ {"baz.h", R"(#pragma once
+  int baz();
+   )"}}));
+}
+
+TEST(IncludeCleanerCheckTest, SuppressMissingIncludes) {
+  const char *PreCode = R"(
+#include "bar.h"
+
+int BarResult = bar();
+int BazResult = baz();
+int QuxResult = qux();
+)";

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo added a comment.

Thanks for the comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

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


[clang-tools-extra] c28506b - [clang-tidy] Implement an include-cleaner check.

2023-06-02 Thread Viktoriia Bakalova via cfe-commits

Author: Viktoriia Bakalova
Date: 2023-06-02T15:21:20Z
New Revision: c28506ba4b6961950849f8fdecd0cf7e503a14f9

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

LOG: [clang-tidy] Implement an include-cleaner check.

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

Added: 
clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.h
clang-tools-extra/docs/clang-tidy/checks/misc/include-cleaner.rst
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/bar.h
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/baz.h
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/foo.h
clang-tools-extra/test/clang-tidy/checkers/misc/Inputs/private.h
clang-tools-extra/test/clang-tidy/checkers/misc/include-cleaner.cpp
clang-tools-extra/test/clang-tidy/checkers/misc/system/string.h
clang-tools-extra/test/clang-tidy/checkers/misc/system/vector.h
clang-tools-extra/unittests/clang-tidy/IncludeCleanerTest.cpp

Modified: 
clang-tools-extra/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/clangd/TidyProvider.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst
clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h
clang-tools-extra/include-cleaner/lib/Record.cpp
clang-tools-extra/unittests/clang-tidy/CMakeLists.txt

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
index a72362906e0b8..1703ff82b942d 100644
--- a/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/misc/CMakeLists.txt
@@ -7,6 +7,7 @@ setup_host_tool(clang-tidy-confusable-chars-gen 
CLANG_TIDY_CONFUSABLE_CHARS_GEN
 
 add_subdirectory(ConfusableTable)
 
+include_directories(BEFORE 
"${CMAKE_CURRENT_SOURCE_DIR}/../../include-cleaner/include")
 
 add_custom_command(
 OUTPUT Confusables.inc
@@ -19,6 +20,7 @@ add_clang_library(clangTidyMiscModule
   ConstCorrectnessCheck.cpp
   DefinitionsInHeadersCheck.cpp
   ConfusableIdentifierCheck.cpp
+  IncludeCleanerCheck.cpp
   MiscTidyModule.cpp
   MisleadingBidirectional.cpp
   MisleadingIdentifier.cpp
@@ -53,6 +55,7 @@ clang_target_link_libraries(clangTidyMiscModule
   clangAST
   clangASTMatchers
   clangBasic
+  clangIncludeCleaner
   clangLex
   clangSerialization
   clangTooling

diff  --git a/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
new file mode 100644
index 0..c7aca83f2ca8c
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp
@@ -0,0 +1,202 @@
+//===--- IncludeCleanerCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "IncludeCleanerCheck.h"
+#include "../ClangTidyCheck.h"
+#include "../ClangTidyDiagnosticConsumer.h"
+#include "../ClangTidyOptions.h"
+#include "../utils/OptionsUtils.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Record.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/FileEntry.h"
+#include "clang/Basic/LLVM.h"
+#include "clang/Basic/LangOptions.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Format/Format.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Tooling/Core/Replacement.h"
+#include "clang/Tooling/Inclusions/HeaderIncludes.h"
+#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Regex.h"
+#include 
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::misc {
+
+namespace {
+struct MissingIncludeInfo {
+  SourceLocation SymRefLocation;
+  include_cleaner::Header Missing;
+};
+} // namespace
+
+IncludeCleanerCheck::IncludeCleanerCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  IgnoreHeaders(utils::options::parseStringList(
+  Options.getLocalOrGlobal("IgnoreHeaders", ""))) {
+  for (const auto  : IgnoreHeaders) {
+if 

[PATCH] D152003: [clang] Fix `static_cast` to array of unknown bound

2023-06-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon created this revision.
Herald added a project: All.
Fznamznon requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Per P1975R0 an expression like `static_cast(...)` defines the type
of the expression as U[1].

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152003

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaType.cpp
  clang/test/SemaCXX/paren-list-agg-init.cpp


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -272,3 +272,14 @@
 // expected-warning@-1 {{braces around scalar init}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a 
parenthesized list of values is a C++20 extension}}
 }
+
+namespace gh62863 {
+int (&)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[2] = static_cast(42); // expected-error {{reference to 
type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a 
parenthesized list of values is a C++20 extension}}
+int (&)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a 
parenthesized list of values is a C++20 extension}}
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8818,6 +8818,17 @@
   }
 }
   }
+  // C++20 [expr.static.cast]p.4: ... If T is “array of unknown bound of U”,
+  // this direct-initialization defines the type of the expression as U[1]
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();
+  if (const auto *AT = dyn_cast(InnerType);
+  AT && AT->getSize() == 1) {
+Cast->setType(SubInit->getType());
+  }
+}
+  }
 }
 
 QualType Sema::getCompletedType(Expr *E) {
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -463,6 +463,8 @@
 - Fix crash when passing a braced initializer list to a parentehsized aggregate
   initialization expression.
   (`#63008 `_).
+- Fixed `static_cast` to array of unknown bound.
+  (`#62863 `_).
 
 Bug Fixes to Compiler Builtins
 ^^


Index: clang/test/SemaCXX/paren-list-agg-init.cpp
===
--- clang/test/SemaCXX/paren-list-agg-init.cpp
+++ clang/test/SemaCXX/paren-list-agg-init.cpp
@@ -272,3 +272,14 @@
 // expected-warning@-1 {{braces around scalar init}}
 // beforecxx20-warning@-2 {{aggregate initialization of type 'A' from a parenthesized list of values is a C++20 extension}}
 }
+
+namespace gh62863 {
+int (&)[] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[1] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[2] = static_cast(42); // expected-error {{reference to type 'int[2]' could not bind to an rvalue of type 'int[1]'}}
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[1]' from a parenthesized list of values is a C++20 extension}}
+int (&)[3] = static_cast(42);
+// beforecxx20-warning@-1 {{aggregate initialization of type 'int[3]' from a parenthesized list of values is a C++20 extension}}
+}
Index: clang/lib/Sema/SemaType.cpp
===
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -8818,6 +8818,17 @@
   }
 }
   }
+  // C++20 [expr.static.cast]p.4: ... If T is “array of unknown bound of U”,
+  // this direct-initialization defines the type of the expression as U[1]
+  if (auto *Cast = dyn_cast(E)) {
+if (auto *SubInit = dyn_cast(Cast->getSubExpr())) {
+  const Type *InnerType = SubInit->getType().getTypePtr();
+  if (const auto *AT = dyn_cast(InnerType);
+  AT && AT->getSize() == 1) {
+Cast->setType(SubInit->getType());
+  }
+}
+  }
 }
 
 QualType Sema::getCompletedType(Expr *E) {
Index: clang/docs/ReleaseNotes.rst
===
--- 

[PATCH] D150185: [include-cleaner] Allow multiple strategies for spelling includes.

2023-06-02 Thread Viktoriia Bakalova via Phabricator via cfe-commits
VitaNuo updated this revision to Diff 527872.
VitaNuo marked 6 inline comments as done.
VitaNuo added a comment.

Address review comments.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D150185

Files:
  clang-tools-extra/clangd/Hover.cpp
  clang-tools-extra/clangd/IncludeCleaner.cpp
  clang-tools-extra/clangd/IncludeCleaner.h
  clang-tools-extra/include-cleaner/include/clang-include-cleaner/Analysis.h
  
clang-tools-extra/include-cleaner/include/clang-include-cleaner/IncludeSpeller.h
  clang-tools-extra/include-cleaner/lib/Analysis.cpp
  clang-tools-extra/include-cleaner/lib/CMakeLists.txt
  clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
  clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
  clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp

Index: clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/unittests/IncludeSpellerTest.cpp
@@ -0,0 +1,78 @@
+//===--- IncludeSpellerTest.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
+//
+//===--===//
+
+#include "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Analysis.h"
+#include "clang-include-cleaner/Types.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Testing/TestAST.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Path.h"
+#include "gtest/gtest.h"
+#include 
+#include 
+namespace clang::include_cleaner {
+namespace {
+
+const char *testRoot() {
+#ifdef _WIN32
+  return "C:\\include-cleaner-test";
+#else
+  return "/include-cleaner-test";
+#endif
+}
+
+std::string testPath(llvm::StringRef File) {
+  assert(llvm::sys::path::is_relative(File) && "FileName should be relative");
+
+  llvm::SmallString<32> NativeFile = File;
+  llvm::sys::path::native(NativeFile, llvm::sys::path::Style::native);
+  llvm::SmallString<32> Path;
+  llvm::sys::path::append(Path, llvm::sys::path::Style::native, testRoot(),
+  NativeFile);
+  return std::string(Path.str());
+}
+
+class DummyIncludeSpeller : public IncludeSpeller {
+public:
+  std::string operator()(const IncludeSpeller::Input ) const override {
+llvm::StringRef AbsolutePath = Input.H.physical()->tryGetRealPathName();
+std::string RootWithSeparator{testRoot()};
+RootWithSeparator += llvm::sys::path::get_separator();
+if (!AbsolutePath.consume_front(llvm::StringRef{RootWithSeparator}))
+  return "";
+return "\"" + AbsolutePath.str() + "\"";
+  }
+};
+
+TEST(IncludeSpeller, IsRelativeToTestRoot) {
+  TestInputs Inputs;
+
+  Inputs.ExtraArgs.push_back("-isystemdir");
+
+  Inputs.ExtraFiles[testPath("foo.h")] = "";
+  Inputs.ExtraFiles["dir/header.h"] = "";
+  TestAST AST{Inputs};
+
+  auto  = AST.fileManager();
+  auto  = AST.preprocessor().getHeaderSearchInfo();
+  const auto *MainFile = AST.sourceManager().getFileEntryForID(
+  AST.sourceManager().getMainFileID());
+
+  EXPECT_EQ("\"foo.h\"", spellHeader({Header{*FM.getFile(testPath("foo.h"))},
+  HS, MainFile}));
+  EXPECT_EQ("",
+spellHeader({Header{*FM.getFile("dir/header.h")}, HS, MainFile}));
+}
+
+IncludeSpellingStrategy::Add
+Speller("dummy", "Dummy Include Speller");
+
+} // namespace
+} // namespace clang::include_cleaner
Index: clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
===
--- clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
+++ clang-tools-extra/include-cleaner/unittests/CMakeLists.txt
@@ -7,6 +7,7 @@
 add_unittest(ClangIncludeCleanerUnitTests ClangIncludeCleanerTests
   AnalysisTest.cpp
   FindHeadersTest.cpp
+  IncludeSpellerTest.cpp
   LocateSymbolTest.cpp
   RecordTest.cpp
   TypesTest.cpp
Index: clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
===
--- /dev/null
+++ clang-tools-extra/include-cleaner/lib/IncludeSpeller.cpp
@@ -0,0 +1,68 @@
+//===--- IncludeSpeller.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
+//
+//===--===//
+
+#include "clang-include-cleaner/IncludeSpeller.h"
+#include "clang-include-cleaner/Types.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/ErrorHandling.h"
+#include 

[PATCH] D152002: [clang][wip] Better handling of dependent lambda. This is an attempt to fix GH62916. However, it breaks GH57960 I seem unable to find something that works for both issues.

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

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152002

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/lib/Sema/TreeTransform.h
  clang/test/SemaCXX/lambda-expressions.cpp


Index: clang/test/SemaCXX/lambda-expressions.cpp
===
--- clang/test/SemaCXX/lambda-expressions.cpp
+++ clang/test/SemaCXX/lambda-expressions.cpp
@@ -715,3 +715,23 @@
   // CHECK-NEXT: ConstantExpr
   // CHECK-NEXT: value: Int 2
 }
+
+#if __cplusplus > 201402L
+namespace GH62916 {
+
+template  int { return T(42); }()>
+struct P {
+static constexpr int value = U;
+};
+
+template 
+constexpr P foo() {
+return {};
+}
+
+void test() {
+  static_assert(foo().value == 42);
+}
+
+}
+#endif
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -761,6 +761,8 @@
   /// the body.
   StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
 
+  bool LambdaExpressionShouldBeConsideredDependent(LambdaExpr *E) const;
+
   QualType TransformReferenceType(TypeLocBuilder , ReferenceTypeLoc TL);
 
   StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
@@ -13294,18 +13296,9 @@
 
   // Create the local class that will describe the lambda.
 
-  // FIXME: DependencyKind below is wrong when substituting inside a templated
-  // context that isn't a DeclContext (such as a variable template), or when
-  // substituting an unevaluated lambda inside of a function's parameter's type
-  // - as parameter types are not instantiated from within a function's DC. We
-  // use evaluation contexts to distinguish the function parameter case.
   CXXRecordDecl::LambdaDependencyKind DependencyKind =
-  CXXRecordDecl::LDK_Unknown;
-  if ((getSema().isUnevaluatedContext() ||
-   getSema().isConstantEvaluatedContext()) &&
-  (getSema().CurContext->isFileContext() ||
-   !getSema().CurContext->getParent()->isDependentContext()))
-DependencyKind = CXXRecordDecl::LDK_NeverDependent;
+  getDerived().LambdaExpressionShouldBeConsideredDependent(E) ?
+  CXXRecordDecl::LDK_AlwaysDependent : CXXRecordDecl::LDK_NeverDependent;
 
   CXXRecordDecl *OldClass = E->getLambdaClass();
   CXXRecordDecl *Class = getSema().createLambdaClosureType(
@@ -13578,6 +13571,12 @@
   return S;
 }
 
+template
+bool 
TreeTransform::LambdaExpressionShouldBeConsideredDependent(LambdaExpr 
*) const {
+  return false;
+}
+
+
 template
 ExprResult
 TreeTransform::TransformCXXUnresolvedConstructExpr(
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1435,6 +1435,20 @@
   return Result;
 }
 
+bool LambdaExpressionShouldBeConsideredDependent(LambdaExpr * E) const {
+  if(E->getLambdaClass()->isNeverDependentLambda())
+return false;
+
+  if(SemaRef.CurContext->isDependentContext())
+return true;
+
+  return llvm::any_of(TemplateArgs.getInnermost(), [](const 
TemplateArgument & C) {
+return C.isDependent();
+  });
+
+}
+
+
 ExprResult TransformRequiresExpr(RequiresExpr *E) {
   LocalInstantiationScope Scope(SemaRef, /*CombineWithOuterScope=*/true);
   ExprResult TransReq = inherited::TransformRequiresExpr(E);


Index: clang/test/SemaCXX/lambda-expressions.cpp
===
--- clang/test/SemaCXX/lambda-expressions.cpp
+++ clang/test/SemaCXX/lambda-expressions.cpp
@@ -715,3 +715,23 @@
   // CHECK-NEXT: ConstantExpr
   // CHECK-NEXT: value: Int 2
 }
+
+#if __cplusplus > 201402L
+namespace GH62916 {
+
+template  int { return T(42); }()>
+struct P {
+static constexpr int value = U;
+};
+
+template 
+constexpr P foo() {
+return {};
+}
+
+void test() {
+  static_assert(foo().value == 42);
+}
+
+}
+#endif
Index: clang/lib/Sema/TreeTransform.h
===
--- clang/lib/Sema/TreeTransform.h
+++ clang/lib/Sema/TreeTransform.h
@@ -761,6 +761,8 @@
   /// the body.
   StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body);
 
+  bool LambdaExpressionShouldBeConsideredDependent(LambdaExpr *E) const;
+
   QualType TransformReferenceType(TypeLocBuilder , ReferenceTypeLoc TL);
 
   StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
@@ -13294,18 +13296,9 @@
 
   // Create the local class that will describe the lambda.
 
-  // FIXME: DependencyKind below is wrong when substituting inside a templated
-  // context that isn't a DeclContext (such as a variable template), or when
-  // substituting an unevaluated lambda inside of a function's 

[PATCH] D151837: [Clang][Parser] Accept GNU attributes preceding C++ style attributes on templates

2023-06-02 Thread Elizabeth Andrews via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcecd8471e499: [Clang][Parser] Accept GNU attributes 
preceding C++ attributes on templates (authored by eandrews).
Herald added a project: clang.

Changed prior to commit:
  https://reviews.llvm.org/D151837?vs=527406=527867#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151837

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Parse/ParseTemplate.cpp
  clang/test/Parser/attr-order.cpp


Index: clang/test/Parser/attr-order.cpp
===
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // 
expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // 
expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // 
expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void i(); // ok
+
+template 
+[[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void j(); // ok
+
+template 
+[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok
Index: clang/lib/Parse/ParseTemplate.cpp
===
--- clang/lib/Parse/ParseTemplate.cpp
+++ clang/lib/Parse/ParseTemplate.cpp
@@ -210,7 +210,15 @@
   }
 
   ParsedAttributes prefixAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(prefixAttrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  // GNU attributes are applied to the declaration specification while the
+  // standard attributes are applied to the declaration.  We parse the two
+  // attribute sets into different containters so we can apply them during
+  // the regular parsing process.
+  while (MaybeParseCXX11Attributes(prefixAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.is(tok::kw_using)) {
 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, 
TemplateInfo, DeclEnd,
@@ -223,6 +231,9 @@
   // Parse the declaration specifiers, stealing any diagnostics from
   // the template parameters.
   ParsingDeclSpec DS(*this, );
+  DS.SetRangeStart(DeclSpecAttrs.Range.getBegin());
+  DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd());
+  DS.takeAttributesFrom(DeclSpecAttrs);
 
   ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
  getDeclSpecContextFromDeclaratorContext(Context));
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -473,6 +473,10 @@
   structs, unions, and scoped enums) were not properly ignored, resulting in
   misleading warning messages. Now, such attribute annotations are correctly
   ignored. (`#61660 `_)
+- GNU attributes preceding C++ style attributes on templates were not properly
+  handled, resulting in compilation error. This has been corrected to match the
+  behavior exhibited by GCC, which permits mixed ordering of GNU and C++
+  attributes.
 
 Bug Fixes to C++ Support
 


Index: clang/test/Parser/attr-order.cpp
===
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] 

[clang] cecd847 - [Clang][Parser] Accept GNU attributes preceding C++ attributes on templates

2023-06-02 Thread Elizabeth Andrews via cfe-commits

Author: Elizabeth Andrews
Date: 2023-06-02T08:11:18-07:00
New Revision: cecd8471e4991b4bea5d2b38a3758cafdb1cbe29

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

LOG: [Clang][Parser] Accept GNU attributes preceding C++ attributes on templates

Clang was rejecting valid code where GNU style attributes preceded C++ style
attributes in template declarations as follows:

template
__attribute__((deprecated("oh no!"))) [[deprecated("oh no!")]] void foo();

This PR fixes the bug.

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Parse/ParseTemplate.cpp
clang/test/Parser/attr-order.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 02736f2ee67fc..69ab645d49c23 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -473,6 +473,10 @@ Bug Fixes to Attribute Support
   structs, unions, and scoped enums) were not properly ignored, resulting in
   misleading warning messages. Now, such attribute annotations are correctly
   ignored. (`#61660 `_)
+- GNU attributes preceding C++ style attributes on templates were not properly
+  handled, resulting in compilation error. This has been corrected to match the
+  behavior exhibited by GCC, which permits mixed ordering of GNU and C++
+  attributes.
 
 Bug Fixes to C++ Support
 

diff  --git a/clang/lib/Parse/ParseTemplate.cpp 
b/clang/lib/Parse/ParseTemplate.cpp
index 79f4ab683281e..d2e8a81ad521a 100644
--- a/clang/lib/Parse/ParseTemplate.cpp
+++ b/clang/lib/Parse/ParseTemplate.cpp
@@ -210,7 +210,15 @@ Decl *Parser::ParseSingleDeclarationAfterTemplate(
   }
 
   ParsedAttributes prefixAttrs(AttrFactory);
-  MaybeParseCXX11Attributes(prefixAttrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+
+  // GNU attributes are applied to the declaration specification while the
+  // standard attributes are applied to the declaration.  We parse the two
+  // attribute sets into 
diff erent containters so we can apply them during
+  // the regular parsing process.
+  while (MaybeParseCXX11Attributes(prefixAttrs) ||
+ MaybeParseGNUAttributes(DeclSpecAttrs))
+;
 
   if (Tok.is(tok::kw_using)) {
 auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, 
TemplateInfo, DeclEnd,
@@ -223,6 +231,9 @@ Decl *Parser::ParseSingleDeclarationAfterTemplate(
   // Parse the declaration specifiers, stealing any diagnostics from
   // the template parameters.
   ParsingDeclSpec DS(*this, );
+  DS.SetRangeStart(DeclSpecAttrs.Range.getBegin());
+  DS.SetRangeEnd(DeclSpecAttrs.Range.getEnd());
+  DS.takeAttributesFrom(DeclSpecAttrs);
 
   ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
  getDeclSpecContextFromDeclaratorContext(Context));

diff  --git a/clang/test/Parser/attr-order.cpp 
b/clang/test/Parser/attr-order.cpp
index 9a8490d819ee3..10bad38cac644 100644
--- a/clang/test/Parser/attr-order.cpp
+++ b/clang/test/Parser/attr-order.cpp
@@ -13,12 +13,21 @@ struct [[]] __attribute__((lockable)) [[]] 
__declspec(dllexport) H {}; // ok
 [[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void b(); // ok
 [[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void c(); // ok
 
-// [[]] attributes before a declaration must be at the start of the line.
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // 
expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // 
expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // 
expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
+
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // ok
 
 [[noreturn]] __attribute__((cdecl))
 [[]]
 __declspec(dllexport) void h();
+
+template 
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void i(); // ok
+
+template 
+[[]] [[noreturn]] __attribute__((cdecl)) __declspec(dllexport) void j(); // ok
+
+template 
+[[noreturn]] __declspec(dllexport) __attribute__((cdecl)) void k(); // ok



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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro added inline comments.



Comment at: clang/test/Frontend/absolute-paths.c:6
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 

tbaeder wrote:
> charmitro wrote:
> > tbaeder wrote:
> > > This checks the same thing in both cases, but in the `NORMAL` case, it 
> > > should //not// use the absolute path, shouldn't it?
> > You're correct. I was constantly testing it from the same path.
> > 
> > Since the relative path is going to be different depending on where you 
> > running from, would it be wise to accept a regular expression of any string 
> > in the `NORMAL` case?
> > 
> > For example, 
> > ```
> > NORMAL: In file included from {{.*}}:
> > ```
> I wonder if it would make sense to just check for the filename in the 
> `NORMAL` case and then do a `NORMAL-NOT: [[ROOT_ABSOLUTE]]`?
Yes, that way we are testing if the warning contains the correct filename+LOC.

Something like: `// NORMAL: In file included from {{.*absolute-paths.c:4}}:`.

But why changefrom `ABSOLUTE:` to `NORMAL-NOT`?


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

https://reviews.llvm.org/D151833

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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread M. Zeeshan Siddiqui via Phabricator via cfe-commits
codemzs added a comment.

In D149573#4390863 , @stuij wrote:

> This is going to be a very unhelpful comment. After looking through the 
> changes, I don't have any comments to make, but I also don't feel comfortable 
> to accept this revision as I don't feel to know enough about the front-end.

@stuij, I sincerely appreciate you taking the time to review the changes. Your 
hesitation due to unfamiliarity with the front-end elements is completely 
understandable, and I respect your candid feedback.

@erichkeane, given your extensive contributions to the core `Sema`* files, I 
believe your expertise and experience would be particularly valuable in 
reviewing the changes I've made. I recall your initial informal approval for 
the change, and since then, I've further refined it after incorporating the 
outcomes of D150913 . I'd be most 
appreciative if you could please review this revision once again.

My intention is to ensure this revision aligns with our shared vision for 
LLVM/Clang, and your reviews will greatly contribute to this goal. If there are 
any other changes or improvements required for the successful landing of this 
revision, please feel free to let me know.


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

https://reviews.llvm.org/D149573

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


[PATCH] D151632: [clang-format] Parse the Verilog language option in configuration

2023-06-02 Thread sstwcw via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG24231df9b8ef: [clang-format] Parse the Verilog language 
option in configuration (authored by sstwcw).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151632

Files:
  clang/lib/Format/Format.cpp
  clang/unittests/Format/ConfigParseTest.cpp


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -1022,6 +1022,23 @@
 ParseError::Error);
 
   EXPECT_EQ(FormatStyle::LK_Cpp, Style.Language);
+
+  Style.Language = FormatStyle::LK_Verilog;
+  CHECK_PARSE("---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 12\n"
+  "---\n"
+  "Language: Cpp\n"
+  "IndentWidth: 34\n"
+  "...\n",
+  IndentWidth, 12u);
+  CHECK_PARSE("---\n"
+  "IndentWidth: 78\n"
+  "---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 56\n"
+  "...\n",
+  IndentWidth, 56u);
 }
 
 TEST(ConfigParseTest, UsesLanguageForBasedOnStyle) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -375,6 +375,7 @@
 IO.enumCase(Value, "TextProto", FormatStyle::LK_TextProto);
 IO.enumCase(Value, "CSharp", FormatStyle::LK_CSharp);
 IO.enumCase(Value, "Json", FormatStyle::LK_Json);
+IO.enumCase(Value, "Verilog", FormatStyle::LK_Verilog);
   }
 };
 


Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -1022,6 +1022,23 @@
 ParseError::Error);
 
   EXPECT_EQ(FormatStyle::LK_Cpp, Style.Language);
+
+  Style.Language = FormatStyle::LK_Verilog;
+  CHECK_PARSE("---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 12\n"
+  "---\n"
+  "Language: Cpp\n"
+  "IndentWidth: 34\n"
+  "...\n",
+  IndentWidth, 12u);
+  CHECK_PARSE("---\n"
+  "IndentWidth: 78\n"
+  "---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 56\n"
+  "...\n",
+  IndentWidth, 56u);
 }
 
 TEST(ConfigParseTest, UsesLanguageForBasedOnStyle) {
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -375,6 +375,7 @@
 IO.enumCase(Value, "TextProto", FormatStyle::LK_TextProto);
 IO.enumCase(Value, "CSharp", FormatStyle::LK_CSharp);
 IO.enumCase(Value, "Json", FormatStyle::LK_Json);
+IO.enumCase(Value, "Verilog", FormatStyle::LK_Verilog);
   }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 24231df - [clang-format] Parse the Verilog language option in configuration

2023-06-02 Thread via cfe-commits

Author: sstwcw
Date: 2023-06-02T14:59:27Z
New Revision: 24231df9b8ef560cc6d3c713d5dba1de703e2cb9

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

LOG: [clang-format] Parse the Verilog language option in configuration

Reviewed By: HazardyKnusperkeks, MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/Format.cpp
clang/unittests/Format/ConfigParseTest.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index d7128ed558dc5..6e2b6a662e7e1 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -375,6 +375,7 @@ template <> struct 
ScalarEnumerationTraits {
 IO.enumCase(Value, "TextProto", FormatStyle::LK_TextProto);
 IO.enumCase(Value, "CSharp", FormatStyle::LK_CSharp);
 IO.enumCase(Value, "Json", FormatStyle::LK_Json);
+IO.enumCase(Value, "Verilog", FormatStyle::LK_Verilog);
   }
 };
 

diff  --git a/clang/unittests/Format/ConfigParseTest.cpp 
b/clang/unittests/Format/ConfigParseTest.cpp
index 0e47abed12472..169c93d1143eb 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -1022,6 +1022,23 @@ TEST(ConfigParseTest, ParsesConfigurationWithLanguages) {
 ParseError::Error);
 
   EXPECT_EQ(FormatStyle::LK_Cpp, Style.Language);
+
+  Style.Language = FormatStyle::LK_Verilog;
+  CHECK_PARSE("---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 12\n"
+  "---\n"
+  "Language: Cpp\n"
+  "IndentWidth: 34\n"
+  "...\n",
+  IndentWidth, 12u);
+  CHECK_PARSE("---\n"
+  "IndentWidth: 78\n"
+  "---\n"
+  "Language: Verilog\n"
+  "IndentWidth: 56\n"
+  "...\n",
+  IndentWidth, 56u);
 }
 
 TEST(ConfigParseTest, UsesLanguageForBasedOnStyle) {



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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

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



Comment at: clang/test/Frontend/absolute-paths.c:6
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 

charmitro wrote:
> tbaeder wrote:
> > This checks the same thing in both cases, but in the `NORMAL` case, it 
> > should //not// use the absolute path, shouldn't it?
> You're correct. I was constantly testing it from the same path.
> 
> Since the relative path is going to be different depending on where you 
> running from, would it be wise to accept a regular expression of any string 
> in the `NORMAL` case?
> 
> For example, 
> ```
> NORMAL: In file included from {{.*}}:
> ```
I wonder if it would make sense to just check for the filename in the `NORMAL` 
case and then do a `NORMAL-NOT: [[ROOT_ABSOLUTE]]`?


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

https://reviews.llvm.org/D151833

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


[PATCH] D149573: [Clang][C++23] Implement core language changes from P1467R9 extended floating-point types and standard names

2023-06-02 Thread Ties Stuij via Phabricator via cfe-commits
stuij added a comment.

This is going to be a very unhelpful comment. After looking through the 
changes, I don't have any comments to make, but I also don't feel comfortable 
to accept this revision as I don't feel to know enough about the front-end.


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

https://reviews.llvm.org/D149573

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


[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-06-02 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added a comment.

Nothing more from me, but I would wait for someone else's approval.




Comment at: clang/lib/Sema/SemaExpr.cpp:18204
+const NamedDecl *ND = cast(DR->getDecl());
+if (const auto *MD = llvm::dyn_cast(ND);
 MD && (MD->isLambdaStaticInvoker() || isLambdaCallOperator(MD)))

Fznamznon wrote:
> 
This one seems to be missed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

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


[PATCH] D147219: [OpenMP][Flang][MLIR] Lowering of requires directive from MLIR to LLVM IR

2023-06-02 Thread Sergio Afonso via Phabricator via cfe-commits
skatrak updated this revision to Diff 527854.
skatrak added a comment.
Herald added subscribers: cfe-commits, hiraditya.
Herald added a project: clang.

Update and remove OpenMP dialect dependency from the generic LLVM IR 
translation.

Followed @kiranchandramohan's suggestion in the comments for D147172 
, since the
current approach prevents the use of OpenMP dialect-specific attributes for
initializing the `OpenMPIRBuilder` configuration. One of these is defined for
representing 'requires' clauses, which need to be stored in the
`OpenMPIRBuilderConfig`, so a different approach is necessary. The approach
implemented in this review is based on the `amendOperation` translation flow.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147219

Files:
  clang/lib/CodeGen/CGOpenMPRuntime.cpp
  llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
  llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
  mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
  mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
  mlir/test/Target/LLVMIR/openmp-llvm.mlir

Index: mlir/test/Target/LLVMIR/openmp-llvm.mlir
===
--- mlir/test/Target/LLVMIR/openmp-llvm.mlir
+++ mlir/test/Target/LLVMIR/openmp-llvm.mlir
@@ -2543,3 +2543,13 @@
 // CHECK: @__omp_rtl_assume_no_thread_state = weak_odr hidden constant i32 1
 // CHECK: @__omp_rtl_assume_no_nested_parallelism = weak_odr hidden constant i32 0
 module attributes {omp.flags = #omp.flags} {}
+
+// -
+
+// Check that OpenMP requires flags are registered by a global constructor.
+// CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }]
+// CHECK-SAME: [{ i32, ptr, ptr } { i32 0, ptr @[[REG_FN:.*]], ptr null }]
+// CHECK: define {{.*}} @[[REG_FN]]({{.*}})
+// CHECK-NOT: }
+// CHECK:   call void @__tgt_register_requires(i64 10)
+module attributes {omp.requires = #omp} {}
Index: mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
===
--- mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -20,8 +20,6 @@
 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
 #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h"
 #include "mlir/Dialect/LLVMIR/Transforms/LegalizeForExport.h"
-#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
-#include "mlir/Dialect/OpenMP/OpenMPInterfaces.h"
 #include "mlir/IR/Attributes.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/IR/BuiltinTypes.h"
@@ -1273,30 +1271,18 @@
 llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() {
   if (!ompBuilder) {
 ompBuilder = std::make_unique(*llvmModule);
+ompBuilder->initialize();
 
-bool isDevice = false;
-llvm::StringRef hostIRFilePath = "";
-
-if (Attribute deviceAttr = mlirModule->getAttr("omp.is_device"))
-  if (::llvm::isa(deviceAttr))
-isDevice = ::llvm::dyn_cast(deviceAttr).getValue();
-
-if (Attribute filepath = mlirModule->getAttr("omp.host_ir_filepath"))
-  if (::llvm::isa(filepath))
-hostIRFilePath =
-::llvm::dyn_cast(filepath).getValue();
-
-ompBuilder->initialize(hostIRFilePath);
-
-// TODO: set the flags when available
-llvm::OpenMPIRBuilderConfig config(
-isDevice, /* IsTargetCodegen */ false,
+// Flags represented as top-level OpenMP dialect attributes are set in
+// OpenMPDialectLLVMIRTranslationInterface::amendOperation(). Here we set
+// the default configuration.
+ompBuilder->setConfig(llvm::OpenMPIRBuilderConfig(
+/* IsEmbedded */ false, /* IsTargetCodegen */ false,
 /* OpenMPOffloadMandatory */ false,
 /* HasRequiresReverseOffload */ false,
 /* HasRequiresUnifiedAddress */ false,
 /* HasRequiresUnifiedSharedMemory */ false,
-/* OpenMPOffloadMandatory */ false);
-ompBuilder->setConfig(config);
+/* OpenMPOffloadMandatory */ false));
   }
   return ompBuilder.get();
 }
@@ -1383,11 +1369,17 @@
 return nullptr;
   if (failed(translator.createTBAAMetadata()))
 return nullptr;
+
+  // Convert module itself before any functions and operations inside, so that
+  // the OpenMPIRBuilder is configured with the OpenMP dialect attributes
+  // attached to the module by the amendOperation() flow before then.
+  llvm::IRBuilder<> llvmBuilder(llvmContext);
+  if (failed(translator.convertOperation(*module, llvmBuilder)))
+return nullptr;
   if (failed(translator.convertFunctions()))
 return nullptr;
 
   // Convert other top-level operations if possible.
-  llvm::IRBuilder<> llvmBuilder(llvmContext);
   for (Operation  : getModuleBody(module).getOperations()) {
 if (!isa() &&
@@ -1397,10 +1389,6 @@
 }
   }
 
-  // Convert module itself.
-  if (failed(translator.convertOperation(*module, llvmBuilder)))
-return nullptr;
-
   if 

[PATCH] D151964: [NFC][CLANG] Fix Static Code Analyzer Concerns with dereference null return value in applyObjCTypeArgs()

2023-06-02 Thread Soumi Manna via Phabricator via cfe-commits
Manna added inline comments.



Comment at: clang/lib/Sema/SemaType.cpp:956
   // Determine whether the type argument is substitutable for the bound.
   if (typeArgObjC->isObjCIdType()) {
 // When the type argument is 'id', the only acceptable type

erichkeane wrote:
> Note for future reviewers: This 'if' on both branches dereferences the 
> `boundObjC` pointer. The true path is just below here, on 959.  Second is in 
> the condition inside of the `else if` on 961, `canAssignObjCInterfaces` 
> immediately dereferences the parameters.
>>This 'if' on both branches dereferences the boundObjC pointer. The true path 
>>is just below here, on 959. Second is in the condition inside of the else if 
>>on 961, canAssignObjCInterfaces immediately dereferences the parameters.

Yes.

Thank you @erichkeane for reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151964

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


[PATCH] D151833: Respect "-fdiagnostics-absolute-paths" on emit include location

2023-06-02 Thread Charalampos Mitrodimas via Phabricator via cfe-commits
charmitro added inline comments.



Comment at: clang/test/Frontend/absolute-paths.c:6
+// NORMAL: In file included from [[ROOT_ABSOLUTE]]:4:
+// ABSOLUTE: In file included from [[ROOT_ABSOLUTE]]:4:
 

tbaeder wrote:
> This checks the same thing in both cases, but in the `NORMAL` case, it should 
> //not// use the absolute path, shouldn't it?
You're correct. I was constantly testing it from the same path.

Since the relative path is going to be different depending on where you running 
from, would it be wise to accept a regular expression of any string in the 
`NORMAL` case?

For example, 
```
NORMAL: In file included from {{.*}}:
```


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

https://reviews.llvm.org/D151833

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


[PATCH] D151094: [clang] Implement P2564 "consteval must propagate up"

2023-06-02 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

I don't understand our consteval implementation enough to approve this, but I 
didn't see anything to comment on while going through this.




Comment at: clang/include/clang/Sema/Sema.h:1071
 FD->setWillHaveBody(true);
-  else
+S.ExprEvalContexts.back().InImmediateFunctionContext =
+FD->isImmediateFunction();

I'm annoyed that we do `ExprEvalContexts.back()` as often as we do, and don't 
just have `Sema::curExprEvalContext`.

There isn't really anything for you to do here, but I wanted to tell someone of 
this annoyance, as this is the 3rd time its popped up in a week for me :/


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151094

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


[PATCH] D151957: [NFC][CLANG] Fix bug with dereference null return value in GetFunctionTypeForVTable()

2023-06-02 Thread Soumi Manna via Phabricator via cfe-commits
Manna added a comment.

Thank you @erichkeane for reviews!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151957

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


  1   2   >