[PATCH] D134208: [clang] [Driver] Do not transform explicit --config filename

2022-09-19 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa7d2409bac7f: [clang] [Driver] Do not transform explicit 
--config filename (authored by mgorny).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134208

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/config-file-errs.c
  clang/test/Driver/config-file.c
  clang/test/Driver/config-file2.c
  clang/test/Driver/config-file3.c

Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -37,7 +37,7 @@
 //
 //--- File specified by --config overrides config inferred from clang executable.
 //
-// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config i386-qqq -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-EXPLICIT
+// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config i386-qqq.cfg -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-EXPLICIT
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
 
@@ -77,27 +77,24 @@
 // RUN: ln -s %clang %t/testreload/x86_64-clang-g++
 // RUN: echo "-Wundefined-func-template" > %t/testreload/i386-clang-g++.cfg
 // RUN: echo "-Werror" > %t/testreload/i386.cfg
+// RUN: echo "-Wall" > %t/testreload/x86_64-clang-g++.cfg
 // RUN: %t/testreload/x86_64-clang-g++ --config-system-dir= --config-user-dir= -c -m32 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD
 //
 // CHECK-RELOAD: Configuration file: {{.*}}/testreload/i386-clang-g++.cfg
 // CHECK-RELOAD: -Wundefined-func-template
 // CHECK-RELOAD-NOT: -Werror
+// CHECK-RELOAD-NOT: -Wall
 
-//--- If config file is specified by --config and its name does not start with architecture, it is used without reloading.
-//
-// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir=%S/Inputs --config-user-dir= --config config-3 -c -m32 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD1a
-//
-// CHECK-RELOAD1a: Configuration file: {{.*}}/Inputs/config-3.cfg
-//
-// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir=%S/Inputs --config-user-dir= --config config-3 -c --target=i386 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD1b
-//
-// CHECK-RELOAD1b: Configuration file: {{.*}}/Inputs/config-3.cfg
+//--- Same for -target in place of -m32.
+// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir= --config-user-dir= -c -target i386 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD
 
-//--- If config file is specified by --config and its name starts with architecture, it is reloaded.
-//
-// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config x86_64-qqq -c -m32 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD1c
+//--- `-target i386 -m64` should load the 64-bit config.
+// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir= --config-user-dir= -c -target i386 -m64 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD1a
 //
-// CHECK-RELOAD1c: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
+// CHECK-RELOAD1a: Configuration file: {{.*}}/testreload/x86_64-clang-g++.cfg
+// CHECK-RELOAD1a: -Wall
+// CHECK-RELOAD1a-NOT: -Werror
+// CHECK-RELOAD1a-NOT: -Wundefined-func-template
 
 //--- x86_64-clang-g++ tries to find config i386.cfg if i386-clang-g++.cfg is not found.
 //
@@ -107,4 +104,9 @@
 // CHECK-RELOAD1d: Configuration file: {{.*}}/testreload/i386.cfg
 // CHECK-RELOAD1d: -Werror
 // CHECK-RELOAD1d-NOT: -Wundefined-func-template
+// CHECK-RELOAD1d-NOT: -Wall
 
+//--- x86_64-clang-g++ uses x86_64-clang-g++.cfg if i386*.cfg are not found.
+//
+// RUN: rm %t/testreload/i386.cfg
+// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir= --config-user-dir= -c -m32 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD1a
Index: clang/test/Driver/config-file2.c
===
--- clang/test/Driver/config-file2.c
+++ /dev/null
@@ -1,51 +0,0 @@
-// REQUIRES: x86-registered-target
-
-//--- Invocation `clang --config x86_64-qqq -m32` loads `i386-qqq.cfg` if the latter exists.
-//
-// RUN: %clang --config-system-dir=%S/Inputs/config --config-user-dir= --config x86_64-qqq -m32 -c %s -### 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD
-// CHECK-RELOAD: Target: i386
-// CHECK-RELOAD: Configuration file: {{.*}}Inputs{{.}}config{{.}}i386-qqq.cfg
-
-
-//--- Invocation `clang --config x86_64-qqq2 -m32` loads `i386.cfg` if the latter exists in another search directory.
-//
-// RUN: %clang --config-system-dir=%S/Inputs/config --config-user-dir=%S/Inputs/config2 --config x8

[clang] a7d2409 - [clang] [Driver] Do not transform explicit --config filename

2022-09-19 Thread Michał Górny via cfe-commits

Author: Michał Górny
Date: 2022-09-20T07:58:27+02:00
New Revision: a7d2409bac7fd9ef6b8c362f1ab54a9b6339a69a

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

LOG: [clang] [Driver] Do not transform explicit --config filename

Disable transformations (e.g. attempting to replace target architecture)
in the config filename that is passed explicitly via `--config`.  This
behavior is surprising and confusing -- if user passes an explicit
config filename, Clang should use it as is.  The transformations are
still applied when the name is deduced from filename.

Update the tests accordingly.  This primarily ensures that full filename
with .cfg suffix is passed to --config (appending `.cfg` implicitly is
not documented, and would collide with use of filenames with other
suffixes).  The config-file2.c suite is removed entirely as it tested
the transformations on the argument to --config.  However, the aspects
of that that were not tested as part of config-file3.c are now added
there (based on config filename deduced from executable).

This change streamlines the code in Driver::loadConfigFile(), opening
the possibility of further changes, including support for handling
multiple --config options and refactoring of filename deduction.

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

Added: 


Modified: 
clang/lib/Driver/Driver.cpp
clang/test/Driver/config-file-errs.c
clang/test/Driver/config-file.c
clang/test/Driver/config-file3.c

Removed: 
clang/test/Driver/config-file2.c



diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 013d5b32074e9..52990f14e7eac 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -964,7 +964,6 @@ bool Driver::readConfigFile(StringRef FileName) {
 
 bool Driver::loadConfigFile() {
   std::string CfgFileName;
-  bool FileSpecifiedExplicitly = false;
 
   // Process options that change search path for config files.
   if (CLOptions) {
@@ -988,7 +987,11 @@ bool Driver::loadConfigFile() {
 }
   }
 
+  // Prepare list of directories where config file is searched for.
+  StringRef CfgFileSearchDirs[] = {UserConfigDir, SystemConfigDir, Dir};
+
   // First try to find config file specified in command line.
+  llvm::SmallString<128> CfgFilePath;
   if (CLOptions) {
 std::vector ConfigFiles =
 CLOptions->getAllArgValues(options::OPT_config);
@@ -1020,7 +1023,18 @@ bool Driver::loadConfigFile() {
 return readConfigFile(CfgFilePath);
   }
 
-  FileSpecifiedExplicitly = true;
+  // Look for the configuration file in the usual locations.
+  if (searchForFile(CfgFilePath, CfgFileSearchDirs, CfgFileName, getVFS()))
+return readConfigFile(CfgFilePath);
+
+  // Report error but only if config file was specified explicitly, by
+  // option --config. If it was deduced from executable name, it is not an
+  // error.
+  Diag(diag::err_drv_config_file_not_found) << CfgFileName;
+  for (const StringRef &SearchDir : CfgFileSearchDirs)
+if (!SearchDir.empty())
+  Diag(diag::note_drv_config_file_searched_in) << SearchDir;
+  return true;
 }
   }
 
@@ -1059,8 +1073,8 @@ bool Driver::loadConfigFile() {
 // Get architecture name from config file name like 'i386.cfg' or
 // 'armv7l-clang.cfg'.
 // Check if command line options changes effective triple.
-llvm::Triple EffectiveTriple = computeTargetTriple(*this,
- CfgTriple.getTriple(), 
*CLOptions);
+llvm::Triple EffectiveTriple =
+computeTargetTriple(*this, CfgTriple.getTriple(), *CLOptions);
 if (CfgTriple.getArch() != EffectiveTriple.getArch()) {
   FixedConfigFile = EffectiveTriple.getArchName();
   FixedArchPrefixLen = FixedConfigFile.size();
@@ -1071,11 +1085,7 @@ bool Driver::loadConfigFile() {
 }
   }
 
-  // Prepare list of directories where config file is searched for.
-  StringRef CfgFileSearchDirs[] = {UserConfigDir, SystemConfigDir, Dir};
-
   // Try to find config file. First try file with corrected architecture.
-  llvm::SmallString<128> CfgFilePath;
   if (!FixedConfigFile.empty()) {
 if (searchForFile(CfgFilePath, CfgFileSearchDirs, FixedConfigFile,
   getVFS()))
@@ -1101,16 +,8 @@ bool Driver::loadConfigFile() {
   return readConfigFile(CfgFilePath);
   }
 
-  // Report error but only if config file was specified explicitly, by option
-  // --config. If it was deduced from executable name, it is not an error.
-  if (FileSpecifiedExplicitly) {
-Diag(diag::err_drv_config_file_not_found) << CfgFileName;
-for (const StringRef &SearchDir : CfgFileSearchDirs)
-  if (!SearchDir.empty())
-Diag(diag::note_drv_config_file_searched_in) << 

[PATCH] D133443: [RISCV][MC] Add support for experimental Zawrs extension

2022-09-19 Thread Alex Bradbury via Phabricator via cfe-commits
asb added a comment.

It looks like they're still missing in this updated version of the patch?


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

https://reviews.llvm.org/D133443

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


[PATCH] D134208: [clang] [Driver] Do not transform explicit --config filename

2022-09-19 Thread Serge Pavlov via Phabricator via cfe-commits
sepavloff accepted this revision.
sepavloff added a comment.

LGTM.

Thanks!


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

https://reviews.llvm.org/D134208

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


[PATCH] D133574: [C2x] reject type definitions in offsetof

2022-09-19 Thread YingChi Long via Phabricator via cfe-commits
inclyc updated this revision to Diff 461463.
inclyc added a comment.

Switch back to RAIIObject.

Currently clang could not generate diagnostic messages for nested definitions
in C++. I believe using RAIIObject here is logically correct, but in C++ mode,
`ActOnTag` returns `nullptr`, and the comment says

> We can't recover well from the cases where we make the type anonymous



  /* SemaDecl.cpp Sema::ActOnTag Ln 17189 */
  // In C++, don't return an invalid declaration. We can't recover well from
  // the cases where we make the type anonymous.
  if (Invalid && getLangOpts().CPlusPlus) {
if (New->isBeingDefined())
  if (auto RD = dyn_cast(New))
RD->completeDefinition();
return nullptr;
  } else if (SkipBody && SkipBody->ShouldSkip) {
return SkipBody->Previous;
  } else {
return New;
  }

I believe the state "ParsingBuiltinOffsetof" is correctly passed into
`ParseCXXMemberSpecification` (parsing nested definition), and if clang
recovers invalid declaration in the furture, nested definitions will be caught.

  if (TUK == Sema::TUK_Definition) {
assert(Tok.is(tok::l_brace) ||
   (getLangOpts().CPlusPlus && Tok.is(tok::colon)) ||
   isClassCompatibleKeyword());
if (SkipBody.ShouldSkip)
  SkipCXXMemberSpecification(StartLoc, AttrFixitLoc, TagType,
 TagOrTempResult.get());
else if (getLangOpts().CPlusPlus)
  ParseCXXMemberSpecification(StartLoc, AttrFixitLoc, attrs, TagType,
  TagOrTempResult.get());  // <  nullptr, 
nested declaration skipped
else {
  Decl *D =
  SkipBody.CheckSameAsPrevious ? SkipBody.New : TagOrTempResult.get();
  // Parse the definition body.
  ParseStructUnionBody(StartLoc, TagType, cast(D));
  if (SkipBody.CheckSameAsPrevious &&
  !Actions.ActOnDuplicateDefinition(TagOrTempResult.get(), SkipBody)) {
DS.SetTypeSpecError();
return;
  }
}
  }


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133574

Files:
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Parse/RAIIObjectsForParser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Parser/declarators.c
  clang/test/Sema/offsetof.c
  clang/test/SemaCXX/offsetof.cpp

Index: clang/test/SemaCXX/offsetof.cpp
===
--- clang/test/SemaCXX/offsetof.cpp
+++ clang/test/SemaCXX/offsetof.cpp
@@ -83,3 +83,18 @@
   expected-error {{invalid application of 'offsetof' to a field of a virtual base}}
 };
 }
+
+// Reject definitions in __builtin_offsetof
+// https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm
+int test_definition(void) {
+  return __builtin_offsetof(struct A // expected-error{{'A' cannot be defined in '__builtin_offsetof'}} 
+  { 
+int a;
+struct B
+{
+  int c;
+  int d;
+};
+B x;
+  }, a);
+}
Index: clang/test/Sema/offsetof.c
===
--- clang/test/Sema/offsetof.c
+++ clang/test/Sema/offsetof.c
@@ -70,3 +70,16 @@
   return __builtin_offsetof(Array, array[*(int*)0]); // expected-warning{{indirection of non-volatile null pointer}} expected-note{{__builtin_trap}}
 }
 
+// Reject definitions in __builtin_offsetof
+// https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm
+int test_definition(void) {
+  return __builtin_offsetof(struct A // expected-error{{'struct A' cannot be defined in '__builtin_offsetof'}} 
+  { 
+int a;
+struct B // expected-error{{'struct B' cannot be defined in '__builtin_offsetof'}}
+{
+  int c;
+  int d;
+} x;
+  }, a);
+}
Index: clang/test/Parser/declarators.c
===
--- clang/test/Parser/declarators.c
+++ clang/test/Parser/declarators.c
@@ -80,10 +80,6 @@
 struct test10 { int a; } static test10x;
 struct test11 { int a; } const test11x;
 
-// PR6216
-void test12(void) {
-  (void)__builtin_offsetof(struct { char c; int i; }, i);
-}
 
 // rdar://7608537
 struct test13 { int a; } (test13x);
Index: clang/lib/Sema/SemaDecl.cpp
===
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -16254,7 +16254,7 @@
  SourceLocation ScopedEnumKWLoc,
  bool ScopedEnumUsesClassTag, TypeResult UnderlyingType,
  bool IsTypeSpecifier, bool IsTemplateParamOrArg,
- SkipBodyInfo *SkipBody) {
+ SkipBodyInfo *SkipBody, bool IsWithinOffsetOf) {
   // If this is not a definition, it must have a name.
   IdentifierInfo *Ori

[PATCH] D133468: [clang] Implement divergence for TypedefType and UsingType

2022-09-19 Thread David Rector via Phabricator via cfe-commits
davrec added a comment.

If I understand this correctly: whenever isDivergent() is true, `getDecl()` or 
`getFoundDecl()` is an arbitrary choice between multiple candidate 
(re)declarations of a typedef or using decl.  In particular it will be the 
first redeclaration, //even though each different redeclaration can contain 
different sugar information//.

E.g. considering your examples:

  using X1 = int;
  using Y1 = int;
  
  using RPB1 = X1*;
  using RPX1 = RPB1;
  using RPB1 = Y1*; // redeclared
  using RPY1 = RPB1;
  
  namespace A { using type1 = X1*; };
  namespace C { using A::type1; };
  using UPX1 = C::type1;
  namespace A { using type1 = Y1*; };  // redeclared
  namespace C { using A::type1; }; // redeclared
  using UPY1 = C::type1;

So far so good: isDivergent() would be false for all the above TypedefTypes and 
UsingTypes, since the UnderlyingTypes and Decls/FoundDecls are consistent.  But 
these types are a different matter:

  auto t29 = 0 ? (RPX1){} : (RPY1){};
  auto t32 = 0 ? (UPX1){} : (UPY1){};

In the process of unifying the sugar to get the deduced type of t29/t32, we 
will compare their sugar, which has the same basic structure for each, but 
different decls/found decls; so unifying these types will simply involve 
unifying their decls; and getCommonDecl(X,Y) has been defined to will simply 
get the older declaration between them.  So, the TypedefType/UsingType sugar in 
t29/t32 will reference the X1 decls and friends, *not* the Y1s, as its 
Decls/FoundDecls.  (Right?)

The UnderlyingType however will not be as arbitrary, as it will use 
getCommonType to skip over everything the two don't have in common.

If I have this right, my question is: since the Decl/FoundDecl is an arbitrary 
choice, should we solve this by either

1. constructing these with a null Decl/FoundDecl for such types, or if that is 
problematic,
2. renaming `isDivergent` to `declIsArbitrary()` or something like that, to 
suggest that not only do the underlying type and decl diverge, it is the 
underlying type which is more meaningful, not the decl.






Comment at: clang/include/clang/AST/Type.h:4490
   UsingShadowDecl *getFoundDecl() const { return Found; }
+  bool isDivergent() const { return UsingBits.isDivergent; }
   QualType getUnderlyingType() const;

The name of this might be less important than just documenting it extremely 
well here, with an example.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133468

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


[PATCH] D133583: [clang][ubsan] Fix __builtin_assume_aligned incorrect type descriptor and C++ object polymorphic address

2022-09-19 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133583

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


[PATCH] D130513: [Flang] Add -fconvert option to swap endianness for unformatted files

2022-09-19 Thread Jonathon Penix via Phabricator via cfe-commits
jpenix-quic added inline comments.



Comment at: flang/test/Driver/emit-mlir.f90:16
 ! CHECK-NEXT: }
+! CHECK-NEXT: fir.global @_QQEnvironmentDefaults constant : 
!fir.ref, 
!fir.ref> {
+! CHECK-NEXT:  %[[VAL_0:.*]] = fir.zero_bits !fir.ref, !fir.ref>

peixin wrote:
> jpenix-quic wrote:
> > peixin wrote:
> > > jpenix-quic wrote:
> > > > peixin wrote:
> > > > > Is it possible not to generated this global variable if `fconvert=` 
> > > > > is not specified?
> > > > I'm not entirely sure--the issue I was running into was how to handle 
> > > > this in Fortran_main.c in a way which worked for all of 
> > > > GCC/Clang/Visual Studio (and maybe others?). I was originally thinking 
> > > > of doing this by using a weak definition of _QQEnvironmentDefaults set 
> > > > to nullptr so fconvert, etc. could override this definition without 
> > > > explicitly generating the fallback case. For GCC/clang, I think I could 
> > > > use __attribute__((weak)), but I wasn't sure how to handle this if 
> > > > someone tried to build with Visual Studio (or maybe another toolchain). 
> > > > I saw a few workarounds (ex: 
> > > > https://devblogs.microsoft.com/oldnewthing/20200731-00/?p=104024) but I 
> > > > shied away from this since it seems to be an undocumented feature (and 
> > > > presumably only helps with Visual Studio). 
> > > > 
> > > > Do you know of a better or more general way I could do this? (Or, is 
> > > > there non-weak symbol approach that might be better that I'm missing?)
> > > How about generate one runtime function with the argument of 
> > > `EnvironmentDefaultList`? This will avoid this and using one extern 
> > > variable?
> > > 
> > > If users use one variable with bind C name `_QQEnvironmentDefaults` in 
> > > fortran or one variable with name `_QQEnvironmentDefaults` in C, it is 
> > > risky. Would using the runtime function and static variable with the type 
> > > `EnvironmentDefaultList` in runtime be safer?
> > Agreed that there are potential risks with the current approach (although, 
> > are the `_Q*` names considered reserved?). Unfortunately, I think 
> > generating a call to set the environment defaults requires somewhat 
> > significant changes to the runtime. The runtime reads environment variables 
> > during initialization in `ExecutionEnvironment::Configure` which is 
> > ultimately called from the "hardcoded" `Fortran_main.c` and I need to set 
> > the defaults before this happens. So, I believe I'd either have to move the 
> > initialization to `_QQmain`  or make it so that `main` isn't hardcoded so 
> > that I could insert the appropriate runtime function.
> > 
> > @klausler I think I asked you about this when I was first trying to figure 
> > out how to implement the environment defaults and you suggested I try the 
> > extern approach--please let me know if you have thoughts/suggestions around 
> > this!
> This is what @klausler suggested:
> ```
> Instead of adding new custom APIs that let command-line options control 
> behavior in a way that is redundant with the runtime environment, I suggest 
> that you try a more general runtime library API by which the main program can 
> specify a default environment variable setting, or a set of them. Then turn 
> the command-line options into the equivalent environment settings and pass 
> them as default settings that could be overridden by the actual environment.
> ```
> If I understand correctly, what I am suggesting match his comments. The "main 
> program" he means should be fortran main program, not the 
> `RTNAME(ProgramStart`. In your initial patch, you add the runtime specified 
> for "convert option". I think @klausler suggest you making the runtime 
> argument more general used for a set of runtime environment variable 
> settings, not restricted to "convert option". And that is what you already 
> added -- `EnvironmentDefaultList`. So, combining this patch and your initial 
> patch will be the solution. Hope I understand it correctly.
The issue I hit with the suggested approach is that in order to use the 
pre-existing runtime environment variable handling to set the internal state I 
need to set the environment variable defaults before the environment variables 
are read by the runtime.

I might be misunderstanding/missing something, but given that the environment 
variables are read as part of `RTNAME(ProgramStart)` in `main` and the earliest 
I can place the call if I am generating it is `_QQmain`, I think that leaves 
three options: 1. don't hardcode `main` so that I can place the call early 
enough 2. delay or rerun the code [[ 
https://github.com/llvm/llvm-project/blob/c619d4f840dcba54751ff8c5aaafce0f173a4ad5/flang/runtime/environment.cpp#L50-L90
 | here ]] that is responsible for initializing the runtime state so that it is 
called as part of `_QQmain` so I can insert my runtime function before it or 3. 
hardcode something like the `_QQEnvironmentDefaults` into Fortran_main.c so 

[PATCH] D134249: [modules] Fix error "malformed or corrupted AST file: 'SourceLocation remap refers to unknown module...'".

2022-09-19 Thread Chuanqi Xu via Phabricator via cfe-commits
ChuanqiXu accepted this revision.
ChuanqiXu added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Serialization/ModuleManager.cpp:284-286
   for (ModuleIterator victim = First; victim != Last; ++victim) {
 Modules.erase(victim->File);
   }

minor: we can remove the `{` here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134249

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


[PATCH] D133920: [X86][fastcall][vectorcall] Move capability check before free register update

2022-09-19 Thread Phoebe Wang via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG46bb4b99ae9f: [X86][fastcall][vectorcall] Move capability 
check before free register update (authored by pengfei).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133920

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/mangle-windows.c
  clang/test/CodeGen/regcall.c
  clang/test/CodeGen/stdcall-fastcall.c
  clang/test/CodeGen/vectorcall.c

Index: clang/test/CodeGen/vectorcall.c
===
--- clang/test/CodeGen/vectorcall.c
+++ clang/test/CodeGen/vectorcall.c
@@ -19,6 +19,10 @@
 // X86: define dso_local x86_vectorcallcc void @"\01v4@@28"(i32 inreg noundef %a, %struct.Large* noundef byval(%struct.Large) align 4 %b, i32 inreg noundef %c)
 // X64: define dso_local x86_vectorcallcc void @"\01v4@@40"(i32 noundef %a, %struct.Large* noundef %b, i32 noundef %c)
 
+void __vectorcall v5(long long a, int b, int c) {}
+// X86: define dso_local x86_vectorcallcc void @"\01v5@@16"(i64 noundef %a, i32 inreg noundef %b, i32 inreg noundef %c)
+// X64: define dso_local x86_vectorcallcc void @"\01v5@@24"(i64 noundef %a, i32 noundef %b, i32 noundef %c)
+
 struct HFA2 { double x, y; };
 struct HFA4 { double w, x, y, z; };
 struct HFA5 { double v, w, x, y, z; };
Index: clang/test/CodeGen/stdcall-fastcall.c
===
--- clang/test/CodeGen/stdcall-fastcall.c
+++ clang/test/CodeGen/stdcall-fastcall.c
@@ -144,3 +144,10 @@
   // CHECK: call x86_fastcallcc void @foo12(float %{{.*}}, i32 inreg noundef %
   foo12(y, x);
 }
+
+void __attribute__((fastcall)) foo13(long long a, int b, int c);
+void bar13(long long a, int b, int c) {
+  // CHECK-LABEL: define{{.*}} void @bar13
+  // CHECK: call x86_fastcallcc void @foo13(i64 noundef %{{.*}}, i32 inreg noundef %{{.*}}, i32 inreg noundef %
+  foo13(a, b, c);
+}
Index: clang/test/CodeGen/regcall.c
===
--- clang/test/CodeGen/regcall.c
+++ clang/test/CodeGen/regcall.c
@@ -31,6 +31,10 @@
 // Win64: define dso_local x86_regcallcc void @__regcall3__v4(i32 noundef %a, %struct.Large* noundef %b, i32 noundef %c)
 // Lin64: define dso_local x86_regcallcc void @__regcall3__v4(i32 noundef %a, [5 x i32] %b.coerce, i32 noundef %c)
 
+void __regcall v5(long long a, int b, int c) {}
+// X86: define dso_local x86_regcallcc void @__regcall3__v5(i64 noundef %a, i32 inreg noundef %b, i32 inreg noundef %c)
+// X64: define dso_local x86_regcallcc void @__regcall3__v5(i64 noundef %a, i32 noundef %b, i32 noundef %c)
+
 struct HFA2 { double x, y; };
 struct HFA4 { double w, x, y, z; };
 struct HFA5 { double v, w, x, y, z; };
Index: clang/test/CodeGen/mangle-windows.c
===
--- clang/test/CodeGen/mangle-windows.c
+++ clang/test/CodeGen/mangle-windows.c
@@ -47,7 +47,7 @@
 // X64: define dso_local void @f8(
 
 void __fastcall f9(long long a, char b, char c, short d) {}
-// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 noundef signext %b, i8 noundef signext %c, i16 noundef signext %d)
+// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 inreg noundef signext %b, i8 inreg noundef signext %c, i16 noundef signext %d)
 // X64: define dso_local void @f9(
 
 void f12(void) {}
@@ -81,3 +81,6 @@
 void __vectorcall v6(char a, char b) {}
 // CHECK: define dso_local x86_vectorcallcc void @"\01v6@@8"(
 // X64: define dso_local x86_vectorcallcc void @"\01v6@@16"(
+
+void __vectorcall v7(long long a, char b, char c, short d) {}
+// CHECK: define dso_local x86_vectorcallcc void @"\01v7@@20"(i64 noundef %a, i8 inreg noundef signext %b, i8 inreg noundef signext %c, i16 noundef signext %d)
Index: clang/lib/CodeGen/TargetInfo.cpp
===
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -1771,23 +1771,22 @@
 }
 
 bool X86_32ABIInfo::shouldPrimitiveUseInReg(QualType Ty, CCState &State) const {
-  if (!updateFreeRegs(Ty, State))
-return false;
+  bool IsPtrOrInt = (getContext().getTypeSize(Ty) <= 32) &&
+(Ty->isIntegralOrEnumerationType() || Ty->isPointerType() ||
+ Ty->isReferenceType());
 
-  if (IsMCUABI)
+  if (!IsPtrOrInt && (State.CC == llvm::CallingConv::X86_FastCall ||
+  State.CC == llvm::CallingConv::X86_VectorCall))
 return false;
 
-  if (State.CC == llvm::CallingConv::X86_FastCall ||
-  State.CC == llvm::CallingConv::X86_VectorCall ||
-  State.CC == llvm::CallingConv::X86_RegCall) {
-if (getContext().getTypeSize(Ty) > 32)
-  return false;
+  if (!updateFreeRegs(Ty, State))
+return false;
 
-return (Ty->isIntegralOrEnumerationType() || Ty->i

[clang] 46bb4b9 - [X86][fastcall][vectorcall] Move capability check before free register update

2022-09-19 Thread Phoebe Wang via cfe-commits

Author: Phoebe Wang
Date: 2022-09-20T09:18:23+08:00
New Revision: 46bb4b99ae9f7b043c58d0b17df031bd02ccfd01

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

LOG: [X86][fastcall][vectorcall] Move capability check before free register 
update

When passing arguments with `__fastcall` or `__vectorcall` in 32-bit MSVC, the 
following arguments have chance to be passed by register if the current one 
failed. `__regcall` from ICC is on the contrary: https://godbolt.org/z/4MPbzhaMG
All the three calling conversions are not supported in GCC.

Fixes: #57737

Reviewed By: rnk

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGen/mangle-windows.c
clang/test/CodeGen/regcall.c
clang/test/CodeGen/stdcall-fastcall.c
clang/test/CodeGen/vectorcall.c

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 96b0c7e363052..1744a8b6f84bf 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -358,6 +358,7 @@ RISC-V Support in Clang
 X86 Support in Clang
 
 - Support ``-mindirect-branch-cs-prefix`` for call and jmp to indirect thunk.
+- Fix 32-bit ``__fastcall`` and ``__vectorcall`` ABI mismatch with MSVC.
 
 DWARF Support in Clang
 --

diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 2f9adb83ffa2a..a16c3ad6ffa89 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -1771,23 +1771,22 @@ bool X86_32ABIInfo::shouldAggregateUseDirect(QualType 
Ty, CCState &State,
 }
 
 bool X86_32ABIInfo::shouldPrimitiveUseInReg(QualType Ty, CCState &State) const 
{
-  if (!updateFreeRegs(Ty, State))
-return false;
+  bool IsPtrOrInt = (getContext().getTypeSize(Ty) <= 32) &&
+(Ty->isIntegralOrEnumerationType() || Ty->isPointerType() 
||
+ Ty->isReferenceType());
 
-  if (IsMCUABI)
+  if (!IsPtrOrInt && (State.CC == llvm::CallingConv::X86_FastCall ||
+  State.CC == llvm::CallingConv::X86_VectorCall))
 return false;
 
-  if (State.CC == llvm::CallingConv::X86_FastCall ||
-  State.CC == llvm::CallingConv::X86_VectorCall ||
-  State.CC == llvm::CallingConv::X86_RegCall) {
-if (getContext().getTypeSize(Ty) > 32)
-  return false;
+  if (!updateFreeRegs(Ty, State))
+return false;
 
-return (Ty->isIntegralOrEnumerationType() || Ty->isPointerType() ||
-Ty->isReferenceType());
-  }
+  if (!IsPtrOrInt && State.CC == llvm::CallingConv::X86_RegCall)
+return false;
 
-  return true;
+  // Return true to apply inreg to all legal parameters except for MCU targets.
+  return !IsMCUABI;
 }
 
 void X86_32ABIInfo::runVectorCallFirstPass(CGFunctionInfo &FI, CCState &State) 
const {

diff  --git a/clang/test/CodeGen/mangle-windows.c 
b/clang/test/CodeGen/mangle-windows.c
index 1fcac01fb0552..046b1e8815a8a 100644
--- a/clang/test/CodeGen/mangle-windows.c
+++ b/clang/test/CodeGen/mangle-windows.c
@@ -47,7 +47,7 @@ void __fastcall f8(long long a) {}
 // X64: define dso_local void @f8(
 
 void __fastcall f9(long long a, char b, char c, short d) {}
-// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 
noundef signext %b, i8 noundef signext %c, i16 noundef signext %d)
+// CHECK: define dso_local x86_fastcallcc void @"\01@f9@20"(i64 noundef %a, i8 
inreg noundef signext %b, i8 inreg noundef signext %c, i16 noundef signext %d)
 // X64: define dso_local void @f9(
 
 void f12(void) {}
@@ -81,3 +81,6 @@ void __vectorcall v5(long long a) {}
 void __vectorcall v6(char a, char b) {}
 // CHECK: define dso_local x86_vectorcallcc void @"\01v6@@8"(
 // X64: define dso_local x86_vectorcallcc void @"\01v6@@16"(
+
+void __vectorcall v7(long long a, char b, char c, short d) {}
+// CHECK: define dso_local x86_vectorcallcc void @"\01v7@@20"(i64 noundef %a, 
i8 inreg noundef signext %b, i8 inreg noundef signext %c, i16 noundef signext 
%d)

diff  --git a/clang/test/CodeGen/regcall.c b/clang/test/CodeGen/regcall.c
index a20671f606f47..d2c7344132b3e 100644
--- a/clang/test/CodeGen/regcall.c
+++ b/clang/test/CodeGen/regcall.c
@@ -31,6 +31,10 @@ void __regcall v4(int a, struct Large b, int c) {}
 // Win64: define dso_local x86_regcallcc void @__regcall3__v4(i32 noundef %a, 
%struct.Large* noundef %b, i32 noundef %c)
 // Lin64: define dso_local x86_regcallcc void @__regcall3__v4(i32 noundef %a, 
[5 x i32] %b.coerce, i32 noundef %c)
 
+void __regcall v5(long long a, int b, int c) {}
+// X86: define dso_local x86_regcallcc void @__regcall3__v5(i64 noundef %a, 
i32 inreg noundef %b, i32 inreg noundef %c)
+// X64: define dso_local x86_regcallcc void @__

[PATCH] D134249: [modules] Fix error "malformed or corrupted AST file: 'SourceLocation remap refers to unknown module...'".

2022-09-19 Thread Volodymyr Sapsai via Phabricator via cfe-commits
vsapsai created this revision.
vsapsai added reviewers: bnbarham, ChuanqiXu.
Herald added a subscriber: ributzka.
Herald added a project: All.
vsapsai requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When a framework can be found at a new location, all references to it in
the module cache become outdated. When we try to load such outdated .pcm
file, we shouldn't change any already loaded and processed modules.

If `Module` has `ASTFile`, it means we've read its AST block already and
it is too late to undo that. If `ASTFile` is `None`, there is no value
in setting it to `None` again. So we don't reset `ASTFile` in
`ModuleManager::removeModules` at all.

rdar://97216258


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134249

Files:
  clang/include/clang/Basic/Module.h
  clang/include/clang/Serialization/ModuleManager.h
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ModuleManager.cpp
  clang/test/Modules/dependent-module-different-location.m

Index: clang/test/Modules/dependent-module-different-location.m
===
--- /dev/null
+++ clang/test/Modules/dependent-module-different-location.m
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+//
+// At first build Stable.pcm that references Movable.framework from StableFrameworks.
+// RUN: %clang_cc1 -fsyntax-only -F %t/JustBuilt -F %t/StableFrameworks %t/prepopulate-module-cache.m \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+//
+// Now add Movable.framework to JustBuilt.
+// RUN: mkdir %t/JustBuilt
+// RUN: cp -r %t/StableFrameworks/Movable.framework %t/JustBuilt/Movable.framework
+//
+// Load Movable.pcm at first for JustBuilt location and then in the same TU try to load transitively for StableFrameworks location.
+// RUN: %clang_cc1 -fsyntax-only -F %t/JustBuilt -F %t/StableFrameworks %t/trigger-error.m \
+// RUN:-fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
+
+// Test the case when a dependent module is found in a different location, so
+// module cache has outdated information. 
+
+//--- StableFrameworks/Movable.framework/Headers/Movable.h
+// empty
+
+//--- StableFrameworks/Movable.framework/Modules/module.modulemap
+framework module Movable {
+  header "Movable.h"
+  export *
+}
+
+
+//--- StableFrameworks/Stable.framework/Headers/Stable.h
+#import 
+
+//--- StableFrameworks/Stable.framework/Modules/module.modulemap
+framework module Stable {
+  header "Stable.h"
+  export *
+}
+
+
+//--- prepopulate-module-cache.m
+#import 
+
+//--- trigger-error.m
+#import 
+#import 
Index: clang/lib/Serialization/ModuleManager.cpp
===
--- clang/lib/Serialization/ModuleManager.cpp
+++ clang/lib/Serialization/ModuleManager.cpp
@@ -249,7 +249,7 @@
   return NewlyLoaded;
 }
 
-void ModuleManager::removeModules(ModuleIterator First, ModuleMap *modMap) {
+void ModuleManager::removeModules(ModuleIterator First) {
   auto Last = end();
   if (First == Last)
 return;
@@ -280,19 +280,11 @@
 }
   }
 
-  // Delete the modules and erase them from the various structures.
+  // Delete the modules.
   for (ModuleIterator victim = First; victim != Last; ++victim) {
 Modules.erase(victim->File);
-
-if (modMap) {
-  StringRef ModuleName = victim->ModuleName;
-  if (Module *mod = modMap->findModule(ModuleName)) {
-mod->setASTFile(None);
-  }
-}
   }
 
-  // Delete the modules.
   Chain.erase(Chain.begin() + (First - begin()), Chain.end());
 }
 
Index: clang/lib/Serialization/ASTReader.cpp
===
--- clang/lib/Serialization/ASTReader.cpp
+++ clang/lib/Serialization/ASTReader.cpp
@@ -4227,10 +4227,7 @@
   ReadASTCore(FileName, Type, ImportLoc,
   /*ImportedBy=*/nullptr, Loaded, 0, 0, ASTFileSignature(),
   ClientLoadCapabilities)) {
-ModuleMgr.removeModules(ModuleMgr.begin() + NumModules,
-PP.getLangOpts().Modules
-? &PP.getHeaderSearchInfo().getModuleMap()
-: nullptr);
+ModuleMgr.removeModules(ModuleMgr.begin() + NumModules);
 
 // If we find that any modules are unusable, the global index is going
 // to be out-of-date. Just remove it.
Index: clang/include/clang/Serialization/ModuleManager.h
===
--- clang/include/clang/Serialization/ModuleManager.h
+++ clang/include/clang/Serialization/ModuleManager.h
@@ -250,7 +250,7 @@
 std::string &ErrorStr);
 
   /// Remove the modules starting from First (to the end).
-  void removeModules(ModuleIterator First, ModuleMap *modMap);
+  void removeModules(ModuleIterator First);
 
   /// Add an in-memor

[PATCH] D134248: [clang][modules][deps] Preserve module map load order

2022-09-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, Bigcheese.
Herald added subscribers: ributzka, arphaman.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In `ASTWriter`, input files are sorted based on whether they are system or 
user. The current implementation used single `std::queue` with `push_back` and 
`push_front`. This resulted in the user files being reversed.

This patch fixes that by keeping the system/user distinction, but otherwise 
serializing files in the order they were loaded by the `SourceManager`. This is 
then used in the dependency scanner to report module map dependencies in the 
correct order.

Depends on D134224 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134248

Files:
  clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-module-map-order.m
  clang/test/Index/Core/index-with-module.m
  clang/test/Modules/module-file-home-is-cwd.m
  clang/test/Modules/module_file_info.m

Index: clang/test/Modules/module_file_info.m
===
--- clang/test/Modules/module_file_info.m
+++ clang/test/Modules/module_file_info.m
@@ -45,16 +45,16 @@
 // CHECK:   Predefined macros:
 // CHECK: -DBLARG
 // CHECK: -DWIBBLE=WOBBLE
-// CHECK: Input file: {{.*}}DependsOnModulePrivate.h
-// CHECK-NEXT: Input file: {{.*}}Other.h
-// CHECK-NEXT: Input file: {{.*}}SubFramework.h
-// CHECK-NEXT: Input file: {{.*}}not_coroutines.h
-// CHECK-NEXT: Input file: {{.*}}not_cxx.h
-// CHECK-NEXT: Input file: {{.*}}other.h
-// CHECK-NEXT: Input file: {{.*}}module.map
-// CHECK-NEXT: Input file: {{.*}}DependsOnModule.h
+// CHECK: Input file: {{.*}}module.map
 // CHECK-NEXT: Input file: {{.*}}module_private.map
+// CHECK-NEXT: Input file: {{.*}}DependsOnModule.h
 // CHECK-NEXT: Input file: {{.*}}module.map
+// CHECK-NEXT: Input file: {{.*}}other.h
+// CHECK-NEXT: Input file: {{.*}}not_cxx.h
+// CHECK-NEXT: Input file: {{.*}}not_coroutines.h
+// CHECK-NEXT: Input file: {{.*}}SubFramework.h
+// CHECK-NEXT: Input file: {{.*}}Other.h
+// CHECK-NEXT: Input file: {{.*}}DependsOnModulePrivate.h
 
 // CHECK: Diagnostic options:
 // CHECK:   IgnoreWarnings: Yes
Index: clang/test/Modules/module-file-home-is-cwd.m
===
--- clang/test/Modules/module-file-home-is-cwd.m
+++ clang/test/Modules/module-file-home-is-cwd.m
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -fmodules -fno-implicit-modules -fmodule-file-home-is-cwd -fmodule-name=libA -emit-module Inputs/normal-module-map/module.map -o %t/mod.pcm
 // RUN: llvm-bcanalyzer --dump --disable-histogram %t/mod.pcm | FileCheck %s
 
-// CHECK:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
-// CHECK:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
 // CHECK:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}module.map'
+// CHECK:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a2.h'
+// CHECK:  blob data = 'Inputs{{/|\\}}normal-module-map{{/|\\}}a1.h'
 // CHECK-NOT: MODULE_DIRECTORY
Index: clang/test/Index/Core/index-with-module.m
===
--- clang/test/Index/Core/index-with-module.m
+++ clang/test/Index/Core/index-with-module.m
@@ -23,5 +23,5 @@
 // CHECK-DAG: 2:6 | function/C | ModA_func | c:@F@ModA_func | {{.*}} | Decl | rel: 0
 // CHECK-DAG: 2:6 | function/C | SubModA_func | c:@F@SubModA_func | {{.*}} | Decl | rel: 0
 // CHECK:  Module Inputs 
-// CHECK: user | {{.*}}ModA.h
 // CHECK: user | {{.*}}module.modulemap
+// CHECK: user | {{.*}}ModA.h
Index: clang/test/ClangScanDeps/modules-module-map-order.m
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-module-map-order.m
@@ -0,0 +1,55 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- this/module.modulemap
+module This { header "This.h" }
+//--- this/This.h
+#include "Foo.h"
+#include "Foo_Private_Excluded.h"
+
+//--- modules/module.modulemap
+module Foo { header "Foo.h" }
+//--- modules/module.private.modulemap
+explicit module Foo.Private {
+  header "Foo_Private.h"
+  exclude header "Foo_Private_Excluded.h"
+}
+//--- modules/Foo.h
+//--- modules/Foo_Private.h
+//--- modules/Foo_Private_Excluded.h
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.m",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -I DIR/this -I DIR/modules -c DIR/tu.m -o DIR/tu.o"
+}]
+
+//--- tu.m
+@import This;
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+
+// RUN: cat %t/result.json | se

[PATCH] D134224: [clang][modules][deps] Report modulemaps describing excluded headers

2022-09-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 461432.
jansvoboda11 added a comment.

Fix failing test by undoing some API changes


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134224

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-excluded-header.m

Index: clang/test/ClangScanDeps/modules-excluded-header.m
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-excluded-header.m
@@ -0,0 +1,54 @@
+// This test checks that we're reporting module maps affecting the compilation by describing excluded headers.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- frameworks/X.framework/Modules/module.modulemap
+framework module X {
+  umbrella header "X.h"
+  exclude header "Excluded.h"
+}
+//--- frameworks/X.framework/Headers/X.h
+//--- frameworks/X.framework/Headers/Excluded.h
+
+//--- mod/module.modulemap
+module Mod { header "Mod.h" }
+//--- mod/Mod.h
+#include 
+
+//--- tu.m
+@import Mod;
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.m",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -I DIR/mod -F DIR/frameworks -Werror=non-modular-include-in-module -c DIR/tu.m -o DIR/tu.m"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK:  {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/mod/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:  "-fmodule-map-file=[[PREFIX]]/frameworks/X.framework/Modules/module.modulemap"
+// CHECK-NOT:  "-fmodule-file={{.*}}"
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK:],
+// CHECK-NEXT:   "name": "Mod"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK:  }
+
+// RUN: %deps-to-rsp %t/result.json --module-name=Mod > %t/Mod.cc1.rsp
+// RUN: %deps-to-rsp %t/result.json --tu-index=0 > %t/tu.rsp
+
+// RUN: %clang @%t/Mod.cc1.rsp
+// RUN: %clang @%t/tu.rsp
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -397,52 +397,34 @@
 MDC.addFileDep(MD, IF.getFile()->getName());
   });
 
-  // We usually don't need to list the module map files of our dependencies when
-  // building a module explicitly: their semantics will be deserialized from PCM
-  // files.
-  //
-  // However, some module maps loaded implicitly during the dependency scan can
-  // describe anti-dependencies. That happens when this module, let's call it
-  // M1, is marked as '[no_undeclared_includes]' and tries to access a header
-  // "M2/M2.h" from another module, M2, but doesn't have a 'use M2;'
-  // declaration. The explicit build needs the module map for M2 so that it
-  // knows that textually including "M2/M2.h" is not allowed.
-  // E.g., '__has_include("M2/M2.h")' should return false, but without M2's
-  // module map the explicit build would return true.
-  //
-  // An alternative approach would be to tell the explicit build what its
-  // textual dependencies are, instead of having it re-discover its
-  // anti-dependencies. For example, we could create and use an `-ivfs-overlay`
-  // with `fall-through: false` that explicitly listed the dependencies.
-  // However, that's more complicated to implement and harder to reason about.
-  if (M->NoUndeclaredIncludes) {
-// We don't have a good way to determine which module map described the
-// anti-dependency (let alone what's the corresponding top-level module
-// map). We simply specify all the module maps in the order they were loaded
-// during the implicit build during scan.
-// TODO: Resolve this by serializing and only using Module::UndeclaredUses.
-MDC.ScanInstance.getASTReader()->visitTopLevelModuleMaps(
-*MF, [&](const FileEntry *FE) {
-  if (FE->getName().endswith("__inferred_module.map"))
-return;
-  // The top-level modulemap of this module will be the input file. We
-  // don't need to specify it as a module map.
-  if (FE == ModuleMap)
-return;
-  MD.ModuleMapFileDeps.push_back(FE->getName().str());
-});
-  }
+  llvm::

[PATCH] D134222: [clang][deps] Report module map describing compiled module

2022-09-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 updated this revision to Diff 461431.
jansvoboda11 added a comment.

Implement suggestions


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134222

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-header-sharing.m

Index: clang/test/ClangScanDeps/modules-header-sharing.m
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-header-sharing.m
@@ -0,0 +1,96 @@
+// There are some edge-cases where Clang depends on knowing the module whose implementation it's currently building.
+// This test makes sure scanner always reports the corresponding module map.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- frameworks/A.framework/Modules/module.modulemap
+framework module A { umbrella header "A.h" }
+//--- frameworks/B.framework/Modules/module.modulemap
+framework module B { umbrella header "B.h" }
+//--- frameworks/A.framework/Headers/A.h
+//--- frameworks/B.framework/Headers/B.h
+//--- frameworks/A.framework/Modules/module.private.modulemap
+framework module A_Private { umbrella header "A_Private.h" }
+//--- frameworks/B.framework/Modules/module.private.modulemap
+framework module B_Private { umbrella header "B_Private.h" }
+//--- frameworks/A.framework/PrivateHeaders/A_Private.h
+#import 
+//--- frameworks/B.framework/PrivateHeaders/B_Private.h
+#import 
+
+//--- shared/H.h
+
+//--- overlay.json.template
+{
+  "case-sensitive": "false",
+  "version": 0,
+  "roots": [
+{
+  "contents": [
+{
+  "external-contents": "DIR/shared/H.h",
+  "name": "H.h",
+  "type": "file"
+}
+  ],
+  "name": "DIR/frameworks/A.framework/PrivateHeaders",
+  "type": "directory"
+},
+{
+  "contents": [
+{
+  "external-contents": "DIR/shared/H.h",
+  "name": "H.h",
+  "type": "file"
+}
+  ],
+  "name": "DIR/frameworks/B.framework/PrivateHeaders",
+  "type": "directory"
+}
+  ]
+}
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.m",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -fmodule-name=A -ivfsoverlay DIR/overlay.json -F DIR/frameworks -c DIR/tu.m -o DIR/tu.o"
+}]
+
+//--- tu.m
+@import B;
+#import 
+#import 
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/overlay.json.template > %t/overlay.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+// CHECK:  {
+// CHECK:"translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "commands": [
+// CHECK-NEXT: {
+// CHECK:"command-line": [
+// CHECK:  "-fmodule-map-file=[[PREFIX]]/frameworks/A.framework/Modules/module.modulemap",
+// CHECK:  "-fmodule-name=A",
+// CHECK:],
+// CHECK-NEXT:   "executable": "clang",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/tu.m",
+// CHECK-NEXT: "[[PREFIX]]/shared/H.h"
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "input-file": "[[PREFIX]]/tu.m"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK-NEXT: }
+
+// RUN: %deps-to-rsp %t/result.json --module-name=B > %t/B.cc1.rsp
+// RUN: %clang @%t/B.cc1.rsp
+
+// RUN: %deps-to-rsp %t/result.json --tu-index=0 > %t/tu.rsp
+// RUN: %clang @%t/tu.rsp
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -189,6 +189,15 @@
   CI.clearImplicitModuleBuildOptions();
 
   if (llvm::any_of(CI.getFrontendOpts().Inputs, needsModules)) {
+Preprocessor &PP = ScanInstance.getPreprocessor();
+if (Module *CurrentModule = PP.getCurrentModuleImplementation())
+  if (const FileEntry *CurrentModuleMap =
+  PP.getHeaderSearchInfo()
+  .getModuleMap()
+  .getModuleMapFileForUniquing(CurrentModule))
+CI.getFrontendOpts().ModuleMapFiles.emplace_back(
+CurrentModuleMap->getName());
+
 SmallVector DirectDeps;
 for (const auto &KV : ModularDeps)
   if (KV.second->ImportedByMainFile)
Index: clang/lib/Lex/Preprocessor.cpp
===
--- clang/lib/Lex/Preprocessor.cpp
+++ clang/lib/Lex/Preprocessor.cpp
@@ -534,6 +534,13 @@
   return getHeaderSearchInfo().lookupModule(getLangOpts().CurrentModule);
 }
 
+Module *P

[PATCH] D134186: [Clang][OpenMP] Codegen generation for has_device_addr claues.

2022-09-19 Thread Abhinav Gaba via Phabricator via cfe-commits
abhinavgaba added inline comments.



Comment at: clang/test/OpenMP/target_has_device_addr_codegen.cpp:317
+// CHECK-NEXT:store [10 x i32]* [[AA]], [10 x i32]** [[RAA]], align 8
+// CHECK-NEXT:[[TMP2:%.*]] = load i32*, i32** [[K]], align 8
+// CHECK-NEXT:[[TMP3:%.*]] = getelementptr inbounds [1 x i8*], [1 x i8*]* 
[[DOTOFFLOAD_BASEPTRS]], i32 0, i32 0

This looks the same as `is_device_ptr(k)`. I don't think that's the correct 
thing to do for `has_device_addr(k)`. For `has_device_addr(k)`, the value being 
stored to `%offload.baseptrs` should be `i32** [[K]]`, and not a load from it.

Similarly, the kernel argument should be `[[K]]` and not `[[TMP2]]` (which is a 
load from `[[K]]`).



Comment at: openmp/libomptarget/test/mapping/has_device_addr.cpp:19
+data_device = (int *)omp_target_alloc(bytes, device_id);
+#pragma omp target teams distribute parallel for has_device_addr(data_device)
+for (int i = 0; i < size; ++i)

The clause used here should either be `has_device_addr(data_device[0])` or 
`is_device_ptr(data_device)`. `data_device` itself is an `i32**` which is 
allocated on the host (`%data_device = alloca i32*`). Its pointee has a device 
address (`%data_device_0 = load i32*, i32** %data_device`).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134186

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


[PATCH] D134136: [Clang] Support constexpr for builtin fmax, fmin, ilogb, logb, scalbn

2022-09-19 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

These patches are hard to review, yes; the reviewer has to go through and 
verify for each function that the substitutes you've written actually match the 
C library semantics.  (It's very easy to make mistakes with that sort of thing.)

On that front, I'm pretty sure the NaN handling in your fmin/fmax 
implementations are wrong.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134136

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


[PATCH] D134243: Don't crash when code completing `using enum ^Foo`.

2022-09-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clang/lib/Parse/ParseDecl.cpp:4591
 Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum);
+DS.SetTypeSpecError();
 return;

this is a bit unusual, usually parse() functions just stop after hitting CC, as 
if they hit something unexpected.

However ParseUsingDeclaration immediately calls ActOnUsingDeclaration, which 
asserts that the enum specifier we parsed was one of {enum, typename, error}. 
It seems simpler to signal failure using the existing mechanism than add a new 
one - LMK what you think.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134243

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


[PATCH] D134222: [clang][deps] Report module map describing compiled module

2022-09-19 Thread Ben Langmuir via Phabricator via cfe-commits
benlangmuir added inline comments.



Comment at: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp:194
+const FileEntry *CurrentModMap =
+PP.getHeaderSearchInfo().getModuleMap().getModuleMapFileForUniquing(
+CurrentModule);

I think this should move inside the `if` below for `needsModules`.

We are checking the result of `getModuleMapFileForUniquing` for `nullptr` in 
ModuleDepCollector.cpp -- should we be doing the same here?  I find it hard to 
guess when it might be null, but there's no asserts that it won't be anywhere 
that I can find.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134222

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


[PATCH] D134243: Don't crash when code completing `using enum ^Foo`.

2022-09-19 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added a subscriber: kadircet.
Herald added a project: All.
sammccall requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134243

Files:
  clang/lib/Parse/ParseDecl.cpp
  clang/test/CodeCompletion/using-enum.cpp


Index: clang/test/CodeCompletion/using-enum.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/using-enum.cpp
@@ -0,0 +1,7 @@
+enum class AAA { X, Y, Z };
+
+namespace N2 {
+  using enum AAA;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:14 %s | FileCheck 
-check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: AAA
+};
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -4588,6 +4588,7 @@
 // Code completion for an enum name.
 cutOffParsing();
 Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum);
+DS.SetTypeSpecError();
 return;
   }
 


Index: clang/test/CodeCompletion/using-enum.cpp
===
--- /dev/null
+++ clang/test/CodeCompletion/using-enum.cpp
@@ -0,0 +1,7 @@
+enum class AAA { X, Y, Z };
+
+namespace N2 {
+  using enum AAA;
+  // RUN: %clang_cc1 -fsyntax-only -code-completion-at=%s:4:14 %s | FileCheck -check-prefix=CHECK-CC1 %s
+  // CHECK-CC1: COMPLETION: AAA
+};
Index: clang/lib/Parse/ParseDecl.cpp
===
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -4588,6 +4588,7 @@
 // Code completion for an enum name.
 cutOffParsing();
 Actions.CodeCompleteTag(getCurScope(), DeclSpec::TST_enum);
+DS.SetTypeSpecError();
 return;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134186: [Clang][OpenMP] Codegen generation for has_device_addr claues.

2022-09-19 Thread Ron Lieberman via Phabricator via cfe-commits
ronlieb added a comment.

seeing a buildbot failure on amdgpu bot
https://lab.llvm.org/buildbot/#/builders/193/builds/18788


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134186

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


[PATCH] D132711: [HLSL] add sqrt library function

2022-09-19 Thread Joshua Batista via Phabricator via cfe-commits
bob80905 updated this revision to Diff 461405.
bob80905 added a comment.

rebase
rebasing review to latest origin/main.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132711

Files:
  clang/test/CodeGenHLSL/builtins/sqrt.hlsl


Index: clang/test/CodeGenHLSL/builtins/sqrt.hlsl
===
--- clang/test/CodeGenHLSL/builtins/sqrt.hlsl
+++ clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   dxil-pc-shadermodel6.2-library %s -fnative-half-type \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
 
 double sqrt_d(double x)


Index: clang/test/CodeGenHLSL/builtins/sqrt.hlsl
===
--- clang/test/CodeGenHLSL/builtins/sqrt.hlsl
+++ clang/test/CodeGenHLSL/builtins/sqrt.hlsl
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   dxil-pc-shadermodel6.2-library %s -fnative-half-type \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 // RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   dxil-pc-shadermodel6.2-library %s -emit-llvm -disable-llvm-passes \
 // RUN:   -o - | FileCheck %s --check-prefix=NO_HALF
 
 double sqrt_d(double x)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2022-09-19 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 461403.
ayzhao added a comment.

remove extra blank line


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/drs/dr4xx.cpp
  clang/test/CXX/drs/dr5xx.cpp
  clang/test/CXX/temp/temp.res/p3.cpp
  clang/test/CXX/temp/temp.res/p4.cpp
  clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p1.cpp
  clang/test/FixIt/fixit.cpp
  clang/test/Parser/cxx-member-initializers.cpp
  clang/test/SemaCXX/MicrosoftCompatibility.cpp
  clang/test/SemaCXX/MicrosoftExtensions.cpp
  clang/test/SemaCXX/MicrosoftSuper.cpp
  clang/test/SemaCXX/rounding-math-crash.cpp
  clang/test/SemaCXX/typo-correction.cpp
  clang/test/SemaCXX/unknown-type-name.cpp
  clang/test/SemaTemplate/alias-templates.cpp
  clang/test/SemaTemplate/typename-specifier-3.cpp

Index: clang/test/SemaTemplate/typename-specifier-3.cpp
===
--- clang/test/SemaTemplate/typename-specifier-3.cpp
+++ clang/test/SemaTemplate/typename-specifier-3.cpp
@@ -28,7 +28,7 @@
   typedef int arg;
 };
 struct C {
-  typedef B::X x; // expected-error {{missing 'typename'}}
+  typedef B::X x; // precxx17-warning{{missing 'typename' prior to dependent type name B::X; implicit 'typename' is a C++20 extension}}
 };
   };
 
Index: clang/test/SemaTemplate/alias-templates.cpp
===
--- clang/test/SemaTemplate/alias-templates.cpp
+++ clang/test/SemaTemplate/alias-templates.cpp
@@ -193,11 +193,10 @@
   struct base {
 template  struct derived;
   };
-  // FIXME: The diagnostics here are terrible.
   template 
-  using derived = base::template derived; // expected-error {{expected a type}} expected-error {{expected ';'}}
+  using derived = base::template derived; // expected-warning {{missing 'typename'}}
   template 
-  using derived2 = ::PR16904::base::template derived; // expected-error {{expected a type}} expected-error {{expected ';'}}
+  using derived2 = ::PR16904::base::template derived; // expected-warning {{missing 'typename'}}
 }
 
 namespace PR14858 {
Index: clang/test/SemaCXX/unknown-type-name.cpp
===
--- clang/test/SemaCXX/unknown-type-name.cpp
+++ clang/test/SemaCXX/unknown-type-name.cpp
@@ -36,15 +36,15 @@
 
   static int n;
   static type m;
-  static int h(T::type, int); // expected-error{{missing 'typename'}}
-  static int h(T::type x, char); // expected-error{{missing 'typename'}}
+  static int h(T::type, int); // expected-warning{{implicit 'typename' is a C++20 extension}}
+  static int h(T::type x, char); // expected-warning{{implicit 'typename' is a C++20 extension}}
 };
 
 template
-A::type g(T t) { return t; } // expected-error{{missing 'typename'}}
+A::type g(T t) { return t; } // expected-warning{{implicit 'typename' is a C++20 extension}}
 
 template
-A::type A::f() { return type(); } // expected-error{{missing 'typename'}}
+A::type A::f() { return type(); } // expected-warning{{implicit 'typename' is a C++20 extension}}
 
 template
 void f(T::type) { } // expected-error{{missing 'typename'}}
@@ -84,11 +84,11 @@
 
 template int A::n(T::value); // ok
 template
-A::type // expected-error{{missing 'typename'}}
+A::type // expected-warning {{implicit 'typename' is a C++20 extension}}
 A::m(T::value, 0); // ok
 
-template int A::h(T::type, int) {} // expected-error{{missing 'typename'}}
-template int A::h(T::type x, char) {} // expected-error{{missing 'typename'}}
+template int A::h(T::type, int) {} // expected-warning{{implicit 'typename' is a C++20 extension}}
+template int A::h(T::type x, char) {} // expected-warning{{implicit 'typename' is a C++20 extension}}
 
 template int h(T::type, int); // expected-error{{missing 'typename'}}
 template int h(T::type x, char); // expected-error{{missing 'typename'}}
@@ -116,4 +116,5 @@
 // FIXME: We know which type specifier should have been specified here. Provide
 //a fix-it to add 'typename A::type'
 template
-A::g() { } // expected-error{{a type specifier is required}}
+A::g() { } // expected-error{{expected unqualified-id}}
+// expected-warning@-1{{implicit 'typename' is a C++20 extension}}
Index: clang/test/SemaCXX/typo-cor

[PATCH] D134235: [clang-doc] Clean up *Info constructors.

2022-09-19 Thread Brett Wilson via Phabricator via cfe-commits
brettw created this revision.
Herald added a project: All.
brettw requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

The *Info object (for the copy of the AST") constructors had many duplicated 
variants. Many of the variants seemed to be in an attempt to avoid default 
arguments. But default arguments are not prohibited and using them allows most 
of the variants to be removed which improves readability.

Remove the IsInGlobalNamespace flag on a Reference. This is set when the path 
is empty, and only read once in the HTML generator with the identical 
condition. The constructor cleanup exposed a problem where this was set to 
false when the constructor with no path was used, but true when the path was 
set to empty.

There should be no observable change with the exception that 
IsInGlobalNamespace is no longer emitted in YAML.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134235

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/Representation.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/BitcodeTest.cpp
  clang-tools-extra/unittests/clang-doc/GeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/HTMLGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/MDGeneratorTest.cpp
  clang-tools-extra/unittests/clang-doc/MergeTest.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -82,7 +82,7 @@
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
-  I.Members.emplace_back("int", "path/to/int", "X",
+  I.Members.emplace_back(TypeInfo("int", "path/to/int"), "X",
  AccessSpecifier::AS_private);
 
   // Member documentation.
@@ -102,7 +102,7 @@
AccessSpecifier::AS_public, true);
   I.Bases.back().ChildFunctions.emplace_back();
   I.Bases.back().ChildFunctions.back().Name = "InheritedFunctionOne";
-  I.Bases.back().Members.emplace_back("int", "path/to/int", "N",
+  I.Bases.back().Members.emplace_back(TypeInfo("int", "path/to/int"), "N",
   AccessSpecifier::AS_private);
   // F is in the global namespace
   I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record, "");
@@ -174,7 +174,6 @@
 Parents:
   - Type:Record
 Name:'F'
-IsInGlobalNamespace: true
 VirtualParents:
   - Type:Record
 Name:'G'
@@ -206,10 +205,10 @@
 
   I.Access = AccessSpecifier::AS_none;
 
-  I.ReturnType =
-  TypeInfo(EmptySID, "void", InfoType::IT_default, "path/to/void");
-  I.Params.emplace_back("int", "path/to/int", "P");
-  I.Params.emplace_back("double", "path/to/double", "D");
+  I.ReturnType = TypeInfo(
+  Reference(EmptySID, "void", InfoType::IT_default, "path/to/void"));
+  I.Params.emplace_back(TypeInfo("int", "path/to/int"), "P");
+  I.Params.emplace_back(TypeInfo("double", "path/to/double"), "D");
   I.Params.back().DefaultValue = "2.0 * M_PI";
   I.IsMethod = true;
   I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
@@ -335,9 +334,9 @@
   FunctionInfo I;
   I.Name = "f";
   I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
-  I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
-  I.Params.emplace_back("int", "I");
-  I.Params.emplace_back("int", "J");
+  I.ReturnType = TypeInfo("void");
+  I.Params.emplace_back(TypeInfo("int"), "I");
+  I.Params.emplace_back(TypeInfo("int"), "J");
   I.Access = AccessSpecifier::AS_none;
 
   CommentInfo Top;
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -119,7 +119,7 @@
   NamespaceInfo ExpectedBWithFunction(EmptySID);
   FunctionInfo F;
   F.Name = "f";
-  F.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  F.ReturnType = TypeInfo("void");
   F.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
   F.Namespace.emplace_back(EmptySID, "B", InfoType::IT_namespace);
   F.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -165,7 +165,8 @@
InfoType::IT_namespace);
   ExpectedE.TagType = TagTypeKind::TTK_Class;
   ExpectedE.DefLoc = Loc

[PATCH] D53847: [C++2a] P0634r3: Down with typename!

2022-09-19 Thread Alan Zhao via Phabricator via cfe-commits
ayzhao updated this revision to Diff 461401.
ayzhao added a comment.

fix typo


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D53847

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Parse/ParseTemplate.cpp
  clang/lib/Parse/ParseTentative.cpp
  clang/lib/Parse/Parser.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/basic/basic.lookup/basic.lookup.qual/class.qual/p2.cpp
  clang/test/CXX/drs/dr1xx.cpp
  clang/test/CXX/drs/dr2xx.cpp
  clang/test/CXX/drs/dr4xx.cpp
  clang/test/CXX/drs/dr5xx.cpp
  clang/test/CXX/temp/temp.res/p3.cpp
  clang/test/CXX/temp/temp.res/p4.cpp
  clang/test/CXX/temp/temp.res/temp.dep/temp.dep.type/p1.cpp
  clang/test/FixIt/fixit.cpp
  clang/test/Parser/cxx-member-initializers.cpp
  clang/test/SemaCXX/MicrosoftCompatibility.cpp
  clang/test/SemaCXX/MicrosoftExtensions.cpp
  clang/test/SemaCXX/MicrosoftSuper.cpp
  clang/test/SemaCXX/rounding-math-crash.cpp
  clang/test/SemaCXX/typo-correction.cpp
  clang/test/SemaCXX/unknown-type-name.cpp
  clang/test/SemaTemplate/alias-templates.cpp
  clang/test/SemaTemplate/typename-specifier-3.cpp

Index: clang/test/SemaTemplate/typename-specifier-3.cpp
===
--- clang/test/SemaTemplate/typename-specifier-3.cpp
+++ clang/test/SemaTemplate/typename-specifier-3.cpp
@@ -28,7 +28,7 @@
   typedef int arg;
 };
 struct C {
-  typedef B::X x; // expected-error {{missing 'typename'}}
+  typedef B::X x; // precxx17-warning{{missing 'typename' prior to dependent type name B::X; implicit 'typename' is a C++20 extension}}
 };
   };
 
Index: clang/test/SemaTemplate/alias-templates.cpp
===
--- clang/test/SemaTemplate/alias-templates.cpp
+++ clang/test/SemaTemplate/alias-templates.cpp
@@ -193,11 +193,10 @@
   struct base {
 template  struct derived;
   };
-  // FIXME: The diagnostics here are terrible.
   template 
-  using derived = base::template derived; // expected-error {{expected a type}} expected-error {{expected ';'}}
+  using derived = base::template derived; // expected-warning {{missing 'typename'}}
   template 
-  using derived2 = ::PR16904::base::template derived; // expected-error {{expected a type}} expected-error {{expected ';'}}
+  using derived2 = ::PR16904::base::template derived; // expected-warning {{missing 'typename'}}
 }
 
 namespace PR14858 {
Index: clang/test/SemaCXX/unknown-type-name.cpp
===
--- clang/test/SemaCXX/unknown-type-name.cpp
+++ clang/test/SemaCXX/unknown-type-name.cpp
@@ -36,15 +36,15 @@
 
   static int n;
   static type m;
-  static int h(T::type, int); // expected-error{{missing 'typename'}}
-  static int h(T::type x, char); // expected-error{{missing 'typename'}}
+  static int h(T::type, int); // expected-warning{{implicit 'typename' is a C++20 extension}}
+  static int h(T::type x, char); // expected-warning{{implicit 'typename' is a C++20 extension}}
 };
 
 template
-A::type g(T t) { return t; } // expected-error{{missing 'typename'}}
+A::type g(T t) { return t; } // expected-warning{{implicit 'typename' is a C++20 extension}}
 
 template
-A::type A::f() { return type(); } // expected-error{{missing 'typename'}}
+A::type A::f() { return type(); } // expected-warning{{implicit 'typename' is a C++20 extension}}
 
 template
 void f(T::type) { } // expected-error{{missing 'typename'}}
@@ -84,11 +84,11 @@
 
 template int A::n(T::value); // ok
 template
-A::type // expected-error{{missing 'typename'}}
+A::type // expected-warning {{implicit 'typename' is a C++20 extension}}
 A::m(T::value, 0); // ok
 
-template int A::h(T::type, int) {} // expected-error{{missing 'typename'}}
-template int A::h(T::type x, char) {} // expected-error{{missing 'typename'}}
+template int A::h(T::type, int) {} // expected-warning{{implicit 'typename' is a C++20 extension}}
+template int A::h(T::type x, char) {} // expected-warning{{implicit 'typename' is a C++20 extension}}
 
 template int h(T::type, int); // expected-error{{missing 'typename'}}
 template int h(T::type x, char); // expected-error{{missing 'typename'}}
@@ -116,4 +116,5 @@
 // FIXME: We know which type specifier should have been specified here. Provide
 //a fix-it to add 'typename A::type'
 template
-A::g() { } // expected-error{{a type specifier is required}}
+A::g() { } // expected-error{{expected unqualified-id}}
+// expected-warning@-1{{implicit 'typename' is a C++20 extension}}
Index: clang/test/SemaCXX/typo-correction.cpp
===

[PATCH] D134225: [clang-doc] Centralize TypeInfo creation.

2022-09-19 Thread Brett Wilson via Phabricator via cfe-commits
brettw updated this revision to Diff 461397.
brettw marked an inline comment as done.
brettw added a comment.

Comment addressed


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

https://reviews.llvm.org/D134225

Files:
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp

Index: clang-tools-extra/clang-doc/Serialize.cpp
===
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -224,12 +224,35 @@
   return hashUSR(USR);
 }
 
-static RecordDecl *getDeclForType(const QualType &T) {
+static TagDecl *getTagDeclForType(const QualType &T) {
+  if (const TagDecl *D = T->getAsTagDecl())
+return D->getDefinition();
+  return nullptr;
+}
+
+static RecordDecl *getRecordDeclForType(const QualType &T) {
   if (const RecordDecl *D = T->getAsRecordDecl())
 return D->getDefinition();
   return nullptr;
 }
 
+TypeInfo getTypeInfoForType(const QualType &T) {
+  const TagDecl *TD = getTagDeclForType(T);
+  if (!TD)
+return TypeInfo(Reference(T.getAsString()));
+
+  InfoType IT;
+  if (dyn_cast(TD)) {
+IT = InfoType::IT_enum;
+  } else if (dyn_cast(TD)) {
+IT = InfoType::IT_record;
+  } else {
+IT = InfoType::IT_default;
+  }
+  return TypeInfo(Reference(getUSRForDecl(TD), TD->getNameAsString(), IT,
+getInfoRelativePath(TD)));
+}
+
 static bool isPublic(const clang::AccessSpecifier AS,
  const clang::Linkage Link) {
   if (AS == clang::AccessSpecifier::AS_private)
@@ -286,28 +309,14 @@
   for (const FieldDecl *F : D->fields()) {
 if (!shouldSerializeInfo(PublicOnly, /*IsInAnonymousNamespace=*/false, F))
   continue;
-if (const auto *T = getDeclForType(F->getTypeSourceInfo()->getType())) {
-  // Use getAccessUnsafe so that we just get the default AS_none if it's not
-  // valid, as opposed to an assert.
-  if (const auto *N = dyn_cast(T)) {
-I.Members.emplace_back(
-getUSRForDecl(T), N->getNameAsString(), InfoType::IT_enum,
-getInfoRelativePath(N), F->getNameAsString(),
-getFinalAccessSpecifier(Access, N->getAccessUnsafe()));
-continue;
-  } else if (const auto *N = dyn_cast(T)) {
-I.Members.emplace_back(
-getUSRForDecl(T), N->getNameAsString(), InfoType::IT_record,
-getInfoRelativePath(N), F->getNameAsString(),
-getFinalAccessSpecifier(Access, N->getAccessUnsafe()));
-continue;
-  }
-}
 
-auto& member = I.Members.emplace_back(
-F->getTypeSourceInfo()->getType().getAsString(), F->getNameAsString(),
+// Use getAccessUnsafe so that we just get the default AS_none if it's not
+// valid, as opposed to an assert.
+MemberTypeInfo &NewMember = I.Members.emplace_back(
+getTypeInfoForType(F->getTypeSourceInfo()->getType()),
+F->getNameAsString(),
 getFinalAccessSpecifier(Access, F->getAccessUnsafe()));
-populateMemberTypeInfo(member, F);
+populateMemberTypeInfo(NewMember, F);
   }
 }
 
@@ -325,27 +334,11 @@
 
 static void parseParameters(FunctionInfo &I, const FunctionDecl *D) {
   for (const ParmVarDecl *P : D->parameters()) {
-FieldTypeInfo *FieldInfo = nullptr;
-if (const auto *T = getDeclForType(P->getOriginalType())) {
-  if (const auto *N = dyn_cast(T)) {
-FieldInfo = &I.Params.emplace_back(
-getUSRForDecl(N), N->getNameAsString(), InfoType::IT_enum,
-getInfoRelativePath(N), P->getNameAsString());
-  } else if (const auto *N = dyn_cast(T)) {
-FieldInfo = &I.Params.emplace_back(
-getUSRForDecl(N), N->getNameAsString(), InfoType::IT_record,
-getInfoRelativePath(N), P->getNameAsString());
-  }
-  // Otherwise fall through to the default case below.
-}
-
-if (!FieldInfo) {
-  FieldInfo = &I.Params.emplace_back(P->getOriginalType().getAsString(),
- P->getNameAsString());
-}
+FieldTypeInfo &FieldInfo = I.Params.emplace_back(
+getTypeInfoForType(P->getOriginalType()), P->getNameAsString());
 
 if (const Expr *DefaultArg = P->getDefaultArg()) {
-  FieldInfo->DefaultValue = getSourceCode(D, DefaultArg->getSourceRange());
+  FieldInfo.DefaultValue = getSourceCode(D, DefaultArg->getSourceRange());
 }
   }
 }
@@ -363,14 +356,14 @@
   const TemplateDecl *D = Ty->getTemplateName().getAsTemplateDecl();
   I.Parents.emplace_back(getUSRForDecl(D), B.getType().getAsString(),
  InfoType::IT_record);
-} else if (const RecordDecl *P = getDeclForType(B.getType()))
+} else if (const RecordDecl *P = getRecordDeclForType(B.getType()))
   I.Parents.emplace_back(getUSRForDecl(P), P->getNameAsString(),
  InfoType::IT_record, getInfoRelativePath(P));
 else
   I.Parents.emplace_back(B.g

[PATCH] D134233: [clang-format] Wrap inserted braces only if preceded by comments

2022-09-19 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, HazardyKnusperkeks, curdeius.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134233

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25388,6 +25388,12 @@
"} while (0);",
Style);
 
+  Style.RemoveBracesLLVM = true;
+  verifyFormat("if (a) //\n"
+   "  return b;",
+   Style);
+  Style.RemoveBracesLLVM = false;
+
   Style.ColumnLimit = 15;
 
   verifyFormat("#define A \\\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1871,7 +1871,7 @@
 std::string Brace;
 if (Token->BraceCount < 0) {
   assert(Token->BraceCount == -1);
-  Brace = "\n{";
+  Brace = Token->is(tok::comment) ? "\n{" : "{";
 } else {
   Brace = '\n' + std::string(Token->BraceCount, '}');
 }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25388,6 +25388,12 @@
"} while (0);",
Style);
 
+  Style.RemoveBracesLLVM = true;
+  verifyFormat("if (a) //\n"
+   "  return b;",
+   Style);
+  Style.RemoveBracesLLVM = false;
+
   Style.ColumnLimit = 15;
 
   verifyFormat("#define A \\\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1871,7 +1871,7 @@
 std::string Brace;
 if (Token->BraceCount < 0) {
   assert(Token->BraceCount == -1);
-  Brace = "\n{";
+  Brace = Token->is(tok::comment) ? "\n{" : "{";
 } else {
   Brace = '\n' + std::string(Token->BraceCount, '}');
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2022-09-19 Thread Ed Catmur via Phabricator via cfe-commits
ecatmur created this revision.
ecatmur added a reviewer: clang-language-wg.
Herald added subscribers: ChuanqiXu, JDevlieghere.
Herald added a project: All.
ecatmur requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- p0960 Allow initializing aggregates from a parenthesized list of values
- p1975 Fixing the wording of parenthesized aggregate-initialization

Follows gcc for the most part, except for coroutines (cf. 
https://cpplang.slack.com/archives/CBTFTLR9R/p1657730176797929)

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

In competition with https://reviews.llvm.org/D129531, sorry - I got frustrated 
waiting.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134231

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Sema/Initialization.h
  clang/lib/Frontend/InitPreprocessor.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaCoroutine.cpp
  clang/lib/Sema/SemaExprCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
  clang/test/CXX/over/over.match/over.match.viable/p3.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p4.cpp
  clang/test/Lexer/cxx-features.cpp
  clang/test/SemaCXX/cxx20-p0960-aggregate-paren-init.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp

Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- clang/test/SemaCXX/cxx2a-explicit-bool.cpp
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -30,6 +30,9 @@
 A<-1> a(0);
 // expected-error@-1 {{no matching constructor}}
 // expected-note@-2 {{in instantiation of template class}}
+#if __cpp_aggregate_paren_init >= 201902
+// expected-note@-4{{candidate aggregate parenthesis initializer not viable}}
+#endif
 
 template
 struct B {
Index: clang/test/SemaCXX/cxx20-p0960-aggregate-paren-init.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx20-p0960-aggregate-paren-init.cpp
@@ -0,0 +1,239 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// RUN: %clang_cc1 -std=c++17 -verify %s
+
+// p0960 Allow initializing aggregates from a parenthesized list of values
+// p1975 Fixing the wording of parenthesized aggregate-initialization
+// class.temporary/6
+// dcl.init/17.5, 17.6
+
+#if __cplusplus >= 202002 && __cpp_aggregate_paren_init < 201902
+#   error "should set __cpp_aggregate_paren_init in C++20 mode"
+#endif
+
+// definitions for std::move
+namespace std { template  T &&move(T &); }
+// definitions for std::is_constructible
+namespace std {
+template
+inline constexpr bool is_constructible_v = __is_constructible(T, A...);
+}
+
+int i1[](1, 2, 3);
+#if __cpp_aggregate_paren_init < 201902
+// expected-error@-2{{array initializer must be an initializer list}}
+#else
+static_assert(sizeof i1 == sizeof(int[3]));
+#endif
+
+int i2[2](1, 2, 3);
+#if __cpp_aggregate_paren_init < 201902
+// expected-error@-2{{array initializer must be an initializer list}}
+#else
+// expected-error@-4{{excess elements in array initializer}}
+#endif
+
+int i3[4](1, 2, 3);
+#if __cpp_aggregate_paren_init < 201902
+// expected-error@-2{{array initializer must be an initializer list}}
+#endif
+
+int i4[](1);
+#if __cpp_aggregate_paren_init < 201902
+// expected-error@-2{{array initializer must be an initializer list}}
+#else
+static_assert(sizeof i4 == sizeof(int[1]));
+#endif
+
+int *p1 = new int[](1, 2, 3);
+#if __cpp_aggregate_paren_init < 201902
+// expected-error@-2{{array 'new' cannot have initialization arguments}}
+#endif
+
+int *p2[2] = new int[2](1, 2, 3);
+#if __cpp_aggregate_paren_init < 201902
+// expected-error@-2{{array 'new' cannot have initialization arguments}}
+#else
+// expected-error@-4{{excess elements in array initializer}}
+#endif
+
+int *p3 = new int[4](1, 2, 3);
+#if __cpp_aggregate_paren_init < 201902
+// expected-error@-2{{array 'new' cannot have initialization arguments}}
+#endif
+
+struct E {
+#if __cpp_aggregate_paren_init >= 201902
+// expected-note@-2 +{{candidate constructor (the implicit copy constructor) not viable}}
+// expected-note@-3 +{{candidate constructor (the implicit move constructor) not viable}}
+#endif
+  E(int);
+#if __cpp_aggregate_paren_init >= 201902
+// expected-note@-2 +{{candidate constructor not viable: requires 1 argument, but 0 were provided}}
+#endif
+};
+
+E e1[3](1, 2, 3);
+#if __cpp_aggregate_paren_init < 201902
+// expected-error@-2{{array initializer must be an initializer list}}
+#endif
+
+E e2[4](1, 2, 3);
+#if __cpp_aggregate_paren_init < 201902
+// expected-error@-2{{array initializer must be an initializer list}}
+#else
+// expected-error@-4{{no matching constructor for initialization of 'E'}}
+// expected-note@-5{{in implicit initialization of array element 3 with omitted initializer}}
+#endif
+
+struct A {
+#if __cpp_aggregate_paren_init < 201902
+// expected-note@-2 +{{candidate constructor (the implicit copy constructor) no

[PATCH] D134225: [clang-doc] Centralize TypeInfo creation.

2022-09-19 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

Also, can you take a look at the premerge check failure? it looks like it had 
trouble applying your patch, so you may need to rebase.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134225

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


[PATCH] D134225: [clang-doc] Centralize TypeInfo creation.

2022-09-19 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth accepted this revision.
paulkirth added a comment.
This revision is now accepted and ready to land.

Thanks for the code cleanup. The patch is LGTM, with some small nits.




Comment at: clang-tools-extra/clang-doc/Serialize.cpp:240
+TypeInfo getTypeInfoForType(const QualType &T) {
+  if (const TagDecl *TD = getTagDeclForType(T)) {
+InfoType IT;

nit: can we invert this condition and use an early return to reduce nesting?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134225

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


[clang] 7349084 - [clang-format] Update removed brace's next token's WhitespaceRange

2022-09-19 Thread via cfe-commits

Author: owenca
Date: 2022-09-19T15:02:08-07:00
New Revision: 7349084e7afc55fc734922a9facd76316f2977b1

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

LOG: [clang-format] Update removed brace's next token's WhitespaceRange

Fixes #57803.

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

Added: 


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

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 58d5fc1f8c865..025e1aa977247 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1920,10 +1920,13 @@ class BracesRemover : public TokenAnalyzer {
 assert(Next || Token == Line->Last);
 if (!Next && NextLine)
   Next = NextLine->First;
-const auto Start =
-Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)
-? Token->Tok.getLocation()
-: Token->WhitespaceRange.getBegin();
+SourceLocation Start;
+if (Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
+  Start = Token->Tok.getLocation();
+  Next->WhitespaceRange = Token->WhitespaceRange;
+} else {
+  Start = Token->WhitespaceRange.getBegin();
+}
 const auto Range =
 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
 cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));

diff  --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 828948e8f5772..8999e590612e3 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -26006,6 +26006,17 @@ TEST_F(FormatTest, RemoveBraces) {
"}",
Style);
 
+  verifyFormat("while (0)\n"
+   "  if (a)\n"
+   "return b;\n"
+   "return a;",
+   "while (0) {\n"
+   "  if (a) {\n"
+   "return b;\n"
+   "}}\n"
+   "return a;",
+   Style);
+
   Style.ColumnLimit = 65;
   verifyFormat("if (condition) {\n"
"  ff(Indices,\n"



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


[PATCH] D134146: [clang-format] Update removed brace's next token's WhitespaceRange

2022-09-19 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7349084e7afc: [clang-format] Update removed brace's 
next token's WhitespaceRange (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134146

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -26006,6 +26006,17 @@
"}",
Style);
 
+  verifyFormat("while (0)\n"
+   "  if (a)\n"
+   "return b;\n"
+   "return a;",
+   "while (0) {\n"
+   "  if (a) {\n"
+   "return b;\n"
+   "}}\n"
+   "return a;",
+   Style);
+
   Style.ColumnLimit = 65;
   verifyFormat("if (condition) {\n"
"  ff(Indices,\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1920,10 +1920,13 @@
 assert(Next || Token == Line->Last);
 if (!Next && NextLine)
   Next = NextLine->First;
-const auto Start =
-Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)
-? Token->Tok.getLocation()
-: Token->WhitespaceRange.getBegin();
+SourceLocation Start;
+if (Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
+  Start = Token->Tok.getLocation();
+  Next->WhitespaceRange = Token->WhitespaceRange;
+} else {
+  Start = Token->WhitespaceRange.getBegin();
+}
 const auto Range =
 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
 cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -26006,6 +26006,17 @@
"}",
Style);
 
+  verifyFormat("while (0)\n"
+   "  if (a)\n"
+   "return b;\n"
+   "return a;",
+   "while (0) {\n"
+   "  if (a) {\n"
+   "return b;\n"
+   "}}\n"
+   "return a;",
+   Style);
+
   Style.ColumnLimit = 65;
   verifyFormat("if (condition) {\n"
"  ff(Indices,\n"
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1920,10 +1920,13 @@
 assert(Next || Token == Line->Last);
 if (!Next && NextLine)
   Next = NextLine->First;
-const auto Start =
-Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)
-? Token->Tok.getLocation()
-: Token->WhitespaceRange.getBegin();
+SourceLocation Start;
+if (Next && Next->NewlinesBefore == 0 && Next->isNot(tok::eof)) {
+  Start = Token->Tok.getLocation();
+  Next->WhitespaceRange = Token->WhitespaceRange;
+} else {
+  Start = Token->WhitespaceRange.getBegin();
+}
 const auto Range =
 CharSourceRange::getCharRange(Start, Token->Tok.getEndLoc());
 cantFail(Result.add(tooling::Replacement(SourceMgr, Range, "")));
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134055: [clang-doc] Add support for explicitly typed enums

2022-09-19 Thread Paul Kirth 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 rGeaa7b324d5a2: [clang-doc] Add support for explicitly typed 
enums (authored by brettw, committed by paulkirth).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134055

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -256,7 +256,11 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
-TEST(YAMLGeneratorTest, emitEnumYAML) {
+// Tests the equivalent of:
+// namespace A {
+// enum e { X };
+// }
+TEST(YAMLGeneratorTest, emitSimpleEnumYAML) {
   EnumInfo I;
   I.Name = "e";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -265,7 +269,7 @@
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   I.Members.emplace_back("X");
-  I.Scoped = true;
+  I.Scoped = false;
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -286,9 +290,42 @@
 Location:
   - LineNumber:  12
 Filename:'test.cpp'
+Members:
+  - Name:'X'
+Value:   '0'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+// Tests the equivalent of:
+// enum class e : short { X = FOO_BAR + 2 };
+TEST(YAMLGeneratorTest, enumTypedScopedEnumYAML) {
+  EnumInfo I;
+  I.Name = "e";
+
+  I.Members.emplace_back("X", "-9876", "FOO_BAR + 2");
+  I.Scoped = true;
+  I.BaseType = TypeInfo("short");
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'e'
 Scoped:  true
+BaseType:
+  Type:
+Name:'short'
 Members:
-  - 'X'
+  - Name:'X'
+Value:   '-9876'
+Expr:'FOO_BAR + 2'
 ...
 )raw";
   EXPECT_EQ(Expected, Actual.str());
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -266,8 +266,8 @@
   EnumInfo E;
   E.Name = "E";
   E.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  E.Members.emplace_back("X");
-  E.Members.emplace_back("Y");
+  E.Members.emplace_back("X", "0");
+  E.Members.emplace_back("Y", "1");
   ExpectedNamespaceWithEnum.ChildEnums.emplace_back(std::move(E));
   CheckNamespaceInfo(&ExpectedNamespaceWithEnum, NamespaceWithEnum);
 
@@ -277,8 +277,8 @@
   G.Name = "G";
   G.Scoped = true;
   G.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  G.Members.emplace_back("A");
-  G.Members.emplace_back("B");
+  G.Members.emplace_back("A", "0");
+  G.Members.emplace_back("B", "1");
   ExpectedNamespaceWithScopedEnum.ChildEnums.emplace_back(std::move(G));
   CheckNamespaceInfo(&ExpectedNamespaceWithScopedEnum, NamespaceWithScopedEnum);
 }
Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -14,6 +14,7 @@
 
 using namespace clang::doc;
 
+// These define YAML traits for decoding the listed values within a vector.
 LLVM_YAML_IS_SEQUENCE_VECTOR(FieldTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(MemberTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(Reference)
@@ -21,6 +22,7 @@
 LLVM_YAML_IS_SEQUENCE_VECTOR(CommentInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(EnumInfo)
+LLVM_YAML_IS_SEQUENCE_VECTOR(EnumValueInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(BaseRecordInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr)
 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::SmallString<16>)
@@ -226,10 +228,19 @@
   }
 };
 
+template <> struct MappingTraits {
+  static void mapping(IO &IO, EnumValueInfo &I) {
+IO.mapOptional("Name", I.Name);
+IO.mapOptional("Value", I.Value);
+IO.mapOptional("Expr", I.ValueExpr, SmallString<16>());
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, EnumInfo &I) {
 SymbolInfoMapping(IO, I);
 

[clang-tools-extra] eaa7b32 - [clang-doc] Add support for explicitly typed enums

2022-09-19 Thread Paul Kirth via cfe-commits

Author: Brett Wilson
Date: 2022-09-19T21:54:41Z
New Revision: eaa7b324d5a272dc640cfc4162b746ac5341ccbd

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

LOG: [clang-doc] Add support for explicitly typed enums

Add support for explicitly typed enums:
  enum Foo : unsigned { ... };
to the internal representation and to the YAML output.

Add support for getting the value of an enum constant, as well as accessing the 
original expression that produced it. This changes the YAML output of enums 
from an array of strings for the enum members to an array of dictionaries. 
These dictionaries now report the name, value, and original expression.

The markdown and HTML outputs are unchanged, they still output the name from 
the new enhanced internal schema.

Reviewed By: paulkirth

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

Added: 


Modified: 
clang-tools-extra/clang-doc/BitcodeReader.cpp
clang-tools-extra/clang-doc/BitcodeWriter.cpp
clang-tools-extra/clang-doc/BitcodeWriter.h
clang-tools-extra/clang-doc/HTMLGenerator.cpp
clang-tools-extra/clang-doc/MDGenerator.cpp
clang-tools-extra/clang-doc/Representation.h
clang-tools-extra/clang-doc/Serialize.cpp
clang-tools-extra/clang-doc/YAMLGenerator.cpp
clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-doc/BitcodeReader.cpp 
b/clang-tools-extra/clang-doc/BitcodeReader.cpp
index 7736e3d14516e..da7f6246b0292 100644
--- a/clang-tools-extra/clang-doc/BitcodeReader.cpp
+++ b/clang-tools-extra/clang-doc/BitcodeReader.cpp
@@ -17,12 +17,19 @@ namespace doc {
 
 using Record = llvm::SmallVector;
 
+// This implements decode for SmallString.
 llvm::Error decodeRecord(const Record &R, llvm::SmallVectorImpl &Field,
  llvm::StringRef Blob) {
   Field.assign(Blob.begin(), Blob.end());
   return llvm::Error::success();
 }
 
+llvm::Error decodeRecord(const Record &R, std::string &Field,
+ llvm::StringRef Blob) {
+  Field.assign(Blob.begin(), Blob.end());
+  return llvm::Error::success();
+}
+
 llvm::Error decodeRecord(const Record &R, SymbolID &Field,
  llvm::StringRef Blob) {
   if (R[0] != BitCodeConstants::USRHashSize)
@@ -218,8 +225,6 @@ llvm::Error parseRecord(const Record &R, unsigned ID, 
llvm::StringRef Blob,
 return decodeRecord(R, I->DefLoc, Blob);
   case ENUM_LOCATION:
 return decodeRecord(R, I->Loc, Blob);
-  case ENUM_MEMBER:
-return decodeRecord(R, I->Members, Blob);
   case ENUM_SCOPED:
 return decodeRecord(R, I->Scoped, Blob);
   default:
@@ -228,6 +233,21 @@ llvm::Error parseRecord(const Record &R, unsigned ID, 
llvm::StringRef Blob,
   }
 }
 
+llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
+EnumValueInfo *I) {
+  switch (ID) {
+  case ENUM_VALUE_NAME:
+return decodeRecord(R, I->Name, Blob);
+  case ENUM_VALUE_VALUE:
+return decodeRecord(R, I->Value, Blob);
+  case ENUM_VALUE_EXPR:
+return decodeRecord(R, I->ValueExpr, Blob);
+  default:
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "invalid field for EnumValueInfo");
+  }
+}
+
 llvm::Error parseRecord(const Record &R, unsigned ID, llvm::StringRef Blob,
 FunctionInfo *I) {
   switch (ID) {
@@ -372,6 +392,9 @@ llvm::Expected 
getCommentInfo(std::unique_ptr &I) {
   return getCommentInfo(I.get());
 }
 
+// When readSubBlock encounters a TypeInfo sub-block, it calls addTypeInfo on
+// the parent block to set it. The template specializations define what to do
+// for each supported parent block.
 template 
 llvm::Error addTypeInfo(T I, TTypeInfo &&TI) {
   return llvm::createStringError(llvm::inconvertibleErrorCode(),
@@ -398,6 +421,11 @@ template <> llvm::Error addTypeInfo(FunctionInfo *I, 
FieldTypeInfo &&T) {
   return llvm::Error::success();
 }
 
+template <> llvm::Error addTypeInfo(EnumInfo *I, TypeInfo &&T) {
+  I->BaseType = std::move(T);
+  return llvm::Error::success();
+}
+
 template  llvm::Error addReference(T I, Reference &&R, FieldId F) {
   return llvm::createStringError(llvm::inconvertibleErrorCode(),
  "invalid type cannot contain Reference");
@@ -524,6 +552,10 @@ template <> void addChild(RecordInfo *I, EnumInfo &&R) {
   I->ChildEnums.emplace_back(std::move(R));
 }
 
+template <> void addChild(EnumInfo *I, EnumValueInfo &&R) {
+  I->Members.emplace_back(std::move(R));
+}
+
 template <> void addChild(RecordInfo *I, BaseRecordInfo &&R) {
   I->Bases.emplace_back(std::move(R));
 }
@@ -587,8 +619,7 @@ llvm::Error ClangDocBitcodeReader::readBlock(unsigned ID

[PATCH] D134208: [clang] [Driver] Do not transform explicit --config filename

2022-09-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay accepted this revision.
MaskRay added a comment.
This revision is now accepted and ready to land.

Thanks!


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

https://reviews.llvm.org/D134208

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


[PATCH] D134055: [clang-doc] Add support for explicitly typed enums

2022-09-19 Thread Brett Wilson via Phabricator via cfe-commits
brettw updated this revision to Diff 461366.
brettw added a comment.

Clang-formatted


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

https://reviews.llvm.org/D134055

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -256,7 +256,11 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
-TEST(YAMLGeneratorTest, emitEnumYAML) {
+// Tests the equivalent of:
+// namespace A {
+// enum e { X };
+// }
+TEST(YAMLGeneratorTest, emitSimpleEnumYAML) {
   EnumInfo I;
   I.Name = "e";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -265,7 +269,7 @@
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   I.Members.emplace_back("X");
-  I.Scoped = true;
+  I.Scoped = false;
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -286,9 +290,42 @@
 Location:
   - LineNumber:  12
 Filename:'test.cpp'
+Members:
+  - Name:'X'
+Value:   '0'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+// Tests the equivalent of:
+// enum class e : short { X = FOO_BAR + 2 };
+TEST(YAMLGeneratorTest, enumTypedScopedEnumYAML) {
+  EnumInfo I;
+  I.Name = "e";
+
+  I.Members.emplace_back("X", "-9876", "FOO_BAR + 2");
+  I.Scoped = true;
+  I.BaseType = TypeInfo("short");
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'e'
 Scoped:  true
+BaseType:
+  Type:
+Name:'short'
 Members:
-  - 'X'
+  - Name:'X'
+Value:   '-9876'
+Expr:'FOO_BAR + 2'
 ...
 )raw";
   EXPECT_EQ(Expected, Actual.str());
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -266,8 +266,8 @@
   EnumInfo E;
   E.Name = "E";
   E.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  E.Members.emplace_back("X");
-  E.Members.emplace_back("Y");
+  E.Members.emplace_back("X", "0");
+  E.Members.emplace_back("Y", "1");
   ExpectedNamespaceWithEnum.ChildEnums.emplace_back(std::move(E));
   CheckNamespaceInfo(&ExpectedNamespaceWithEnum, NamespaceWithEnum);
 
@@ -277,8 +277,8 @@
   G.Name = "G";
   G.Scoped = true;
   G.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  G.Members.emplace_back("A");
-  G.Members.emplace_back("B");
+  G.Members.emplace_back("A", "0");
+  G.Members.emplace_back("B", "1");
   ExpectedNamespaceWithScopedEnum.ChildEnums.emplace_back(std::move(G));
   CheckNamespaceInfo(&ExpectedNamespaceWithScopedEnum, NamespaceWithScopedEnum);
 }
Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -14,6 +14,7 @@
 
 using namespace clang::doc;
 
+// These define YAML traits for decoding the listed values within a vector.
 LLVM_YAML_IS_SEQUENCE_VECTOR(FieldTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(MemberTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(Reference)
@@ -21,6 +22,7 @@
 LLVM_YAML_IS_SEQUENCE_VECTOR(CommentInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(EnumInfo)
+LLVM_YAML_IS_SEQUENCE_VECTOR(EnumValueInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(BaseRecordInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr)
 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::SmallString<16>)
@@ -226,10 +228,19 @@
   }
 };
 
+template <> struct MappingTraits {
+  static void mapping(IO &IO, EnumValueInfo &I) {
+IO.mapOptional("Name", I.Name);
+IO.mapOptional("Value", I.Value);
+IO.mapOptional("Expr", I.ValueExpr, SmallString<16>());
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, EnumInfo &I) {
 SymbolInfoMapping(IO, I);
 IO.mapOptional("Scoped", I.Scoped, false);
+IO.mapOptional("BaseType", I.BaseType);
 IO.mapOptional("Members", I.Members);
   }
 };
Index: clang-tools-extra/clang-doc/Serialize.cpp

[PATCH] D134225: [clang-doc] Centralize TypeInfo creation.

2022-09-19 Thread Brett Wilson via Phabricator via cfe-commits
brettw created this revision.
brettw added a reviewer: paulkirth.
brettw added a project: clang-tools-extra.
Herald added a project: All.
brettw requested review of this revision.
Herald added a subscriber: cfe-commits.

Several different places in the code had similar computations for the 
parameters that were eventually passed to the TypeInfo constructor.

  

This centralizes that code in one function, and allows passing TypeInfo to the 
various other *Info structures that need it.

  

Remove some "auto" types and replace with the real type for getting 
declarations. This was making some duplicate checking difficult to see.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134225

Files:
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp

Index: clang-tools-extra/clang-doc/Serialize.cpp
===
--- clang-tools-extra/clang-doc/Serialize.cpp
+++ clang-tools-extra/clang-doc/Serialize.cpp
@@ -224,12 +224,34 @@
   return hashUSR(USR);
 }
 
-static RecordDecl *getDeclForType(const QualType &T) {
+static TagDecl *getTagDeclForType(const QualType &T) {
+  if (const TagDecl *D = T->getAsTagDecl())
+return D->getDefinition();
+  return nullptr;
+}
+
+static RecordDecl *getRecordDeclForType(const QualType &T) {
   if (const RecordDecl *D = T->getAsRecordDecl())
 return D->getDefinition();
   return nullptr;
 }
 
+TypeInfo getTypeInfoForType(const QualType &T) {
+  if (const TagDecl *TD = getTagDeclForType(T)) {
+InfoType IT;
+if (dyn_cast(TD)) {
+  IT = InfoType::IT_enum;
+} else if (dyn_cast(TD)) {
+  IT = InfoType::IT_record;
+} else {
+  IT = InfoType::IT_default;
+}
+return TypeInfo(Reference(getUSRForDecl(TD), TD->getNameAsString(),
+  IT, getInfoRelativePath(TD)));
+  }
+  return TypeInfo(Reference(T.getAsString()));
+}
+
 static bool isPublic(const clang::AccessSpecifier AS,
  const clang::Linkage Link) {
   if (AS == clang::AccessSpecifier::AS_private)
@@ -286,28 +308,14 @@
   for (const FieldDecl *F : D->fields()) {
 if (!shouldSerializeInfo(PublicOnly, /*IsInAnonymousNamespace=*/false, F))
   continue;
-if (const auto *T = getDeclForType(F->getTypeSourceInfo()->getType())) {
-  // Use getAccessUnsafe so that we just get the default AS_none if it's not
-  // valid, as opposed to an assert.
-  if (const auto *N = dyn_cast(T)) {
-I.Members.emplace_back(
-getUSRForDecl(T), N->getNameAsString(), InfoType::IT_enum,
-getInfoRelativePath(N), F->getNameAsString(),
-getFinalAccessSpecifier(Access, N->getAccessUnsafe()));
-continue;
-  } else if (const auto *N = dyn_cast(T)) {
-I.Members.emplace_back(
-getUSRForDecl(T), N->getNameAsString(), InfoType::IT_record,
-getInfoRelativePath(N), F->getNameAsString(),
-getFinalAccessSpecifier(Access, N->getAccessUnsafe()));
-continue;
-  }
-}
 
-auto& member = I.Members.emplace_back(
-F->getTypeSourceInfo()->getType().getAsString(), F->getNameAsString(),
+// Use getAccessUnsafe so that we just get the default AS_none if it's not
+// valid, as opposed to an assert.
+MemberTypeInfo &NewMember = I.Members.emplace_back(
+getTypeInfoForType(F->getTypeSourceInfo()->getType()),
+F->getNameAsString(),
 getFinalAccessSpecifier(Access, F->getAccessUnsafe()));
-populateMemberTypeInfo(member, F);
+populateMemberTypeInfo(NewMember, F);
   }
 }
 
@@ -325,27 +333,12 @@
 
 static void parseParameters(FunctionInfo &I, const FunctionDecl *D) {
   for (const ParmVarDecl *P : D->parameters()) {
-FieldTypeInfo *FieldInfo = nullptr;
-if (const auto *T = getDeclForType(P->getOriginalType())) {
-  if (const auto *N = dyn_cast(T)) {
-FieldInfo = &I.Params.emplace_back(
-getUSRForDecl(N), N->getNameAsString(), InfoType::IT_enum,
-getInfoRelativePath(N), P->getNameAsString());
-  } else if (const auto *N = dyn_cast(T)) {
-FieldInfo = &I.Params.emplace_back(
-getUSRForDecl(N), N->getNameAsString(), InfoType::IT_record,
-getInfoRelativePath(N), P->getNameAsString());
-  }
-  // Otherwise fall through to the default case below.
-}
-
-if (!FieldInfo) {
-  FieldInfo = &I.Params.emplace_back(P->getOriginalType().getAsString(),
- P->getNameAsString());
-}
+FieldTypeInfo& FieldInfo = I.Params.emplace_back(
+getTypeInfoForType(P->getOriginalType()),
+P->getNameAsString());
 
 if (const Expr *DefaultArg = P->getDefaultArg()) {
-  FieldInfo->DefaultValue = getSourceCode(D, DefaultArg->getSourceRange());
+  FieldInfo.DefaultValue = getSourceCode(D, DefaultArg->getSourceRange());
 }
   }
 }
@@ -363,14 +356,14 @@
   const Templa

[PATCH] D134224: [clang][modules][deps] Report modulemaps describing excluded headers

2022-09-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, Bigcheese, rsmith.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Module map files describing excluded headers do affect compilation. Track them 
in the compiler, serialize them into the PCM file and report them in the 
scanner.

Depends on D134222 .


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134224

Files:
  clang/include/clang/Lex/HeaderSearch.h
  clang/include/clang/Lex/ModuleMap.h
  clang/lib/Lex/HeaderSearch.cpp
  clang/lib/Lex/ModuleMap.cpp
  clang/lib/Serialization/ASTReader.cpp
  clang/lib/Serialization/ASTWriter.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-excluded-header.m

Index: clang/test/ClangScanDeps/modules-excluded-header.m
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-excluded-header.m
@@ -0,0 +1,54 @@
+// This test checks that we're reporting module maps affecting the compilation by describing excluded headers.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- frameworks/X.framework/Modules/module.modulemap
+framework module X {
+  umbrella header "X.h"
+  exclude header "Excluded.h"
+}
+//--- frameworks/X.framework/Headers/X.h
+//--- frameworks/X.framework/Headers/Excluded.h
+
+//--- mod/module.modulemap
+module Mod { header "Mod.h" }
+//--- mod/Mod.h
+#include 
+
+//--- tu.m
+@import Mod;
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.m",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -I DIR/mod -F DIR/frameworks -Werror=non-modular-include-in-module -c DIR/tu.m -o DIR/tu.m"
+}]
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK:  {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "clang-module-deps": [],
+// CHECK-NEXT:   "clang-modulemap-file": "[[PREFIX]]/mod/module.modulemap",
+// CHECK-NEXT:   "command-line": [
+// CHECK:  "-fmodule-map-file=[[PREFIX]]/frameworks/X.framework/Modules/module.modulemap"
+// CHECK-NOT:  "-fmodule-file={{.*}}"
+// CHECK:],
+// CHECK-NEXT:   "context-hash": "{{.*}}",
+// CHECK-NEXT:   "file-deps": [
+// CHECK:],
+// CHECK-NEXT:   "name": "Mod"
+// CHECK-NEXT: }
+// CHECK-NEXT:   ]
+// CHECK:  }
+
+// RUN: %deps-to-rsp %t/result.json --module-name=Mod > %t/Mod.cc1.rsp
+// RUN: %deps-to-rsp %t/result.json --tu-index=0 > %t/tu.rsp
+
+// RUN: %clang @%t/Mod.cc1.rsp
+// RUN: %clang @%t/tu.rsp
Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
===
--- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -396,52 +396,34 @@
 MDC.addFileDep(MD, IF.getFile()->getName());
   });
 
-  // We usually don't need to list the module map files of our dependencies when
-  // building a module explicitly: their semantics will be deserialized from PCM
-  // files.
-  //
-  // However, some module maps loaded implicitly during the dependency scan can
-  // describe anti-dependencies. That happens when this module, let's call it
-  // M1, is marked as '[no_undeclared_includes]' and tries to access a header
-  // "M2/M2.h" from another module, M2, but doesn't have a 'use M2;'
-  // declaration. The explicit build needs the module map for M2 so that it
-  // knows that textually including "M2/M2.h" is not allowed.
-  // E.g., '__has_include("M2/M2.h")' should return false, but without M2's
-  // module map the explicit build would return true.
-  //
-  // An alternative approach would be to tell the explicit build what its
-  // textual dependencies are, instead of having it re-discover its
-  // anti-dependencies. For example, we could create and use an `-ivfs-overlay`
-  // with `fall-through: false` that explicitly listed the dependencies.
-  // However, that's more complicated to implement and harder to reason about.
-  if (M->NoUndeclaredIncludes) {
-// We don't have a good way to determine which module map described the
-// anti-dependency (let alone what's the corresponding top-level module
-// map). We simply specify all the module maps in the order they were loaded
-// during the implicit build during scan.
-// TODO: Resolve this by serializing and only using Module::UndeclaredUses.
-MDC.ScanInstance.getASTReader()->visitTopLevelModuleMaps(
-*MF, [&](const FileEntry *FE) {
-  if (FE->getName().endswith("__inferred_module

[PATCH] D130130: [clang-tidy] Add an IgnoreMacros option to readability-avoid-const-params-in-decls

2022-09-19 Thread Thomas Etter via Phabricator via cfe-commits
thomasetter added a comment.

Friendly ping


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

https://reviews.llvm.org/D130130

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


[PATCH] D134128: Resubmit an implemention for constrained template template parameters [P0857R0 Part B]

2022-09-19 Thread Erich Keane via Phabricator via cfe-commits
erichkeane added a comment.

One test that i need to have (that might actually end up conflicting with the 
above mentioned), is a reproducer that has a `ClassTemplateDecl` that is its 
own friend.  So something like:

  template class C requires ...>
  struct S {
  template class C requires ...>
  friend struct S;
  };

And make sure that an instantiation still checks those correctly (that is, I 
don't expect any diagnostics).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134128

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


[clang] 368b683 - [Clang] Implement fix for DR2628

2022-09-19 Thread Roy Jacobson via cfe-commits

Author: Roy Jacobson
Date: 2022-09-20T00:07:41+03:00
New Revision: 368b6832de33b366d4eb155f940e7476daace6a8

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

LOG: [Clang] Implement fix for DR2628

Implement suggested fix for [[ https://cplusplus.github.io/CWG/issues/2628.html 
| DR2628. ]] Couldn't update the DR docs because there hasn't been a DR index 
since it was filed, but the tests still run in CI.

Note: I only transfer the constructor constraints, not the struct constraints. 
I think that's OK because the struct constraints are the same
for all constructors so they don't affect the overload resolution, and if they 
deduce to something that doesn't pass the constraints
we catch it anyway. So (hopefully) that should be more efficient without 
sacrificing correctness.

Closes:
https://github.com/llvm/llvm-project/issues/57646
https://github.com/llvm/llvm-project/issues/43829

Reviewed By: erichkeane

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

Added: 
clang/test/CXX/drs/dr26xx.cpp

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplate.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 2546142d2b3d7..96b0c7e363052 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -151,6 +151,10 @@ Bug Fixes
   `Issue 57369 `_
   `Issue 57643 `_
   `Issue 57793 `_
+- Respect constructor constraints during class template argument deduction 
(CTAD).
+  This is the suggested resolution to CWG DR2628.
+  `Issue 57646 `_
+  `Issue 43829 `_
 
 
 Improvements to Clang's diagnostics

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index e0f913e395771..2ab59e7a37c0d 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2445,6 +2445,8 @@ struct ConvertConstructorToDeductionGuideTransform {
   TInfo->getType(), TInfo, LocEnd, Ctor);
 Guide->setImplicit();
 Guide->setParams(Params);
+if (Ctor && Ctor->getTrailingRequiresClause())
+  Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
 for (auto *Param : Params)
   Param->setDeclContext(Guide);

diff  --git a/clang/test/CXX/drs/dr26xx.cpp b/clang/test/CXX/drs/dr26xx.cpp
new file mode 100644
index 0..1178cefa5bcdf
--- /dev/null
+++ b/clang/test/CXX/drs/dr26xx.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+
+namespace dr2628 { // dr2628: yes
+
+template 
+struct foo {
+  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete;
+};
+
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+  // expected-note@#DR2628_CTOR {{marked deleted here}}
+}
+
+}



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


[PATCH] D134145: [Clang] Implement fix for DR2628

2022-09-19 Thread Roy Jacobson 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 rG368b6832de33: [Clang] Implement fix for DR2628 (authored by 
royjacobson).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134145

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/drs/dr26xx.cpp


Index: clang/test/CXX/drs/dr26xx.cpp
===
--- /dev/null
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+
+namespace dr2628 { // dr2628: yes
+
+template 
+struct foo {
+  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete;
+};
+
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+  // expected-note@#DR2628_CTOR {{marked deleted here}}
+}
+
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2445,6 +2445,8 @@
   TInfo->getType(), TInfo, LocEnd, Ctor);
 Guide->setImplicit();
 Guide->setParams(Params);
+if (Ctor && Ctor->getTrailingRequiresClause())
+  Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
 for (auto *Param : Params)
   Param->setDeclContext(Guide);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -151,6 +151,10 @@
   `Issue 57369 `_
   `Issue 57643 `_
   `Issue 57793 `_
+- Respect constructor constraints during class template argument deduction 
(CTAD).
+  This is the suggested resolution to CWG DR2628.
+  `Issue 57646 `_
+  `Issue 43829 `_
 
 
 Improvements to Clang's diagnostics


Index: clang/test/CXX/drs/dr26xx.cpp
===
--- /dev/null
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+
+namespace dr2628 { // dr2628: yes
+
+template 
+struct foo {
+  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete;
+};
+
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+  // expected-note@#DR2628_CTOR {{marked deleted here}}
+}
+
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2445,6 +2445,8 @@
   TInfo->getType(), TInfo, LocEnd, Ctor);
 Guide->setImplicit();
 Guide->setParams(Params);
+if (Ctor && Ctor->getTrailingRequiresClause())
+  Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
 for (auto *Param : Params)
   Param->setDeclContext(Guide);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -151,6 +151,10 @@
   `Issue 57369 `_
   `Issue 57643 `_
   `Issue 57793 `_
+- Respect constructor constraints during class template argument deduction (CTAD).
+  This is the suggested resolution to CWG DR2628.
+  `Issue 57646 `_
+  `Issue 43829 `_
 
 
 Improvements to Clang's diagnostics
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134145: [Clang] Implement fix for DR2628

2022-09-19 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 461352.
royjacobson added a comment.

rebase on main


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134145

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/drs/dr26xx.cpp


Index: clang/test/CXX/drs/dr26xx.cpp
===
--- /dev/null
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+
+namespace dr2628 { // dr2628: yes
+
+template 
+struct foo {
+  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete;
+};
+
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+  // expected-note@#DR2628_CTOR {{marked deleted here}}
+}
+
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2445,6 +2445,8 @@
   TInfo->getType(), TInfo, LocEnd, Ctor);
 Guide->setImplicit();
 Guide->setParams(Params);
+if (Ctor && Ctor->getTrailingRequiresClause())
+  Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
 for (auto *Param : Params)
   Param->setDeclContext(Guide);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -151,6 +151,10 @@
   `Issue 57369 `_
   `Issue 57643 `_
   `Issue 57793 `_
+- Respect constructor constraints during class template argument deduction 
(CTAD).
+  This is the suggested resolution to CWG DR2628.
+  `Issue 57646 `_
+  `Issue 43829 `_
 
 
 Improvements to Clang's diagnostics


Index: clang/test/CXX/drs/dr26xx.cpp
===
--- /dev/null
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+
+namespace dr2628 { // dr2628: yes
+
+template 
+struct foo {
+  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete;
+};
+
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+  // expected-note@#DR2628_CTOR {{marked deleted here}}
+}
+
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2445,6 +2445,8 @@
   TInfo->getType(), TInfo, LocEnd, Ctor);
 Guide->setImplicit();
 Guide->setParams(Params);
+if (Ctor && Ctor->getTrailingRequiresClause())
+  Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
 for (auto *Param : Params)
   Param->setDeclContext(Guide);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -151,6 +151,10 @@
   `Issue 57369 `_
   `Issue 57643 `_
   `Issue 57793 `_
+- Respect constructor constraints during class template argument deduction (CTAD).
+  This is the suggested resolution to CWG DR2628.
+  `Issue 57646 `_
+  `Issue 43829 `_
 
 
 Improvements to Clang's diagnostics
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134145: [Clang] Implement fix for DR2628

2022-09-19 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson added inline comments.



Comment at: clang/test/CXX/drs/dr26xx.cpp:12
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+}

erichkeane wrote:
> 
That does look much nicer, thanks! I qualified it with DR2628 because the DR 
tests can get pretty large.



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134145

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


[PATCH] D134145: [Clang] Implement fix for DR2628

2022-09-19 Thread Roy Jacobson via Phabricator via cfe-commits
royjacobson updated this revision to Diff 461351.
royjacobson edited the summary of this revision.
royjacobson added a comment.

Add release note, slightly nicer test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134145

Files:
  clang/docs/ReleaseNotes.rst
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/CXX/drs/dr26xx.cpp


Index: clang/test/CXX/drs/dr26xx.cpp
===
--- /dev/null
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+
+namespace dr2628 { // dr2628: yes
+
+template 
+struct foo {
+  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete;
+};
+
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+  // expected-note@#DR2628_CTOR {{marked deleted here}}
+}
+
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2445,6 +2445,8 @@
   TInfo->getType(), TInfo, LocEnd, Ctor);
 Guide->setImplicit();
 Guide->setParams(Params);
+if (Ctor && Ctor->getTrailingRequiresClause())
+  Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
 for (auto *Param : Params)
   Param->setDeclContext(Guide);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -146,6 +146,10 @@
 - A SubstTemplateTypeParmType can now represent the pack index for a
   substitution from an expanded pack.
   `Issue 56099 `_
+- Respect constructor constraints during class template argument deduction 
(CTAD).
+  This is the suggested resolution to CWG DR2628.
+  `Issue 57646 `_
+  `Issue 43829 `_
 
 
 Improvements to Clang's diagnostics


Index: clang/test/CXX/drs/dr26xx.cpp
===
--- /dev/null
+++ clang/test/CXX/drs/dr26xx.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify
+
+namespace dr2628 { // dr2628: yes
+
+template 
+struct foo {
+  constexpr foo() requires (!A && !B) = delete; // #DR2628_CTOR
+  constexpr foo() requires (A || B) = delete;
+};
+
+void f() {
+  foo fooable; // expected-error {{call to deleted}}
+  // expected-note@#DR2628_CTOR {{marked deleted here}}
+}
+
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -2445,6 +2445,8 @@
   TInfo->getType(), TInfo, LocEnd, Ctor);
 Guide->setImplicit();
 Guide->setParams(Params);
+if (Ctor && Ctor->getTrailingRequiresClause())
+  Guide->setTrailingRequiresClause(Ctor->getTrailingRequiresClause());
 
 for (auto *Param : Params)
   Param->setDeclContext(Guide);
Index: clang/docs/ReleaseNotes.rst
===
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -146,6 +146,10 @@
 - A SubstTemplateTypeParmType can now represent the pack index for a
   substitution from an expanded pack.
   `Issue 56099 `_
+- Respect constructor constraints during class template argument deduction (CTAD).
+  This is the suggested resolution to CWG DR2628.
+  `Issue 57646 `_
+  `Issue 43829 `_
 
 
 Improvements to Clang's diagnostics
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134222: [clang][deps] Report module map describing compiled module

2022-09-19 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: benlangmuir, Bigcheese.
Herald added a subscriber: ributzka.
Herald added a project: All.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch fixes compilation failure with explicit modules caused by scanner 
not reporting the module map describing the module whose implementation is 
being compiled.

Below is a breakdown of the attached test case. Note the VFS that makes 
frameworks "A" and "B" share the same header "shared/H.h".

In non-modular build, Clang skips the last import, since the "shared/H.h" 
header has already been included.

During scan (or implicit build), the compiler handles "tu.m" as follows:

- `@import B` imports module "B", as expected,
- `#import ` is resolved textually (due to `-fmodule-name=A`) to 
"shared/H.h" (due to the VFS remapping),
- `#import ` is resolved to import module "A_Private", since the header 
"shared/H.h" is already known to be part of that module, and the import is 
skipped.

In the end, the only modular dependency of the TU is "B".

In explicit modular build without `-fmodule-name=A`, TU does depend on module 
"A_Private" properly, not just textually. Clang therefore builds & loads its 
PCM, and knows to ignore the last import, since "shared/H.h" is known to be 
part of "A_Private".

But with current scanner behavior and `-fmodule-name=A` present, the last 
import fails during explicit build. Clang doesn't know about "A_Private" (it's 
included textually) and tries to import "B_Private" instead, which it doesn't 
know about either (the scanner correctly didn't report it as dependency). This 
is fixed by reporting the module map describing "A" and matching the semantics 
of implicit build.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134222

Files:
  clang/include/clang/Basic/LangOptions.h
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/Preprocessor.cpp
  clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
  clang/test/ClangScanDeps/modules-header-sharing.m

Index: clang/test/ClangScanDeps/modules-header-sharing.m
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-header-sharing.m
@@ -0,0 +1,96 @@
+// There are some edge-cases where Clang depends on knowing the module whose implementation it's currently building.
+// This test makes sure scanner always reports the corresponding module map.
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+//--- frameworks/A.framework/Modules/module.modulemap
+framework module A { umbrella header "A.h" }
+//--- frameworks/B.framework/Modules/module.modulemap
+framework module B { umbrella header "B.h" }
+//--- frameworks/A.framework/Headers/A.h
+//--- frameworks/B.framework/Headers/B.h
+//--- frameworks/A.framework/Modules/module.private.modulemap
+framework module A_Private { umbrella header "A_Private.h" }
+//--- frameworks/B.framework/Modules/module.private.modulemap
+framework module B_Private { umbrella header "B_Private.h" }
+//--- frameworks/A.framework/PrivateHeaders/A_Private.h
+#import 
+//--- frameworks/B.framework/PrivateHeaders/B_Private.h
+#import 
+
+//--- shared/H.h
+
+//--- overlay.json.template
+{
+  "case-sensitive": "false",
+  "version": 0,
+  "roots": [
+{
+  "contents": [
+{
+  "external-contents": "DIR/shared/H.h",
+  "name": "H.h",
+  "type": "file"
+}
+  ],
+  "name": "DIR/frameworks/A.framework/PrivateHeaders",
+  "type": "directory"
+},
+{
+  "contents": [
+{
+  "external-contents": "DIR/shared/H.h",
+  "name": "H.h",
+  "type": "file"
+}
+  ],
+  "name": "DIR/frameworks/B.framework/PrivateHeaders",
+  "type": "directory"
+}
+  ]
+}
+
+//--- cdb.json.template
+[{
+  "file": "DIR/tu.m",
+  "directory": "DIR",
+  "command": "clang -fmodules -fmodules-cache-path=DIR/cache -fmodule-name=A -ivfsoverlay DIR/overlay.json -F DIR/frameworks -c DIR/tu.m -o DIR/tu.o"
+}]
+
+//--- tu.m
+@import B;
+#import 
+#import 
+
+// RUN: sed -e "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: sed -e "s|DIR|%/t|g" %t/overlay.json.template > %t/overlay.json
+
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json
+// RUN: cat %t/result.json | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+// CHECK:  {
+// CHECK:"translation-units": [
+// CHECK-NEXT: {
+// CHECK-NEXT:   "commands": [
+// CHECK-NEXT: {
+// CHECK:"command-line": [
+// CHECK:  "-fmodule-map-file=[[PREFIX]]/frameworks/A.framework/Modules/module.modulemap",
+// CHECK:  "-fmodule-name=A",
+// CHECK:],
+// CHECK-NEXT:   "executable": "clang",
+// CHECK-NEXT:   "file-deps": [
+// CHECK-NEXT: "[[PREFIX]]/tu.m",
+// CHECK-NEX

[PATCH] D134186: [Clang][OpenMP] Codegen generation for has_device_addr claues.

2022-09-19 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134186

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


[PATCH] D134207: [Clang] Support case and default labels at end of compound statement

2022-09-19 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 461347.
Izaron added a comment.

Fix corresponding FixIt clang test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134207

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseStmt.cpp
  clang/test/AST/ast-dump-stmt.c
  clang/test/C/C2x/n2508.c
  clang/test/FixIt/fixit.c
  clang/test/Parser/c2x-label.c
  clang/test/Parser/cxx2b-label.cpp
  clang/test/Parser/switch-recovery.cpp
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -763,13 +763,7 @@
 
   Free positioning of labels inside compound statements
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf";>N2508
-
-  Partial
-Clang supports labels at the end of compound statements but does
-not yet support case or default labels at
-the end of a switch statement's compound block.
-  
-
+  Clang 16
 
 
   Clarification request for C17 example of undefined behavior
Index: clang/test/Parser/switch-recovery.cpp
===
--- clang/test/Parser/switch-recovery.cpp
+++ clang/test/Parser/switch-recovery.cpp
@@ -160,15 +160,15 @@
 void missing_statement_case(int x) {
   switch (x) {
 case 1:
-case 0: // expected-error {{label at end of switch compound statement: expected statement}}
-  }
+case 0:
+  } // expected-warning {{label at end of compound statement is a C++2b extension}}
 }
 
 void missing_statement_default(int x) {
   switch (x) {
 case 0:
-default: // expected-error {{label at end of switch compound statement: expected statement}}
-  }
+default:
+  } // expected-warning {{label at end of compound statement is a C++2b extension}}
 }
 
 void pr19022_1() {
@@ -178,9 +178,8 @@
 
 void pr19022_1a(int x) {
   switch(x) {
-  case 1  // expected-error{{expected ':' after 'case'}} \
-  // expected-error{{label at end of switch compound statement: expected statement}}
-  }
+  case 1  // expected-error{{expected ':' after 'case'}}
+  } // expected-warning {{label at end of compound statement is a C++2b extension}}
 }
 
 void pr19022_1b(int x) {
@@ -210,9 +209,9 @@
 
 void pr19022_5(int x) {
   switch(x) {
-  case 1: case // expected-error{{expected ':' after 'case'}} \
-   // expected-error{{expected statement}}
-  }  // expected-error{{expected expression}}
+  case 1: case // expected-error{{expected ':' after 'case'}}
+  }  // expected-error{{expected expression}} \
+ // expected-warning {{label at end of compound statement is a C++2b extension}}
 }
 
 namespace pr19022 {
Index: clang/test/Parser/cxx2b-label.cpp
===
--- clang/test/Parser/cxx2b-label.cpp
+++ clang/test/Parser/cxx2b-label.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b -Wpre-c++2b-compat %s
 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
 
-void foo() {
+void test_label_in_func() {
 label1:
 int x;
 label2:
@@ -9,3 +9,23 @@
 label3: label4: label5:
 } // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
  cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
+
+int test_label_in_switch(int v) {
+switch (v) {
+case 1:
+return 1;
+case 2:
+return 2;
+case 3: case 4: case 5:
+} // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
+ cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
+
+switch (v) {
+case 6:
+return 6;
+default:
+} // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
+ cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
+
+return 0;
+}
Index: clang/test/Parser/c2x-label.c
===
--- clang/test/Parser/c2x-label.c
+++ clang/test/Parser/c2x-label.c
@@ -1,10 +1,30 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c17 -Wc2x-compat -verify=c17 %s
 // RUN: %clang_cc1 -fsyntax-only -std=c2x -Wpre-c2x-compat -verify=c2x %s
 
-void foo() {
+void test_label_in_func() {
 int x;
 label1:
 x = 1;
 label2: label3: label4:
 } // c17-warning {{label at end of compound statement is a C2x extension}} \
  c2x-warning {{label at end of compound statement is incompatible with C standards before C2x}}
+
+int test_label_in_switch(int v) {
+switch (v) {
+case 1:
+return 1;
+case 2:
+return 2;
+case 3: case 4: case 5:
+} // c17-warning {{label at end of compound statement is a C2x extension}} \

[PATCH] D133443: [RISCV][MC] Add support for experimental Zawrs extension

2022-09-19 Thread Philip Reames via Phabricator via cfe-commits
reames updated this revision to Diff 461345.

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

https://reviews.llvm.org/D133443

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

Index: llvm/test/MC/RISCV/attribute-arch.s
===
--- llvm/test/MC/RISCV/attribute-arch.s
+++ llvm/test/MC/RISCV/attribute-arch.s
@@ -197,5 +197,8 @@
 .attribute arch, "rv32izca0p70"
 # CHECK: attribute  5, "rv32i2p0_zca0p70"
 
+.attribute arch, "rv32izawrs1p0"
+# CHECK: attribute  5, "rv32i2p0_zawrs1p0"
+
 .attribute arch, "rv32iztso0p1"
 # CHECK: attribute  5, "rv32i2p0_ztso0p1"
Index: llvm/test/CodeGen/RISCV/attributes.ll
===
--- llvm/test/CodeGen/RISCV/attributes.ll
+++ llvm/test/CodeGen/RISCV/attributes.ll
@@ -84,6 +84,7 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbom %s -o - | FileCheck --check-prefix=RV64ZICBOM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicboz %s -o - | FileCheck --check-prefix=RV64ZICBOZ %s
 ; RUN: llc -mtriple=riscv64 -mattr=+zicbop %s -o - | FileCheck --check-prefix=RV64ZICBOP %s
+; RUN: llc -mtriple=riscv64 -mattr=+experimental-zawrs %s -o - | FileCheck --check-prefix=RV64ZAWRS %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ztso %s -o - | FileCheck --check-prefix=RV64ZTSO %s
 
 ; RV32M: .attribute 5, "rv32i2p0_m2p0"
@@ -170,6 +171,7 @@
 ; RV64COMBINEINTOZKS: .attribute 5, "rv64i2p0_zbkb1p0_zbkc1p0_zbkx1p0_zks1p0_zksed1p0_zksh1p0"
 ; RV64ZICBOM: .attribute 5, "rv64i2p0_zicbom1p0"
 ; RV64ZICBOZ: .attribute 5, "rv64i2p0_zicboz1p0"
+; RV64ZAWRS: .attribute 5, "rv64i2p0_zawrs1p0"
 ; RV64ZICBOP: .attribute 5, "rv64i2p0_zicbop1p0"
 ; RV64ZTSO: .attribute 5, "rv64i2p0_ztso0p1"
 
Index: llvm/lib/Target/RISCV/RISCVSubtarget.h
===
--- llvm/lib/Target/RISCV/RISCVSubtarget.h
+++ llvm/lib/Target/RISCV/RISCVSubtarget.h
@@ -92,6 +92,7 @@
   bool HasStdExtZicboz = false;
   bool HasStdExtZicbop = false;
   bool HasStdExtZmmul = false;
+  bool HasStdExtZawrs = false;
   bool HasStdExtZtso = false;
   bool HasRV32 = false;
   bool HasRV64 = false;
@@ -192,6 +193,7 @@
   bool hasStdExtZicbom() const { return HasStdExtZicbom; }
   bool hasStdExtZicboz() const { return HasStdExtZicboz; }
   bool hasStdExtZicbop() const { return HasStdExtZicbop; }
+  bool hasStdExtZawrs() const { return HasStdExtZawrs; }
   bool hasStdExtZmmul() const { return HasStdExtZmmul; }
   bool hasStdExtZtso() const { return HasStdExtZtso; }
   bool is64Bit() const { return HasRV64; }
Index: llvm/lib/Target/RISCV/RISCVInstrInfo.td
===
--- llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -705,6 +705,23 @@
   let rd = 0;
   let imm12 = 0b1100;
 }
+
+let Predicates = [HasStdExtZawrs] in {
+def WRS_NTO : RVInstI<0b000, OPC_SYSTEM, (outs), (ins), "wrs.nto", "">,
+  Sched<[]> {
+  let rs1 = 0;
+  let rd = 0;
+  let imm12 = 0b1101;
+}
+
+def WRS_STO : RVInstI<0b000, OPC_SYSTEM, (outs), (ins), "wrs.sto", "">,
+  Sched<[]> {
+  let rs1 = 0;
+  let rd = 0;
+  let imm12 = 0b00011101;
+}
+} // Predicates = [HasStdExtZawrs]
+
 } // hasSideEffects = 1, mayLoad = 0, mayStore = 0
 
 def CSRRW : CSR_ir<0b001, "csrrw">;
Index: llvm/lib/Target/RISCV/RISCV.td
===
--- llvm/lib/Target/RISCV/RISCV.td
+++ llvm/lib/Target/RISCV/RISCV.td
@@ -461,6 +461,13 @@
AssemblerPredicate<(all_of FeatureStdExtZtso),
"'Ztso' (Memory Model - Total Store Order)">;
 
+def FeatureStdExtZawrs
+: SubtargetFeature<"experimental-zawrs", "HasStdExtZawrs", "true",
+   "'Zawrs' (Wait on Reservation Set)">;
+def HasStdExtZawrs : Predicate<"Subtarget->hasStdExtZawrs()">,
+   AssemblerPredicate<(all_of FeatureStdExtZawrs),
+   "'Zawrs' (Wait on Reservation Set)">;
+
 // Feature32Bit exists to mark CPUs that support RV32 to distinquish them from
 // tuning CPU names.
 def Feature32Bit
Index: llvm/lib/Support/RISCVISAInfo.cpp
===
--- llvm/lib/Support/RISCVISAInfo.cpp
+++ llvm/lib/Support/RISCVISAInfo.cpp
@@ -114,6 +114,7 @@
 {"zbt", RISCVExtensionVersion{0, 93}},
 {"zca", RISCVExtensionVersion{0, 70}},
 {"zvfh", RISCVExtensionVersion{0, 1}},
+{"zawrs", RISCVExtensionVersion{1, 0}},
 {"ztso", RISCVExtensionVersion{0, 1}},
 };
 
Index: llvm/docs/RISCVUsage.rst
=

[PATCH] D133443: [RISCV][MC] Add support for experimental Zawrs extension

2022-09-19 Thread Philip Reames via Phabricator via cfe-commits
reames added a comment.

In D133443#3795603 , @asb wrote:

> Everything that's in this patch looks good to me - it's just missing some 
> simple round-trip tests in the style of rv32zicboz-valid.s (and perhaps an 
> -invalid.s that shows a sensible error message being produced when the 
> instructions have an argument).

You had me very confused at first as I'd written the valid tests - until I 
realized they'd been lost in the rebase.  Updated patch forthcoming.


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

https://reviews.llvm.org/D133443

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


[PATCH] D134055: [clang-doc] Add support for explicitly typed enums

2022-09-19 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth added a comment.

Sorry, it looks like a pre-submit formatting check failed. can you `git 
clang-format HEAD~` and re-upload? I can land your change after that.


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

https://reviews.llvm.org/D134055

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


[clang] 955d7c3 - [clang] Add support for #pragma strict_gs_check

2022-09-19 Thread David Majnemer via cfe-commits

Author: David Majnemer
Date: 2022-09-19T20:07:14Z
New Revision: 955d7c39ff74868a28c848a0462ff41be972043e

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

LOG: [clang] Add support for #pragma strict_gs_check

Added: 
clang/test/CodeGenCXX/pragma-strict_gs_check.cpp

Modified: 
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/Parse/ParsePragma.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaAttr.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index ee9deef0dde1..0238b3877120 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4454,8 +4454,8 @@ def NoStackProtectorDocs : Documentation {
   let Category = DocCatFunction;
   let Heading = "no_stack_protector, safebuffers";
   let Content = [{
-Clang supports the ``__attribute__((no_stack_protector))`` and Microsoft style
-``__declspec(safebuffers)`` attribute which disables
+Clang supports the GNU style ``__attribute__((no_stack_protector))`` and 
Microsoft
+style ``__declspec(safebuffers)`` attribute which disables
 the stack protector on the specified function. This attribute is useful for
 selectively disabling the stack protector on some functions when building with
 ``-fstack-protector`` compiler option.

diff  --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 690a56bf6614..273af97ef241 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -194,6 +194,7 @@ class Parser : public CodeCompletionHandler {
   std::unique_ptr MSConstSeg;
   std::unique_ptr MSCodeSeg;
   std::unique_ptr MSSection;
+  std::unique_ptr MSStrictGuardStackCheck;
   std::unique_ptr MSRuntimeChecks;
   std::unique_ptr MSIntrinsic;
   std::unique_ptr MSFunction;
@@ -725,6 +726,8 @@ class Parser : public CodeCompletionHandler {
  SourceLocation PragmaLocation);
   bool HandlePragmaMSInitSeg(StringRef PragmaName,
  SourceLocation PragmaLocation);
+  bool HandlePragmaMSStrictGuardStackCheck(StringRef PragmaName,
+   SourceLocation PragmaLocation);
   bool HandlePragmaMSFunction(StringRef PragmaName,
   SourceLocation PragmaLocation);
   bool HandlePragmaMSAllocText(StringRef PragmaName,

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f1a4c8d914c0..6dd656e29559 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -691,6 +691,9 @@ class Sema final {
   PragmaStack ConstSegStack;
   PragmaStack CodeSegStack;
 
+  // #pragma strict_gs_check.
+  PragmaStack StrictGuardStackCheckStack;
+
   // This stack tracks the current state of Sema.CurFPFeatures.
   PragmaStack FpPragmaStack;
   FPOptionsOverride CurFPFeatureOverrides() {
@@ -10295,6 +10298,12 @@ class Sema final {
  SourceLocation IncludeLoc);
   void DiagnoseUnterminatedPragmaAlignPack();
 
+  /// ActOnPragmaMSStrictGuardStackCheck - Called on well formed \#pragma
+  /// strict_gs_check.
+  void ActOnPragmaMSStrictGuardStackCheck(SourceLocation PragmaLocation,
+  PragmaMsStackAction Action,
+  bool Value);
+
   /// ActOnPragmaMSStruct - Called on well formed \#pragma ms_struct [on|off].
   void ActOnPragmaMSStruct(PragmaMSStructKind Kind);
 

diff  --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 74fa70379858..123d94ee703f 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -449,6 +449,9 @@ void Parser::initializePragmaHandlers() {
 PP.AddPragmaHandler(MSCodeSeg.get());
 MSSection = std::make_unique("section");
 PP.AddPragmaHandler(MSSection.get());
+MSStrictGuardStackCheck =
+std::make_unique("strict_gs_check");
+PP.AddPragmaHandler(MSStrictGuardStackCheck.get());
 MSFunction = std::make_unique("function");
 PP.AddPragmaHandler(MSFunction.get());
 MSAllocText = std::make_unique("alloc_text");
@@ -567,6 +570,8 @@ void Parser::resetPragmaHandlers() {
 MSCodeSeg.reset();
 PP.RemovePragmaHandler(MSSection.get());
 MSSection.reset();
+PP.RemovePragmaHandler(MSStrictGuardStackCheck.get());
+MSStrictGuardStackCheck.reset();
 PP.RemovePragmaHandler(MSFunction.get());
 MSFunction.reset();
 PP.RemovePragmaHandler(MSAllocText.get());
@@ -936,6 +941,7 @@ void Parser::HandlePragmaMSPragma() {
   .Case("code_seg", &Parser::HandlePragmaMSSegment)
   .Case("section", 

[PATCH] D133668: [HLSL] Use _BitInt(16) for int16_t to avoid promote to int.

2022-09-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

LGTM, but please wait a bit to land for the codegen reviewers to weigh in on 
those tests.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133668

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


[PATCH] D134136: [Clang] Support constexpr for builtin fmax, fmin, ilogb, logb, scalbn

2022-09-19 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron updated this revision to Diff 461312.
Izaron added a comment.

Removed whitespaces in comments.

P.S. I wonder if smaller review requests will make things better? Say a review 
request for `fmax`+`fmin`, then a new one for `ilogb`+`logb`, then for `scalbn`.
This may lead to a more understandable and robust review process =)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134136

Files:
  clang/docs/LanguageExtensions.rst
  clang/lib/AST/ExprConstant.cpp
  clang/test/Sema/constant-builtins-math.cpp
  llvm/include/llvm/ADT/APFloat.h
  llvm/lib/Support/APFloat.cpp

Index: llvm/lib/Support/APFloat.cpp
===
--- llvm/lib/Support/APFloat.cpp
+++ llvm/lib/Support/APFloat.cpp
@@ -4198,6 +4198,19 @@
   return Normalized.exponent - SignificandBits;
 }
 
+IEEEFloat logb(const IEEEFloat &Arg) {
+  IEEEFloat Result(Arg.getSemantics());
+  if (Arg.isNaN())
+Result.makeNaN();
+  else if (Arg.isZero())
+Result.makeInf(/*Negative=*/true);
+  else if (Arg.isInfinity())
+Result.makeInf(/*Negative=*/false);
+  else
+Result = IEEEFloat(static_cast(ilogb(Arg)));
+  return Result;
+}
+
 IEEEFloat scalbn(IEEEFloat X, int Exp, IEEEFloat::roundingMode RoundingMode) {
   auto MaxExp = X.getSemantics().maxExponent;
   auto MinExp = X.getSemantics().minExponent;
Index: llvm/include/llvm/ADT/APFloat.h
===
--- llvm/include/llvm/ADT/APFloat.h
+++ llvm/include/llvm/ADT/APFloat.h
@@ -592,6 +592,7 @@
 
 hash_code hash_value(const IEEEFloat &Arg);
 int ilogb(const IEEEFloat &Arg);
+IEEEFloat logb(const IEEEFloat &Arg);
 IEEEFloat scalbn(IEEEFloat X, int Exp, IEEEFloat::roundingMode);
 IEEEFloat frexp(const IEEEFloat &Val, int &Exp, IEEEFloat::roundingMode RM);
 
@@ -1248,6 +1249,9 @@
 
   friend hash_code hash_value(const APFloat &Arg);
   friend int ilogb(const APFloat &Arg) { return ilogb(Arg.getIEEE()); }
+  friend APFloat logb(const APFloat &Arg) {
+return APFloat(logb(Arg.getIEEE()), Arg.getSemantics());
+  }
   friend APFloat scalbn(APFloat X, int Exp, roundingMode RM);
   friend APFloat frexp(const APFloat &X, int &Exp, roundingMode RM);
   friend IEEEFloat;
Index: clang/test/Sema/constant-builtins-math.cpp
===
--- /dev/null
+++ clang/test/Sema/constant-builtins-math.cpp
@@ -0,0 +1,42 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+static_assert(__builtin_fmax(12.34, 56.78) == 56.78);
+static_assert(__builtin_fmaxf(12.34f, 56.78f) == 56.78f);
+static_assert(__builtin_fmaxl(12.34, 56.78) == 56.78);
+static_assert(__builtin_fmaxf16(12.0, 56.0) == 56.0);
+static_assert(__builtin_fmaxf128(12.34, 56.78) == 56.78);
+
+static_assert(__builtin_fmin(12.34, 56.78) == 12.34);
+static_assert(__builtin_fminf(12.34f, 56.78f) == 12.34f);
+static_assert(__builtin_fminl(12.34, 56.78) == 12.34);
+static_assert(__builtin_fminf16(12.0, 56.0) == 12.0);
+static_assert(__builtin_fminf128(12.34, 56.78) == 12.34);
+
+// TODO: investigate why this is `INT_MIN + 1` instead of `INT_MIN`
+static_assert(__builtin_ilogb(0.0) == -2147483647);
+static_assert(__builtin_ilogb(__builtin_inf()) == 2147483647);
+static_assert(__builtin_ilogb(__builtin_nan("")) == -2147483648);
+static_assert(__builtin_ilogb(1.0) == 0);
+static_assert(__builtin_ilogb(32.0) == 5);
+static_assert(__builtin_ilogb(1024.0) == 10);
+static_assert(__builtin_ilogb(-1024.0) == 10);
+static_assert(__builtin_ilogb(0.1) == -4);
+static_assert(__builtin_ilogb(0.1) == -44);
+
+static_assert(__builtin_logb(0.0) == -__builtin_inf());
+static_assert(__builtin_logb(__builtin_inf()) == __builtin_inf());
+static_assert(__builtin_isnan(__builtin_logb(__builtin_nan("";
+static_assert(__builtin_logb(1.0) == 0.0);
+static_assert(__builtin_logb(32.0) == 5.0);
+static_assert(__builtin_logb(1024.0) == 10.0);
+static_assert(__builtin_logb(-1024.0) == 10.0);
+static_assert(__builtin_logb(0.1) == -4.0);
+static_assert(__builtin_logb(0.1) == -44.0);
+
+static_assert(__builtin_scalbn(12.5, 0) == 12.5);
+static_assert(__builtin_scalbn(12.5, 1) == 25);
+static_assert(__builtin_scalbn(12.5, 3) == 100.0);
+static_assert(__builtin_scalbn(0.0, 100) == 0);
+static_assert(__builtin_scalbn(__builtin_inf(), 100) == __builtin_inf());
+static_assert(__builtin_isnan(__builtin_scalbn(__builtin_nan(""), 100)));
Index: clang/lib/AST/ExprConstant.cpp
===
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -12410,6 +12410,19 @@
   return false;
 return Success(DidOverflow, E);
   }
+
+  case Builtin::BI__builtin_ilogb:
+  case Builtin::BI__builtin_ilogbf:
+  case Builtin::BI__builtin_ilogbl:
+  case Builtin::BI__builtin_ilogbf128: {
+APFloat F(0.0);
+if (!EvaluateFloat(E->getArg(0), F

[PATCH] D134189: [CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode

2022-09-19 Thread Joseph Huber via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb647f13226b4: [CUDA][HIP] Fix new driver crashing when using 
-save-temps in RDC-mode (authored by jhuber6).

Changed prior to commit:
  https://reviews.llvm.org/D134189?vs=461286&id=461310#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134189

Files:
  clang/include/clang/Driver/Action.h
  clang/lib/Driver/Action.cpp
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c
  clang/test/Driver/cuda-bindings.cu
  clang/test/Driver/cuda-phases.cu
  clang/test/Driver/openmp-offload-gpu.c
  clang/test/Driver/openmp-offload.c

Index: clang/test/Driver/openmp-offload.c
===
--- clang/test/Driver/openmp-offload.c
+++ clang/test/Driver/openmp-offload.c
@@ -110,8 +110,8 @@
 // CHK-PHASES-NEXT: 7: backend, {6}, assembler, (device-openmp)
 // CHK-PHASES-NEXT: 8: assembler, {7}, object, (device-openmp)
 // CHK-PHASES-NEXT: 9: offload, "device-openmp (powerpc64-ibm-linux-gnu)" {8}, object
-// CHK-PHASES-NEXT: 10: clang-offload-packager, {9}, image
-// CHK-PHASES-NEXT: 11: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {2}, " (powerpc64-ibm-linux-gnu)" {10}, ir
+// CHK-PHASES-NEXT: 10: clang-offload-packager, {9}, image, (device-openmp)
+// CHK-PHASES-NEXT: 11: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {2}, "device-openmp (powerpc64-ibm-linux-gnu)" {10}, ir
 // CHK-PHASES-NEXT: 12: backend, {11}, assembler, (host-openmp)
 // CHK-PHASES-NEXT: 13: assembler, {12}, object, (host-openmp)
 // CHK-PHASES-NEXT: 14: clang-linker-wrapper, {13}, image, (host-openmp)
@@ -139,8 +139,8 @@
 // CHK-PHASES-FILES-NEXT: 15: backend, {14}, assembler, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 16: assembler, {15}, object, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 17: offload, "device-openmp (powerpc64-ibm-linux-gnu)" {16}, object
-// CHK-PHASES-FILES-NEXT: 18: clang-offload-packager, {10, 17}, image
-// CHK-PHASES-FILES-NEXT: 19: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {3}, " (powerpc64-ibm-linux-gnu)" {18}, ir
+// CHK-PHASES-FILES-NEXT: 18: clang-offload-packager, {10, 17}, image, (device-openmp)
+// CHK-PHASES-FILES-NEXT: 19: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {3}, "device-openmp (powerpc64-ibm-linux-gnu)" {18}, ir
 // CHK-PHASES-FILES-NEXT: 20: backend, {19}, assembler, (host-openmp)
 // CHK-PHASES-FILES-NEXT: 21: assembler, {20}, object, (host-openmp)
 // CHK-PHASES-FILES-NEXT: 22: input, "[[INPUT]]", c, (host-openmp)
@@ -160,8 +160,8 @@
 // CHK-PHASES-FILES-NEXT: 36: backend, {35}, assembler, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 37: assembler, {36}, object, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 38: offload, "device-openmp (powerpc64-ibm-linux-gnu)" {37}, object
-// CHK-PHASES-FILES-NEXT: 39: clang-offload-packager, {31, 38}, image
-// CHK-PHASES-FILES-NEXT: 40: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {24}, " (powerpc64-ibm-linux-gnu)" {39}, ir
+// CHK-PHASES-FILES-NEXT: 39: clang-offload-packager, {31, 38}, image, (device-openmp)
+// CHK-PHASES-FILES-NEXT: 40: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {24}, "device-openmp (powerpc64-ibm-linux-gnu)" {39}, ir
 // CHK-PHASES-FILES-NEXT: 41: backend, {40}, assembler, (host-openmp)
 // CHK-PHASES-FILES-NEXT: 42: assembler, {41}, object, (host-openmp)
 // CHK-PHASES-FILES-NEXT: 43: clang-linker-wrapper, {0, 21, 42}, image, (host-openmp)
Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -258,7 +258,7 @@
 // CHECK-PHASES: 8: assembler, {7}, object, (device-openmp)
 // CHECK-PHASES: 9: offload, "device-openmp (nvptx64-nvidia-cuda)" {8}, object
 // CHECK-PHASES: 10: clang-offload-packager, {9}, image
-// CHECK-PHASES: 11: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, " (x86_64-unknown-linux-gnu)" {10}, ir
+// CHECK-PHASES: 11: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, "device-openmp (x86_64-unknown-linux-gnu)" {10}, ir
 // CHECK-PHASES: 12: backend, {11}, assembler, (host-openmp)
 // CHECK-PHASES: 13: assembler, {12}, object, (host-openmp)
 // CHECK-PHASES: 14: clang-linker-wrapper, {13}, image, (host-openmp)
Index: clang/test/Driver/cuda-phases.cu
===
--- clang/test/Driver/cuda-phases.cu
+++ clang/test/Driver/cuda-phases.cu
@@ -238,8 +238,8 @@
 // NEW-DRIVER-RDC-NEXT: 12: backend, {11}, assembler, (device-cuda, sm_70)
 // NEW-DRIVER-RDC-NEXT: 13: assembler, {12}, object, (device-cuda, sm_70)
 // NEW-DRIVER-RDC-NEXT: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object
-// NEW-DRIVER-RDC-NEXT: 15: clang-offload-packager, {8, 14}, image
-// NEW-DRIVER-RDC-NEXT: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm

[clang] b647f13 - [CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode

2022-09-19 Thread Joseph Huber via cfe-commits

Author: Joseph Huber
Date: 2022-09-19T14:38:44-05:00
New Revision: b647f13226b4b30b8b0cb6e9baebc7a01558cde4

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

LOG: [CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode

Previously when using the `clang-offload-packager` we did not pass the
active offloading kinds. Then in Clang when we attempted to detect when
there was host-offloading action that needed to be embedded in the host
we did not find it. This patch adds the active offloading kinds so we
know when there is input to be embedded.

Reviewed By: tra

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

Added: 


Modified: 
clang/include/clang/Driver/Action.h
clang/lib/Driver/Action.cpp
clang/lib/Driver/Driver.cpp
clang/test/Driver/amdgpu-openmp-toolchain.c
clang/test/Driver/cuda-bindings.cu
clang/test/Driver/cuda-phases.cu
clang/test/Driver/openmp-offload-gpu.c
clang/test/Driver/openmp-offload.c

Removed: 




diff  --git a/clang/include/clang/Driver/Action.h 
b/clang/include/clang/Driver/Action.h
index 9d940766ad264..550a47baaffaf 100644
--- a/clang/include/clang/Driver/Action.h
+++ b/clang/include/clang/Driver/Action.h
@@ -296,11 +296,16 @@ class OffloadAction final : public Action {
 OffloadKindList DeviceOffloadKinds;
 
   public:
-/// Add a action along with the associated toolchain, bound arch, and
+/// Add an action along with the associated toolchain, bound arch, and
 /// offload kind.
 void add(Action &A, const ToolChain &TC, const char *BoundArch,
  OffloadKind OKind);
 
+/// Add an action along with the associated toolchain, bound arch, and
+/// offload kinds.
+void add(Action &A, const ToolChain &TC, const char *BoundArch,
+ unsigned OffloadKindMask);
+
 /// Get each of the individual arrays.
 const ActionList &getActions() const { return DeviceActions; }
 const ToolChainList &getToolChains() const { return DeviceToolChains; }

diff  --git a/clang/lib/Driver/Action.cpp b/clang/lib/Driver/Action.cpp
index 1cb68276e11eb..bec649191baaf 100644
--- a/clang/lib/Driver/Action.cpp
+++ b/clang/lib/Driver/Action.cpp
@@ -307,6 +307,19 @@ void OffloadAction::DeviceDependences::add(Action &A, 
const ToolChain &TC,
   DeviceOffloadKinds.push_back(OKind);
 }
 
+void OffloadAction::DeviceDependences::add(Action &A, const ToolChain &TC,
+   const char *BoundArch,
+   unsigned OffloadKindMask) {
+  DeviceActions.push_back(&A);
+  DeviceToolChains.push_back(&TC);
+  DeviceBoundArchs.push_back(BoundArch);
+
+  // Add each active offloading kind from a mask.
+  for (OffloadKind OKind : {OFK_OpenMP, OFK_Cuda, OFK_HIP})
+if (OKind & OffloadKindMask)
+  DeviceOffloadKinds.push_back(OKind);
+}
+
 OffloadAction::HostDependence::HostDependence(Action &A, const ToolChain &TC,
   const char *BoundArch,
   const DeviceDependences &DDeps)

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index a67cf36152448..013d5b32074e9 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4391,7 +4391,7 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
 Action *PackagerAction =
 C.MakeAction(OffloadActions, 
types::TY_Image);
 DDep.add(*PackagerAction, *C.getSingleOffloadToolChain(),
- nullptr, Action::OFK_None);
+ nullptr, C.getActiveOffloadKinds());
   }
 
   // If we are unable to embed a single device output into the host, we need to

diff  --git a/clang/test/Driver/amdgpu-openmp-toolchain.c 
b/clang/test/Driver/amdgpu-openmp-toolchain.c
index 96caf57f33bf4..288122c89bf0d 100644
--- a/clang/test/Driver/amdgpu-openmp-toolchain.c
+++ b/clang/test/Driver/amdgpu-openmp-toolchain.c
@@ -26,7 +26,7 @@
 // CHECK-PHASES: 8: assembler, {7}, object, (device-openmp)
 // CHECK-PHASES: 9: offload, "device-openmp (amdgcn-amd-amdhsa)" {8}, object
 // CHECK-PHASES: 10: clang-offload-packager, {9}, image
-// CHECK-PHASES: 11: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, " 
(x86_64-unknown-linux-gnu)" {10}, ir
+// CHECK-PHASES: 11: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, 
"device-openmp (x86_64-unknown-linux-gnu)" {10}, ir
 // CHECK-PHASES: 12: backend, {11}, assembler, (host-openmp)
 // CHECK-PHASES: 13: assembler, {12}, object, (host-openmp)
 // CHECK-PHASES: 14: clang-linker-wrapper, {13}, image, (host-openmp)

diff  --git a/clang/test/Driver/cuda-bindings.cu 
b/clang/test/Driver/cuda-bindings.cu
index f95d2de80f4a8..78c9bb975c6f1 100644
--- a/clang/test/Driver/cuda-bindings.cu
+++ b/clang/test/Driver/cuda-bin

[PATCH] D133668: [HLSL] Use _BitInt(16) for int16_t to avoid promote to int.

2022-09-19 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 461308.
python3kgae added a comment.

Limit max bitint width to 64 for HLSL.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133668

Files:
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Headers/hlsl/hlsl_basic_types.h
  clang/test/CodeGenHLSL/basic_types.hlsl
  clang/test/CodeGenHLSL/builtins/abs.hlsl
  clang/test/CodeGenHLSL/int16_t_add.hlsl
  clang/test/SemaHLSL/BitInt128.hlsl

Index: clang/test/SemaHLSL/BitInt128.hlsl
===
--- /dev/null
+++ clang/test/SemaHLSL/BitInt128.hlsl
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -ast-dump -o - %s -verify
+
+// expected-error@+1 {{signed _BitInt of bit sizes greater than 64 not supported}}
+_BitInt(128) i128;
+
+// expected-error@+1 {{unsigned _BitInt of bit sizes greater than 64 not supported}}
+unsigned _BitInt(128) u128;
Index: clang/test/CodeGenHLSL/int16_t_add.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/int16_t_add.hlsl
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -D__HLSL_ENABLE_16_BIT \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+
+// Make sure generate i16 add.
+// CHECK: add nsw i16 %
+int16_t add(int16_t a, int16_t b) {
+  return a + b;
+}
+// CHECK: define noundef <2 x i16> @
+// CHECK: add <2 x i16>
+int16_t2 add(int16_t2 a, int16_t2 b) {
+  return a + b;
+}
+// CHECK: define noundef <3 x i16> @
+// CHECK: add <3 x i16>
+int16_t3 add(int16_t3 a, int16_t3 b) {
+  return a + b;
+}
+// CHECK: define noundef <4 x i16> @
+// CHECK: add <4 x i16>
+int16_t4 add(int16_t4 a, int16_t4 b) {
+  return a + b;
+}
Index: clang/test/CodeGenHLSL/builtins/abs.hlsl
===
--- clang/test/CodeGenHLSL/builtins/abs.hlsl
+++ clang/test/CodeGenHLSL/builtins/abs.hlsl
@@ -7,8 +7,7 @@
 
 
 // CHECK: define noundef signext i16 @
-// FIXME: int16_t is promoted to i32 now. Change to abs.i16 once it is fixed.
-// CHECK: call i32 @llvm.abs.i32(
+// CHECK: call i16 @llvm.abs.i16(
 int16_t test_abs_int16_t ( int16_t p0 ) {
   return abs ( p0 );
 }
Index: clang/test/CodeGenHLSL/basic_types.hlsl
===
--- clang/test/CodeGenHLSL/basic_types.hlsl
+++ clang/test/CodeGenHLSL/basic_types.hlsl
@@ -3,17 +3,17 @@
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 
 
-// CHECK:"?uint16_t_Val@@3GA" = global i16 0, align 2
-// CHECK:"?int16_t_Val@@3FA" = global i16 0, align 2
+// CHECK:"?uint16_t_Val@@3U?$_UBitInt@$0BA@@__clang@@A" = global i16 0, align 2
+// CHECK:"?int16_t_Val@@3U?$_BitInt@$0BA@@__clang@@A" = global i16 0, align 2
 // CHECK:"?uint_Val@@3IA" = global i32 0, align 4
 // CHECK:"?uint64_t_Val@@3KA" = global i64 0, align 8
 // CHECK:"?int64_t_Val@@3JA" = global i64 0, align 8
-// CHECK:"?int16_t2_Val@@3T?$__vector@F$01@__clang@@A" = global <2 x i16> zeroinitializer, align 4
-// CHECK:"?int16_t3_Val@@3T?$__vector@F$02@__clang@@A" = global <3 x i16> zeroinitializer, align 8
-// CHECK:"?int16_t4_Val@@3T?$__vector@F$03@__clang@@A" = global <4 x i16> zeroinitializer, align 8
-// CHECK:"?uint16_t2_Val@@3T?$__vector@G$01@__clang@@A" = global <2 x i16> zeroinitializer, align 4
-// CHECK:"?uint16_t3_Val@@3T?$__vector@G$02@__clang@@A" = global <3 x i16> zeroinitializer, align 8
-// CHECK:"?uint16_t4_Val@@3T?$__vector@G$03@__clang@@A" = global <4 x i16> zeroinitializer, align 8
+// CHECK:"?int16_t2_Val@@3T?$__vector@U?$_BitInt@$0BA@@__clang@@$01@__clang@@A" = global <2 x i16> zeroinitializer, align 4
+// CHECK:"?int16_t3_Val@@3T?$__vector@U?$_BitInt@$0BA@@__clang@@$02@__clang@@A" = global <3 x i16> zeroinitializer, align 8
+// CHECK:"?int16_t4_Val@@3T?$__vector@U?$_BitInt@$0BA@@__clang@@$03@__clang@@A" = global <4 x i16> zeroinitializer, align 8
+// CHECK:"?uint16_t2_Val@@3T?$__vector@U?$_UBitInt@$0BA@@__clang@@$01@__clang@@A" = global <2 x i16> zeroinitializer, align 4
+// CHECK:"?uint16_t3_Val@@3T?$__vector@U?$_UBitInt@$0BA@@__clang@@$02@__clang@@A" = global <3 x i16> zeroinitializer, align 8
+// CHECK:"?uint16_t4_Val@@3T?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clang@@A" = global <4 x i16> zeroinitializer, align 8
 // CHECK:"?int2_Val@@3T?$__vector@H$01@__clang@@A" = global <2 x i32> zeroinitializer, align 8
 // CHECK:"?int3_Val@@3T?$__vector@H$02@__clang@@A" = global <3 x i32> zeroinitializer, align 16
 // CHECK:"?int4_Val@@3T?$__vector@H$03@__clang@@A" = global <4 x i32> zeroinitializer, align 16
Index: clang/lib/Headers/hlsl/hlsl_basic_types.h
===
--- clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -13,8 +13,8 @@
 
 #ifdef __HLSL_ENABLE_16_BIT
 // 16-bi

[PATCH] D134208: [clang] [Driver] Do not transform explicit --config filename

2022-09-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: sepavloff, MaskRay.
Herald added a subscriber: StephenFan.
Herald added a project: All.
mgorny requested review of this revision.

Disable transformations (e.g. attempting to replace target architecture)
in the config filename that is passed explicitly via `--config`.  This
behavior is surprising and confusing -- if user passes an explicit
config filename, Clang should use it as is.  The transformations are
still applied when the name is deduced from filename.

Update the tests accordingly.  This primarily ensures that full filename
with .cfg suffix is passed to --config (appending `.cfg` implicitly is
not documented, and would collide with use of filenames with other
suffixes).  The config-file2.c suite is removed entirely as it tested
the transformations on the argument to --config.  However, the aspects
of that that were not tested as part of config-file3.c are now added
there (based on config filename deduced from executable).

This change streamlines the code in Driver::loadConfigFile(), opening
the possibility of further changes, including support for handling
multiple --config options and refactoring of filename deduction.


https://reviews.llvm.org/D134208

Files:
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/config-file-errs.c
  clang/test/Driver/config-file.c
  clang/test/Driver/config-file2.c
  clang/test/Driver/config-file3.c

Index: clang/test/Driver/config-file3.c
===
--- clang/test/Driver/config-file3.c
+++ clang/test/Driver/config-file3.c
@@ -37,7 +37,7 @@
 //
 //--- File specified by --config overrides config inferred from clang executable.
 //
-// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config i386-qqq -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-EXPLICIT
+// RUN: %t/testdmode/qqq-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config i386-qqq.cfg -c -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-EXPLICIT
 //
 // CHECK-EXPLICIT: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
 
@@ -77,27 +77,24 @@
 // RUN: ln -s %clang %t/testreload/x86_64-clang-g++
 // RUN: echo "-Wundefined-func-template" > %t/testreload/i386-clang-g++.cfg
 // RUN: echo "-Werror" > %t/testreload/i386.cfg
+// RUN: echo "-Wall" > %t/testreload/x86_64-clang-g++.cfg
 // RUN: %t/testreload/x86_64-clang-g++ --config-system-dir= --config-user-dir= -c -m32 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD
 //
 // CHECK-RELOAD: Configuration file: {{.*}}/testreload/i386-clang-g++.cfg
 // CHECK-RELOAD: -Wundefined-func-template
 // CHECK-RELOAD-NOT: -Werror
+// CHECK-RELOAD-NOT: -Wall
 
-//--- If config file is specified by --config and its name does not start with architecture, it is used without reloading.
-//
-// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir=%S/Inputs --config-user-dir= --config config-3 -c -m32 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD1a
-//
-// CHECK-RELOAD1a: Configuration file: {{.*}}/Inputs/config-3.cfg
-//
-// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir=%S/Inputs --config-user-dir= --config config-3 -c --target=i386 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD1b
-//
-// CHECK-RELOAD1b: Configuration file: {{.*}}/Inputs/config-3.cfg
+//--- Same for -target in place of -m32.
+// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir= --config-user-dir= -c -target i386 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD
 
-//--- If config file is specified by --config and its name starts with architecture, it is reloaded.
-//
-// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir=%S/Inputs/config --config-user-dir= --config x86_64-qqq -c -m32 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD1c
+//--- `-target i386 -m64` should load the 64-bit config.
+// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir= --config-user-dir= -c -target i386 -m64 -no-canonical-prefixes -### %s 2>&1 | FileCheck %s -check-prefix CHECK-RELOAD1a
 //
-// CHECK-RELOAD1c: Configuration file: {{.*}}/Inputs/config/i386-qqq.cfg
+// CHECK-RELOAD1a: Configuration file: {{.*}}/testreload/x86_64-clang-g++.cfg
+// CHECK-RELOAD1a: -Wall
+// CHECK-RELOAD1a-NOT: -Werror
+// CHECK-RELOAD1a-NOT: -Wundefined-func-template
 
 //--- x86_64-clang-g++ tries to find config i386.cfg if i386-clang-g++.cfg is not found.
 //
@@ -107,4 +104,9 @@
 // CHECK-RELOAD1d: Configuration file: {{.*}}/testreload/i386.cfg
 // CHECK-RELOAD1d: -Werror
 // CHECK-RELOAD1d-NOT: -Wundefined-func-template
+// CHECK-RELOAD1d-NOT: -Wall
 
+//--- x86_64-clang-g++ uses x86_64-clang-g++.cfg if i386*.cfg are not found.
+//
+// RUN: rm %t/testreload/i386.cfg
+// RUN: %t/testreload/x86_64-clang-g++ --config-system-dir= --config-user-dir= -c -m32 -no-canon

[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-09-19 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

In D128465#3800479 , @andrewrk wrote:

>   if(LLVM_ENABLE_ZSTD)
> list(APPEND imported_libs zstd::libzstd_shared)
>   endif()
>
> This hard codes shared linking which breaks the use case of static linking 
> LLVM.

This was addressed by D132870  and D133222 
.

> Also LLVM needs to now include a Findzstd.cmake file or else we get this 
> error:
>
>   CMake Error at cmake/config-ix.cmake:144 (find_package):
> By not providing "Findzstd.cmake" in CMAKE_MODULE_PATH this project has
> asked CMake to find a package configuration file provided by "zstd", but
> CMake did not find one.
>   
> Could not find a package configuration file provided by "zstd" with any of
> the following names:
>   
>   zstdConfig.cmake
>   zstd-config.cmake
>   
> Add the installation prefix of "zstd" to CMAKE_PREFIX_PATH or set
> "zstd_DIR" to a directory containing one of the above files.  If "zstd"
> provides a separate development package or SDK, be sure it has been
> installed.
>   Call Stack (most recent call first):
> CMakeLists.txt:774 (include)
>
> It is impossible to satisfy this dependency when bootstrapping a static build 
> of zig without patching LLVM.

It should be possible to use `CMAKE_FIND_PACKAGE_PREFER_CONFIG=ON` to pick up 
config file that's part of the zstd installation, but I'd be also fine 
including `Findzstd.cmake` in LLVM to avoid needing that.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

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


[PATCH] D133583: [clang][ubsan] Fix __builtin_assume_aligned incorrect type descriptor and C++ object polymorphic address

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

LGTM! Please give @rjmccall another day to chime in with any concerns he has.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133583

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


[PATCH] D134207: [Clang] Support case and default labels at end of compound statement

2022-09-19 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron added inline comments.



Comment at: clang/include/clang/Basic/DiagnosticParseKinds.td:298-299
   "and have an empty entry in the selector">;
-def err_switch_label_end_of_compound_statement : Error<
-  "label at end of switch compound statement: expected statement">;
 def ext_c_label_end_of_compound_statement : ExtWarn<

This is not an error anymore



Comment at: clang/lib/Parse/ParseStmt.cpp:948-956
+if (getLangOpts().CPlusPlus) {
+  Diag(Tok, getLangOpts().CPlusPlus2b
+? diag::warn_cxx20_compat_label_end_of_compound_statement
+: diag::ext_cxx_label_end_of_compound_statement);
+} else {
+  Diag(Tok, getLangOpts().C2x
+? diag::warn_c2x_compat_label_end_of_compound_statement

We have copy-pasted this piece of code in 3 places (simple label, case label, 
default label). Does it make sense to have a method for label diags?



Comment at: clang/test/Parser/c2x-label.c:12-30
+int test_label_in_switch(int v) {
+switch (v) {
+case 1:
+return 1;
+case 2:
+return 2;
+case 3: case 4: case 5:

I feel like we may be having redundant tests, because `Parser/c2x-label.c` and 
`C2x/n2508.c` test the same things...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134207

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


[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-09-19 Thread Andrew Kelley via Phabricator via cfe-commits
andrewrk added a comment.

Compiler infrastructure should not assume the existence of a Linux 
distribution. The portable way is simple and can easily be supported. One 
should be able to install `$prefix/lib/libzstd.a` and `$prefix/include/zstd.h`, 
then have that prefix searched as part of the standard `CMAKE_PREFIX_PATH`.

If LLVM will not carry Findzstd.cmake then it should not use `FIND_PACKAGE` in 
the case of `-DLLVM_ENABLE_ZSTD=FORCE_ON`; it should just throw `-lzstd` on the 
linker line instead of throwing rakes in my path for no reason.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

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


[PATCH] D134207: [Clang] Support case and default labels at end of compound statement

2022-09-19 Thread Evgeny Shulgin via Phabricator via cfe-commits
Izaron created this revision.
Izaron added reviewers: clang-language-wg, aaron.ballman, cor3ntin.
Herald added a project: All.
Izaron requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Direct continuation of https://reviews.llvm.org/D133887


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134207

Files:
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/lib/Parse/ParseStmt.cpp
  clang/test/AST/ast-dump-stmt.c
  clang/test/C/C2x/n2508.c
  clang/test/Parser/c2x-label.c
  clang/test/Parser/cxx2b-label.cpp
  clang/test/Parser/switch-recovery.cpp
  clang/www/c_status.html

Index: clang/www/c_status.html
===
--- clang/www/c_status.html
+++ clang/www/c_status.html
@@ -763,13 +763,7 @@
 
   Free positioning of labels inside compound statements
   https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2508.pdf";>N2508
-
-  Partial
-Clang supports labels at the end of compound statements but does
-not yet support case or default labels at
-the end of a switch statement's compound block.
-  
-
+  Clang 16
 
 
   Clarification request for C17 example of undefined behavior
Index: clang/test/Parser/switch-recovery.cpp
===
--- clang/test/Parser/switch-recovery.cpp
+++ clang/test/Parser/switch-recovery.cpp
@@ -160,15 +160,15 @@
 void missing_statement_case(int x) {
   switch (x) {
 case 1:
-case 0: // expected-error {{label at end of switch compound statement: expected statement}}
-  }
+case 0:
+  } // expected-warning {{label at end of compound statement is a C++2b extension}}
 }
 
 void missing_statement_default(int x) {
   switch (x) {
 case 0:
-default: // expected-error {{label at end of switch compound statement: expected statement}}
-  }
+default:
+  } // expected-warning {{label at end of compound statement is a C++2b extension}}
 }
 
 void pr19022_1() {
@@ -178,9 +178,8 @@
 
 void pr19022_1a(int x) {
   switch(x) {
-  case 1  // expected-error{{expected ':' after 'case'}} \
-  // expected-error{{label at end of switch compound statement: expected statement}}
-  }
+  case 1  // expected-error{{expected ':' after 'case'}}
+  } // expected-warning {{label at end of compound statement is a C++2b extension}}
 }
 
 void pr19022_1b(int x) {
@@ -210,9 +209,9 @@
 
 void pr19022_5(int x) {
   switch(x) {
-  case 1: case // expected-error{{expected ':' after 'case'}} \
-   // expected-error{{expected statement}}
-  }  // expected-error{{expected expression}}
+  case 1: case // expected-error{{expected ':' after 'case'}}
+  }  // expected-error{{expected expression}} \
+ // expected-warning {{label at end of compound statement is a C++2b extension}}
 }
 
 namespace pr19022 {
Index: clang/test/Parser/cxx2b-label.cpp
===
--- clang/test/Parser/cxx2b-label.cpp
+++ clang/test/Parser/cxx2b-label.cpp
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx2b -std=c++2b -Wpre-c++2b-compat %s
 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx20 -std=c++20 %s
 
-void foo() {
+void test_label_in_func() {
 label1:
 int x;
 label2:
@@ -9,3 +9,23 @@
 label3: label4: label5:
 } // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
  cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
+
+int test_label_in_switch(int v) {
+switch (v) {
+case 1:
+return 1;
+case 2:
+return 2;
+case 3: case 4: case 5:
+} // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
+ cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
+
+switch (v) {
+case 6:
+return 6;
+default:
+} // cxx20-warning {{label at end of compound statement is a C++2b extension}} \
+ cxx2b-warning {{label at end of compound statement is incompatible with C++ standards before C++2b}}
+
+return 0;
+}
Index: clang/test/Parser/c2x-label.c
===
--- clang/test/Parser/c2x-label.c
+++ clang/test/Parser/c2x-label.c
@@ -1,10 +1,30 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c17 -Wc2x-compat -verify=c17 %s
 // RUN: %clang_cc1 -fsyntax-only -std=c2x -Wpre-c2x-compat -verify=c2x %s
 
-void foo() {
+void test_label_in_func() {
 int x;
 label1:
 x = 1;
 label2: label3: label4:
 } // c17-warning {{label at end of compound statement is a C2x extension}} \
  c2x-warning {{label at end of compound statement is incompatible with C standards before C2x}}
+
+int test_label_in_switch(int v) {
+switch (v) {
+case 1:
+return 1;
+case 2:
+return 2;
+case 3:

[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-09-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

zstd provides GNU Makefile, CMake, and Meson. The CMake files are only 
installed when configured with CMake. Debian and Ubuntu lack such files.
The pkg-config file libzstd.pc is probably the most portable file. (I have also 
used it for a binutils-gdb patch.)

I think we can then avoid the

  zstdConfig.cmake
  zstd-config.cmake

issue.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

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


[PATCH] D133668: [HLSL] Use _BitInt(16) for int16_t to avoid promote to int.

2022-09-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added reviewers: rjmccall, efriedma.
aaron.ballman added a comment.

Adding some codegen reviewers for awareness.




Comment at: clang/lib/Basic/Targets/DirectX.h:66
 
+  bool hasBitIntType() const override { return true; }
   bool hasFeature(StringRef Feature) const override {

beanz wrote:
> aaron.ballman wrote:
> > This change requires more testing/thought, IMO -- do you support 128-bit 
> > operations? When we bump that limit to be arbitrarily high, should DX have 
> > the arbitrary limits or do you need to enforce something lower? Have you 
> > considered how you want to pack these into structures or other data layout 
> > considerations?
> Yea, we definitely need to set the max width to 64 for DirectX.
Nothing seems to have handled this comment yet. Be sure to add a Sema test for 
that as well.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133668

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


[clang] 88210b8 - [clang][dataflow] Refactor `clang/Analysis/FlowSensitive/MatchSwitchTest.cpp`.

2022-09-19 Thread Wei Yi Tee via cfe-commits

Author: Wei Yi Tee
Date: 2022-09-19T19:10:41Z
New Revision: 88210b81eed803598afeeaa2a60eb26ddbb65435

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

LOG: [clang][dataflow] Refactor 
`clang/Analysis/FlowSensitive/MatchSwitchTest.cpp`.

- Remove use of `runDataflowAnalysis` to keep test isolated.
- Add test for `ASTMatchSwitch`.

Reviewed By: gribozavr2, sgatev

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

Added: 


Modified: 
clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp

Removed: 




diff  --git a/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
index 42bf5ddec508..eec1c704dbbb 100644
--- a/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
@@ -7,24 +7,15 @@
 
//===--===//
 
 #include "clang/Analysis/FlowSensitive/MatchSwitch.h"
-#include "TestingSupport.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
-#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
-#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
-#include "clang/Analysis/FlowSensitive/MapLattice.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Testing/ADT/StringMapEntry.h"
-#include "llvm/Testing/Support/Error.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -34,172 +25,114 @@
 
 using namespace clang;
 using namespace dataflow;
+using namespace ast_matchers;
 
 namespace {
-using ::llvm::IsStringMapEntry;
-using ::testing::UnorderedElementsAre;
 
-class BooleanLattice {
-public:
-  BooleanLattice() : Value(false) {}
-  explicit BooleanLattice(bool B) : Value(B) {}
-
-  static BooleanLattice bottom() { return BooleanLattice(false); }
-
-  static BooleanLattice top() { return BooleanLattice(true); }
-
-  LatticeJoinEffect join(BooleanLattice Other) {
-auto Prev = Value;
-Value = Value || Other.Value;
-return Prev == Value ? LatticeJoinEffect::Unchanged
- : LatticeJoinEffect::Changed;
-  }
-
-  friend bool operator==(BooleanLattice LHS, BooleanLattice RHS) {
-return LHS.Value == RHS.Value;
-  }
-
-  friend std::ostream &operator<<(std::ostream &Os, const BooleanLattice &B) {
-Os << B.Value;
-return Os;
-  }
-
-  bool value() const { return Value; }
-
-private:
-  bool Value;
-};
-} // namespace
-
-MATCHER_P(Holds, m,
-  ((negation ? "doesn't hold" : "holds") +
-   llvm::StringRef(" a lattice element that ") +
-   ::testing::DescribeMatcher(m, negation))
-  .str()) {
-  return ExplainMatchResult(m, arg.Lattice, result_listener);
-}
-
-void TransferSetTrue(const DeclRefExpr *,
- const ast_matchers::MatchFinder::MatchResult &,
- TransferState &State) {
-  State.Lattice = BooleanLattice(true);
-}
-
-void TransferSetFalse(const Stmt *,
-  const ast_matchers::MatchFinder::MatchResult &,
-  TransferState &State) {
-  State.Lattice = BooleanLattice(false);
-}
-
-class TestAnalysis : public DataflowAnalysis {
-  MatchSwitch> TransferSwitch;
-
-public:
-  explicit TestAnalysis(ASTContext &Context)
-  : DataflowAnalysis(Context) {
-using namespace ast_matchers;
-TransferSwitch =
-MatchSwitchBuilder>()
-.CaseOf(declRefExpr(to(varDecl(hasName("X",
- TransferSetTrue)
-.CaseOf(callExpr(callee(functionDecl(hasName("Foo",
-  TransferSetFalse)
-.Build();
-  }
-
-  static BooleanLattice initialElement() { return BooleanLattice::bottom(); }
-
-  void transfer(const Stmt *S, BooleanLattice &L, Environment &Env) {
-TransferState State(L, Env);
-TransferSwitch(*S, getASTContext(), State);
-  }
-};
-
-template 
-void RunDataflow(llvm::StringRef Code, Matcher Expectations) {
-  using namespace ast_matchers;
-  using namespace test;
-  ASSERT_THAT_ERROR(
-  checkDataflow(
-  AnalysisInputs(
-  Code, hasName("fun"),
-  [](ASTContext &C, Environment &) { return TestAnalysis(C); })
-  .withASTBuildArgs({"-fsyntax-only", "-std=c++17"}),
-  /*VerifyResults=*/
-  [&Expectations](
-  const llvm::StringMap<
-  DataflowAnalysisState> &Result

[PATCH] D133935: [clang][dataflow] Refactor `clang/Analysis/FlowSensitive/MatchSwitchTest.cpp`.

2022-09-19 Thread weiyi 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 rG88210b81eed8: [clang][dataflow] Refactor 
`clang/Analysis/FlowSensitive/MatchSwitchTest.cpp`. (authored by wyt).

Changed prior to commit:
  https://reviews.llvm.org/D133935?vs=460371&id=461295#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133935

Files:
  clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/MatchSwitchTest.cpp
@@ -7,24 +7,15 @@
 //===--===//
 
 #include "clang/Analysis/FlowSensitive/MatchSwitch.h"
-#include "TestingSupport.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/Expr.h"
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
-#include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
-#include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
-#include "clang/Analysis/FlowSensitive/DataflowLattice.h"
-#include "clang/Analysis/FlowSensitive/MapLattice.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
-#include "llvm/Support/Error.h"
-#include "llvm/Testing/ADT/StringMapEntry.h"
-#include "llvm/Testing/Support/Error.h"
-#include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
 #include 
@@ -34,172 +25,114 @@
 
 using namespace clang;
 using namespace dataflow;
+using namespace ast_matchers;
 
 namespace {
-using ::llvm::IsStringMapEntry;
-using ::testing::UnorderedElementsAre;
 
-class BooleanLattice {
-public:
-  BooleanLattice() : Value(false) {}
-  explicit BooleanLattice(bool B) : Value(B) {}
-
-  static BooleanLattice bottom() { return BooleanLattice(false); }
-
-  static BooleanLattice top() { return BooleanLattice(true); }
-
-  LatticeJoinEffect join(BooleanLattice Other) {
-auto Prev = Value;
-Value = Value || Other.Value;
-return Prev == Value ? LatticeJoinEffect::Unchanged
- : LatticeJoinEffect::Changed;
-  }
-
-  friend bool operator==(BooleanLattice LHS, BooleanLattice RHS) {
-return LHS.Value == RHS.Value;
-  }
-
-  friend std::ostream &operator<<(std::ostream &Os, const BooleanLattice &B) {
-Os << B.Value;
-return Os;
-  }
-
-  bool value() const { return Value; }
-
-private:
-  bool Value;
-};
-} // namespace
-
-MATCHER_P(Holds, m,
-  ((negation ? "doesn't hold" : "holds") +
-   llvm::StringRef(" a lattice element that ") +
-   ::testing::DescribeMatcher(m, negation))
-  .str()) {
-  return ExplainMatchResult(m, arg.Lattice, result_listener);
-}
-
-void TransferSetTrue(const DeclRefExpr *,
- const ast_matchers::MatchFinder::MatchResult &,
- TransferState &State) {
-  State.Lattice = BooleanLattice(true);
-}
-
-void TransferSetFalse(const Stmt *,
-  const ast_matchers::MatchFinder::MatchResult &,
-  TransferState &State) {
-  State.Lattice = BooleanLattice(false);
-}
-
-class TestAnalysis : public DataflowAnalysis {
-  MatchSwitch> TransferSwitch;
-
-public:
-  explicit TestAnalysis(ASTContext &Context)
-  : DataflowAnalysis(Context) {
-using namespace ast_matchers;
-TransferSwitch =
-MatchSwitchBuilder>()
-.CaseOf(declRefExpr(to(varDecl(hasName("X",
- TransferSetTrue)
-.CaseOf(callExpr(callee(functionDecl(hasName("Foo",
-  TransferSetFalse)
-.Build();
-  }
-
-  static BooleanLattice initialElement() { return BooleanLattice::bottom(); }
-
-  void transfer(const Stmt *S, BooleanLattice &L, Environment &Env) {
-TransferState State(L, Env);
-TransferSwitch(*S, getASTContext(), State);
-  }
-};
-
-template 
-void RunDataflow(llvm::StringRef Code, Matcher Expectations) {
-  using namespace ast_matchers;
-  using namespace test;
-  ASSERT_THAT_ERROR(
-  checkDataflow(
-  AnalysisInputs(
-  Code, hasName("fun"),
-  [](ASTContext &C, Environment &) { return TestAnalysis(C); })
-  .withASTBuildArgs({"-fsyntax-only", "-std=c++17"}),
-  /*VerifyResults=*/
-  [&Expectations](
-  const llvm::StringMap<
-  DataflowAnalysisState> &Results,
-  const AnalysisOutputs &) { EXPECT_THAT(Results, Expectations); }),
-  llvm::Succeeded());
-}
-
-TEST(MatchSwitchTest, JustX) {
-  std::string Code = R"(
-void fun() {
-  int X = 1;
-  (void)X;
-  // [[

[PATCH] D128465: [llvm] add zstd to `llvm::compression` namespace

2022-09-19 Thread Andrew Kelley via Phabricator via cfe-commits
andrewrk added a comment.

  if(LLVM_ENABLE_ZSTD)
list(APPEND imported_libs zstd::libzstd_shared)
  endif()

This hard codes shared linking which breaks the use case of static linking LLVM.

Also LLVM needs to now include a Findzstd.cmake file or else we get this error:

  CMake Error at cmake/config-ix.cmake:144 (find_package):
By not providing "Findzstd.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "zstd", but
CMake did not find one.
  
Could not find a package configuration file provided by "zstd" with any of
the following names:
  
  zstdConfig.cmake
  zstd-config.cmake
  
Add the installation prefix of "zstd" to CMAKE_PREFIX_PATH or set
"zstd_DIR" to a directory containing one of the above files.  If "zstd"
provides a separate development package or SDK, be sure it has been
installed.
  Call Stack (most recent call first):
CMakeLists.txt:774 (include)

It is impossible to satisfy this dependency when bootstrapping a static build 
of zig without patching LLVM.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128465

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


[PATCH] D134189: [CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode

2022-09-19 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 marked 3 inline comments as done.
jhuber6 added inline comments.



Comment at: clang/lib/Driver/Action.cpp:320
+if (OKind & Mask)
+  DeviceOffloadKinds.push_back(OKind);
+}

tra wrote:
> It would be good to clear processed bits in `Mask` and then assert that it's 
> zero after we're done. Otherwise it would be easy to miss handling a new 
> offload kind if/when it gets added.
I was also considering just putting something like this next to the 
declarations since we already do this for the new driver as well.

```
constexpr OffloadKind[] DeviceOffloadingKinds = {OFK_OpenMP, OFK_Cuda, OFK_HIP};
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134189

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


[PATCH] D134189: [CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode

2022-09-19 Thread Artem Belevich via Phabricator via cfe-commits
tra accepted this revision.
tra added a comment.
This revision is now accepted and ready to land.

LGTM with a few nits.




Comment at: clang/include/clang/Driver/Action.h:304
 
+/// Add a action along with the associated toolchain, bound arch, and
+/// offload kinds.

Nit: Add a*n* action



Comment at: clang/include/clang/Driver/Action.h:307
+void add(Action &A, const ToolChain &TC, const char *BoundArch,
+ unsigned Mask);
+

Nit: `OffloadKindMask`?



Comment at: clang/lib/Driver/Action.cpp:320
+if (OKind & Mask)
+  DeviceOffloadKinds.push_back(OKind);
+}

It would be good to clear processed bits in `Mask` and then assert that it's 
zero after we're done. Otherwise it would be easy to miss handling a new 
offload kind if/when it gets added.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134189

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


[clang] 41d52c5 - [clang][dataflow] Modify `transfer` in `DataflowModel` to take `CFGElement` as input instead of `Stmt`.

2022-09-19 Thread Wei Yi Tee via cfe-commits

Author: Wei Yi Tee
Date: 2022-09-19T18:40:29Z
New Revision: 41d52c5a7f7ad1acf8e84ad6d7f04813c1a5a7ec

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

LOG: [clang][dataflow] Modify `transfer` in `DataflowModel` to take 
`CFGElement` as input instead of `Stmt`.

To keep API of transfer functions consistent.

The single use of this transfer function in `ChromiumCheckModel` is also 
updated.

Reviewed By: gribozavr2, sgatev

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index 098c13cf4e35a..cbd20ad9ee568 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -193,8 +193,8 @@ runDataflowAnalysis(
 /// example, a model may capture a type and its related functions.
 class DataflowModel : public Environment::ValueModel {
 public:
-  /// Return value indicates whether the model processed the `Stmt`.
-  virtual bool transfer(const Stmt *Stmt, Environment &Env) = 0;
+  /// Return value indicates whether the model processed the `Element`.
+  virtual bool transfer(const CFGElement *Element, Environment &Env) = 0;
 };
 
 } // namespace dataflow

diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h 
b/clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
index 93c427bd1ddc6..e65f40b0b726e 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
@@ -26,7 +26,7 @@ namespace dataflow {
 class ChromiumCheckModel : public DataflowModel {
 public:
   ChromiumCheckModel() = default;
-  bool transfer(const Stmt *Stmt, Environment &Env) override;
+  bool transfer(const CFGElement *Element, Environment &Env) override;
 
 private:
   /// Declarations for `::logging::CheckError::.*Check`, lazily initialized.

diff  --git a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
index 3910847316a59..f457964fb1324 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
@@ -50,7 +50,11 @@ bool isCheckLikeMethod(llvm::SmallDenseSet &CheckDecls,
   return CheckDecls.contains(&D);
 }
 
-bool ChromiumCheckModel::transfer(const Stmt *Stmt, Environment &Env) {
+bool ChromiumCheckModel::transfer(const CFGElement *Element, Environment &Env) 
{
+  auto CS = Element->getAs();
+  if (!CS)
+return false;
+  auto Stmt = CS->getStmt();
   if (const auto *Call = dyn_cast(Stmt)) {
 if (const auto *M = dyn_cast(Call->getDirectCallee())) {
   if (isCheckLikeMethod(CheckDecls, *M)) {

diff  --git a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
index 574366963bd67..1e149db9b44e7 100644
--- a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
@@ -119,9 +119,7 @@ class ModelAdaptorAnalysis
   static NoopLattice initialElement() { return NoopLattice(); }
 
   void transfer(const CFGElement *E, NoopLattice &, Environment &Env) {
-if (auto S = E->getAs()) {
-  M.transfer(S->getStmt(), Env);
-}
+M.transfer(E, Env);
   }
 
 private:



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


[PATCH] D133933: [clang][dataflow] Modify `transfer` in `DataflowModel` to take `CFGElement` as input instead of `Stmt`.

2022-09-19 Thread weiyi 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 rG41d52c5a7f7a: [clang][dataflow] Modify `transfer` in 
`DataflowModel` to take `CFGElement` as… (authored by wyt).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133933

Files:
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
  clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
  clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp


Index: clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
@@ -119,9 +119,7 @@
   static NoopLattice initialElement() { return NoopLattice(); }
 
   void transfer(const CFGElement *E, NoopLattice &, Environment &Env) {
-if (auto S = E->getAs()) {
-  M.transfer(S->getStmt(), Env);
-}
+M.transfer(E, Env);
   }
 
 private:
Index: clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
@@ -50,7 +50,11 @@
   return CheckDecls.contains(&D);
 }
 
-bool ChromiumCheckModel::transfer(const Stmt *Stmt, Environment &Env) {
+bool ChromiumCheckModel::transfer(const CFGElement *Element, Environment &Env) 
{
+  auto CS = Element->getAs();
+  if (!CS)
+return false;
+  auto Stmt = CS->getStmt();
   if (const auto *Call = dyn_cast(Stmt)) {
 if (const auto *M = dyn_cast(Call->getDirectCallee())) {
   if (isCheckLikeMethod(CheckDecls, *M)) {
Index: clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
===
--- clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
+++ clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
@@ -26,7 +26,7 @@
 class ChromiumCheckModel : public DataflowModel {
 public:
   ChromiumCheckModel() = default;
-  bool transfer(const Stmt *Stmt, Environment &Env) override;
+  bool transfer(const CFGElement *Element, Environment &Env) override;
 
 private:
   /// Declarations for `::logging::CheckError::.*Check`, lazily initialized.
Index: clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
===
--- clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -193,8 +193,8 @@
 /// example, a model may capture a type and its related functions.
 class DataflowModel : public Environment::ValueModel {
 public:
-  /// Return value indicates whether the model processed the `Stmt`.
-  virtual bool transfer(const Stmt *Stmt, Environment &Env) = 0;
+  /// Return value indicates whether the model processed the `Element`.
+  virtual bool transfer(const CFGElement *Element, Environment &Env) = 0;
 };
 
 } // namespace dataflow


Index: clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
@@ -119,9 +119,7 @@
   static NoopLattice initialElement() { return NoopLattice(); }
 
   void transfer(const CFGElement *E, NoopLattice &, Environment &Env) {
-if (auto S = E->getAs()) {
-  M.transfer(S->getStmt(), Env);
-}
+M.transfer(E, Env);
   }
 
 private:
Index: clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/ChromiumCheckModel.cpp
@@ -50,7 +50,11 @@
   return CheckDecls.contains(&D);
 }
 
-bool ChromiumCheckModel::transfer(const Stmt *Stmt, Environment &Env) {
+bool ChromiumCheckModel::transfer(const CFGElement *Element, Environment &Env) {
+  auto CS = Element->getAs();
+  if (!CS)
+return false;
+  auto Stmt = CS->getStmt();
   if (const auto *Call = dyn_cast(Stmt)) {
 if (const auto *M = dyn_cast(Call->getDirectCallee())) {
   if (isCheckLikeMethod(CheckDecls, *M)) {
Index: clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
===
--- clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
+++ clang/include/clang/Analysis/FlowSensitive/Models/ChromiumCheckModel.h
@@ -26,7 +26,7 @@
 class ChromiumCheckModel : public DataflowM

[PATCH] D134189: [CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode

2022-09-19 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 marked an inline comment as done.
jhuber6 added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:4391
 DDep.add(*PackagerAction, *C.getSingleOffloadToolChain(),
- nullptr, Action::OFK_None);
+ nullptr, C.getActiveOffloadKinds());
   }

tra wrote:
> `getActiveOffloadKinds` returns a mask of offload kinds, yet we cast it to 
> `OffloadKind` in `DeviceDependences::add` above. This mixing of OffloadKind 
> and sets of them looks questionable to me.
> 
> If we are relying on passing sets of `OffloadKind`now, then we should make it 
> clear in the code that it is the intent, including a more detailed 
> description that `DeviceOffloadKinds` is a list of `OffloadKind` sets, so 
> whoever iterates over elements does not attempt to compare its elements with 
> `OffloadKind` values. I think it would be helpful to change 
> `DeviceOffloadKinds` element type to a new class with a helper method 
> `hasOffloadKind(OffloadKind)` to avoid accidental comparison of a mask with 
> enum value.
> 
> 
Yeah I think I shouldn't mix the logic here. I updated it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134189

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


[PATCH] D134189: [CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode

2022-09-19 Thread Joseph Huber via Phabricator via cfe-commits
jhuber6 updated this revision to Diff 461286.
jhuber6 added a comment.

Mixing the concept of the mask passing via an `unsigned` and a single enum 
value was incorrect. Add a new interface that accepts a mask and adds all 
active values instead.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134189

Files:
  clang/include/clang/Driver/Action.h
  clang/lib/Driver/Action.cpp
  clang/lib/Driver/Driver.cpp
  clang/test/Driver/amdgpu-openmp-toolchain.c
  clang/test/Driver/cuda-bindings.cu
  clang/test/Driver/cuda-phases.cu
  clang/test/Driver/openmp-offload-gpu.c
  clang/test/Driver/openmp-offload.c

Index: clang/test/Driver/openmp-offload.c
===
--- clang/test/Driver/openmp-offload.c
+++ clang/test/Driver/openmp-offload.c
@@ -110,8 +110,8 @@
 // CHK-PHASES-NEXT: 7: backend, {6}, assembler, (device-openmp)
 // CHK-PHASES-NEXT: 8: assembler, {7}, object, (device-openmp)
 // CHK-PHASES-NEXT: 9: offload, "device-openmp (powerpc64-ibm-linux-gnu)" {8}, object
-// CHK-PHASES-NEXT: 10: clang-offload-packager, {9}, image
-// CHK-PHASES-NEXT: 11: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {2}, " (powerpc64-ibm-linux-gnu)" {10}, ir
+// CHK-PHASES-NEXT: 10: clang-offload-packager, {9}, image, (device-openmp)
+// CHK-PHASES-NEXT: 11: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {2}, "device-openmp (powerpc64-ibm-linux-gnu)" {10}, ir
 // CHK-PHASES-NEXT: 12: backend, {11}, assembler, (host-openmp)
 // CHK-PHASES-NEXT: 13: assembler, {12}, object, (host-openmp)
 // CHK-PHASES-NEXT: 14: clang-linker-wrapper, {13}, image, (host-openmp)
@@ -139,8 +139,8 @@
 // CHK-PHASES-FILES-NEXT: 15: backend, {14}, assembler, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 16: assembler, {15}, object, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 17: offload, "device-openmp (powerpc64-ibm-linux-gnu)" {16}, object
-// CHK-PHASES-FILES-NEXT: 18: clang-offload-packager, {10, 17}, image
-// CHK-PHASES-FILES-NEXT: 19: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {3}, " (powerpc64-ibm-linux-gnu)" {18}, ir
+// CHK-PHASES-FILES-NEXT: 18: clang-offload-packager, {10, 17}, image, (device-openmp)
+// CHK-PHASES-FILES-NEXT: 19: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {3}, "device-openmp (powerpc64-ibm-linux-gnu)" {18}, ir
 // CHK-PHASES-FILES-NEXT: 20: backend, {19}, assembler, (host-openmp)
 // CHK-PHASES-FILES-NEXT: 21: assembler, {20}, object, (host-openmp)
 // CHK-PHASES-FILES-NEXT: 22: input, "[[INPUT]]", c, (host-openmp)
@@ -160,8 +160,8 @@
 // CHK-PHASES-FILES-NEXT: 36: backend, {35}, assembler, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 37: assembler, {36}, object, (device-openmp)
 // CHK-PHASES-FILES-NEXT: 38: offload, "device-openmp (powerpc64-ibm-linux-gnu)" {37}, object
-// CHK-PHASES-FILES-NEXT: 39: clang-offload-packager, {31, 38}, image
-// CHK-PHASES-FILES-NEXT: 40: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {24}, " (powerpc64-ibm-linux-gnu)" {39}, ir
+// CHK-PHASES-FILES-NEXT: 39: clang-offload-packager, {31, 38}, image, (device-openmp)
+// CHK-PHASES-FILES-NEXT: 40: offload, "host-openmp (powerpc64-ibm-linux-gnu)" {24}, "device-openmp (powerpc64-ibm-linux-gnu)" {39}, ir
 // CHK-PHASES-FILES-NEXT: 41: backend, {40}, assembler, (host-openmp)
 // CHK-PHASES-FILES-NEXT: 42: assembler, {41}, object, (host-openmp)
 // CHK-PHASES-FILES-NEXT: 43: clang-linker-wrapper, {0, 21, 42}, image, (host-openmp)
Index: clang/test/Driver/openmp-offload-gpu.c
===
--- clang/test/Driver/openmp-offload-gpu.c
+++ clang/test/Driver/openmp-offload-gpu.c
@@ -258,7 +258,7 @@
 // CHECK-PHASES: 8: assembler, {7}, object, (device-openmp)
 // CHECK-PHASES: 9: offload, "device-openmp (nvptx64-nvidia-cuda)" {8}, object
 // CHECK-PHASES: 10: clang-offload-packager, {9}, image
-// CHECK-PHASES: 11: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, " (x86_64-unknown-linux-gnu)" {10}, ir
+// CHECK-PHASES: 11: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, "device-openmp (x86_64-unknown-linux-gnu)" {10}, ir
 // CHECK-PHASES: 12: backend, {11}, assembler, (host-openmp)
 // CHECK-PHASES: 13: assembler, {12}, object, (host-openmp)
 // CHECK-PHASES: 14: clang-linker-wrapper, {13}, image, (host-openmp)
Index: clang/test/Driver/cuda-phases.cu
===
--- clang/test/Driver/cuda-phases.cu
+++ clang/test/Driver/cuda-phases.cu
@@ -238,8 +238,8 @@
 // NEW-DRIVER-RDC-NEXT: 12: backend, {11}, assembler, (device-cuda, sm_70)
 // NEW-DRIVER-RDC-NEXT: 13: assembler, {12}, object, (device-cuda, sm_70)
 // NEW-DRIVER-RDC-NEXT: 14: offload, "device-cuda (nvptx64-nvidia-cuda:sm_70)" {13}, object
-// NEW-DRIVER-RDC-NEXT: 15: clang-offload-packager, {8, 14}, image
-// NEW-DRIVER-RDC-NEXT: 16: offload, " (powerpc64le-ibm-linux-gnu)" {2}, " (powerpc64le-ibm-linux-gnu)" {15}, ir
+// NEW-DRIVER-RDC

[PATCH] D133931: [clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `clang/Analysis/FlowSensitive`.

2022-09-19 Thread weiyi 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 rGcf94c52e35f2: [clang][dataflow] Replace `transfer(const Stmt 
*, ...)` with `transfer(const… (authored by wyt).

Changed prior to commit:
  https://reviews.llvm.org/D133931?vs=460350&id=461278#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133931

Files:
  clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h
  clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
  clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
  clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
  clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp
@@ -111,7 +111,7 @@
 
   static NonConvergingLattice initialElement() { return {0}; }
 
-  void transfer(const Stmt *S, NonConvergingLattice &E, Environment &Env) {
+  void transfer(const CFGElement *, NonConvergingLattice &E, Environment &) {
 ++E.State;
   }
 };
@@ -162,7 +162,11 @@
 
   static FunctionCallLattice initialElement() { return {}; }
 
-  void transfer(const Stmt *S, FunctionCallLattice &E, Environment &Env) {
+  void transfer(const CFGElement *Elt, FunctionCallLattice &E, Environment &) {
+auto CS = Elt->getAs();
+if (!CS)
+  return;
+auto S = CS->getStmt();
 if (auto *C = dyn_cast(S)) {
   if (auto *F = dyn_cast(C->getCalleeDecl())) {
 E.CalledFunctions.insert(F->getNameInfo().getAsString());
@@ -314,7 +318,11 @@
 
   static NoopLattice initialElement() { return {}; }
 
-  void transfer(const Stmt *S, NoopLattice &, Environment &Env) {
+  void transfer(const CFGElement *Elt, NoopLattice &, Environment &Env) {
+auto CS = Elt->getAs();
+if (!CS)
+  return;
+auto S = CS->getStmt();
 auto SpecialBoolRecordDecl = recordDecl(hasName("SpecialBool"));
 auto HasSpecialBoolType = hasType(SpecialBoolRecordDecl);
 
@@ -466,7 +474,11 @@
 
   static NoopLattice initialElement() { return {}; }
 
-  void transfer(const Stmt *S, NoopLattice &, Environment &Env) {
+  void transfer(const CFGElement *Elt, NoopLattice &, Environment &Env) {
+auto CS = Elt->getAs();
+if (!CS)
+  return;
+auto S = CS->getStmt();
 auto OptionalIntRecordDecl = recordDecl(hasName("OptionalInt"));
 auto HasOptionalIntType = hasType(OptionalIntRecordDecl);
 
Index: clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
@@ -19,10 +19,10 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
-#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/None.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
@@ -123,8 +123,12 @@
 return ConstantPropagationLattice::bottom();
   }
 
-  void transfer(const Stmt *S, ConstantPropagationLattice &Element,
+  void transfer(const CFGElement *E, ConstantPropagationLattice &Element,
 Environment &Env) {
+auto CS = E->getAs();
+if (!CS)
+  return;
+auto S = CS->getStmt();
 auto matcher = stmt(
 anyOf(declStmt(hasSingleDecl(varDecl(hasType(isInteger()),
  hasInitializer(expr().bind(kInit)))
Index: clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
@@ -132,8 +133,12 @@
 return ConstantPropagationLattice::bottom();
   }
 
-  void transfer(const Stmt *S, ConstantPropagationLattice &Vars,
+  void transfer(const CFGElement *E, ConstantPropagationLattice &Vars,

[clang] cf94c52 - [clang][dataflow] Replace `transfer(const Stmt *, ...)` with `transfer(const CFGElement *, ...)` in `clang/Analysis/FlowSensitive`.

2022-09-19 Thread Wei Yi Tee via cfe-commits

Author: Wei Yi Tee
Date: 2022-09-19T18:06:57Z
New Revision: cf94c52e35f2daf4e4caaeb93648f4b5413b557a

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

LOG: [clang][dataflow] Replace `transfer(const Stmt *, ...)` with 
`transfer(const CFGElement *, ...)` in `clang/Analysis/FlowSensitive`.

Reviewed By: gribozavr2, sgatev

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

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h
clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp

Removed: 




diff  --git a/clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h
index 4f05f5f4554bb..bf27ec3a58ddb 100644
--- a/clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/NoopAnalysis.h
@@ -14,7 +14,7 @@
 #define LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_NOOPANALYSIS_H
 
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/Stmt.h"
+#include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
@@ -38,7 +38,7 @@ class NoopAnalysis : public DataflowAnalysis {
 
   static NoopLattice initialElement() { return {}; }
 
-  void transfer(const Stmt *S, NoopLattice &E, Environment &Env) {}
+  void transfer(const CFGElement *E, NoopLattice &L, Environment &Env) {}
 };
 
 } // namespace dataflow

diff  --git a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
index ea171f7c1fbd9..574366963bd67 100644
--- a/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/ChromiumCheckModelTest.cpp
@@ -11,6 +11,7 @@
 #include "TestingSupport.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -117,8 +118,10 @@ class ModelAdaptorAnalysis
 
   static NoopLattice initialElement() { return NoopLattice(); }
 
-  void transfer(const Stmt *S, NoopLattice &, Environment &Env) {
-M.transfer(S, Env);
+  void transfer(const CFGElement *E, NoopLattice &, Environment &Env) {
+if (auto S = E->getAs()) {
+  M.transfer(S->getStmt(), Env);
+}
   }
 
 private:

diff  --git 
a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
index d2e774db5a3f4..39a1e1dd0859f 100644
--- a/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/MultiVarConstantPropagationTest.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
@@ -132,8 +133,12 @@ class ConstantPropagationAnalysis
 return ConstantPropagationLattice::bottom();
   }
 
-  void transfer(const Stmt *S, ConstantPropagationLattice &Vars,
+  void transfer(const CFGElement *E, ConstantPropagationLattice &Vars,
 Environment &Env) {
+auto CS = E->getAs();
+if (!CS)
+  return;
+auto S = CS->getStmt();
 auto matcher =
 stmt(anyOf(declStmt(hasSingleDecl(
varDecl(decl().bind(kVar), hasType(isInteger()),

diff  --git 
a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp 
b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
index 67c86f130c977..60b7860917899 100644
--- 
a/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
+++ 
b/clang/unittests/Analysis/FlowSensitive/SingleVarConstantPropagationTest.cpp
@@ -19,10 +19,10 @@
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
 #include "clang/Analysis/FlowSensitive/DataflowLattice.h"
-#include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/None.h"
 #in

[PATCH] D133890: [CMake] Do these replacements to make use of D132608

2022-09-19 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added a comment.

I don't see anything wrong with this change per se, but I'm conflicted on the 
name of the variable.  These are not standard variables but are encroaching on 
the CMake namespace.  What happens if upstream decides to use these names?  I 
think that we should keep the names in the `LLVM_` namespace.  However, I 
realize that the variable itself is not being touched here and this is a 
mechanical replacement.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133890

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


[PATCH] D133993: [HLSL] Remove global ctor/dtor variable for non-lib profile.

2022-09-19 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 461271.
python3kgae added a comment.
Herald added a reviewer: aaron.ballman.

Add test for dtor in lib.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133993

Files:
  clang/lib/CodeGen/CGHLSLRuntime.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
  clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
  clang/test/CodeGenHLSL/GlobalConstructors.hlsl
  clang/test/CodeGenHLSL/GlobalDestructors.hlsl
  clang/test/CodeGenHLSL/GlobalDestructorsLib.hlsl

Index: clang/test/CodeGenHLSL/GlobalDestructorsLib.hlsl
===
--- clang/test/CodeGenHLSL/GlobalDestructorsLib.hlsl
+++ clang/test/CodeGenHLSL/GlobalDestructorsLib.hlsl
@@ -1,4 +1,7 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -std=hlsl202x -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -std=hlsl202x -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
+
+// Make sure global variable for dtors exist for lib profile.
+// CHECK:@llvm.global_dtors
 
 struct Tail {
   Tail() {
@@ -39,9 +42,10 @@
   Wag();
 }
 
+
 //CHECK:  define void @main()
 //CHECK-NEXT: entry:
-//CHECK-NEXT:   call void @_GLOBAL__sub_I_GlobalDestructors.hlsl()
+//CHECK-NEXT:   call void @_GLOBAL__sub_I_GlobalDestructorsLib.hlsl()
 //CHECK-NEXT:   %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
 //CHECK-NEXT:   call void @"?main@@YAXI@Z"(i32 %0)
 //CHECK-NEXT:   call void @_GLOBAL__D_a()
Index: clang/test/CodeGenHLSL/GlobalDestructors.hlsl
===
--- clang/test/CodeGenHLSL/GlobalDestructors.hlsl
+++ clang/test/CodeGenHLSL/GlobalDestructors.hlsl
@@ -39,6 +39,9 @@
   Wag();
 }
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
 //CHECK:  define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @_GLOBAL__sub_I_GlobalDestructors.hlsl()
Index: clang/test/CodeGenHLSL/GlobalConstructors.hlsl
===
--- clang/test/CodeGenHLSL/GlobalConstructors.hlsl
+++ clang/test/CodeGenHLSL/GlobalConstructors.hlsl
@@ -5,6 +5,9 @@
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {}
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
 //CHECK:  define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @_GLOBAL__sub_I_GlobalConstructors.hlsl()
Index: clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
===
--- clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
+++ clang/test/CodeGenHLSL/GlobalConstructorLib.hlsl
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -S -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s
 
+// Make sure global variable for ctors exist for lib profile.
+// CHECK:@llvm.global_ctors
+
 RWBuffer Buffer;
 
 [shader("compute")]
Index: clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
===
--- clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
+++ clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
@@ -17,6 +17,10 @@
 [numthreads(1,1,1)]
 void main(unsigned GI : SV_GroupIndex) {}
 
+// Make sure global variable for ctors/dtors removed.
+// CHECK-NOT:@llvm.global_ctors
+// CHECK-NOT:@llvm.global_dtors
+
 //CHECK: define void @main()
 //CHECK-NEXT: entry:
 //CHECK-NEXT:   call void @"?call_me_first@@YAXXZ"()
Index: clang/lib/Sema/SemaDeclAttr.cpp
===
--- clang/lib/Sema/SemaDeclAttr.cpp
+++ clang/lib/Sema/SemaDeclAttr.cpp
@@ -6895,7 +6895,10 @@
 static void handleHLSLSVGroupIndexAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
   using llvm::Triple;
   Triple Target = S.Context.getTargetInfo().getTriple();
-  if (Target.getEnvironment() != Triple::Compute) {
+  if (Target.getEnvironment() != Triple::Compute &&
+  Target.getEnvironment() != Triple::Library) {
+// FIXME: it is OK for a compute shader entry and pixel shader entry live in
+// same HLSL file.
 uint32_t Pipeline =
 (uint32_t)S.Context.getTargetInfo().getTriple().getEnvironment() -
 (uint32_t)llvm::Triple::Pixel;
Index: clang/lib/CodeGen/CGHLSLRuntime.cpp
===
--- clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -202,4 +202,14 @@
 for (auto *Fn : DtorFns)
   B.CreateCall(FunctionCallee(Fn));
   }
+
+  // No need to keep global ctors/dtors for non-lib profile after call to
+  // ctors/dtors added for entry.
+  Triple T(M.getTargetTriple());
+  if (T.getEnvironment() != T

[PATCH] D134189: [CUDA][HIP] Fix new driver crashing when using -save-temps in RDC-mode

2022-09-19 Thread Artem Belevich via Phabricator via cfe-commits
tra added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:4391
 DDep.add(*PackagerAction, *C.getSingleOffloadToolChain(),
- nullptr, Action::OFK_None);
+ nullptr, C.getActiveOffloadKinds());
   }

`getActiveOffloadKinds` returns a mask of offload kinds, yet we cast it to 
`OffloadKind` in `DeviceDependences::add` above. This mixing of OffloadKind and 
sets of them looks questionable to me.

If we are relying on passing sets of `OffloadKind`now, then we should make it 
clear in the code that it is the intent, including a more detailed description 
that `DeviceOffloadKinds` is a list of `OffloadKind` sets, so whoever iterates 
over elements does not attempt to compare its elements with `OffloadKind` 
values. I think it would be helpful to change `DeviceOffloadKinds` element type 
to a new class with a helper method `hasOffloadKind(OffloadKind)` to avoid 
accidental comparison of a mask with enum value.




Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134189

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


[clang] 7538b36 - [clang][dataflow] Replace usage of deprecated functions with the optional check

2022-09-19 Thread Wei Yi Tee via cfe-commits

Author: Wei Yi Tee
Date: 2022-09-19T17:33:25Z
New Revision: 7538b3604519b03d32221cdcc346cc1c181b50fb

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

LOG: [clang][dataflow] Replace usage of deprecated functions with the optional 
check

- Update `transfer` and `diagnose` to take `const CFGElement *` as input in 
`Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel`.
- Update 
`clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp` 
accordingly.
- Rename `runDataflowAnalysisOnCFG` to `runDataflowAnalysis` and remove the 
deprecated `runDataflowAnalysis` (this was only used by the now updated 
optional check).

Reviewed By: gribozavr2, sgatev

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

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h

clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
index 5ee1a0126b232..b2f6b9ed62843 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
@@ -59,12 +59,11 @@ analyzeFunction(const FunctionDecl &FuncDecl, ASTContext 
&ASTCtx) {
   BlockToOutputState = dataflow::runDataflowAnalysis(
   *Context, Analysis, Env,
   [&ASTCtx, &Diagnoser, &Diagnostics](
-  const CFGStmt &Stmt,
+  const CFGElement &Elt,
   const 
DataflowAnalysisState
   &State) mutable {
-auto StmtDiagnostics =
-Diagnoser.diagnose(ASTCtx, Stmt.getStmt(), State.Env);
-llvm::move(StmtDiagnostics, std::back_inserter(Diagnostics));
+auto EltDiagnostics = Diagnoser.diagnose(ASTCtx, &Elt, State.Env);
+llvm::move(EltDiagnostics, std::back_inserter(Diagnostics));
   });
   if (!BlockToOutputState)
 return llvm::None;

diff  --git a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
index 4e084d57ba011..098c13cf4e35a 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
@@ -136,9 +136,6 @@ template  struct DataflowAnalysisState {
   Environment Env;
 };
 
-// FIXME: Rename to `runDataflowAnalysis` after usages of the overload that
-// applies to `CFGStmt` have been replaced.
-//
 /// Performs dataflow analysis and returns a mapping from basic block IDs to
 /// dataflow analysis states that model the respective basic blocks. The
 /// returned vector, if any, will have the same size as the number of CFG
@@ -149,7 +146,7 @@ template  struct DataflowAnalysisState {
 template 
 llvm::Expected>>>
-runDataflowAnalysisOnCFG(
+runDataflowAnalysis(
 const ControlFlowContext &CFCtx, AnalysisT &Analysis,
 const Environment &InitEnv,
 std::function
-llvm::Expected>>>
-runDataflowAnalysis(
-const ControlFlowContext &CFCtx, AnalysisT &Analysis,
-const Environment &InitEnv,
-std::function &)>
-PostVisitStmt = nullptr) {
-  std::function &)>
-  PostVisitCFG = nullptr;
-  if (PostVisitStmt) {
-PostVisitCFG =
-[&PostVisitStmt](
-const CFGElement &Element,
-const DataflowAnalysisState &State) {
-  if (auto Stmt = Element.getAs()) {
-PostVisitStmt(*Stmt, State);
-  }
-};
-  }
-  return runDataflowAnalysisOnCFG(CFCtx, Analysis, InitEnv, PostVisitCFG);
-}
-
 /// Abstract base class for dataflow "models": reusable analysis components 
that
 /// model a particular aspect of program semantics in the `Environment`. For
 /// example, a model may capture a type and its related functions.

diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
index 25054deaf8afc..66aabb531a213 100644
--- 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
+++ 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
@@ -15,10 +15,10 @@
 #define CLANG_ANALYSIS_FLOWSENSITIVE_MODELS_UNCHECKEDOPTIONALACCESSMODEL_H
 
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/Stmt.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowS

[PATCH] D133930: [clang][dataflow] Replace usage of deprecated functions with the optional check

2022-09-19 Thread weiyi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7538b3604519: [clang][dataflow] Replace usage of deprecated 
functions with the optional check (authored by wyt).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133930

Files:
  clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
  clang/include/clang/Analysis/FlowSensitive/DataflowAnalysis.h
  
clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
  clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
  clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp

Index: clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
===
--- clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
+++ clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp
@@ -14,10 +14,8 @@
 #include "clang/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Tooling/Tooling.h"
-#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/StringExtras.h"
 #include "llvm/Support/Error.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
@@ -1248,13 +1246,9 @@
  Diagnoser = UncheckedOptionalAccessDiagnoser(Options)](
 ASTContext &Ctx, const CFGElement &Elt,
 const TypeErasedDataflowAnalysisState &State) mutable {
-  auto Stmt = Elt.getAs();
-  if (!Stmt) {
-return;
-  }
-  auto StmtDiagnostics =
-  Diagnoser.diagnose(Ctx, Stmt->getStmt(), State.Env);
-  llvm::move(StmtDiagnostics, std::back_inserter(Diagnostics));
+  auto EltDiagnostics =
+  Diagnoser.diagnose(Ctx, &Elt, State.Env);
+  llvm::move(EltDiagnostics, std::back_inserter(Diagnostics));
 })
 .withASTBuildArgs(
 {"-fsyntax-only", "-std=c++17", "-Wno-undefined-inline"})
Index: clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
===
--- clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -18,8 +18,9 @@
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Stmt.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Analysis/CFG.h"
+#include "clang/Analysis/FlowSensitive/CFGMatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
-#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
 #include "clang/Analysis/FlowSensitive/Value.h"
 #include "clang/Basic/SourceLocation.h"
@@ -559,41 +560,42 @@
   // lot of duplicated work (e.g. string comparisons), consider providing APIs
   // that avoid it through memoization.
   auto IgnorableOptional = ignorableOptional(Options);
-  return MatchSwitchBuilder()
+  return CFGMatchSwitchBuilder()
   // Attach a symbolic "has_value" state to optional values that we see for
   // the first time.
-  .CaseOf(
+  .CaseOfCFGStmt(
   expr(anyOf(declRefExpr(), memberExpr()), hasOptionalType()),
   initializeOptionalReference)
 
   // make_optional
-  .CaseOf(isMakeOptionalCall(), transferMakeOptionalCall)
+  .CaseOfCFGStmt(isMakeOptionalCall(), transferMakeOptionalCall)
 
   // optional::optional
-  .CaseOf(
+  .CaseOfCFGStmt(
   isOptionalInPlaceConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState &State) {
 assignOptionalValue(*E, State, State.Env.getBoolLiteralValue(true));
   })
-  .CaseOf(
+  .CaseOfCFGStmt(
   isOptionalNulloptConstructor(),
   [](const CXXConstructExpr *E, const MatchFinder::MatchResult &,
  LatticeTransferState &State) {
 assignOptionalValue(*E, State,
 State.Env.getBoolLiteralValue(false));
   })
-  .CaseOf(isOptionalValueOrConversionConstructor(),
-transferValueOrConversionConstructor)
+  .CaseOfCFGStmt(isOptionalValueOrConversionConstructor(),
+   transferValueOrConversionConstructor)
 
   // optional::operator=
-  .CaseOf(isOptionalValueOrConversionAssignment(),
-   transferValueOrConversionAssignment)
-  .CaseOf(isOptionalNulloptAssignment(),
-   transferNulloptAssignment)
+  .CaseOfCFGStmt(
+  isOpti

[PATCH] D134055: [clang-doc] Add support for explicitly typed enums

2022-09-19 Thread Paul Kirth via Phabricator via cfe-commits
paulkirth accepted this revision.
paulkirth added a comment.
This revision is now accepted and ready to land.

LGTM.


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

https://reviews.llvm.org/D134055

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


[clang] e782d9a - [clang] Fix a nullptr-access crash in CheckTemplateArgument.

2022-09-19 Thread Haojian Wu via cfe-commits

Author: Haojian Wu
Date: 2022-09-19T19:18:50+02:00
New Revision: e782d9a4a49c8aaf65bea4209cb6a8e7739526ac

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

LOG: [clang] Fix a nullptr-access crash in CheckTemplateArgument.

It is possible that we can pass a null ParamType to
CheckNonTypeTemplateParameter -- the ParamType var can be reset to a null
type on Line 6940, and the followed bailout if is not entered.

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index adca91b0ae63e..e0f913e395771 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -6949,7 +6949,10 @@ ExprResult 
Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
  // along with the other associated constraints after
  // checking the template argument list.
  /*IgnoreConstraints=*/true);
-  if (Result != TDK_Success && Result != TDK_AlreadyDiagnosed) {
+  if (Result == TDK_AlreadyDiagnosed) {
+if (ParamType.isNull())
+  return ExprError();
+  } else if (Result != TDK_Success) {
 Diag(Arg->getExprLoc(),
  diag::err_non_type_template_parm_type_deduction_failure)
 << Param->getDeclName() << Param->getType() << Arg->getType()

diff  --git a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp 
b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
index 8c290cb69772d..24c486cb35ad3 100644
--- a/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ b/clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -558,3 +558,24 @@ namespace TypeSuffix {
   X<1, 1u>::type y; // expected-error {{no type named 'type' in 
'TypeSuffix::X<1, 1U>'}}
   X<1, 1>::type z; // expected-error {{no type named 'type' in 
'TypeSuffix::X<1, 1>'}}
 }
+
+namespace no_crash {
+template 
+class Base {
+public:
+  template  class EntryPointSpec {};
+  template 
+  using EntryPoint = EntryPointSpec;
+};
+
+class Derived : Base{
+  template  class Spec {};
+
+  void Invalid(Undefined) const; // expected-error {{unknown type name 
'Undefined'}}
+  void crash() {
+return Spec{
+EntryPoint<&Invalid>()
+};
+  }
+};
+} // no_crash



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


[PATCH] D134180: [clang] Fix a nullptr-access crash in CheckTemplateArgument.

2022-09-19 Thread Haojian Wu 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 rGe782d9a4a49c: [clang] Fix a nullptr-access crash in 
CheckTemplateArgument. (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134180

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp


Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -558,3 +558,24 @@
   X<1, 1u>::type y; // expected-error {{no type named 'type' in 
'TypeSuffix::X<1, 1U>'}}
   X<1, 1>::type z; // expected-error {{no type named 'type' in 
'TypeSuffix::X<1, 1>'}}
 }
+
+namespace no_crash {
+template 
+class Base {
+public:
+  template  class EntryPointSpec {};
+  template 
+  using EntryPoint = EntryPointSpec;
+};
+
+class Derived : Base{
+  template  class Spec {};
+
+  void Invalid(Undefined) const; // expected-error {{unknown type name 
'Undefined'}}
+  void crash() {
+return Spec{
+EntryPoint<&Invalid>()
+};
+  }
+};
+} // no_crash
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -6949,7 +6949,10 @@
  // along with the other associated constraints after
  // checking the template argument list.
  /*IgnoreConstraints=*/true);
-  if (Result != TDK_Success && Result != TDK_AlreadyDiagnosed) {
+  if (Result == TDK_AlreadyDiagnosed) {
+if (ParamType.isNull())
+  return ExprError();
+  } else if (Result != TDK_Success) {
 Diag(Arg->getExprLoc(),
  diag::err_non_type_template_parm_type_deduction_failure)
 << Param->getDeclName() << Param->getType() << Arg->getType()


Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -558,3 +558,24 @@
   X<1, 1u>::type y; // expected-error {{no type named 'type' in 'TypeSuffix::X<1, 1U>'}}
   X<1, 1>::type z; // expected-error {{no type named 'type' in 'TypeSuffix::X<1, 1>'}}
 }
+
+namespace no_crash {
+template 
+class Base {
+public:
+  template  class EntryPointSpec {};
+  template 
+  using EntryPoint = EntryPointSpec;
+};
+
+class Derived : Base{
+  template  class Spec {};
+
+  void Invalid(Undefined) const; // expected-error {{unknown type name 'Undefined'}}
+  void crash() {
+return Spec{
+EntryPoint<&Invalid>()
+};
+  }
+};
+} // no_crash
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -6949,7 +6949,10 @@
  // along with the other associated constraints after
  // checking the template argument list.
  /*IgnoreConstraints=*/true);
-  if (Result != TDK_Success && Result != TDK_AlreadyDiagnosed) {
+  if (Result == TDK_AlreadyDiagnosed) {
+if (ParamType.isNull())
+  return ExprError();
+  } else if (Result != TDK_Success) {
 Diag(Arg->getExprLoc(),
  diag::err_non_type_template_parm_type_deduction_failure)
 << Param->getDeclName() << Param->getType() << Arg->getType()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134180: [clang] Fix a nullptr-access crash in CheckTemplateArgument.

2022-09-19 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang/lib/Sema/SemaTemplate.cpp:6960
+if (ParamType.isNull())
+  return ExprError();
 // CheckNonTypeTemplateParameterType will produce a diagnostic if there's

adamcz wrote:
> So this can only happen when Result is TDK_AlreadyDiagnosed above, right? In 
> that case, I would handle such case explicitly in the code above, like:
> if (Result == TDK_AlreadyDiagnosed) return ExprError();
> else if (Result != TDK_Success) { ... }
> Seems like it would be more readable. 
> 
> However, I am definitely not opposed to keeping this check here as well, in 
> case there are other ways to get into this situation.
right. I think either of them works, switched to your version. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134180

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


[PATCH] D134180: [clang] Fix a nullptr-access crash in CheckTemplateArgument.

2022-09-19 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 461260.
hokein marked an inline comment as done.
hokein added a comment.

address review comment.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134180

Files:
  clang/lib/Sema/SemaTemplate.cpp
  clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp


Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -558,3 +558,24 @@
   X<1, 1u>::type y; // expected-error {{no type named 'type' in 
'TypeSuffix::X<1, 1U>'}}
   X<1, 1>::type z; // expected-error {{no type named 'type' in 
'TypeSuffix::X<1, 1>'}}
 }
+
+namespace no_crash {
+template 
+class Base {
+public:
+  template  class EntryPointSpec {};
+  template 
+  using EntryPoint = EntryPointSpec;
+};
+
+class Derived : Base{
+  template  class Spec {};
+
+  void Invalid(Undefined) const; // expected-error {{unknown type name 
'Undefined'}}
+  void crash() {
+return Spec{
+EntryPoint<&Invalid>()
+};
+  }
+};
+} // no_crash
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -6949,7 +6949,10 @@
  // along with the other associated constraints after
  // checking the template argument list.
  /*IgnoreConstraints=*/true);
-  if (Result != TDK_Success && Result != TDK_AlreadyDiagnosed) {
+  if (Result == TDK_AlreadyDiagnosed) {
+if (ParamType.isNull())
+  return ExprError();
+  } else if (Result != TDK_Success) {
 Diag(Arg->getExprLoc(),
  diag::err_non_type_template_parm_type_deduction_failure)
 << Param->getDeclName() << Param->getType() << Arg->getType()


Index: clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
===
--- clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
+++ clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp
@@ -558,3 +558,24 @@
   X<1, 1u>::type y; // expected-error {{no type named 'type' in 'TypeSuffix::X<1, 1U>'}}
   X<1, 1>::type z; // expected-error {{no type named 'type' in 'TypeSuffix::X<1, 1>'}}
 }
+
+namespace no_crash {
+template 
+class Base {
+public:
+  template  class EntryPointSpec {};
+  template 
+  using EntryPoint = EntryPointSpec;
+};
+
+class Derived : Base{
+  template  class Spec {};
+
+  void Invalid(Undefined) const; // expected-error {{unknown type name 'Undefined'}}
+  void crash() {
+return Spec{
+EntryPoint<&Invalid>()
+};
+  }
+};
+} // no_crash
Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -6949,7 +6949,10 @@
  // along with the other associated constraints after
  // checking the template argument list.
  /*IgnoreConstraints=*/true);
-  if (Result != TDK_Success && Result != TDK_AlreadyDiagnosed) {
+  if (Result == TDK_AlreadyDiagnosed) {
+if (ParamType.isNull())
+  return ExprError();
+  } else if (Result != TDK_Success) {
 Diag(Arg->getExprLoc(),
  diag::err_non_type_template_parm_type_deduction_failure)
 << Param->getDeclName() << Param->getType() << Arg->getType()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134055: [clang-doc] Add support for explicitly typed enums

2022-09-19 Thread Brett Wilson via Phabricator via cfe-commits
brettw added inline comments.



Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:53
 
+llvm::Error decodeRecord(const Record &R, llvm::APSInt &Field, llvm::StringRef 
Blob) {
+  auto ByteWidth = R[0];

paulkirth wrote:
> brettw wrote:
> > paulkirth wrote:
> > > do you need to do all of this? APSInt already supports to/from string 
> > > methods, as well as converting to/from integers. can you use that here 
> > > and in the writer to avoid some complexity?
> > I don't think converting to an integer is a good idea because people 
> > sometimes use min/max values for enum values and since this could be signed 
> > or unsigned, it gets kind of complicated.
> > 
> > Serializing a number as a string to bitcode also seemed wrong to me.
> > 
> > The simplest thing would be to store the value as a string in the 
> > EnumValueInfo and then always treat this as a string from then on. If you 
> > want it simplified, I think that's the thing to do. But I thought you would 
> > want the numeric value stored in clang-doc's "ast" because some backends 
> > may want to treat this as a number, check its signed/unsignedness, etc. I 
> > happy to change this if you want.
> Those are fair points, and I think I misread/misunderstood a bit of what's 
> going on here.
> 
> As for encoding/decoding integers,  BitcodeWriter already has integer 
> support, so if you need to convert to/from those, it should already work, 
> right?
> 
> Regardless, you may want to look at the bitcode reader/writer in llvm to see 
> how they serialize/deserialize APInt, as their implementation seems a bit 
> more straightforward IMO.
> 
> https://github.com/llvm/llvm-project/blob/9050a59c6678789831b7286b8b68d18b966c4694/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L1636
> https://github.com/llvm/llvm-project/blob/main/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L2520
> https://github.com/llvm/llvm-project/blob/9050a59c6678789831b7286b8b68d18b966c4694/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L2843
> https://github.com/llvm/llvm-project/blob/9050a59c6678789831b7286b8b68d18b966c4694/llvm/lib/Bitcode/Reader/BitcodeReader.cpp#L2743
I just converted everything to a string which allowed most of this code to be 
deleted. I don't think any theoretical benefit of keeping the APSInt is worth 
the complexity.



Comment at: clang-tools-extra/clang-doc/BitcodeReader.cpp:71
+
+  llvm::SmallVector AsWords;
+  AsWords.resize(WordWidth);

paulkirth wrote:
> You can avoid the resize w/ SmallVector(Size) constructor, right?
This is now deleted.



Comment at: clang-tools-extra/clang-doc/Representation.h:425
+  // constant. This will be empty for implicit enumeration values.
+  std::string ValueExpr;
+};

paulkirth wrote:
> Sorry to nitpick, but SmallString was the correct choice to use in this type. 
> We avoid its use as a return value, because it tends to be brittle, and stops 
> us from assigning into arbitrary sized SmallStrings.  In the struct, it's a 
> reasonable choice, especially if you expect most uses to be small.  for these 
> expressions, I expect most to either be the number itself, or some shift 
> operation, so SmallString<16> was probably more than sufficient.
In the common case there will be will be empty, so std::string actually seems 
more efficient. Also, I personally think the current quantity of SmallString in 
this code is over-optimization.


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

https://reviews.llvm.org/D134055

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


[PATCH] D134055: [clang-doc] Add support for explicitly typed enums

2022-09-19 Thread Brett Wilson via Phabricator via cfe-commits
brettw updated this revision to Diff 461259.
brettw marked an inline comment as done.

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

https://reviews.llvm.org/D134055

Files:
  clang-tools-extra/clang-doc/BitcodeReader.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.cpp
  clang-tools-extra/clang-doc/BitcodeWriter.h
  clang-tools-extra/clang-doc/HTMLGenerator.cpp
  clang-tools-extra/clang-doc/MDGenerator.cpp
  clang-tools-extra/clang-doc/Representation.h
  clang-tools-extra/clang-doc/Serialize.cpp
  clang-tools-extra/clang-doc/YAMLGenerator.cpp
  clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -256,7 +256,11 @@
   EXPECT_EQ(Expected, Actual.str());
 }
 
-TEST(YAMLGeneratorTest, emitEnumYAML) {
+// Tests the equivalent of:
+// namespace A {
+// enum e { X };
+// }
+TEST(YAMLGeneratorTest, emitSimpleEnumYAML) {
   EnumInfo I;
   I.Name = "e";
   I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
@@ -265,7 +269,7 @@
   I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
 
   I.Members.emplace_back("X");
-  I.Scoped = true;
+  I.Scoped = false;
 
   auto G = getYAMLGenerator();
   assert(G);
@@ -286,9 +290,42 @@
 Location:
   - LineNumber:  12
 Filename:'test.cpp'
+Members:
+  - Name:'X'
+Value:   '0'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+// Tests the equivalent of:
+// enum class e : short { X = FOO_BAR + 2 };
+TEST(YAMLGeneratorTest, enumTypedScopedEnumYAML) {
+  EnumInfo I;
+  I.Name = "e";
+
+  I.Members.emplace_back("X", "-9876", "FOO_BAR + 2");
+  I.Scoped = true;
+  I.BaseType = TypeInfo("short");
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual, ClangDocContext());
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'e'
 Scoped:  true
+BaseType:
+  Type:
+Name:'short'
 Members:
-  - 'X'
+  - Name:'X'
+Value:   '-9876'
+Expr:'FOO_BAR + 2'
 ...
 )raw";
   EXPECT_EQ(Expected, Actual.str());
Index: clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
===
--- clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
+++ clang-tools-extra/unittests/clang-doc/SerializeTest.cpp
@@ -266,8 +266,8 @@
   EnumInfo E;
   E.Name = "E";
   E.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  E.Members.emplace_back("X");
-  E.Members.emplace_back("Y");
+  E.Members.emplace_back("X", "0");
+  E.Members.emplace_back("Y", "1");
   ExpectedNamespaceWithEnum.ChildEnums.emplace_back(std::move(E));
   CheckNamespaceInfo(&ExpectedNamespaceWithEnum, NamespaceWithEnum);
 
@@ -277,8 +277,8 @@
   G.Name = "G";
   G.Scoped = true;
   G.DefLoc = Location(0, llvm::SmallString<16>{"test.cpp"});
-  G.Members.emplace_back("A");
-  G.Members.emplace_back("B");
+  G.Members.emplace_back("A", "0");
+  G.Members.emplace_back("B", "1");
   ExpectedNamespaceWithScopedEnum.ChildEnums.emplace_back(std::move(G));
   CheckNamespaceInfo(&ExpectedNamespaceWithScopedEnum, NamespaceWithScopedEnum);
 }
Index: clang-tools-extra/clang-doc/YAMLGenerator.cpp
===
--- clang-tools-extra/clang-doc/YAMLGenerator.cpp
+++ clang-tools-extra/clang-doc/YAMLGenerator.cpp
@@ -14,6 +14,7 @@
 
 using namespace clang::doc;
 
+// These define YAML traits for decoding the listed values within a vector.
 LLVM_YAML_IS_SEQUENCE_VECTOR(FieldTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(MemberTypeInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(Reference)
@@ -21,6 +22,7 @@
 LLVM_YAML_IS_SEQUENCE_VECTOR(CommentInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(EnumInfo)
+LLVM_YAML_IS_SEQUENCE_VECTOR(EnumValueInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(BaseRecordInfo)
 LLVM_YAML_IS_SEQUENCE_VECTOR(std::unique_ptr)
 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::SmallString<16>)
@@ -226,10 +228,19 @@
   }
 };
 
+template <> struct MappingTraits {
+  static void mapping(IO &IO, EnumValueInfo &I) {
+IO.mapOptional("Name", I.Name);
+IO.mapOptional("Value", I.Value);
+IO.mapOptional("Expr", I.ValueExpr, SmallString<16>());
+  }
+};
+
 template <> struct MappingTraits {
   static void mapping(IO &IO, EnumInfo &I) {
 SymbolInfoMapping(IO, I);
 IO.mapOptional("Scoped", I.Scoped, false);
+IO.mapOptional("BaseType", I.BaseType);
 IO.mapOptional("Members", I.Members);
   }
 };
Index: clang-tools-extra/clang-doc/Serialize.cpp
=

[PATCH] D134127: [ARM] Check target feature support for __builtin_arm_crc*

2022-09-19 Thread Fangrui Song via Phabricator via cfe-commits
MaskRay added a comment.

In D134127#3798442 , @dmgreen wrote:

> This looks like a subset of D133359 ?

D133359  looks like it is for AArch64 and may 
change the diagnostic in a more aggressive way.
This patch seems to be in a suitable granule to fix just this clang crash 
problem for AArch32...


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134127

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


[clang-tools-extra] 8edce2f - [test][clangd] Join back -Xclang and -undef

2022-09-19 Thread Vitaly Buka via cfe-commits

Author: Vitaly Buka
Date: 2022-09-19T10:11:37-07:00
New Revision: 8edce2ff049d2fc635fc20c658daa283661a9958

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

LOG: [test][clangd] Join back -Xclang and -undef

Added: 


Modified: 
clang-tools-extra/clangd/unittests/TestTU.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/TestTU.cpp 
b/clang-tools-extra/clangd/unittests/TestTU.cpp
index f7d294ca2c26..03f1cd77191d 100644
--- a/clang-tools-extra/clangd/unittests/TestTU.cpp
+++ b/clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -40,12 +40,14 @@ ParseInputs TestTU::inputs(MockFS &FS) const {
   ParseInputs Inputs;
   Inputs.FeatureModules = FeatureModules;
   auto &Argv = Inputs.CompileCommand.CommandLine;
-  Argv = {"clang", "-Xclang"};
+  Argv = {"clang"};
   // In tests, unless explicitly specified otherwise, omit predefined macros
   // (__GNUC__ etc) for a 25% speedup. There are hundreds, and we'd generate,
   // parse, serialize, and re-parse them!
-  if (!PredefineMacros)
+  if (!PredefineMacros) {
+Argv.push_back("-Xclang");
 Argv.push_back("-undef");
+  }
   // FIXME: this shouldn't need to be conditional, but it breaks a
   // GoToDefinition test for some reason (getMacroArgExpandedLocation fails).
   if (!HeaderCode.empty()) {



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


[PATCH] D133668: [HLSL] Use _BitInt(16) for int16_t to avoid promote to int.

2022-09-19 Thread Xiang Li via Phabricator via cfe-commits
python3kgae updated this revision to Diff 461251.
python3kgae added a comment.

Rebase and update test.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133668

Files:
  clang/lib/Basic/Targets/DirectX.h
  clang/lib/Headers/hlsl/hlsl_basic_types.h
  clang/test/CodeGenHLSL/basic_types.hlsl
  clang/test/CodeGenHLSL/builtins/abs.hlsl
  clang/test/CodeGenHLSL/int16_t_add.hlsl


Index: clang/test/CodeGenHLSL/int16_t_add.hlsl
===
--- /dev/null
+++ clang/test/CodeGenHLSL/int16_t_add.hlsl
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -D__HLSL_ENABLE_16_BIT \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+
+// Make sure generate i16 add.
+// CHECK: add nsw i16 %
+int16_t add(int16_t a, int16_t b) {
+  return a + b;
+}
+// CHECK: define noundef <2 x i16> @
+// CHECK: add <2 x i16>
+int16_t2 add(int16_t2 a, int16_t2 b) {
+  return a + b;
+}
+// CHECK: define noundef <3 x i16> @
+// CHECK: add <3 x i16>
+int16_t3 add(int16_t3 a, int16_t3 b) {
+  return a + b;
+}
+// CHECK: define noundef <4 x i16> @
+// CHECK: add <4 x i16>
+int16_t4 add(int16_t4 a, int16_t4 b) {
+  return a + b;
+}
Index: clang/test/CodeGenHLSL/builtins/abs.hlsl
===
--- clang/test/CodeGenHLSL/builtins/abs.hlsl
+++ clang/test/CodeGenHLSL/builtins/abs.hlsl
@@ -7,8 +7,7 @@
 
 
 // CHECK: define noundef signext i16 @
-// FIXME: int16_t is promoted to i32 now. Change to abs.i16 once it is fixed.
-// CHECK: call i32 @llvm.abs.i32(
+// CHECK: call i16 @llvm.abs.i16(
 int16_t test_abs_int16_t ( int16_t p0 ) {
   return abs ( p0 );
 }
Index: clang/test/CodeGenHLSL/basic_types.hlsl
===
--- clang/test/CodeGenHLSL/basic_types.hlsl
+++ clang/test/CodeGenHLSL/basic_types.hlsl
@@ -3,17 +3,17 @@
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s
 
 
-// CHECK:"?uint16_t_Val@@3GA" = global i16 0, align 2
-// CHECK:"?int16_t_Val@@3FA" = global i16 0, align 2
+// CHECK:"?uint16_t_Val@@3U?$_UBitInt@$0BA@@__clang@@A" = global i16 0, align 2
+// CHECK:"?int16_t_Val@@3U?$_BitInt@$0BA@@__clang@@A" = global i16 0, align 2
 // CHECK:"?uint_Val@@3IA" = global i32 0, align 4
 // CHECK:"?uint64_t_Val@@3KA" = global i64 0, align 8
 // CHECK:"?int64_t_Val@@3JA" = global i64 0, align 8
-// CHECK:"?int16_t2_Val@@3T?$__vector@F$01@__clang@@A" = global <2 x i16> 
zeroinitializer, align 4
-// CHECK:"?int16_t3_Val@@3T?$__vector@F$02@__clang@@A" = global <3 x i16> 
zeroinitializer, align 8
-// CHECK:"?int16_t4_Val@@3T?$__vector@F$03@__clang@@A" = global <4 x i16> 
zeroinitializer, align 8
-// CHECK:"?uint16_t2_Val@@3T?$__vector@G$01@__clang@@A" = global <2 x i16> 
zeroinitializer, align 4
-// CHECK:"?uint16_t3_Val@@3T?$__vector@G$02@__clang@@A" = global <3 x i16> 
zeroinitializer, align 8
-// CHECK:"?uint16_t4_Val@@3T?$__vector@G$03@__clang@@A" = global <4 x i16> 
zeroinitializer, align 8
+// 
CHECK:"?int16_t2_Val@@3T?$__vector@U?$_BitInt@$0BA@@__clang@@$01@__clang@@A" = 
global <2 x i16> zeroinitializer, align 4
+// 
CHECK:"?int16_t3_Val@@3T?$__vector@U?$_BitInt@$0BA@@__clang@@$02@__clang@@A" = 
global <3 x i16> zeroinitializer, align 8
+// 
CHECK:"?int16_t4_Val@@3T?$__vector@U?$_BitInt@$0BA@@__clang@@$03@__clang@@A" = 
global <4 x i16> zeroinitializer, align 8
+// 
CHECK:"?uint16_t2_Val@@3T?$__vector@U?$_UBitInt@$0BA@@__clang@@$01@__clang@@A" 
= global <2 x i16> zeroinitializer, align 4
+// 
CHECK:"?uint16_t3_Val@@3T?$__vector@U?$_UBitInt@$0BA@@__clang@@$02@__clang@@A" 
= global <3 x i16> zeroinitializer, align 8
+// 
CHECK:"?uint16_t4_Val@@3T?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clang@@A" 
= global <4 x i16> zeroinitializer, align 8
 // CHECK:"?int2_Val@@3T?$__vector@H$01@__clang@@A" = global <2 x i32> 
zeroinitializer, align 8
 // CHECK:"?int3_Val@@3T?$__vector@H$02@__clang@@A" = global <3 x i32> 
zeroinitializer, align 16
 // CHECK:"?int4_Val@@3T?$__vector@H$03@__clang@@A" = global <4 x i32> 
zeroinitializer, align 16
Index: clang/lib/Headers/hlsl/hlsl_basic_types.h
===
--- clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -13,8 +13,8 @@
 
 #ifdef __HLSL_ENABLE_16_BIT
 // 16-bit integer.
-typedef unsigned short uint16_t;
-typedef short int16_t;
+typedef unsigned _BitInt(16) uint16_t;
+typedef _BitInt(16) int16_t;
 #endif
 
 // unsigned 32-bit integer.
Index: clang/lib/Basic/Targets/DirectX.h
===
--- clang/lib/Basic/Targets/DirectX.h
+++ clang/lib/Basic/Targets/DirectX.h
@@ -65,6 +65,7 @@
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override;
 
+  bool hasBitIntType() cons

[PATCH] D134191: [clang] Make config-related options CoreOptions

2022-09-19 Thread Michał Górny 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 rGdaebf2c13ce2: [clang] Make config-related options 
CoreOptions (authored by mgorny).
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134191

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -899,13 +899,13 @@
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, 
Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
-def config : Separate<["--"], "config">, Flags<[NoXarchOption]>,
+def config : Separate<["--"], "config">, Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Specifies configuration file">;
-def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption]>,
+def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Disable loading default configuration files">;
-def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
+def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, CoreOption, HelpHidden]>,
   HelpText<"System directory for configuration files">;
-def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
+def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, 
Flags<[NoXarchOption, CoreOption, HelpHidden]>,
   HelpText<"User directory for configuration files">;
 def coverage : Flag<["-", "--"], "coverage">, Group, 
Flags<[CoreOption]>;
 def cpp_precomp : Flag<["-"], "cpp-precomp">, Group;


Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -899,13 +899,13 @@
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
-def config : Separate<["--"], "config">, Flags<[NoXarchOption]>,
+def config : Separate<["--"], "config">, Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Specifies configuration file">;
-def no_default_config : Flag<["--"], "no-default-config">, Flags<[NoXarchOption]>,
+def no_default_config : Flag<["--"], "no-default-config">, Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Disable loading default configuration files">;
-def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, Flags<[NoXarchOption, HelpHidden]>,
+def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, Flags<[NoXarchOption, CoreOption, HelpHidden]>,
   HelpText<"System directory for configuration files">;
-def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, Flags<[NoXarchOption, HelpHidden]>,
+def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, Flags<[NoXarchOption, CoreOption, HelpHidden]>,
   HelpText<"User directory for configuration files">;
 def coverage : Flag<["-", "--"], "coverage">, Group, Flags<[CoreOption]>;
 def cpp_precomp : Flag<["-"], "cpp-precomp">, Group;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] daebf2c - [clang] Make config-related options CoreOptions

2022-09-19 Thread Michał Górny via cfe-commits

Author: Michał Górny
Date: 2022-09-19T18:58:09+02:00
New Revision: daebf2c13ce27ac6a7403525cc7fcbc063eb892e

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

LOG: [clang] Make config-related options CoreOptions

Make `--config`, `--no-default-config` and `--config-*-dir` CoreOptions
to enable their availability to all clang driver modes.  This improves
consistency given that the default set of configuration files is
processed independently of mode anyway.

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

Added: 


Modified: 
clang/include/clang/Driver/Options.td

Removed: 




diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 8dea1a01c1f89..67ceaf5bf0f2a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -899,13 +899,13 @@ def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, 
Group, Flags<[CC1Op
 def client__name : JoinedOrSeparate<["-"], "client_name">;
 def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, 
Unsupported]>;
 def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
-def config : Separate<["--"], "config">, Flags<[NoXarchOption]>,
+def config : Separate<["--"], "config">, Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Specifies configuration file">;
-def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption]>,
+def no_default_config : Flag<["--"], "no-default-config">, 
Flags<[NoXarchOption, CoreOption]>,
   HelpText<"Disable loading default configuration files">;
-def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
+def config_system_dir_EQ : Joined<["--"], "config-system-dir=">, 
Flags<[NoXarchOption, CoreOption, HelpHidden]>,
   HelpText<"System directory for configuration files">;
-def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, 
Flags<[NoXarchOption, HelpHidden]>,
+def config_user_dir_EQ : Joined<["--"], "config-user-dir=">, 
Flags<[NoXarchOption, CoreOption, HelpHidden]>,
   HelpText<"User directory for configuration files">;
 def coverage : Flag<["-", "--"], "coverage">, Group, 
Flags<[CoreOption]>;
 def cpp_precomp : Flag<["-"], "cpp-precomp">, Group;



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


[PATCH] D134191: [clang] Make config-related options CoreOptions

2022-09-19 Thread Michał Górny via Phabricator via cfe-commits
mgorny added a comment.

In D134191#3799841 , @MaskRay wrote:

> They don't need to be `NoXarchOption` if I am not mistaken.

I don't know about that. The comment on top says "The option is a "driver"-only 
option, and should not be forwarded to other tools via `-Xarch` options.". 
Well, it's processed by driver only, isn't it?


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

https://reviews.llvm.org/D134191

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


[clang] 95b3947 - [clang-format] JSON formatting add new option for controlling newlines in json arrays

2022-09-19 Thread via cfe-commits

Author: mydeveloperday
Date: 2022-09-19T17:54:39+01:00
New Revision: 95b39471110680f609cf56f5babf031a1c855d64

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

LOG: [clang-format] JSON formatting add new option for controlling newlines in 
json arrays

Working in a mixed environment of both vscode/vim with a team configured 
prettier configuration, this can leave clang-format and prettier fighting each 
other over the formatting of arrays, both simple arrays of elements.

This review aims to add some "control knobs" to the Json formatting in 
clang-format to help align the two tools so they can be used interchangeably.

This will allow simply arrays `[1, 2, 3]` to remain on a single line but will 
break those arrays based on context within that array.

Happy to change the name of the option (this is the third name I tried)

Reviewed By: HazardyKnusperkeks, owenpan

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

Added: 


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

Removed: 




diff  --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 01ebbd72aae44..3be291578828d 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -1698,6 +1698,23 @@ the configuration (without a prefix: ``Auto``).
  @Mock
  DataLoad loader;
 
+**BreakArrays** (``Boolean``) :versionbadge:`clang-format 16`
+  If ``true``, clang-format will always break after a Json array `[`
+  otherwise it will scan until the closing `]` to determine if it should add
+  newlines between elements (prettier compatible).
+
+  NOTE: This is currently only for formatting JSON.
+
+  .. code-block:: c++
+
+ true:  false:
+ [  vs.  [1, 2, 3, 4]
+   1,
+   2,
+   3,
+   4
+ ]
+
 **BreakBeforeBinaryOperators** (``BinaryOperatorStyle``) 
:versionbadge:`clang-format 3.6`
   The way to wrap binary operators.
 

diff  --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 818dbe0c89c78..c8b22f5ebde06 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -872,6 +872,23 @@ struct FormatStyle {
   /// \version 3.7
   bool BinPackParameters;
 
+  /// If ``true``, clang-format will always break after a Json array `[`
+  /// otherwise it will scan until the closing `]` to determine if it should 
add
+  /// newlines between elements (prettier compatible).
+  ///
+  /// NOTE: This is currently only for formatting JSON.
+  /// \code
+  ///true:  false:
+  ///[  vs.  [1, 2, 3, 4]
+  ///  1,
+  ///  2,
+  ///  3,
+  ///  4
+  ///]
+  /// \endcode
+  /// \version 16
+  bool BreakArrays;
+
   /// The style of wrapping parameters on the same line (bin-packed) or
   /// on one line each.
   enum BinPackStyle : int8_t {
@@ -3878,6 +3895,7 @@ struct FormatStyle {
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
BinPackParameters == R.BinPackParameters &&
+   BreakArrays == R.BreakArrays &&
BreakBeforeBinaryOperators == R.BreakBeforeBinaryOperators &&
BreakBeforeBraces == R.BreakBeforeBraces &&
BreakBeforeConceptDeclarations == R.BreakBeforeConceptDeclarations 
&&

diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 0327a7ccb22ea..58d5fc1f8c865 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -728,6 +728,7 @@ template <> struct MappingTraits {
 
 IO.mapOptional("BreakAfterJavaFieldAnnotations",
Style.BreakAfterJavaFieldAnnotations);
+IO.mapOptional("BreakArrays", Style.BreakArrays);
 IO.mapOptional("BreakStringLiterals", Style.BreakStringLiterals);
 IO.mapOptional("ColumnLimit", Style.ColumnLimit);
 IO.mapOptional("CommentPragmas", Style.CommentPragmas);
@@ -1249,6 +1250,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Never;
   LLVMStyle.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
   LLVMStyle.ExperimentalAutoDetectBinPacking = false;
+  LLVMStyle.BreakArrays = true;
   LLVMStyle.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
   LLVMStyle.FixNamespaceComments = true;
   LLVMStyle.ForEachMacros.push_back("foreach");

diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index e530120fa4454..21c

[PATCH] D133589: [clang-format] JSON formatting add new option for controlling newlines in json arrays

2022-09-19 Thread MyDeveloperDay via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG95b394711106: [clang-format] JSON formatting add new option 
for controlling newlines in json… (authored by MyDeveloperDay).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133589

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTestJson.cpp

Index: clang/unittests/Format/FormatTestJson.cpp
===
--- clang/unittests/Format/FormatTestJson.cpp
+++ clang/unittests/Format/FormatTestJson.cpp
@@ -159,6 +159,27 @@
"]");
 }
 
+TEST_F(FormatTestJson, JsonArrayOneLine) {
+  FormatStyle Style = getLLVMStyle(FormatStyle::LK_Json);
+  Style.BreakArrays = false;
+  Style.SpacesInContainerLiterals = false;
+  verifyFormat("[]", Style);
+  verifyFormat("[1]", Style);
+  verifyFormat("[1, 2]", Style);
+  verifyFormat("[1, 2, 3]", Style);
+  verifyFormat("[1, 2, 3, 4]", Style);
+  verifyFormat("[1, 2, 3, 4, 5]", Style);
+
+  verifyFormat("[\n"
+   "  1,\n"
+   "  2,\n"
+   "  {\n"
+   "A: 1\n"
+   "  }\n"
+   "]",
+   Style);
+}
+
 TEST_F(FormatTestJson, JsonNoStringSplit) {
   FormatStyle Style = getLLVMStyle(FormatStyle::LK_Json);
   Style.IndentWidth = 4;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4401,18 +4401,22 @@
 // }
 if (Left.is(TT_DictLiteral) && Left.is(tok::l_brace))
   return true;
-// Always break after a JSON array opener.
-// [
-// ]
-if (Left.is(TT_ArrayInitializerLSquare) && Left.is(tok::l_square) &&
-!Right.is(tok::r_square)) {
-  return true;
+// Always break after a JSON array opener based on BreakArrays.
+if ((Left.is(TT_ArrayInitializerLSquare) && Left.is(tok::l_square) &&
+ Right.isNot(tok::r_square)) ||
+Left.is(tok::comma)) {
+  if (Right.is(tok::l_brace))
+return true;
+  // scan to the right if an we see an object or an array inside
+  // then break.
+  for (const auto *Tok = &Right; Tok; Tok = Tok->Next) {
+if (Tok->isOneOf(tok::l_brace, tok::l_square))
+  return true;
+if (Tok->isOneOf(tok::r_brace, tok::r_square))
+  break;
+  }
+  return Style.BreakArrays;
 }
-// Always break after successive entries.
-// 1,
-// 2
-if (Left.is(tok::comma))
-  return true;
   }
 
   // If the last token before a '}', ']', or ')' is a comma or a trailing
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -728,6 +728,7 @@
 
 IO.mapOptional("BreakAfterJavaFieldAnnotations",
Style.BreakAfterJavaFieldAnnotations);
+IO.mapOptional("BreakArrays", Style.BreakArrays);
 IO.mapOptional("BreakStringLiterals", Style.BreakStringLiterals);
 IO.mapOptional("ColumnLimit", Style.ColumnLimit);
 IO.mapOptional("CommentPragmas", Style.CommentPragmas);
@@ -1249,6 +1250,7 @@
   LLVMStyle.EmptyLineAfterAccessModifier = FormatStyle::ELAAMS_Never;
   LLVMStyle.EmptyLineBeforeAccessModifier = FormatStyle::ELBAMS_LogicalBlock;
   LLVMStyle.ExperimentalAutoDetectBinPacking = false;
+  LLVMStyle.BreakArrays = true;
   LLVMStyle.PackConstructorInitializers = FormatStyle::PCIS_BinPack;
   LLVMStyle.FixNamespaceComments = true;
   LLVMStyle.ForEachMacros.push_back("foreach");
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -872,6 +872,23 @@
   /// \version 3.7
   bool BinPackParameters;
 
+  /// If ``true``, clang-format will always break after a Json array `[`
+  /// otherwise it will scan until the closing `]` to determine if it should add
+  /// newlines between elements (prettier compatible).
+  ///
+  /// NOTE: This is currently only for formatting JSON.
+  /// \code
+  ///true:  false:
+  ///[  vs.  [1, 2, 3, 4]
+  ///  1,
+  ///  2,
+  ///  3,
+  ///  4
+  ///]
+  /// \endcode
+  /// \version 16
+  bool BreakArrays;
+
   /// The style of wrapping parameters on the same line (bin-packed) or
   /// on one line each.
   enum BinPackStyle : int8_t {
@@ -3878,6 +3895,7 @@
AttributeMacros == R.AttributeMacros &&
BinPackArguments == R.BinPackArguments &&
BinPackParameters == R.BinPackParameters &&
+   BreakArrays == R.BreakArrays &&
  

[clang] 649a597 - [clang] Allow vector of BitInt

2022-09-19 Thread Xiang Li via cfe-commits

Author: Xiang Li
Date: 2022-09-19T09:26:56-07:00
New Revision: 649a59712ffbc937174268d04ee9a8885f572e2a

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

LOG: [clang] Allow vector of BitInt

Remove check which disable BitInt as element type for ext_vector.

Enabling it for HLSL to use _BitInt(16) as 16bit int at 
https://reviews.llvm.org/D133668

Reviewed By: erichkeane

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

Added: 
clang/test/CodeGenCXX/ext-int-vector-abi.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/MicrosoftMangle.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGenCXX/ext-int.cpp
clang/test/Sema/builtin-classify-type.c
clang/test/SemaCXX/ext-int.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 97ccc2a98c93b..673aba962b7fe 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3021,6 +3021,9 @@ def err_attribute_too_many_arguments : Error<
 def err_attribute_too_few_arguments : Error<
   "%0 attribute takes at least %1 argument%s1">;
 def err_attribute_invalid_vector_type : Error<"invalid vector element type 
%0">;
+def err_attribute_invalid_bitint_vector_type : Error<
+  "'_BitInt' vector element width must be %select{a power of 2|"
+  "at least as wide as 'CHAR_BIT'}0">;
 def err_attribute_invalid_matrix_type : Error<"invalid matrix element type 
%0">;
 def err_attribute_bad_neon_vector_size : Error<
   "Neon vector size must be 64 or 128 bits">;

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index ab141789416ca..622bad78e59a8 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -4019,7 +4019,11 @@ QualType ASTContext::getScalableVectorType(QualType 
EltTy,
 /// the specified element type and size. VectorType must be a built-in type.
 QualType ASTContext::getVectorType(QualType vecType, unsigned NumElts,
VectorType::VectorKind VecKind) const {
-  assert(vecType->isBuiltinType());
+  assert(vecType->isBuiltinType() ||
+ (vecType->isBitIntType() &&
+  // Only support _BitInt elements with byte-sized power of 2 NumBits.
+  llvm::isPowerOf2_32(vecType->getAs()->getNumBits()) &&
+  vecType->getAs()->getNumBits() >= 8));
 
   // Check if we've already instantiated a vector of this type.
   llvm::FoldingSetNodeID ID;
@@ -4087,9 +4091,13 @@ ASTContext::getDependentVectorType(QualType VecType, 
Expr *SizeExpr,
 
 /// getExtVectorType - Return the unique reference to an extended vector type 
of
 /// the specified element type and size. VectorType must be a built-in type.
-QualType
-ASTContext::getExtVectorType(QualType vecType, unsigned NumElts) const {
-  assert(vecType->isBuiltinType() || vecType->isDependentType());
+QualType ASTContext::getExtVectorType(QualType vecType,
+  unsigned NumElts) const {
+  assert(vecType->isBuiltinType() || vecType->isDependentType() ||
+ (vecType->isBitIntType() &&
+  // Only support _BitInt elements with byte-sized power of 2 NumBits.
+  llvm::isPowerOf2_32(vecType->getAs()->getNumBits()) &&
+  vecType->getAs()->getNumBits() >= 8));
 
   // Check if we've already instantiated a vector of this type.
   llvm::FoldingSetNodeID ID;

diff  --git a/clang/lib/AST/MicrosoftMangle.cpp 
b/clang/lib/AST/MicrosoftMangle.cpp
index e58fedb6fa54c..bc69d85e49c96 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -3073,14 +3073,17 @@ bool 
MicrosoftCXXNameMangler::isArtificialTagType(QualType T) const {
 
 void MicrosoftCXXNameMangler::mangleType(const VectorType *T, Qualifiers Quals,
  SourceRange Range) {
-  const BuiltinType *ET = T->getElementType()->getAs();
-  assert(ET && "vectors with non-builtin elements are unsupported");
+  QualType EltTy = T->getElementType();
+  const BuiltinType *ET = EltTy->getAs();
+  const BitIntType *BitIntTy = EltTy->getAs();
+  assert((ET || BitIntTy) &&
+ "vectors with non-builtin/_BitInt elements are unsupported");
   uint64_t Width = getASTContext().getTypeSize(T);
   // Pattern match exactly the typedefs in our intrinsic headers.  Anything 
that
   // doesn't match the Intel types uses a custom mangling below.
   size_t OutSizeBefore = Out.tell();
   if (!isa(T)) {
-if (getASTContext().getTargetInfo().getTriple().isX86()) {
+if (getASTContext().getTargetInfo().getTriple().isX86() && ET) {
   if (Width == 64 && ET->getKind() == BuiltinType::LongLong) {
 mangleArtificialTagType(

[PATCH] D133634: [clang] Allow vector of BitInt

2022-09-19 Thread Xiang Li via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
python3kgae marked an inline comment as done.
Closed by commit rG649a59712ffb: [clang] Allow vector of BitInt (authored by 
python3kgae).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133634

Files:
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/lib/AST/ASTContext.cpp
  clang/lib/AST/MicrosoftMangle.cpp
  clang/lib/Sema/SemaType.cpp
  clang/test/CodeGenCXX/ext-int-vector-abi.cpp
  clang/test/CodeGenCXX/ext-int.cpp
  clang/test/Sema/builtin-classify-type.c
  clang/test/SemaCXX/ext-int.cpp

Index: clang/test/SemaCXX/ext-int.cpp
===
--- clang/test/SemaCXX/ext-int.cpp
+++ clang/test/SemaCXX/ext-int.cpp
@@ -84,10 +84,22 @@
 };
 
 // Reject vector types:
-// expected-error@+1{{invalid vector element type '_BitInt(32)'}}
-typedef _BitInt(32) __attribute__((vector_size(16))) VecTy;
-// expected-error@+1{{invalid vector element type '_BitInt(32)'}}
-typedef _BitInt(32) __attribute__((ext_vector_type(32))) OtherVecTy;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(2) __attribute__((vector_size(16))) VecTy;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(2) __attribute__((ext_vector_type(32))) OtherVecTy;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(4) __attribute__((vector_size(16))) VecTy2;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(4) __attribute__((ext_vector_type(32))) OtherVecTy2;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(5) __attribute__((vector_size(16))) VecTy3;
+// expected-error@+1{{'_BitInt' vector element width must be at least as wide as 'CHAR_BIT'}}
+typedef _BitInt(5) __attribute__((ext_vector_type(32))) OtherVecTy3;
+// expected-error@+1{{'_BitInt' vector element width must be a power of 2}}
+typedef _BitInt(37) __attribute__((vector_size(16))) VecTy4;
+// expected-error@+1{{'_BitInt' vector element width must be a power of 2}}
+typedef _BitInt(37) __attribute__((ext_vector_type(32))) OtherVecTy4;
 
 // Allow _Complex:
 _Complex _BitInt(3) Cmplx;
Index: clang/test/Sema/builtin-classify-type.c
===
--- clang/test/Sema/builtin-classify-type.c
+++ clang/test/Sema/builtin-classify-type.c
@@ -29,6 +29,23 @@
   __attribute__((vector_size(16))) int vec;
   typedef __attribute__((ext_vector_type(4))) int evec_t;
   evec_t evec;
+  typedef _BitInt(8) int8_t3 __attribute__((ext_vector_type(3)));
+  int8_t3 t3;
+  typedef _BitInt(16) int16_t3 __attribute__((ext_vector_type(4)));
+  int16_t3 t4;
+  typedef _BitInt(32) int32_t3 __attribute__((ext_vector_type(5)));
+  int32_t3 t5;
+  typedef _BitInt(64) int64_t3 __attribute__((ext_vector_type(6)));
+  int64_t3 t6;
+  typedef _BitInt(8) vint8_t3 __attribute__((vector_size(3)));
+  vint8_t3 vt3;
+  typedef _BitInt(16) vint16_t3 __attribute__((vector_size(4)));
+  vint16_t3 vt4;
+  typedef _BitInt(32) vint32_t3 __attribute__((vector_size(8)));
+  vint32_t3 vt5;
+  typedef _BitInt(64) vint64_t3 __attribute__((vector_size(16)));
+  vint64_t3 vt6;
+
   _Atomic int atomic_i;
   _Atomic double atomic_d;
   _Complex int complex_i;
Index: clang/test/CodeGenCXX/ext-int.cpp
===
--- clang/test/CodeGenCXX/ext-int.cpp
+++ clang/test/CodeGenCXX/ext-int.cpp
@@ -129,6 +129,9 @@
   return 0;
 }
 
+typedef unsigned _BitInt(16) uint16_t4 __attribute__((ext_vector_type(4)));
+typedef _BitInt(32) vint32_t8 __attribute__((vector_size(32)));
+
 template
 void ManglingTestTemplateParam(T&);
 template<_BitInt(99) T>
@@ -136,7 +139,6 @@
 template 
 auto ManglingDependent() -> decltype(_BitInt(N){});
 
-
 void ManglingInstantiator() {
   // LIN: define{{.*}} void @_Z20ManglingInstantiatorv()
   // WIN: define dso_local void @"?ManglingInstantiator@@YAXXZ"()
@@ -156,6 +158,12 @@
   // LIN: call signext i4 @_Z17ManglingDependentILi4EEDTtlDBT__EEv()
   // WIN64: call i4 @"??$ManglingDependent@$03@@YAU?$_BitInt@$03@__clang@@XZ"()
   // WIN32: call signext i4 @"??$ManglingDependent@$03@@YAU?$_BitInt@$03@__clang@@XZ"()
+  uint16_t4 V;
+  ManglingTestTemplateParam(V);
+  // LIN: call void @_Z25ManglingTestTemplateParamIDv4_DU16_EvRT_(<4 x i16>*
+  // WIN64: call void @"??$ManglingTestTemplateParam@T?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clangYAXAEAT?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clang@@@Z"(<4 x i16>*
+  // WIN32: call void @"??$ManglingTestTemplateParam@T?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clangYAXAAT?$__vector@U?$_UBitInt@$0BA@@__clang@@$03@__clang@@@Z"(<4 x i16>*
+
 }
 
 void Ta

[PATCH] D133920: [X86][fastcall][vectorcall] Move capability check before free register update

2022-09-19 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.
This revision is now accepted and ready to land.

lgtm, thanks for the fix!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133920

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


[PATCH] D133711: [Sema] Reject array element types whose sizes aren't a multiple of their alignments

2022-09-19 Thread Reid Kleckner via Phabricator via cfe-commits
rnk accepted this revision.
rnk added a comment.

Sound like a good plan. 👍


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D133711

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


  1   2   >